Changeset 30254 in vbox
- Timestamp:
- Jun 16, 2010 2:37:24 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
include/iprt/fs.h (modified) (2 diffs)
-
src/VBox/Runtime/r3/posix/fs-posix.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/fs.h
r28800 r30254 180 180 181 181 182 /** @name Filesystem type IDs. Used by RTFsQueryType. */ 183 #define RTFS_FS_TYPE_UNKNOWN 0 184 #define RTFS_FS_TYPE_EXT 1 185 #define RTFS_FS_TYPE_EXT2 2 186 #define RTFS_FS_TYPE_EXT3 3 187 #define RTFS_FS_TYPE_EXT4 4 188 #define RTFS_FS_TYPE_TMPFS 5 189 #define RTFS_FS_TYPE_JFS 6 190 #define RTFS_FS_TYPE_NFS 7 191 #define RTFS_FS_TYPE_HFS 8 192 #define RTFS_FS_TYPE_CIFS 9 193 #define RTFS_FS_TYPE_FAT 10 194 #define RTFS_FS_TYPE_NTFS 11 195 #define RTFS_FS_TYPE_ZFS 12 196 197 182 198 /** 183 199 * The available additional information in a RTFSOBJATTR object. … … 385 401 RTR3DECL(int) RTFsQueryDriver(const char *pszFsPath, char *pszFsDriver, size_t cbFsDriver); 386 402 403 /** 404 * Query the name of the filesystem the file is located on. 405 * 406 * @returns iprt status code. 407 * @param pszFsPath Path within the mounted filesystem. 408 * @param pu32Type Where to store the filesystem type. 409 * See RTFS_FS_TYPE_xxx constants. 410 */ 411 RTR3DECL(int) RTFsQueryType(const char *pszFsPath, uint32_t *pu32Type); 412 387 413 #endif /* IN_RING3 */ 388 414 -
trunk/src/VBox/Runtime/r3/posix/fs-posix.cpp
r28915 r30254 32 32 #include <sys/statvfs.h> 33 33 #include <errno.h> 34 #include <stdio.h> 35 #ifdef RT_OS_LINUX 36 # include <mntent.h> 37 #endif 34 38 35 39 #include <iprt/fs.h> … … 163 167 } 164 168 169 170 RTR3DECL(int) RTFsQueryType(const char *pszFsPath, uint32_t *pu32Type) 171 { 172 /* 173 * Validate input. 174 */ 175 AssertMsgReturn(VALID_PTR(pszFsPath) && *pszFsPath, ("%p", pszFsPath), VERR_INVALID_PARAMETER); 176 177 /* 178 * Convert the path and query the stats. 179 * We're simply return the device id. 180 */ 181 char const *pszNativeFsPath; 182 int rc = rtPathToNative(&pszNativeFsPath, pszFsPath, NULL); 183 if (RT_SUCCESS(rc)) 184 { 185 *pu32Type = RTFS_FS_TYPE_UNKNOWN; 186 187 struct stat Stat; 188 if (!stat(pszNativeFsPath, &Stat)) 189 { 190 #if defined(RT_OS_LINUX) 191 FILE *mounted = setmntent("/proc/mounts", "r"); 192 if (!mounted) 193 mounted = setmntent("/etc/mtab", "r"); 194 if (mounted) 195 { 196 char szBuf[1024]; 197 struct stat mntStat; 198 struct mntent mntEnt; 199 while (getmntent_r(mounted, &mntEnt, szBuf, sizeof(szBuf))) 200 { 201 if (!stat(mntEnt.mnt_dir, &mntStat)) 202 { 203 if (mntStat.st_dev == Stat.st_dev) 204 { 205 if (!strcmp("ext4", mntEnt.mnt_type)) 206 *pu32Type = RTFS_FS_TYPE_EXT4; 207 else if (!strcmp("ext3", mntEnt.mnt_type)) 208 *pu32Type = RTFS_FS_TYPE_EXT3; 209 else if (!strcmp("ext2", mntEnt.mnt_type)) 210 *pu32Type = RTFS_FS_TYPE_EXT2; 211 else if ( !strcmp("vfat", mntEnt.mnt_type) 212 || !strcmp("msdos", mntEnt.mnt_type)) 213 *pu32Type = RTFS_FS_TYPE_FAT; 214 else if (!strcmp("tmpfs", mntEnt.mnt_type)) 215 *pu32Type = RTFS_FS_TYPE_TMPFS; 216 else 217 { 218 /* sometimes there are more than one entry for the same partition */ 219 continue; 220 } 221 break; 222 } 223 } 224 } 225 endmntent(mounted); 226 } 227 #elif defined(RT_OS_SOLARIS) 228 if (!strcmp("zfs", Stat.st_fstype)) 229 *pu32Type = RTFS_FS_TYPE_ZFS; 230 #endif 231 } 232 else 233 rc = RTErrConvertFromErrno(errno); 234 rtPathFreeNative(pszNativeFsPath, pszFsPath); 235 } 236 237 return rc; 238 }
Note:
See TracChangeset
for help on using the changeset viewer.

