Changeset 69840 in vbox for trunk/src/VBox/Runtime/common/fs
- Timestamp:
- Nov 27, 2017 3:19:30 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 119281
- Location:
- trunk/src/VBox/Runtime/common/fs
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/fs/fatvfs.cpp
r69832 r69840 5606 5606 * 5607 5607 * Check the DOS signature first. The PC-DOS 1.0 boot floppy does not have 5608 * a signature and we ASSUME this is the case for all flop ies formated by it.5608 * a signature and we ASSUME this is the case for all floppies formated by it. 5609 5609 */ 5610 5610 if (Buf.BootSector.uSignature != FATBOOTSECTOR_SIGNATURE) -
trunk/src/VBox/Runtime/common/fs/filesystemext.cpp
r69111 r69840 29 29 * Header Files * 30 30 *********************************************************************************************************************************/ 31 #define LOG_GROUP LOG_GROUP_DEFAULT 32 #include <iprt/types.h> 31 #define LOG_GROUP RTLOGGROUP_FS 32 #include <iprt/fsvfs.h> 33 33 34 #include <iprt/assert.h> 35 #include <iprt/log.h> 34 36 #include <iprt/mem.h> 35 #include <iprt/filesystem.h>36 37 #include <iprt/string.h> 37 38 #include <iprt/vfs.h> 38 #include "internal/filesystem.h" 39 #include <iprt/vfslowlevel.h> 40 #include <iprt/formats/ext2.h> 39 41 40 42 … … 42 44 * Structures and Typedefs * 43 45 *********************************************************************************************************************************/ 44 45 /*46 * The filesystem structures are from http://wiki.osdev.org/Ext2 and47 * http://www.nongnu.org/ext2-doc/ext2.html48 */49 50 /**51 * Ext superblock.52 *53 * Everything is stored little endian on the disk.54 */55 #pragma pack(1)56 typedef struct ExtSuperBlock57 {58 /** Total number of inodes in the filesystem. */59 uint32_t cInodesTotal;60 /** Total number of blocks in the filesystem. */61 uint32_t cBlocksTotal;62 /** Number of blocks reserved for the super user. */63 uint32_t cBlocksRsvdForSuperUser;64 /** Total number of unallocated blocks. */65 uint32_t cBlocksUnallocated;66 /** Total number of unallocated inodes. */67 uint32_t cInodesUnallocated;68 /** Block number of block containing the superblock. */69 uint32_t iBlockOfSuperblock;70 /** Number of bits to shift 1024 to the left to get the block size */71 uint32_t cBitsShiftLeftBlockSize;72 /** Number of bits to shift 1024 to the left to get the fragment size */73 uint32_t cBitsShiftLeftFragmentSize;74 /** Number of blocks in each block group. */75 uint32_t cBlocksPerGroup;76 /** Number of fragments in each block group. */77 uint32_t cFragmentsPerBlockGroup;78 /** Number of inodes in each block group. */79 uint32_t cInodesPerBlockGroup;80 /** Last mount time. */81 uint32_t u32LastMountTime;82 /** Last written time. */83 uint32_t u32LastWrittenTime;84 /** Number of times the volume was mounted since the last check. */85 uint16_t cMountsSinceLastCheck;86 /** Number of mounts allowed before a consistency check. */87 uint16_t cMaxMountsUntilCheck;88 /** Signature to identify a ext2 volume. */89 uint16_t u16Signature;90 /** State of the filesystem (clean/errors) */91 uint16_t u16FilesystemState;92 /** What to do on an error. */93 uint16_t u16ActionOnError;94 /** Minor version field. */95 uint16_t u16VersionMinor;96 /** Time of last check. */97 uint32_t u32LastCheckTime;98 /** Interval between consistency checks. */99 uint32_t u32CheckInterval;100 /** Operating system ID of the filesystem creator. */101 uint32_t u32OsIdCreator;102 /** Major version field. */103 uint32_t u32VersionMajor;104 /** User ID that is allowed to use reserved blocks. */105 uint16_t u16UidReservedBlocks;106 /** Group ID that is allowed to use reserved blocks. */107 uint16_t u16GidReservedBlocks;108 /** Reserved fields. */109 uint8_t abReserved[940];110 } ExtSuperBlock;111 #pragma pack()112 AssertCompileSize(ExtSuperBlock, 1024);113 /** Pointer to an ext super block. */114 typedef ExtSuperBlock *PExtSuperBlock;115 116 /** Ext2 signature. */117 #define RTFILESYSTEM_EXT2_SIGNATURE (0xef53)118 /** Clean filesystem state. */119 #define RTFILESYSTEM_EXT2_STATE_CLEAN (0x0001)120 /** Error filesystem state. */121 #define RTFILESYSTEM_EXT2_STATE_ERRORS (0x0002)122 123 /**124 * Block group descriptor.125 */126 #pragma pack(1)127 typedef struct BlockGroupDesc128 {129 /** Block address of the block bitmap. */130 uint32_t offBlockBitmap;131 /** Block address of the inode bitmap. */132 uint32_t offInodeBitmap;133 /** Start block address of the inode table. */134 uint32_t offInodeTable;135 /** Number of unallocated blocks in group. */136 uint16_t cBlocksUnallocated;137 /** Number of unallocated inodes in group. */138 uint16_t cInodesUnallocated;139 /** Number of directories in the group. */140 uint16_t cDirectories;141 /** Padding. */142 uint16_t u16Padding;143 /** Reserved. */144 uint8_t abReserved[12];145 } BlockGroupDesc;146 #pragma pack()147 AssertCompileSize(BlockGroupDesc, 32);148 /** Pointer to an ext block group descriptor. */149 typedef BlockGroupDesc *PBlockGroupDesc;150 151 46 /** 152 47 * Cached block group descriptor data. … … 187 82 188 83 189 /*********************************************************************************************************************************190 * Methods *191 *********************************************************************************************************************************/192 84 193 85 /** … … 203 95 PRTFILESYSTEMEXTBLKGRP pBlkGrpDesc = pThis->pBlkGrpDesc; 204 96 uint64_t offRead = (pThis->iSbBlock + 1) * pThis->cbBlock; 205 BlockGroupDescBlkDesc;97 EXT2BLOCKGROUPDESC BlkDesc; 206 98 size_t cbBlockBitmap; 207 99 … … 232 124 } 233 125 234 static bool rtFsExtIsBlockRangeInUse(PRTFILESYSTEMEXTBLKGRP pBlkGrpDesc, 235 uint32_t offBlockStart, size_t cBlocks) 126 static bool rtFsExtIsBlockRangeInUse(PRTFILESYSTEMEXTBLKGRP pBlkGrpDesc, uint32_t offBlockStart, size_t cBlocks) 236 127 { 237 128 bool fUsed = false; … … 256 147 257 148 258 static DECLCALLBACK(int) rtFsExtProbe(RTVFSFILE hVfsFile, uint32_t *puScore)259 {260 int rc = VINF_SUCCESS;261 uint64_t cbMedium = 0;262 263 *puScore = RTFILESYSTEM_MATCH_SCORE_UNSUPPORTED;264 265 rc = RTVfsFileGetSize(hVfsFile, &cbMedium);266 if (RT_SUCCESS(rc))267 {268 if (cbMedium >= 2*sizeof(ExtSuperBlock))269 {270 ExtSuperBlock SuperBlock;271 272 rc = RTVfsFileReadAt(hVfsFile, 1024, &SuperBlock, sizeof(ExtSuperBlock), NULL);273 if (RT_SUCCESS(rc))274 {275 #if defined(RT_BIGENDIAN)276 /** @todo Convert to host endianess. */277 #endif278 if (SuperBlock.u16Signature == RTFILESYSTEM_EXT2_SIGNATURE)279 *puScore = RTFILESYSTEM_MATCH_SCORE_SUPPORTED;280 }281 }282 }283 284 return rc;285 }286 287 static DECLCALLBACK(int) rtFsExtInit(void *pvThis, RTVFSFILE hVfsFile)288 {289 int rc = VINF_SUCCESS;290 PRTFILESYSTEMEXT pThis = (PRTFILESYSTEMEXT)pvThis;291 ExtSuperBlock SuperBlock;292 293 pThis->hVfsFile = hVfsFile;294 pThis->pBlkGrpDesc = NULL;295 296 rc = RTVfsFileReadAt(hVfsFile, 1024, &SuperBlock, sizeof(ExtSuperBlock), NULL);297 if (RT_SUCCESS(rc))298 {299 #if defined(RT_BIGENDIAN)300 /** @todo Convert to host endianess. */301 #endif302 if (SuperBlock.u16FilesystemState == RTFILESYSTEM_EXT2_STATE_ERRORS)303 rc = VERR_FILESYSTEM_CORRUPT;304 else305 {306 pThis->iSbBlock = SuperBlock.iBlockOfSuperblock;307 pThis->cbBlock = 1024 << SuperBlock.cBitsShiftLeftBlockSize;308 pThis->cBlocksPerGroup = SuperBlock.cBlocksPerGroup;309 pThis->cBlockGroups = SuperBlock.cBlocksTotal / pThis->cBlocksPerGroup;310 311 /* Load first block group descriptor. */312 rc = rtFsExtLoadBlkGrpDesc(pThis, 0);313 }314 }315 316 return rc;317 }318 319 320 149 /** 321 150 * @interface_method_impl{RTVFSOBJOPS::Obj,pfnClose} 322 151 */ 323 static DECLCALLBACK(int) rtFsExt Vol_Close(void *pvThis)152 static DECLCALLBACK(int) rtFsExt2Vol_Close(void *pvThis) 324 153 { 325 154 PRTFILESYSTEMEXT pThis = (PRTFILESYSTEMEXT)pvThis; … … 335 164 * @interface_method_impl{RTVFSOBJOPS::Obj,pfnQueryInfo} 336 165 */ 337 static DECLCALLBACK(int) rtFsExt Vol_QueryInfo(void *pvThis, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr)166 static DECLCALLBACK(int) rtFsExt2Vol_QueryInfo(void *pvThis, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr) 338 167 { 339 168 RT_NOREF(pvThis, pObjInfo, enmAddAttr); … … 342 171 343 172 344 static DECLCALLBACK(int) rtFsExtOpenRoot(void *pvThis, PRTVFSDIR phVfsDir) 173 /** 174 * @interface_method_impl{RTVFSOBJOPS::Obj,pfnOpenRoot} 175 */ 176 static DECLCALLBACK(int) rtFsExt2_OpenRoot(void *pvThis, PRTVFSDIR phVfsDir) 345 177 { 346 178 NOREF(pvThis); … … 349 181 } 350 182 351 static DECLCALLBACK(int) rtFsExtIsRangeInUse(void *pvThis, RTFOFF off, size_t cb, 352 bool *pfUsed) 183 184 /** 185 * @interface_method_impl{RTVFSOBJOPS::Obj,pfnIsRangeInUse} 186 */ 187 static DECLCALLBACK(int) rtFsExt2_IsRangeInUse(void *pvThis, RTFOFF off, size_t cb, bool *pfUsed) 353 188 { 354 189 int rc = VINF_SUCCESS; … … 394 229 395 230 396 DECL_HIDDEN_CONST(RTFILESYSTEMDESC) const g_rtFsExt = 397 { 398 /* .cbFs = */ sizeof(RTFILESYSTEMEXT), 399 /* .VfsOps = */ 400 { 401 /* .Obj = */ 231 DECL_HIDDEN_CONST(const RTVFSOPS) g_rtFsExt2VolOps = 232 { 233 /* .Obj = */ 234 { 235 /* .uVersion = */ RTVFSOBJOPS_VERSION, 236 /* .enmType = */ RTVFSOBJTYPE_VFS, 237 /* .pszName = */ "Ext2Vol", 238 /* .pfnClose = */ rtFsExt2Vol_Close, 239 /* .pfnQueryInfo = */ rtFsExt2Vol_QueryInfo, 240 /* .uEndMarker = */ RTVFSOBJOPS_VERSION 241 }, 242 /* .uVersion = */ RTVFSOPS_VERSION, 243 /* .fFeatures = */ 0, 244 /* .pfnOpenRoot = */ rtFsExt2_OpenRoot, 245 /* .pfnIsRangeInUse = */ rtFsExt2_IsRangeInUse, 246 /* .uEndMarker = */ RTVFSOPS_VERSION 247 }; 248 249 250 RTDECL(int) RTFsExt2VolOpen(RTVFSFILE hVfsFileIn, uint32_t fMntFlags, uint32_t fExtFlags, PRTVFS phVfs, PRTERRINFO pErrInfo) 251 { 252 AssertPtrReturn(phVfs, VERR_INVALID_POINTER); 253 AssertReturn(!(fMntFlags & RTVFSMNT_F_VALID_MASK), VERR_INVALID_FLAGS); 254 AssertReturn(!fExtFlags, VERR_INVALID_FLAGS); 255 256 uint32_t cRefs = RTVfsFileRetain(hVfsFileIn); 257 AssertReturn(cRefs != UINT32_MAX, VERR_INVALID_HANDLE); 258 259 PRTFILESYSTEMEXT pThis; 260 int rc = RTVfsNew(&g_rtFsExt2VolOps, sizeof(*pThis), NIL_RTVFS, RTVFSLOCK_CREATE_RW, phVfs, (void **)&pThis); 261 if (RT_SUCCESS(rc)) 262 { 263 pThis->hVfsFile = hVfsFileIn; 264 pThis->pBlkGrpDesc = NULL; 265 266 EXT2SUPERBLOCK SuperBlock; 267 rc = RTVfsFileReadAt(hVfsFileIn, 1024, &SuperBlock, sizeof(EXT2SUPERBLOCK), NULL); 268 if (RT_SUCCESS(rc)) 402 269 { 403 /* .uVersion = */ RTVFSOBJOPS_VERSION, 404 /* .enmType = */ RTVFSOBJTYPE_VFS, 405 /* .pszName = */ "ExtVol", 406 /* .pfnClose = */ rtFsExtVol_Close, 407 /* .pfnQueryInfo = */ rtFsExtVol_QueryInfo, 408 /* .uEndMarker = */ RTVFSOBJOPS_VERSION 409 }, 410 /* .uVersion = */ RTVFSOPS_VERSION, 411 /* .fFeatures = */ 0, 412 /* .pfnOpenRoot = */ rtFsExtOpenRoot, 413 /* .pfnIsRangeInUse = */ rtFsExtIsRangeInUse, 414 /* .uEndMarker = */ RTVFSOPS_VERSION 415 }, 416 /* .pfnProbe = */ rtFsExtProbe, 417 /* .pfnInit = */ rtFsExtInit 418 }; 419 270 #if defined(RT_BIGENDIAN) 271 /** @todo Convert to host endianess. */ 272 #endif 273 if (SuperBlock.u16FilesystemState == EXT2_STATE_ERRORS) 274 rc = RTERRINFO_LOG_SET(pErrInfo, VERR_FILESYSTEM_CORRUPT, "EXT2_STATE_ERRORS"); 275 else 276 { 277 pThis->iSbBlock = SuperBlock.iBlockOfSuperblock; 278 pThis->cbBlock = 1024 << SuperBlock.cBitsShiftLeftBlockSize; 279 pThis->cBlocksPerGroup = SuperBlock.cBlocksPerGroup; 280 pThis->cBlockGroups = SuperBlock.cBlocksTotal / pThis->cBlocksPerGroup; 281 282 /* Load first block group descriptor. */ 283 rc = rtFsExtLoadBlkGrpDesc(pThis, 0); 284 } 285 if (RT_SUCCESS(rc)) 286 { 287 return VINF_SUCCESS; 288 } 289 } 290 else 291 rc = RTERRINFO_LOG_SET(pErrInfo, rc, "Error reading super block"); 292 293 RTVfsRelease(*phVfs); 294 *phVfs = NIL_RTVFS; 295 } 296 else 297 RTVfsFileRelease(hVfsFileIn); 298 299 return rc; 300 } 301
Note:
See TracChangeset
for help on using the changeset viewer.