Changeset 66693 in vbox for trunk/src/VBox/Storage/testcase
- Timestamp:
- Apr 27, 2017 2:47:05 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/testcase/vbox-img.cpp
r66250 r66693 26 26 #include <iprt/asm.h> 27 27 #include <iprt/buildconfig.h> 28 #include <iprt/fsvfs.h> 28 29 #include <iprt/path.h> 29 30 #include <iprt/string.h> … … 37 38 #include <iprt/vfs.h> 38 39 40 41 /********************************************************************************************************************************* 42 * Global Variables * 43 *********************************************************************************************************************************/ 39 44 static const char *g_pszProgName = ""; 45 46 47 40 48 static void printUsage(PRTSTREAM pStrm) 41 49 { … … 76 84 " [--dataalignment <alignment in bytes>]\n" 77 85 "\n" 86 " createfloppy --filename <filename>\n" 87 " [--size <size in bytes>]\n" 88 " [--root-dir-entries <value>]\n" 89 " [--sector-size <bytes>]\n" 90 " [--heads <value>]\n" 91 " [--sectors-per-track <count>]\n" 92 " [--media-byte <byte>]\n" 93 "\n" 78 94 " repair --filename <filename>\n" 79 95 " [--dry-run]\n" … … 1908 1924 1909 1925 1926 static int handleCreateFloppy(HandlerArg *a) 1927 { 1928 const char *pszFilename = NULL; 1929 uint64_t cbFloppy = 1474560; 1930 uint16_t cbSector = 0; 1931 uint8_t cHeads = 0; 1932 uint8_t cSectorsPerCluster = 0; 1933 uint8_t cSectorsPerTrack = 0; 1934 uint16_t cRootDirEntries = 0; 1935 uint8_t bMedia = 0; 1936 1937 /* Parse the command line. */ 1938 static const RTGETOPTDEF s_aOptions[] = 1939 { 1940 { "--sectors-per-cluster", 'c', RTGETOPT_REQ_UINT8 }, 1941 { "--filename", 'f', RTGETOPT_REQ_STRING }, 1942 { "--heads", 'h', RTGETOPT_REQ_UINT8 }, 1943 { "--media-byte", 'm', RTGETOPT_REQ_UINT8 }, 1944 { "--root-dir-entries", 'r', RTGETOPT_REQ_UINT16 }, 1945 { "--size", 's', RTGETOPT_REQ_UINT64 }, 1946 { "--sector-size", 'S', RTGETOPT_REQ_UINT16 }, 1947 { "--sectors-per-track", 't', RTGETOPT_REQ_UINT8 }, 1948 }; 1949 int ch; 1950 RTGETOPTUNION ValueUnion; 1951 RTGETOPTSTATE GetState; 1952 RTGetOptInit(&GetState, a->argc, a->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0, RTGETOPTINIT_FLAGS_OPTS_FIRST); 1953 while ((ch = RTGetOpt(&GetState, &ValueUnion))) 1954 { 1955 switch (ch) 1956 { 1957 case 'c': cSectorsPerCluster = ValueUnion.u8; break; 1958 case 'f': pszFilename = ValueUnion.psz; break; 1959 case 'h': cHeads = ValueUnion.u8; break; 1960 case 'm': bMedia = ValueUnion.u8; break; 1961 case 'r': cRootDirEntries = ValueUnion.u16; break; 1962 case 's': cbFloppy = ValueUnion.u64; break; 1963 case 'S': cbSector = ValueUnion.u16; break; 1964 case 't': cSectorsPerTrack = ValueUnion.u8; break; 1965 1966 default: 1967 ch = RTGetOptPrintError(ch, &ValueUnion); 1968 printUsage(g_pStdErr); 1969 return ch; 1970 } 1971 } 1972 1973 /* Check for mandatory parameters. */ 1974 if (!pszFilename) 1975 return errorSyntax("Mandatory --filename option missing\n"); 1976 1977 /* 1978 * Do the job. 1979 */ 1980 uint32_t offError; 1981 RTERRINFOSTATIC ErrInfo; 1982 RTVFSFILE hVfsFile; 1983 int rc = RTVfsChainOpenFile(pszFilename, 1984 RTFILE_O_WRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_ALL 1985 | (0770 << RTFILE_O_CREATE_MODE_SHIFT), 1986 &hVfsFile, &offError, RTErrInfoInitStatic(&ErrInfo)); 1987 if (RT_SUCCESS(rc)) 1988 { 1989 rc = RTFsFatVolFormat(hVfsFile, 0, cbFloppy, RTFSFATVOL_FMT_F_FULL, cbSector, cSectorsPerCluster, RTFSFATTYPE_INVALID, 1990 cHeads, cSectorsPerTrack, bMedia, 0 /*cHiddenSectors*/, cRootDirEntries, 1991 RTErrInfoInitStatic(&ErrInfo)); 1992 RTVfsFileRelease(hVfsFile); 1993 if (RT_SUCCESS(rc)) 1994 return RTEXITCODE_SUCCESS; 1995 1996 if (RTErrInfoIsSet(&ErrInfo.Core)) 1997 errorRuntime("Error %Rrc formatting floppy '%s': %s", rc, pszFilename, ErrInfo.Core.pszMsg); 1998 else 1999 errorRuntime("Error formatting floppy '%s': %Rrc", pszFilename, rc); 2000 } 2001 else 2002 RTVfsChainMsgError("RTVfsChainOpenFile", pszFilename, rc, offError, &ErrInfo.Core); 2003 return RTEXITCODE_FAILURE; 2004 } 2005 2006 1910 2007 static int handleClearResize(HandlerArg *a) 1911 2008 { … … 2069 2166 { "createcache", handleCreateCache }, 2070 2167 { "createbase", handleCreateBase }, 2168 { "createfloppy", handleCreateFloppy }, 2071 2169 { "repair", handleRepair }, 2072 2170 { "clearcomment", handleClearComment },
Note:
See TracChangeset
for help on using the changeset viewer.