Lines Matching refs:fs
17 fs::{Cluster, FATFileSystem, MAX_FILE_SIZE},
83 fs: &Arc<FATFileSystem>, in read()
92 let start_cluster_number: u64 = offset / fs.bytes_per_cluster(); in read()
95 fs.get_cluster_by_relative(self.first_cluster, start_cluster_number as usize) in read()
105 let mut in_cluster_offset: u64 = offset % fs.bytes_per_cluster(); in read()
113 if in_cluster_offset >= fs.bytes_per_cluster() { in read()
114 if let Some(FATEntry::Next(c)) = fs.get_fat_entry(current_cluster).ok() { in read()
116 in_cluster_offset %= fs.bytes_per_cluster(); in read()
126 (fs.bytes_per_cluster() - in_cluster_offset) as usize, in read()
132 let offset = fs.cluster_bytes_offset(current_cluster) + in_cluster_offset; in read()
133 let r = fs.partition.disk().device().read_at( in read()
160 fs: &Arc<FATFileSystem>, in write()
164 self.ensure_len(fs, offset, buf.len() as u64)?; in write()
167 let start_cluster_num = offset / fs.bytes_per_cluster(); in write()
170 fs.get_cluster_by_relative(self.first_cluster, start_cluster_num as usize) in write()
177 let mut in_cluster_bytes_offset: u64 = offset % fs.bytes_per_cluster(); in write()
184 if in_cluster_bytes_offset >= fs.bytes_per_cluster() { in write()
185 if let Some(FATEntry::Next(c)) = fs.get_fat_entry(current_cluster).ok() { in write()
187 in_cluster_bytes_offset = in_cluster_bytes_offset % fs.bytes_per_cluster(); in write()
194 (fs.bytes_per_cluster() - in_cluster_bytes_offset) as usize, in write()
199 let offset = fs.cluster_bytes_offset(current_cluster) + in_cluster_bytes_offset; in write()
201 let w: usize = fs.partition.disk().device().write_at( in write()
231 fs: &Arc<FATFileSystem>, in ensure_len()
241 let in_cluster_offset = self.size() % fs.bytes_per_cluster(); in ensure_len()
245 fs.bytes_per_cluster() - in_cluster_offset in ensure_len()
255 self.first_cluster = fs.allocate_cluster(None)?; in ensure_len()
257 bytes_remain_in_cluster = fs.bytes_per_cluster(); in ensure_len()
263 (extra_bytes - bytes_remain_in_cluster + fs.bytes_per_cluster() - 1) in ensure_len()
264 / fs.bytes_per_cluster(); in ensure_len()
265 let last_cluster = if let Some(c) = fs.get_last_cluster(self.first_cluster) { in ensure_len()
274 current_cluster = fs.allocate_cluster(Some(current_cluster))?; in ensure_len()
281 let start_cluster: u64 = self.size() / fs.bytes_per_cluster(); in ensure_len()
282 let start_cluster: Cluster = fs in ensure_len()
287 fs.cluster_bytes_offset(start_cluster) + self.size() % fs.bytes_per_cluster(); in ensure_len()
289 let bytes_remain: u64 = fs.bytes_per_cluster() - (self.size() % fs.bytes_per_cluster()); in ensure_len()
291 let cluster_offset_start = offset / fs.bytes_per_cluster(); in ensure_len()
293 let end_cluster: Cluster = fs in ensure_len()
298 self.zero_range(fs, start_offset, start_offset + bytes_remain)?; in ensure_len()
300 self.zero_range(fs, start_offset, start_offset + offset - self.size())?; in ensure_len()
307 let short_entry_offset = fs.cluster_bytes_offset(self.loc.1 .0) + self.loc.1 .1; in ensure_len()
310 self.short_dir_entry.flush(fs, short_entry_offset)?; in ensure_len()
320 fs: &Arc<FATFileSystem>, in zero_range()
329 fs.partition.disk().device().write_at( in zero_range()
343 pub fn truncate(&mut self, fs: &Arc<FATFileSystem>, new_size: u64) -> Result<(), SystemError> { in truncate()
348 let new_last_cluster = (new_size + fs.bytes_per_cluster() - 1) / fs.bytes_per_cluster(); in truncate()
350 fs.get_cluster_by_relative(self.first_cluster, new_last_cluster as usize) in truncate()
352 fs.deallocate_cluster_chain(begin_delete)?; in truncate()
363 let short_entry_offset = fs.cluster_bytes_offset((self.loc.1).0) + (self.loc.1).1; in truncate()
364 self.short_dir_entry.flush(fs, short_entry_offset)?; in truncate()
388 pub fn to_iter(&self, fs: Arc<FATFileSystem>) -> FATDirIter { in to_iter()
393 fs: fs, in to_iter()
404 pub fn size(&self, fs: &Arc<FATFileSystem>) -> u64 { in size()
405 return fs.num_clusters_chain(self.first_cluster) * fs.bytes_per_cluster(); in size()
418 fs: Arc<FATFileSystem>, in find_free_entries()
428 if offset >= fs.bytes_per_cluster() && !self.is_root() { in find_free_entries()
430 if let Some(FATEntry::Next(c)) = fs.get_fat_entry(current_cluster).ok() { in find_free_entries()
433 offset = offset % fs.bytes_per_cluster(); in find_free_entries()
440 if self.is_root() && offset > fs.root_dir_end_bytes_offset().unwrap() { in find_free_entries()
444 let e_offset = fs.cluster_bytes_offset(current_cluster) + offset; in find_free_entries()
445 let entry: FATRawDirEntry = get_raw_dir_entry(&fs, e_offset)?; in find_free_entries()
473 (remain_entries * FATRawDirEntry::DIR_ENTRY_LEN + fs.bytes_per_cluster() - 1) in find_free_entries()
474 / fs.bytes_per_cluster(); in find_free_entries()
482 let c: Cluster = fs.allocate_cluster(Some(prev_cluster))?; in find_free_entries()
513 fs: Arc<FATFileSystem>, in find_entry()
517 for e in self.to_iter(fs) { in find_entry()
541 pub fn open_file(&self, name: &str, fs: Arc<FATFileSystem>) -> Result<FATFile, SystemError> { in open_file()
542 let f: FATFile = self.find_entry(name, Some(false), None, fs)?.to_file()?; in open_file()
547 pub fn open_dir(&self, name: &str, fs: Arc<FATFileSystem>) -> Result<FATDir, SystemError> { in open_dir()
548 let d: FATDir = self.find_entry(name, Some(true), None, fs)?.to_dir()?; in open_dir()
556 pub fn create_file(&self, name: &str, fs: &Arc<FATFileSystem>) -> Result<FATFile, SystemError> { in create_file()
558 self.check_existence(name, Some(false), fs.clone()); in create_file()
582 fs.clone(), in create_file()
595 pub fn create_dir(&self, name: &str, fs: &Arc<FATFileSystem>) -> Result<FATDir, SystemError> { in create_dir()
597 self.check_existence(name, Some(true), fs.clone()); in create_dir()
616 let first_cluster: Cluster = fs.allocate_cluster(None)?; in create_dir()
629 dot_entry.flush(&fs, fs.cluster_bytes_offset(first_cluster) + offset)?; in create_dir()
643 dot_dot_entry.flush(&fs, fs.cluster_bytes_offset(first_cluster) + offset)?; in create_dir()
655 fs.clone(), in create_dir()
680 fs: Arc<FATFileSystem>, in check_existence()
686 self.find_entry(name, expect_dir, Some(&mut sng), fs.clone()); in check_existence()
726 fs: Arc<FATFileSystem>,
740 self.find_free_entries(num_entries, fs.clone())?;
747 FATDirEntryOffsetIter::new(fs.clone(), start_loc, num_entries, None).collect();
754 let bytes_offset = fs.cluster_bytes_offset(off.0) + off.1;
755 long_entry.flush(fs.clone(), bytes_offset)?;
761 let offset = fs.cluster_bytes_offset(end.0) + end.1;
762 short_dentry.flush(&fs, offset)?;
771 pub fn is_empty(&self, fs: Arc<FATFileSystem>) -> bool { in is_empty()
772 for e in self.to_iter(fs) { in is_empty()
793 fs: Arc<FATFileSystem>, in remove()
797 let e: FATDirEntry = self.find_entry(name, None, None, fs.clone())?; in remove()
800 if e.is_dir() && !(e.to_dir().unwrap().is_empty(fs.clone())) { in remove()
806 fs.deallocate_cluster_chain(e.first_cluster())?; in remove()
810 self.remove_dir_entries(fs, e.get_dir_range().unwrap())?; in remove()
822 fs: Arc<FATFileSystem>, in remove_dir_entries()
827 FATDirEntryOffsetIter::new(fs.clone(), cluster_range.0, 15, Some(cluster_range.1)) in remove_dir_entries()
831 let disk_bytes_offset = fs.cluster_bytes_offset(off.0) + off.1; in remove_dir_entries()
834 short_entry.flush(&fs, disk_bytes_offset)?; in remove_dir_entries()
845 fs: Arc<FATFileSystem>, in get_dir_entry()
853 return self.find_entry(name, None, None, fs); in get_dir_entry()
860 fs: Arc<FATFileSystem>, in rename()
866 self.check_existence(old_name, None, fs.clone())? in rename()
875 self.check_existence(new_name, None, fs.clone())? in rename()
886 self.remove(fs.clone(), old_dentry.name().as_str(), false)?; in rename()
894 fs.clone(), in rename()
1086 pub fn flush(&self, fs: Arc<FATFileSystem>, disk_bytes_offset: u64) -> Result<(), SystemError> { in flush()
1088 let blk_offset = fs.get_in_block_offset(disk_bytes_offset); in flush()
1089 let lba = fs.get_lba_from_offset( in flush()
1090 fs.bytes_to_sector(fs.get_in_partition_bytes_offset(disk_bytes_offset)), in flush()
1093 v.resize(1 * fs.lba_per_sector() * LBA_SIZE, 0); in flush()
1094 fs.partition in flush()
1096 .read_at(lba, 1 * fs.lba_per_sector(), &mut v)?; in flush()
1123 fs.partition in flush()
1125 .write_at(lba, 1 * fs.lba_per_sector(), cursor.as_slice())?; in flush()
1126 fs.partition.disk().sync()?; in flush()
1298 fs: &Arc<FATFileSystem>, in flush()
1302 let blk_offset = fs.get_in_block_offset(disk_bytes_offset); in flush()
1303 let lba = fs.get_lba_from_offset( in flush()
1304 fs.bytes_to_sector(fs.get_in_partition_bytes_offset(disk_bytes_offset)), in flush()
1307 v.resize(1 * fs.lba_per_sector() * LBA_SIZE, 0); in flush()
1308 fs.partition in flush()
1310 .read_at(lba, 1 * fs.lba_per_sector(), &mut v)?; in flush()
1329 fs.partition in flush()
1331 .write_at(lba, 1 * fs.lba_per_sector(), cursor.as_slice())?; in flush()
1332 fs.partition.disk().sync()?; in flush()
1405 fs: Arc<FATFileSystem>, field
1423 if self.offset >= self.fs.bytes_per_cluster() && !self.is_root { in get_dir_entry()
1424 match self.fs.get_fat_entry(self.current_cluster)? { in get_dir_entry()
1428 self.offset %= self.fs.bytes_per_cluster(); in get_dir_entry()
1440 if self.is_root && self.offset > self.fs.root_dir_end_bytes_offset().unwrap() { in get_dir_entry()
1445 let offset: u64 = self.fs.cluster_bytes_offset(self.current_cluster) + self.offset; in get_dir_entry()
1448 let raw_dentry: FATRawDirEntry = get_raw_dir_entry(&self.fs, offset)?; in get_dir_entry()
1481 if self.offset >= self.fs.bytes_per_cluster() && !self.is_root { in get_dir_entry()
1482 match self.fs.get_fat_entry(self.current_cluster)? { in get_dir_entry()
1486 self.offset %= self.fs.bytes_per_cluster(); in get_dir_entry()
1498 && self.offset > self.fs.root_dir_end_bytes_offset().unwrap() in get_dir_entry()
1505 self.fs.cluster_bytes_offset(self.current_cluster) + self.offset; in get_dir_entry()
1507 let raw_dentry: FATRawDirEntry = get_raw_dir_entry(&self.fs, offset)?; in get_dir_entry()
2281 fs: Arc<FATFileSystem>, field
2300 fs: Arc<FATFileSystem>, in new()
2308 fs, in new()
2329 if new_offset >= self.fs.bytes_per_cluster() { in next()
2330 new_offset %= self.fs.bytes_per_cluster(); in next()
2332 match self.fs.get_fat_entry(new_cluster) { in next()
2357 fs: &Arc<FATFileSystem>, in get_raw_dir_entry()
2361 let blk_offset: u64 = fs.get_in_block_offset(in_disk_bytes_offset); in get_raw_dir_entry()
2362 let lba = fs.get_lba_from_offset( in get_raw_dir_entry()
2363 fs.bytes_to_sector(fs.get_in_partition_bytes_offset(in_disk_bytes_offset)), in get_raw_dir_entry()
2373 fs.partition.disk().read_at(lba, 1, &mut v)?; in get_raw_dir_entry()