[UDFS]
[reactos.git] / reactos / drivers / filesystems / udfs / udf_info / extent.cpp
index 99768c0..2ffa31d 100644 (file)
@@ -1,6 +1,7 @@
 ////////////////////////////////////////////////////////////////////
 // Copyright (C) Alexander Telyatnikov, Ivan Keliukh, Yegor Anchishkin, SKIF Software, 1999-2013. Kiev, Ukraine
 // All rights reserved
+// This file was released under the GPLv2 on June 2015.
 ////////////////////////////////////////////////////////////////////
 /*
         Module name:
@@ -85,10 +86,12 @@ UDFNextExtentToLba(
 {
 //    uint32 Lba;
 
-    uint32 l, d;
+    uint32 l;
+//    uint32 d;
 
     // scan extent table for suitable range (frag)
-    d = (l = (Extent->extLength & UDF_EXTENT_LENGTH_MASK));
+//    d = (l = (Extent->extLength & UDF_EXTENT_LENGTH_MASK));
+    l = (Extent->extLength & UDF_EXTENT_LENGTH_MASK);
 
     if(!l) {
         (*Index) = -1;
@@ -119,7 +122,7 @@ UDFLocateLbaInExtent(
     uint32 l, BSh = Vcb->BlockSizeBits;
     uint32 i=0;
 
-    while(l = ((Extent->extLength & UDF_EXTENT_LENGTH_MASK) >> BSh)) {
+    while((l = ((Extent->extLength & UDF_EXTENT_LENGTH_MASK) >> BSh))) {
 
         if(Extent->extLocation   >= lba &&
            Extent->extLocation+l <  lba) {
@@ -143,8 +146,7 @@ UDFGetExtentLength(
     if(!Extent) return 0;
     int64 i=0;
 
-//#ifdef _X86_
-#ifdef _MSC_VER
+#if defined (_X86_) && defined (_MSC_VER)
 
     __asm push  ebx
     __asm push  ecx
@@ -225,8 +227,7 @@ UDFGetMappingLength(
     if(!Extent) return 0;
     uint32 i=0;
 
-//#ifdef _X86_
-#ifdef _MSC_VER
+#if defined (_X86_) && defined (_MSC_VER)
     __asm push  ebx
 
     __asm mov   ebx,Extent
@@ -299,7 +300,8 @@ UDFShortAllocDescToMapping(
     OUT PEXTENT_INFO AllocLoc
     )
 {
-    uint32 i, lim, l, len, BSh, type;
+    uint32 i, lim, l, len, type;
+//    uint32 BSh;
     PEXTENT_MAP Extent, Extent2, AllocMap;
     EXTENT_AD AllocExt;
     PALLOC_EXT_DESC NextAllocDesc;
@@ -313,7 +315,7 @@ UDFShortAllocDescToMapping(
     if(SubCallCount > ALLOC_DESC_MAX_RECURSE) return NULL;
 
     locAddr.partitionReferenceNum = (uint16)PartNum;
-    BSh = Vcb->BlockSizeBits;
+//    BSh = Vcb->BlockSizeBits;
     l = ((lim = (AllocDescLength/sizeof(SHORT_AD))) + 1 ) * sizeof(EXTENT_AD);
     Extent = (PEXTENT_MAP)MyAllocatePoolTag__(NonPagedPool, l, MEM_EXTMAP_TAG);
     if(!Extent) return NULL;
@@ -460,7 +462,8 @@ UDFLongAllocDescToMapping(
     OUT PEXTENT_INFO AllocLoc // .Mapping must be intialized (non-Zero)
     )
 {
-    uint32 i, lim, l, len, BSh, type;
+    uint32 i, lim, l, len, type;
+//    uint32 BSh;
     PEXTENT_MAP Extent, Extent2, AllocMap;
     EXTENT_AD AllocExt;
     PALLOC_EXT_DESC NextAllocDesc;
@@ -471,7 +474,7 @@ UDFLongAllocDescToMapping(
 
     if(SubCallCount > ALLOC_DESC_MAX_RECURSE) return NULL;
 
-    BSh = Vcb->BlockSizeBits;
+//    BSh = Vcb->BlockSizeBits;
     l = ((lim = (AllocDescLength/sizeof(LONG_AD))) + 1 ) * sizeof(EXTENT_AD);
     Extent = (PEXTENT_MAP)MyAllocatePoolTag__(NonPagedPool, l, MEM_EXTMAP_TAG);
     if(!Extent) return NULL;
@@ -597,7 +600,8 @@ UDFExtAllocDescToMapping(
     OUT PEXTENT_INFO AllocLoc // .Mapping must be intialized (non-Zero)
     )
 {
-    uint32 i, lim, l, len, BSh, type;
+    uint32 i, lim, l, len, type;
+//    uint32 BSh;
     PEXTENT_MAP Extent, Extent2, AllocMap;
     EXTENT_AD AllocExt;
     PALLOC_EXT_DESC NextAllocDesc;
@@ -608,7 +612,7 @@ UDFExtAllocDescToMapping(
 
     if(SubCallCount > ALLOC_DESC_MAX_RECURSE) return NULL;
 
-    BSh = Vcb->BlockSizeBits;
+//    BSh = Vcb->BlockSizeBits;
     l = ((lim = (AllocDescLength/sizeof(EXT_AD))) + 1 ) * sizeof(EXTENT_AD);
     Extent = (PEXTENT_MAP)MyAllocatePoolTag__(NonPagedPool, l, MEM_EXTMAP_TAG);
     if(!Extent) return NULL;
@@ -851,7 +855,7 @@ UDFBuildShortAllocDescs(
     ValidateFileInfo(FileInfo);
     ExtPrint(("UDFBuildShortAllocDescs: FE %x\n", FileInfo->Dloc->FELoc.Mapping[0].extLocation));
     // calculate length
-    for(len=0; i=(Extent[len].extLength & UDF_EXTENT_LENGTH_MASK); len++, ph_len+=i) {
+    for(len=0; (i=(Extent[len].extLength & UDF_EXTENT_LENGTH_MASK)); len++, ph_len+=i) {
         ExtPrint(("bShExt: type %x, loc %x, len %x\n",
             Extent[len].extLength >> 30, Extent[len].extLocation, Extent[len].extLength & UDF_EXTENT_LENGTH_MASK));
     }
@@ -1038,7 +1042,7 @@ UDFBuildLongAllocDescs(
     ExtPrint(("UDFBuildLongAllocDescs: FE %x\n", FileInfo->Dloc->FELoc.Mapping[0].extLocation));
     // calculate length
     //for(len=0; i=(Extent[len].extLength & UDF_EXTENT_LENGTH_MASK); len++, ph_len+=i);
-    for(len=0; i=(Extent[len].extLength & UDF_EXTENT_LENGTH_MASK); len++, ph_len+=i) {
+    for(len=0; (i=(Extent[len].extLength & UDF_EXTENT_LENGTH_MASK)); len++, ph_len+=i) {
         ExtPrint(("bLnExt: type %x, loc %x, len %x\n",
             Extent[len].extLength >> 30, Extent[len].extLocation, Extent[len].extLength & UDF_EXTENT_LENGTH_MASK));
     }
@@ -1748,7 +1752,7 @@ UDFFreeFESpace(
                 j = i;
             }
         }
-        if(j != -1) {
+        if(j != (ULONG)-1) {
             i = j;
             Ext->Mapping[i].extLocation = Lba;
             Ext->Mapping[i].extLength   = Vcb->LBlockSize | (EXTENT_NOT_RECORDED_ALLOCATED << 30);
@@ -1827,7 +1831,7 @@ UDFMarkAllocatedAsRecorded(
     // I don't know what else comment can be added here.
     // Just belive that it works
     lba = UDFExtentOffsetToLba(Vcb, ExtInfo->Mapping, (Offset & ~((int64)LBS-1)), NULL, NULL, NULL, &i);
-    if(i == -1) return STATUS_INVALID_PARAMETER;
+    if(i == (ULONG)-1) return STATUS_INVALID_PARAMETER;
 #ifdef UDF_DBG
     check_size = UDFGetExtentLength(ExtInfo->Mapping);
     ASSERT(!(check_size & (LBS-1)));
@@ -1856,7 +1860,9 @@ UDFMarkAllocatedAsRecorded(
             UDFPackMapping(Vcb, ExtInfo);
         }
         AdPrint(("Alloc->Rec (1) new %x\n", ExtInfo->Mapping));
+#ifdef UDF_DBG
         ASSERT(check_size == UDFGetExtentLength(ExtInfo->Mapping));
+#endif
         AdPrint(("Alloc->Rec: ExtInfo %x, Extent %x\n", ExtInfo, ExtInfo->Mapping));
         return STATUS_SUCCESS;
     }
@@ -1924,8 +1930,10 @@ UDFMarkAllocatedAsRecorded(
     ExtInfo->Mapping = NewExtent;
     if(TryPack)
         UDFPackMapping(Vcb, ExtInfo);
+#ifdef UDF_DBG
     ASSERT(check_size == UDFGetExtentLength(ExtInfo->Mapping));
     ASSERT(!(check_size & (LBS-1)));
+#endif
 
     AdPrint(("Alloc->Rec: ExtInfo %x, Extent %x\n", ExtInfo, ExtInfo->Mapping));
 
@@ -1961,7 +1969,7 @@ UDFMarkNotAllocatedAsAllocated(
 #endif
     AdPrint(("Not->Alloc  ExtInfo %x, Extent %x\n", ExtInfo, Extent));
     UDFExtentOffsetToLba(Vcb, ExtInfo->Mapping, Offset, NULL, NULL, NULL, &i);
-    if(i == -1) return STATUS_INVALID_PARAMETER;
+    if(i == (ULONG)-1) return STATUS_INVALID_PARAMETER;
     if((Extent[i].extLength >> 30) != EXTENT_NOT_RECORDED_NOT_ALLOCATED) return STATUS_SUCCESS;
 
     uint32 PartNum = UDFGetPartNumByPhysLba(Vcb, Extent[0].extLocation);
@@ -2119,7 +2127,7 @@ UDFMarkAllocatedAsNotXXX(
 
     DeadMapping[0].extLocation =
         UDFExtentOffsetToLba(Vcb, ExtInfo->Mapping, Offset, NULL, NULL, NULL, &i);
-    if(i == -1) {
+    if(i == (ULONG)-1) {
         BrutePoint();
         return STATUS_INVALID_PARAMETER;
     }
@@ -2619,7 +2627,7 @@ UDFBuildAllocDescs(
     OUT int8** AllocData
     )
 {
-    PEXTENT_MAP InMap;
+//    PEXTENT_MAP InMap;
 //    uint32 i=0;
     int8* Allocs;
     uint16 AllocMode;
@@ -2636,7 +2644,7 @@ UDFBuildAllocDescs(
         return STATUS_INSUFFICIENT_RESOURCES;
     }
     RtlZeroMemory(Allocs, InitSz);
-    InMap = FileInfo->Dloc->DataLoc.Mapping;
+//    InMap = FileInfo->Dloc->DataLoc.Mapping;
     UDFCheckSpaceAllocation(Vcb, 0, InMap, AS_USED); // check if used
 
     // TODO: move data from mapped locations here
@@ -2824,8 +2832,10 @@ UDFPackMapping(
     NewMap[j].extLength =
     NewMap[j].extLocation = 0;
 
+#ifdef UDF_DBG
     ASSERT(check_size == UDFGetExtentLength(ExtInfo->Mapping));
     ASSERT(check_size == UDFGetExtentLength(NewMap));
+#endif
 
     AdPrint(("Pack ExtInfo %x, NewMap %x, OldMap %x\n", ExtInfo, NewMap, OldMap));
     
@@ -2859,7 +2869,7 @@ UDFUnPackMapping(
 
     j=0;
     d = LBS >> Vcb->BlockSizeBits;
-    for(i=0; l = (Mapping[i].extLength & UDF_EXTENT_LENGTH_MASK); i++) {
+    for(i=0; (l = (Mapping[i].extLength & UDF_EXTENT_LENGTH_MASK)); i++) {
         base = Mapping[i].extLocation;
         type = Mapping[i].extLength & UDF_EXTENT_FLAG_MASK;
         for(; l>=(LONG)LBS; j++) {
@@ -2911,7 +2921,7 @@ UDFIsExtentCached(
     PEXTENT_MAP Extent = ExtInfo->Mapping;   // Extent array
     uint32 to_read, Lba, sect_offs, flags, i;
 
-    WCacheStartDirect__(&(Vcb->FastCache), Vcb, TRUE/*FALSE/*ForWrite*/);
+    WCacheStartDirect__(&(Vcb->FastCache), Vcb, TRUE/*FALSE*//*ForWrite*/);
     if(!ExtInfo || !ExtInfo->Mapping) goto EO_IsCached;
     if(!Length) {
         retstat = TRUE;
@@ -3077,7 +3087,7 @@ UDFReadExtentLocation(
     int32 SubExtInfoSz = *_SubExtInfoSz;
     int64 Length;
     int64 NextOffset;
-    OSSTATUS status = STATUS_BUFFER_OVERFLOW;
+//    OSSTATUS status = STATUS_BUFFER_OVERFLOW;
 
     (*_SubExtInfo) = NULL;
     (*_SubExtInfoSz) = 0;
@@ -3120,7 +3130,7 @@ UDFReadExtentLocation(
         // prepare for reading next frag...
         Length -= to_read;
         if(!Length) {
-            status = STATUS_SUCCESS;
+//            status = STATUS_SUCCESS;
             break;
         }
         ASSERT(to_read);
@@ -3131,8 +3141,10 @@ UDFReadExtentLocation(
     return STATUS_SUCCESS;
 } // end UDFReadExtentLocation()
 
+#ifdef _MSC_VER
 #pragma warning(push)               
 #pragma warning(disable:4035)               // re-enable below
+#endif
 
 uint32
 UDFGetZeroLength(
@@ -3149,7 +3161,9 @@ UDFGetZeroLength(
     return Length*sizeof(uint32);
 }
 
+#ifdef _MSC_VER
 #pragma warning(pop) // re-enable warning #4035
+#endif
 
 #ifndef UDF_READ_ONLY_BUILD
 /*