Make FileSystemStats struct fields non-public and add getters
This way new fields can be added later without losing backward compatibility.
This commit is contained in:
parent
66c976bc3b
commit
0b5b04aca6
20
src/fs.rs
20
src/fs.rs
@ -311,11 +311,25 @@ impl FsOptions {
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct FileSystemStats {
|
||||
/// Cluster size in bytes
|
||||
pub cluster_size: u32,
|
||||
cluster_size: u32,
|
||||
/// Number of total clusters in filesystem usable for file allocation
|
||||
pub total_clusters: u32,
|
||||
total_clusters: u32,
|
||||
/// Number of free clusters
|
||||
pub free_clusters: u32,
|
||||
free_clusters: u32,
|
||||
}
|
||||
|
||||
impl FileSystemStats {
|
||||
pub fn cluster_size(&self) -> u32 {
|
||||
self.cluster_size
|
||||
}
|
||||
|
||||
pub fn total_clusters(&self) -> u32 {
|
||||
self.total_clusters
|
||||
}
|
||||
|
||||
pub fn free_clusters(&self) -> u32 {
|
||||
self.free_clusters
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) type FileSystemRef<'a, 'b> = &'a FileSystem<'b>;
|
||||
|
@ -218,9 +218,9 @@ fn test_status_flags_fat32() {
|
||||
fn test_stats_fat12() {
|
||||
call_with_fs(&|fs| {
|
||||
let stats = fs.stats().unwrap();
|
||||
assert_eq!(stats.cluster_size, 512);
|
||||
assert_eq!(stats.total_clusters, 1955); // 1000 * 1024 / 512 = 2000
|
||||
assert_eq!(stats.free_clusters, 1920);
|
||||
assert_eq!(stats.cluster_size(), 512);
|
||||
assert_eq!(stats.total_clusters(), 1955); // 1000 * 1024 / 512 = 2000
|
||||
assert_eq!(stats.free_clusters(), 1920);
|
||||
}, FAT12_IMG)
|
||||
}
|
||||
|
||||
@ -228,9 +228,9 @@ fn test_stats_fat12() {
|
||||
fn test_stats_fat16() {
|
||||
call_with_fs(&|fs| {
|
||||
let stats = fs.stats().unwrap();
|
||||
assert_eq!(stats.cluster_size, 512);
|
||||
assert_eq!(stats.total_clusters, 4927); // 2500 * 1024 / 512 = 5000
|
||||
assert_eq!(stats.free_clusters, 4892);
|
||||
assert_eq!(stats.cluster_size(), 512);
|
||||
assert_eq!(stats.total_clusters(), 4927); // 2500 * 1024 / 512 = 5000
|
||||
assert_eq!(stats.free_clusters(), 4892);
|
||||
}, FAT16_IMG)
|
||||
}
|
||||
|
||||
@ -238,8 +238,8 @@ fn test_stats_fat16() {
|
||||
fn test_stats_fat32() {
|
||||
call_with_fs(&|fs| {
|
||||
let stats = fs.stats().unwrap();
|
||||
assert_eq!(stats.cluster_size, 512);
|
||||
assert_eq!(stats.total_clusters, 66922); // 34000 * 1024 / 512 = 68000
|
||||
assert_eq!(stats.free_clusters, 66886);
|
||||
assert_eq!(stats.cluster_size(), 512);
|
||||
assert_eq!(stats.total_clusters(), 66922); // 34000 * 1024 / 512 = 68000
|
||||
assert_eq!(stats.free_clusters(), 66886);
|
||||
}, FAT32_IMG)
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ fn test_rename_file(fs: FileSystem) {
|
||||
assert_eq!(str::from_utf8(&buf).unwrap(), TEST_STR2);
|
||||
|
||||
let new_stats = fs.stats().unwrap();
|
||||
assert_eq!(new_stats.free_clusters, stats.free_clusters);
|
||||
assert_eq!(new_stats.free_clusters(), stats.free_clusters());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user