Find the answer to your Linux question:
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 ...
  1. #1
    Just 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

  2. #2
    Linux Guru Rubberman's Avatar
    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):
    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 */
              };
    The member you are interested in is st_dev.

    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!

  3. #3
    Just Joined!
    Join Date
    May 2009
    Posts
    2
    Quote Originally Posted by Rubberman View Post
    The member you are interested in is st_dev.

    FYI, this is a C language function, so it will work just fine in your code provided you #include <sys/stat.h>.
    Thanks! I've just figured it out but it's good to know st_dev is the thing. Much appreciated.

    --
    Jan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...