VirtualBox

Changeset 63786 in vbox for trunk


Ignore:
Timestamp:
Sep 9, 2016 10:06:48 PM (8 years ago)
Author:
vboxsync
Message:

Storage/DMG: Cleanup, get rid of goto ...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Storage/DMG.cpp

    r63785 r63786  
    20472047    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
    20482048
    2049     AssertPtr(pThis);
    2050 
    2051     if (pThis)
    2052         return 1;
    2053     else
    2054         return 0;
     2049    AssertPtrReturn(pThis, 0);
     2050
     2051    return 1;
    20552052}
    20562053
     
    20602057    LogFlowFunc(("pBackendData=%#p\n", pBackendData));
    20612058    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
     2059
     2060    AssertPtrReturn(pThis, 0);
     2061
    20622062    uint32_t cb = 0;
    2063 
    2064     AssertPtr(pThis);
    2065 
    2066     if (pThis && (pThis->pStorage || pThis->hDmgFileInXar != NIL_RTVFSFILE))
     2063    if (pThis->pStorage || pThis->hDmgFileInXar != NIL_RTVFSFILE)
    20672064        cb = 2048;
    20682065
     
    20762073    LogFlowFunc(("pBackendData=%#p\n", pBackendData));
    20772074    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
     2075
     2076    AssertPtrReturn(pThis, 0);
     2077
    20782078    uint64_t cb = 0;
    2079 
    2080     AssertPtr(pThis);
    2081 
    2082     if (pThis && (pThis->pStorage || pThis->hDmgFileInXar != NIL_RTVFSFILE))
     2079    if (pThis->pStorage || pThis->hDmgFileInXar != NIL_RTVFSFILE)
    20832080        cb = pThis->cbSize;
    20842081
     
    20922089    LogFlowFunc(("pBackendData=%#p\n", pBackendData));
    20932090    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
    2094     uint64_t cb = 0;
    2095 
    2096     AssertPtr(pThis);
    2097 
    2098     if (pThis && (pThis->pStorage || pThis->hDmgFileInXar != NIL_RTVFSFILE))
    2099     {
    2100         uint64_t cbFile;
     2091
     2092    AssertPtrReturn(pThis, 0);
     2093
     2094    uint64_t cbFile = 0;
     2095    if (pThis->pStorage || pThis->hDmgFileInXar != NIL_RTVFSFILE)
     2096    {
    21012097        int rc = dmgWrapFileGetSize(pThis, &cbFile);
    2102         if (RT_SUCCESS(rc))
    2103             cb = cbFile;
    2104     }
    2105 
    2106     LogFlowFunc(("returns %lld\n", cb));
    2107     return cb;
     2098        if (RT_FAILURE(rc))
     2099            cbFile = 0; /* Make sure it is 0 */
     2100    }
     2101
     2102    LogFlowFunc(("returns %lld\n", cbFile));
     2103    return cbFile;
    21082104}
    21092105
     
    21132109    LogFlowFunc(("pBackendData=%#p pPCHSGeometry=%#p\n", pBackendData, pPCHSGeometry));
    21142110    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
    2115     int rc;
    2116 
    2117     AssertPtr(pThis);
    2118 
    2119     if (pThis)
    2120     {
    2121         if (pThis->PCHSGeometry.cCylinders)
    2122         {
    2123             *pPCHSGeometry = pThis->PCHSGeometry;
    2124             rc = VINF_SUCCESS;
    2125         }
    2126         else
    2127             rc = VERR_VD_GEOMETRY_NOT_SET;
    2128     }
     2111    int rc = VINF_SUCCESS;
     2112
     2113    AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
     2114
     2115    if (pThis->PCHSGeometry.cCylinders)
     2116        *pPCHSGeometry = pThis->PCHSGeometry;
    21292117    else
    2130         rc = VERR_VD_NOT_OPENED;
     2118        rc = VERR_VD_GEOMETRY_NOT_SET;
    21312119
    21322120    LogFlowFunc(("returns %Rrc (PCHS=%u/%u/%u)\n", rc, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
     
    21402128                 pBackendData, pPCHSGeometry, pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, pPCHSGeometry->cSectors));
    21412129    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
    2142     int rc;
    2143 
    2144     AssertPtr(pThis);
    2145 
    2146     if (pThis)
    2147     {
    2148         if (!(pThis->uOpenFlags & VD_OPEN_FLAGS_READONLY))
    2149         {
    2150             pThis->PCHSGeometry = *pPCHSGeometry;
    2151             rc = VINF_SUCCESS;
    2152         }
    2153         else
    2154             rc = VERR_VD_IMAGE_READ_ONLY;
    2155     }
     2130    int rc = VINF_SUCCESS;
     2131
     2132    AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
     2133
     2134    if (pThis->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     2135        rc = VERR_VD_IMAGE_READ_ONLY;
    21562136    else
    2157         rc = VERR_VD_NOT_OPENED;
     2137        pThis->PCHSGeometry = *pPCHSGeometry;
    21582138
    21592139    LogFlowFunc(("returns %Rrc\n", rc));
     
    21642144static DECLCALLBACK(int) dmgGetLCHSGeometry(void *pBackendData, PVDGEOMETRY pLCHSGeometry)
    21652145{
    2166      LogFlowFunc(("pBackendData=%#p pLCHSGeometry=%#p\n", pBackendData, pLCHSGeometry));
     2146    LogFlowFunc(("pBackendData=%#p pLCHSGeometry=%#p\n", pBackendData, pLCHSGeometry));
    21672147    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
    2168     int rc;
    2169 
    2170     AssertPtr(pThis);
    2171 
    2172     if (pThis)
    2173     {
    2174         if (pThis->LCHSGeometry.cCylinders)
    2175         {
    2176             *pLCHSGeometry = pThis->LCHSGeometry;
    2177             rc = VINF_SUCCESS;
    2178         }
    2179         else
    2180             rc = VERR_VD_GEOMETRY_NOT_SET;
    2181     }
     2148    int rc = VINF_SUCCESS;
     2149
     2150    AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
     2151
     2152    if (pThis->LCHSGeometry.cCylinders)
     2153        *pLCHSGeometry = pThis->LCHSGeometry;
    21822154    else
    2183         rc = VERR_VD_NOT_OPENED;
     2155        rc = VERR_VD_GEOMETRY_NOT_SET;
    21842156
    21852157    LogFlowFunc(("returns %Rrc (LCHS=%u/%u/%u)\n", rc, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
     
    21932165                 pBackendData, pLCHSGeometry, pLCHSGeometry->cCylinders, pLCHSGeometry->cHeads, pLCHSGeometry->cSectors));
    21942166    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
    2195     int rc;
    2196 
    2197     AssertPtr(pThis);
    2198 
    2199     if (pThis)
    2200     {
    2201         if (!(pThis->uOpenFlags & VD_OPEN_FLAGS_READONLY))
    2202         {
    2203             pThis->LCHSGeometry = *pLCHSGeometry;
    2204             rc = VINF_SUCCESS;
    2205         }
    2206         else
    2207             rc = VERR_VD_IMAGE_READ_ONLY;
    2208     }
     2167    int rc = VINF_SUCCESS;
     2168
     2169    AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
     2170
     2171    if (pThis->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     2172        rc = VERR_VD_IMAGE_READ_ONLY;
    22092173    else
    2210         rc = VERR_VD_NOT_OPENED;
     2174        pThis->LCHSGeometry = *pLCHSGeometry;
    22112175
    22122176    LogFlowFunc(("returns %Rrc\n", rc));
     
    22192183    LogFlowFunc(("pBackendData=%#p\n", pBackendData));
    22202184    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
    2221     unsigned uImageFlags;
    2222 
    2223     AssertPtr(pThis);
    2224 
    2225     if (pThis)
    2226         uImageFlags = pThis->uImageFlags;
    2227     else
    2228         uImageFlags = 0;
    2229 
    2230     LogFlowFunc(("returns %#x\n", uImageFlags));
    2231     return uImageFlags;
     2185    AssertPtrReturn(pThis, 0);
     2186
     2187    LogFlowFunc(("returns %#x\n", pThis->uImageFlags));
     2188    return pThis->uImageFlags;
    22322189}
    22332190
     
    22372194    LogFlowFunc(("pBackendData=%#p\n", pBackendData));
    22382195    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
    2239     unsigned uOpenFlags;
    2240 
    2241     AssertPtr(pThis);
    2242 
    2243     if (pThis)
    2244         uOpenFlags = pThis->uOpenFlags;
    2245     else
    2246         uOpenFlags = 0;
    2247 
    2248     LogFlowFunc(("returns %#x\n", uOpenFlags));
    2249     return uOpenFlags;
     2196
     2197    AssertPtrReturn(pThis, 0);
     2198
     2199    LogFlowFunc(("returns %#x\n", pThis->uOpenFlags));
     2200    return pThis->uOpenFlags;
    22502201}
    22512202
     
    22552206    LogFlowFunc(("pBackendData=%#p\n uOpenFlags=%#x", pBackendData, uOpenFlags));
    22562207    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
    2257     int rc;
     2208    int rc = VINF_SUCCESS;
    22582209
    22592210    /* Image must be opened and the new flags must be valid. */
     
    22612212                                  | VD_OPEN_FLAGS_SHAREABLE | VD_OPEN_FLAGS_SEQUENTIAL
    22622213                                  | VD_OPEN_FLAGS_SKIP_CONSISTENCY_CHECKS)))
    2263     {
    22642214        rc = VERR_INVALID_PARAMETER;
    2265         goto out;
    2266     }
    2267 
    2268     /* Implement this operation via reopening the image. */
    2269     rc = dmgFreeImage(pThis, false);
    2270     if (RT_FAILURE(rc))
    2271         goto out;
    2272     rc = dmgOpenImage(pThis, uOpenFlags);
    2273 
    2274 out:
     2215    else
     2216    {
     2217        /* Implement this operation via reopening the image. */
     2218        rc = dmgFreeImage(pThis, false);
     2219        if (RT_SUCCESS(rc))
     2220            rc = dmgOpenImage(pThis, uOpenFlags);
     2221    }
     2222
    22752223    LogFlowFunc(("returns %Rrc\n", rc));
    22762224    return rc;
     
    22832231    LogFlowFunc(("pBackendData=%#p pszComment=%#p cbComment=%zu\n", pBackendData, pszComment, cbComment));
    22842232    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
    2285     int rc;
    2286 
    2287     AssertPtr(pThis);
    2288 
    2289     if (pThis)
    2290         rc = VERR_NOT_SUPPORTED;
    2291     else
    2292         rc = VERR_VD_NOT_OPENED;
    2293 
    2294     LogFlowFunc(("returns %Rrc comment='%s'\n", rc, pszComment));
    2295     return rc;
     2233
     2234    AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
     2235
     2236    LogFlowFunc(("returns %Rrc comment='%s'\n", VERR_NOT_SUPPORTED, pszComment));
     2237    return VERR_NOT_SUPPORTED;
    22962238}
    22972239
     
    23012243    RT_NOREF1(pszComment);
    23022244    LogFlowFunc(("pBackendData=%#p pszComment=\"%s\"\n", pBackendData, pszComment));
    2303     PDMGIMAGE pImage = (PDMGIMAGE)pBackendData;
     2245    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
     2246
     2247    AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
     2248
    23042249    int rc;
    2305 
    2306     AssertPtr(pImage);
    2307 
    2308     if (pImage)
    2309     {
    2310         if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
    2311             rc = VERR_VD_IMAGE_READ_ONLY;
    2312         else
    2313             rc = VERR_NOT_SUPPORTED;
    2314     }
     2250    if (pThis->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     2251        rc = VERR_VD_IMAGE_READ_ONLY;
    23152252    else
    2316         rc = VERR_VD_NOT_OPENED;
     2253        rc = VERR_NOT_SUPPORTED;
    23172254
    23182255    LogFlowFunc(("returns %Rrc\n", rc));
     
    23262263    LogFlowFunc(("pBackendData=%#p pUuid=%#p\n", pBackendData, pUuid));
    23272264    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
    2328     int rc;
    2329 
    2330     AssertPtr(pThis);
    2331 
    2332     if (pThis)
    2333         rc = VERR_NOT_SUPPORTED;
    2334     else
    2335         rc = VERR_VD_NOT_OPENED;
    2336 
    2337     LogFlowFunc(("returns %Rrc (%RTuuid)\n", rc, pUuid));
    2338     return rc;
     2265
     2266    AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
     2267
     2268    LogFlowFunc(("returns %Rrc (%RTuuid)\n", VERR_NOT_SUPPORTED, pUuid));
     2269    return VERR_NOT_SUPPORTED;
    23392270}
    23402271
     
    23452276    LogFlowFunc(("pBackendData=%#p Uuid=%RTuuid\n", pBackendData, pUuid));
    23462277    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
     2278
     2279    AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
     2280
    23472281    int rc;
    2348 
    2349     LogFlowFunc(("%RTuuid\n", pUuid));
    2350     AssertPtr(pThis);
    2351 
    2352     if (pThis)
    2353     {
    2354         if (!(pThis->uOpenFlags & VD_OPEN_FLAGS_READONLY))
    2355             rc = VERR_NOT_SUPPORTED;
    2356         else
    2357             rc = VERR_VD_IMAGE_READ_ONLY;
    2358     }
     2282    if (pThis->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     2283        rc = VERR_VD_IMAGE_READ_ONLY;
    23592284    else
    2360         rc = VERR_VD_NOT_OPENED;
     2285        rc = VERR_NOT_SUPPORTED;
    23612286
    23622287    LogFlowFunc(("returns %Rrc\n", rc));
     
    23702295    LogFlowFunc(("pBackendData=%#p pUuid=%#p\n", pBackendData, pUuid));
    23712296    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
    2372     int rc;
    2373 
    2374     AssertPtr(pThis);
    2375 
    2376     if (pThis)
    2377         rc = VERR_NOT_SUPPORTED;
    2378     else
    2379         rc = VERR_VD_NOT_OPENED;
    2380 
    2381     LogFlowFunc(("returns %Rrc (%RTuuid)\n", rc, pUuid));
    2382     return rc;
     2297
     2298    AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
     2299
     2300    LogFlowFunc(("returns %Rrc (%RTuuid)\n", VERR_NOT_SUPPORTED, pUuid));
     2301    return VERR_NOT_SUPPORTED;
    23832302}
    23842303
     
    23892308    LogFlowFunc(("pBackendData=%#p Uuid=%RTuuid\n", pBackendData, pUuid));
    23902309    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
     2310
     2311    AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
     2312
    23912313    int rc;
    2392 
    2393     AssertPtr(pThis);
    2394 
    2395     if (pThis)
    2396     {
    2397         if (!(pThis->uOpenFlags & VD_OPEN_FLAGS_READONLY))
    2398             rc = VERR_NOT_SUPPORTED;
    2399         else
    2400             rc = VERR_VD_IMAGE_READ_ONLY;
    2401     }
     2314    if (pThis->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     2315        rc = VERR_VD_IMAGE_READ_ONLY;
    24022316    else
    2403         rc = VERR_VD_NOT_OPENED;
     2317        rc = VERR_NOT_SUPPORTED;
    24042318
    24052319    LogFlowFunc(("returns %Rrc\n", rc));
     
    24132327    LogFlowFunc(("pBackendData=%#p pUuid=%#p\n", pBackendData, pUuid));
    24142328    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
    2415     int rc;
    2416 
    2417     AssertPtr(pThis);
    2418 
    2419     if (pThis)
    2420         rc = VERR_NOT_SUPPORTED;
    2421     else
    2422         rc = VERR_VD_NOT_OPENED;
    2423 
    2424     LogFlowFunc(("returns %Rrc (%RTuuid)\n", rc, pUuid));
    2425     return rc;
     2329
     2330    AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
     2331
     2332    LogFlowFunc(("returns %Rrc (%RTuuid)\n", VERR_NOT_SUPPORTED, pUuid));
     2333    return VERR_NOT_SUPPORTED;
    24262334}
    24272335
     
    24322340    LogFlowFunc(("pBackendData=%#p Uuid=%RTuuid\n", pBackendData, pUuid));
    24332341    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
     2342
     2343    AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
     2344
    24342345    int rc;
    2435 
    2436     AssertPtr(pThis);
    2437 
    2438     if (pThis)
    2439     {
    2440         if (!(pThis->uOpenFlags & VD_OPEN_FLAGS_READONLY))
    2441             rc = VERR_NOT_SUPPORTED;
    2442         else
    2443             rc = VERR_VD_IMAGE_READ_ONLY;
    2444     }
     2346    if (pThis->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     2347        rc = VERR_VD_IMAGE_READ_ONLY;
    24452348    else
    2446         rc = VERR_VD_NOT_OPENED;
     2349        rc = VERR_NOT_SUPPORTED;
    24472350
    24482351    LogFlowFunc(("returns %Rrc\n", rc));
     
    24562359    LogFlowFunc(("pBackendData=%#p pUuid=%#p\n", pBackendData, pUuid));
    24572360    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
     2361
     2362    AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
     2363
    24582364    int rc;
    2459 
    2460     AssertPtr(pThis);
    2461 
    2462     if (pThis)
     2365    if (pThis->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     2366        rc = VERR_VD_IMAGE_READ_ONLY;
     2367    else
    24632368        rc = VERR_NOT_SUPPORTED;
    2464     else
    2465         rc = VERR_VD_NOT_OPENED;
    24662369
    24672370    LogFlowFunc(("returns %Rrc (%RTuuid)\n", rc, pUuid));
     
    24752378    LogFlowFunc(("pBackendData=%#p Uuid=%RTuuid\n", pBackendData, pUuid));
    24762379    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
     2380
     2381    AssertPtrReturn(pThis, VERR_VD_NOT_OPENED);
     2382
    24772383    int rc;
    2478 
    2479     AssertPtr(pThis);
    2480 
    2481     if (pThis)
    2482     {
    2483         if (!(pThis->uOpenFlags & VD_OPEN_FLAGS_READONLY))
    2484             rc = VERR_NOT_SUPPORTED;
    2485         else
    2486             rc = VERR_VD_IMAGE_READ_ONLY;
    2487     }
     2384    if (pThis->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     2385        rc = VERR_VD_IMAGE_READ_ONLY;
    24882386    else
    2489         rc = VERR_VD_NOT_OPENED;
     2387        rc = VERR_NOT_SUPPORTED;
    24902388
    24912389    LogFlowFunc(("returns %Rrc\n", rc));
     
    24982396    PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
    24992397
    2500     AssertPtr(pThis);
    2501     if (pThis)
    2502     {
    2503         vdIfErrorMessage(pThis->pIfError, "Header: Geometry PCHS=%u/%u/%u LCHS=%u/%u/%u cSectors=%llu\n",
    2504                          pThis->PCHSGeometry.cCylinders, pThis->PCHSGeometry.cHeads, pThis->PCHSGeometry.cSectors,
    2505                          pThis->LCHSGeometry.cCylinders, pThis->LCHSGeometry.cHeads, pThis->LCHSGeometry.cSectors,
    2506                          pThis->cbSize / DMG_SECTOR_SIZE);
    2507     }
     2398    AssertPtrReturnVoid(pThis);
     2399    vdIfErrorMessage(pThis->pIfError, "Header: Geometry PCHS=%u/%u/%u LCHS=%u/%u/%u cSectors=%llu\n",
     2400                     pThis->PCHSGeometry.cCylinders, pThis->PCHSGeometry.cHeads, pThis->PCHSGeometry.cSectors,
     2401                     pThis->LCHSGeometry.cCylinders, pThis->LCHSGeometry.cHeads, pThis->LCHSGeometry.cSectors,
     2402                     pThis->cbSize / DMG_SECTOR_SIZE);
    25082403}
    25092404
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette