From 4727b170df85fe9f19559b993169f97ffaa83986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Harabie=C5=84?= Date: Sat, 8 Dec 2018 19:29:02 +0100 Subject: [PATCH] Add more logging on trace channel --- src/dir.rs | 14 ++++++++++++-- src/fs.rs | 6 ++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/dir.rs b/src/dir.rs index f365c29..6619204 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -171,6 +171,7 @@ impl<'a, T: ReadWriteSeek + 'a> Dir<'a, T> { /// /// `path` is a '/' separated directory path relative to self directory. pub fn open_dir(&self, path: &str) -> io::Result { + trace!("open_dir {}", path); let (name, rest_opt) = split_path(path); let e = self.find_entry(name, Some(true), None)?; match rest_opt { @@ -183,6 +184,7 @@ impl<'a, T: ReadWriteSeek + 'a> Dir<'a, T> { /// /// `path` is a '/' separated file path relative to self directory. pub fn open_file(&self, path: &str) -> io::Result> { + trace!("open_file {}", path); // traverse path let (name, rest_opt) = split_path(path); if let Some(rest) = rest_opt { @@ -199,6 +201,7 @@ impl<'a, T: ReadWriteSeek + 'a> Dir<'a, T> { /// `path` is a '/' separated file path relative to self directory. /// File is never truncated when opening. It can be achieved by calling `File::truncate` method after opening. pub fn create_file(&self, path: &str) -> io::Result> { + trace!("create_file {}", path); // traverse path let (name, rest_opt) = split_path(path); if let Some(rest) = rest_opt { @@ -221,6 +224,7 @@ impl<'a, T: ReadWriteSeek + 'a> Dir<'a, T> { /// /// `path` is a '/' separated path relative to self directory. pub fn create_dir(&self, path: &str) -> io::Result { + trace!("create_dir {}", path); // traverse path let (name, rest_opt) = split_path(path); if let Some(rest) = rest_opt { @@ -252,6 +256,7 @@ impl<'a, T: ReadWriteSeek + 'a> Dir<'a, T> { } fn is_empty(&self) -> io::Result { + trace!("is_empty"); // check if directory contains no files for r in self.iter() { let e = r?; @@ -270,13 +275,13 @@ impl<'a, T: ReadWriteSeek + 'a> Dir<'a, T> { /// Make sure there is no reference to this file (no File instance) or filesystem corruption /// can happen. pub fn remove(&self, path: &str) -> io::Result<()> { + trace!("remove {}", path); // traverse path let (name, rest_opt) = split_path(path); if let Some(rest) = rest_opt { let e = self.find_entry(name, Some(true), None)?; return e.to_dir().remove(rest); } - trace!("removing {}", path); // in case of directory check if it is empty let e = self.find_entry(name, None, None)?; if e.is_dir() && !e.to_dir().is_empty()? { @@ -308,6 +313,7 @@ impl<'a, T: ReadWriteSeek + 'a> Dir<'a, T> { /// Make sure there is no reference to this file (no File instance) or filesystem corruption /// can happen. pub fn rename(&self, src_path: &str, dst_dir: &Dir, dst_path: &str) -> io::Result<()> { + trace!("rename {} {}", src_path, dst_path); // traverse source path let (name, rest_opt) = split_path(src_path); if let Some(rest) = rest_opt { @@ -325,7 +331,7 @@ impl<'a, T: ReadWriteSeek + 'a> Dir<'a, T> { } fn rename_internal(&self, src_name: &str, dst_dir: &Dir, dst_name: &str) -> io::Result<()> { - trace!("moving {} to {}", src_name, dst_name); + trace!("rename_internal {} {}", src_name, dst_name); // find existing file let e = self.find_entry(src_name, None, None)?; // check if destionation filename is unused @@ -491,6 +497,7 @@ impl<'a, T: ReadWriteSeek> DirIter<'a, T> { } fn read_dir_entry(&mut self) -> io::Result>> { + trace!("read_dir_entry"); let mut lfn_buf = LongNameBuilder::new(); let mut offset = self.stream.seek(SeekFrom::Current(0))?; let mut begin_offset = offset; @@ -503,6 +510,7 @@ impl<'a, T: ReadWriteSeek> DirIter<'a, T> { } // Check if this is deleted or volume ID entry if self.should_ship_entry(&raw_entry) { + trace!("skip entry"); lfn_buf.clear(); begin_offset = offset; continue; @@ -515,6 +523,7 @@ impl<'a, T: ReadWriteSeek> DirIter<'a, T> { lfn_buf.validate_chksum(data.name()); // Return directory entry let short_name = ShortName::new(data.name()); + trace!("file entry {:?}", data.name()); return Ok(Some(DirEntry { data, short_name, @@ -526,6 +535,7 @@ impl<'a, T: ReadWriteSeek> DirIter<'a, T> { }, DirEntryData::Lfn(data) => { // Append to LFN buffer + trace!("lfn entry"); lfn_buf.process(&data); }, } diff --git a/src/fs.rs b/src/fs.rs index eadddbb..2b430e2 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -295,6 +295,7 @@ impl FileSystem { /// cause a filesystem corruption. pub fn new(mut disk: T, options: FsOptions) -> io::Result { // Make sure given image is not seeked + trace!("FileSystem::new"); debug_assert!(disk.seek(SeekFrom::Current(0))? == 0); // read boot sector @@ -327,6 +328,7 @@ impl FileSystem { // return FileSystem struct let status_flags = bpb.status_flags(); + trace!("FileSystem::new end"); Ok(FileSystem { disk: RefCell::new(disk), options, @@ -410,6 +412,7 @@ impl FileSystem { /// Returns a root directory object allowing for futher penetration of a filesystem structure. pub fn root_dir<'b>(&'b self) -> Dir<'b, T> { + trace!("root_dir"); let root_rdr = { match self.fat_type { FatType::Fat12 | FatType::Fat16 => DirRawStream::Root(DiskSlice::from_sectors( @@ -470,6 +473,7 @@ impl FileSystem { } pub(crate) fn alloc_cluster(&self, prev_cluster: Option) -> io::Result { + trace!("alloc_cluster"); let hint = self.fs_info.borrow().next_free_cluster; let mut fat = self.fat_slice(); let cluster = alloc_cluster(&mut fat, self.fat_type, prev_cluster, hint, self.total_clusters)?; @@ -877,6 +881,7 @@ impl FormatVolumeOptions { /// image (e.g. partition) library user should wrap the file struct in a struct limiting /// access to partition bytes only e.g. `fscommon::StreamSlice`. pub fn format_volume(mut disk: T, options: FormatVolumeOptions) -> io::Result<()> { + trace!("format_volume"); disk.seek(SeekFrom::Start(0))?; // Create boot sector, validate and write to storage device let (boot, fat_type) = format_boot_sector(&options)?; @@ -938,5 +943,6 @@ pub fn format_volume(mut disk: T, options: FormatVolumeOptions // TODO: create volume label dir entry if volume label is set disk.seek(SeekFrom::Start(0))?; + trace!("format_volume end"); Ok(()) }