Add more logging on trace channel

This commit is contained in:
Rafał Harabień 2018-12-08 19:29:02 +01:00
parent 1768b0fe7e
commit 4727b170df
2 changed files with 18 additions and 2 deletions

View File

@ -171,6 +171,7 @@ impl<'a, T: ReadWriteSeek + 'a> Dir<'a, T> {
/// ///
/// `path` is a '/' separated directory path relative to self directory. /// `path` is a '/' separated directory path relative to self directory.
pub fn open_dir(&self, path: &str) -> io::Result<Self> { pub fn open_dir(&self, path: &str) -> io::Result<Self> {
trace!("open_dir {}", path);
let (name, rest_opt) = split_path(path); let (name, rest_opt) = split_path(path);
let e = self.find_entry(name, Some(true), None)?; let e = self.find_entry(name, Some(true), None)?;
match rest_opt { 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. /// `path` is a '/' separated file path relative to self directory.
pub fn open_file(&self, path: &str) -> io::Result<File<'a, T>> { pub fn open_file(&self, path: &str) -> io::Result<File<'a, T>> {
trace!("open_file {}", path);
// traverse path // traverse path
let (name, rest_opt) = split_path(path); let (name, rest_opt) = split_path(path);
if let Some(rest) = rest_opt { 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. /// `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. /// 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<File<'a, T>> { pub fn create_file(&self, path: &str) -> io::Result<File<'a, T>> {
trace!("create_file {}", path);
// traverse path // traverse path
let (name, rest_opt) = split_path(path); let (name, rest_opt) = split_path(path);
if let Some(rest) = rest_opt { 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. /// `path` is a '/' separated path relative to self directory.
pub fn create_dir(&self, path: &str) -> io::Result<Self> { pub fn create_dir(&self, path: &str) -> io::Result<Self> {
trace!("create_dir {}", path);
// traverse path // traverse path
let (name, rest_opt) = split_path(path); let (name, rest_opt) = split_path(path);
if let Some(rest) = rest_opt { if let Some(rest) = rest_opt {
@ -252,6 +256,7 @@ impl<'a, T: ReadWriteSeek + 'a> Dir<'a, T> {
} }
fn is_empty(&self) -> io::Result<bool> { fn is_empty(&self) -> io::Result<bool> {
trace!("is_empty");
// check if directory contains no files // check if directory contains no files
for r in self.iter() { for r in self.iter() {
let e = r?; 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 /// Make sure there is no reference to this file (no File instance) or filesystem corruption
/// can happen. /// can happen.
pub fn remove(&self, path: &str) -> io::Result<()> { pub fn remove(&self, path: &str) -> io::Result<()> {
trace!("remove {}", path);
// traverse path // traverse path
let (name, rest_opt) = split_path(path); let (name, rest_opt) = split_path(path);
if let Some(rest) = rest_opt { if let Some(rest) = rest_opt {
let e = self.find_entry(name, Some(true), None)?; let e = self.find_entry(name, Some(true), None)?;
return e.to_dir().remove(rest); return e.to_dir().remove(rest);
} }
trace!("removing {}", path);
// in case of directory check if it is empty // in case of directory check if it is empty
let e = self.find_entry(name, None, None)?; let e = self.find_entry(name, None, None)?;
if e.is_dir() && !e.to_dir().is_empty()? { 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 /// Make sure there is no reference to this file (no File instance) or filesystem corruption
/// can happen. /// can happen.
pub fn rename(&self, src_path: &str, dst_dir: &Dir<T>, dst_path: &str) -> io::Result<()> { pub fn rename(&self, src_path: &str, dst_dir: &Dir<T>, dst_path: &str) -> io::Result<()> {
trace!("rename {} {}", src_path, dst_path);
// traverse source path // traverse source path
let (name, rest_opt) = split_path(src_path); let (name, rest_opt) = split_path(src_path);
if let Some(rest) = rest_opt { 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<T>, dst_name: &str) -> io::Result<()> { fn rename_internal(&self, src_name: &str, dst_dir: &Dir<T>, dst_name: &str) -> io::Result<()> {
trace!("moving {} to {}", src_name, dst_name); trace!("rename_internal {} {}", src_name, dst_name);
// find existing file // find existing file
let e = self.find_entry(src_name, None, None)?; let e = self.find_entry(src_name, None, None)?;
// check if destionation filename is unused // 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<Option<DirEntry<'a, T>>> { fn read_dir_entry(&mut self) -> io::Result<Option<DirEntry<'a, T>>> {
trace!("read_dir_entry");
let mut lfn_buf = LongNameBuilder::new(); let mut lfn_buf = LongNameBuilder::new();
let mut offset = self.stream.seek(SeekFrom::Current(0))?; let mut offset = self.stream.seek(SeekFrom::Current(0))?;
let mut begin_offset = offset; 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 // Check if this is deleted or volume ID entry
if self.should_ship_entry(&raw_entry) { if self.should_ship_entry(&raw_entry) {
trace!("skip entry");
lfn_buf.clear(); lfn_buf.clear();
begin_offset = offset; begin_offset = offset;
continue; continue;
@ -515,6 +523,7 @@ impl<'a, T: ReadWriteSeek> DirIter<'a, T> {
lfn_buf.validate_chksum(data.name()); lfn_buf.validate_chksum(data.name());
// Return directory entry // Return directory entry
let short_name = ShortName::new(data.name()); let short_name = ShortName::new(data.name());
trace!("file entry {:?}", data.name());
return Ok(Some(DirEntry { return Ok(Some(DirEntry {
data, data,
short_name, short_name,
@ -526,6 +535,7 @@ impl<'a, T: ReadWriteSeek> DirIter<'a, T> {
}, },
DirEntryData::Lfn(data) => { DirEntryData::Lfn(data) => {
// Append to LFN buffer // Append to LFN buffer
trace!("lfn entry");
lfn_buf.process(&data); lfn_buf.process(&data);
}, },
} }

View File

@ -295,6 +295,7 @@ impl<T: ReadWriteSeek> FileSystem<T> {
/// cause a filesystem corruption. /// cause a filesystem corruption.
pub fn new(mut disk: T, options: FsOptions) -> io::Result<Self> { pub fn new(mut disk: T, options: FsOptions) -> io::Result<Self> {
// Make sure given image is not seeked // Make sure given image is not seeked
trace!("FileSystem::new");
debug_assert!(disk.seek(SeekFrom::Current(0))? == 0); debug_assert!(disk.seek(SeekFrom::Current(0))? == 0);
// read boot sector // read boot sector
@ -327,6 +328,7 @@ impl<T: ReadWriteSeek> FileSystem<T> {
// return FileSystem struct // return FileSystem struct
let status_flags = bpb.status_flags(); let status_flags = bpb.status_flags();
trace!("FileSystem::new end");
Ok(FileSystem { Ok(FileSystem {
disk: RefCell::new(disk), disk: RefCell::new(disk),
options, options,
@ -410,6 +412,7 @@ impl<T: ReadWriteSeek> FileSystem<T> {
/// Returns a root directory object allowing for futher penetration of a filesystem structure. /// Returns a root directory object allowing for futher penetration of a filesystem structure.
pub fn root_dir<'b>(&'b self) -> Dir<'b, T> { pub fn root_dir<'b>(&'b self) -> Dir<'b, T> {
trace!("root_dir");
let root_rdr = { let root_rdr = {
match self.fat_type { match self.fat_type {
FatType::Fat12 | FatType::Fat16 => DirRawStream::Root(DiskSlice::from_sectors( FatType::Fat12 | FatType::Fat16 => DirRawStream::Root(DiskSlice::from_sectors(
@ -470,6 +473,7 @@ impl<T: ReadWriteSeek> FileSystem<T> {
} }
pub(crate) fn alloc_cluster(&self, prev_cluster: Option<u32>) -> io::Result<u32> { pub(crate) fn alloc_cluster(&self, prev_cluster: Option<u32>) -> io::Result<u32> {
trace!("alloc_cluster");
let hint = self.fs_info.borrow().next_free_cluster; let hint = self.fs_info.borrow().next_free_cluster;
let mut fat = self.fat_slice(); let mut fat = self.fat_slice();
let cluster = alloc_cluster(&mut fat, self.fat_type, prev_cluster, hint, self.total_clusters)?; 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 /// image (e.g. partition) library user should wrap the file struct in a struct limiting
/// access to partition bytes only e.g. `fscommon::StreamSlice`. /// access to partition bytes only e.g. `fscommon::StreamSlice`.
pub fn format_volume<T: ReadWriteSeek>(mut disk: T, options: FormatVolumeOptions) -> io::Result<()> { pub fn format_volume<T: ReadWriteSeek>(mut disk: T, options: FormatVolumeOptions) -> io::Result<()> {
trace!("format_volume");
disk.seek(SeekFrom::Start(0))?; disk.seek(SeekFrom::Start(0))?;
// Create boot sector, validate and write to storage device // Create boot sector, validate and write to storage device
let (boot, fat_type) = format_boot_sector(&options)?; let (boot, fat_type) = format_boot_sector(&options)?;
@ -938,5 +943,6 @@ pub fn format_volume<T: ReadWriteSeek>(mut disk: T, options: FormatVolumeOptions
// TODO: create volume label dir entry if volume label is set // TODO: create volume label dir entry if volume label is set
disk.seek(SeekFrom::Start(0))?; disk.seek(SeekFrom::Start(0))?;
trace!("format_volume end");
Ok(()) Ok(())
} }