سؤال

Is there a method in boost::filesystem that gives the file system type for a path, as provided by;

$ stat -f -L -c %T .
ext2/ext3

I don't necessarily want a string. An enumerated value would do.

هل كانت مفيدة؟

المحلول

I don't think boost provides any way for querying file system type. However, you may want to use the statfs function for this purpose. From the man page -

The function statfs() returns information about a mounted file system. path is the pathname of any file within the mounted file system. buf is a pointer to a statfs structure defined approximately as follows:

       struct statfs {
           __SWORD_TYPE f_type;    /* type of file system (see below) */
           __SWORD_TYPE f_bsize;   /* optimal transfer block size */
           fsblkcnt_t   f_blocks;  /* total data blocks in file system */
           fsblkcnt_t   f_bfree;   /* free blocks in fs */
           fsblkcnt_t   f_bavail;  /* free blocks available to
                                      unprivileged user */
           fsfilcnt_t   f_files;   /* total file nodes in file system */
           fsfilcnt_t   f_ffree;   /* free file nodes in fs */
           fsid_t       f_fsid;    /* file system id */
           __SWORD_TYPE f_namelen; /* maximum length of filenames */
           __SWORD_TYPE f_frsize;  /* fragment size (since Linux 2.6) */
           __SWORD_TYPE f_spare[5];
       };
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top