capsules_system/storage_permissions/
tbf_header.rsuse core::cmp;
use kernel::capabilities::ApplicationStorageCapability;
use kernel::platform::chip::Chip;
use kernel::process::Process;
use kernel::process::ShortId;
use kernel::storage_permissions::StoragePermissions;
pub struct TbfHeaderStoragePermissions<
C: Chip,
D: kernel::process::ProcessStandardDebug,
CAP: ApplicationStorageCapability,
> {
cap: CAP,
_chip: core::marker::PhantomData<C>,
_debug: core::marker::PhantomData<D>,
}
impl<C: Chip, D: kernel::process::ProcessStandardDebug, CAP: ApplicationStorageCapability>
TbfHeaderStoragePermissions<C, D, CAP>
{
pub fn new(cap: CAP) -> Self {
Self {
cap,
_chip: core::marker::PhantomData,
_debug: core::marker::PhantomData,
}
}
}
impl<C: Chip, D: kernel::process::ProcessStandardDebug, CAP: ApplicationStorageCapability>
kernel::process::ProcessStandardStoragePermissionsPolicy<C, D>
for TbfHeaderStoragePermissions<C, D, CAP>
{
fn get_permissions(
&self,
process: &kernel::process::ProcessStandard<C, D>,
) -> StoragePermissions {
match process.short_app_id() {
ShortId::Fixed(id) => {
if let Some((write_allowed, read_count, read_ids, modify_count, modify_ids)) =
process.get_tbf_storage_permissions()
{
let read_count_capped = cmp::min(read_count, 8);
let modify_count_capped = cmp::min(modify_count, 8);
StoragePermissions::new_fixed_size(
id,
write_allowed,
false,
read_count_capped,
read_ids,
modify_count_capped,
modify_ids,
&self.cap,
)
} else {
StoragePermissions::new_null()
}
}
ShortId::LocallyUnique => StoragePermissions::new_null(),
}
}
}