Skip to content

Commit

Permalink
Dokan: minor changes to debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
inetic committed May 3, 2024
1 parent 71117c8 commit a1caf58
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 16 deletions.
88 changes: 76 additions & 12 deletions vfs/src/dokan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,19 @@ impl VirtualFilesystem {
create_disposition: u32,
create_options: u32,
) -> Result<CreateFileInfo<EntryHandle>, Error> {
tracing::debug!("enter");

let create_disposition = create_disposition.try_into()?;
let delete_on_close = create_options & FILE_DELETE_ON_CLOSE > 0;
let create_dir = create_options & FILE_DIRECTORY_FILE > 0;
let delete_access = access_mask.has_delete();

tracing::trace!(
"enter delete_on_close:{:?}, create_dir:{:?}, delete_access:{:?}, create_disposition:{:?}",
delete_on_close,
create_dir,
delete_access,
create_disposition,
);

let path = to_path(file_name)?;

let (entry, is_new, id) = self
Expand Down Expand Up @@ -381,7 +387,7 @@ impl VirtualFilesystem {
_info: &OperationInfo<'c, 'h, Super>,
context: &'c EntryHandle,
) {
tracing::debug!("enter");
tracing::trace!("enter");

match &context.entry {
Entry::File(entry) => {
Expand Down Expand Up @@ -528,7 +534,7 @@ impl VirtualFilesystem {
_info: &OperationInfo<'c, 'h, Super>,
context: &'c EntryHandle,
) -> Result<(), Error> {
tracing::debug!("enter");
tracing::trace!("enter");
match &context.entry {
Entry::File(entry) => {
let mut lock = entry.file.lock().await;
Expand Down Expand Up @@ -559,7 +565,7 @@ impl VirtualFilesystem {
_info: &OperationInfo<'c, 'h, Super>,
context: &'c EntryHandle,
) -> Result<FileInfo, Error> {
tracing::debug!("enter");
tracing::trace!("enter");

let (attributes, file_size) = match &context.entry {
Entry::File(entry) => {
Expand Down Expand Up @@ -658,7 +664,7 @@ impl VirtualFilesystem {
.map_err(Error::into)
}

#[instrument(skip_all, fields(?_file_name), err(Debug))]
#[instrument(skip_all, fields(?_file_name, file_attributes = file_attribute_to_string(_file_attributes)), err(Debug))]
async fn async_set_file_attributes<'c, 'h: 'c, Super: FileSystemHandler<'c, 'h>>(
&self,
_file_name: &U16CStr,
Expand Down Expand Up @@ -724,7 +730,7 @@ impl VirtualFilesystem {
info: &OperationInfo<'c, 'h, Super>,
context: &'c EntryHandle,
) -> Result<(), Error> {
tracing::debug!("enter");
tracing::trace!("enter");
let file_entry = context.entry.as_file()?;
file_entry.shared.write().await.delete_on_close = info.delete_on_close();
Ok(())
Expand All @@ -748,7 +754,7 @@ impl VirtualFilesystem {
info: &OperationInfo<'c, 'h, Super>,
context: &'c EntryHandle,
) -> Result<(), Error> {
tracing::debug!("enter");
tracing::trace!("enter");
let dir_entry = context.entry.as_directory()?;
let path = to_path(file_name)?;
let mut shared = dir_entry.shared.write().await;
Expand Down Expand Up @@ -785,7 +791,7 @@ impl VirtualFilesystem {
_info: &OperationInfo<'c, 'h, Super>,
handle: &'c EntryHandle,
) -> Result<(), Error> {
tracing::debug!("enter");
tracing::trace!("enter");

let src_path = to_path(file_name)?;
let dst_path = to_path(new_file_name)?;
Expand Down Expand Up @@ -857,7 +863,7 @@ impl VirtualFilesystem {
info: &OperationInfo<'c, 'h, Super>,
context: &'c EntryHandle,
) -> Result<(), Error> {
tracing::debug!("enter");
tracing::trace!("enter");
// TODO: How do the fwo functions differ?
self.async_set_allocation_size(file_name, offset, info, context)
.await
Expand All @@ -883,7 +889,7 @@ impl VirtualFilesystem {
_info: &OperationInfo<'c, 'h, Super>,
context: &'c EntryHandle,
) -> Result<(), Error> {
tracing::debug!("enter");
tracing::trace!("enter");
let desired_len: u64 = alloc_size
.try_into()
.map_err(|_| STATUS_INVALID_PARAMETER)?;
Expand Down Expand Up @@ -969,7 +975,7 @@ impl VirtualFilesystem {
&self,
_info: &OperationInfo<'c, 'h, Super>,
) -> Result<VolumeInfo, Error> {
tracing::debug!("enter");
tracing::trace!("enter");
Ok(VolumeInfo {
name: U16CString::from_str("ouisync").unwrap(),
serial_number: 0,
Expand Down Expand Up @@ -1418,3 +1424,61 @@ pub(crate) fn default_mount_flags() -> MountFlags {
//flags |= MountFlags::REMOVABLE;
MountFlags::empty()
}

// For debugging
fn file_attribute_to_string(file_attributes: u32) -> String {
let mut ret = String::new();

let mut check = |attr: u32, attr_name: &str| {
if file_attributes & attr > 0 {
if !ret.is_empty() {
ret += "|";
}
ret += attr_name;
}
};

check(winnt::FILE_ATTRIBUTE_READONLY, "FILE_ATTRIBUTE_READONLY");
check(winnt::FILE_ATTRIBUTE_HIDDEN, "FILE_ATTRIBUTE_HIDDEN");
check(winnt::FILE_ATTRIBUTE_SYSTEM, "FILE_ATTRIBUTE_SYSTEM");
check(winnt::FILE_ATTRIBUTE_DIRECTORY, "FILE_ATTRIBUTE_DIRECTORY");
check(winnt::FILE_ATTRIBUTE_ARCHIVE, "FILE_ATTRIBUTE_ARCHIVE");
check(winnt::FILE_ATTRIBUTE_DEVICE, "FILE_ATTRIBUTE_DEVICE");
check(winnt::FILE_ATTRIBUTE_NORMAL, "FILE_ATTRIBUTE_NORMAL");
check(winnt::FILE_ATTRIBUTE_TEMPORARY, "FILE_ATTRIBUTE_TEMPORARY");
check(
winnt::FILE_ATTRIBUTE_SPARSE_FILE,
"FILE_ATTRIBUTE_SPARSE_FILE",
);
check(
winnt::FILE_ATTRIBUTE_REPARSE_POINT,
"FILE_ATTRIBUTE_REPARSE_POINT",
);
check(
winnt::FILE_ATTRIBUTE_COMPRESSED,
"FILE_ATTRIBUTE_COMPRESSED",
);
check(winnt::FILE_ATTRIBUTE_OFFLINE, "FILE_ATTRIBUTE_OFFLINE");
check(
winnt::FILE_ATTRIBUTE_NOT_CONTENT_INDEXED,
"FILE_ATTRIBUTE_NOT_CONTENT_INDEXED",
);
check(winnt::FILE_ATTRIBUTE_ENCRYPTED, "FILE_ATTRIBUTE_ENCRYPTED");
check(
winnt::FILE_ATTRIBUTE_INTEGRITY_STREAM,
"FILE_ATTRIBUTE_INTEGRITY_STREAM",
);
check(winnt::FILE_ATTRIBUTE_EA, "FILE_ATTRIBUTE_EA");
check(winnt::FILE_ATTRIBUTE_PINNED, "FILE_ATTRIBUTE_PINNED");
check(winnt::FILE_ATTRIBUTE_UNPINNED, "FILE_ATTRIBUTE_UNPINNED");
check(
winnt::FILE_ATTRIBUTE_RECALL_ON_OPEN,
"FILE_ATTRIBUTE_RECALL_ON_OPEN",
);
check(
winnt::FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS,
"FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS",
);

ret
}
5 changes: 1 addition & 4 deletions vfs/src/dokan/multi_repo_mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,10 +781,7 @@ impl<'c, 'h: 'c> FileSystemHandler<'c, 'h> for Handler {
let debug_id = self.generate_debug_id();

if self.debug_type == DebugType::Full {
println!(
"{debug_id} Enter: close_file {:?}",
file_name.to_string_lossy()
);
println!("{debug_id} Enter: close_file {:?}", file_name.as_ustr());
}

self.close_file_(file_name, info, context);
Expand Down

0 comments on commit a1caf58

Please sign in to comment.