Skip to content

Commit 49010b9

Browse files
committed
Expose bytes_per_sector and first_cluster
1 parent b20dbb1 commit 49010b9

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ New features:
4343
* Add `strict` field in `FsOptions`, which allows disabling validation of boot signature to improve compatibility with old FAT images
4444
* Improve `open_dir`
4545
* Flush on unmount
46+
* Expose bytes_per_sector and first_cluster
4647

4748
Bug fixes:
4849
* Fix formatting volumes with size in range 4096-4199 KB

src/boot_sector.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ impl BiosParameterBlock {
395395
u32::from(self.sectors_per_cluster) * u32::from(self.bytes_per_sector)
396396
}
397397

398+
pub(crate) fn bytes_per_sector(&self) -> u16 {
399+
self.bytes_per_sector
400+
}
401+
398402
pub(crate) fn clusters_from_bytes(&self, bytes: u64) -> u32 {
399403
let cluster_size = u64::from(self.cluster_size());
400404
((bytes + cluster_size - 1) / cluster_size) as u32

src/dir_entry.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,9 @@ impl<'a, IO: ReadWriteSeek, TP, OCC: OemCpConverter> DirEntry<'a, IO, TP, OCC> {
606606
self.data.is_file()
607607
}
608608

609-
pub(crate) fn first_cluster(&self) -> Option<u32> {
609+
/// Return first cluster of a entry.
610+
#[must_use]
611+
pub fn first_cluster(&self) -> Option<u32> {
610612
self.data.first_cluster(self.fs.fat_type())
611613
}
612614

src/fs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,12 @@ impl<IO: Read + Write + Seek, TP, OCC> FileSystem<IO, TP, OCC> {
460460
self.bpb.cluster_size()
461461
}
462462

463+
/// Get sector size in bytes
464+
#[must_use]
465+
pub fn bytes_per_sector(&self) -> u16 {
466+
self.bpb.bytes_per_sector()
467+
}
468+
463469
pub(crate) fn offset_from_cluster(&self, cluster: u32) -> u64 {
464470
self.offset_from_sector(self.sector_from_cluster(cluster))
465471
}

0 commit comments

Comments
 (0)