use crate::ArcMutex;
use crate::error::Result;
use crate::fat_table::fat_entry::FAT_ENTRY_SIZE;
use crate::fat_table::{FatEntry, get_params};
use crate::{CachedPartition, ClusterId};
pub(crate) fn next_cluster(
cluster_id: ClusterId,
device: ArcMutex<CachedPartition>,
) -> Result<Option<ClusterId>> {
let fat_entry = read_fat_entry(cluster_id, device)?;
Ok(match fat_entry {
FatEntry::DataCluster(id) => Some(ClusterId::new(id)),
_ => None,
})
}
pub(crate) fn read_fat_entry(
cluster_id: ClusterId,
device: ArcMutex<CachedPartition>,
) -> Result<FatEntry> {
let mut buf = [0u8; FAT_ENTRY_SIZE];
let (sector, offset) = get_params(&device, cluster_id)?;
device
.read_sector_offset(sector, offset, &mut buf)
.map(|_| FatEntry::from(buf))
}