Results 1 to 3 of 3
Hello. From within C++ I need to determine whether two files/directories (specified by two strings) belong to the same volume or not. How can I do that?
I tried using ...
- 05-25-2009 #1Just Joined!
- Join Date
- May 2009
- Posts
- 2
How to tell if two files are on the same mount point?
Hello. From within C++ I need to determine whether two files/directories (specified by two strings) belong to the same volume or not. How can I do that?
I tried using statfs() and statvfs() but the volume id field they return (f_fsid) is always zero for non-root users. There must be a different way to find out? I don't really need volume IDs, just a boolean value saying "same volume"/"different volumes".
Thanks!!
--
Jan
- 05-27-2009 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Use fstat(). You pass it a struct stat pointer that it fills out with information about the file. The structure is defined as follows (from the fstat manpage):
The member you are interested in is st_dev.Code: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 filesystem I/O */ blkcnt_t st_blocks; /* number of 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 */ };
FYI, this is a C language function, so it will work just fine in your code provided you #include <sys/stat.h>.Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 05-28-2009 #3Just Joined!
- Join Date
- May 2009
- Posts
- 2


Reply With Quote
