smb_fstat doesn't work for directories
opened this issue · comments
On a directory, smb_fstat seems to always return NULL.
Current workaround:
smb_stat stat = smb_fstat(s, tid, path);
if (stat == NULL) {
smb_stat_list stats = smb_find(s, tid, path);
if (stats != NULL) {
size_t n = smb_stat_list_count(stats);
if (n == 1) {
stat = smb_stat_list_at(stats, 0);
}
}
}
Unless of course, I misunderstood the api...
A quick look at the code confirms this.
Also, smb_stat_name(stat)
on the result of smb_fstat
returns the complete path (including the name of the share), while the same call on an item of a smb_stat_list
only returns the actual name of the file or directory. I don't know, which behaviour is correct. I'd prefer the latter.
What does fstat give?
Not sure I understand your question. As mentioned above smb_fstat
gives the complete path smb_stat_list
just the name(s).
Ah, are you talking about the samba client?
If however, you are referring to the posix function, the file name or path doesn't seem to be part of the result:
struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device ID (if special file) */
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for file system I/O */
blkcnt_t st_blocks; /* number of 512B blocks allocated */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last status change */
};
And this is from the samba smbclient:
stat file
This command depends on the server supporting the CIFS UNIX extensions and will fail if the server does not. The client requests the UNIX basic info level and prints out the same info that the Linux stat command would about the file. This includes the size, blocks used on disk, file type, permissions, inode number, number of links and finally the three timestamps (access, modify and change). If the file is a special file (symlink, character or block device, fifo or socket) then extra information may also be printed.
I'd say just the name of the file, then.
Thanks. BTW, on the command line stat
just echoes what you key in, e.g. stat -f "%N" ../asdf/test.pdf
would print ../asdf/test.pdf
.
Using bin/dsm sample, I cannot reproduce your issue. smb_fstat is working for a directory and tell me that the file is indeed a directory.