ReactOS 0.4.15-dev-7788-g1ad9096
udf_info.h File Reference
#include "ecma_167.h"
#include "osta_misc.h"
#include "udf_rel.h"
#include "wcache.h"
Include dependency graph for udf_info.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define HASH_POSIX   0x01
 
#define HASH_ULFN   0x02
 
#define HASH_DOS   0x04
 
#define HASH_ALL   0x07
 
#define HASH_KEEP_NAME   0x08
 
#define UDFExtentToMapping(e)   UDFExtentToMapping_(e)
 
#define UDFDOSName__(Vcb, DosName, UdfName, FileInfo)    UDFDOSName(Vcb, DosName, UdfName, (FileInfo) && ((FileInfo)->Index < 2));
 
#define UDFCheckSpaceAllocation(Vcb, FileInfo, Map, asXXX)   {;}
 
#define UDFMarkSpaceAsXXXNoProtect(Vcb, FileInfo, Map, asXXX)    UDFMarkSpaceAsXXXNoProtect_(Vcb, Map, asXXX);
 
#define UDFMarkSpaceAsXXX(Vcb, FileInfo, Map, asXXX)    UDFMarkSpaceAsXXX_(Vcb, Map, asXXX);
 
#define AS_FREE   0x00
 
#define AS_USED   0x01
 
#define AS_DISCARDED   0x02
 
#define AS_BAD   0x04
 
#define UDFAllocFreeExtent(v, l, ss, sl, e, af)   UDFAllocFreeExtent_(v, l, ss, sl, e, af)
 
#define UDF_PREALLOC_CLASS_FE   0x00
 
#define UDF_PREALLOC_CLASS_DIR   0x01
 
#define FLUSH_FE_KEEP   FALSE
 
#define FLUSH_FE_FOR_DEL   TRUE
 
#define UDF_FSPACE_BM   0x00
 
#define UDF_ZSPACE_BM   0x01
 
#define UDFMarkAllocatedAsNotAllocated(Vcb, Off, Len, Ext)    UDFMarkAllocatedAsNotXXX(Vcb, Off, Len, Ext, TRUE)
 
#define UDFMarkRecordedAsAllocated(Vcb, Off, Len, Ext)    UDFMarkAllocatedAsNotXXX(Vcb, Off, Len, Ext, FALSE)
 
#define UDFZeroExtent__(Vcb, Ext, Off, Len, Dir, WB)    UDFZeroExtent(Vcb, Ext, Off, Len, FALSE, Dir, WB)
 
#define UDFSparseExtent__(Vcb, Ext, Off, Len, Dir, WB)    UDFZeroExtent(Vcb, Ext, Off, Len, TRUE, Dir, WB)
 
#define UDFIncFileLinkCount(fi)   UDFChangeFileLinkCount(fi, TRUE)
 
#define UDFDecFileLinkCount(fi)   UDFChangeFileLinkCount(fi, FALSE)
 
#define UDFSetEntityID_imp(eID, Str)    UDFSetEntityID_imp_(eID, (uint8*)(Str), sizeof(Str));
 
#define UDFIncFileCounter(Vcb)   UDFChangeFileCounter(Vcb, TRUE, TRUE);
 
#define UDFDecFileCounter(Vcb)   UDFChangeFileCounter(Vcb, TRUE, FALSE);
 
#define UDFIncDirCounter(Vcb)   UDFChangeFileCounter(Vcb, FALSE, TRUE);
 
#define UDFDecDirCounter(Vcb)   UDFChangeFileCounter(Vcb, FALSE, FALSE);
 
#define UDF_FREE_NOTHING   0x00
 
#define UDF_FREE_FILEINFO   0x01
 
#define UDF_FREE_DLOC   0x02
 
#define UDFIsDeleted(DirNdx)    (((DirNdx)->FileCharacteristics & FILE_DELETED) ? TRUE : FALSE)
 
#define UDFIsADirectory(FileInfo)    (((FileInfo) && ((FileInfo)->Dloc) && ((FileInfo)->Dloc->DirIndex || ((FileInfo)->FileIdent && ((FileInfo)->FileIdent->fileCharacteristics & FILE_DIRECTORY)))) ? TRUE : FALSE)
 
#define UDFGetFileAllocationSize(Vcb, FileInfo)    (((FileInfo)->Dloc->DataLoc.Mapping) ? UDFGetExtentLength((FileInfo)->Dloc->DataLoc.Mapping) : Vcb->LBlockSize)
 
#define UDFIsFlushed(FI)
 
#define UDFIsFileCached__(Vcb, FileInfo, Offset, Length, ForWrite)    (UDFIsExtentCached(Vcb, &((FileInfo)->Dloc->DataLoc), Offset, Length, ForWrite))
 
#define UDFGetLVIDiUse(Vcb)
 
#define UDFIsAStreamDir(FI)   ((FI) && ((FI)->Dloc) && ((FI)->Dloc->FE_Flags & UDF_FE_FLAG_IS_SDIR))
 
#define UDFHasAStreamDir(FI)   ((FI) && ((FI)->Dloc) && ((FI)->Dloc->FE_Flags & UDF_FE_FLAG_HAS_SDIR))
 
#define UDFIsAStream(FI)   ((FI) && UDFIsAStreamDir((FI)->ParentFile))
 
#define UDFIsSDirDeleted(FI)   ((FI) && (FI)->Dloc && ((FI)->Dloc->FE_Flags & UDF_FE_FLAG_IS_DEL_SDIR))
 
#define UDFGetPartNumByPartNdx(Vcb, pi)   (Vcb->Partitions[pi].PartitionNum)
 
#define UDFStreamsSupported(Vcb)    (Vcb->maxUDFWriteRev >= 0x0200)
 
#define UDFNtAclSupported(Vcb)    (Vcb->maxUDFWriteRev >= 0x0200)
 
#define UDFReferenceFile__(fi)
 
#define UDFReferenceFileEx__(fi, i)
 
#define UDFDereferenceFile__(fi)
 
#define UDFIsDirEmpty__(fi)   UDFIsDirEmpty((fi)->Dloc->DirIndex)
 
#define UDFIsDirOpened__(fi)   (fi->OpenCount)
 
#define UDFSetFileAllocMode__(fi, mode)
 
#define UDFGetFileAllocMode__(fi)   ((fi)->Dloc->DataLoc.Flags & EXTENT_FLAG_ALLOC_MASK)
 
#define UDFGetFileICBAllocMode__(fi)   (((PFILE_ENTRY)((fi)->Dloc->FileEntry))->icbTag.flags & ICB_FLAG_ALLOC_MASK)
 
#define UDF_DIR_INDEX_FRAME_SH   9
 
#define UDF_DIR_INDEX_FRAME   ((uint_di)(1 << UDF_DIR_INDEX_FRAME_SH))
 
#define UDF_DIR_INDEX_FRAME_GRAN   (32)
 
#define UDF_DIR_INDEX_FRAME_GRAN_MASK   (UDF_DIR_INDEX_FRAME_GRAN-1)
 
#define AlignDirIndex(n)   ((n+UDF_DIR_INDEX_FRAME_GRAN_MASK) & ~(UDF_DIR_INDEX_FRAME_GRAN_MASK))
 
#define UDFDirIndexGetLastIndex(di)   ((((di)->FrameCount - 1) << UDF_DIR_INDEX_FRAME_SH) + (di)->LastFrameCount)
 
#define UDFGetBit(arr, bit)   ( (BOOLEAN) ( ((((uint32*)(arr))[(bit)>>5]) >> ((bit)&31)) &1 ) )
 
#define UDFSetBit(arr, bit)   ( (((uint32*)(arr))[(bit)>>5]) |= (((uint32)1) << ((bit)&31)) )
 
#define UDFClrBit(arr, bit)   ( (((uint32*)(arr))[(bit)>>5]) &= (~(((uint32)1) << ((bit)&31))) )
 
#define UDFSetBits(arr, bit, bc)
 
#define UDFClrBits(arr, bit, bc)
 
#define UDFGetUsedBit(arr, bit)   (!UDFGetBit(arr,bit))
 
#define UDFGetFreeBit(arr, bit)   UDFGetBit(arr,bit)
 
#define UDFSetUsedBit(arr, bit)   UDFClrBit(arr,bit)
 
#define UDFSetFreeBit(arr, bit)   UDFSetBit(arr,bit)
 
#define UDFSetUsedBits(arr, bit, bc)   UDFClrBits(arr,bit,bc)
 
#define UDFSetFreeBits(arr, bit, bc)   UDFSetBits(arr,bit,bc)
 
#define UDFGetBadBit(arr, bit)   UDFGetBit(arr,bit)
 
#define UDFGetZeroBit(arr, bit)   UDFGetBit(arr,bit)
 
#define UDFSetZeroBit(arr, bit)   UDFSetBit(arr,bit)
 
#define UDFClrZeroBit(arr, bit)   UDFClrBit(arr,bit)
 
#define UDFSetZeroBits(arr, bit, bc)   UDFSetBits(arr,bit,bc)
 
#define UDFClrZeroBits(arr, bit, bc)   UDFClrBits(arr,bit,bc)
 
#define UDFSetFreeBitOwner(Vcb, i)
 
#define UDFSetUsedBitOwner(Vcb, i, o)
 
#define UDFCheckUsedBitOwner(Vcb, i, o)
 
#define UDFCheckFreeBitOwner(Vcb, i)
 
#define UDFRegisterFsStructure(Vcb, Lba, Length)   {NOTHING;}
 
#define UDF_MAX_VERIFY_CACHE   (8*1024*1024/2048)
 
#define UDF_VERIFY_CACHE_LOW   (4*1024*1024/2048)
 
#define UDF_VERIFY_CACHE_GRAN   (512*1024/2048)
 
#define UDF_SYS_CACHE_STOP_THR   (10*1024*1024/2048)
 
#define PH_FORGET_VERIFIED   0x00800000
 
#define PH_READ_VERIFY_CACHE   0x00400000
 
#define PH_KEEP_VERIFY_CACHE   0x00200000
 
#define UFD_VERIFY_FLAG_FORCE   0x01
 
#define UFD_VERIFY_FLAG_WAIT   0x02
 
#define UFD_VERIFY_FLAG_BG   0x04
 
#define UFD_VERIFY_FLAG_LOCKED   0x10
 

Functions

uint32 UDFMemRealloc (IN int8 *OldBuff, IN uint32 OldLength, OUT int8 **NewBuff, IN uint32 NewLength)
 
uint32 UDFExtentOffsetToLba (IN PVCB Vcb, IN PEXTENT_AD Extent, IN int64 Offset, OUT uint32 *SectorOffset, OUT PSIZE_T AvailLength, OUT uint32 *Flags, OUT uint32 *Index)
 
ULONG UDFLocateLbaInExtent (IN PVCB Vcb, IN PEXTENT_MAP Extent, IN lba_t lba)
 
OSSTATUS UDFReadExtent (IN PVCB Vcb, IN PEXTENT_INFO ExtInfo, IN int64 Offset, IN SIZE_T Length, IN BOOLEAN Direct, OUT int8 *Buffer, OUT PSIZE_T ReadBytes)
 
OSSTATUS UDFReadExtentLocation (IN PVCB Vcb, IN PEXTENT_INFO ExtInfo, IN int64 Offset, OUT PEXTENT_MAP *_SubExtInfo, IN OUT uint32 *_SubExtInfoSz, OUT int64 *_NextOffset)
 
int64 UDFGetExtentLength (IN PEXTENT_MAP Extent)
 
void __fastcall UDFDecompressUnicode (IN OUT PUNICODE_STRING UName, IN uint8 *CS0, IN SIZE_T Length, OUT uint16 *valueCRC)
 
uint8 UDFBuildHashEntry (IN PVCB Vcb, IN PUNICODE_STRING Name, OUT PHASH_ENTRY hashes, IN uint8 Mask)
 
PDIR_INDEX_ITEM UDFDirIndexGetFrame (IN PDIR_INDEX_HDR hDirNdx, IN uint32 Frame, OUT uint32 *FrameLen, OUT uint_di *Index, IN uint_di Rel)
 
void UDFDirIndexFree (PDIR_INDEX_HDR hDirNdx)
 
OSSTATUS UDFDirIndexGrow (IN PDIR_INDEX_HDR *_hDirNdx, IN uint_di d)
 
OSSTATUS UDFDirIndexTrunc (IN PDIR_INDEX_HDR *_hDirNdx, IN uint_di d)
 
BOOLEAN UDFDirIndexInitScan (IN PUDF_FILE_INFO DirInfo, OUT PUDF_DIR_SCAN_CONTEXT Context, IN uint_di Index)
 
PDIR_INDEX_ITEM UDFDirIndexScan (PUDF_DIR_SCAN_CONTEXT Context, PUDF_FILE_INFO *_FileInfo)
 
OSSTATUS UDFIndexDirectory (IN PVCB Vcb, IN OUT PUDF_FILE_INFO FileInfo)
 
OSSTATUS UDFFindFile (IN PVCB Vcb, IN BOOLEAN IgnoreCase, IN BOOLEAN NotDeleted, IN PUNICODE_STRING Name, IN PUDF_FILE_INFO DirInfo, IN OUT uint_di *Index)
 
__inline OSSTATUS UDFFindFile__ (IN PVCB Vcb, IN BOOLEAN IgnoreCase, IN PUNICODE_STRING Name, IN PUDF_FILE_INFO DirInfo)
 
uint32 UDFGetMappingLength (IN PEXTENT_MAP Extent)
 
PEXTENT_MAP __fastcall UDFMergeMappings (IN PEXTENT_MAP Extent, IN PEXTENT_MAP Extent2)
 
PEXTENT_MAP UDFShortAllocDescToMapping (IN PVCB Vcb, IN uint32 PartNum, IN PLONG_AD AllocDesc, IN uint32 AllocDescLength, IN uint32 SubCallCount, OUT PEXTENT_INFO AllocLoc)
 
PEXTENT_MAP UDFLongAllocDescToMapping (IN PVCB Vcb, IN PLONG_AD AllocDesc, IN uint32 AllocDescLength, IN uint32 SubCallCount, OUT PEXTENT_INFO AllocLoc)
 
PEXTENT_MAP UDFExtAllocDescToMapping (IN PVCB Vcb, IN PLONG_AD AllocDesc, IN uint32 AllocDescLength, IN uint32 SubCallCount, OUT PEXTENT_INFO AllocLoc)
 
PEXTENT_MAP UDFReadMappingFromXEntry (IN PVCB Vcb, IN uint32 PartNum, IN tag *XEntry, IN OUT uint32 *Offset, OUT PEXTENT_INFO AllocLoc)
 
OSSTATUS UDFReadFileEntry (IN PVCB Vcb, IN long_ad *Icb, IN OUT PFILE_ENTRY FileEntry, IN OUT uint16 *Ident)
 
OSSTATUS UDFFindLastFileSet (IN PVCB Vcb, IN lb_addr *Addr, IN OUT PFILE_SET_DESC FileSetDesc)
 
OSSTATUS UDFLoadSparingTable (IN PVCB Vcb, IN PSPARABLE_PARTITION_MAP PartMap)
 
PEXTENT_MAP __fastcall UDFExtentToMapping_ (IN PEXTENT_AD Extent)
 
OSSTATUS __fastcall UDFRemapPacket (IN PVCB Vcb, IN uint32 Lba, IN BOOLEAN RemapSpared)
 
OSSTATUS __fastcall UDFUnmapRange (IN PVCB Vcb, IN uint32 Lba, IN uint32 BCount)
 
uint32 __fastcall UDFRelocateSector (IN PVCB Vcb, IN uint32 Lba)
 
BOOLEAN __fastcall UDFAreSectorsRelocated (IN PVCB Vcb, IN uint32 Lba, IN uint32 BlockCount)
 
PEXTENT_MAP __fastcall UDFRelocateSectors (IN PVCB Vcb, IN uint32 Lba, IN uint32 BlockCount)
 
BOOLEAN UDFUnicodeInString (IN uint8 *string, IN WCHAR ch)
 
BOOLEAN __fastcall UDFIsIllegalChar (IN WCHAR ch)
 
void __fastcall UDFDOSName (IN PVCB Vcb, IN OUT PUNICODE_STRING DosName, IN PUNICODE_STRING UdfName, IN BOOLEAN KeepIntact)
 
void __fastcall UDFDOSName201 (IN OUT PUNICODE_STRING DosName, IN PUNICODE_STRING UdfName, IN BOOLEAN KeepIntact)
 
void __fastcall UDFDOSName200 (IN OUT PUNICODE_STRING DosName, IN PUNICODE_STRING UdfName, IN BOOLEAN KeepIntact, IN BOOLEAN Mode150)
 
void __fastcall UDFDOSName100 (IN OUT PUNICODE_STRING DosName, IN PUNICODE_STRING UdfName, IN BOOLEAN KeepIntact)
 
SIZE_T UDFGetBitmapLen (uint32 *Bitmap, SIZE_T Offs, SIZE_T Lim)
 
SIZE_T UDFFindMinSuitableExtent (IN PVCB Vcb, IN uint32 Length, IN uint32 SearchStart, IN uint32 SearchLim, OUT uint32 *MaxExtLen, IN uint8 AllocFlags)
 
void UDFMarkSpaceAsXXXNoProtect_ (IN PVCB Vcb, IN PEXTENT_MAP Map, IN uint32 asXXX)
 
void UDFMarkSpaceAsXXX_ (IN PVCB Vcb, IN PEXTENT_MAP Map, IN uint32 asXXX)
 
OSSTATUS UDFAllocFreeExtent_ (IN PVCB Vcb, IN int64 Length, IN uint32 SearchStart, IN uint32 SearchLim, OUT PEXTENT_INFO Extent, IN uint8 AllocFlags)
 
uint32 __fastcall UDFGetPartFreeSpace (IN PVCB Vcb, IN uint32 partNum)
 
OSSTATUS UDFGetCachedAllocation (IN PVCB Vcb, IN uint32 ParentLocation, OUT PEXTENT_INFO Ext, OUT uint32 *Items, IN uint32 AllocClass)
 
OSSTATUS UDFStoreCachedAllocation (IN PVCB Vcb, IN uint32 ParentLocation, IN PEXTENT_INFO Ext, IN uint32 Items, IN uint32 AllocClass)
 
OSSTATUS UDFFlushAllCachedAllocations (IN PVCB Vcb, IN uint32 AllocClass)
 
OSSTATUS UDFAllocateFESpace (IN PVCB Vcb, IN PUDF_FILE_INFO DirInfo, IN uint32 PartNum, IN PEXTENT_INFO FEExtInfo, IN uint32 Len)
 
void UDFFreeFESpace (IN PVCB Vcb, IN PUDF_FILE_INFO DirInfo, IN PEXTENT_INFO FEExtInfo)
 
void UDFFlushFESpace (IN PVCB Vcb, IN PUDF_DATALOC_INFO Dloc, IN BOOLEAN Discard=FLUSH_FE_KEEP)
 
void UDFFreeFileAllocation (IN PVCB Vcb, IN PUDF_FILE_INFO DirInfo, IN PUDF_FILE_INFO FileInfo)
 
uint32 UDFPhysLbaToPart (IN PVCB Vcb, IN uint32 PartNum, IN uint32 Addr)
 
void UDFSetUpTag (IN PVCB Vcb, IN tag *Tag, IN uint16 DataLen, IN uint32 TagLoc)
 
OSSTATUS UDFBuildShortAllocDescs (IN PVCB Vcb, IN uint32 PartNum, OUT int8 **Buff, IN uint32 InitSz, IN OUT PUDF_FILE_INFO FileInfo)
 
OSSTATUS UDFBuildLongAllocDescs (IN PVCB Vcb, IN uint32 PartNum, OUT int8 **Buff, IN uint32 InitSz, IN OUT PUDF_FILE_INFO FileInfo)
 
OSSTATUS UDFBuildFileEntry (IN PVCB Vcb, IN PUDF_FILE_INFO DirInfo, IN PUDF_FILE_INFO FileInfo, IN uint32 PartNum, IN uint16 AllocMode, IN uint32 ExtAttrSz, IN BOOLEAN Extended)
 
uint32 __fastcall UDFGetPartNumByPhysLba (IN PVCB Vcb, IN uint32 Lba)
 
OSSTATUS UDFAddXSpaceBitmap (IN PVCB Vcb, IN uint32 PartNum, IN PSHORT_AD bm, IN ULONG bm_type)
 
OSSTATUS UDFDelXSpaceBitmap (IN PVCB Vcb, IN uint32 PartNum, IN PSHORT_AD bm)
 
OSSTATUS UDFBuildFreeSpaceBitmap (IN PVCB Vcb, IN uint32 PartNdx, IN PPARTITION_HEADER_DESC phd, IN uint32 Lba)
 
OSSTATUS UDFLoadExtInfo (IN PVCB Vcb, IN PFILE_ENTRY fe, IN PLONG_AD fe_loc, IN OUT PEXTENT_INFO FExtInfo, IN OUT PEXTENT_INFO AExtInfo)
 
void __fastcall UDFCompressUnicode (IN PUNICODE_STRING UName, IN OUT uint8 **_CS0, IN OUT PSIZE_T Length)
 
OSSTATUS UDFBuildFileIdent (IN PVCB Vcb, IN PUNICODE_STRING fn, IN PLONG_AD FileEntryIcb, IN uint32 ImpUseLen, OUT PFILE_IDENT_DESC *_FileId, OUT uint32 *FileIdLen)
 
OSSTATUS UDFMarkAllocatedAsRecorded (IN PVCB Vcb, IN int64 Offset, IN uint32 Length, IN PEXTENT_INFO ExtInfo)
 
OSSTATUS UDFMarkNotAllocatedAsAllocated (IN PVCB Vcb, IN int64 Offset, IN uint32 Length, IN PEXTENT_INFO ExtInfo)
 
OSSTATUS UDFMarkAllocatedAsNotXXX (IN PVCB Vcb, IN int64 Offset, IN uint32 Length, IN PEXTENT_INFO ExtInfo, IN BOOLEAN Deallocate)
 
OSSTATUS UDFWriteExtent (IN PVCB Vcb, IN PEXTENT_INFO ExtInfo, IN int64 Offset, IN SIZE_T Length, IN BOOLEAN Direct, IN int8 *Buffer, OUT PSIZE_T WrittenBytes)
 
OSSTATUS UDFZeroExtent (IN PVCB Vcb, IN PEXTENT_INFO ExtInfo, IN int64 Offset, IN SIZE_T Length, IN BOOLEAN Deallocate, IN BOOLEAN Direct, OUT PSIZE_T WrittenBytes)
 
uint32 __fastcall UDFPartStart (PVCB Vcb, uint32 PartNum)
 
uint32 __fastcall UDFPartEnd (PVCB Vcb, uint32 PartNum)
 
OSSTATUS UDFResizeExtent (IN PVCB Vcb, IN uint32 PartNum, IN int64 Length, IN BOOLEAN AlwaysInIcb, OUT PEXTENT_INFO ExtInfo)
 
OSSTATUS UDFBuildAllocDescs (IN PVCB Vcb, IN uint32 PartNum, IN OUT PUDF_FILE_INFO FileInfo, OUT int8 **AllocData)
 
void UDFSetFileSize (IN PUDF_FILE_INFO FileInfo, IN int64 Size)
 
void UDFSetFileSizeInDirNdx (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN int64 *ASize)
 
int64 UDFGetFileSize (IN PUDF_FILE_INFO FileInfo)
 
int64 UDFGetFileSizeFromDirNdx (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
 
void UDFSetAllocDescLen (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
 
void UDFChangeFileLinkCount (IN PUDF_FILE_INFO FileInfo, IN BOOLEAN Increase)
 
void UDFSetEntityID_imp_ (IN EntityID *eID, IN uint8 *Str, IN uint32 Len)
 
uint16 UDFGetFileLinkCount (IN PUDF_FILE_INFO FileInfo)
 
void UDFReadEntityID_Domain (PVCB Vcb, EntityID *eID)
 
uint32 UDFGetFileEALength (IN PUDF_FILE_INFO FileInfo)
 
void UDFSetFileUID (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
 
int64 UDFGetFileUID (IN PUDF_FILE_INFO FileInfo)
 
void UDFChangeFileCounter (IN PVCB Vcb, IN BOOLEAN FileCounter, IN BOOLEAN Increase)
 
OSSTATUS UDFWriteFile__ (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN int64 Offset, IN SIZE_T Length, IN BOOLEAN Direct, IN int8 *Buffer, OUT PSIZE_T WrittenBytes)
 
OSSTATUS UDFUnlinkFile__ (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN BOOLEAN FreeSpace)
 
OSSTATUS UDFUnlinkAllFilesInDir (IN PVCB Vcb, IN PUDF_FILE_INFO DirInfo)
 
OSSTATUS UDFOpenFile__ (IN PVCB Vcb, IN BOOLEAN IgnoreCase, IN BOOLEAN NotDeleted, IN PUNICODE_STRING fn, IN PUDF_FILE_INFO DirInfo, OUT PUDF_FILE_INFO *_FileInfo, IN uint_di *IndexToOpen)
 
OSSTATUS UDFOpenRootFile__ (IN PVCB Vcb, IN lb_addr *RootLoc, OUT PUDF_FILE_INFO FileInfo)
 
uint32 UDFCleanUpFile__ (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
 
OSSTATUS UDFCreateFile__ (IN PVCB Vcb, IN BOOLEAN IgnoreCase, IN PUNICODE_STRING fn, IN uint32 ExtAttrSz, IN uint32 ImpUseLen, IN BOOLEAN Extended, IN BOOLEAN CreateNew, IN OUT PUDF_FILE_INFO DirInfo, OUT PUDF_FILE_INFO *_FileInfo)
 
__inline OSSTATUS UDFReadFile__ (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN int64 Offset, IN SIZE_T Length, IN BOOLEAN Direct, OUT int8 *Buffer, OUT PSIZE_T ReadBytes)
 
__inline OSSTATUS UDFReadFileLocation__ (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN int64 Offset, OUT PEXTENT_MAP *SubExtInfo, IN OUT uint32 *SubExtInfoSz, OUT int64 *NextOffset)
 
__inline OSSTATUS UDFZeroFile__ (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN int64 Offset, IN uint32 Length, IN BOOLEAN Direct, OUT uint32 *ReadBytes)
 
__inline OSSTATUS UDFSparseFile__ (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN int64 Offset, IN uint32 Length, IN BOOLEAN Direct, OUT uint32 *ReadBytes)
 
OSSTATUS UDFPadLastSector (IN PVCB Vcb, IN PEXTENT_INFO ExtInfo)
 
OSSTATUS UDFCloseFile__ (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
 
OSSTATUS UDFPrepareXSpaceBitmap (IN PVCB Vcb, IN OUT PSHORT_AD XSpaceBitmap, IN OUT PEXTENT_INFO XSBMExtInfo, IN OUT int8 **XSBM, IN OUT uint32 *XSl)
 
OSSTATUS UDFUpdateXSpaceBitmaps (IN PVCB Vcb, IN uint32 PartNum, IN PPARTITION_HEADER_DESC phd)
 
OSSTATUS UDFUpdatePartDesc (PVCB Vcb, int8 *Buf)
 
OSSTATUS UDFUpdateLogicalVolInt (PVCB Vcb, BOOLEAN Close)
 
OSSTATUS UDFUpdateUSpaceDesc (IN PVCB Vcb, int8 *Buf)
 
OSSTATUS UDFUpdateVDS (IN PVCB Vcb, IN uint32 block, IN uint32 lastblock, IN uint32 flags)
 
OSSTATUS UDFUmount__ (IN PVCB Vcb)
 
OSSTATUS UDFRenameMoveFile__ (IN PVCB Vcb, IN BOOLEAN IgnoreCase, IN OUT BOOLEAN *Replace, IN PUNICODE_STRING fn, IN OUT PUDF_FILE_INFO DirInfo1, IN OUT PUDF_FILE_INFO DirInfo2, IN OUT PUDF_FILE_INFO FileInfo)
 
OSSTATUS UDFResizeFile__ (IN PVCB Vcb, IN OUT PUDF_FILE_INFO FileInfo, IN int64 NewLength)
 
OSSTATUS UDFRecordDirectory__ (IN PVCB Vcb, IN OUT PUDF_FILE_INFO DirInfo)
 
OSSTATUS UDFPackDirectory__ (IN PVCB Vcb, IN OUT PUDF_FILE_INFO FileInfo)
 
OSSTATUS UDFReTagDirectory (IN PVCB Vcb, IN OUT PUDF_FILE_INFO FileInfo)
 
OSSTATUS UDFLoadVAT (IN PVCB Vcb, IN uint32 PartNdx)
 
int64 __fastcall UDFGetFreeSpace (IN PVCB Vcb)
 
int64 __fastcall UDFGetTotalSpace (IN PVCB Vcb)
 
PDIR_INDEX_HDR UDFGetDirIndexByFileInfo (IN PUDF_FILE_INFO FileInfo)
 
BOOLEAN UDFIsDirEmpty (IN PDIR_INDEX_HDR hCurDirNdx)
 
OSSTATUS UDFFlushFE (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN uint32 PartNum)
 
OSSTATUS UDFFlushFI (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN uint32 PartNum)
 
OSSTATUS UDFFlushFile__ (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN ULONG FlushFlags=0)
 
BOOLEAN UDFCompareFileInfo (IN PUDF_FILE_INFO f1, IN PUDF_FILE_INFO f2)
 
void __fastcall UDFPackMapping (IN PVCB Vcb, IN PEXTENT_INFO ExtInfo)
 
BOOLEAN UDFIsExtentCached (IN PVCB Vcb, IN PEXTENT_INFO ExtInfo, IN int64 Offset, IN uint32 Length, IN BOOLEAN ForWrite)
 
ULONG UDFIsBlockAllocated (IN void *_Vcb, IN uint32 Lba)
 
OSSTATUS UDFUpdateVolIdent (IN PVCB Vcb, IN UDF_VDS_RECORD Lba, IN PUNICODE_STRING VolIdent)
 
uint16 __fastcall UDFUnicodeCksum (PWCHAR s, uint32 n)
 
uint16 __fastcall UDFUnicodeCksum150 (PWCHAR s, uint32 n)
 
uint32 __fastcall crc32 (IN uint8 *s, IN uint32 len)
 
uint16 __fastcall UDFCrc (IN uint8 *Data, IN SIZE_T Size)
 
OSSTATUS UDFReadTagged (IN PVCB Vcb, IN int8 *Buf, IN uint32 Block, IN uint32 Location, OUT uint16 *Ident)
 
uint32 __fastcall UDFPartLbaToPhys (IN PVCB Vcb, IN lb_addr *Addr)
 
lba_t UDFFindAnchor (PVCB Vcb)
 
uint32 UDFFindVRS (PVCB Vcb)
 
void UDFLoadPVolDesc (PVCB Vcb, int8 *Buf)
 
OSSTATUS UDFLoadLogicalVolInt (PDEVICE_OBJECT DeviceObject, PVCB Vcb, extent_ad loc)
 
OSSTATUS UDFLoadLogicalVol (PDEVICE_OBJECT DeviceObject, PVCB Vcb, int8 *Buf, lb_addr *fileset)
 
OSSTATUS UDFLoadPartDesc (PVCB Vcb, int8 *Buf)
 
OSSTATUS UDFReadVDS (IN PVCB Vcb, IN uint32 block, IN uint32 lastblock, IN PUDF_VDS_RECORD vds, IN int8 *Buf)
 
OSSTATUS UDFProcessSequence (IN PDEVICE_OBJECT DeviceObject, IN PVCB Vcb, IN uint32 block, IN uint32 lastblock, OUT lb_addr *fileset)
 
OSSTATUS UDFVerifySequence (IN PDEVICE_OBJECT DeviceObject, IN PVCB Vcb, IN uint32 block, IN uint32 lastblock, OUT lb_addr *fileset)
 
void UDFLoadFileset (IN PVCB Vcb, IN PFILE_SET_DESC fset, OUT lb_addr *root, OUT lb_addr *sysstream)
 
OSSTATUS UDFLoadPartition (IN PDEVICE_OBJECT DeviceObject, IN PVCB Vcb, OUT lb_addr *fileset)
 
OSSTATUS UDFGetDiskInfoAndVerify (IN PDEVICE_OBJECT DeviceObject, IN PVCB Vcb)
 
OSSTATUS UDFHardLinkFile__ (IN PVCB Vcb, IN BOOLEAN IgnoreCase, IN OUT BOOLEAN *Replace, IN PUNICODE_STRING fn, IN OUT PUDF_FILE_INFO DirInfo1, IN OUT PUDF_FILE_INFO DirInfo2, IN OUT PUDF_FILE_INFO FileInfo)
 
LONG UDFFindDloc (IN PVCB Vcb, IN uint32 Lba)
 
LONG UDFFindFreeDloc (IN PVCB Vcb, IN uint32 Lba)
 
OSSTATUS UDFAcquireDloc (IN PVCB Vcb, IN PUDF_DATALOC_INFO Dloc)
 
OSSTATUS UDFReleaseDloc (IN PVCB Vcb, IN PUDF_DATALOC_INFO Dloc)
 
OSSTATUS UDFStoreDloc (IN PVCB Vcb, IN PUDF_FILE_INFO fi, IN uint32 Lba)
 
OSSTATUS UDFRemoveDloc (IN PVCB Vcb, IN PUDF_DATALOC_INFO Dloc)
 
OSSTATUS UDFUnlinkDloc (IN PVCB Vcb, IN PUDF_DATALOC_INFO Dloc)
 
void UDFFreeDloc (IN PVCB Vcb, IN PUDF_DATALOC_INFO Dloc)
 
void UDFRelocateDloc (IN PVCB Vcb, IN PUDF_DATALOC_INFO Dloc, IN uint32 NewLba)
 
void UDFReleaseDlocList (IN PVCB Vcb)
 
PUDF_FILE_INFO UDFLocateParallelFI (PUDF_FILE_INFO di, uint_di i, PUDF_FILE_INFO fi)
 
PUDF_FILE_INFO UDFLocateAnyParallelFI (PUDF_FILE_INFO fi)
 
void UDFInsertLinkedFile (PUDF_FILE_INFO fi, PUDF_FILE_INFO fi2)
 
OSSTATUS UDFCreateRootFile__ (IN PVCB Vcb, IN uint32 PartNum, IN uint32 ExtAttrSz, IN uint32 ImpUseLen, IN BOOLEAN Extended, OUT PUDF_FILE_INFO *_FileInfo)
 
OSSTATUS UDFCreateStreamDir__ (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, OUT PUDF_FILE_INFO *_SDirInfo)
 
OSSTATUS UDFOpenStreamDir__ (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, OUT PUDF_FILE_INFO *_SDirInfo)
 
OSSTATUS UDFRecordVAT (IN PVCB Vcb)
 
OSSTATUS UDFModifyVAT (IN PVCB Vcb, IN uint32 Lba, IN uint32 Length)
 
OSSTATUS UDFUpdateVAT (IN void *_Vcb, IN uint32 Lba, IN uint32 *RelocTab, IN uint32 BCount)
 
OSSTATUS __fastcall UDFUnPackMapping (IN PVCB Vcb, IN PEXTENT_INFO ExtInfo)
 
OSSTATUS UDFConvertFEToNonInICB (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN uint8 NewAllocMode)
 
OSSTATUS UDFConvertFEToExtended (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
 
uint32 __fastcall UDFPartLen (PVCB Vcb, uint32 PartNum)
 
OSSTATUS UDFPretendFileDeleted__ (IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
 
__inline PDIR_INDEX_ITEM UDFDirIndex (IN PDIR_INDEX_HDR hDirNdx, IN uint_di i)
 
OSSTATUS UDFVInit (IN PVCB Vcb)
 
VOID UDFVRelease (IN PVCB Vcb)
 
OSSTATUS UDFVWrite (IN PVCB Vcb, IN void *Buffer, IN uint32 BCount, IN uint32 LBA, IN uint32 Flags)
 
OSSTATUS UDFVRead (IN PVCB Vcb, IN void *Buffer, IN uint32 BCount, IN uint32 LBA, IN uint32 Flags)
 
OSSTATUS UDFVForget (IN PVCB Vcb, IN uint32 BCount, IN uint32 LBA, IN uint32 Flags)
 
VOID UDFVVerify (IN PVCB Vcb, IN ULONG Flags)
 
VOID UDFVFlush (IN PVCB Vcb)
 
__inline BOOLEAN __fastcall UDFVIsStored (IN PVCB Vcb, IN lba_t lba)
 
BOOLEAN __fastcall UDFCheckArea (IN PVCB Vcb, IN lba_t LBA, IN uint32 BCount)
 

Variables

const char hexChar []
 

Macro Definition Documentation

◆ AlignDirIndex

Definition at line 1093 of file udf_info.h.

◆ AS_BAD

#define AS_BAD   0x04

Definition at line 329 of file udf_info.h.

◆ AS_DISCARDED

#define AS_DISCARDED   0x02

Definition at line 328 of file udf_info.h.

◆ AS_FREE

#define AS_FREE   0x00

Definition at line 326 of file udf_info.h.

◆ AS_USED

#define AS_USED   0x01

Definition at line 327 of file udf_info.h.

◆ FLUSH_FE_FOR_DEL

#define FLUSH_FE_FOR_DEL   TRUE

Definition at line 396 of file udf_info.h.

◆ FLUSH_FE_KEEP

#define FLUSH_FE_KEEP   FALSE

Definition at line 395 of file udf_info.h.

◆ HASH_ALL

#define HASH_ALL   0x07

Definition at line 78 of file udf_info.h.

◆ HASH_DOS

#define HASH_DOS   0x04

Definition at line 77 of file udf_info.h.

◆ HASH_KEEP_NAME

#define HASH_KEEP_NAME   0x08

Definition at line 79 of file udf_info.h.

◆ HASH_POSIX

#define HASH_POSIX   0x01

Definition at line 75 of file udf_info.h.

◆ HASH_ULFN

#define HASH_ULFN   0x02

Definition at line 76 of file udf_info.h.

◆ PH_FORGET_VERIFIED

#define PH_FORGET_VERIFIED   0x00800000

Definition at line 1270 of file udf_info.h.

◆ PH_KEEP_VERIFY_CACHE

#define PH_KEEP_VERIFY_CACHE   0x00200000

Definition at line 1272 of file udf_info.h.

◆ PH_READ_VERIFY_CACHE

#define PH_READ_VERIFY_CACHE   0x00400000

Definition at line 1271 of file udf_info.h.

◆ UDF_DIR_INDEX_FRAME

#define UDF_DIR_INDEX_FRAME   ((uint_di)(1 << UDF_DIR_INDEX_FRAME_SH))

Definition at line 1089 of file udf_info.h.

◆ UDF_DIR_INDEX_FRAME_GRAN

#define UDF_DIR_INDEX_FRAME_GRAN   (32)

Definition at line 1091 of file udf_info.h.

◆ UDF_DIR_INDEX_FRAME_GRAN_MASK

#define UDF_DIR_INDEX_FRAME_GRAN_MASK   (UDF_DIR_INDEX_FRAME_GRAN-1)

Definition at line 1092 of file udf_info.h.

◆ UDF_DIR_INDEX_FRAME_SH

#define UDF_DIR_INDEX_FRAME_SH   9

Definition at line 1084 of file udf_info.h.

◆ UDF_FREE_DLOC

#define UDF_FREE_DLOC   0x02

Definition at line 650 of file udf_info.h.

◆ UDF_FREE_FILEINFO

#define UDF_FREE_FILEINFO   0x01

Definition at line 649 of file udf_info.h.

◆ UDF_FREE_NOTHING

#define UDF_FREE_NOTHING   0x00

Definition at line 648 of file udf_info.h.

◆ UDF_FSPACE_BM

#define UDF_FSPACE_BM   0x00

Definition at line 445 of file udf_info.h.

◆ UDF_MAX_VERIFY_CACHE

#define UDF_MAX_VERIFY_CACHE   (8*1024*1024/2048)

Definition at line 1255 of file udf_info.h.

◆ UDF_PREALLOC_CLASS_DIR

#define UDF_PREALLOC_CLASS_DIR   0x01

Definition at line 356 of file udf_info.h.

◆ UDF_PREALLOC_CLASS_FE

#define UDF_PREALLOC_CLASS_FE   0x00

Definition at line 355 of file udf_info.h.

◆ UDF_SYS_CACHE_STOP_THR

#define UDF_SYS_CACHE_STOP_THR   (10*1024*1024/2048)

Definition at line 1258 of file udf_info.h.

◆ UDF_VERIFY_CACHE_GRAN

#define UDF_VERIFY_CACHE_GRAN   (512*1024/2048)

Definition at line 1257 of file udf_info.h.

◆ UDF_VERIFY_CACHE_LOW

#define UDF_VERIFY_CACHE_LOW   (4*1024*1024/2048)

Definition at line 1256 of file udf_info.h.

◆ UDF_ZSPACE_BM

#define UDF_ZSPACE_BM   0x01

Definition at line 446 of file udf_info.h.

◆ UDFAllocFreeExtent

#define UDFAllocFreeExtent (   v,
  l,
  ss,
  sl,
  e,
  af 
)    UDFAllocFreeExtent_(v, l, ss, sl, e, af)

Definition at line 347 of file udf_info.h.

◆ UDFCheckFreeBitOwner

#define UDFCheckFreeBitOwner (   Vcb,
  i 
)

Definition at line 1238 of file udf_info.h.

◆ UDFCheckSpaceAllocation

#define UDFCheckSpaceAllocation (   Vcb,
  FileInfo,
  Map,
  asXXX 
)    {;}

Definition at line 281 of file udf_info.h.

◆ UDFCheckUsedBitOwner

#define UDFCheckUsedBitOwner (   Vcb,
  i,
 
)

Definition at line 1237 of file udf_info.h.

◆ UDFClrBit

#define UDFClrBit (   arr,
  bit 
)    ( (((uint32*)(arr))[(bit)>>5]) &= (~(((uint32)1) << ((bit)&31))) )

Definition at line 1182 of file udf_info.h.

◆ UDFClrBits

#define UDFClrBits (   arr,
  bit,
  bc 
)
Value:
{uint32 j; \
for(j=0;j<bc;j++) { \
UDFClrBit(arr, (bit)+j); \
}}
unsigned int uint32
Definition: types.h:32
PBATCH_CONTEXT bc
Definition: batch.c:67
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250

Definition at line 1190 of file udf_info.h.

◆ UDFClrZeroBit

#define UDFClrZeroBit (   arr,
  bit 
)    UDFClrBit(arr,bit)

Definition at line 1209 of file udf_info.h.

◆ UDFClrZeroBits

#define UDFClrZeroBits (   arr,
  bit,
  bc 
)    UDFClrBits(arr,bit,bc)

Definition at line 1211 of file udf_info.h.

◆ UDFDecDirCounter

#define UDFDecDirCounter (   Vcb)    UDFChangeFileCounter(Vcb, FALSE, FALSE);

Definition at line 617 of file udf_info.h.

◆ UDFDecFileCounter

#define UDFDecFileCounter (   Vcb)    UDFChangeFileCounter(Vcb, TRUE, FALSE);

Definition at line 615 of file udf_info.h.

◆ UDFDecFileLinkCount

#define UDFDecFileLinkCount (   fi)    UDFChangeFileLinkCount(fi, FALSE)

Definition at line 581 of file udf_info.h.

◆ UDFDereferenceFile__

#define UDFDereferenceFile__ (   fi)
Value:
{ \
UDFInterlockedDecrement((PLONG)&((fi)->RefCount)); \
UDFInterlockedDecrement((PLONG)&((fi)->Dloc->LinkRefCount)); \
if((fi)->ParentFile) { \
UDFInterlockedDecrement((PLONG)&((fi)->ParentFile->OpenCount)); \
} \
}
int32_t * PLONG
Definition: typedefs.h:58

Definition at line 1061 of file udf_info.h.

◆ UDFDirIndexGetLastIndex

#define UDFDirIndexGetLastIndex (   di)    ((((di)->FrameCount - 1) << UDF_DIR_INDEX_FRAME_SH) + (di)->LastFrameCount)

Definition at line 1122 of file udf_info.h.

◆ UDFDOSName__

#define UDFDOSName__ (   Vcb,
  DosName,
  UdfName,
  FileInfo 
)     UDFDOSName(Vcb, DosName, UdfName, (FileInfo) && ((FileInfo)->Index < 2));

Definition at line 217 of file udf_info.h.

◆ UDFExtentToMapping

#define UDFExtentToMapping (   e)    UDFExtentToMapping_(e)

Definition at line 181 of file udf_info.h.

◆ UDFGetBadBit

#define UDFGetBadBit (   arr,
  bit 
)    UDFGetBit(arr,bit)

Definition at line 1205 of file udf_info.h.

◆ UDFGetBit

#define UDFGetBit (   arr,
  bit 
)    ( (BOOLEAN) ( ((((uint32*)(arr))[(bit)>>5]) >> ((bit)&31)) &1 ) )

Definition at line 1180 of file udf_info.h.

◆ UDFGetFileAllocationSize

#define UDFGetFileAllocationSize (   Vcb,
  FileInfo 
)     (((FileInfo)->Dloc->DataLoc.Mapping) ? UDFGetExtentLength((FileInfo)->Dloc->DataLoc.Mapping) : Vcb->LBlockSize)

Definition at line 797 of file udf_info.h.

◆ UDFGetFileAllocMode__

#define UDFGetFileAllocMode__ (   fi)    ((fi)->Dloc->DataLoc.Flags & EXTENT_FLAG_ALLOC_MASK)

Definition at line 1079 of file udf_info.h.

◆ UDFGetFileICBAllocMode__

#define UDFGetFileICBAllocMode__ (   fi)    (((PFILE_ENTRY)((fi)->Dloc->FileEntry))->icbTag.flags & ICB_FLAG_ALLOC_MASK)

Definition at line 1081 of file udf_info.h.

◆ UDFGetFreeBit

#define UDFGetFreeBit (   arr,
  bit 
)    UDFGetBit(arr,bit)

Definition at line 1199 of file udf_info.h.

◆ UDFGetLVIDiUse

#define UDFGetLVIDiUse (   Vcb)
Value:
( ((Vcb) && (Vcb)->LVid) ? \
( ((int8*)(Vcb->LVid+1)) + \
Vcb->LVid->numOfPartitions*2*sizeof(uint32))) \
: NULL)
#define NULL
Definition: types.h:112
char int8
Definition: platform.h:10
#define Vcb
Definition: cdprocs.h:1415

Definition at line 884 of file udf_info.h.

◆ UDFGetPartNumByPartNdx

#define UDFGetPartNumByPartNdx (   Vcb,
  pi 
)    (Vcb->Partitions[pi].PartitionNum)

Definition at line 1028 of file udf_info.h.

◆ UDFGetUsedBit

#define UDFGetUsedBit (   arr,
  bit 
)    (!UDFGetBit(arr,bit))

Definition at line 1198 of file udf_info.h.

◆ UDFGetZeroBit

#define UDFGetZeroBit (   arr,
  bit 
)    UDFGetBit(arr,bit)

Definition at line 1207 of file udf_info.h.

◆ UDFHasAStreamDir

#define UDFHasAStreamDir (   FI)    ((FI) && ((FI)->Dloc) && ((FI)->Dloc->FE_Flags & UDF_FE_FLAG_HAS_SDIR))

Definition at line 1000 of file udf_info.h.

◆ UDFIncDirCounter

#define UDFIncDirCounter (   Vcb)    UDFChangeFileCounter(Vcb, FALSE, TRUE);

Definition at line 616 of file udf_info.h.

◆ UDFIncFileCounter

#define UDFIncFileCounter (   Vcb)    UDFChangeFileCounter(Vcb, TRUE, TRUE);

Definition at line 614 of file udf_info.h.

◆ UDFIncFileLinkCount

#define UDFIncFileLinkCount (   fi)    UDFChangeFileLinkCount(fi, TRUE)

Definition at line 580 of file udf_info.h.

◆ UDFIsADirectory

#define UDFIsADirectory (   FileInfo)     (((FileInfo) && ((FileInfo)->Dloc) && ((FileInfo)->Dloc->DirIndex || ((FileInfo)->FileIdent && ((FileInfo)->FileIdent->fileCharacteristics & FILE_DIRECTORY)))) ? TRUE : FALSE)

Definition at line 792 of file udf_info.h.

◆ UDFIsAStream

#define UDFIsAStream (   FI)    ((FI) && UDFIsAStreamDir((FI)->ParentFile))

Definition at line 1002 of file udf_info.h.

◆ UDFIsAStreamDir

#define UDFIsAStreamDir (   FI)    ((FI) && ((FI)->Dloc) && ((FI)->Dloc->FE_Flags & UDF_FE_FLAG_IS_SDIR))

Definition at line 998 of file udf_info.h.

◆ UDFIsDeleted

#define UDFIsDeleted (   DirNdx)     (((DirNdx)->FileCharacteristics & FILE_DELETED) ? TRUE : FALSE)

Definition at line 788 of file udf_info.h.

◆ UDFIsDirEmpty__

#define UDFIsDirEmpty__ (   fi)    UDFIsDirEmpty((fi)->Dloc->DirIndex)

Definition at line 1070 of file udf_info.h.

◆ UDFIsDirOpened__

#define UDFIsDirOpened__ (   fi)    (fi->OpenCount)

Definition at line 1071 of file udf_info.h.

◆ UDFIsFileCached__

#define UDFIsFileCached__ (   Vcb,
  FileInfo,
  Offset,
  Length,
  ForWrite 
)     (UDFIsExtentCached(Vcb, &((FileInfo)->Dloc->DataLoc), Offset, Length, ForWrite))

Definition at line 839 of file udf_info.h.

◆ UDFIsFlushed

#define UDFIsFlushed (   FI)
Value:
( FI && \
!(FI->Dloc->FE_Flags & UDF_FE_FLAG_FE_MODIFIED) && \
!(FI->Dloc->DataLoc.Modified) && \
!(FI->Dloc->AllocLoc.Modified) &&\
!(FI->Dloc->FELoc.Modified) && \
!(UDFGetDirIndexByFileInfo(FI)[FI->Index].FI_Flags & UDF_FI_FLAG_FI_MODIFIED) )
PDIR_INDEX_HDR UDFGetDirIndexByFileInfo(IN PUDF_FILE_INFO FileInfo)
Definition: dirtree.cpp:1092
#define UDF_FE_FLAG_FE_MODIFIED
Was modified & should be flushed.
Definition: udf_rel.h:323
#define UDF_FI_FLAG_FI_MODIFIED
FileIdent was modified & should be flushed.
Definition: udf_rel.h:217

Definition at line 814 of file udf_info.h.

◆ UDFIsSDirDeleted

#define UDFIsSDirDeleted (   FI)    ((FI) && (FI)->Dloc && ((FI)->Dloc->FE_Flags & UDF_FE_FLAG_IS_DEL_SDIR))

Definition at line 1004 of file udf_info.h.

◆ UDFMarkAllocatedAsNotAllocated

#define UDFMarkAllocatedAsNotAllocated (   Vcb,
  Off,
  Len,
  Ext 
)     UDFMarkAllocatedAsNotXXX(Vcb, Off, Len, Ext, TRUE)

Definition at line 503 of file udf_info.h.

◆ UDFMarkRecordedAsAllocated

#define UDFMarkRecordedAsAllocated (   Vcb,
  Off,
  Len,
  Ext 
)     UDFMarkAllocatedAsNotXXX(Vcb, Off, Len, Ext, FALSE)

Definition at line 516 of file udf_info.h.

◆ UDFMarkSpaceAsXXX

#define UDFMarkSpaceAsXXX (   Vcb,
  FileInfo,
  Map,
  asXXX 
)     UDFMarkSpaceAsXXX_(Vcb, Map, asXXX);

Definition at line 322 of file udf_info.h.

◆ UDFMarkSpaceAsXXXNoProtect

#define UDFMarkSpaceAsXXXNoProtect (   Vcb,
  FileInfo,
  Map,
  asXXX 
)     UDFMarkSpaceAsXXXNoProtect_(Vcb, Map, asXXX);

Definition at line 302 of file udf_info.h.

◆ UDFNtAclSupported

#define UDFNtAclSupported (   Vcb)     (Vcb->maxUDFWriteRev >= 0x0200)

Definition at line 1040 of file udf_info.h.

◆ UDFReferenceFile__

#define UDFReferenceFile__ (   fi)
Value:
{ \
UDFInterlockedIncrement((PLONG)&((fi)->RefCount)); \
UDFInterlockedIncrement((PLONG)&((fi)->Dloc->LinkRefCount)); \
if((fi)->ParentFile) { \
UDFInterlockedIncrement((PLONG)&((fi)->ParentFile->OpenCount)); \
} \
}

Definition at line 1043 of file udf_info.h.

◆ UDFReferenceFileEx__

#define UDFReferenceFileEx__ (   fi,
  i 
)
Value:
{ \
UDFInterlockedExchangeAdd((PLONG)&((fi)->RefCount),i); \
UDFInterlockedExchangeAdd((PLONG)&((fi)->Dloc->LinkRefCount),i); \
if((fi)->ParentFile) { \
UDFInterlockedExchangeAdd((PLONG)&((fi)->ParentFile->OpenCount),i); \
} \
}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Definition at line 1052 of file udf_info.h.

◆ UDFRegisterFsStructure

#define UDFRegisterFsStructure (   Vcb,
  Lba,
  Length 
)    {NOTHING;}

Definition at line 1250 of file udf_info.h.

◆ UDFSetBit

#define UDFSetBit (   arr,
  bit 
)    ( (((uint32*)(arr))[(bit)>>5]) |= (((uint32)1) << ((bit)&31)) )

Definition at line 1181 of file udf_info.h.

◆ UDFSetBits

#define UDFSetBits (   arr,
  bit,
  bc 
)
Value:
{uint32 j; \
for(j=0;j<bc;j++) { \
UDFSetBit(arr, (bit)+j); \
}}

Definition at line 1184 of file udf_info.h.

◆ UDFSetEntityID_imp

#define UDFSetEntityID_imp (   eID,
  Str 
)     UDFSetEntityID_imp_(eID, (uint8*)(Str), sizeof(Str));

Definition at line 598 of file udf_info.h.

◆ UDFSetFileAllocMode__

#define UDFSetFileAllocMode__ (   fi,
  mode 
)
Value:
{ \
(fi)->Dloc->DataLoc.Flags = \
((fi)->Dloc->DataLoc.Flags & ~EXTENT_FLAG_ALLOC_MASK) | (mode & EXTENT_FLAG_ALLOC_MASK); \
}
GLenum mode
Definition: glext.h:6217
#define EXTENT_FLAG_ALLOC_MASK
Definition: udf_rel.h:78

Definition at line 1073 of file udf_info.h.

◆ UDFSetFreeBit

#define UDFSetFreeBit (   arr,
  bit 
)    UDFSetBit(arr,bit)

Definition at line 1201 of file udf_info.h.

◆ UDFSetFreeBitOwner

#define UDFSetFreeBitOwner (   Vcb,
  i 
)

Definition at line 1235 of file udf_info.h.

◆ UDFSetFreeBits

#define UDFSetFreeBits (   arr,
  bit,
  bc 
)    UDFSetBits(arr,bit,bc)

Definition at line 1203 of file udf_info.h.

◆ UDFSetUsedBit

#define UDFSetUsedBit (   arr,
  bit 
)    UDFClrBit(arr,bit)

Definition at line 1200 of file udf_info.h.

◆ UDFSetUsedBitOwner

#define UDFSetUsedBitOwner (   Vcb,
  i,
 
)

Definition at line 1236 of file udf_info.h.

◆ UDFSetUsedBits

#define UDFSetUsedBits (   arr,
  bit,
  bc 
)    UDFClrBits(arr,bit,bc)

Definition at line 1202 of file udf_info.h.

◆ UDFSetZeroBit

#define UDFSetZeroBit (   arr,
  bit 
)    UDFSetBit(arr,bit)

Definition at line 1208 of file udf_info.h.

◆ UDFSetZeroBits

#define UDFSetZeroBits (   arr,
  bit,
  bc 
)    UDFSetBits(arr,bit,bc)

Definition at line 1210 of file udf_info.h.

◆ UDFSparseExtent__

#define UDFSparseExtent__ (   Vcb,
  Ext,
  Off,
  Len,
  Dir,
  WB 
)     UDFZeroExtent(Vcb, Ext, Off, Len, TRUE, Dir, WB)

Definition at line 542 of file udf_info.h.

◆ UDFStreamsSupported

#define UDFStreamsSupported (   Vcb)     (Vcb->maxUDFWriteRev >= 0x0200)

Definition at line 1037 of file udf_info.h.

◆ UDFZeroExtent__

#define UDFZeroExtent__ (   Vcb,
  Ext,
  Off,
  Len,
  Dir,
  WB 
)     UDFZeroExtent(Vcb, Ext, Off, Len, FALSE, Dir, WB)

Definition at line 539 of file udf_info.h.

◆ UFD_VERIFY_FLAG_BG

#define UFD_VERIFY_FLAG_BG   0x04

Definition at line 1304 of file udf_info.h.

◆ UFD_VERIFY_FLAG_FORCE

#define UFD_VERIFY_FLAG_FORCE   0x01

Definition at line 1302 of file udf_info.h.

◆ UFD_VERIFY_FLAG_LOCKED

#define UFD_VERIFY_FLAG_LOCKED   0x10

Definition at line 1305 of file udf_info.h.

◆ UFD_VERIFY_FLAG_WAIT

#define UFD_VERIFY_FLAG_WAIT   0x02

Definition at line 1303 of file udf_info.h.

Function Documentation

◆ crc32()

uint32 __fastcall crc32 ( IN uint8 s,
IN uint32  len 
)

Definition at line 4290 of file udf_info.cpp.

4294{
4295#if defined(_X86_) && defined(_MSC_VER) && !defined(__clang__)
4296// uint32 _Size = len;
4297
4298 __asm {
4299 push ebx
4300 push ecx
4301 push edx
4302 push esi
4303
4304 xor eax,eax
4305 mov esi,ecx // ESI <- s
4306 mov ecx,edx // ECX <- len
4307
4308 jecxz EO_CRC
4309
4310 lea ebx,[crc32_tab]
4311 xor edx,edx
4312
4313CRC_loop:
4314
4315 mov dl,al
4316 xor dl,[esi]
4317 shr eax,8
4318 xor eax,[dword ptr ebx+edx*4]
4319 inc esi
4320 loop CRC_loop
4321
4322EO_CRC:
4323
4324 pop esi
4325 pop edx
4326 pop ecx
4327 pop ebx
4328
4329 ret
4330 }
4331#else // NO X86 optimization , use generic C/C++
4332 uint32 i;
4333 uint32 crc32val = 0;
4334
4335 for(i=0; i<len; i++, s++) {
4336 crc32val =
4337 crc32_tab[(crc32val ^ (*s)) & 0xff] ^ (crc32val >> 8);
4338 }
4339 return crc32val;
4340#endif // _X86_
4341} // end crc32()
static void xor(unsigned char *dst, const unsigned char *a, const unsigned char *b, const int count)
Definition: crypt_des.c:251
GLdouble s
Definition: gl.h:2039
GLenum GLsizei len
Definition: glext.h:6722
static PVOID ptr
Definition: dispmode.c:27
static calc_node_t * pop(void)
Definition: rpn_ieee.c:90
static void push(calc_node_t *op)
Definition: rpn_ieee.c:113
ecx edi movl ebx edx edi decl ecx esi eax jecxz decl eax andl ebx
Definition: synth_sse3d.h:83
ecx edi movl ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl eax
Definition: synth_sse3d.h:85
ecx edi movl ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx movl TEMP incl eax andl eax ecx incl ebx testl eax jnz xchgl ecx incl TEMP esi
Definition: synth_sse3d.h:103
ecx edi movl ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx
Definition: synth_sse3d.h:87
static const uint32 crc32_tab[]
Definition: udf_info.cpp:86
int ret

◆ UDFAcquireDloc()

OSSTATUS UDFAcquireDloc ( IN PVCB  Vcb,
IN PUDF_DATALOC_INFO  Dloc 
)

Definition at line 1206 of file dirtree.cpp.

1210{
1211 UDFAcquireResourceExclusive(&(Vcb->DlocResource2),TRUE);
1212 if(Dloc->FE_Flags & UDF_FE_FLAG_UNDER_INIT) {
1213 UDFReleaseResource(&(Vcb->DlocResource2));
1214 return STATUS_SHARING_PAUSED;
1215 }
1216 Dloc->FE_Flags |= UDF_FE_FLAG_UNDER_INIT;
1217 UDFReleaseResource(&(Vcb->DlocResource2));
1218 return STATUS_SUCCESS;
1219} // end UDFAcquireDloc()
#define TRUE
Definition: types.h:120
#define UDFReleaseResource(Resource)
Definition: env_spec_w32.h:661
#define UDFAcquireResourceExclusive(Resource, CanWait)
Definition: env_spec_w32.h:656
#define STATUS_SUCCESS
Definition: shellext.h:65
#define UDF_FE_FLAG_UNDER_INIT
Dloc is being initialized, don't touch it now.
Definition: udf_rel.h:335
#define STATUS_SHARING_PAUSED
Definition: udferr_usr.h:165

Referenced by UDFStoreDloc().

◆ UDFAddXSpaceBitmap()

OSSTATUS UDFAddXSpaceBitmap ( IN PVCB  Vcb,
IN uint32  PartNum,
IN PSHORT_AD  bm,
IN ULONG  bm_type 
)

Definition at line 1569 of file mount.cpp.

1575{
1576 int8* tmp;
1577 int8* tmp_bm;
1578 uint32 i, lim, j, lba, l, lim2, l2, k;
1579 lb_addr locAddr;
1581 uint16 Ident;
1582 uint32 flags;
1583 SIZE_T Length;
1585 BOOLEAN bit_set;
1586
1588 UDFPrint(("UDFAddXSpaceBitmap: at block=%x, partition=%d\n",
1589 bm->extPosition,
1590 PartNum));
1591
1592 if(!(Length = (bm->extLength & UDF_EXTENT_LENGTH_MASK))) return STATUS_SUCCESS;
1593 i=UDFPartStart(Vcb, PartNum);
1594 flags = bm->extLength >> 30;
1595 if(!flags /*|| flags == EXTENT_NOT_RECORDED_ALLOCATED*/) {
1596 tmp = (int8*)DbgAllocatePool(NonPagedPool, max(Length, Vcb->BlockSize));
1597 if(!tmp) return STATUS_INSUFFICIENT_RESOURCES;
1598 locAddr.partitionReferenceNum = (uint16)PartNum;
1599 locAddr.logicalBlockNum = bm->extPosition;
1600 // read header of the Bitmap
1601 if(!OS_SUCCESS(status = UDFReadTagged(Vcb, tmp, lba = UDFPartLbaToPhys(Vcb, &(locAddr)),
1602 locAddr.logicalBlockNum, &Ident)) ) {
1603err_addxsbm_1:
1604 DbgFreePool(tmp);
1605 return status;
1606 }
1607 if(Ident != TID_SPACE_BITMAP_DESC) {
1609 goto err_addxsbm_1;
1610 }
1611 UDFRegisterFsStructure(Vcb, lba, Vcb->BlockSize);
1612 // read the whole Bitmap
1613 if(!OS_SUCCESS(status = UDFReadData(Vcb, FALSE, ((uint64)lba)<<Vcb->BlockSizeBits, Length, FALSE, tmp, &ReadBytes)))
1614 goto err_addxsbm_1;
1616 lim = min(i + ((lim2 = ((PSPACE_BITMAP_DESC)tmp)->numOfBits) << Vcb->LB2B_Bits), Vcb->FSBM_BitCount);
1617 tmp_bm = tmp + sizeof(SPACE_BITMAP_DESC);
1618 j = 0;
1619 for(;(l = UDFGetBitmapLen((uint32*)tmp_bm, j, lim2)) && (i<lim);) {
1620 // expand LBlocks to Sectors...
1621 l2 = l << Vcb->LB2B_Bits;
1622 // ...and mark them
1623 if(bm_type == UDF_FSPACE_BM) {
1624 bit_set = UDFGetFreeBit(tmp_bm, j);
1625 for(k=0;(k<l2) && (i<lim);k++) {
1626 if(bit_set) {
1627 // FREE block
1628 UDFSetFreeBit(Vcb->FSBM_Bitmap, i);
1630 UDFSetZeroBit(Vcb->ZSBM_Bitmap, i);
1631 } else {
1632 // USED block
1633 UDFClrZeroBit(Vcb->ZSBM_Bitmap, i);
1634 }
1635 i++;
1636 }
1637 } else {
1638 bit_set = UDFGetZeroBit(tmp_bm, j);
1639 for(k=0;(k<l2) && (i<lim);k++) {
1640 if(bit_set) {
1641 // ZERO block
1642 UDFSetZeroBit(Vcb->ZSBM_Bitmap, i);
1643 } else {
1644 // DATA block
1645 UDFClrZeroBit(Vcb->ZSBM_Bitmap, i);
1646 }
1647 i++;
1648 }
1649 }
1650 j += l;
1651 }
1652 DbgFreePool(tmp);
1653/* } else if((bm->extLength >> 30) == EXTENT_NOT_RECORDED_ALLOCATED) {
1654 i=Vcb->Partitions[PartNum].PartitionRoot;
1655 lim = i + Vcb->Partitions[PartNum].PartitionLen;
1656 for(;i<lim;i++) {
1657 UDFSetUsedBit(Vcb->FSBM_Bitmap, i);
1658 }*/
1659 }
1660 return STATUS_SUCCESS;
1661} // end UDFAddXSpaceBitmap()
unsigned char BOOLEAN
uint32 __fastcall UDFPartStart(PVCB Vcb, uint32 PartNum)
Definition: alloc.cpp:222
SIZE_T __stdcall UDFGetBitmapLen(uint32 *Bitmap, SIZE_T Offs, SIZE_T Lim)
Definition: alloc.cpp:496
uint32 __fastcall UDFPartLbaToPhys(IN PVCB Vcb, IN lb_addr *Addr)
Definition: alloc.cpp:114
unsigned short uint16
Definition: types.h:30
r l[0]
Definition: byte_order.h:168
#define FALSE
Definition: types.h:117
unsigned long long uint64
Definition: platform.h:18
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:67
struct _SPACE_BITMAP_DESC SPACE_BITMAP_DESC
#define TID_SPACE_BITMAP_DESC
Definition: ecma_167.h:173
#define OS_SUCCESS(a)
Definition: env_spec_w32.h:56
#define DbgFreePool
Definition: env_spec_w32.h:334
#define OSSTATUS
Definition: env_spec_w32.h:57
#define DbgAllocatePool
Definition: env_spec_w32.h:332
#define NonPagedPool
Definition: env_spec_w32.h:307
GLbitfield flags
Definition: glext.h:7161
#define min(a, b)
Definition: monoChain.cc:55
int k
Definition: mpi.c:3369
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define UDF_EXTENT_LENGTH_MASK
Definition: osta_misc.h:148
OSSTATUS UDFReadData(IN PVCB Vcb, IN BOOLEAN Translate, IN LONGLONG Offset, IN ULONG Length, IN BOOLEAN Direct, OUT PCHAR Buffer, OUT PSIZE_T ReadBytes)
uint16 partitionReferenceNum
Definition: ecma_167.h:363
uint32 logicalBlockNum
Definition: ecma_167.h:362
Definition: ps.c:97
#define max(a, b)
Definition: svc.c:63
ULONG_PTR SIZE_T
Definition: typedefs.h:80
OSSTATUS UDFReadTagged(PVCB Vcb, int8 *Buf, uint32 Block, uint32 Location, uint16 *Ident)
Definition: udf_info.cpp:4586
#define lba
#define UDFClrZeroBit(arr, bit)
Definition: udf_info.h:1209
#define UDFSetFreeBit(arr, bit)
Definition: udf_info.h:1201
#define UDFRegisterFsStructure(Vcb, Lba, Length)
Definition: udf_info.h:1250
#define UDFGetZeroBit(arr, bit)
Definition: udf_info.h:1207
#define UDFSetFreeBitOwner(Vcb, i)
Definition: udf_info.h:1235
#define UDF_FSPACE_BM
Definition: udf_info.h:445
#define UDFSetZeroBit(arr, bit)
Definition: udf_info.h:1208
#define UDFGetFreeBit(arr, bit)
Definition: udf_info.h:1199
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define UDF_CHECK_BITMAP_RESOURCE(Vcb)
Definition: udffs.h:264
#define UDFPrint(Args)
Definition: udffs.h:225

Referenced by UDFBuildFreeSpaceBitmap().

◆ UDFAllocateFESpace()

OSSTATUS UDFAllocateFESpace ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  DirInfo,
IN uint32  PartNum,
IN PEXTENT_INFO  FEExtInfo,
IN uint32  Len 
)

Definition at line 1563 of file extent.cpp.

1570{
1571#ifdef UDF_FE_ALLOCATION_CHARGE // UDF_FE_ALLOCATION_CHARGE
1575 BOOLEAN retry = FALSE;
1576 uint32 i, lim;
1577
1578/*
1579 1. #Dir1#->*File* -> Dir1's FECharge
1580 2. #Dir1#->*Dir* -> Dir1's FECharge
1581 3. #Dir1#->*SDir* -> Dir1's FECharge
1582 4. Dir1->#SDir#->*Stream* -> Dir1's FEChargeSDir
1583 5. Dir1->#File#->*SDir* -> Dir1's FEChargeSDir
1584 6. Dir1->#Dir#->*SDir* -> (see p.2)
1585 7. Dir1->File->#SDir#->*Stream* -> Dir1's FEChargeSDir
1586 8. Dir1->Dir->#SDir#->*Stream* -> (see p.4)
1587
1588## ~ DirInfo
1589** ~ Object to be created
1590
1591*/
1592
1593// ASSERT(!FEExtInfo->Mapping);
1594 // check if DirInfo we are called with is a Directory
1595 // (it can be a file with SDir)
1596 if(!DirInfo || !DirInfo->Dloc->DirIndex ||
1597 ((lim = ((DirInfo->Dloc->FE_Flags & UDF_FE_FLAG_IS_SDIR) ? Vcb->FEChargeSDir : Vcb->FECharge)) <= 1))
1598#endif // UDF_FE_ALLOCATION_CHARGE
1599 return UDFAllocFreeExtent(Vcb, Len,
1600 UDFPartStart(Vcb, PartNum), UDFPartEnd(Vcb, PartNum), FEExtInfo, EXTENT_FLAG_VERIFY);
1601#ifdef UDF_FE_ALLOCATION_CHARGE // UDF_FE_ALLOCATION_CHARGE
1602
1603 Ext = &(DirInfo->Dloc->DirIndex->FECharge);
1604
1605 while(TRUE) {
1606
1607 if(!Ext->Mapping) {
1608 ULONG p_start;
1609 ULONG p_end;
1610 ULONG fe_loc;
1611 ULONG l1, l2;
1612
1613 p_start = UDFPartStart(Vcb, PartNum);
1614 p_end = UDFPartEnd(Vcb, PartNum);
1615 fe_loc = DirInfo->Dloc->FELoc.Mapping[0].extLocation;
1616
1618 if(OS_SUCCESS(status)) {
1619 // do nothing, even do not unpack
1620 } else
1621 if(Vcb->LowFreeSpace) {
1622 status = UDFAllocFreeExtent(Vcb, Len << Vcb->LBlockSizeBits,p_start, p_end, FEExtInfo, EXTENT_FLAG_VERIFY);
1623 if(OS_SUCCESS(status)) {
1624 UDFPrint(("FE @ %x (1)\n", FEExtInfo->Mapping[0].extLocation ));
1625 }
1626 return status;
1627 } else {
1628 if(fe_loc > p_start + 512*16) {
1629 l1 = fe_loc - 512*16;
1630 } else {
1631 l1 = p_start;
1632 }
1633 if(fe_loc + 512*16 < p_end) {
1634 l2 = fe_loc + 512*16;
1635 } else {
1636 l2 = p_end;
1637 }
1638 status = UDFAllocFreeExtent(Vcb, lim << Vcb->LBlockSizeBits, l1, l2, Ext, EXTENT_FLAG_VERIFY);
1639 if(!OS_SUCCESS(status)) {
1640 status = UDFAllocFreeExtent(Vcb, lim << Vcb->LBlockSizeBits, (p_start+fe_loc)/2, (fe_loc+p_end)/2, Ext, EXTENT_FLAG_VERIFY);
1641 }
1642 if(!OS_SUCCESS(status)) {
1643 status = UDFAllocFreeExtent(Vcb, lim << Vcb->LBlockSizeBits, p_start, p_end, Ext, EXTENT_FLAG_VERIFY);
1644 }
1645 if(!OS_SUCCESS(status)) {
1646 status = UDFAllocFreeExtent(Vcb, lim << Vcb->LBlockSizeBits, p_start+1024, p_end-1024, Ext, EXTENT_FLAG_VERIFY);
1647 }
1648 if(!OS_SUCCESS(status = UDFAllocFreeExtent(Vcb, lim << Vcb->LBlockSizeBits, p_start, p_end, Ext, EXTENT_FLAG_VERIFY) )) {
1649 // can't pre-allocate space for multiple FEs. Try single FE
1650 UDFPrint(("allocate single FE entry\n"));
1652 p_start, p_end, FEExtInfo, EXTENT_FLAG_VERIFY);
1653 if(OS_SUCCESS(status)) {
1654 UDFPrint(("FE @ %x (2)\n", FEExtInfo->Mapping[0].extLocation ));
1655 }
1656 return status;
1657 }
1659 if(!OS_SUCCESS(status)) {
1660 MyFreePool__(Ext->Mapping);
1661 Ext->Mapping = NULL;
1662 return status;
1663 }
1664 }
1665 }
1666
1667 for(i=0;i<lim;i++) {
1668 if( (Ext->Mapping[i].extLength >> 30) == EXTENT_NOT_RECORDED_ALLOCATED ) {
1669 Ext->Mapping[i].extLength &= UDF_EXTENT_LENGTH_MASK; // EXTENT_RECORDED_ALLOCATED
1670
1671 Extent.extLength = Vcb->LBlockSize | (EXTENT_NOT_RECORDED_ALLOCATED << 30);
1672 Extent.extLocation = Ext->Mapping[i].extLocation;
1673
1674 if(Vcb->BSBM_Bitmap) {
1675 uint32 lba = Ext->Mapping[i].extLocation;
1676 if(UDFGetBadBit((uint32*)(Vcb->BSBM_Bitmap), lba)) {
1677 UDFPrint(("Remove BB @ %x from FE charge\n", lba));
1678 Ext->Mapping[i].extLength |= (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30);
1679 Ext->Mapping[i].extLocation = 0;
1680 continue;
1681 }
1682 }
1683
1684 FEExtInfo->Mapping = UDFExtentToMapping(&Extent);
1685 if(!FEExtInfo->Mapping) {
1686 ASSERT(!(Ext->Mapping[i].extLength >> 30));
1687 Ext->Mapping[i].extLength |= (EXTENT_NOT_RECORDED_ALLOCATED << 30);
1689 }
1690 UDFPrint(("FE @ %x (3)\n", FEExtInfo->Mapping[0].extLocation ));
1691 FEExtInfo->Length = Len;
1692 FEExtInfo->Offset = 0;
1693 FEExtInfo->Modified = TRUE;
1694 return STATUS_SUCCESS;
1695 }
1696 }
1697
1698 if(Vcb->LowFreeSpace) {
1700 UDFPartStart(Vcb, PartNum), UDFPartEnd(Vcb, PartNum), FEExtInfo, EXTENT_FLAG_VERIFY);
1701 if(OS_SUCCESS(status)) {
1702 UDFPrint(("FE @ %x (4)\n", FEExtInfo->Mapping[0].extLocation ));
1703 }
1704 return status;
1705 }
1706 if(retry)
1708
1709 // we can get here if there are no free slots in
1710 // preallocated FE charge. So, we should release
1711 // memory and try to allocate space for new FE charge.
1712 MyFreePool__(Ext->Mapping);
1713 Ext->Mapping = NULL;
1714 retry = TRUE;
1715 }
1717#endif // UDF_FE_ALLOCATION_CHARGE
1718
1719} // end UDFAllocateFESpace()
uint32 __fastcall UDFPartEnd(PVCB Vcb, uint32 PartNum)
Definition: alloc.cpp:242
#define Len
Definition: deflate.h:82
#define EXTENT_NOT_RECORDED_ALLOCATED
Definition: ecma_167.h:368
#define EXTENT_NOT_RECORDED_NOT_ALLOCATED
Definition: ecma_167.h:369
OSSTATUS __fastcall UDFUnPackMapping(IN PVCB Vcb, IN PEXTENT_INFO ExtInfo)
Definition: extent.cpp:2860
OSSTATUS UDFGetCachedAllocation(IN PVCB Vcb, IN uint32 ParentLocation, OUT PEXTENT_INFO Ext, OUT uint32 *Items, IN uint32 AllocClass)
Definition: extent.cpp:1417
#define MyFreePool__(addr)
Definition: mem_tools.h:152
static struct proto Ext[]
Definition: mkg3states.c:87
#define ASSERT(a)
Definition: mode.c:44
uint32_t ULONG
Definition: typedefs.h:59
#define UDFAllocFreeExtent(v, l, ss, sl, e, af)
Definition: udf_info.h:347
#define UDFExtentToMapping(e)
Definition: udf_info.h:181
#define UDF_PREALLOC_CLASS_FE
Definition: udf_info.h:355
#define UDFGetBadBit(arr, bit)
Definition: udf_info.h:1205
#define UDF_FE_FLAG_IS_SDIR
File is a StreamDir.
Definition: udf_rel.h:327
#define EXTENT_FLAG_VERIFY
Definition: udf_rel.h:81

Referenced by UDFBuildFileEntry(), and UDFFlushFE().

◆ UDFAllocFreeExtent_()

OSSTATUS UDFAllocFreeExtent_ ( IN PVCB  Vcb,
IN int64  Length,
IN uint32  SearchStart,
IN uint32  SearchLim,
OUT PEXTENT_INFO  Extent,
IN uint8  AllocFlags 
)

Definition at line 963 of file alloc.cpp.

975{
977 PEXTENT_MAP Map = NULL;
978 uint32 len, LBS, BSh, blen;
979
980 LBS = Vcb->LBlockSize;
981 BSh = Vcb->BlockSizeBits;
982 blen = (uint32)(((Length+LBS-1) & ~((int64)LBS-1)) >> BSh);
983 ExtInfo->Mapping = NULL;
984 ExtInfo->Offset = 0;
985
986 ASSERT(blen <= (uint32)(UDF_MAX_EXTENT_LENGTH >> BSh));
987
988 UDFAcquireResourceExclusive(&(Vcb->BitMapResource1),TRUE);
989
990 if(blen > (SearchLim - SearchStart)) {
991 goto no_free_space_err;
992 }
993 // walk through the free space bitmap & find a single extent or a set of
994 // frags giving in sum the Length specified
995 while(blen) {
996 Ext.extLocation = UDFFindMinSuitableExtent(Vcb, blen, SearchStart,
997 SearchLim, &len, AllocFlags);
998
999// ASSERT(len <= (uint32)(UDF_MAX_EXTENT_LENGTH >> BSh));
1000 if(len >= blen) {
1001 // complete search
1002 Ext.extLength = blen<<BSh;
1003 blen = 0;
1004 } else if(len) {
1005 // we need still some frags to complete request &
1006 // probably we have the opportunity to do it
1007 Ext.extLength = len<<BSh;
1008 blen -= len;
1009 } else {
1010no_free_space_err:
1011 // no more free space. abort
1012 if(ExtInfo->Mapping) {
1013 UDFMarkSpaceAsXXXNoProtect(Vcb, 0, ExtInfo->Mapping, AS_DISCARDED); // free
1014 MyFreePool__(ExtInfo->Mapping);
1015 ExtInfo->Mapping = NULL;
1016 }
1017 UDFReleaseResource(&(Vcb->BitMapResource1));
1018 ExtInfo->Length = 0;//UDFGetExtentLength(ExtInfo->Mapping);
1019 AdPrint((" DISK_FULL\n"));
1020 return STATUS_DISK_FULL;
1021 }
1022 // append the frag found to mapping
1023 ASSERT(!(Ext.extLength >> 30));
1024 ASSERT(Ext.extLocation);
1025
1026 // mark newly allocated blocks as zero-filled
1027 UDFSetZeroBits(Vcb->ZSBM_Bitmap, Ext.extLocation, (Ext.extLength & UDF_EXTENT_LENGTH_MASK) >> BSh);
1028
1029 if(AllocFlags & EXTENT_FLAG_VERIFY) {
1030 if(!UDFCheckArea(Vcb, Ext.extLocation, Ext.extLength >> BSh)) {
1031 AdPrint(("newly allocated extent contains BB\n"));
1032 UDFMarkSpaceAsXXXNoProtect(Vcb, 0, ExtInfo->Mapping, AS_DISCARDED); // free
1033 UDFMarkBadSpaceAsUsed(Vcb, Ext.extLocation, Ext.extLength >> BSh); // bad -> bad+used
1034 // roll back
1035 blen += Ext.extLength>>BSh;
1036 continue;
1037 }
1038 }
1039
1040 Ext.extLength |= EXTENT_NOT_RECORDED_ALLOCATED << 30;
1041 if(!(ExtInfo->Mapping)) {
1042 // create new
1043#ifdef UDF_TRACK_ALLOC_FREE_EXTENT
1044 ExtInfo->Mapping = UDFExtentToMapping_(&Ext, src, line);
1045#else // UDF_TRACK_ALLOC_FREE_EXTENT
1046 ExtInfo->Mapping = UDFExtentToMapping(&Ext);
1047#endif // UDF_TRACK_ALLOC_FREE_EXTENT
1048 if(!ExtInfo->Mapping) {
1049 BrutePoint();
1050 UDFReleaseResource(&(Vcb->BitMapResource1));
1051 ExtInfo->Length = 0;
1053 }
1054 UDFMarkSpaceAsXXXNoProtect(Vcb, 0, ExtInfo->Mapping, AS_USED); // used
1055 } else {
1056 // update existing
1057 Map = UDFExtentToMapping(&Ext);
1058 if(!Map) {
1059 BrutePoint();
1060 UDFReleaseResource(&(Vcb->BitMapResource1));
1061 ExtInfo->Length = UDFGetExtentLength(ExtInfo->Mapping);
1063 }
1064 UDFMarkSpaceAsXXXNoProtect(Vcb, 0, Map, AS_USED); // used
1065 ExtInfo->Mapping = UDFMergeMappings(ExtInfo->Mapping, Map);
1066 MyFreePool__(Map);
1067 }
1068 if(!ExtInfo->Mapping) {
1069 BrutePoint();
1070 UDFReleaseResource(&(Vcb->BitMapResource1));
1071 ExtInfo->Length = 0;
1073 }
1074 }
1075 UDFReleaseResource(&(Vcb->BitMapResource1));
1076 ExtInfo->Length = Length;
1077 return STATUS_SUCCESS;
1078} // end UDFAllocFreeExtent_()
SIZE_T UDFFindMinSuitableExtent(IN PVCB Vcb, IN uint32 Length, IN uint32 SearchStart, IN uint32 SearchLim, OUT uint32 *MaxExtLen, IN uint8 AllocFlags)
Definition: alloc.cpp:556
void UDFMarkBadSpaceAsUsed(IN PVCB Vcb, IN lba_t lba, IN ULONG len)
Definition: alloc.cpp:761
long long int64
Definition: platform.h:13
#define BrutePoint()
Definition: env_spec_w32.h:504
#define AdPrint(_x_)
Definition: env_spec_w32.h:292
int64 UDFGetExtentLength(IN PEXTENT_MAP Extent)
Definition: extent.cpp:142
PEXTENT_MAP __fastcall UDFExtentToMapping_(IN PEXTENT_AD Extent)
Definition: extent.cpp:189
PEXTENT_MAP __fastcall UDFMergeMappings(IN PEXTENT_MAP Extent, IN PEXTENT_MAP Extent2)
Definition: extent.cpp:266
GLenum src
Definition: glext.h:6340
BOOLEAN __fastcall UDFCheckArea(IN PVCB Vcb, IN lba_t LBA, IN uint32 BCount)
Definition: remap.cpp:763
Definition: parser.c:49
#define AS_USED
Definition: udf_info.h:327
#define UDFMarkSpaceAsXXXNoProtect(Vcb, FileInfo, Map, asXXX)
Definition: udf_info.h:302
#define UDFSetZeroBits(arr, bit, bc)
Definition: udf_info.h:1210
#define AS_DISCARDED
Definition: udf_info.h:328
#define UDF_MAX_EXTENT_LENGTH
Definition: udf_rel.h:511
#define STATUS_DISK_FULL
Definition: udferr_usr.h:155

◆ UDFAreSectorsRelocated()

BOOLEAN __fastcall UDFAreSectorsRelocated ( IN PVCB  Vcb,
IN uint32  Lba,
IN uint32  BlockCount 
)

Definition at line 982 of file remap.cpp.

987{
988
989 if(Vcb->SparingTable) {
990 // use sparing table for relocation
991 uint32 i, BS, orig;
992 BS = Vcb->SparingBlockSize;
993 PSPARING_MAP Map;
994
995 Map = Vcb->SparingTable;
996 for(i=0;i<Vcb->SparingCount;i++,Map++) {
997 if( ((Lba >= (orig = Map->origLocation)) && (Lba < orig + BS)) ||
998 ((Lba+BlockCount-1 >= orig) && (Lba+BlockCount-1 < orig + BS)) ||
999 ((orig >= Lba) && (orig < Lba+BlockCount)) ||
1000 ((orig+BS >= Lba) && (orig+BS < Lba+BlockCount)) ) {
1001 return TRUE;
1002 }
1003 }
1004 } else if(Vcb->Vat) {
1005 // use VAT for relocation
1006 uint32 i, root, j;
1007 uint32* Map;
1008 if(Lba < (root = Vcb->Partitions[Vcb->VatPartNdx].PartitionRoot))
1009 return FALSE;
1010 if(Lba+BlockCount >= Vcb->NWA)
1011 return TRUE;
1012 Map = &(Vcb->Vat[Lba-root/*+i*/]);
1013 for(i=0; i<BlockCount; i++, Map++) {
1014 if((j = (*Map)) &&
1015 (j != Lba-root+i) &&
1016 ((j != UDF_VAT_FREE_ENTRY) || ((Lba+i) < Vcb->LastLBA)))
1017 return TRUE;
1018 }
1019 }
1020 return FALSE;
1021} // end UDFAreSectorsRelocated()
struct _root root
#define UDF_VAT_FREE_ENTRY
Definition: osta_misc.h:71
uint32 origLocation
Definition: osta_misc.h:191
#define BS
Definition: telnetd.h:22

Referenced by UDFRelocateSectors().

◆ UDFBuildAllocDescs()

OSSTATUS UDFBuildAllocDescs ( IN PVCB  Vcb,
IN uint32  PartNum,
IN OUT PUDF_FILE_INFO  FileInfo,
OUT int8 **  AllocData 
)

Definition at line 2628 of file extent.cpp.

2634{
2635// PEXTENT_MAP InMap;
2636// uint32 i=0;
2637 int8* Allocs;
2638 uint16 AllocMode;
2639 uint32 InitSz;
2641
2643 AdPrint(("BuildAllocDesc\n"));
2644 // get space available in the 1st LBlock after FE
2645 InitSz = Vcb->LBlockSize - FileInfo->Dloc->FileEntryLen;
2646 Allocs = (int8*)MyAllocatePool__(NonPagedPool, InitSz);
2647 if(!Allocs) {
2648 *AllocData = NULL;
2649 AdPrint(("BuildAllocDesc: cant alloc %x bytes for Allocs\n", InitSz));
2651 }
2652 RtlZeroMemory(Allocs, InitSz);
2653// InMap = FileInfo->Dloc->DataLoc.Mapping;
2654 UDFCheckSpaceAllocation(Vcb, 0, InMap, AS_USED); // check if used
2655
2656 // TODO: move data from mapped locations here
2657
2658 AllocMode = ((PFILE_ENTRY)(FileInfo->Dloc->FileEntry))->icbTag.flags & ICB_FLAG_ALLOC_MASK;
2659 switch(AllocMode) {
2660 case ICB_FLAG_AD_IN_ICB: {
2661 MyFreePool__(Allocs);
2662 ASSERT(!FileInfo->Dloc->AllocLoc.Mapping);
2663 Allocs = NULL;
2665 break;
2666 }
2667 case ICB_FLAG_AD_SHORT: {
2668 status = UDFBuildShortAllocDescs(Vcb, PartNum, &Allocs, InitSz, FileInfo);
2669 break;
2670 }
2671 case ICB_FLAG_AD_LONG: {
2672 status = UDFBuildLongAllocDescs(Vcb, PartNum, &Allocs, InitSz, FileInfo);
2673 break;
2674 }
2675/* case ICB_FLAG_AD_EXTENDED: {
2676 status = UDFBuildExtAllocDescs(Vcb, PartNum, &Allocs, InitSz, FileInfo);
2677 break;
2678 }*/
2679 default: {
2680 MyFreePool__(Allocs);
2681 Allocs = NULL;
2683 }
2684 }
2685
2686 *AllocData = Allocs;
2687 UDFCheckSpaceAllocation(Vcb, 0, FileInfo->Dloc->DataLoc.Mapping, AS_USED); // check if used
2688
2689 return status;
2690} // end UDFBuildAllocDescs()
#define ICB_FLAG_AD_LONG
Definition: ecma_167.h:494
#define ICB_FLAG_AD_SHORT
Definition: ecma_167.h:493
struct _FILE_ENTRY * PFILE_ENTRY
#define ICB_FLAG_AD_IN_ICB
Definition: ecma_167.h:496
#define ICB_FLAG_ALLOC_MASK
Definition: ecma_167.h:480
#define ValidateFileInfo(fi)
Definition: env_spec_w32.h:516
OSSTATUS UDFBuildShortAllocDescs(IN PVCB Vcb, IN uint32 PartNum, OUT int8 **Buff, IN uint32 InitSz, IN OUT PUDF_FILE_INFO FileInfo)
Definition: extent.cpp:825
OSSTATUS UDFBuildLongAllocDescs(IN PVCB Vcb, IN uint32 PartNum, OUT int8 **Buff, IN uint32 InitSz, IN OUT PUDF_FILE_INFO FileInfo)
Definition: extent.cpp:1012
#define MyAllocatePool__(type, size)
Definition: mem_tools.h:149
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define UDFCheckSpaceAllocation(Vcb, FileInfo, Map, asXXX)
Definition: udf_info.h:281
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

Referenced by UDFFlushFE().

◆ UDFBuildFileEntry()

OSSTATUS UDFBuildFileEntry ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  DirInfo,
IN PUDF_FILE_INFO  FileInfo,
IN uint32  PartNum,
IN uint16  AllocMode,
IN uint32  ExtAttrSz,
IN BOOLEAN  Extended 
)

Definition at line 971 of file udf_info.cpp.

980{
981 PFILE_ENTRY FileEntry;
983// EntityID* eID;
984 uint32 l;
985 EXTENT_INFO _FEExtInfo;
986 uint16* lcp;
987
988 ASSERT(!PartNum);
989 ASSERT(!ExtAttrSz);
990 // calculate the length required
991 l = (Extended ? sizeof(EXTENDED_FILE_ENTRY) : sizeof(FILE_ENTRY)) + ExtAttrSz;
992 if(l > Vcb->LBlockSize) return STATUS_INVALID_PARAMETER;
993 // allocate block for FE
994 if(!OS_SUCCESS(status = UDFAllocateFESpace(Vcb, DirInfo, PartNum, &_FEExtInfo, l) ))
995 return status;
996 // remember FE location for future hard link creation
997 ASSERT(UDFFindDloc(Vcb, _FEExtInfo.Mapping[0].extLocation) == (-1));
998 if(!OS_SUCCESS(status = UDFStoreDloc(Vcb, FileInfo, _FEExtInfo.Mapping[0].extLocation))) {
1000 UDFFreeFESpace(Vcb, DirInfo, &_FEExtInfo); // free
1001 MyFreePool__(_FEExtInfo.Mapping);
1002 return status;
1003 }
1005 if(!FileEntry) {
1006 UDFRemoveDloc(Vcb, FileInfo->Dloc);
1007 FileInfo->Dloc = NULL;
1008 UDFFreeFESpace(Vcb, DirInfo, &_FEExtInfo); // free
1009 MyFreePool__(_FEExtInfo.Mapping);
1011 }
1012 FileInfo->Dloc->FELoc = _FEExtInfo;
1013
1014 RtlZeroMemory((int8*)FileEntry, l);
1015 // set up in-memory FE structure
1016 FileEntry->icbTag.flags = AllocMode;
1018 FileEntry->icbTag.numEntries = 1;
1019// if(DirInfo && DirInfo->Dloc && DirInfo->Dloc
1020 FileEntry->icbTag.strategyType = 4;
1021// FileEntry->icbTag.strategyParameter = 0;
1022 FileEntry->descTag.tagIdent = Extended ? TID_EXTENDED_FILE_ENTRY : TID_FILE_ENTRY;
1023 FileEntry->descTag.tagLocation = UDFPhysLbaToPart(Vcb, PartNum, _FEExtInfo.Mapping[0].extLocation);
1024 FileEntry->uid = Vcb->DefaultUID;
1025 FileEntry->gid = Vcb->DefaultGID;
1026
1027 if(Extended) {
1028// eID = &(((PEXTENDED_FILE_ENTRY)FileEntry)->impIdent);
1029 lcp = &(((PEXTENDED_FILE_ENTRY)FileEntry)->fileLinkCount);
1030 ((PEXTENDED_FILE_ENTRY)FileEntry)->checkpoint = 1;
1031 } else {
1032// eID = &(FileEntry->impIdent);
1033 lcp = &(FileEntry->fileLinkCount);
1034 ((PFILE_ENTRY)FileEntry)->checkpoint = 1;
1035 }
1036
1037#if 0
1039#endif
1040
1041 /*RtlCopyMemory((int8*)&(eID->ident), UDF_ID_DEVELOPER, sizeof(UDF_ID_DEVELOPER) );
1042 iis = (impIdentSuffix*)&(eID->identSuffix);
1043 iis->OSClass = UDF_OS_CLASS_WINNT;
1044 iis->OSIdent = UDF_OS_ID_WINNT;*/
1045
1046 *lcp = 0xffff;
1047
1048 FileInfo->Dloc->FileEntry = (tag*)FileEntry;
1049 FileInfo->Dloc->FileEntryLen = l;
1050
1051 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_FE_MODIFIED;
1052
1053 return STATUS_SUCCESS;
1054} // end UDFBuildFileEntry()
uint32 UDFPhysLbaToPart(IN PVCB Vcb, IN uint32 PartNum, IN uint32 Addr)
Definition: alloc.cpp:46
OSSTATUS UDFStoreDloc(IN PVCB Vcb, IN PUDF_FILE_INFO fi, IN uint32 Lba)
Definition: dirtree.cpp:1240
OSSTATUS UDFRemoveDloc(IN PVCB Vcb, IN PUDF_DATALOC_INFO Dloc)
Definition: dirtree.cpp:1299
LONG UDFFindDloc(IN PVCB Vcb, IN uint32 Lba)
Definition: dirtree.cpp:1127
struct _EXTENDED_FILE_ENTRY EXTENDED_FILE_ENTRY
#define TID_EXTENDED_FILE_ENTRY
Definition: ecma_167.h:175
#define TID_FILE_ENTRY
Definition: ecma_167.h:170
#define UDF_FILE_TYPE_REGULAR
Definition: ecma_167.h:469
struct _EXTENDED_FILE_ENTRY * PEXTENDED_FILE_ENTRY
OSSTATUS UDFAllocateFESpace(IN PVCB Vcb, IN PUDF_FILE_INFO DirInfo, IN uint32 PartNum, IN PEXTENT_INFO FEExtInfo, IN uint32 Len)
Definition: extent.cpp:1563
void UDFFreeFESpace(IN PVCB Vcb, IN PUDF_FILE_INFO DirInfo, IN PEXTENT_INFO FEExtInfo)
Definition: extent.cpp:1725
#define MyAllocatePoolTag__(type, size, tag)
Definition: mem_tools.h:150
#define UDF_ID_DEVELOPER
Definition: osta_misc.h:20
Definition: shlfileop.cpp:53
uint32 extLocation
Definition: ecma_167.h:129
PEXTENT_MAP Mapping
Definition: udf_rel.h:66
Definition: ecma_167.h:513
tag descTag
Definition: ecma_167.h:514
uint16 fileLinkCount
Definition: ecma_167.h:519
uint32 gid
Definition: ecma_167.h:517
icbtag icbTag
Definition: ecma_167.h:515
uint32 uid
Definition: ecma_167.h:516
uint16 numEntries
Definition: ecma_167.h:456
uint8 fileType
Definition: ecma_167.h:458
uint16 strategyType
Definition: ecma_167.h:454
uint16 flags
Definition: ecma_167.h:460
Definition: ecma_167.h:138
uint32 tagLocation
Definition: ecma_167.h:146
uint16 tagIdent
Definition: ecma_167.h:139
#define UDFSetEntityID_imp(eID, Str)
Definition: udf_info.h:598
#define MEM_FE_TAG
Definition: udf_rel.h:486

Referenced by UDFCreateFile__(), and UDFCreateRootFile__().

◆ UDFBuildFileIdent()

OSSTATUS UDFBuildFileIdent ( IN PVCB  Vcb,
IN PUNICODE_STRING  fn,
IN PLONG_AD  FileEntryIcb,
IN uint32  ImpUseLen,
OUT PFILE_IDENT_DESC _FileId,
OUT uint32 FileIdLen 
)

Definition at line 1107 of file udf_info.cpp.

1115{
1116 PFILE_IDENT_DESC FileId;
1117 uint8* CS0;
1118 SIZE_T Nlen;
1119 uint32 l;
1120 // prepare filename
1121 UDFCompressUnicode(fn, &CS0, &Nlen);
1122 if(!CS0) return STATUS_INSUFFICIENT_RESOURCES;
1123 if(Nlen < 2) {
1124 Nlen = 0;
1125 } else
1126 if(Nlen > UDF_NAME_LEN) {
1127 if(CS0) MyFreePool__(CS0);
1129 }
1130 // allocate memory for FI
1131 l = (sizeof(FILE_IDENT_DESC) + Nlen + ImpUseLen + 3) & ~((uint32)3);
1133 if(!FileId) {
1134 if(CS0) MyFreePool__(CS0);
1136 }
1137 // fill FI structure
1138 RtlZeroMemory( (int8*)FileId, l);
1139 RtlCopyMemory( ((int8*)(FileId+1))+ImpUseLen, CS0, Nlen);
1141 FileId->fileVersionNum = 1;
1142 FileId->lengthOfImpUse = (uint16)ImpUseLen;
1143 FileId->lengthFileIdent = (uint8)Nlen;
1144 FileId->icb = *FileEntryIcb;
1145 *_FileId = FileId;
1146 *FileIdLen = l;
1147
1148 if(CS0) MyFreePool__(CS0);
1149 return STATUS_SUCCESS;
1150} // end UDFBuildFileIdent()
unsigned char uint8
Definition: types.h:28
struct _FILE_IDENT_DESC * PFILE_IDENT_DESC
struct _FILE_IDENT_DESC FILE_IDENT_DESC
#define TID_FILE_IDENT_DESC
Definition: ecma_167.h:166
#define UDF_NAME_LEN
Definition: osta_misc.h:314
uint16 lengthOfImpUse
Definition: ecma_167.h:431
uint16 fileVersionNum
Definition: ecma_167.h:427
uint8 lengthFileIdent
Definition: ecma_167.h:429
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
void __fastcall UDFCompressUnicode(IN PUNICODE_STRING UName, IN OUT uint8 **_CS0, IN OUT PSIZE_T Length)
Definition: udf_info.cpp:240
#define MEM_FID_TAG
Definition: udf_rel.h:488
#define STATUS_OBJECT_NAME_INVALID
Definition: udferr_usr.h:148
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159

Referenced by UDFCreateFile__(), and UDFRecordDirectory__().

◆ UDFBuildFreeSpaceBitmap()

OSSTATUS UDFBuildFreeSpaceBitmap ( IN PVCB  Vcb,
IN uint32  PartNdx,
IN PPARTITION_HEADER_DESC  phd,
IN uint32  Lba 
)

Definition at line 1910 of file mount.cpp.

1916{
1918 uint32 i, l;
1919 uint16 Ident;
1920 int8* AllocDesc;
1922 lb_addr locAddr;
1923 uint32 PartNum;
1924
1925 PartNum = UDFGetPartNumByPartNdx(Vcb, PartNdx);
1926 if(!(Vcb->FSBM_Bitmap)) {
1927 // init Bitmap buffer if necessary
1928 Vcb->FSBM_Bitmap = (int8*)DbgAllocatePool(NonPagedPool, (i = (Vcb->LastPossibleLBA+1+7)>>3) );
1929 if(!(Vcb->FSBM_Bitmap)) return STATUS_INSUFFICIENT_RESOURCES;
1930
1931 Vcb->ZSBM_Bitmap = (int8*)DbgAllocatePool(NonPagedPool, (i = (Vcb->LastPossibleLBA+1+7)>>3) );
1932 if(!(Vcb->ZSBM_Bitmap)) {
1933#ifdef UDF_TRACK_ONDISK_ALLOCATION_OWNERS
1934free_fsbm:
1935#endif //UDF_TRACK_ONDISK_ALLOCATION_OWNERS
1936 MyFreePool__(Vcb->FSBM_Bitmap);
1937 Vcb->FSBM_Bitmap = NULL;
1939 }
1940
1941 RtlZeroMemory(Vcb->FSBM_Bitmap, i);
1942 RtlZeroMemory(Vcb->ZSBM_Bitmap, i);
1943#ifdef UDF_TRACK_ONDISK_ALLOCATION_OWNERS
1944 Vcb->FSBM_Bitmap_owners = (uint32*)DbgAllocatePool(NonPagedPool, (Vcb->LastPossibleLBA+1)*sizeof(uint32));
1945 if(!(Vcb->FSBM_Bitmap_owners)) {
1946 MyFreePool__(Vcb->ZSBM_Bitmap);
1947 Vcb->ZSBM_Bitmap = NULL;
1948 goto free_fsbm;
1949 }
1950 RtlFillMemory(Vcb->FSBM_Bitmap_owners, (Vcb->LastPossibleLBA+1)*sizeof(uint32), 0xff);
1951#endif //UDF_TRACK_ONDISK_ALLOCATION_OWNERS
1952 Vcb->FSBM_ByteCount = i;
1953 Vcb->FSBM_BitCount = Vcb->LastPossibleLBA+1;
1954 }
1955 // read info for partition header (if any)
1956 if(phd) {
1957 // read unallocated Bitmap
1958 if(!OS_SUCCESS(status = UDFAddXSpaceBitmap(Vcb, PartNum, &(phd->unallocatedSpaceBitmap), UDF_FSPACE_BM)))
1959 return status;
1960 // read freed Bitmap
1961 if(!OS_SUCCESS(status = UDFAddXSpaceBitmap(Vcb, PartNum, &(phd->freedSpaceBitmap), UDF_ZSPACE_BM)))
1962 return status;
1963 }
1964 // read UnallocatedSpaceDesc & convert to Bitmap
1965 if(Lba) {
1966 if(!(AllocDesc = (int8*)MyAllocatePool__(NonPagedPool, Vcb->LBlockSize + sizeof(EXTENT_AD) )))
1968 RtlZeroMemory(((int8*)AllocDesc) + Vcb->LBlockSize, sizeof(EXTENT_AD));
1969 if(!OS_SUCCESS(status = UDFReadTagged(Vcb, AllocDesc, Lba, Lba, &Ident)) ||
1970 !(Extent = (PEXTENT_MAP)MyAllocatePool__(NonPagedPool, l = (((PUNALLOC_SPACE_DESC)AllocDesc)->numAllocDescs+1) * sizeof(EXTENT_AD) ))) {
1971 MyFreePool__(AllocDesc);
1972 return status;
1973 }
1974 UDFRegisterFsStructure(Vcb, Lba, Vcb->BlockSize);
1975 RtlCopyMemory((int8*)Extent, AllocDesc+sizeof(UNALLOC_SPACE_DESC), (((PUNALLOC_SPACE_DESC)AllocDesc)->numAllocDescs+1) * sizeof(EXTENT_AD) );
1976 locAddr.partitionReferenceNum = (uint16)PartNum;
1977 // read extent is recorded with relative addresses
1978 // so, we should convert it to suitable form
1979 for(i=0; Extent[i].extLength; i++) {
1980 locAddr.logicalBlockNum = Extent[i].extLocation;
1981 Extent[i].extLocation = UDFPartLbaToPhys(Vcb, &locAddr);
1982 if(Extent[i].extLocation == LBA_OUT_OF_EXTENT) {
1983 BrutePoint();
1984 MyFreePool__(AllocDesc);
1986 }
1987 if((Extent[i].extLocation >> 30) == EXTENT_NEXT_EXTENT_ALLOCDESC) {
1988 // load continuation
1989 Lba = Extent[i].extLocation & UDF_EXTENT_LENGTH_MASK;
1990 if(!OS_SUCCESS(status = UDFReadTagged(Vcb, AllocDesc, Lba, Lba, &Ident)) ||
1991 !(Extent = (PEXTENT_MAP)MyAllocatePool__(NonPagedPool, (((PUNALLOC_SPACE_DESC)AllocDesc)->numAllocDescs+1) * sizeof(EXTENT_AD) ))) {
1992 MyFreePool__(AllocDesc);
1993 return status;
1994 }
1995 if(Ident == TID_UNALLOC_SPACE_DESC) {
1996 UDFRegisterFsStructure(Vcb, Lba, Vcb->BlockSize);
1997 if(!(l = MyReallocPool__((int8*)Extent, l, (int8**)&Extent, i*sizeof(EXTENT_MAP)))) {
1999 MyFreePool__(AllocDesc);
2001 }
2002 Extent[i].extLength =
2003 Extent[i].extLocation = 0;
2005#ifdef UDF_DBG
2006 } else {
2007 UDFPrint(("Broken unallocated space descriptor sequence\n"));
2008#endif // UDF_DBG
2009 }
2010 }
2011 }
2012 UDFMarkSpaceAsXXX(Vcb, (-1), Extent, AS_USED); // mark as used
2014 MyFreePool__(AllocDesc);
2015 }
2016 return status;
2017} // end UDFVerifyFreeSpaceBitmap()
#define EXTENT_NEXT_EXTENT_ALLOCDESC
Definition: ecma_167.h:370
#define TID_UNALLOC_SPACE_DESC
Definition: ecma_167.h:160
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:599
ULONG MyReallocPool__(PCHAR addr, ULONG len, PCHAR *pnewaddr, ULONG newlen)
Definition: mem_tools.h:230
OSSTATUS UDFAddXSpaceBitmap(IN PVCB Vcb, IN uint32 PartNum, IN PSHORT_AD bm, IN ULONG bm_type)
Definition: mount.cpp:1569
#define UDF_ZSPACE_BM
Definition: udf_info.h:446
#define UDFGetPartNumByPartNdx(Vcb, pi)
Definition: udf_info.h:1028
#define UDFMarkSpaceAsXXX(Vcb, FileInfo, Map, asXXX)
Definition: udf_info.h:322
#define LBA_OUT_OF_EXTENT
Definition: udf_rel.h:426

Referenced by UDFLoadPartDesc(), and UDFProcessSequence().

◆ UDFBuildHashEntry()

uint8 UDFBuildHashEntry ( IN PVCB  Vcb,
IN PUNICODE_STRING  Name,
OUT PHASH_ENTRY  hashes,
IN uint8  Mask 
)

Definition at line 429 of file dirtree.cpp.

435{
436 UNICODE_STRING UName;
437 WCHAR ShortNameBuffer[13];
438 uint8 RetFlags = 0;
439
440 if(!Name->Buffer) return 0;
441
442 if(Mask & HASH_POSIX)
443 hashes->hPosix = crc32((uint8*)(Name->Buffer), Name->Length);
444
445 if(Mask & HASH_ULFN) {
446/* if(OS_SUCCESS(MyInitUnicodeString(&UName, L"")) &&
447 OS_SUCCESS(MyAppendUnicodeStringToStringTag(&UName, Name, MEM_USDIRHASH_TAG))) {*/
448 if(OS_SUCCESS(MyCloneUnicodeString(&UName, Name))) {
449 RtlUpcaseUnicodeString(&UName, &UName, FALSE);
450 /* if(!RtlCompareUnicodeString(Name, &UName, FALSE)) {
451 RetFlags |= UDF_FI_FLAG_LFN;
452 }*/
453 hashes->hLfn = crc32((uint8*)(UName.Buffer), UName.Length);
454 } else {
455 BrutePoint();
456 }
457 MyFreePool__(UName.Buffer);
458 }
459
460 if(Mask & HASH_DOS) {
461 UName.Buffer = (PWCHAR)(&ShortNameBuffer);
462 UName.MaximumLength = 13*sizeof(WCHAR);
463 UDFDOSName(Vcb, &UName, Name, (Mask & HASH_KEEP_NAME) ? TRUE : FALSE);
464 if(!RtlCompareUnicodeString(Name, &UName, TRUE)) {
465 RetFlags |= UDF_FI_FLAG_DOS;
466 }
467 hashes->hDos = crc32((uint8*)(UName.Buffer), UName.Length);
468 }
469 return RetFlags;
470} // UDFBuildHashEntry()
NTSTATUS MyCloneUnicodeString(IN PUNICODE_STRING Str1, IN PUNICODE_STRING Str2)
#define crc32(crc, buf, len)
Definition: inflate.c:1081
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
NTSTATUS RtlUpcaseUnicodeString(PUNICODE_STRING dst, PUNICODE_STRING src, BOOLEAN Alloc)
Definition: string_lib.cpp:46
unsigned int Mask
Definition: fpcontrol.c:82
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWCHAR
Definition: typedefs.h:56
void __fastcall UDFDOSName(IN PVCB Vcb, IN OUT PUNICODE_STRING DosName, IN PUNICODE_STRING UdfName, IN BOOLEAN KeepIntact)
Definition: udf_info.cpp:427
#define HASH_ULFN
Definition: udf_info.h:76
#define HASH_KEEP_NAME
Definition: udf_info.h:79
#define HASH_DOS
Definition: udf_info.h:77
#define HASH_POSIX
Definition: udf_info.h:75
#define UDF_FI_FLAG_DOS
Definition: udf_rel.h:225
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by UDFBlankMount(), UDFCreateFile__(), UDFFindFile(), UDFIndexDirectory(), UDFQueryDirectory(), and UDFRenameMoveFile__().

◆ UDFBuildLongAllocDescs()

OSSTATUS UDFBuildLongAllocDescs ( IN PVCB  Vcb,
IN uint32  PartNum,
OUT int8 **  Buff,
IN uint32  InitSz,
IN OUT PUDF_FILE_INFO  FileInfo 
)

Definition at line 1012 of file extent.cpp.

1019{
1020 uint32 i, j;
1021 uint32 len=0;
1022 PEXTENT_MAP Extent = FileInfo->Dloc->DataLoc.Mapping;
1023 PEXTENT_INFO AllocExtent = &(FileInfo->Dloc->AllocLoc);
1025 uint32 NewLen;
1027 uint32 ph_len=0; // in general, this should be uint64,
1028 // but we need its lower part only
1029#ifdef UDF_ALLOW_FRAG_AD
1030 uint32 ac, len2, ts;
1031 uint32 TagLoc, prevTagLoc;
1032 uint32 LBS = Vcb->LBlockSize;
1033 uint32 LBSh = Vcb->BlockSizeBits;
1034 uint32 BufOffs;
1035 uint32 ExtOffs = AllocExtent->Offset;
1036 PLONG_AD saved_Alloc;
1037 uint32 TagLen = 0;
1038 tag* Tag = NULL;
1039#endif //UDF_ALLOW_FRAG_AD
1040
1042 ExtPrint(("UDFBuildLongAllocDescs: FE %x\n", FileInfo->Dloc->FELoc.Mapping[0].extLocation));
1043 // calculate length
1044 //for(len=0; i=(Extent[len].extLength & UDF_EXTENT_LENGTH_MASK); len++, ph_len+=i);
1045 for(len=0; (i=(Extent[len].extLength & UDF_EXTENT_LENGTH_MASK)); len++, ph_len+=i) {
1046 ExtPrint(("bLnExt: type %x, loc %x, len %x\n",
1047 Extent[len].extLength >> 30, Extent[len].extLocation, Extent[len].extLength & UDF_EXTENT_LENGTH_MASK));
1048 }
1051 // fill contiguous AllocDesc buffer (decribing UserData)
1052 for(i=0;i<len;i++) {
1053 Alloc[i].extLength = Extent[i].extLength;
1054 Alloc[i].extLocation.logicalBlockNum = UDFPhysLbaToPart(Vcb, PartNum, Extent[i].extLocation);
1055 Alloc[i].extLocation.partitionReferenceNum = (uint16)PartNum;
1056 RtlZeroMemory(&(Alloc[i].impUse), sizeof(Alloc[i].impUse));
1057 }
1058 if((Vcb->CompatFlags & UDF_VCB_IC_W2K_COMPAT_ALLOC_DESCS) && i) {
1059 Alloc[i-1].extLength -= (ph_len - (ULONG)(FileInfo->Dloc->DataLoc.Length)) &
1060 (Vcb->LBlockSize-1);
1061 ExtPrint(("bLnExt: cut tail -> %x\n",
1062 Alloc[i-1].extLength & UDF_EXTENT_LENGTH_MASK));
1063 }
1064 RtlZeroMemory(&(Alloc[i]), sizeof(LONG_AD));
1065 j = len*sizeof(LONG_AD); // required space
1066 len = (InitSz & ~(sizeof(LONG_AD)-1)); // space available in 1st block
1067 ASSERT(len == InitSz);
1068
1069 // Ok. Let's init AllocLoc
1070 if(!(FileInfo->Dloc->AllocLoc.Mapping)) {
1071 FileInfo->Dloc->AllocLoc.Mapping = (PEXTENT_MAP)MyAllocatePoolTag__(NonPagedPool, 2 * sizeof(EXTENT_MAP), MEM_EXTMAP_TAG);
1072 if(!(FileInfo->Dloc->AllocLoc.Mapping)) {
1075 }
1076 // allocation descriptors are located in the same sector as FileEntry
1077 // (at least their 1st part), just after it
1078 FileInfo->Dloc->AllocLoc.Mapping[0] = FileInfo->Dloc->FELoc.Mapping[0];
1079 FileInfo->Dloc->AllocLoc.Offset = FileInfo->Dloc->FileEntryLen;
1080 FileInfo->Dloc->AllocLoc.Length = 0;
1081 // set terminator
1082 FileInfo->Dloc->AllocLoc.Mapping[1].extLength =
1083 FileInfo->Dloc->AllocLoc.Mapping[1].extLocation = 0;
1084 }
1085
1086 if(j <= len) {
1087 // we needn't allocating additional blocks to store AllocDescs
1088 RtlCopyMemory(*Buff, (int8*)Alloc, j);
1089 NewLen = j;
1091 } else {
1092#ifndef UDF_ALLOW_FRAG_AD
1093 AdPrint((" DISK_FULL\n"));
1094 return STATUS_DISK_FULL;
1095#else //UDF_ALLOW_FRAG_AD
1096 BufOffs = 0;
1097 TagLoc = prevTagLoc = 0;
1098 // calculate the space available for LONG_ADs in each block
1099 ac = (LBS - (sizeof(ALLOC_EXT_DESC) + sizeof(LONG_AD))) & ~(sizeof(LONG_AD)-1);
1100 len2 = len;
1101 // tail size
1102 ts = InitSz - len2;
1103 len -= sizeof(LONG_AD);
1104 // calculate actual AllocSequence length (in LBlocks)
1105 NewLen = ( ((j - len + ac - 1) / ac) << LBSh) + InitSz + sizeof(LONG_AD);
1106 MyFreePool__(*Buff);
1107 (*Buff) = (int8*)MyAllocatePoolTag__(NonPagedPool, NewLen, MEM_LNGAD_TAG);
1108 if(!(*Buff)) {
1110 goto lad_alloc_err;
1111 }
1112 if(UDFGetExtentLength(AllocExtent->Mapping) < NewLen) {
1113 status = UDFResizeExtent(Vcb, PartNum, NewLen, TRUE, AllocExtent);
1114 if(!OS_SUCCESS(status)) {
1115lad_alloc_err:
1117 return status;
1118 }
1119 }
1120 ExtOffs = AllocExtent->Offset;
1121 RtlZeroMemory(*Buff, NewLen);
1122 NewLen = 0; // recorded length
1123 saved_Alloc = Alloc;
1124 len2 = len+sizeof(LONG_AD);
1125 // fill buffer sector by sector (adding links at the end of each one)
1126 while(TRUE) {
1127
1128 // j - remained AllocDescs length (in bytes)
1129 // len - bytes available for in AllocDescs each block
1130
1131 // leave space for terminator or pointer to next part of sequence
1132 if(j == len2) {
1133 // if we have only 1 LONG_AD that we can fit in last sector
1134 // we shall do it instead of recording link & allocating new block
1135 len =
1136 TagLen = len2;
1137 }
1138 RtlCopyMemory( (*Buff)+BufOffs, (int8*)Alloc, len);
1139 Alloc = (PLONG_AD)((int8*)Alloc + len);
1140 j -= len;
1141 BufOffs += len;
1142 if(Tag) {
1143 // Set up Tag for AllocDesc
1144 Tag->tagIdent = TID_ALLOC_EXTENT_DESC;
1145 UDFSetUpTag(Vcb, Tag, (uint16)TagLen, TagLoc);
1146 prevTagLoc = TagLoc;
1147 }
1148 if(!j) {
1149 // terminate loop
1150 NewLen = BufOffs;
1151 break;
1152 }
1153 len = ac;
1154 if(j <= (len + sizeof(LONG_AD)))
1155 len = j - sizeof(LONG_AD);
1156 len2 = len+sizeof(LONG_AD);
1157 // we have more than 1 LONG_AD that we can't fit in current block
1158 // so we shall set up pointer to the next block
1159 ((PLONG_AD)((*Buff)+BufOffs))->extLength = /*LBS*/ len2 |
1161 ((PLONG_AD)((*Buff)+BufOffs))->extLocation.logicalBlockNum = TagLoc =
1162 UDFPhysLbaToPart(Vcb, PartNum,
1163 UDFExtentOffsetToLba(Vcb, AllocExtent->Mapping,
1164 ExtOffs+BufOffs+sizeof(LONG_AD)+ts,
1165 NULL, NULL, NULL, NULL) );
1166 ((PLONG_AD)((*Buff)+BufOffs))->extLocation.partitionReferenceNum = (uint16)PartNum;
1167 // reflect additional (link) block & LBlock tail (if any)
1168 BufOffs += ts+sizeof(LONG_AD);
1169 // init AllocDesc
1170 ( (PALLOC_EXT_DESC) ((*Buff)+BufOffs))->lengthAllocDescs = len2;
1171 ( (PALLOC_EXT_DESC) ((*Buff)+BufOffs))->previousAllocExtLocation = prevTagLoc;
1172 Tag = (tag*)((*Buff)+BufOffs);
1173 TagLen = len2;
1174 ts = LBS-len2-sizeof(ALLOC_EXT_DESC);
1175 BufOffs += sizeof(ALLOC_EXT_DESC);
1176 }
1177 MyFreePool__(saved_Alloc);
1178#endif //UDF_ALLOW_FRAG_AD
1179 }
1180 status = UDFResizeExtent(Vcb, PartNum, NewLen, TRUE, AllocExtent);
1181 return status;
1182} // end UDFBuildLongAllocDescs()
PVOID Alloc(IN DWORD dwFlags, IN SIZE_T dwBytes)
Definition: main.c:63
struct _ALLOC_EXT_DESC ALLOC_EXT_DESC
PEXTENT_AD PEXTENT_MAP
Definition: ecma_167.h:135
struct _ALLOC_EXT_DESC * PALLOC_EXT_DESC
long_ad LONG_AD
Definition: ecma_167.h:379
LONG_AD * PLONG_AD
Definition: ecma_167.h:380
#define TID_ALLOC_EXTENT_DESC
Definition: ecma_167.h:167
#define ExtPrint(_x_)
Definition: env_spec_w32.h:294
uint32 UDFExtentOffsetToLba(IN PVCB Vcb, IN PEXTENT_MAP Extent, IN int64 Offset, OUT uint32 *SectorOffset, OUT PSIZE_T AvailLength, OUT uint32 *Flags, OUT uint32 *Index)
Definition: extent.cpp:28
OSSTATUS UDFResizeExtent(IN PVCB Vcb, IN uint32 PartNum, IN int64 Length, IN BOOLEAN AlwaysInIcb, OUT PEXTENT_INFO ExtInfo)
Definition: extent.cpp:2235
uint32 Offset
Definition: udf_rel.h:65
#define UDF_VCB_IC_W2K_COMPAT_ALLOC_DESCS
Definition: udf_common.h:501
void UDFSetUpTag(IN PVCB Vcb, IN tag *Tag, IN uint16 DataLen, IN uint32 TagLoc)
Definition: udf_info.cpp:936
#define MEM_EXTMAP_TAG
Definition: udf_rel.h:492
#define MEM_LNGAD_TAG
Definition: udf_rel.h:495
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065

Referenced by UDFBuildAllocDescs().

◆ UDFBuildShortAllocDescs()

OSSTATUS UDFBuildShortAllocDescs ( IN PVCB  Vcb,
IN uint32  PartNum,
OUT int8 **  Buff,
IN uint32  InitSz,
IN OUT PUDF_FILE_INFO  FileInfo 
)

Definition at line 825 of file extent.cpp.

832{
833 uint32 i, j;
834 uint32 len=0;
835 PEXTENT_MAP Extent = FileInfo->Dloc->DataLoc.Mapping;
836 PEXTENT_INFO AllocExtent = &(FileInfo->Dloc->AllocLoc);
838 uint32 NewLen;
840 uint32 ph_len=0; // in general, this should be uint64,
841 // but we need its lower part only
842#ifdef UDF_ALLOW_FRAG_AD
843 uint32 ts, ac, len2;
844 uint32 LBS = Vcb->LBlockSize;
845 uint32 LBSh = Vcb->BlockSizeBits;
846 uint32 TagLen = 0;
847 tag* Tag = NULL;
848 PSHORT_AD saved_Alloc;
849 uint32 TagLoc, prevTagLoc;
850 uint32 BufOffs;
851 uint32 ExtOffs;
852 uint32 saved_NewLen;
853#endif //UDF_ALLOW_FRAG_AD
854
856 ExtPrint(("UDFBuildShortAllocDescs: FE %x\n", FileInfo->Dloc->FELoc.Mapping[0].extLocation));
857 // calculate length
858 for(len=0; (i=(Extent[len].extLength & UDF_EXTENT_LENGTH_MASK)); len++, ph_len+=i) {
859 ExtPrint(("bShExt: type %x, loc %x, len %x\n",
860 Extent[len].extLength >> 30, Extent[len].extLocation, Extent[len].extLength & UDF_EXTENT_LENGTH_MASK));
861 }
863 if(!Alloc) {
864 BrutePoint();
866 }
867 // fill contiguous AllocDesc buffer (decribing UserData)
868 for(i=0;i<len;i++) {
869 Alloc[i].extLength = Extent[i].extLength;
870 Alloc[i].extPosition = UDFPhysLbaToPart(Vcb, PartNum, Extent[i].extLocation);
871 }
872 if((Vcb->CompatFlags & UDF_VCB_IC_W2K_COMPAT_ALLOC_DESCS) && i) {
873 Alloc[i-1].extLength -= (ph_len - (ULONG)(FileInfo->Dloc->DataLoc.Length)) &
874 (Vcb->LBlockSize-1);
875 ExtPrint(("bShExt: cut tail -> %x\n",
876 Alloc[i-1].extLength & UDF_EXTENT_LENGTH_MASK));
877 }
878 Alloc[i].extLength =
879 Alloc[i].extPosition = 0;
880 j = len*sizeof(SHORT_AD); // required space
881 len = (InitSz & ~(sizeof(SHORT_AD)-1)); // space available in 1st block
882 ASSERT(len == InitSz);
883
884 // Ok. Let's init AllocLoc
885 if(!(FileInfo->Dloc->AllocLoc.Mapping)) {
886 FileInfo->Dloc->AllocLoc.Mapping = (PEXTENT_MAP)MyAllocatePoolTag__(NonPagedPool, 2 * sizeof(EXTENT_MAP), MEM_EXTMAP_TAG);
887 if(!(FileInfo->Dloc->AllocLoc.Mapping)) {
888 BrutePoint();
891 }
892 // allocation descriptors are located in the same sector as FileEntry
893 // (at least their 1st part), just after it
894 FileInfo->Dloc->AllocLoc.Mapping[0] = FileInfo->Dloc->FELoc.Mapping[0];
895 FileInfo->Dloc->AllocLoc.Offset = FileInfo->Dloc->FileEntryLen;
896 FileInfo->Dloc->AllocLoc.Length = 0;
897 // set terminator
898 FileInfo->Dloc->AllocLoc.Mapping[1].extLength =
899 FileInfo->Dloc->AllocLoc.Mapping[1].extLocation = 0;
900 }
901
902 if(j <= len) {
903 // we needn't allocating additional blocks to store AllocDescs
904 AdPrint(("in-ICB AllocDescs, j=%x\n",j));
905 RtlCopyMemory(*Buff, (int8*)Alloc, j);
906 NewLen = j;
908 } else {
909#ifndef UDF_ALLOW_FRAG_AD
910 AdPrint((" DISK_FULL\n"));
911 return STATUS_DISK_FULL;
912#else //UDF_ALLOW_FRAG_AD
913 AdPrint(("multi-block AllocDescs, j=%x\n",j));
914 BufOffs = 0;
915 TagLoc = prevTagLoc = 0;
916 // calculate the space available for SHORT_ADs in each block
917 ac = (LBS - (sizeof(ALLOC_EXT_DESC) + sizeof(SHORT_AD))) & ~(sizeof(SHORT_AD)-1);
918 len2 = len;
919 // tail size
920 ts = InitSz - len2;
921 len -= sizeof(SHORT_AD);
922 // calculate actual AllocSequence length (in bytes)
923 NewLen = ( ((j - len + ac - 1) / ac) << LBSh) + InitSz + sizeof(SHORT_AD);
924 MyFreePool__(*Buff);
926 if(!(*Buff)) {
928 UDFPrint(("UDFResizeExtent() failed (%x)\n",status));
929 BrutePoint();
930 goto sh_alloc_err;
931 }
932 if(UDFGetExtentLength(AllocExtent->Mapping) < NewLen) {
933 status = UDFResizeExtent(Vcb, PartNum, NewLen, TRUE, AllocExtent);
934 if(!OS_SUCCESS(status)) {
935 UDFPrint(("UDFResizeExtent(2) failed (%x)\n",status));
936 BrutePoint();
937sh_alloc_err:
939 return status;
940 }
941 }
942 ExtOffs = AllocExtent->Offset;
943 RtlZeroMemory(*Buff, NewLen);
944 saved_NewLen = NewLen;
945 NewLen = 0; // recorded length
946 saved_Alloc = Alloc;
947 // fill buffer sector by sector (adding links at the end of each one)
948 while(TRUE) {
949
950 // j - remained AllocDescs length (in bytes)
951 // len - bytes available for AllocDescs in current block
952 // ac - bytes available for AllocDescs in each block
953
954 // leave space for terminator or pointer to next part of sequence
955 if(j == len2) {
956 // if we have only 1 SHORT_AD that we can fit in last sector
957 // we shall do it instead of recording link & allocating new block
958 len =
959 TagLen = len2;
960 }
961 ASSERT(saved_NewLen >= (BufOffs + len));
962 RtlCopyMemory( (*Buff)+BufOffs, (int8*)Alloc, len);
963 Alloc = (PSHORT_AD)((int8*)Alloc + len);
964 j -= len;
965 BufOffs += len;
966 if(Tag) {
967 // Set up Tag for AllocDesc
968 Tag->tagIdent = TID_ALLOC_EXTENT_DESC;
969 UDFSetUpTag(Vcb, Tag, (uint16)TagLen, TagLoc);
970 prevTagLoc = TagLoc;
971 }
972 if(!j) {
973 // terminate loop
974 NewLen = BufOffs;
975 break;
976 }
977 len = ac;
978 if(j <= (len + sizeof(SHORT_AD)))
979 len = j - sizeof(SHORT_AD);
980 len2 = len + sizeof(SHORT_AD);
981 // we have more than 1 SHORT_AD that we can't fit in current block
982 // so we shall set up pointer to the next block
983 ((PSHORT_AD)((*Buff)+BufOffs))->extLength = /*LBS*/ len2 |
985 ((PSHORT_AD)((*Buff)+BufOffs))->extPosition = TagLoc =
986 UDFPhysLbaToPart(Vcb, PartNum,
987 UDFExtentOffsetToLba(Vcb, AllocExtent->Mapping,
988 ExtOffs+BufOffs+sizeof(SHORT_AD)+ts,
989 NULL, NULL, NULL, NULL) );
990 // reflect additional (link) block & LBlock tail (if any)
991 BufOffs += ts+sizeof(SHORT_AD);
992 // init AllocDesc
993 ( (PALLOC_EXT_DESC) ((*Buff)+BufOffs))->lengthAllocDescs = len2;
994 ( (PALLOC_EXT_DESC) ((*Buff)+BufOffs))->previousAllocExtLocation = prevTagLoc;
995 Tag = (tag*)((*Buff)+BufOffs);
996 TagLen = len2;
997 ts = LBS-len2-sizeof(ALLOC_EXT_DESC);
998 BufOffs += sizeof(ALLOC_EXT_DESC);
999 }
1000 MyFreePool__(saved_Alloc);
1001#endif //UDF_ALLOW_FRAG_AD
1002 }
1003 status = UDFResizeExtent(Vcb, PartNum, NewLen, TRUE, AllocExtent);
1004 return status;
1005} // end UDFBuildShortAllocDescs()
struct _SHORT_AD * PSHORT_AD
struct _SHORT_AD SHORT_AD
#define MEM_SHAD_TAG
Definition: udf_rel.h:494

Referenced by UDFBuildAllocDescs().

◆ UDFChangeFileCounter()

void UDFChangeFileCounter ( IN PVCB  Vcb,
IN BOOLEAN  FileCounter,
IN BOOLEAN  Increase 
)

Definition at line 1520 of file udf_info.cpp.

1525{
1526 uint32* counter;
1527
1528 counter = FileCounter ?
1529 &(Vcb->numFiles) :
1530 &(Vcb->numDirs);
1531 if(*counter == (ULONG)-1)
1532 return;
1533 if(Increase) {
1535 } else {
1537 }
1538
1539} // end UDFChangeFileCounter()
long int32
Definition: platform.h:12
#define UDFInterlockedDecrement(addr)
Definition: env_spec_w32.h:677
#define UDFInterlockedIncrement(addr)
Definition: env_spec_w32.h:675

Referenced by UDFUnlinkFile__().

◆ UDFChangeFileLinkCount()

void UDFChangeFileLinkCount ( IN PUDF_FILE_INFO  FileInfo,
IN BOOLEAN  Increase 
)

Definition at line 1315 of file udf_info.cpp.

1319{
1320 uint16 Ident;
1321
1323
1324 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_FE_MODIFIED;
1325 Ident = FileInfo->Dloc->FileEntry->tagIdent;
1326 if(Ident == TID_FILE_ENTRY) {
1327 PFILE_ENTRY fe = (PFILE_ENTRY)(FileInfo->Dloc->FileEntry);
1328 if(Increase) {
1329 fe->fileLinkCount++;
1330 } else {
1331 fe->fileLinkCount--;
1332 }
1333 if(fe->fileLinkCount & 0x8000)
1334 fe->fileLinkCount = 0xffff;
1335 return;
1336 } else if(Ident == TID_EXTENDED_FILE_ENTRY) {
1337 PEXTENDED_FILE_ENTRY fe = (PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry);
1338 if(Increase) {
1339 fe->fileLinkCount++;
1340 } else {
1341 fe->fileLinkCount--;
1342 }
1343 if(fe->fileLinkCount & 0x8000)
1344 fe->fileLinkCount = 0xffff;
1345 return;
1346 }
1347 return;
1348} // end UDFChangeFileLinkCount()
Definition: ecma_167.h:742
uint16 fileLinkCount
Definition: ecma_167.h:748

◆ UDFCheckArea()

BOOLEAN __fastcall UDFCheckArea ( IN PVCB  Vcb,
IN lba_t  LBA,
IN uint32  BCount 
)

Definition at line 763 of file remap.cpp.

768{
769 uint8* buff;
770 OSSTATUS RC;
772 uint32 i, d;
773 BOOLEAN ext_ok = TRUE;
774 EXTENT_MAP Map[2];
775 uint32 PS = Vcb->WriteBlockSize >> Vcb->BlockSizeBits;
776
777 buff = (uint8*)DbgAllocatePoolWithTag(NonPagedPool, Vcb->WriteBlockSize, 'bNWD' );
778 if(buff) {
779 for(i=0; i<BCount; i+=d) {
780 if(!((LBA+i) & (PS-1)) &&
781 (i+PS <= BCount)) {
782 d = PS;
783 } else {
784 d = 1;
785 }
786 RC = UDFTRead(Vcb,
787 buff,
788 d << Vcb->BlockSizeBits,
789 LBA+i,
790 &ReadBytes,
792
793 if(RC != STATUS_SUCCESS) {
794 Map[0].extLocation = LBA+i;
795 Map[0].extLength = d << Vcb->BlockSizeBits;
796 UDFMarkSpaceAsXXXNoProtect(Vcb, 0, &(Map[0]), AS_DISCARDED | AS_BAD); // free
797 ext_ok = FALSE;
798 }
799 }
801 }
802 return ext_ok;
803} // end UDFCheckArea()
#define DbgAllocatePoolWithTag(a, b, c)
Definition: env_spec_w32.h:333
static unsigned char buff[32768]
Definition: fatten.c:17
@ PS
#define d
Definition: ke_i.h:81
OSSTATUS UDFTRead(IN void *_Vcb, IN void *Buffer, IN SIZE_T Length, IN uint32 LBA, OUT PSIZE_T ReadBytes, IN uint32 Flags)
Definition: phys_lib.cpp:596
#define PH_TMP_BUFFER
Definition: phys_lib.h:65
uint32 extLength
Definition: ecma_167.h:128
#define AS_BAD
Definition: udf_info.h:329

Referenced by UDFAllocFreeExtent_(), and UDFRemapPacket().

◆ UDFCleanUpFile__()

uint32 UDFCleanUpFile__ ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo 
)

Definition at line 2276 of file udf_info.cpp.

2280{
2281 PUDF_DATALOC_INFO Dloc;
2282 uint32 lc = 0;
2283 BOOLEAN IsASDir;
2284 BOOLEAN KeepDloc;
2285 PDIR_INDEX_ITEM DirNdx, DirNdx2;
2286 BOOLEAN Parallel = FALSE;
2288#ifdef UDF_DBG
2289 BOOLEAN Modified = FALSE;
2290 PDIR_INDEX_HDR hDirNdx;
2291 uint_di Index;
2292 PUDF_FILE_INFO DirInfo;
2293#endif // UDF_DBG
2294
2295 if(!FileInfo) return UDF_FREE_FILEINFO;
2296
2298
2299 if(FileInfo->OpenCount || FileInfo->RefCount) {
2300 UDFPrint(("UDF: not all references are closed\n"));
2301 UDFPrint((" Skipping cleanup\n"));
2302 UDFPrint(("UDF: OpenCount = %x, RefCount = %x, LinkRefCount = %x\n",
2303 FileInfo->OpenCount,FileInfo->RefCount,FileInfo->Dloc->LinkRefCount));
2304 return UDF_FREE_NOTHING;
2305 }
2306 if(FileInfo->Fcb) {
2307 UDFPrint(("Operating System still has references to this file\n"));
2308 UDFPrint((" Skipping cleanup\n"));
2309// BrutePoint();
2310 return UDF_FREE_NOTHING;
2311 }
2312
2313 IsASDir = UDFIsAStreamDir(FileInfo);
2314
2315 if((Dloc = FileInfo->Dloc)) {
2316
2317#ifdef UDF_DBG
2318 DirInfo = FileInfo->ParentFile;
2319 if(DirInfo) {
2320 hDirNdx = DirInfo->Dloc->DirIndex;
2321 Index = FileInfo->Index;
2322 // we can't delete modified file
2323 // it should be closed & reopened (or flushed) before deletion
2324 DirNdx = UDFDirIndex(hDirNdx,Index);
2325 UDFPrint(("Cleanup Mod: %s%s%s%s%s%s\n",
2326 (Dloc->FE_Flags & UDF_FE_FLAG_FE_MODIFIED) ? "FE " : "",
2327 (Dloc->DataLoc.Modified) ? "DataLoc " : "",
2328 (Dloc->DataLoc.Flags & EXTENT_FLAG_PREALLOCATED) ? "Data-PreAlloc " : "",
2329 (Dloc->AllocLoc.Modified) ? "AllocLoc " : "",
2330 (Dloc->FELoc.Modified) ? "FELoc " : "",
2331 (DirNdx && (DirNdx->FI_Flags & UDF_FI_FLAG_FI_MODIFIED)) ? "FI " : ""
2332 ));
2333 Modified = ((Dloc->FE_Flags & UDF_FE_FLAG_FE_MODIFIED) ||
2334 Dloc->DataLoc.Modified ||
2336 Dloc->AllocLoc.Modified ||
2337 Dloc->FELoc.Modified ||
2338 (DirNdx && (DirNdx->FI_Flags & UDF_FI_FLAG_FI_MODIFIED)) );
2339 }
2340#endif // UDF_DBG
2341
2343
2344 Parallel = (ParFileInfo != NULL);
2345 Linked = (FileInfo->NextLinkedFile != FileInfo);
2346
2347// Parallel = (FileInfo->NextLinkedFile != FileInfo);
2348 ASSERT(FileInfo->NextLinkedFile);
2349// ASSERT(!Parallel);
2350 KeepDloc = (Dloc->LinkRefCount ||
2351 Dloc->CommonFcb ||
2352 Linked ) ?
2353 TRUE : FALSE;
2354
2355 if(Dloc->DirIndex) {
2356 uint_di i;
2357 for(i=2; (DirNdx = UDFDirIndex(Dloc->DirIndex,i)); i++) {
2358 if(DirNdx->FileInfo) {
2359 if(!KeepDloc) {
2360 BrutePoint();
2361 UDFPrint(("UDF: Found not cleaned up reference.\n"));
2362 UDFPrint((" Skipping cleanup (1)\n"));
2363// BrutePoint();
2364 return UDF_FREE_NOTHING;
2365 }
2366 // The file being cleaned up may have not closed Dirs
2367 // (linked Dir). In this case each of them may have
2368 // reference to FileInfo in DirIndex[1]
2369 // Here we'll check it and change for valid value if
2370 // necessary (Update Child Objects - I)
2371 if(DirNdx->FileInfo->Dloc) {
2372 // we can get here only when (Parallel == TRUE)
2373 DirNdx2 = UDFDirIndex(DirNdx->FileInfo->Dloc->DirIndex, 1);
2374 // It is enough to check DirNdx2->FileInfo only.
2375 // If one of Parallel FI's has reference (and equal)
2376 // to the FI being removed, it'll be removed from
2377 // the chain & nothing wrong will happen.
2378 if(DirNdx2 && (DirNdx2->FileInfo == FileInfo)) {
2379 if(FileInfo->PrevLinkedFile == FileInfo) {
2380 BrutePoint();
2381 DirNdx2->FileInfo = NULL;
2382 } else {
2383 DirNdx2->FileInfo = Parallel ?
2384 ParFileInfo : FileInfo->PrevLinkedFile;
2385 }
2386 ASSERT(!DirNdx2->FileInfo->RefCount);
2387 }
2388 }
2389 }
2390 }
2391 }
2392 if(Dloc->SDirInfo) {
2393 UDFPrint(("UDF: Found not cleaned up reference (SDir).\n"));
2394
2395 // (Update Child Objects - II)
2396 if(Dloc->SDirInfo->ParentFile == FileInfo) {
2397 BrutePoint();
2398 ASSERT(ParFileInfo);
2399 Dloc->SDirInfo->ParentFile = ParFileInfo;
2400 }
2401 // We should break Cleanup process if alive reference detected
2402 // and there is no possibility to store pointer in some other
2403 // place (in parallel object)
2404 if(!KeepDloc) {
2405 BrutePoint();
2406 UDFPrint((" Skipping cleanup\n"));
2407 return UDF_FREE_NOTHING;
2408 }
2409
2410 if(!UDFIsSDirDeleted(Dloc->SDirInfo) &&
2411 Dloc->SDirInfo->Dloc) {
2412 DirNdx2 = UDFDirIndex(Dloc->SDirInfo->Dloc->DirIndex, 1);
2413 if(DirNdx2 && (DirNdx2->FileInfo == FileInfo)) {
2414 DirNdx2->FileInfo =
2415 Parallel ? ParFileInfo : NULL;
2416 ASSERT(!DirNdx2->FileInfo->RefCount);
2417 }
2418 }
2419 }
2420
2421 if(!KeepDloc) {
2422
2423#ifdef UDF_DBG
2424 ASSERT(!Modified);
2425#endif
2426
2427#ifndef UDF_TRACK_ONDISK_ALLOCATION
2428 if(Dloc->DataLoc.Mapping) MyFreePool__(Dloc->DataLoc.Mapping);
2429 if(Dloc->AllocLoc.Mapping) MyFreePool__(Dloc->AllocLoc.Mapping);
2430 if(Dloc->FELoc.Mapping) MyFreePool__(Dloc->FELoc.Mapping);
2431 if(Dloc->FileEntry) {
2432 // plain file
2434 MyFreePool__(Dloc->FileEntry);
2435 Dloc->FileEntry = NULL;
2436 } else if(FileInfo->Index >= 2) {
2437 // error durring open operation
2439 }
2440#endif //UDF_TRACK_ONDISK_ALLOCATION
2441 if(FileInfo->Dloc->DirIndex) {
2442 uint_di i;
2443 for(i=2; (DirNdx = UDFDirIndex(Dloc->DirIndex,i)); i++) {
2444 ASSERT(!DirNdx->FileInfo);
2445 if(DirNdx->FName.Buffer)
2446 MyFreePool__(DirNdx->FName.Buffer);
2447 }
2448 // The only place where we can free FE_Charge extent is here
2449 UDFFlushFESpace(Vcb, Dloc);
2451 Dloc->DirIndex = NULL;
2452#ifdef UDF_TRACK_ONDISK_ALLOCATION
2454 if(FileInfo->Dloc->DirIndex) {
2455 for(i=2; DirNdx = UDFDirIndex(Dloc->DirIndex,i); i++) {
2456 ASSERT(!DirNdx->FileInfo);
2457 if(DirNdx->FName.Buffer)
2458 MyFreePool__(DirNdx->FName.Buffer);
2459 }
2461 Dloc->DirIndex = NULL;
2462 }
2463#endif //UDF_TRACK_ONDISK_ALLOCATION
2464 }
2465
2466#ifdef UDF_TRACK_ONDISK_ALLOCATION
2467 if(Dloc->AllocLoc.Mapping) MyFreePool__(Dloc->AllocLoc.Mapping);
2468 if(Dloc->FELoc.Mapping) MyFreePool__(Dloc->FELoc.Mapping);
2469 if(Dloc->FileEntry) {
2470 // plain file
2472 MyFreePool__(Dloc->FileEntry);
2473 Dloc->FileEntry = NULL;
2474 } else if(FileInfo->Index >= 2) {
2475 // error durring open operation
2477 }
2478 if(Dloc->DataLoc.Mapping) {
2479 if(lc && (lc != UDF_INVALID_LINK_COUNT)) {
2480 UDFCheckSpaceAllocation(Vcb, 0, Dloc->DataLoc.Mapping, AS_USED); // check if used
2481 } else {
2482 UDFCheckSpaceAllocation(Vcb, 0, Dloc->DataLoc.Mapping, AS_FREE); // check if free
2483 }
2485 }
2486#endif //UDF_TRACK_ONDISK_ALLOCATION
2487
2488 if(lc && (lc != UDF_INVALID_LINK_COUNT)) {
2489 UDFRemoveDloc(Vcb, Dloc);
2490 } else {
2491 UDFFreeDloc(Vcb, Dloc);
2492 }
2493 } else // KeepDloc cannot be FALSE if (Linked == TRUE)
2494 if(Linked) {
2495// BrutePoint();
2496 // Update pointers in ParentObject (if any)
2497 if(FileInfo->ParentFile->Dloc->SDirInfo == FileInfo)
2498 FileInfo->ParentFile->Dloc->SDirInfo = FileInfo->PrevLinkedFile;
2499 DirNdx = UDFDirIndex(FileInfo->Dloc->DirIndex, 0);
2500 if(DirNdx && (DirNdx->FileInfo == FileInfo))
2501 DirNdx->FileInfo = FileInfo->PrevLinkedFile;
2502 DirNdx = UDFDirIndex(FileInfo->ParentFile->Dloc->DirIndex, FileInfo->Index);
2503 if(DirNdx && (DirNdx->FileInfo == FileInfo))
2504 DirNdx->FileInfo = ParFileInfo;
2505 // remove from linked chain
2506 FileInfo->NextLinkedFile->PrevLinkedFile = FileInfo->PrevLinkedFile;
2507 FileInfo->PrevLinkedFile->NextLinkedFile = FileInfo->NextLinkedFile;
2508 // update pointer in Dloc
2509 if(FileInfo->Dloc->LinkedFileInfo == FileInfo)
2510 FileInfo->Dloc->LinkedFileInfo = FileInfo->PrevLinkedFile;
2511 }
2512 FileInfo->Dloc = NULL;
2513 } else {
2514 KeepDloc = FALSE;
2515 }
2516
2517 // Cleanup pointers in ParentObject (if any)
2518 if(IsASDir) {
2519 if(FileInfo->ParentFile->Dloc->SDirInfo == FileInfo) {
2520 ASSERT(!Linked);
2521 FileInfo->ParentFile->Dloc->SDirInfo = NULL;
2522 FileInfo->ParentFile->Dloc->FE_Flags &= ~UDF_FE_FLAG_HAS_DEL_SDIR;
2523 }
2524 } else
2525 if(FileInfo->ParentFile) {
2526 ASSERT(FileInfo->ParentFile->Dloc);
2527 DirNdx = UDFDirIndex(FileInfo->ParentFile->Dloc->DirIndex, FileInfo->Index);
2528 ASSERT(DirNdx);
2529#ifdef UDF_DBG
2530 PUDF_FILE_INFO OldFI;
2531 if(Parallel) {
2532 ASSERT(!DirNdx || !(OldFI = DirNdx->FileInfo) ||
2533 !(OldFI == FileInfo));
2534 } else {
2535 ASSERT(!DirNdx || !(OldFI = DirNdx->FileInfo) ||
2536 (OldFI == FileInfo));
2537 }
2538#endif
2539 if( DirNdx && (DirNdx->FileInfo == FileInfo) ) {
2540 if(!Parallel)
2541 DirNdx->FileInfo = NULL;
2542#ifdef UDF_DBG
2543 } else {
2544 // We can get here after incomplete Open
2545 if(!Parallel && DirNdx->FileInfo)
2546 BrutePoint();
2547#endif
2548 }
2549#ifdef UDF_DBG
2550 } else {
2551// BrutePoint();
2552#endif
2553 }
2554
2555 if(!Parallel && FileInfo->FileIdent)
2556 MyFreePool__(FileInfo->FileIdent);
2557 FileInfo->FileIdent = NULL;
2558 // Kill reference to parent object
2559 FileInfo->ParentFile = NULL;
2560 // Kill references to parallel object(s) since it has no reference to
2561 // this one now
2562 FileInfo->NextLinkedFile =
2563 FileInfo->PrevLinkedFile = FileInfo;
2564 if(FileInfo->ListPtr)
2565 FileInfo->ListPtr->FileInfo = NULL;;
2566 return KeepDloc ? UDF_FREE_FILEINFO : (UDF_FREE_FILEINFO | UDF_FREE_DLOC);
2567} // end UDFCleanUpFile__()
PUDF_FILE_INFO UDFLocateAnyParallelFI(PUDF_FILE_INFO fi)
Definition: dirtree.cpp:1439
OSSTATUS UDFIndexDirectory(IN PVCB Vcb, IN OUT PUDF_FILE_INFO FileInfo)
Definition: dirtree.cpp:507
void UDFDirIndexFree(PDIR_INDEX_HDR hDirNdx)
Definition: dirtree.cpp:98
void UDFFreeDloc(IN PVCB Vcb, IN PUDF_DATALOC_INFO Dloc)
Definition: dirtree.cpp:1353
static const WCHAR Linked[]
Definition: interface.c:30
void UDFFlushFESpace(IN PVCB Vcb, IN PUDF_DATALOC_INFO Dloc, IN BOOLEAN Discard)
Definition: extent.cpp:1776
UNICODE_STRING FName
Definition: udf_rel.h:173
struct _UDF_FILE_INFO * FileInfo
Definition: udf_rel.h:204
uint8 FI_Flags
Definition: udf_rel.h:199
UCHAR Flags
Definition: udf_rel.h:69
BOOLEAN Modified
Definition: udf_rel.h:68
uint32 FE_Flags
Definition: udf_rel.h:299
struct _UDF_FILE_INFO * SDirInfo
Definition: udf_rel.h:319
EXTENT_INFO FELoc
Definition: udf_rel.h:279
EXTENT_INFO DataLoc
Definition: udf_rel.h:262
struct _UDFNTRequiredFCB * CommonFcb
Definition: udf_rel.h:255
uint32 LinkRefCount
Definition: udf_rel.h:306
EXTENT_INFO AllocLoc
Definition: udf_rel.h:274
PDIR_INDEX_HDR DirIndex
Definition: udf_rel.h:312
PUDF_DATALOC_INFO Dloc
Definition: udf_rel.h:367
uint16 UDFGetFileLinkCount(IN PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:1355
#define UDFIsSDirDeleted(FI)
Definition: udf_info.h:1004
#define UDF_FREE_NOTHING
Definition: udf_info.h:648
#define AS_FREE
Definition: udf_info.h:326
__inline PDIR_INDEX_ITEM UDFDirIndex(IN PDIR_INDEX_HDR hDirNdx, IN uint_di i)
Definition: udf_info.h:1105
#define UDFIsAStreamDir(FI)
Definition: udf_info.h:998
#define UDF_FREE_FILEINFO
Definition: udf_info.h:649
#define UDF_FREE_DLOC
Definition: udf_info.h:650
uint32 uint_di
Definition: udf_rel.h:29
#define EXTENT_FLAG_PREALLOCATED
Definition: udf_rel.h:79
#define UDF_INVALID_LINK_COUNT
Definition: udf_rel.h:508
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by UDFBlankMount(), UDFCleanUpFcbChain(), UDFCloseResidual(), UDFCommonCreate(), UDFCompareVcb(), UDFCompleteMount(), UDFCreateFile__(), UDFCreateStreamDir__(), UDFHardLinkFile__(), UDFLoadVAT(), UDFMarkStreamsForDeletion(), UDFReadSecurity(), UDFRenameMoveFile__(), UDFUnlinkAllFilesInDir(), UDFUnlinkFile__(), and UDFWriteSecurity().

◆ UDFCloseFile__()

OSSTATUS UDFCloseFile__ ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo 
)

Definition at line 2994 of file udf_info.cpp.

2998{
3000
3001 if(!FileInfo) return STATUS_SUCCESS;
3002 if(FileInfo->Index<2 && (FileInfo->ParentFile) && !UDFIsAStreamDir(FileInfo)) {
3003 UDFPrint(("Closing Current or Parent Directory... :-\\\n"));
3004 if(FileInfo->RefCount) {
3005 UDFInterlockedDecrement((PLONG)&(FileInfo->RefCount));
3006 ASSERT(FileInfo->Dloc);
3007 if(FileInfo->Dloc)
3008 UDFInterlockedDecrement((PLONG)&(FileInfo->Dloc->LinkRefCount));
3009#ifdef UDF_DBG
3010 } else {
3011 BrutePoint();
3012 UDFPrint(("ERROR: Closing unreferenced file!\n"));
3013#endif // UDF_DBG
3014 }
3015 if(FileInfo->ParentFile->OpenCount) {
3016 UDFInterlockedDecrement((PLONG)&(FileInfo->ParentFile->OpenCount));
3017#ifdef UDF_DBG
3018 } else {
3019 BrutePoint();
3020 UDFPrint(("ERROR: Closing unopened file!\n"));
3021#endif // UDF_DBG
3022 }
3023 return STATUS_SUCCESS;
3024 }
3025 PUDF_FILE_INFO DirInfo = FileInfo->ParentFile;
3027 uint32 PartNum;
3028 if(FileInfo->RefCount) {
3029 UDFInterlockedDecrement((PLONG)&(FileInfo->RefCount));
3030 ASSERT(FileInfo->Dloc);
3031 if(FileInfo->Dloc)
3032 UDFInterlockedDecrement((PLONG)&(FileInfo->Dloc->LinkRefCount));
3033#ifdef UDF_DBG
3034 } else {
3035 BrutePoint();
3036 UDFPrint(("ERROR: Closing unreferenced file!\n"));
3037#endif // UDF_DBG
3038 }
3039 if(DirInfo) {
3040 // validate DirInfo
3041 ValidateFileInfo(DirInfo);
3042
3043 if(DirInfo->OpenCount) {
3045#ifdef UDF_DBG
3046 } else {
3047 BrutePoint();
3048 UDFPrint(("ERROR: Closing unopened file!\n"));
3049#endif // UDF_DBG
3050 }
3051 }
3052 // If the file has gone (unlinked) we should return STATUS_SUCCESS here.
3053 if(!FileInfo->Dloc) return STATUS_SUCCESS;
3054
3055 if(FileInfo->RefCount ||
3056 FileInfo->OpenCount ||
3057 !(FileInfo->Dloc->FELoc.Mapping)) return STATUS_SUCCESS;
3058// ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation);
3059 PartNum = UDFGetPartNumByPhysLba(Vcb, FileInfo->Dloc->FELoc.Mapping[0].extLocation);
3060 if(PartNum == (uint32)-1) {
3061 UDFPrint((" Is DELETED ?\n"));
3062 if(DirInfo) {
3063 PartNum = UDFGetPartNumByPhysLba(Vcb, DirInfo->Dloc->FELoc.Mapping[0].extLocation);
3064 } else {
3065 BrutePoint();
3066 }
3067 }
3068#ifdef UDF_CHECK_DISK_ALLOCATION
3069 if( FileInfo->Fcb &&
3070 UDFGetFreeBit(((uint32*)(Vcb->FSBM_Bitmap)), FileInfo->Dloc->FELoc.Mapping[0].extLocation)) {
3071
3072 //ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation);
3075 UDFPrint((" Not DELETED SDir\n"));
3076 BrutePoint();
3077 }
3078 ASSERT(!FileInfo->Dloc->FELoc.Modified);
3079 } else
3080 if(!FileInfo->FileIdent ||
3081 !(FileInfo->FileIdent->fileCharacteristics & FILE_DELETED)) {
3082 if(!FileInfo->FileIdent) {
3083 AdPrint((" No FileIdent\n"));
3084 }
3085 if(FileInfo->FileIdent &&
3086 !(FileInfo->FileIdent->fileCharacteristics & FILE_DELETED))
3087 AdPrint((" Not DELETED\n"));
3088 ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation);
3089 AdPrint(("Flushing to Discarded block %x\n", FileInfo->Dloc->FELoc.Mapping[0].extLocation));
3090 BrutePoint();
3091 } else {
3092 UDFCheckSpaceAllocation(Vcb, 0, FileInfo->Dloc->DataLoc.Mapping, AS_FREE); // check if free
3093 UDFCheckSpaceAllocation(Vcb, 0, FileInfo->Dloc->FELoc.Mapping, AS_FREE); // check if free
3094 }
3095 } else {
3096 if(!FileInfo->Dloc->FELoc.Mapping[0].extLocation ||
3097 UDFGetFreeBit(((uint32*)(Vcb->FSBM_Bitmap)), FileInfo->Dloc->FELoc.Mapping[0].extLocation)) {
3098 UDFCheckSpaceAllocation(Vcb, 0, FileInfo->Dloc->DataLoc.Mapping, AS_FREE); // check if free
3099 } else {
3100 UDFCheckSpaceAllocation(Vcb, 0, FileInfo->Dloc->DataLoc.Mapping, AS_USED); // check if used
3101 }
3102 }
3103#endif // UDF_CHECK_DISK_ALLOCATION
3104 // check if we should update parentICBLocation
3105 if( !((icbtag*)(FileInfo->Dloc->FileEntry+1))->parentICBLocation.logicalBlockNum &&
3106 !((icbtag*)(FileInfo->Dloc->FileEntry+1))->parentICBLocation.partitionReferenceNum &&
3107 DirInfo &&
3108 !Vcb->CDR_Mode &&
3109 Vcb->Modified &&
3111 ASSERT(DirInfo->Dloc->FELoc.Mapping[0].extLocation);
3112 ((icbtag*)(FileInfo->Dloc->FileEntry+1))->parentICBLocation.logicalBlockNum =
3113 UDFPhysLbaToPart(Vcb, PartNum, DirInfo->Dloc->FELoc.Mapping[0].extLocation);
3114 ((icbtag*)(FileInfo->Dloc->FileEntry+1))->parentICBLocation.partitionReferenceNum = (uint16)PartNum;
3115 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_FE_MODIFIED;
3116 }
3117
3118 // we needn't flushing FE & Allocs untill all links are closed...
3119 if(!FileInfo->Dloc->LinkRefCount) {
3120
3121 // flush FE and pre-allocation charge for directories
3122 if(FileInfo->Dloc &&
3123 FileInfo->Dloc->DirIndex) {
3124
3126 if(FileInfo->Dloc->DataLoc.Flags & EXTENT_FLAG_PREALLOCATED) {
3127 FileInfo->Dloc->DataLoc.Flags |= EXTENT_FLAG_CUT_PREALLOCATED;
3128 status = UDFResizeExtent(Vcb, PartNum, UDFGetFileSize(FileInfo), FALSE, &(FileInfo->Dloc->DataLoc));
3130 if(OS_SUCCESS(status)) {
3131 AdPrint(("Dir pre-alloc truncated (Close)\n"));
3132 FileInfo->Dloc->DataLoc.Modified = TRUE;
3133 }
3134 }
3135 }
3136
3137 if(!OS_SUCCESS(status = UDFFlushFE(Vcb, FileInfo, PartNum))) {
3138 UDFPrint(("Error flushing FE\n"));
3139//flush_recovery:
3140 BrutePoint();
3141 if(FileInfo->Index >= 2) {
3142 PDIR_INDEX_ITEM DirNdx;
3144 if(DirNdx) {
3145 UDFPrint(("Recovery: mark as deleted & flush FI\n"));
3148 FileInfo->FileIdent->fileCharacteristics |= FILE_DELETED;
3149 UDFFlushFI(Vcb, FileInfo, PartNum);
3150 }
3151 }
3152 return status;
3153 }
3154 }
3155 // ... but FI must be updated (if any)
3156 if(!OS_SUCCESS(status = UDFFlushFI(Vcb, FileInfo, PartNum))) {
3157 UDFPrint(("Error flushing FI\n"));
3158 return status;
3159 }
3160#ifdef UDF_DBG
3161// ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation);
3162 if((FileInfo->Dloc->FileEntry->descVersion != 2) &&
3163 (FileInfo->Dloc->FileEntry->descVersion != 3)) {
3164 ASSERT(UDFGetFreeBit(((uint32*)(Vcb->FSBM_Bitmap)), FileInfo->Dloc->FELoc.Mapping[0].extLocation));
3165 }
3166#endif // UDF_DBG
3167 return STATUS_SUCCESS;
3168} // end UDFCloseFile__()
uint32 __fastcall UDFGetPartNumByPhysLba(IN PVCB Vcb, IN uint32 Lba)
Definition: alloc.cpp:201
PDIR_INDEX_HDR UDFGetDirIndexByFileInfo(IN PUDF_FILE_INFO FileInfo)
Definition: dirtree.cpp:1092
#define FILE_DELETED
Definition: ecma_167.h:440
uint8 FileCharacteristics
Definition: udf_rel.h:182
uint32 OpenCount
Definition: udf_rel.h:407
OSSTATUS UDFFlushFI(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN uint32 PartNum)
Definition: udf_info.cpp:4051
int64 UDFGetFileSize(IN PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:1236
OSSTATUS UDFFlushFE(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN uint32 PartNum)
Definition: udf_info.cpp:3864
#define EXTENT_FLAG_CUT_PREALLOCATED
Definition: udf_rel.h:80

Referenced by UDFCleanUpFcbChain(), UDFCloseFileInfoChain(), UDFCloseResidual(), UDFCommonCreate(), UDFCompareVcb(), UDFCompleteMount(), UDFCreateFile__(), UDFCreateStreamDir__(), UDFHardLinkFile__(), UDFLoadVAT(), UDFMarkStreamsForDeletion(), UDFReadSecurity(), UDFRename(), UDFRenameMoveFile__(), UDFSetEOF(), UDFUnlinkAllFilesInDir(), UDFUnlinkFile__(), and UDFWriteSecurity().

◆ UDFCompareFileInfo()

BOOLEAN UDFCompareFileInfo ( IN PUDF_FILE_INFO  f1,
IN PUDF_FILE_INFO  f2 
)

Definition at line 4218 of file udf_info.cpp.

4222{
4223 uint_di i;
4224 PDIR_INDEX_HDR hDirIndex1;
4225 PDIR_INDEX_HDR hDirIndex2;
4226 PDIR_INDEX_ITEM DirIndex1;
4227 PDIR_INDEX_ITEM DirIndex2;
4228
4229 if(!f1 || !f2) return FALSE;
4230 if(f1->Dloc->FileEntryLen != f2->Dloc->FileEntryLen) return FALSE;
4231// if(f1->FileIdentLen != f2->FileIdentLen) return FALSE;
4232/* if(f1->Dloc->DirIndex && !f2->Dloc->DirIndex) return FALSE;
4233 if(f2->Dloc->DirIndex && !f1->Dloc->DirIndex) return FALSE;
4234 if((f1->Dloc->DirIndex) &&
4235 (f1->Dloc->DirIndex->LastFrameCount != f2->Dloc->DirIndex->LastFrameCount)) return FALSE;*/
4236 if(f1->Index != f2->Index) return FALSE;
4237 if(!(f1->Dloc->DataLoc.Mapping)) return FALSE;
4238 if(!(f2->Dloc->DataLoc.Mapping)) return FALSE;
4239 if(f1->Dloc->DataLoc.Mapping[0].extLocation != f2->Dloc->DataLoc.Mapping[0].extLocation) return FALSE;
4240 if(f1->Dloc->DataLoc.Mapping[0].extLength != f2->Dloc->DataLoc.Mapping[0].extLength) return FALSE;
4241// if(f1-> != f2->) return FALSE;
4242// if(f1-> != f2->) return FALSE;
4243// if(f1-> != f2->) return FALSE;
4244 if(!(f1->Dloc->FileEntry)) return FALSE;
4245 if(!(f2->Dloc->FileEntry)) return FALSE;
4246 if(RtlCompareMemory(f1->Dloc->FileEntry, f2->Dloc->FileEntry, f2->Dloc->FileEntryLen) != f2->Dloc->FileEntryLen)
4247 return FALSE;
4248 if(!(hDirIndex1 = f1->Dloc->DirIndex)) return FALSE;
4249 if(!(hDirIndex2 = f2->Dloc->DirIndex)) return FALSE;
4250
4251 for(i=2; (DirIndex1 = UDFDirIndex(hDirIndex1,i)) &&
4252 (DirIndex2 = UDFDirIndex(hDirIndex2,i)); i++) {
4253 if( DirIndex1->FName.Buffer &&
4254 !DirIndex2->FName.Buffer)
4255 return FALSE;
4256 if( DirIndex2->FName.Buffer &&
4257 !DirIndex1->FName.Buffer)
4258 return FALSE;
4259 if(!DirIndex2->FName.Buffer &&
4260 !DirIndex1->FName.Buffer)
4261 continue;
4262 if(RtlCompareUnicodeString(&(DirIndex1->FName),
4263 &(DirIndex2->FName),FALSE)) {
4264 return FALSE;
4265 }
4266// if(DirIndex1[i].FileEntry != DirIndex2[i].FileEntry)
4267// return FALSE;
4268 if(RtlCompareMemory(&(DirIndex1->FileEntryLoc),
4269 &(DirIndex2->FileEntryLoc), sizeof(lb_addr)) != sizeof(lb_addr))
4270 return FALSE;
4271 }
4272
4273 return TRUE;
4274} // end UDFCompareFileInfo()
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
#define f2(x, y, z)
Definition: sha1.c:31
#define f1(x, y, z)
Definition: sha1.c:30
lb_addr FileEntryLoc
Definition: udf_rel.h:178

Referenced by UDFCompareVcb().

◆ UDFCompressUnicode()

void __fastcall UDFCompressUnicode ( IN PUNICODE_STRING  UName,
IN OUT uint8 **  _CS0,
IN OUT PSIZE_T  Length 
)

Definition at line 240 of file udf_info.cpp.

245{
246 uint8* CS0;
247 uint8 compID;
248 uint16 unicodeIndex;
249 uint32 i, len;
250 PWCHAR Buff;
251
252 len = (UName->Length) / sizeof(WCHAR);
253 compID = (!len) ? 0 : UDF_COMP_ID_8;
254 // check for uncompressable characters
255 Buff = UName->Buffer;
256 for(i=0; i<len; i++, Buff++) {
257 if((*Buff) & 0xff00) {
258 compID = UDF_COMP_ID_16;
259 break;
260 }
261 }
262
263 CS0 = (uint8*)MyAllocatePool__(NonPagedPool, *Length = (((compID==UDF_COMP_ID_8) ? 1 : 2)*len + 1) );
264 if(!CS0) return;
265
266 CS0[0] = compID;
267 *_CS0 = CS0;
268 // init loop
269 CS0++;
270 unicodeIndex = 0;
271 Buff = UName->Buffer;
272 if(compID == UDF_COMP_ID_16) {
273 // Loop through all the bytes.
274 while (unicodeIndex < len) {
275 // Move the 2nd byte to the low bits of the compressed unicode char.
276 *CS0 = (uint8)((*Buff) >> 8);
277 CS0++;
278 *CS0 = (uint8)(*Buff);
279 CS0++;
280 Buff++;
281 unicodeIndex++;
282 }
283 } else {
284 // Loop through all the bytes.
285 while (unicodeIndex < len) {
286 *CS0 = (uint8)(*Buff);
287 CS0++;
288 Buff++;
289 unicodeIndex++;
290 }
291 }
292} // end UDFCompressUnicode()
#define UDF_COMP_ID_16
Definition: ecma_167.h:23
#define UDF_COMP_ID_8
Definition: ecma_167.h:22

Referenced by UDFBuildFileIdent(), UDFRenameMoveFile__(), and UDFSetDstring().

◆ UDFConvertFEToExtended()

OSSTATUS UDFConvertFEToExtended ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo 
)

Definition at line 5458 of file udf_info.cpp.

5462{
5463 PEXTENDED_FILE_ENTRY ExFileEntry;
5464 PFILE_ENTRY FileEntry;
5468
5471 if(FileInfo->Dloc->FileEntry->tagIdent == TID_EXTENDED_FILE_ENTRY) return STATUS_SUCCESS;
5472 if(FileInfo->Dloc->FileEntry->tagIdent != TID_FILE_ENTRY) return STATUS_INVALID_PARAMETER;
5473
5474/* if(!OS_SUCCESS(status = UDFFlushFile__(Vcb, FileInfo)))
5475 return status;*/
5476
5477 Length = FileInfo->Dloc->FileEntryLen;
5478 NewLength = Length - sizeof(FILE_ENTRY) + sizeof(EXTENDED_FILE_ENTRY);
5480 if(!ExFileEntry) return STATUS_INSUFFICIENT_RESOURCES;
5481 FileEntry = (PFILE_ENTRY)(FileInfo->Dloc->FileEntry);
5482 RtlZeroMemory(ExFileEntry, NewLength);
5483
5485 ExFileEntry->icbTag = FileEntry->icbTag;
5486 ExFileEntry->uid = FileEntry->uid;
5487 ExFileEntry->gid = FileEntry->gid;
5488 ExFileEntry->permissions = FileEntry->permissions;
5489 ExFileEntry->fileLinkCount = FileEntry->fileLinkCount;
5490 ExFileEntry->recordFormat = FileEntry->recordFormat;
5491 ExFileEntry->recordDisplayAttr = FileEntry->recordDisplayAttr;
5492 ExFileEntry->recordLength = FileEntry->recordLength;
5493 ExFileEntry->informationLength = FileEntry->informationLength;
5494 ExFileEntry->logicalBlocksRecorded = FileEntry->logicalBlocksRecorded;
5495 ExFileEntry->accessTime = FileEntry->accessTime;
5496 ExFileEntry->modificationTime = FileEntry->modificationTime;
5497 ExFileEntry->attrTime = FileEntry->attrTime;
5498 ExFileEntry->checkpoint = FileEntry->checkpoint;
5499 ExFileEntry->extendedAttrICB = FileEntry->extendedAttrICB;
5500 ExFileEntry->impIdent = FileEntry->impIdent;
5501 ExFileEntry->uniqueID = FileEntry->uniqueID;
5502 ExFileEntry->lengthExtendedAttr = FileEntry->lengthExtendedAttr;
5503 ExFileEntry->lengthAllocDescs = FileEntry->lengthAllocDescs;
5504 RtlCopyMemory(ExFileEntry+1, FileEntry+1, FileEntry->lengthExtendedAttr);
5505 RtlCopyMemory((int8*)(ExFileEntry+1)+FileEntry->lengthExtendedAttr, (int8*)(ExFileEntry+1)+FileEntry->lengthExtendedAttr, FileEntry->lengthAllocDescs);
5506
5507 if((((PFILE_ENTRY)(FileInfo->Dloc->FileEntry))->icbTag.flags & ICB_FLAG_ALLOC_MASK) == ICB_FLAG_AD_IN_ICB) {
5508
5509 if((l = (uint32)(FileInfo->Dloc->DataLoc.Length))) {
5510
5511 int8* tmp_buff = (int8*)MyAllocatePool__(NonPagedPool, l);
5512 if(!tmp_buff) {
5513 MyFreePool__(ExFileEntry);
5515 }
5516 if(!OS_SUCCESS(status = UDFReadFile__(Vcb, FileInfo, 0, l, FALSE, tmp_buff, &ReadBytes)) ||
5518 MyFreePool__(ExFileEntry);
5519 MyFreePool__(tmp_buff);
5520 return status;
5521 }
5522 FileInfo->Dloc->FELoc.Length =
5523 FileInfo->Dloc->DataLoc.Offset = NewLength;
5524 FileInfo->Dloc->FELoc.Modified =
5525 FileInfo->Dloc->DataLoc.Modified = TRUE;
5526 MyFreePool__(FileInfo->Dloc->FileEntry);
5527 FileInfo->Dloc->FileEntry = (tag*)ExFileEntry;
5529 !OS_SUCCESS(status = UDFWriteFile__(Vcb, FileInfo, 0, l, FALSE, tmp_buff, &ReadBytes)) ) {
5530 MyFreePool__(ExFileEntry);
5531 MyFreePool__(tmp_buff);
5532 return status;
5533 }
5534 MyFreePool__(tmp_buff);
5535 } else {
5536 FileInfo->Dloc->FELoc.Length =
5537 FileInfo->Dloc->DataLoc.Offset = NewLength;
5538 FileInfo->Dloc->FELoc.Modified =
5539 FileInfo->Dloc->DataLoc.Modified = TRUE;
5540 MyFreePool__(FileInfo->Dloc->FileEntry);
5541 FileInfo->Dloc->FileEntry = (tag*)ExFileEntry;
5542 }
5543 } else {
5544 FileInfo->Dloc->FELoc.Length =
5545 FileInfo->Dloc->AllocLoc.Offset = NewLength;
5546 FileInfo->Dloc->FELoc.Modified =
5547 FileInfo->Dloc->AllocLoc.Modified = TRUE;
5548 MyFreePool__(FileInfo->Dloc->FileEntry);
5549 FileInfo->Dloc->FileEntry = (tag*)ExFileEntry;
5550 }
5551 FileInfo->Dloc->FileEntryLen = NewLength;
5552 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_FE_MODIFIED;
5553 if(Vcb->minUDFReadRev < 0x0200)
5554 Vcb->minUDFReadRev = 0x0200;
5555 return STATUS_SUCCESS;
5556} // end UDFConvertFEToExtended()
static USHORT USHORT * NewLength
icbtag icbTag
Definition: ecma_167.h:744
uint64 informationLength
Definition: ecma_167.h:752
timestamp modificationTime
Definition: ecma_167.h:756
uint32 permissions
Definition: ecma_167.h:747
uint32 checkpoint
Definition: ecma_167.h:759
uint64 uniqueID
Definition: ecma_167.h:764
uint32 gid
Definition: ecma_167.h:746
long_ad extendedAttrICB
Definition: ecma_167.h:761
timestamp accessTime
Definition: ecma_167.h:755
uint64 logicalBlocksRecorded
Definition: ecma_167.h:754
uint32 lengthExtendedAttr
Definition: ecma_167.h:765
uint32 uid
Definition: ecma_167.h:745
timestamp attrTime
Definition: ecma_167.h:758
EntityID impIdent
Definition: ecma_167.h:763
uint8 recordFormat
Definition: ecma_167.h:749
uint32 recordLength
Definition: ecma_167.h:751
tag descTag
Definition: ecma_167.h:743
uint8 recordDisplayAttr
Definition: ecma_167.h:750
uint32 lengthAllocDescs
Definition: ecma_167.h:766
uint32 permissions
Definition: ecma_167.h:518
uint32 lengthAllocDescs
Definition: ecma_167.h:534
uint32 checkpoint
Definition: ecma_167.h:528
uint32 lengthExtendedAttr
Definition: ecma_167.h:533
EntityID impIdent
Definition: ecma_167.h:530
uint8 recordDisplayAttr
Definition: ecma_167.h:521
timestamp modificationTime
Definition: ecma_167.h:526
uint64 logicalBlocksRecorded
Definition: ecma_167.h:524
uint64 uniqueID
Definition: ecma_167.h:531
timestamp accessTime
Definition: ecma_167.h:525
uint32 recordLength
Definition: ecma_167.h:522
uint64 informationLength
Definition: ecma_167.h:523
long_ad extendedAttrICB
Definition: ecma_167.h:529
timestamp attrTime
Definition: ecma_167.h:527
uint8 recordFormat
Definition: ecma_167.h:520
OSSTATUS UDFWriteFile__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN int64 Offset, IN SIZE_T Length, IN BOOLEAN Direct, IN int8 *Buffer, OUT PSIZE_T WrittenBytes)
Definition: udf_info.cpp:1605
OSSTATUS UDFResizeFile__(IN PVCB Vcb, IN OUT PUDF_FILE_INFO FileInfo, IN int64 NewLength)
Definition: udf_info.cpp:3468
__inline OSSTATUS UDFReadFile__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN int64 Offset, IN SIZE_T Length, IN BOOLEAN Direct, OUT int8 *Buffer, OUT PSIZE_T ReadBytes)
Definition: udf_info.h:666
#define MEM_XFE_TAG
Definition: udf_rel.h:487

Referenced by UDFCreateStreamDir__().

◆ UDFConvertFEToNonInICB()

OSSTATUS UDFConvertFEToNonInICB ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo,
IN uint8  NewAllocMode 
)

Definition at line 5358 of file udf_info.cpp.

5363{
5365 int8* OldInIcb = NULL;
5366 uint32 OldLen;
5369 SIZE_T _WrittenBytes;
5370 PUDF_DATALOC_INFO Dloc;
5371
5372// ASSERT(FileInfo->RefCount >= 1);
5373
5374 Dloc = FileInfo->Dloc;
5375 ASSERT(Dloc->FELoc.Mapping[0].extLocation);
5377
5378 if(NewAllocMode == ICB_FLAG_AD_DEFAULT_ALLOC_MODE) {
5379 NewAllocMode = (uint8)(Vcb->DefaultAllocMode);
5380 }
5381 // we do not support recording of extended AD now
5382 if(NewAllocMode != ICB_FLAG_AD_SHORT &&
5383 NewAllocMode != ICB_FLAG_AD_LONG)
5385 if(!Dloc->DataLoc.Offset || !Dloc->DataLoc.Length)
5386 return STATUS_SUCCESS;
5387 ASSERT(!Dloc->AllocLoc.Mapping);
5388 // read in-icb data. it'll be replaced after resize
5389 OldInIcb = (int8*)MyAllocatePool__(NonPagedPool, (uint32)(Dloc->DataLoc.Length));
5390 if(!OldInIcb)
5392 OldLen = (uint32)(Dloc->DataLoc.Length);
5393 status = UDFReadExtent(Vcb, &(Dloc->DataLoc), 0, OldLen, FALSE, OldInIcb, &ReadBytes);
5394 if(!OS_SUCCESS(status)) {
5395 MyFreePool__(OldInIcb);
5396 return status;
5397 }
5398/* if(!Dloc->AllocLoc.Mapping) {
5399 Dloc->AllocLoc.Mapping = (PEXTENT_MAP)MyAllocatePool__(NonPagedPool, sizeof(EXTENT_MAP)*2);
5400 if(!Dloc->AllocLoc.Mapping) {
5401 MyFreePool__(OldInIcb);
5402 return STATUS_INSUFFICIENT_RESOURCES;
5403 }
5404 }
5405 // init Alloc mode
5406 if((((PFILE_ENTRY)(Dloc->FileEntry))->icbTag.flags & ICB_FLAG_ALLOC_MASK) == ICB_FLAG_AD_IN_ICB) {
5407 ((PFILE_ENTRY)(Dloc->FileEntry))->icbTag.flags &= ~ICB_FLAG_ALLOC_MASK;
5408 ((PFILE_ENTRY)(Dloc->FileEntry))->icbTag.flags |= Vcb->DefaultAllocMode;
5409 } else {
5410 BrutePoint();
5411 }
5412 RtlZeroMemory(Dloc->AllocLoc.Mapping, sizeof(EXTENT_MAP)*2);
5413// Dloc->AllocLoc.Mapping[0].extLocation = 0;
5414 Dloc->AllocLoc.Mapping[0].extLength = Vcb->LBlockSize | EXTENT_NOT_RECORDED_NOT_ALLOCATED;
5415// Dloc->AllocLoc.Mapping[1].extLocation = 0;
5416// Dloc->AllocLoc.Mapping[1].extLength = 0;
5417*/
5418
5419 // grow extent in order to force space allocation
5420 status = UDFResizeExtent(Vcb, PartNum, Vcb->LBlockSize, FALSE, &Dloc->DataLoc);
5421 if(!OS_SUCCESS(status)) {
5422 MyFreePool__(OldInIcb);
5423 return status;
5424 }
5425
5426 // set Alloc mode
5427 if((((PFILE_ENTRY)(Dloc->FileEntry))->icbTag.flags & ICB_FLAG_ALLOC_MASK) == ICB_FLAG_AD_IN_ICB) {
5428 ((PFILE_ENTRY)(Dloc->FileEntry))->icbTag.flags &= ~ICB_FLAG_ALLOC_MASK;
5429 ((PFILE_ENTRY)(Dloc->FileEntry))->icbTag.flags |= NewAllocMode;
5430 } else {
5431 BrutePoint();
5432 }
5433
5434 // revert to initial extent size. This will not cause NonInICB->InICB transform
5435 status = UDFResizeExtent(Vcb, PartNum, OldLen, FALSE, &Dloc->DataLoc);
5436 if(!OS_SUCCESS(status)) {
5437 MyFreePool__(OldInIcb);
5438 return status;
5439 }
5440
5441 // replace data from ICB (if any) & free buffer
5442 status = UDFWriteExtent(Vcb, &(Dloc->DataLoc), 0, OldLen, FALSE, OldInIcb, &_WrittenBytes);
5443 MyFreePool__(OldInIcb);
5444 if(!OS_SUCCESS(status)) {
5445 return status;
5446 }
5447 // inform UdfInfo, that AllocDesc's must be rebuilt on flush/close
5448 Dloc->AllocLoc.Modified = TRUE;
5449 Dloc->DataLoc.Modified = TRUE;
5450 return STATUS_SUCCESS;
5451} // end UDFConvertFEToNonInICB()
OSSTATUS UDFReadExtent(IN PVCB Vcb, IN PEXTENT_INFO ExtInfo, IN int64 Offset, IN SIZE_T Length, IN BOOLEAN Direct, OUT int8 *Buffer, OUT PSIZE_T ReadBytes)
Definition: extent.cpp:3021
OSSTATUS UDFWriteExtent(IN PVCB Vcb, IN PEXTENT_INFO ExtInfo, IN int64 Offset, IN SIZE_T Length, IN BOOLEAN Direct, IN int8 *Buffer, OUT PSIZE_T WrittenBytes)
Definition: extent.cpp:3186
int64 Length
Definition: udf_rel.h:67
#define ICB_FLAG_AD_DEFAULT_ALLOC_MODE
Definition: udf_rel.h:506

Referenced by UDFSetFileAllocModeFromICB().

◆ UDFCrc()

uint16 __fastcall UDFCrc ( IN uint8 Data,
IN SIZE_T  Size 
)

Definition at line 4527 of file udf_info.cpp.

4531{
4532#if defined(_X86_) && defined(_MSC_VER) && !defined(__clang__)
4533// uint32 _Size = Size;
4534
4535 __asm {
4536 push ebx
4537 push ecx
4538 push edx
4539 push esi
4540
4541 mov esi,ecx
4542 mov ecx,edx
4543 xor eax,eax
4544
4545 jecxz EO_CRC
4546
4547 lea ebx,[CrcTable]
4548 xor edx,edx
4549
4550CRC_loop:
4551
4552 mov dl,ah
4553 xor dl,[esi]
4554 mov ah,al
4555 mov al,dh
4556 xor ax,[word ptr ebx+edx*2]
4557 inc esi
4558 loop CRC_loop
4559
4560EO_CRC:
4561
4562 pop esi
4563 pop edx
4564 pop ecx
4565 pop ebx
4566
4567 ret
4568 }
4569#else // NO X86 optimization , use generic C/C++
4570 uint16 Crc = 0;
4571 while (Size--)
4572 Crc = CrcTable[(Crc >> 8 ^ *Data++) & 0xff] ^ (Crc << 8);
4573 return Crc;
4574#endif // _X86_
4575
4576} // end UDFCrc()
const WCHAR * word
Definition: lex.c:36
ecx edi movl ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx movl TEMP incl eax andl eax ecx incl ebx testl eax jnz xchgl ecx incl TEMP esp ecx subl ebx pushl ecx ecx edx ecx shrl ecx mm0 mm4 mm0 mm4 mm1 mm5 mm1 mm5 mm2 mm6 mm2 mm6 mm3 mm7 mm3 mm7 paddd mm0 paddd mm4 paddd mm0 paddd mm4 paddd mm0 paddd mm4 movq mm1 movq mm5 psrlq mm1 psrlq mm5 paddd mm0 paddd mm4 psrad mm0 psrad mm4 packssdw mm0 packssdw mm4 mm1 punpckldq mm0 pand mm1 pand mm0 por mm1 movq edi esi edx edi decl ecx jnz popl ecx andl ecx jecxz mm0 mm0 mm1 mm1 mm2 mm2 mm3 mm3 paddd mm0 paddd mm0 paddd mm0 movq mm1 psrlq mm1 paddd mm0 psrad mm0 packssdw mm0 movd eax movw ax
Definition: synth_sse3d.h:180
static const uint16 CrcTable[256]
Definition: udf_info.cpp:51
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by UDFDecompressUnicode(), UDFReadTagged(), and UDFSetUpTag().

◆ UDFCreateFile__()

OSSTATUS UDFCreateFile__ ( IN PVCB  Vcb,
IN BOOLEAN  IgnoreCase,
IN PUNICODE_STRING  fn,
IN uint32  ExtAttrSz,
IN uint32  ImpUseLen,
IN BOOLEAN  Extended,
IN BOOLEAN  CreateNew,
IN OUT PUDF_FILE_INFO  DirInfo,
OUT PUDF_FILE_INFO _FileInfo 
)

Definition at line 2577 of file udf_info.cpp.

2589{
2590 uint32 l, d;
2591 uint_di i, j;
2593 LONG_AD FEicb;
2594 UDF_DIR_SCAN_CONTEXT ScanContext;
2595 PDIR_INDEX_HDR hDirNdx = DirInfo->Dloc->DirIndex;
2596 PDIR_INDEX_ITEM DirNdx;
2597 uint32 LBS = Vcb->LBlockSize;
2599 *_FileInfo = NULL;
2600 BOOLEAN undel = FALSE;
2602// BOOLEAN PackDir = FALSE;
2603 BOOLEAN FEAllocated = FALSE;
2604
2605 ValidateFileInfo(DirInfo);
2606 *_FileInfo = NULL;
2607
2608 ASSERT(DirInfo->Dloc->FELoc.Mapping[0].extLocation);
2609 uint32 PartNum = UDFGetPartNumByPhysLba(Vcb, DirInfo->Dloc->FELoc.Mapping[0].extLocation);
2610 if(!hDirNdx) return STATUS_NOT_A_DIRECTORY;
2611 i = 0;
2612
2613 _SEH2_TRY {
2614
2615 // check if exists
2616 status = UDFFindFile(Vcb, IgnoreCase, FALSE, _fn, DirInfo, &i);
2617 DirNdx = UDFDirIndex(hDirNdx,i);
2618 if(OS_SUCCESS(status)) {
2619 // file is a Cur(Parent)Dir
2621 // file deleted
2622 if(UDFIsDeleted(DirNdx)) {
2623 j=0;
2624 if(OS_SUCCESS(UDFFindFile(Vcb, IgnoreCase, TRUE, _fn, DirInfo, &j))) {
2625 i=j;
2626 DirNdx = UDFDirIndex(hDirNdx,i);
2627 goto CreateBothFound;
2628 }
2629 // we needn't allocating new FileIdent inside Dir stream
2630 // perform 'undel'
2631 if(DirNdx->FileInfo) {
2632 // BrutePoint();
2634 if(!OS_SUCCESS(status))
2636 } else {
2637 undel = TRUE;
2638 }
2639 // BrutePoint();
2640 goto CreateUndel;
2641 }
2642CreateBothFound:
2643 // file already exists
2644 if(CreateNew) try_return (status = STATUS_ACCESS_DENIED);
2645 // try to open it
2646 BrutePoint();
2647 status = UDFOpenFile__(Vcb, IgnoreCase, TRUE, _fn, DirInfo, _FileInfo,&i);
2648 // *_FileInfo = FileInfo; // OpenFile__ has already done it, so update it...
2649 DirNdx = UDFDirIndex(hDirNdx,i);
2650 DirNdx->FI_Flags &= ~UDF_FI_FLAG_SYS_ATTR;
2651 FileInfo = *_FileInfo;
2652 if(!OS_SUCCESS(status)) {
2653 // :(( can't open....
2656 *_FileInfo = NULL;
2657 }
2658 BrutePoint();
2660 }
2661 // check if we can delete this file
2662 if(FileInfo->OpenCount || (FileInfo->RefCount > 1)) {
2663 BrutePoint();
2666 }
2667 BrutePoint();
2668 // remove DIRECTORY flag
2669 DirNdx->FileCharacteristics &= ~FILE_DIRECTORY;
2670 FileInfo->FileIdent->fileCharacteristics &= ~FILE_DIRECTORY;
2672 // truncate file size to ZERO
2674 if(!OS_SUCCESS(status)) {
2675 BrutePoint();
2677 }
2678 // set NORMAL flag
2679 FileInfo->FileIdent->fileCharacteristics = 0;
2680 DirNdx->FileCharacteristics = 0;
2681 // update DeletedFiles counter in Directory... (for PackDir)
2682 if(undel && OS_SUCCESS(status))
2683 hDirNdx->DelCount--;
2685 }
2686
2687CreateUndel:
2688
2689 // allocate FileInfo
2691 *_FileInfo = FileInfo;
2692 if(!FileInfo)
2694 ImpUseLen = (ImpUseLen + 3) & ~((uint16)3);
2695
2697 // init horizontal links
2698 FileInfo->NextLinkedFile =
2699 FileInfo->PrevLinkedFile = FileInfo;
2700 // allocate space for FileEntry
2701 if(!OS_SUCCESS(status =
2702 UDFBuildFileEntry(Vcb, DirInfo, FileInfo, PartNum, ICB_FLAG_AD_IN_ICB, ExtAttrSz, Extended) )) {
2703 BrutePoint();
2705 }
2706 FEAllocated = TRUE;
2707 FEicb.extLength = LBS;
2708 ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation);
2709 FEicb.extLocation.logicalBlockNum = UDFPhysLbaToPart(Vcb, PartNum, FileInfo->Dloc->FELoc.Mapping[0].extLocation);
2710 FEicb.extLocation.partitionReferenceNum = (uint16)PartNum;
2711 RtlZeroMemory(&(FEicb.impUse), sizeof(FEicb.impUse));
2712
2713 if(!undel) {
2714 // build FileIdent
2715 if(!OS_SUCCESS(status =
2716 UDFBuildFileIdent(Vcb, _fn, &FEicb, ImpUseLen,
2717 &(FileInfo->FileIdent), &(FileInfo->FileIdentLen)) ))
2719 } else {
2720 // read FileIdent
2723 FileInfo->FileIdentLen = DirNdx->Length;
2724 if(!OS_SUCCESS(status = UDFReadExtent(Vcb, &(DirInfo->Dloc->DataLoc), DirNdx->Offset,
2725 DirNdx->Length, FALSE, (int8*)(FileInfo->FileIdent), &ReadBytes) ))
2727 FileInfo->FileIdent->fileCharacteristics = 0;
2728 FileInfo->FileIdent->icb = FEicb;
2729 ImpUseLen = FileInfo->FileIdent->lengthOfImpUse;
2730 DirNdx->FileCharacteristics = 0;
2731 }
2732 // init 'parentICBLocation' & so on in FE
2733 ((icbtag*)(FileInfo->Dloc->FileEntry+1))->parentICBLocation.logicalBlockNum =
2734 UDFPhysLbaToPart(Vcb, PartNum, DirInfo->Dloc->FELoc.Mapping[0].extLocation);
2735 ((icbtag*)(FileInfo->Dloc->FileEntry+1))->parentICBLocation.partitionReferenceNum = (uint16)PartNum;
2736 // ((icbtag*)(FileInfo->Dloc->FileEntry+1))->strategyType = 4;
2737 // ((icbtag*)(FileInfo->Dloc->FileEntry+1))->numEntries = 1;
2738 // try to find suitable unused FileIdent in DirIndex
2739 l = FileInfo->FileIdentLen;
2740 if(undel) goto CrF__2;
2741#ifndef UDF_LIMIT_DIR_SIZE
2742 if(Vcb->CDR_Mode) {
2743#endif // UDF_LIMIT_DIR_SIZE
2744 // search for suitable unused entry
2745 if(UDFDirIndexInitScan(DirInfo, &ScanContext, 2)) {
2746 while((DirNdx = UDFDirIndexScan(&ScanContext, NULL))) {
2747 if((DirNdx->Length == l) && UDFIsDeleted(DirNdx) &&
2748 !DirNdx->FileInfo ) {
2749 // free unicode-buffer with old name
2750 if(DirNdx->FName.Buffer) {
2751 MyFreePool__(DirNdx->FName.Buffer);
2752 DirNdx->FName.Buffer = NULL;
2753 }
2754 i = ScanContext.i;
2755 goto CrF__1;
2756 }
2757 }
2758 }
2759#ifndef UDF_LIMIT_DIR_SIZE
2760 } else {
2761#endif // UDF_LIMIT_DIR_SIZE
2762 i = UDFDirIndexGetLastIndex(hDirNdx); // 'i' points beyond EO DirIndex
2763#ifndef UDF_LIMIT_DIR_SIZE
2764 }
2765#endif // UDF_LIMIT_DIR_SIZE
2766
2767 // append entry
2768 if(!OS_SUCCESS(status = UDFDirIndexGrow(&(DirInfo->Dloc->DirIndex), 1))) {
2770 }
2771
2772 // init offset of new FileIdent in directory Data extent
2773 hDirNdx = DirInfo->Dloc->DirIndex;
2774 if(i-1) {
2775 DirNdx = UDFDirIndex(hDirNdx,i-1);
2776 UDFDirIndex(hDirNdx,i)->Offset = DirNdx->Offset + DirNdx->Length;
2777 DirNdx = UDFDirIndex(hDirNdx,i);
2778 } else {
2779 DirNdx = UDFDirIndex(hDirNdx,i);
2780 DirNdx->Offset = 0;
2781 }
2782 // new terminator is recorded by UDFDirIndexGrow()
2783 if( ((d = ((LBS - (DirNdx->Offset + l + DirInfo->Dloc->DataLoc.Offset)) & (LBS-1) )) < sizeof(FILE_IDENT_DESC)) &&
2784 d ) {
2785 // insufficient space at the end of last sector for
2786 // next FileIdent's tag. fill it with ImpUse data
2787
2788 // generally, all data should be DWORD-aligned, but if it is not so
2789 // this opearation will help us to avoid glitches
2790 d = (d+3) & ~((uint32)3);
2791
2792 uint32 IUl, FIl;
2793 if(!MyReallocPool__((int8*)(FileInfo->FileIdent), l,
2794 (int8**)&(FileInfo->FileIdent), (l+d+3) & ~((uint32)(3)) ))
2796 l += d;
2797 IUl = FileInfo->FileIdent->lengthOfImpUse;
2798 FIl = FileInfo->FileIdent->lengthFileIdent;
2799 // move filename to higher addr
2800 RtlMoveMemory(((int8*)(FileInfo->FileIdent+1))+IUl+d,
2801 ((int8*)(FileInfo->FileIdent+1))+IUl, FIl);
2802 RtlZeroMemory(((int8*)(FileInfo->FileIdent+1))+IUl, d);
2803 FileInfo->FileIdent->lengthOfImpUse += (uint16)d;
2804 FileInfo->FileIdentLen = l;
2805 }
2806 DirNdx->Length = l;
2807CrF__1:
2808 // clone unicode string
2809 // it **<<MUST>>** be allocated with internal memory manager
2810 DirNdx->FName.Buffer = (PWCHAR)MyAllocatePoolTag__(UDF_FILENAME_MT, (DirNdx->FName.MaximumLength = _fn->Length + sizeof(WCHAR)), MEM_FNAMECPY_TAG);
2811 DirNdx->FName.Length = _fn->Length;
2812 if(!DirNdx->FName.Buffer)
2814 RtlCopyMemory(DirNdx->FName.Buffer, _fn->Buffer, _fn->Length);
2815 DirNdx->FName.Buffer[_fn->Length/sizeof(WCHAR)] = 0;
2816CrF__2:
2817 DirNdx->FI_Flags |= UDFBuildHashEntry(Vcb, &(DirNdx->FName), &(DirNdx->hashes), HASH_ALL);
2818 // we get here immediately when 'undel' occured
2819 FileInfo->Index = i;
2821 DirNdx->FI_Flags &= ~UDF_FI_FLAG_SYS_ATTR;
2822 ASSERT(!DirNdx->FileInfo);
2823 DirNdx->FileInfo = FileInfo;
2824 DirNdx->FileEntryLoc = FEicb.extLocation;
2825 // mark file as 'deleted' for now
2827 FileInfo->FileIdent->fileCharacteristics |= FILE_DELETED;
2828 FileInfo->Dloc->DataLoc.Mapping = UDFExtentToMapping(&(FileInfo->Dloc->FELoc.Mapping[0]));
2829 if(!(FileInfo->Dloc->DataLoc.Mapping)) {
2830 UDFFlushFI(Vcb, FileInfo, PartNum);
2832 }
2833 FileInfo->Dloc->DataLoc.Length = 0;
2834 FileInfo->Dloc->DataLoc.Offset = FileInfo->Dloc->FileEntryLen;
2835 FileInfo->ParentFile = DirInfo;
2836 // init FileEntry
2839 UDFIncFileLinkCount(FileInfo); // increase to 1
2840 UDFUpdateCreateTime(Vcb, FileInfo);
2842 FileInfo->Dloc->FileEntry, Vcb->DefaultAttr);
2843 FileInfo->Dloc->DataLoc.Mapping[0].extLength &= UDF_EXTENT_LENGTH_MASK;
2844 FileInfo->Dloc->DataLoc.Modified = TRUE;
2845 FileInfo->Dloc->FELoc.Mapping[0].extLength &= UDF_EXTENT_LENGTH_MASK;
2846 // zero sector for FileEntry
2847 if(!Vcb->CDR_Mode) {
2848 status = UDFWriteData(Vcb, TRUE, ((int64)(FileInfo->Dloc->FELoc.Mapping[0].extLocation)) << Vcb->BlockSizeBits, LBS, FALSE, Vcb->ZBuffer, &ReadBytes);
2849 if(!OS_SUCCESS(status)) {
2850 UDFFlushFI(Vcb, FileInfo, PartNum);
2852 }
2853 }
2854#if 0
2855 if((i >= 2) && (DirNdx->FName.Buffer[0] == L'.')) {
2856 BrutePoint();
2857 }
2858#endif
2859
2860#ifdef UDF_CHECK_DISK_ALLOCATION
2861 if( /*FileInfo->Fcb &&*/
2862 UDFGetFreeBit(((uint32*)(Vcb->FSBM_Bitmap)), FileInfo->Dloc->FELoc.Mapping[0].extLocation)) {
2863
2864 if(!FileInfo->FileIdent ||
2865 !(FileInfo->FileIdent->fileCharacteristics & FILE_DELETED)) {
2866 AdPrint(("Flushing to Discarded block %x\n", FileInfo->Dloc->FELoc.Mapping[0].extLocation));
2867 BrutePoint();
2868 }
2869 }
2870#endif // UDF_CHECK_DISK_ALLOCATION
2871
2872 // make FileIdent valid
2873 FileInfo->FileIdent->fileCharacteristics = 0;
2874 DirNdx->FileCharacteristics = 0;
2876 UDFFlushFE(Vcb, FileInfo, PartNum);
2877 if(undel)
2878 hDirNdx->DelCount--;
2879 UDFReleaseDloc(Vcb, FileInfo->Dloc);
2881
2882 UDFCheckSpaceAllocation(Vcb, 0, FileInfo->Dloc->DataLoc.Mapping, AS_USED); // check if used
2883
2885
2886try_exit: NOTHING;
2887
2888 } _SEH2_FINALLY {
2889 if(!OS_SUCCESS(status)) {
2890 if(FEAllocated)
2891 UDFFreeFESpace(Vcb, DirInfo, &(FileInfo->Dloc->FELoc));
2892 }
2893 } _SEH2_END
2894 return status;
2895
2896} // end UDFCreateFile__()
VOID UDFAttributesToUDF(IN PDIR_INDEX_ITEM FileDirNdx, IN tag *FileEntry, IN ULONG NTAttr)
#define try_return(S)
Definition: cdprocs.h:2179
#define IgnoreCase
Definition: cdprocs.h:461
OSSTATUS UDFReleaseDloc(IN PVCB Vcb, IN PUDF_DATALOC_INFO Dloc)
Definition: dirtree.cpp:1224
OSSTATUS UDFDirIndexGrow(IN PDIR_INDEX_HDR *_hDirNdx, IN uint_di d)
Definition: dirtree.cpp:117
PDIR_INDEX_ITEM UDFDirIndexScan(PUDF_DIR_SCAN_CONTEXT Context, PUDF_FILE_INFO *_FileInfo)
Definition: dirtree.cpp:378
uint8 UDFBuildHashEntry(IN PVCB Vcb, IN PUNICODE_STRING Name, OUT PHASH_ENTRY hashes, IN uint8 Mask)
Definition: dirtree.cpp:429
OSSTATUS UDFFindFile(IN PVCB Vcb, IN BOOLEAN IgnoreCase, IN BOOLEAN NotDeleted, IN PUNICODE_STRING Name, IN PUDF_FILE_INFO DirInfo, IN OUT uint_di *Index)
Definition: dirtree.cpp:982
BOOLEAN UDFDirIndexInitScan(IN PUDF_FILE_INFO DirInfo, OUT PUDF_DIR_SCAN_CONTEXT Context, IN uint_di Index)
Definition: dirtree.cpp:347
#define _SEH2_FINALLY
Definition: filesup.c:21
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define NOTHING
Definition: input_list.c:10
#define L(x)
Definition: ntvdm.h:50
OSSTATUS UDFWriteData(IN PVCB Vcb, IN BOOLEAN Translate, IN int64 Offset, IN SIZE_T Length, IN BOOLEAN Direct, IN int8 *Buffer, OUT PSIZE_T WrittenBytes)
Definition: phys_lib.cpp:4141
#define STATUS_CANNOT_DELETE
Definition: shellext.h:71
uint_di DelCount
Definition: udf_rel.h:139
uint32 Offset
Definition: udf_rel.h:161
uint32 Length
Definition: udf_rel.h:168
HASH_ENTRY hashes
Definition: udf_rel.h:206
lb_addr extLocation
Definition: ecma_167.h:375
uint32 extLength
Definition: ecma_167.h:374
uint8 impUse[6]
Definition: ecma_167.h:376
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
void UDFSetFileSize(IN PUDF_FILE_INFO FileInfo, IN int64 Size)
Definition: udf_info.cpp:1157
OSSTATUS UDFBuildFileEntry(IN PVCB Vcb, IN PUDF_FILE_INFO DirInfo, IN PUDF_FILE_INFO FileInfo, IN uint32 PartNum, IN uint16 AllocMode, IN uint32 ExtAttrSz, IN BOOLEAN Extended)
Definition: udf_info.cpp:971
OSSTATUS UDFCloseFile__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:2994
OSSTATUS UDFBuildFileIdent(IN PVCB Vcb, IN PUNICODE_STRING fn, IN PLONG_AD FileEntryIcb, IN uint32 ImpUseLen, OUT PFILE_IDENT_DESC *_FileId, OUT uint32 *FileIdLen)
Definition: udf_info.cpp:1107
uint32 UDFCleanUpFile__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:2276
void UDFSetFileUID(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:1456
OSSTATUS UDFPretendFileDeleted__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:5566
OSSTATUS UDFOpenFile__(IN PVCB Vcb, IN BOOLEAN IgnoreCase, IN BOOLEAN NotDeleted, IN PUNICODE_STRING fn, IN PUDF_FILE_INFO DirInfo, OUT PUDF_FILE_INFO *_FileInfo, IN uint_di *IndexToOpen)
Definition: udf_info.cpp:2004
#define UDFIncFileLinkCount(fi)
Definition: udf_info.h:580
#define UDFReferenceFile__(fi)
Definition: udf_info.h:1043
#define UDFIsDeleted(DirNdx)
Definition: udf_info.h:788
#define UDFIncFileCounter(Vcb)
Definition: udf_info.h:614
#define UDFDirIndexGetLastIndex(di)
Definition: udf_info.h:1122
#define HASH_ALL
Definition: udf_info.h:78
#define MEM_FNAMECPY_TAG
Definition: udf_rel.h:485
#define UDF_FILE_INFO_MT
Definition: udf_rel.h:338
#define UDF_FILENAME_MT
Definition: udf_rel.h:126
struct _UDF_FILE_INFO * PUDF_FILE_INFO
#define STATUS_NOT_A_DIRECTORY
Definition: udferr_usr.h:169
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_FILE_DELETED
Definition: udferr_usr.h:172

Referenced by UDFCommonCreate(), UDFHardLinkFile__(), UDFRenameMoveFile__(), and UDFWriteSecurity().

◆ UDFCreateRootFile__()

OSSTATUS UDFCreateRootFile__ ( IN PVCB  Vcb,
IN uint32  PartNum,
IN uint32  ExtAttrSz,
IN uint32  ImpUseLen,
IN BOOLEAN  Extended,
OUT PUDF_FILE_INFO _FileInfo 
)

Definition at line 4827 of file udf_info.cpp.

4836{
4838 LONG_AD FEicb;
4840 *_FileInfo = NULL;
4842
4844 *_FileInfo = FileInfo;
4845 if(!FileInfo)
4847 ImpUseLen = (ImpUseLen + 3) & ~((uint16)3);
4848
4850 // init horizontal links
4851 FileInfo->NextLinkedFile =
4852 FileInfo->PrevLinkedFile = FileInfo;
4853 // allocate space for FileEntry
4854 if(!OS_SUCCESS(status =
4855 UDFBuildFileEntry(Vcb, NULL, FileInfo, PartNum, ICB_FLAG_AD_IN_ICB, ExtAttrSz, Extended) ))
4856 return status;
4857 FEicb.extLength = Vcb->LBlockSize;
4858 FEicb.extLocation.logicalBlockNum = UDFPhysLbaToPart(Vcb, PartNum, FileInfo->Dloc->FELoc.Mapping[0].extLocation);
4859 FEicb.extLocation.partitionReferenceNum = (uint16)PartNum;
4860 RtlZeroMemory(&(FEicb.impUse), sizeof(FEicb.impUse));
4861
4862 FileInfo->Dloc->DataLoc.Mapping = UDFExtentToMapping(&(FileInfo->Dloc->FELoc.Mapping[0]));
4863 if(!(FileInfo->Dloc->DataLoc.Mapping)) return STATUS_INSUFFICIENT_RESOURCES;
4864 FileInfo->Dloc->DataLoc.Length = 0;
4865 FileInfo->Dloc->DataLoc.Offset = FileInfo->Dloc->FileEntryLen;
4866 // init FileEntry
4869 UDFIncFileLinkCount(FileInfo); // increase to 1
4870 UDFUpdateCreateTime(Vcb, FileInfo);
4871 // zero sector for FileEntry
4872 FileInfo->Dloc->DataLoc.Mapping[0].extLength &= UDF_EXTENT_LENGTH_MASK;
4873 FileInfo->Dloc->FELoc.Mapping[0].extLength &= UDF_EXTENT_LENGTH_MASK;
4874 status = UDFWriteData(Vcb, TRUE, ((int64)(FileInfo->Dloc->FELoc.Mapping[0].extLocation)) << Vcb->BlockSizeBits, Vcb->LBlockSize, FALSE, Vcb->ZBuffer, &ReadBytes);
4875 if(!OS_SUCCESS(status))
4876 return status;
4877
4879 UDFReleaseDloc(Vcb, FileInfo->Dloc);
4880 return STATUS_SUCCESS;
4881} // end UDFCreateRootFile__()
#define MEM_FINF_TAG
Definition: udf_rel.h:489

Referenced by UDFCreateStreamDir__().

◆ UDFCreateStreamDir__()

OSSTATUS UDFCreateStreamDir__ ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo,
OUT PUDF_FILE_INFO _SDirInfo 
)

Definition at line 4888 of file udf_info.cpp.

4894{
4896 PUDF_FILE_INFO SDirInfo;
4897 uint16 Ident;
4898
4899 *_SDirInfo = NULL;
4901 // check currently recorded UDF revision
4904 // check if we are allowed to associate Stream Dir with this file
4905 if((FileInfo->ParentFile && UDFIsAStreamDir(FileInfo->ParentFile)) ||
4907 return STATUS_FILE_DELETED;
4908 // check if we have Deleted SDir
4909 if(FileInfo->Dloc->SDirInfo &&
4910 UDFIsSDirDeleted(FileInfo->Dloc->SDirInfo))
4911 return STATUS_ACCESS_DENIED;
4912 // check if this file has ExtendedFileEntry
4913 if((Ident = FileInfo->Dloc->FileEntry->tagIdent) != TID_EXTENDED_FILE_ENTRY) {
4915 return status;
4916 }
4917
4918 uint32 PartNum = UDFGetPartNumByPhysLba(Vcb, FileInfo->Dloc->FELoc.Mapping[0].extLocation);
4919 // create stream directory file
4920 if(!OS_SUCCESS(status = UDFCreateRootFile__(Vcb, PartNum, 0,0,FALSE, &SDirInfo)))
4921 return status;
4922 // link objects
4923 SDirInfo->ParentFile = FileInfo;
4924 // record directory structure
4926
4927 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_HAS_SDIR;
4929 FileInfo->Dloc->FE_Flags &= ~UDF_FE_FLAG_HAS_SDIR;
4930
4931 status = UDFRecordDirectory__(Vcb, SDirInfo);
4933
4934 UDFInterlockedIncrement((PLONG)&(FileInfo->OpenCount));
4935 if(!OS_SUCCESS(status)) {
4936 UDFUnlinkFile__(Vcb, SDirInfo, TRUE);
4937 UDFCloseFile__(Vcb, SDirInfo);
4938 UDFCleanUpFile__(Vcb, SDirInfo);
4939 MyFreePool__(SDirInfo);
4940 ((PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry))->streamDirectoryICB.extLength = 0;
4941 ((PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry))->streamDirectoryICB.extLocation.partitionReferenceNum = 0;
4942 ((PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry))->streamDirectoryICB.extLocation.logicalBlockNum = 0;
4943 return status;
4944 }
4945 *_SDirInfo = SDirInfo;
4946 // do some init
4947 ((PEXTENDED_FILE_ENTRY)(SDirInfo->Dloc->FileEntry))->icbTag.fileType = UDF_FILE_TYPE_STREAMDIR;
4948 ((PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry))->streamDirectoryICB.extLength = Vcb->LBlockSize;
4949 ((PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry))->streamDirectoryICB.extLocation.partitionReferenceNum = (uint16)PartNum;
4950 ((PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry))->streamDirectoryICB.extLocation.logicalBlockNum =
4951 UDFPhysLbaToPart(Vcb, PartNum, SDirInfo->Dloc->FELoc.Mapping[0].extLocation);
4952 ((PEXTENDED_FILE_ENTRY)(SDirInfo->Dloc->FileEntry))->uniqueID =
4953 ((PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry))->uniqueID;
4955 // open & finalize linkage
4956 FileInfo->Dloc->SDirInfo = SDirInfo;
4957 return STATUS_SUCCESS;
4958} // end UDFCreateStreamDir__()
#define UDF_FILE_TYPE_STREAMDIR
Definition: ecma_167.h:477
struct _UDF_FILE_INFO * ParentFile
Definition: udf_rel.h:381
OSSTATUS UDFConvertFEToExtended(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:5458
OSSTATUS UDFRecordDirectory__(IN PVCB Vcb, IN OUT PUDF_FILE_INFO DirInfo)
Definition: udf_info.cpp:3384
OSSTATUS UDFUnlinkFile__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN BOOLEAN FreeSpace)
Definition: udf_info.cpp:1766
OSSTATUS UDFCreateRootFile__(IN PVCB Vcb, IN uint32 PartNum, IN uint32 ExtAttrSz, IN uint32 ImpUseLen, IN BOOLEAN Extended, OUT PUDF_FILE_INFO *_FileInfo)
Definition: udf_info.cpp:4827
#define UDFStreamsSupported(Vcb)
Definition: udf_info.h:1037
#define UDFHasAStreamDir(FI)
Definition: udf_info.h:1000
#define UDFDecDirCounter(Vcb)
Definition: udf_info.h:617
#define UDF_FE_FLAG_HAS_SDIR
File contains Stream Dir.
Definition: udf_rel.h:325

Referenced by UDFCommonCreate(), and UDFWriteSecurity().

◆ UDFDecompressUnicode()

void __fastcall UDFDecompressUnicode ( IN OUT PUNICODE_STRING  UName,
IN uint8 CS0,
IN SIZE_T  Length,
OUT uint16 valueCRC 
)

Definition at line 170 of file udf_info.cpp.

176{
177 uint16 compID = CS0[0];
178 uint32 unicodeIndex = 0;
179 uint32 byteIndex = 1;
180 PWCHAR buff;
181 uint8* _CS0 = CS0+1;
182
183 if(!Length) goto return_empty_str;
184 // First check for valid compID.
185 switch(compID) {
186 case UDF_COMP_ID_8: {
187
189 if(!buff) goto return_empty_str;
190 UName->Buffer = buff;
191
192 // Loop through all the bytes.
193 while (byteIndex < Length) {
194 (*buff) = (*_CS0);
195 _CS0++;
196 byteIndex++;
197 buff++;
198 }
199 unicodeIndex = byteIndex-1;
200 break;
201 }
202 case UDF_COMP_ID_16: {
203
205 if(!buff) goto return_empty_str;
206 UName->Buffer = buff;
207
208 // Loop through all the bytes.
209 while (byteIndex < Length) {
210 // Move the first byte to the high bits of the unicode char.
211 *buff = ((*_CS0) << 8) | (*(_CS0+1));
212 _CS0+=2;
213 byteIndex+=2;
214 unicodeIndex++;
215 buff++;
216 ASSERT(byteIndex <= Length);
217 }
218 break;
219 }
220 default: {
221return_empty_str:
222 UName->Buffer = NULL;
223 UName->MaximumLength =
224 UName->Length = 0;
225 return;
226 }
227 }
228 UName->MaximumLength = (UName->Length = (((uint16)unicodeIndex)*sizeof(WCHAR))) + sizeof(WCHAR);
229 UName->Buffer[unicodeIndex] = 0;
230 if(valueCRC) {
231 *valueCRC = UDFCrc(CS0+1, Length-1);
232 }
233} // end UDFDecompressUnicode()
uint16 __fastcall UDFCrc(IN uint8 *Data, IN SIZE_T Size)
Definition: udf_info.cpp:4527
#define MEM_FNAME_TAG
Definition: udf_rel.h:483
#define MEM_FNAME16_TAG
Definition: udf_rel.h:484

Referenced by UDFGetDstring(), and UDFIndexDirectory().

◆ UDFDelXSpaceBitmap()

OSSTATUS UDFDelXSpaceBitmap ( IN PVCB  Vcb,
IN uint32  PartNum,
IN PSHORT_AD  bm 
)

◆ UDFDirIndex()

__inline PDIR_INDEX_ITEM UDFDirIndex ( IN PDIR_INDEX_HDR  hDirNdx,
IN uint_di  i 
)

Definition at line 1105 of file udf_info.h.

1107{
1108#ifdef UDF_LIMIT_DIR_SIZE
1109 if( hDirNdx && (i < hDirNdx->LastFrameCount))
1110 return &( (((PDIR_INDEX_ITEM*)(hDirNdx+1))[0])[i] );
1111#else //UDF_LIMIT_DIR_SIZE
1112 uint_di j, k;
1113 if( hDirNdx &&
1114 ((j = (i >> UDF_DIR_INDEX_FRAME_SH)) < (k = hDirNdx->FrameCount) ) &&
1115 ((i = (i & (UDF_DIR_INDEX_FRAME-1))) < ((j < (k-1)) ? UDF_DIR_INDEX_FRAME : hDirNdx->LastFrameCount)) )
1116 return &( (((PDIR_INDEX_ITEM*)(hDirNdx+1))[j])[i] );
1117#endif // UDF_LIMIT_DIR_SIZE
1118 return NULL;
1119}
#define UDF_DIR_INDEX_FRAME_SH
Definition: udf_info.h:1084
#define UDF_DIR_INDEX_FRAME
Definition: udf_info.h:1089

Referenced by UDFBlankMount(), UDFCleanUpFile__(), UDFCloseFile__(), UDFCommonCleanup(), UDFCommonClose(), UDFCommonCreate(), UDFCompareFileInfo(), UDFCompleteMount(), UDFCreateFile__(), UDFDoesOSAllowFilePretendDeleted__(), UDFDoesOSAllowFileToBeTargetForRename__(), UDFDoesOSAllowFileToBeUnlinked__(), UDFFindNextMatch(), UDFFirstOpenFile(), UDFFlushAFile(), UDFFlushFE(), UDFFlushFI(), UDFFlushFile__(), UDFGetAltNameInformation(), UDFGetBasicInformation(), UDFGetFileSizeFromDirNdx(), UDFGetFileStreamInformation(), UDFGetNetworkInformation(), UDFHardLinkFile__(), UDFIndexDirectory(), UDFIsDirEmpty(), UDFIsDirInfoCached(), UDFOpenFile__(), UDFPackDirectory__(), UDFPretendFileDeleted__(), UDFQueryDirectory(), UDFRecordDirectory__(), UDFRename(), UDFRenameMoveFile__(), UDFResizeFile__(), UDFReTagDirectory(), UDFSetBasicInformation(), UDFSetEOF(), UDFSetFileSizeInDirNdx(), UDFSetFileXTime(), UDFUnlinkAllFilesInDir(), and UDFUnlinkFile__().

◆ UDFDirIndexFree()

void UDFDirIndexFree ( PDIR_INDEX_HDR  hDirNdx)

Definition at line 98 of file dirtree.cpp.

101{
102 uint32 k;
103 PDIR_INDEX_ITEM* FrameList;
104
105 FrameList = (PDIR_INDEX_ITEM*)(hDirNdx+1);
106 if(!hDirNdx) return;
107 for(k=0; k<hDirNdx->FrameCount; k++, FrameList++) {
108 if(*FrameList) MyFreePool__(*FrameList);
109 }
110 MyFreePool__(hDirNdx);
111} // UDFDirIndexFree();
uint_di FrameCount
Definition: udf_rel.h:137

Referenced by UDFCleanUpFile__(), and UDFIndexDirectory().

◆ UDFDirIndexGetFrame()

PDIR_INDEX_ITEM UDFDirIndexGetFrame ( IN PDIR_INDEX_HDR  hDirNdx,
IN uint32  Frame,
OUT uint32 FrameLen,
OUT uint_di Index,
IN uint_di  Rel 
)

Definition at line 316 of file dirtree.cpp.

323{
324 if(Frame >= hDirNdx->FrameCount)
325 return NULL;
326 if(Index) {
327#ifdef UDF_LIMIT_DIR_SIZE
328 (*Index) = Rel;
329// if(FrameLen)
330 (*FrameLen) = hDirNdx->LastFrameCount;
331#else //UDF_LIMIT_DIR_SIZE
332 (*Index) = Frame*UDF_DIR_INDEX_FRAME+Rel;
333// if(FrameLen)
334 (*FrameLen) = (Frame < (hDirNdx->FrameCount-1)) ? UDF_DIR_INDEX_FRAME :
335 hDirNdx->LastFrameCount;
336#endif //UDF_LIMIT_DIR_SIZE
337 }
338 return ((PDIR_INDEX_ITEM*)(hDirNdx+1))[Frame]+Rel;
339} // end UDFDirIndexGetFrame()

Referenced by UDFDirIndexInitScan(), and UDFDirIndexScan().

◆ UDFDirIndexGrow()

OSSTATUS UDFDirIndexGrow ( IN PDIR_INDEX_HDR _hDirNdx,
IN uint_di  d 
)

Definition at line 117 of file dirtree.cpp.

121{
122 uint_di j,k;
123 PDIR_INDEX_HDR hDirNdx = *_hDirNdx;
124 PDIR_INDEX_ITEM* FrameList;
125
128
129 j = hDirNdx->LastFrameCount+d;
130
131 if(j > UDF_DIR_INDEX_FRAME) {
132#ifndef UDF_LIMIT_DIR_SIZE // release
133 // Grow header
134 k = hDirNdx->FrameCount;
135 if(!MyReallocPool__((int8*)hDirNdx, sizeof(DIR_INDEX_HDR) + k*sizeof(PDIR_INDEX_ITEM),
136 (int8**)(&hDirNdx), sizeof(DIR_INDEX_HDR) + (k+1)*sizeof(PDIR_INDEX_ITEM) ) )
138 FrameList = (PDIR_INDEX_ITEM*)(hDirNdx+1);
139 // Grow last frame
140 if(!MyReallocPool__((int8*)(FrameList[k-1]), AlignDirIndex(hDirNdx->LastFrameCount)*sizeof(DIR_INDEX_ITEM),
141 (int8**)(&(FrameList[k-1])), UDF_DIR_INDEX_FRAME*sizeof(DIR_INDEX_ITEM) ) )
143 RtlZeroMemory(&(FrameList[k-1][hDirNdx->LastFrameCount]),
144 (UDF_DIR_INDEX_FRAME-hDirNdx->LastFrameCount)*sizeof(DIR_INDEX_ITEM));
145 hDirNdx->LastFrameCount = UDF_DIR_INDEX_FRAME;
146 // Allocate new frame
148 if(!FrameList[k])
150 hDirNdx->FrameCount++;
151 RtlZeroMemory(FrameList[k], (j-UDF_DIR_INDEX_FRAME)*sizeof(DIR_INDEX_ITEM));
152 hDirNdx->LastFrameCount = j-UDF_DIR_INDEX_FRAME;
153 (*_hDirNdx) = hDirNdx;
154#else // UDF_LIMIT_DIR_SIZE
156#endif // UDF_LIMIT_DIR_SIZE
157 } else {
158 k = hDirNdx->FrameCount;
159 FrameList = (PDIR_INDEX_ITEM*)(hDirNdx+1);
160 if(!MyReallocPool__((int8*)(FrameList[k-1]), AlignDirIndex(hDirNdx->LastFrameCount)*sizeof(DIR_INDEX_ITEM),
161 (int8**)(&(FrameList[k-1])), AlignDirIndex(j)*sizeof(DIR_INDEX_ITEM) ) )
163 RtlZeroMemory(&(FrameList[k-1][hDirNdx->LastFrameCount]),
164 (j-hDirNdx->LastFrameCount)*sizeof(DIR_INDEX_ITEM));
165 hDirNdx->LastFrameCount = j;
166 }
167 return STATUS_SUCCESS;
168} // end UDFDirIndexGrow()
uint_di LastFrameCount
Definition: udf_rel.h:138
#define AlignDirIndex(n)
Definition: udf_info.h:1093
#define UDF_DIR_INDEX_MT
Definition: udf_rel.h:125
struct _DIR_INDEX_ITEM * PDIR_INDEX_ITEM
#define MEM_DIR_NDX_TAG
Definition: udf_rel.h:480
struct _DIR_INDEX_ITEM DIR_INDEX_ITEM

Referenced by UDFCreateFile__().

◆ UDFDirIndexInitScan()

BOOLEAN UDFDirIndexInitScan ( IN PUDF_FILE_INFO  DirInfo,
OUT PUDF_DIR_SCAN_CONTEXT  Context,
IN uint_di  Index 
)

Definition at line 347 of file dirtree.cpp.

352{
353 Context->DirInfo = DirInfo;
354 Context->hDirNdx = DirInfo->Dloc->DirIndex;
355 if( (Context->frame = (Index >> UDF_DIR_INDEX_FRAME_SH)) >=
356 Context->hDirNdx->FrameCount) {
357 return FALSE;
358 }
359 if( (Context->j = Index & (UDF_DIR_INDEX_FRAME-1)) >=
360 ((Context->frame < (Context->hDirNdx->FrameCount-1))
361 ?
362 UDF_DIR_INDEX_FRAME : Context->hDirNdx->LastFrameCount) ) {
363 return FALSE;
364 }
365 Context->DirNdx = UDFDirIndexGetFrame(Context->hDirNdx,
366 Context->frame,
367 &(Context->d),
368 &(Context->i),
369 Context->j);
370 Context->i--;
371 Context->j--;
372 Context->DirNdx--;
373
374 return TRUE;
375} // end UDFDirIndexInitScan()
PDIR_INDEX_ITEM UDFDirIndexGetFrame(IN PDIR_INDEX_HDR hDirNdx, IN uint32 Frame, OUT uint32 *FrameLen, OUT uint_di *Index, IN uint_di Rel)
Definition: dirtree.cpp:316

Referenced by UDFBuildTreeItemsList(), UDFCreateFile__(), UDFFindFile(), UDFFlushADirectory(), UDFMarkStreamsForDeletion(), UDFPackDirectory__(), and UDFReTagDirectory().

◆ UDFDirIndexScan()

PDIR_INDEX_ITEM UDFDirIndexScan ( PUDF_DIR_SCAN_CONTEXT  Context,
PUDF_FILE_INFO _FileInfo 
)

Definition at line 378 of file dirtree.cpp.

382{
384 PUDF_FILE_INFO ParFileInfo;
385
386 Context->i++;
387 Context->j++;
388 Context->DirNdx++;
389
390 if(Context->j >= Context->d) {
391 Context->j=0;
392 Context->frame++;
393 Context->DirNdx = UDFDirIndexGetFrame(Context->hDirNdx,
394 Context->frame,
395 &(Context->d),
396 &(Context->i),
397 Context->j);
398 }
399 if(!Context->DirNdx) {
400 if(_FileInfo)
401 (*_FileInfo) = NULL;
402 return NULL;
403 }
404
405 if(_FileInfo) {
406 if((FileInfo = Context->DirNdx->FileInfo)) {
407 if(FileInfo->ParentFile != Context->DirInfo) {
408 ParFileInfo = UDFLocateParallelFI(Context->DirInfo,
409 Context->i,
410 FileInfo);
411#ifdef UDF_DBG
412 if(ParFileInfo->ParentFile != Context->DirInfo) {
413 BrutePoint();
414 }
415#endif // UDF_DBG
416 FileInfo = ParFileInfo;
417 }
418 }
419 (*_FileInfo) = FileInfo;
420 }
421
422 return (Context->DirNdx);
423} // end UDFDirIndexScan()
PUDF_FILE_INFO UDFLocateParallelFI(PUDF_FILE_INFO di, uint_di i, PUDF_FILE_INFO fi)
Definition: dirtree.cpp:1417

Referenced by UDFBuildTreeItemsList(), UDFCreateFile__(), UDFFindFile(), UDFFlushADirectory(), UDFMarkStreamsForDeletion(), UDFPackDirectory__(), and UDFReTagDirectory().

◆ UDFDirIndexTrunc()

OSSTATUS UDFDirIndexTrunc ( IN PDIR_INDEX_HDR _hDirNdx,
IN uint_di  d 
)

Definition at line 174 of file dirtree.cpp.

178{
179 uint_di j,k;
180
181 if(d > UDF_DIR_INDEX_FRAME) {
183 while(d) {
185 if(!OS_SUCCESS(status = UDFDirIndexTrunc(_hDirNdx, k))) {
186 return status;
187 }
188 d -= k;
189 }
190 return STATUS_SUCCESS;
191 }
192
193 PDIR_INDEX_HDR hDirNdx = *_hDirNdx;
194 PDIR_INDEX_ITEM* FrameList;
195
197 FrameList = (PDIR_INDEX_ITEM*)(hDirNdx+1);
198 k = hDirNdx->FrameCount-1;
199
200 if(j <= UDF_DIR_INDEX_FRAME) {
201 // free last frame
202 if(!k && (j < 2)) {
203 // someone tries to trunc. residual entries...
205 }
206 MyFreePool__(FrameList[k]);
207 FrameList[k] = NULL;
209 hDirNdx->FrameCount--;
210 // Truncate new last frame
211 if(!MyReallocPool__((int8*)(FrameList[k-1]), UDF_DIR_INDEX_FRAME*sizeof(DIR_INDEX_ITEM),
212 (int8**)(&(FrameList[k-1])), AlignDirIndex(j)*sizeof(DIR_INDEX_ITEM) ) )
214 hDirNdx->LastFrameCount = j;
215 // Truncate header
216 if(!MyReallocPool__((int8*)hDirNdx, sizeof(DIR_INDEX_HDR) + (k+1)*sizeof(PDIR_INDEX_ITEM),
217 (int8**)(&hDirNdx), sizeof(DIR_INDEX_HDR) + k*sizeof(PDIR_INDEX_ITEM) ) )
219
220 (*_hDirNdx) = hDirNdx;
221
222 } else {
223
225 if(!k && (j < 2)) {
226 // someone tries to trunc. residual entries...
228 }
229
230 if(!MyReallocPool__((int8*)(FrameList[k]), AlignDirIndex(hDirNdx->LastFrameCount)*sizeof(DIR_INDEX_ITEM),
231 (int8**)(&(FrameList[k])), AlignDirIndex(j)*sizeof(DIR_INDEX_ITEM) ) )
233 hDirNdx->LastFrameCount = j;
234 }
235 return STATUS_SUCCESS;
236} // end UDFDirIndexTrunc()
OSSTATUS UDFDirIndexTrunc(IN PDIR_INDEX_HDR *_hDirNdx, IN uint_di d)
Definition: dirtree.cpp:174

Referenced by UDFDirIndexTrunc(), and UDFPackDirectory__().

◆ UDFDOSName()

void __fastcall UDFDOSName ( IN PVCB  Vcb,
IN OUT PUNICODE_STRING  DosName,
IN PUNICODE_STRING  UdfName,
IN BOOLEAN  KeepIntact 
)

Definition at line 427 of file udf_info.cpp.

433{
434#ifndef _CONSOLE
435 if(Vcb->CompatFlags & UDF_VCB_IC_OS_NATIVE_DOS_NAME) {
436 UDFDOSNameOsNative(DosName, UdfName, KeepIntact);
437 return;
438 }
439#endif //_CONSOLE
440
441 switch(Vcb->CurrentUDFRev) {
442 case 0x0100:
443 case 0x0101:
444 case 0x0102:
445 UDFDOSName100(DosName, UdfName, KeepIntact);
446 break;
447
448 case 0x0150:
449 // in general, we need bytes-from-media to
450 // create valid UDF 1.50 name.
451 // Curently it is impossible, thus, we'll use
452 // UDF 2.00 translation algorithm
453 case 0x0200:
454 UDFDOSName200(DosName, UdfName, KeepIntact, Vcb->CurrentUDFRev == 0x0150);
455 break;
456
457 case 0x0201:
458 default:
459 UDFDOSName201(DosName, UdfName, KeepIntact);
460 }
461}
void __fastcall UDFDOSNameOsNative(IN OUT PUNICODE_STRING DosName, IN PUNICODE_STRING UdfName, IN BOOLEAN KeepIntact)
#define UDF_VCB_IC_OS_NATIVE_DOS_NAME
Definition: udf_common.h:503
void __fastcall UDFDOSName100(IN OUT PUNICODE_STRING DosName, IN PUNICODE_STRING UdfName, IN BOOLEAN KeepIntact)
Definition: udf_info.cpp:465
void __fastcall UDFDOSName200(IN OUT PUNICODE_STRING DosName, IN PUNICODE_STRING UdfName, IN BOOLEAN KeepIntact, IN BOOLEAN Mode150)
Definition: udf_info.cpp:582
void __fastcall UDFDOSName201(IN OUT PUNICODE_STRING DosName, IN PUNICODE_STRING UdfName, IN BOOLEAN KeepIntact)
Definition: udf_info.cpp:700
_Out_ PUNICODE_STRING DosName
Definition: rtlfuncs.h:1269

Referenced by UDFBuildHashEntry(), UDFFileDirInfoToNT(), UDFFindFile(), and UDFIsNameInExpression().

◆ UDFDOSName100()

void __fastcall UDFDOSName100 ( IN OUT PUNICODE_STRING  DosName,
IN PUNICODE_STRING  UdfName,
IN BOOLEAN  KeepIntact 
)

Definition at line 465 of file udf_info.cpp.

470{
471 PWCHAR dosName = DosName->Buffer;
472 PWCHAR udfName = UdfName->Buffer;
473 uint32 udfLen = UdfName->Length / sizeof(WCHAR);
474
475 uint32 index, dosIndex = 0, extIndex = 0, lastPeriodIndex;
476 BOOLEAN needsCRC = FALSE, hasExt = FALSE, writingExt = FALSE, isParent = FALSE;
477 uint32 valueCRC;
479
480 if(KeepIntact &&
481 (udfLen <= 2) && (udfName[0] == UNICODE_PERIOD)) {
482 isParent = TRUE;
483 if((udfLen == 2) && (udfName[1] != UNICODE_PERIOD))
484 isParent = FALSE;
485 }
486
487 for (index = 0 ; index < udfLen ; index++) {
488 current = udfName[index];
489 if (current == UNICODE_PERIOD && !isParent) {
490 if (dosIndex==0 || hasExt) {
491 // Ignore leading periods or any other than used for extension.
492 needsCRC = TRUE;
493 } else {
494 // First, find last character which is NOT a period or space.
495 lastPeriodIndex = udfLen - 1;
496 while(lastPeriodIndex >=0 &&
497 (udfName[lastPeriodIndex] == UNICODE_PERIOD ||
498 udfName[lastPeriodIndex] == UNICODE_SPACE))
499 lastPeriodIndex--;
500 // Now search for last remaining period.
501 while(lastPeriodIndex >= 0 &&
502 udfName[lastPeriodIndex] != UNICODE_PERIOD)
503 lastPeriodIndex--;
504 // See if the period we found was the last or not.
505 if (lastPeriodIndex != index)
506 needsCRC = TRUE; // If not, name needs translation.
507 // As long as the period was not trailing,
508 // the file name has an extension.
509 if (lastPeriodIndex >= 0) hasExt = TRUE;
510 }
511 } else {
512 if ((!hasExt && dosIndex == DOS_NAME_LEN) ||
513 extIndex == DOS_EXT_LEN) {
514 // File name or extension is too long for DOS.
515 needsCRC = TRUE;
516 } else {
517 if (current == UNICODE_SPACE) { // Ignore spaces.
518 needsCRC = TRUE;
519 } else {
520 // Look for illegal or unprintable characters.
521 if (UDFIsIllegalChar(current) /*|| !UnicodeIsPrint(current)*/) {
522 needsCRC = TRUE;
524 /* Skip Illegal characters(even spaces),
525 * but not periods.
526 */
527 while(index+1 < udfLen &&
528 (UDFIsIllegalChar(udfName[index+1]) /*||
529 !UnicodeIsPrint(udfName[index+1])*/) &&
530 udfName[index+1] != UNICODE_PERIOD)
531 index++;
532 }
533 // Add current char to either file name or ext.
534 if (writingExt) {
535 ext[extIndex] = current;
536 extIndex++;
537 } else {
538 dosName[dosIndex] = current;
539 dosIndex++;
540 }
541 }
542 }
543 }
544 // See if we are done with file name, either because we reached
545 // the end of the file name length, or the final period.
546 if (!writingExt && hasExt && (dosIndex == DOS_NAME_LEN ||
547 index == lastPeriodIndex)) {
548 // If so, and the name has an extension, start reading it.
549 writingExt = TRUE;
550 // Extension starts after last period.
551 index = lastPeriodIndex;
552 }
553 }
554 //
555 if (needsCRC) {
556 // Add CRC to end of file name or at position 4.
557 if (dosIndex >4) dosIndex = 4;
558 valueCRC = UDFUnicodeCksum(udfName, udfLen);
559 // set CRC prefix
560 dosName[dosIndex] = UNICODE_CRC_MARK;
561 // Convert 12-bit CRC to hex characters.
562 dosName[dosIndex+1] = hexChar[(valueCRC & 0x0f00) >> 8];
563 dosName[dosIndex+2] = hexChar[(valueCRC & 0x00f0) >> 4];
564 dosName[dosIndex+3] = hexChar[(valueCRC & 0x000f)];
565 dosIndex+=4;
566 }
567 // Add extension, if any.
568 if (extIndex != 0) {
569 dosName[dosIndex] = UNICODE_PERIOD;
570 dosIndex++;
571 for (index = 0; index < extIndex; index++) {
572 dosName[dosIndex] = ext[index];
573 dosIndex++;
574 }
575 }
576 DosName->Length = (uint16)dosIndex*sizeof(WCHAR);
578} // end UDFDOSName100()
#define index(s, c)
Definition: various.h:29
static const WCHAR *const ext[]
Definition: module.c:53
GLuint index
Definition: glext.h:6031
struct task_struct * current
Definition: linux.c:32
uint16 __fastcall UDFUnicodeCksum(PWCHAR s, uint32 n)
Definition: udf_info.cpp:4356
#define hexChar
Definition: udf_info.cpp:45
BOOLEAN __fastcall UDFIsIllegalChar(IN WCHAR chr)
Definition: udf_info.cpp:370
#define UNICODE_SPACE
Definition: udf_rel.h:424
#define DOS_NAME_LEN
Definition: udf_rel.h:419
#define UNICODE_PERIOD
Definition: udf_rel.h:423
#define ILLEGAL_CHAR_MARK
Definition: udf_rel.h:421
#define UNICODE_CRC_MARK
Definition: udf_rel.h:422
#define DOS_EXT_LEN
Definition: udf_rel.h:420

Referenced by UDFDOSName().

◆ UDFDOSName200()

void __fastcall UDFDOSName200 ( IN OUT PUNICODE_STRING  DosName,
IN PUNICODE_STRING  UdfName,
IN BOOLEAN  KeepIntact,
IN BOOLEAN  Mode150 
)

Definition at line 582 of file udf_info.cpp.

588{
589 PWCHAR dosName = DosName->Buffer;
590 PWCHAR udfName = UdfName->Buffer;
591 uint32 udfLen = UdfName->Length / sizeof(WCHAR);
592
593 uint32 index, dosIndex = 0, extIndex = 0, lastPeriodIndex;
594 BOOLEAN needsCRC = FALSE, hasExt = FALSE, writingExt = FALSE, isParent = FALSE;
595 uint32 valueCRC;
597
598 if(KeepIntact &&
599 (udfLen <= 2) && (udfName[0] == UNICODE_PERIOD)) {
600 isParent = TRUE;
601 if((udfLen == 2) && (udfName[1] != UNICODE_PERIOD))
602 isParent = FALSE;
603 }
604
605 for (index = 0 ; index < udfLen ; index++) {
606 current = udfName[index];
607 if (current == UNICODE_PERIOD && !isParent) {
608 if (dosIndex==0 || hasExt) {
609 // Ignore leading periods or any other than used for extension.
610 needsCRC = TRUE;
611 } else {
612 // First, find last character which is NOT a period or space.
613 lastPeriodIndex = udfLen - 1;
614 while(lastPeriodIndex >=0 &&
615 (udfName[lastPeriodIndex] == UNICODE_PERIOD ||
616 udfName[lastPeriodIndex] == UNICODE_SPACE))
617 lastPeriodIndex--;
618 // Now search for last remaining period.
619 while(lastPeriodIndex >= 0 &&
620 udfName[lastPeriodIndex] != UNICODE_PERIOD)
621 lastPeriodIndex--;
622 // See if the period we found was the last or not.
623 if (lastPeriodIndex != index)
624 needsCRC = TRUE; // If not, name needs translation.
625 // As long as the period was not trailing,
626 // the file name has an extension.
627 if (lastPeriodIndex >= 0) hasExt = TRUE;
628 }
629 } else {
630 if ((!hasExt && dosIndex == DOS_NAME_LEN) ||
631 extIndex == DOS_EXT_LEN) {
632 // File name or extension is too long for DOS.
633 needsCRC = TRUE;
634 } else {
635 if (current == UNICODE_SPACE) { // Ignore spaces.
636 needsCRC = TRUE;
637 } else {
638 // Look for illegal or unprintable characters.
639 if (UDFIsIllegalChar(current) /*|| !UnicodeIsPrint(current)*/) {
640 needsCRC = TRUE;
642 /* Skip Illegal characters(even spaces),
643 * but not periods.
644 */
645 while(index+1 < udfLen &&
646 (UDFIsIllegalChar(udfName[index+1]) /*||
647 !UnicodeIsPrint(udfName[index+1])*/) &&
648 udfName[index+1] != UNICODE_PERIOD)
649 index++;
650 }
651 // Add current char to either file name or ext.
652 if (writingExt) {
653 ext[extIndex] = current;
654 extIndex++;
655 } else {
656 dosName[dosIndex] = current;
657 dosIndex++;
658 }
659 }
660 }
661 }
662 // See if we are done with file name, either because we reached
663 // the end of the file name length, or the final period.
664 if (!writingExt && hasExt && (dosIndex == DOS_NAME_LEN ||
665 index == lastPeriodIndex)) {
666 // If so, and the name has an extension, start reading it.
667 writingExt = TRUE;
668 // Extension starts after last period.
669 index = lastPeriodIndex;
670 }
671 }
672 // Now handle CRC if needed.
673 if (needsCRC) {
674 // Add CRC to end of file name or at position 4.
675 if (dosIndex >4) dosIndex = 4;
676 valueCRC = Mode150 ? UDFUnicodeCksum150(udfName, udfLen) : UDFUnicodeCksum(udfName, udfLen);
677 // Convert 16-bit CRC to hex characters.
678 dosName[dosIndex] = hexChar[(valueCRC & 0xf000) >> 12];
679 dosName[dosIndex+1] = hexChar[(valueCRC & 0x0f00) >> 8];
680 dosName[dosIndex+2] = hexChar[(valueCRC & 0x00f0) >> 4];
681 dosName[dosIndex+3] = hexChar[(valueCRC & 0x000f)];
682 dosIndex+=4;
683 }
684 // Add extension, if any.
685 if (extIndex != 0) {
686 dosName[dosIndex] = UNICODE_PERIOD;
687 dosIndex++;
688 for (index = 0; index < extIndex; index++) {
689 dosName[dosIndex] = ext[index];
690 dosIndex++;
691 }
692 }
693 DosName->Length = (uint16)dosIndex*sizeof(WCHAR);
695} // end UDFDOSName200()
uint16 __fastcall UDFUnicodeCksum150(PWCHAR s, uint32 n)
Definition: udf_info.cpp:4422

Referenced by UDFDOSName().

◆ UDFDOSName201()

void __fastcall UDFDOSName201 ( IN OUT PUNICODE_STRING  DosName,
IN PUNICODE_STRING  UdfName,
IN BOOLEAN  KeepIntact 
)

Definition at line 700 of file udf_info.cpp.

705{
706 PWCHAR dosName = DosName->Buffer;
707 PWCHAR udfName = UdfName->Buffer;
708 uint16 udfLen = UdfName->Length / sizeof(WCHAR);
709
710 uint16 index, dosIndex = 0;
711 //uint16 extIndex = 0;
712 BOOLEAN needsCRC = FALSE, isParent = FALSE;
713 //BOOLEAN hasExt = FALSE, writingExt = FALSE;
714 uint16 valueCRC;
717
718 if(KeepIntact &&
719 (udfLen <= 2) && (udfName[0] == UNICODE_PERIOD)) {
720 isParent = TRUE;
721 if((udfLen == 2) && (udfName[1] != UNICODE_PERIOD))
722 isParent = FALSE;
723 }
724
725 #define DOS_CRC_LEN 4
726 #define DOS_CRC_MODULUS 41
727
728 int16 crcIndex;
729 uint16 extLen;
730 uint16 nameLen;
731 uint16 charLen;
732 int16 overlayBytes;
733 int16 bytesLeft;
734
735 /* Start at the end of the UDF file name and scan for a period */
736 /* ('.'). This will be where the DOS extension starts (if */
737 /* any). */
738 index = udfLen;
739 while (index-- > 0) {
740 if (udfName[index] == '.')
741 break;
742 }
743 if ((index < 0) || isParent) {
744 /* There name was scanned to the beginning of the buffer */
745 /* and no extension was found. */
746 extLen = 0;
747 nameLen = udfLen;
748 } else {
749 /* A DOS extension was found, process it first. */
750 extLen = udfLen - index - 1;
751 nameLen = index;
752 dosIndex = 0;
753 bytesLeft = DOS_EXT_LEN;
754 while (++index < udfLen && bytesLeft > 0) {
755 /* Get the current character and convert it to upper */
756 /* case. */
757 current = udfName[index];
758 if (current == ' ') {
759 /* If a space is found, a CRC must be appended to */
760 /* the mangled file name. */
761 needsCRC = TRUE;
762 } else {
763 /* Determine if this is a valid file name char and */
764 /* calculate its corresponding BCS character byte */
765 /* length (zero if the char is not legal or */
766 /* undisplayable on this system). */
767
768 charLen = (UDFIsIllegalChar(current)
769 /*|| !UnicodeIsPrint(current)*/) ? 0 : 1;
770
771 /* If the char is larger than the available space */
772 /* in the buffer, pretend it is undisplayable. */
773 if (charLen > bytesLeft)
774 charLen = 0;
775 if (charLen == 0) {
776 /* Undisplayable or illegal characters are */
777 /* substituted with an underscore ("_"), and */
778 /* required a CRC code appended to the mangled */
779 /* file name. */
780 needsCRC = TRUE;
781 charLen = 1;
782 current = '_';
783 /* Skip over any following undiplayable or */
784 /* illegal chars. */
785 while (index +1 <udfLen &&
786 (UDFIsIllegalChar(udfName[index+1])
787 /*|| !UnicodeIsPrint(udfName[index+1])*/))
788 index++;
789 }
790 /* Assign the resulting char to the next index in */
791 /* the extension buffer and determine how many BCS */
792 /* bytes are left. */
793 ext[dosIndex++] = current;
794 bytesLeft -= charLen;
795 }
796 }
797 /* Save the number of Unicode characters in the extension */
798 extLen = dosIndex;
799 /* If the extension was too large, or it was zero length */
800 /* (i.e. the name ended in a period), a CRC code must be */
801 /* appended to the mangled name. */
802 if (index < udfLen || extLen == 0)
803 needsCRC = TRUE;
804 }
805 /* Now process the actual file name. */
806 index = 0;
807 dosIndex = 0;
808 crcIndex = 0;
809 overlayBytes = -1;
810 bytesLeft = DOS_NAME_LEN;
811 while (index < nameLen && bytesLeft > 0) {
812 /* Get the current character and convert it to upper case. */
813 current = udfName[index];
814 if (current ==' ' || (current == '.' && !isParent) ) {
815 /* Spaces and periods are just skipped, a CRC code */
816 /* must be added to the mangled file name. */
817 needsCRC = TRUE;
818 } else {
819 /* Determine if this is a valid file name char and */
820 /* calculate its corresponding BCS character byte */
821 /* length (zero if the char is not legal or */
822 /* undisplayable on this system). */
823
824 charLen = (UDFIsIllegalChar(current)
825 /*|| !UnicodeIsPrint(current)*/) ? 0 : 1;
826
827 /* If the char is larger than the available space in */
828 /* the buffer, pretend it is undisplayable. */
829 if (charLen > bytesLeft)
830 charLen = 0;
831
832 if (charLen == 0) {
833 /* Undisplayable or illegal characters are */
834 /* substituted with an underscore ("_"), and */
835 /* required a CRC code appended to the mangled */
836 /* file name. */
837 needsCRC = TRUE;
838 charLen = 1;
839 current = '_';
840 /* Skip over any following undisplayable or illegal */
841 /* chars. */
842 while (index +1 <nameLen &&
843 (UDFIsIllegalChar(udfName[index+1])
844 /*|| !UnicodeIsPrint(udfName[index+1])*/))
845 index++;
846 /* Terminate loop if at the end of the file name. */
847 if (index >= nameLen)
848 break;
849 }
850 /* Assign the resulting char to the next index in the */
851 /* file name buffer and determine how many BCS bytes */
852 /* are left. */
853 dosName[dosIndex++] = current;
854 bytesLeft -= charLen;
855 /* This figures out where the CRC code needs to start */
856 /* in the file name buffer. */
857 if (bytesLeft >= DOS_CRC_LEN) {
858 /* If there is enough space left, just tack it */
859 /* onto the end. */
860 crcIndex = dosIndex;
861 } else {
862 /* If there is not enough space left, the CRC */
863 /* must overlay a character already in the file */
864 /* name buffer. Once this condition has been */
865 /* met, the value will not change. */
866 if (overlayBytes < 0) {
867 /* Determine the index and save the length of */
868 /* the BCS character that is overlayed. It */
869 /* is possible that the CRC might overlay */
870 /* half of a two-byte BCS character depending */
871 /* upon how the character boundaries line up. */
872 overlayBytes = (bytesLeft + charLen > DOS_CRC_LEN)?1 :0;
873 crcIndex = dosIndex - 1;
874 }
875 }
876 }
877 /* Advance to the next character. */
878 index++;
879 }
880 /* If the scan did not reach the end of the file name, or the */
881 /* length of the file name is zero, a CRC code is needed. */
882 if (index < nameLen || index == 0)
883 needsCRC = TRUE;
884
885 /* If the name has illegal characters or and extension, it */
886 /* is not a DOS device name. */
887
888/* if (needsCRC == FALSE && extLen == 0) { */
889 /* If this is the name of a DOS device, a CRC code should */
890 /* be appended to the file name.
891 if (IsDeviceName(udfName, udfLen))
892 needsCRC = TRUE;
893 }*/
894
895 /* Append the CRC code to the file name, if needed. */
896 if (needsCRC) {
897 /* Get the CRC value for the original Unicode string */
898 valueCRC = UDFUnicodeCksum(udfName, udfLen);
899
900 /* begin. */
901 dosIndex = crcIndex;
902 /* If the character being overlayed is a two-byte BCS */
903 /* character, replace the first byte with an underscore. */
904 if (overlayBytes > 0)
905 dosName[dosIndex++] = '_';
906 /* Append the encoded CRC value with delimiter. */
907 dosName[dosIndex++] = '#';
908 dosName[dosIndex++] =
910 valueCRC %= DOS_CRC_MODULUS * DOS_CRC_MODULUS;
911 dosName[dosIndex++] =
912 crcChar[valueCRC / DOS_CRC_MODULUS];
913 valueCRC %= DOS_CRC_MODULUS;
914 dosName[dosIndex++] = crcChar[valueCRC];
915 }
916 /* Append the extension, if any. */
917 if (extLen > 0) {
918 /* Tack on a period and each successive byte in the */
919 /* extension buffer. */
920 dosName[dosIndex++] = '.';
921 for (index = 0; index < extLen; index++)
922 dosName[dosIndex++] = ext[index];
923 }
924 /* Return the length of the resulting Unicode string. */
925 DosName->Length = (uint16)dosIndex*sizeof(WCHAR);
927
928} // end UDFDOSName201()
short int16
Definition: platform.h:11
static const char crcChar[]
Definition: udf_info.cpp:46
#define DOS_CRC_MODULUS
Definition: udf_info.cpp:44
#define DOS_CRC_LEN

Referenced by UDFDOSName().

◆ UDFExtAllocDescToMapping()

PEXTENT_MAP UDFExtAllocDescToMapping ( IN PVCB  Vcb,
IN PLONG_AD  AllocDesc,
IN uint32  AllocDescLength,
IN uint32  SubCallCount,
OUT PEXTENT_INFO  AllocLoc 
)

◆ UDFExtentOffsetToLba()

uint32 UDFExtentOffsetToLba ( IN PVCB  Vcb,
IN PEXTENT_AD  Extent,
IN int64  Offset,
OUT uint32 SectorOffset,
OUT PSIZE_T  AvailLength,
OUT uint32 Flags,
OUT uint32 Index 
)

Definition at line 28 of file extent.cpp.

37{
38 uint32 j=0, l, d, BSh = Vcb->BlockSizeBits;
39 uint32 Offs;
40 uint32 i=0, BOffset; // block nums
41
42 BOffset = (uint32)(Offset >> BSh);
43 // scan extent table for suitable range (frag)
44 ExtPrint(("ExtLen %x\n", Extent->extLength));
45 while(i+(d = (l = (Extent->extLength & UDF_EXTENT_LENGTH_MASK)) >> BSh) <= BOffset) {
46
47 if(!l) {
48 if(Index) (*Index) = j-1;
49 if(Flags) {
50 Extent--;
51 (*Flags) = (Extent->extLength >> 30);
52 }
53 return LBA_OUT_OF_EXTENT;
54 }
55 if(!d)
56 break;
57 i += d; //frag offset
58 j++; // frag index
59 Extent++;
60 }
61 BOffset -= i;
62 Offs = (*((uint32*)&Offset)) - (i << BSh); // offset in frag
63
64 if(SectorOffset)
65 (*SectorOffset) = Offs & (Vcb->BlockSize-1);// offset in 1st Lba
66 if(AvailLength)
67 (*AvailLength) = l - Offs;// bytes to EO frag
68 if(Flags)
69 (*Flags) = (Extent->extLength >> 30);
70 if(Index)
71 (*Index) = j;
72
73 ASSERT(((Extent->extLength >> 30) == EXTENT_NOT_RECORDED_NOT_ALLOCATED) || Extent->extLocation);
74
75 return Extent->extLocation + BOffset;// 1st Lba
76} // end UDFExtentOffsetToLba()
#define SectorOffset(L)
Definition: cdprocs.h:1622
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by UDFBuildLongAllocDescs(), UDFBuildShortAllocDescs(), UDFFlushFI(), UDFIndexDirectory(), UDFIsExtentCached(), UDFMarkAllocatedAsNotXXX(), UDFMarkAllocatedAsRecorded(), UDFMarkNotAllocatedAsAllocated(), UDFPackDirectory__(), UDFPadLastSector(), UDFReadExtent(), UDFReadExtentLocation(), UDFResizeExtent(), UDFReTagDirectory(), UDFWriteExtent(), and UDFZeroExtent().

◆ UDFExtentToMapping_()

PEXTENT_MAP __fastcall UDFExtentToMapping_ ( IN PEXTENT_AD  Extent)

Definition at line 189 of file extent.cpp.

196{
197 PEXTENT_MAP Map;
198
199#ifdef UDF_TRACK_EXTENT_TO_MAPPING
200#define UDF_EXT_MAP_MULT 4
201#else //UDF_TRACK_EXTENT_TO_MAPPING
202#define UDF_EXT_MAP_MULT 2
203#endif //UDF_TRACK_EXTENT_TO_MAPPING
204
206 sizeof(EXTENT_MAP), MEM_EXTMAP_TAG);
207 if(!Map) return NULL;
208 RtlZeroMemory((int8*)(Map+1), sizeof(EXTENT_MAP));
209 Map[0].extLength = Extent->extLength;
210 Map[0].extLocation = Extent->extLocation;
211#ifdef UDF_TRACK_EXTENT_TO_MAPPING
212 Map[2].extLength = src;
213 Map[2].extLocation = line;
214#endif //UDF_TRACK_EXTENT_TO_MAPPING
215 return Map;
216} // end UDFExtentToMapping()
#define UDF_EXT_MAP_MULT

Referenced by UDFAllocFreeExtent_().

◆ UDFFindAnchor()

lba_t UDFFindAnchor ( PVCB  Vcb)

Definition at line 1011 of file mount.cpp.

1014{
1015// OSSTATUS RC = STATUS_SUCCESS;
1016
1017 uint16 ident;
1018 uint32 i;
1019 uint32 LastBlock;
1021 int8* Buf = (int8*)MyAllocatePool__(NonPagedPool,Vcb->BlockSize);
1022 BOOLEAN MRW_candidate;
1023 BOOLEAN IsMRW = (Vcb->MRWStatus != 0);
1024 if(!Buf)
1025 return 0;
1026
1027 UDFPrint(("UDFFindAnchor\n"));
1028 // init probable locations...
1029 RtlZeroMemory(&(Vcb->Anchor), sizeof(Vcb->Anchor));
1030 Vcb->Anchor[0] = 256 + Vcb->FirstLBALastSes;
1031 Vcb->Anchor[1] = 512 + Vcb->FirstLBALastSes;
1032 Vcb->Anchor[2] = 256 + Vcb->TrackMap[Vcb->LastTrackNum].FirstLba;
1033 Vcb->Anchor[3] = 512 + Vcb->TrackMap[Vcb->LastTrackNum].FirstLba;
1034 Vcb->Anchor[4] = Vcb->LastLBA - 256;
1035 Vcb->Anchor[5] = Vcb->LastLBA - 256 + 1;
1036 Vcb->Anchor[6] = Vcb->LastLBA - 256 - 2;
1037 // vat locations
1038 Vcb->Anchor[7] = Vcb->LastLBA - 2;
1039 Vcb->Anchor[8] = Vcb->LastLBA;
1040 Vcb->Anchor[9] = Vcb->LastLBA - 512;
1041// Vcb->Anchor[7] = Vcb->LastLBA - 256 - 7;
1042// Vcb->Anchor[8] = Vcb->LastLBA - 512 - 2;
1043// Vcb->Anchor[9] = Vcb->LastLBA - 512 - 7;
1044
1045 LastBlock = 0;
1046 // ... and check them
1047 for (i=0; i<sizeof(Vcb->Anchor)/sizeof(int); i++) {
1048 if(Vcb->Anchor[i] > Vcb->LastLBA)
1049 Vcb->Anchor[i] = 0;
1050 MRW_candidate = FALSE;
1051 if(Vcb->Anchor[i]) {
1052 UDFPrint(("check Anchor %x\n", Vcb->Anchor[i]));
1054 Vcb->Anchor[i], Vcb->Anchor[i], &ident))) {
1055
1056 // Fucking MRW...
1057 if(!IsMRW && (i<2) &&
1058 (Vcb->CompatFlags & UDF_VCB_IC_MRW_ADDR_PROBLEM)) {
1060 Vcb->Anchor[i]+MRW_DMA_OFFSET, Vcb->Anchor[i], &ident))) {
1061 // do MRW workaround.....
1062 UDFPrint(("UDF: looks like we have MRW....\n"));
1063 MRW_candidate = TRUE;
1064 goto MRW_workaround;
1065 }
1066 }
1067
1068 Vcb->Anchor[i] = 0;
1070 UDFPrint(("UDF: disk seems to be incomplete\n"));
1071 break;
1072 }
1073 } else {
1074MRW_workaround:
1075 if((ident != TID_ANCHOR_VOL_DESC_PTR) && ((i<6) ||
1077 Vcb->Anchor[i] = 0;
1078 } else {
1079 UDFPrint(("UDF: Found AVD at %x (point %d)\n",Vcb->Anchor[i], i));
1080 if(!LastBlock)
1081 LastBlock = Vcb->LastLBA;
1082 if(MRW_candidate) {
1083 UDFPrint(("UDF: looks like we _*really*_ have MRW....\n"));
1084 IsMRW = TRUE;
1085 ASSERT(Vcb->LastReadTrack == 1);
1086 Vcb->TrackMap[Vcb->LastReadTrack].Flags |= TrackMap_FixMRWAddressing;
1087 WCachePurgeAll__(&(Vcb->FastCache), Vcb);
1088 UDFPrint(("UDF: MRW on non-MRW drive => ReadOnly"));
1090
1091 UDFRegisterFsStructure(Vcb, Vcb->Anchor[i], Vcb->BlockSize);
1092
1093 }
1094 }
1095 }
1096 }
1097 }
1098
1099 UDFPrint(("UDF: -----------------\nUDF: Last block %x\n",LastBlock));
1100 MyFreePool__(Buf);
1101 return LastBlock;
1102} // end UDFFindAnchor()
#define MRW_DMA_OFFSET
Definition: cdrw_hw.h:3199
#define TrackMap_FixMRWAddressing
Definition: cdrw_usr.h:1642
#define TID_ANCHOR_VOL_DESC_PTR
Definition: ecma_167.h:155
#define UDF_VCB_FLAGS_VOLUME_READ_ONLY
Definition: udf_common.h:463
#define UDF_VCB_IC_MRW_ADDR_PROBLEM
Definition: udf_common.h:510
#define STATUS_NONEXISTENT_SECTOR
Definition: udferr_usr.h:143
VOID WCachePurgeAll__(IN PW_CACHE Cache, IN PVOID Context)
_In_ ULONG _In_ ULONG_PTR ident
Definition: winddi.h:3994

Referenced by UDFGetDiskInfoAndVerify().

◆ UDFFindDloc()

LONG UDFFindDloc ( IN PVCB  Vcb,
IN uint32  Lba 
)

Definition at line 1127 of file dirtree.cpp.

1131{
1132 PUDF_DATALOC_INDEX DlocList;
1133 uint32 l;
1134
1135 if(!(DlocList = Vcb->DlocList) || !Lba) return (-1);
1136 // scan FE location cache
1137 l = Vcb->DlocCount;
1138 for(uint32 i=0; i<l; i++, DlocList++) {
1139 if(DlocList->Lba == Lba)
1140 return i;
1141 }
1142 return (-1);
1143} // end UDFFindDloc()

Referenced by UDFBuildFileEntry(), and UDFStoreDloc().

◆ UDFFindFile()

OSSTATUS UDFFindFile ( IN PVCB  Vcb,
IN BOOLEAN  IgnoreCase,
IN BOOLEAN  NotDeleted,
IN PUNICODE_STRING  Name,
IN PUDF_FILE_INFO  DirInfo,
IN OUT uint_di Index 
)

Definition at line 982 of file dirtree.cpp.

990{
991// PDIR_INDEX_HDR hDirIndex = DirInfo->Dloc->DirIndex;
993 WCHAR ShortNameBuffer[13];
994 PDIR_INDEX_ITEM DirNdx;
995 UDF_DIR_SCAN_CONTEXT ScanContext;
996 uint_di j=(-1), k=(-1);
997 HASH_ENTRY hashes;
998 BOOLEAN CanBe8d3;
999
1001
1002 if((CanBe8d3 = UDFCanNameBeA8dot3(Name))) {
1003 ShortName.MaximumLength = 13 * sizeof(WCHAR);
1004 ShortName.Buffer = (PWCHAR)&ShortNameBuffer;
1005 }
1006
1007 if(!UDFDirIndexInitScan(DirInfo, &ScanContext, (*Index)))
1009
1010 if(!IgnoreCase && !CanBe8d3) {
1011 // perform case sensetive sequential directory scan
1012
1013 while((DirNdx = UDFDirIndexScan(&ScanContext, NULL))) {
1014 if( (DirNdx->hashes.hPosix == hashes.hPosix) &&
1015 DirNdx->FName.Buffer &&
1016 (!RtlCompareUnicodeString(&(DirNdx->FName), Name, FALSE)) &&
1017 ( (!UDFIsDeleted(DirNdx)) || (!NotDeleted) ) ) {
1018 (*Index) = ScanContext.i;
1019 return STATUS_SUCCESS;
1020 }
1021 }
1023 }
1024
1025 if(hashes.hPosix == hashes.hLfn) {
1026
1027 while((DirNdx = UDFDirIndexScan(&ScanContext, NULL))) {
1028 if(!DirNdx->FName.Buffer ||
1029 (NotDeleted && UDFIsDeleted(DirNdx)) )
1030 continue;
1031 if( (DirNdx->hashes.hLfn == hashes.hLfn) &&
1032 (!RtlCompareUnicodeString(&(DirNdx->FName), Name, IgnoreCase)) ) {
1033 (*Index) = ScanContext.i;
1034 return STATUS_SUCCESS;
1035 } else
1036 if( CanBe8d3 &&
1037 !(DirNdx->FI_Flags & UDF_FI_FLAG_DOS) &&
1038 (DirNdx->hashes.hDos == hashes.hLfn) &&
1039 (k == (uint_di)(-1))) {
1040 UDFDOSName(Vcb, &ShortName, &(DirNdx->FName), ScanContext.i < 2) ;
1042 k = ScanContext.i;
1043 }
1044 }
1045
1046 } else {
1047
1048 while((DirNdx = UDFDirIndexScan(&ScanContext, NULL))) {
1049 // perform sequential directory scan
1050 if(!DirNdx->FName.Buffer ||
1051 (NotDeleted && UDFIsDeleted(DirNdx)) )
1052 continue;
1053 if( (DirNdx->hashes.hPosix == hashes.hPosix) &&
1054 (!RtlCompareUnicodeString(&(DirNdx->FName), Name, FALSE)) ) {
1055 (*Index) = ScanContext.i;
1056 return STATUS_SUCCESS;
1057 } else
1058 if( (DirNdx->hashes.hLfn == hashes.hLfn) &&
1059 (j == (uint_di)(-1)) &&
1060 (!RtlCompareUnicodeString(&(DirNdx->FName), Name, IgnoreCase)) ) {
1061 j = ScanContext.i;
1062 } else
1063 if( CanBe8d3 &&
1064 !(DirNdx->FI_Flags & UDF_FI_FLAG_DOS) &&
1065 (DirNdx->hashes.hDos == hashes.hLfn) &&
1066 (k == (uint_di)(-1))) {
1067 UDFDOSName(Vcb, &ShortName, &(DirNdx->FName), ScanContext.i < 2 );
1069 k = ScanContext.i;
1070 }
1071 }
1072 }
1073 }
1074
1075 if(j != (uint_di)(-1)) {
1076 (*Index) = j;
1077 return STATUS_SUCCESS;
1078 } else
1079 if(k != (uint_di)(-1)) {
1080 (*Index) = k;
1081 return STATUS_SUCCESS;
1082 }
1083
1085
1086} // end UDFFindFile()
IN PDCB IN POEM_STRING IN PUNICODE_STRING IN OUT POEM_STRING ShortName
Definition: fatprocs.h:1306
BOOLEAN __fastcall UDFCanNameBeA8dot3(IN PUNICODE_STRING Name)
Definition: namesup.cpp:266
Definition: udf_rel.h:128
uint32 hLfn
Definition: udf_rel.h:130
uint32 hDos
Definition: udf_rel.h:129
uint32 hPosix
Definition: udf_rel.h:131
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149

Referenced by UDFCreateFile__(), UDFFindFile__(), UDFHardLinkFile__(), UDFOpenFile__(), and UDFRenameMoveFile__().

◆ UDFFindFile__()

__inline OSSTATUS UDFFindFile__ ( IN PVCB  Vcb,
IN BOOLEAN  IgnoreCase,
IN PUNICODE_STRING  Name,
IN PUDF_FILE_INFO  DirInfo 
)

Definition at line 114 of file udf_info.h.

118{
119 if(!DirInfo->Dloc->DirIndex)
121 uint_di i=0;
122 return UDFFindFile(Vcb, IgnoreCase, TRUE, Name, DirInfo, &i);
123}
OSSTATUS UDFFindFile(IN PVCB Vcb, IN BOOLEAN IgnoreCase, IN BOOLEAN NotDeleted, IN PUNICODE_STRING Name, IN PUDF_FILE_INFO DirInfo, IN OUT uint_di *Index)
Definition: dirtree.cpp:982

Referenced by UDFCommonCreate(), and UDFRename().

◆ UDFFindFreeDloc()

LONG UDFFindFreeDloc ( IN PVCB  Vcb,
IN uint32  Lba 
)

Definition at line 1171 of file dirtree.cpp.

1175{
1176 PUDF_DATALOC_INDEX DlocList;
1177 uint32 l;
1178
1179 if(!Vcb->DlocList) {
1180 // init FE location cache
1182 return (-1);
1184 Vcb->DlocCount = DLOC_LIST_GRANULARITY;
1185 }
1186 // scan for free entry
1187 DlocList = Vcb->DlocList;
1188 l = Vcb->DlocCount;
1189 for(uint32 i=0; i<l; i++, DlocList++) {
1190 if(!DlocList->Dloc)
1191 return i;
1192 }
1193 // alloc some free entries
1194 if(!MyReallocPool__((int8*)(Vcb->DlocList), Vcb->DlocCount*sizeof(UDF_DATALOC_INDEX),
1195 (int8**)&(Vcb->DlocList), (Vcb->DlocCount+DLOC_LIST_GRANULARITY)*sizeof(UDF_DATALOC_INDEX))) {
1196 return (-1);
1197 }
1198 RtlZeroMemory(&(Vcb->DlocList[Vcb->DlocCount]), DLOC_LIST_GRANULARITY*sizeof(UDF_DATALOC_INDEX));
1199 Vcb->DlocCount += DLOC_LIST_GRANULARITY;
1200 return (Vcb->DlocCount - DLOC_LIST_GRANULARITY);
1201} // end UDFFindFreeDloc()
PUDF_DATALOC_INFO Dloc
Definition: udf_rel.h:437
#define DLOC_LIST_GRANULARITY
Definition: udf_common.h:654
#define MEM_DLOC_NDX_TAG
Definition: udf_rel.h:481

Referenced by UDFStoreDloc().

◆ UDFFindLastFileSet()

OSSTATUS UDFFindLastFileSet ( IN PVCB  Vcb,
IN lb_addr Addr,
IN OUT PFILE_SET_DESC  FileSetDesc 
)

Definition at line 2739 of file mount.cpp.

2744{
2746 uint32 relLocExt = Addr->logicalBlockNum;
2747 uint32 locExt = UDFPartLbaToPhys(Vcb, Addr);
2748 uint16 Ident;
2749 uint32 relPrevExt, prevExt;
2750
2751 relPrevExt, prevExt = NULL;
2752 FileSetDesc->nextExt.extLength = 1; // ;)
2753 // walk through FileSet chain
2754 // we've just pre-init'd extent length to read 1st FileSet
2755 while(FileSetDesc->nextExt.extLength) {
2756 status = UDFReadTagged(Vcb, (int8*)FileSetDesc, locExt, relLocExt, &Ident);
2757 if(!OS_SUCCESS(status)) {
2758 FileSetDesc->nextExt.extLength = 0;
2759 return status;
2760 }
2761 UDFRegisterFsStructure(Vcb, locExt, Vcb->BlockSize);
2762 if((locExt == LBA_OUT_OF_EXTENT) || (Ident != TID_FILE_SET_DESC)) {
2763 // try to read previous FileSet
2764 if(!prevExt) return STATUS_UNRECOGNIZED_VOLUME;
2765 status = UDFReadTagged(Vcb, (int8*)FileSetDesc, prevExt, relLocExt, &Ident);
2766 if(OS_SUCCESS(status)) {
2767 UDFRegisterFsStructure(Vcb, prevExt, Vcb->BlockSize);
2768 }
2769 return status;
2770 }
2771 prevExt = locExt;
2772 relPrevExt = relLocExt;
2773 locExt = UDFPartLbaToPhys(Vcb, &(FileSetDesc->nextExt.extLocation));
2774 }
2775 return STATUS_SUCCESS;
2776} // end UDFFindLastFileSet()
#define TID_FILE_SET_DESC
Definition: ecma_167.h:165
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173

Referenced by UDFGetDiskInfoAndVerify().

◆ UDFFindMinSuitableExtent()

SIZE_T UDFFindMinSuitableExtent ( IN PVCB  Vcb,
IN uint32  Length,
IN uint32  SearchStart,
IN uint32  SearchLim,
OUT uint32 MaxExtLen,
IN uint8  AllocFlags 
)

Definition at line 556 of file alloc.cpp.

564{
565 SIZE_T i, len;
566 uint32* cur;
567 SIZE_T best_lba=0;
568 SIZE_T best_len=0;
569 SIZE_T max_lba=0;
570 SIZE_T max_len=0;
572 SIZE_T PS = Vcb->WriteBlockSize >> Vcb->BlockSizeBits;
573
575
576 // we'll try to allocate packet-aligned block at first
577 if(!(Length & (PS-1)) && !Vcb->CDR_Mode && (Length >= PS*2))
578 align = TRUE;
579 if(AllocFlags & EXTENT_FLAG_ALLOC_SEQUENTIAL)
580 align = TRUE;
581 if(Length > (uint32)(UDF_MAX_EXTENT_LENGTH >> Vcb->BlockSizeBits))
582 Length = (UDF_MAX_EXTENT_LENGTH >> Vcb->BlockSizeBits);
583 // align Length according to _Logical_ block size & convert it to BCount
584 i = (1<<Vcb->LB2B_Bits)-1;
585 Length = (Length+i) & ~i;
586 cur = (uint32*)(Vcb->FSBM_Bitmap);
587
588retry_no_align:
589
591 // scan Bitmap
592 while(i<SearchLim) {
593 ASSERT(i <= SearchLim);
594 if(align) {
595 i = (i+PS-1) & ~(PS-1);
596 ASSERT(i <= SearchLim);
597 if(i >= SearchLim)
598 break;
599 }
600 len = UDFGetBitmapLen(cur, i, SearchLim);
601 if(UDFGetFreeBit(cur, i)) { // is the extent found free or used ?
602 // wow! it is free!
603 if(len >= Length) {
604 // minimize extent length
605 if(!best_len || (best_len > len)) {
606 best_lba = i;
607 best_len = len;
608 }
609 if(len == Length)
610 break;
611 } else {
612 // remember max extent
613 if(max_len < len) {
614 max_lba = i;
615 max_len = len;
616 }
617 }
618 // if this is CD-R mode, we should not think about fragmentation
619 // due to CD-R nature file will be fragmented in any case
620 if(Vcb->CDR_Mode) break;
621 }
622 i += len;
623 }
624 // if we can't find suitable Packet-size aligned block,
625 // retry without any alignment requirements
626 if(!best_len && align) {
627 align = FALSE;
628 goto retry_no_align;
629 }
630 if(best_len) {
631 // minimal suitable block
632 (*MaxExtLen) = best_len;
633 return best_lba;
634 }
635 // maximal available
636 (*MaxExtLen) = max_len;
637 return max_lba;
638} // end UDFFindMinSuitableExtent()
int align(int length, int align)
Definition: dsound8.c:36
FxCollectionEntry * cur
#define EXTENT_FLAG_ALLOC_SEQUENTIAL
Definition: udf_rel.h:77

Referenced by UDFAllocFreeExtent_().

◆ UDFFindVRS()

uint32 UDFFindVRS ( PVCB  Vcb)

Definition at line 1108 of file mount.cpp.

1111{
1112 VolStructDesc *vsd = NULL;
1113 uint32 offset;
1114 uint32 retStat = 0;
1115 uint32 BeginOffset = Vcb->FirstLBA;
1116 OSSTATUS RC;
1119
1120 if(!buffer) return 0;
1121 // Relative to First LBA in Last Session
1122 offset = Vcb->FirstLBA + 0x10;
1123
1124 UDFPrint(("UDFFindVRS:\n"));
1125
1126 // Process the sequence (if applicable)
1127 for (;(offset-BeginOffset <=0x20); offset ++) {
1128 // Read a block
1130 if(!OS_SUCCESS(RC)) continue;
1131
1132 // Look for ISO descriptors
1133 vsd = (VolStructDesc *)(buffer);
1134
1135 if(vsd->stdIdent[0]) {
1136 if(!strncmp((int8*)(&vsd->stdIdent), STD_ID_CD001, STD_ID_LEN))
1137 {
1138 retStat |= VRS_ISO9660_FOUND;
1139 switch (vsd->structType)
1140 {
1141 case 0:
1142 UDFPrint(("UDF: ISO9660 Boot Record found\n"));
1143 break;
1144 case 1:
1145 UDFPrint(("UDF: ISO9660 Primary Volume Descriptor found\n"));
1146 break;
1147 case 2:
1148 UDFPrint(("UDF: ISO9660 Supplementary Volume Descriptor found\n"));
1149 break;
1150 case 3:
1151 UDFPrint(("UDF: ISO9660 Volume Partition Descriptor found\n"));
1152 break;
1153 case 255:
1154 UDFPrint(("UDF: ISO9660 Volume Descriptor Set Terminator found\n"));
1155 break;
1156 default:
1157 UDFPrint(("UDF: ISO9660 VRS (%u) found\n", vsd->structType));
1158 break;
1159 }
1160 }
1161 else if(!strncmp((int8*)(&vsd->stdIdent), STD_ID_BEA01, STD_ID_LEN))
1162 {
1163 UDFPrint(("UDF: BEA01 Found\n"));
1164 }
1165 else if(!strncmp((int8*)(&vsd->stdIdent), STD_ID_TEA01, STD_ID_LEN))
1166 {
1167 UDFPrint(("UDF: TEA01 Found\n"));
1168 break;
1169 }
1170 else if(!strncmp((int8*)(&vsd->stdIdent), STD_ID_NSR02, STD_ID_LEN))
1171 {
1172 retStat |= VRS_NSR02_FOUND;
1173 UDFPrint(("UDF: NSR02 Found\n"));
1174 break;
1175 }
1176 else if(!strncmp((int8*)(&vsd->stdIdent), STD_ID_NSR03, STD_ID_LEN))
1177 {
1178 retStat |= VRS_NSR03_FOUND;
1179 UDFPrint(("UDF: NSR03 Found\n"));
1180 break;
1181 }
1182 }
1183 }
1184
1186
1187 return retStat;
1188} // end UDFFindVRS()
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define STD_ID_TEA01
Definition: ecma_167.h:86
#define STD_ID_LEN
Definition: ecma_167.h:71
#define STD_ID_NSR03
Definition: ecma_167.h:85
#define STD_ID_NSR02
Definition: ecma_167.h:84
#define STD_ID_CD001
Definition: ecma_167.h:82
#define STD_ID_BEA01
Definition: ecma_167.h:80
GLuint buffer
Definition: glext.h:5915
GLintptr offset
Definition: glext.h:5920
#define UDFReadSectors(Vcb, Translate, Lba, BCount, Direct, Buffer, ReadBytes)
Definition: phys_lib.h:126
uint8 structType
Definition: ecma_167.h:73
uint8 stdIdent[STD_ID_LEN]
Definition: ecma_167.h:74
#define VRS_NSR02_FOUND
Definition: udf_rel.h:112
#define VRS_NSR03_FOUND
Definition: udf_rel.h:113
#define VRS_ISO9660_FOUND
Definition: udf_rel.h:114

Referenced by UDFGetDiskInfoAndVerify().

◆ UDFFlushAllCachedAllocations()

OSSTATUS UDFFlushAllCachedAllocations ( IN PVCB  Vcb,
IN uint32  AllocClass 
)

Definition at line 1508 of file extent.cpp.

1512{
1513 PUDF_ALLOCATION_CACHE_ITEM AllocCache;
1514 uint32 i, lim;
1516
1517 UDFPrint(("Flush AllocationCache\n"));
1518 UDFAcquireResourceExclusive(&(Vcb->PreallocResource),TRUE);
1519
1520 status = UDFInitAllocationCache(Vcb, AllocClass, &AllocCache, &lim, FALSE);
1521 if(!OS_SUCCESS(status)) {
1522 UDFReleaseResource(&(Vcb->PreallocResource));
1523 return status;
1524 }
1525
1526 for(i=0; i<lim; i++) {
1527 if(AllocCache[i].ParentLocation != LBA_NOT_ALLOCATED) {
1528 switch(AllocClass) {
1530 UDFDiscardFESpace(Vcb, AllocCache[i].Ext.Mapping, AllocCache[i].Items);
1531 break;
1533 UDFMarkSpaceAsXXX(Vcb, 0, AllocCache[i].Ext.Mapping, AS_DISCARDED);
1534 break;
1535 }
1536 }
1537 }
1538 MyFreePool__(AllocCache);
1539 switch(AllocClass) {
1541 Vcb->FEChargeCache = NULL;
1542 Vcb->FEChargeCacheMaxSize = 0;
1543 break;
1545 Vcb->PreallocCache = NULL;
1546 Vcb->PreallocCacheMaxSize = 0;
1547 break;
1548 }
1549 UDFReleaseResource(&(Vcb->PreallocResource));
1550 //
1551 return STATUS_SUCCESS;
1552} // end UDFFlushAllCachedAllocations()
void UDFDiscardFESpace(IN PVCB Vcb, IN PEXTENT_MAP Mapping, IN uint32 lim)
Definition: extent.cpp:1329
OSSTATUS UDFInitAllocationCache(IN PVCB Vcb, IN uint32 AllocClass, OUT PUDF_ALLOCATION_CACHE_ITEM *_AllocCache, OUT uint32 *_lim, IN BOOLEAN Init)
Definition: extent.cpp:1361
#define UDF_PREALLOC_CLASS_DIR
Definition: udf_info.h:356
#define LBA_NOT_ALLOCATED
Definition: udf_rel.h:427

Referenced by UDFEjectReqWaiter(), and UDFUmount__().

◆ UDFFlushFE()

OSSTATUS UDFFlushFE ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo,
IN uint32  PartNum 
)

Definition at line 3864 of file udf_info.cpp.

3869{
3870 int8* NewAllocDescs;
3872 SIZE_T WrittenBytes;
3873 uint16 AllocMode;
3874 uint32 lba;
3875
3876 AllocMode = ((PFILE_ENTRY)(FileInfo->Dloc->FileEntry))->icbTag.flags & ICB_FLAG_ALLOC_MASK;
3877#ifdef UDF_DBG
3878/* if(UDFIsADirectory(FileInfo) && (UDFGetFileSize(FileInfo) < 0x28) &&
3879 !UDFIsDeleted(UDFDirIndex(DirInfo->Dloc->DirIndex, FileInfo->Index)) ) {
3880 BrutePoint();
3881 }*/
3882// ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation);
3883 if(FileInfo->Dloc->FELoc.Offset) {
3884 BrutePoint();
3885 }
3886 if(FileInfo->Dloc->AllocLoc.Mapping) {
3887 ASSERT(AllocMode != ICB_FLAG_AD_IN_ICB);
3888 }
3889#endif // UDF_DBG
3890retry_flush_FE:
3891 UDFPrint((" FlushFE: %x\n", FileInfo->Dloc->FELoc.Mapping[0].extLocation));
3892#ifndef UDF_READ_ONLY_BUILD
3894 if(FileInfo->Dloc->DataLoc.Modified ||
3895 FileInfo->Dloc->AllocLoc.Modified) {
3896 ASSERT(PartNum != (uint32)(-1));
3897 // prepare new AllocDescs for flushing...
3898 if(!OS_SUCCESS(status = UDFBuildAllocDescs(Vcb, PartNum, FileInfo, &NewAllocDescs))) {
3899 UDFPrint((" FlushFE: UDFBuildAllocDescs() faliled (%x)\n", status));
3900 if(NewAllocDescs)
3901 MyFreePool__(NewAllocDescs);
3902 return status;
3903 }
3904#ifdef UDF_DBG
3905 if(Vcb->CompatFlags & UDF_VCB_IC_W2K_COMPAT_ALLOC_DESCS) {
3906 ASSERT(UDFGetFileSize(FileInfo) <= UDFGetExtentLength(FileInfo->Dloc->DataLoc.Mapping));
3907 } else {
3908 ASSERT(((UDFGetFileSize(FileInfo)+Vcb->LBlockSize-1) & (Vcb->LBlockSize-1)) ==
3909 ((UDFGetExtentLength(FileInfo->Dloc->DataLoc.Mapping)+Vcb->LBlockSize-1) & (Vcb->LBlockSize-1)));
3910 }
3911 AllocMode = ((PFILE_ENTRY)(FileInfo->Dloc->FileEntry))->icbTag.flags & ICB_FLAG_ALLOC_MASK;
3912#endif // UDF_DBG
3913 // initiate update of lengthAllocDescs
3914 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_FE_MODIFIED;
3915 if(NewAllocDescs) {
3916 ASSERT(AllocMode != ICB_FLAG_AD_IN_ICB);
3917 status = UDFPadLastSector(Vcb, &(FileInfo->Dloc->AllocLoc));
3918 // ... and flush it
3919 status = UDFWriteExtent(Vcb, &(FileInfo->Dloc->AllocLoc), 0, (uint32)(FileInfo->Dloc->AllocLoc.Length), FALSE, NewAllocDescs, &WrittenBytes);
3920 MyFreePool__(NewAllocDescs);
3921 if(!OS_SUCCESS(status)) {
3922 UDFPrint((" FlushFE: UDFWriteExtent() faliled (%x)\n", status));
3923 return status;
3924 }
3925#ifdef UDF_DBG
3926 } else {
3927 ASSERT(AllocMode == ICB_FLAG_AD_IN_ICB);
3928#endif // UDF_DBG
3929 }
3930 FileInfo->Dloc->DataLoc.Modified = FALSE;
3931 FileInfo->Dloc->AllocLoc.Modified = FALSE;
3932 } else {
3933#if defined(UDF_DBG) && !defined(UDF_CHECK_UTIL)
3934 if(Vcb->CompatFlags & UDF_VCB_IC_W2K_COMPAT_ALLOC_DESCS) {
3935 ASSERT(UDFGetFileSize(FileInfo) <= UDFGetExtentLength(FileInfo->Dloc->DataLoc.Mapping));
3936 } else {
3937 ASSERT(((UDFGetFileSize(FileInfo)+Vcb->LBlockSize-1) & (Vcb->LBlockSize-1)) ==
3938 ((UDFGetExtentLength(FileInfo->Dloc->DataLoc.Mapping)+Vcb->LBlockSize-1) & (Vcb->LBlockSize-1)));
3939 }
3940#endif // UDF_DBG
3941 }
3942/* if(FileInfo->Fcb &&
3943 ((FileInfo->Dloc->FELoc.Mapping[0].extLocation > Vcb->LastLBA) ||
3944 UDFGetFreeBit(((uint32*)(Vcb->FSBM_Bitmap)), FileInfo->Dloc->FELoc.Mapping[0].extLocation)) ) {
3945 BrutePoint();
3946 }*/
3947/* if(FileInfo->Dloc->FELoc.Mapping[0].extLocation) {
3948 ASSERT( FileInfo->Dloc->FileEntry->tagLocation ==
3949 (FileInfo->Dloc->FELoc.Mapping[0].extLocation - 0x580));
3950 }*/
3951 if((FileInfo->Dloc->FE_Flags & UDF_FE_FLAG_FE_MODIFIED) ||
3952 FileInfo->Dloc->FELoc.Modified) {
3953 ASSERT(PartNum != (uint32)(-1));
3954 ASSERT(!PartNum);
3955 if(PartNum == (uint32)(-1) || PartNum == (uint32)(-2)) {
3956 UDFPrint((" bad PartNum: %d\n", PartNum));
3957 }
3958 // update lengthAllocDescs in FE
3960/* ASSERT( FileInfo->Dloc->FileEntry->tagLocation ==
3961 (FileInfo->Dloc->FELoc.Mapping[0].extLocation - 0x580));*/
3962 // flush FileEntry
3963
3964 // if FE is located in remapped block, place it to reliable space
3965 lba = FileInfo->Dloc->FELoc.Mapping[0].extLocation;
3966 if(Vcb->BSBM_Bitmap) {
3967 if(UDFGetBadBit((uint32*)(Vcb->BSBM_Bitmap), lba)) {
3968 AdPrint((" bad block under FE @%x\n", lba));
3969 goto relocate_FE;
3970 }
3971 }
3972
3973 AdPrint((" setup tag: @%x\n", lba));
3974 ASSERT( lba );
3975 UDFSetUpTag(Vcb, FileInfo->Dloc->FileEntry, (uint16)(FileInfo->Dloc->FileEntryLen),
3976 UDFPhysLbaToPart(Vcb, PartNum, lba));
3977 status = UDFWriteExtent(Vcb, &(FileInfo->Dloc->FELoc), 0,
3978 (uint32)(FileInfo->Dloc->FELoc.Length), FALSE,
3979 (int8*)(FileInfo->Dloc->FileEntry), &WrittenBytes);
3980 if(!OS_SUCCESS(status)) {
3981 UDFPrint((" FlushFE: UDFWriteExtent(2) faliled (%x)\n", status));
3983relocate_FE:
3984 UDFPrint((" try to relocate\n"));
3985
3986 EXTENT_INFO _FEExtInfo;
3987 // calculate the length required
3988
3989 // allocate block for FE
3990 if(OS_SUCCESS(UDFAllocateFESpace(Vcb, FileInfo->ParentFile, PartNum, &_FEExtInfo, (uint32)(FileInfo->Dloc->FELoc.Length)) )) {
3991 UDFPrint((" relocate %x -> %x\n",
3992 lba,
3993 _FEExtInfo.Mapping[0].extLocation));
3994
3995 UDFMarkSpaceAsXXX(Vcb, 0, FileInfo->Dloc->FELoc.Mapping, AS_BAD);
3996
3997 UDFRelocateDloc(Vcb, FileInfo->Dloc, _FEExtInfo.Mapping[0].extLocation);
3998 MyFreePool__(FileInfo->Dloc->FELoc.Mapping);
3999 FileInfo->Dloc->FELoc.Mapping = _FEExtInfo.Mapping;
4000
4001 FileInfo->Dloc->FELoc.Modified = TRUE;
4002 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_FE_MODIFIED;
4003
4004 AllocMode = ((PFILE_ENTRY)(FileInfo->Dloc->FileEntry))->icbTag.flags & ICB_FLAG_ALLOC_MASK;
4005 if(AllocMode == ICB_FLAG_AD_IN_ICB) {
4006 UDFPrint((" IN-ICB data lost\n"));
4007 FileInfo->Dloc->DataLoc.Mapping[0].extLocation = _FEExtInfo.Mapping[0].extLocation;
4008 FileInfo->Dloc->DataLoc.Modified = TRUE;
4009 } else {
4010 FileInfo->Dloc->AllocLoc.Mapping[0].extLocation = _FEExtInfo.Mapping[0].extLocation;
4011 FileInfo->Dloc->AllocLoc.Modified = TRUE;
4012 }
4013
4014 if(FileInfo->Index >= 2) {
4015 PDIR_INDEX_ITEM DirNdx;
4017 if(DirNdx) {
4018 UDFPrint((" update reference in FI\n"));
4020 FileInfo->FileIdent->icb.extLocation.logicalBlockNum =
4021 UDFPhysLbaToPart(Vcb, PartNum, _FEExtInfo.Mapping[0].extLocation);
4023 }
4024 }
4025 // this will update
4026 UDFPrint((" retry flush...\n"));
4027 goto retry_flush_FE;
4028 }
4029 }
4030 BrutePoint();
4031 return status;
4032 }
4033 FileInfo->Dloc->FE_Flags &= ~UDF_FE_FLAG_FE_MODIFIED;
4034 FileInfo->Dloc->FELoc.Modified = FALSE;
4035 } else {
4036 ASSERT((FileInfo->Dloc->FileEntry->descVersion == 2) ||
4037 (FileInfo->Dloc->FileEntry->descVersion == 3));
4038 }
4039#endif //UDF_READ_ONLY_BUILD
4040#ifdef UDF_DBG
4041 if(FileInfo->Dloc->AllocLoc.Mapping) {
4042 ASSERT(AllocMode != ICB_FLAG_AD_IN_ICB);
4043 } else {
4044 ASSERT(AllocMode == ICB_FLAG_AD_IN_ICB);
4045 }
4046#endif // UDF_DBG
4047 return STATUS_SUCCESS;
4048} // end UDFFlushFE()
void UDFRelocateDloc(IN PVCB Vcb, IN PUDF_DATALOC_INFO Dloc, IN uint32 NewLba)
Definition: dirtree.cpp:1374
OSSTATUS UDFReTagDirectory(IN PVCB Vcb, IN OUT PUDF_FILE_INFO FileInfo)
Definition: dirtree.cpp:895
OSSTATUS UDFBuildAllocDescs(IN PVCB Vcb, IN uint32 PartNum, IN OUT PUDF_FILE_INFO FileInfo, OUT int8 **AllocData)
Definition: extent.cpp:2628
OSSTATUS UDFPadLastSector(IN PVCB Vcb, IN PEXTENT_INFO ExtInfo)
Definition: udf_info.cpp:2962
void UDFSetAllocDescLen(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:1277
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159

Referenced by UDFCloseFile__(), UDFCreateFile__(), and UDFFlushFile__().

◆ UDFFlushFESpace()

void UDFFlushFESpace ( IN PVCB  Vcb,
IN PUDF_DATALOC_INFO  Dloc,
IN BOOLEAN  Discard = FLUSH_FE_KEEP 
)

Definition at line 1776 of file extent.cpp.

1781{
1782#ifdef UDF_FE_ALLOCATION_CHARGE // UDF_FE_ALLOCATION_CHARGE
1784 uint32 lim;
1785
1786 if(!(Mapping = Dloc->DirIndex->FECharge.Mapping))
1787 return;
1788
1789 lim = (Dloc->FE_Flags & UDF_FE_FLAG_IS_SDIR) ? Vcb->FEChargeSDir : Vcb->FECharge;
1790
1791 if(!Discard) {
1792 // cache it!
1794 Dloc->FELoc.Mapping[0].extLocation,
1795 &Dloc->DirIndex->FECharge, lim, UDF_PREALLOC_CLASS_FE))) {
1796 Dloc->DirIndex->FECharge.Mapping = NULL;
1797 return;
1798 }
1799 }
1800 Dloc->DirIndex->FECharge.Mapping = NULL;
1802#else // UDF_FE_ALLOCATION_CHARGE
1803 ASSERT(!Dloc->DirIndex->FECharge.Mapping);
1804 return;
1805#endif // UDF_FE_ALLOCATION_CHARGE
1806} // end UDFFlushFESpace()
static PVOID Mapping[EMS_PHYSICAL_PAGES]
Definition: emsdrv.c:41
OSSTATUS UDFStoreCachedAllocation(IN PVCB Vcb, IN uint32 ParentLocation, IN PEXTENT_INFO Ext, IN uint32 Items, IN uint32 AllocClass)
Definition: extent.cpp:1457

Referenced by UDFCleanUpFile__(), UDFCloseFile__(), UDFFlushFile__(), and UDFUnlinkFile__().

◆ UDFFlushFI()

OSSTATUS UDFFlushFI ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo,
IN uint32  PartNum 
)

Definition at line 4051 of file udf_info.cpp.

4056{
4057 PUDF_FILE_INFO DirInfo = FileInfo->ParentFile;
4058 PDIR_INDEX_ITEM DirNdx;
4060 SIZE_T WrittenBytes;
4061 // use WrittenBytes variable to store LBA of FI to be recorded
4062 #define lba WrittenBytes
4063
4064// ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation);
4065 // some files has no FI
4066 if(!DirInfo || UDFIsAStreamDir(FileInfo))
4067 return STATUS_SUCCESS;
4068 DirNdx = UDFDirIndex(DirInfo->Dloc->DirIndex, FileInfo->Index);
4069// ASSERT(FileInfo->FileIdent->lengthFileIdent < 0x80);
4070#ifdef UDF_DBG
4071 if(DirNdx->FileCharacteristics & FILE_DELETED) {
4072 ASSERT(FileInfo->FileIdent->fileCharacteristics & FILE_DELETED);
4073 }
4074#endif // UDF_DBG
4075 UDFPrint((" FlushFI: offs %x\n", (ULONG)(DirNdx->Offset)));
4076#ifndef UDF_READ_ONLY_BUILD
4077 if((DirNdx->FI_Flags & UDF_FI_FLAG_FI_MODIFIED)) {
4078 // flush FileIdent
4079 ASSERT(PartNum != (uint32)(-1));
4080 FileInfo->FileIdent->fileCharacteristics = DirNdx->FileCharacteristics;
4082 DirNdx->Offset, NULL, NULL, NULL, NULL);
4083 AdPrint((" FI lba %x\n", lba));
4084 // check if requested Offset is allocated
4085 if(lba == (uint32)LBA_OUT_OF_EXTENT) {
4086 // write 1 byte
4087 if(!OS_SUCCESS(status = UDFWriteFile__(Vcb, DirInfo, DirNdx->Offset, 1, FALSE, (int8*)(FileInfo->FileIdent), &WrittenBytes) )) {
4088 BrutePoint();
4089 return status;
4090 }
4092 DirNdx->Offset, NULL, NULL, NULL, NULL);
4093 AdPrint((" allocated FI lba %x\n", lba));
4094 // check if requested Offset is allocated
4095 if(lba == (uint32)LBA_OUT_OF_EXTENT) {
4096 BrutePoint();
4097 return STATUS_UNSUCCESSFUL;
4098 }
4099 }
4100 // init structure
4101 UDFSetUpTag(Vcb, &(FileInfo->FileIdent->descTag), (uint16)(FileInfo->FileIdentLen),
4102 UDFPhysLbaToPart(Vcb, PartNum, lba));
4103 // record data
4104 if(!OS_SUCCESS(status = UDFWriteFile__(Vcb, DirInfo, DirNdx->Offset, FileInfo->FileIdentLen, FALSE, (int8*)(FileInfo->FileIdent), &WrittenBytes) )) {
4105 BrutePoint();
4106 return status;
4107 }
4108 DirNdx->FI_Flags &= ~UDF_FI_FLAG_FI_MODIFIED;
4109 }
4110#endif //UDF_READ_ONLY_BUILD
4111 return STATUS_SUCCESS;
4112} // end UDFFlushFI()
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by UDFCloseFile__(), UDFCreateFile__(), UDFFlushFile__(), and UDFRenameMoveFile__().

◆ UDFFlushFile__()

OSSTATUS UDFFlushFile__ ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo,
IN ULONG  FlushFlags = 0 
)

Definition at line 4119 of file udf_info.cpp.

4124{
4126
4127 if(!FileInfo) return STATUS_SUCCESS;
4129 uint32 PartNum;
4130
4131 ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation);
4132 PartNum = UDFGetPartNumByPhysLba(Vcb, FileInfo->Dloc->FELoc.Mapping[0].extLocation);
4133 if(PartNum == (uint32)-1) {
4134 UDFPrint((" Is DELETED ?\n"));
4135 if(FileInfo->ParentFile) {
4136 PartNum = UDFGetPartNumByPhysLba(Vcb, FileInfo->ParentFile->Dloc->FELoc.Mapping[0].extLocation);
4137 } else {
4138 BrutePoint();
4139 }
4140 }
4141#ifdef UDF_CHECK_DISK_ALLOCATION
4142 if( FileInfo->Fcb &&
4143 UDFGetFreeBit(((uint32*)(Vcb->FSBM_Bitmap)), FileInfo->Dloc->FELoc.Mapping[0].extLocation)) {
4144
4147 UDFPrint((" Not DELETED SDir\n"));
4148 BrutePoint();
4149 }
4150 ASSERT(!FileInfo->Dloc->FELoc.Modified);
4151 } else
4152 if(!FileInfo->FileIdent ||
4153 !(FileInfo->FileIdent->fileCharacteristics & FILE_DELETED)) {
4154 if(!FileInfo->FileIdent)
4155 AdPrint((" No FileIdent\n"));
4156 if(FileInfo->FileIdent &&
4157 !(FileInfo->FileIdent->fileCharacteristics & FILE_DELETED))
4158 AdPrint((" Not DELETED\n"));
4159 AdPrint(("Flushing to Discarded block %x\n", FileInfo->Dloc->FELoc.Mapping[0].extLocation));
4160 BrutePoint();
4161 }
4162 }
4163#endif // UDF_CHECK_DISK_ALLOCATION
4164
4165 // flush FE and pre-allocation charge for directories
4166 if(FileInfo->Dloc &&
4167 FileInfo->Dloc->DirIndex) {
4168 // if Lite Flush is used, keep preallocations
4169 if(!(FlushFlags & UDF_FLUSH_FLAGS_LITE)) {
4170full_flush:
4172 if(FileInfo->Dloc->DataLoc.Flags & EXTENT_FLAG_PREALLOCATED) {
4173 FileInfo->Dloc->DataLoc.Flags |= EXTENT_FLAG_CUT_PREALLOCATED;
4174 status = UDFResizeExtent(Vcb, PartNum, UDFGetFileSize(FileInfo), FALSE, &(FileInfo->Dloc->DataLoc));
4176 if(OS_SUCCESS(status)) {
4177 AdPrint(("Dir pre-alloc truncated (Flush)\n"));
4178 FileInfo->Dloc->DataLoc.Modified = TRUE;
4179 }
4180 }
4181 }
4182 }
4183 // flush FE
4184 if(!OS_SUCCESS(status = UDFFlushFE(Vcb, FileInfo, PartNum))) {
4185 UDFPrint(("Error flushing FE\n"));
4186 BrutePoint();
4187 if(FlushFlags & UDF_FLUSH_FLAGS_LITE) {
4188 UDFPrint((" flush pre-alloc\n"));
4189 FlushFlags &= ~UDF_FLUSH_FLAGS_LITE;
4190 goto full_flush;
4191 }
4192 if(FileInfo->Index >= 2) {
4193 PDIR_INDEX_ITEM DirNdx;
4195 if(DirNdx) {
4196 UDFPrint(("Recovery: mark as deleted & flush FI\n"));
4199 FileInfo->FileIdent->fileCharacteristics |= FILE_DELETED;
4200 UDFFlushFI(Vcb, FileInfo, PartNum);
4201 }
4202 }
4203 return status;
4204 }
4205 if(!OS_SUCCESS(status = UDFFlushFI(Vcb, FileInfo, PartNum)))
4206 return status;
4207
4208 ASSERT((FileInfo->Dloc->FileEntry->descVersion == 2) ||
4209 (FileInfo->Dloc->FileEntry->descVersion == 3));
4210
4211 return STATUS_SUCCESS;
4212} // end UDFFlushFile__()
#define UDF_FLUSH_FLAGS_LITE
Definition: struct.h:341

Referenced by UDFCleanUpFcbChain(), UDFCommonCleanup(), UDFCommonCreate(), UDFFlushADirectory(), UDFFlushAFile(), UDFRecordVAT(), UDFRenameMoveFile__(), UDFUnlinkAllFilesInDir(), UDFUnlinkFile__(), UDFUpdateNonAllocated(), and UDFWriteSecurity().

◆ UDFFreeDloc()

void UDFFreeDloc ( IN PVCB  Vcb,
IN PUDF_DATALOC_INFO  Dloc 
)

Definition at line 1353 of file dirtree.cpp.

1357{
1358 LONG i;
1359
1360 UDFAcquireResourceExclusive(&(Vcb->DlocResource),TRUE);
1361
1362 if((i = UDFFindDlocInMem(Vcb, Dloc)) != (-1)) {
1363 ASSERT(Vcb->DlocList);
1364 RtlZeroMemory(&(Vcb->DlocList[i]), sizeof(UDF_DATALOC_INDEX));
1365 }
1366 UDFReleaseResource(&(Vcb->DlocResource));
1367 MyFreePool__(Dloc);
1368} // end UDFFreeDloc()
LONG UDFFindDlocInMem(IN PVCB Vcb, IN PUDF_DATALOC_INFO Dloc)
Definition: dirtree.cpp:1149
long LONG
Definition: pedump.c:60

Referenced by UDFCleanUpFile__().

◆ UDFFreeFESpace()

void UDFFreeFESpace ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  DirInfo,
IN PEXTENT_INFO  FEExtInfo 
)

Definition at line 1725 of file extent.cpp.

1730{
1731#ifdef UDF_FE_ALLOCATION_CHARGE // UDF_FE_ALLOCATION_CHARGE
1733 uint32 i, lim, j=-1;
1734 uint32 Lba;
1735
1736 // check if the DirInfo we are called with is a Directory
1737 // (it can be a file with SDir)
1738 if(DirInfo && DirInfo->Dloc->DirIndex &&
1739 (Ext = &(DirInfo->Dloc->DirIndex->FECharge))->Mapping) {
1740 if(!FEExtInfo->Mapping)
1741 return;
1742 Lba = FEExtInfo->Mapping[0].extLocation;
1743
1744 lim = (DirInfo->Dloc->FE_Flags & UDF_FE_FLAG_IS_SDIR) ? Vcb->FEChargeSDir : Vcb->FECharge;
1745 for(i=0;i<lim;i++) {
1746 if(Ext->Mapping[i].extLocation == Lba) {
1747 ASSERT(!(Ext->Mapping[i].extLength >> 30));
1748 Ext->Mapping[i].extLength |= (EXTENT_NOT_RECORDED_ALLOCATED << 30);
1749 goto clean_caller;
1750 }
1751 if(!Ext->Mapping[i].extLocation) {
1752 j = i;
1753 }
1754 }
1755 if(j != (ULONG)-1) {
1756 i = j;
1757 Ext->Mapping[i].extLocation = Lba;
1758 Ext->Mapping[i].extLength = Vcb->LBlockSize | (EXTENT_NOT_RECORDED_ALLOCATED << 30);
1759 goto clean_caller;
1760 }
1761 }
1762#endif // UDF_FE_ALLOCATION_CHARGE
1763 UDFMarkSpaceAsXXX(Vcb, 0, FEExtInfo->Mapping, AS_DISCARDED); // free
1764clean_caller:
1765 FEExtInfo->Mapping[0].extLocation = 0;
1766 FEExtInfo->Mapping[0].extLength = (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30);
1767 return;
1768} // end UDFFreeFESpace()

Referenced by UDFBuildFileEntry(), UDFCreateFile__(), UDFFreeFileAllocation(), UDFHardLinkFile__(), and UDFRenameMoveFile__().

◆ UDFFreeFileAllocation()

void UDFFreeFileAllocation ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  DirInfo,
IN PUDF_FILE_INFO  FileInfo 
)

Definition at line 2696 of file extent.cpp.

2701{
2702 if(FileInfo->Dloc->DataLoc.Offset) {
2703 // in-ICB data
2704 if(FileInfo->Dloc->DataLoc.Mapping) {
2705 ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation ==
2706 FileInfo->Dloc->DataLoc.Mapping[0].extLocation);
2707 UDFMarkSpaceAsXXX(Vcb, FileInfo->Dloc, &(FileInfo->Dloc->DataLoc.Mapping[1]), AS_DISCARDED); // free
2708 FileInfo->Dloc->DataLoc.Mapping[1].extLocation =
2709 FileInfo->Dloc->DataLoc.Mapping[1].extLength = 0;
2710 FileInfo->Dloc->DataLoc.Mapping[0].extLocation = 0;
2711 FileInfo->Dloc->DataLoc.Mapping[0].extLength = EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30;
2712 }
2713 if(FileInfo->Dloc->AllocLoc.Mapping) {
2714 ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation ==
2715 FileInfo->Dloc->AllocLoc.Mapping[0].extLocation);
2716 UDFMarkSpaceAsXXX(Vcb, FileInfo->Dloc, &(FileInfo->Dloc->AllocLoc.Mapping[1]), AS_DISCARDED); // free
2717 FileInfo->Dloc->AllocLoc.Mapping[1].extLocation =
2718 FileInfo->Dloc->AllocLoc.Mapping[1].extLength = 0;
2719 FileInfo->Dloc->AllocLoc.Mapping[0].extLocation = 0;
2720 FileInfo->Dloc->AllocLoc.Mapping[0].extLength = EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30;
2721 }
2722 UDFFreeFESpace(Vcb, DirInfo, &(FileInfo->Dloc->FELoc));
2723 } else {
2724 if(FileInfo->Dloc->AllocLoc.Mapping) {
2725 ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation ==
2726 FileInfo->Dloc->AllocLoc.Mapping[0].extLocation);
2727 UDFMarkSpaceAsXXX(Vcb, FileInfo->Dloc, &(FileInfo->Dloc->AllocLoc.Mapping[1]), AS_DISCARDED); // free
2728 FileInfo->Dloc->AllocLoc.Mapping[1].extLocation =
2729 FileInfo->Dloc->AllocLoc.Mapping[1].extLength = 0;
2730 FileInfo->Dloc->AllocLoc.Mapping[0].extLocation = 0;
2731 FileInfo->Dloc->AllocLoc.Mapping[0].extLength = EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30;
2732 }
2733 UDFFreeFESpace(Vcb, DirInfo, &(FileInfo->Dloc->FELoc));
2734 UDFMarkSpaceAsXXX(Vcb, FileInfo->Dloc, FileInfo->Dloc->DataLoc.Mapping, AS_DISCARDED); // free
2735 }
2736 FileInfo->Dloc->DataLoc.Modified =
2737 FileInfo->Dloc->AllocLoc.Modified =
2738 FileInfo->Dloc->FELoc.Modified = FALSE;
2739} // end UDFFreeFileAllocation()

Referenced by UDFUnlinkFile__().

◆ UDFGetBitmapLen()

SIZE_T UDFGetBitmapLen ( uint32 Bitmap,
SIZE_T  Offs,
SIZE_T  Lim 
)

Definition at line 496 of file alloc.cpp.

501{
502 ASSERT(Offs <= Lim);
503 if(Offs >= Lim) {
504 return 0;//(Offs == Lim);
505 }
506
507 BOOLEAN bit = UDFGetBit(Bitmap, Offs);
508 SIZE_T i=Offs>>5;
509 SIZE_T len=0;
510 uint8 j=(uint8)(Offs&31);
511 uint8 lLim=(uint8)(Lim&31);
512
513 Lim = Lim>>5;
514
515 ASSERT((bit == 0) || (bit == 1));
516
517 uint32 a;
518
519 a = Bitmap[i] >> j;
520
521 while(i<=Lim) {
522
523 while( j < ((i<Lim) ? 32 : lLim) ) {
524 if( ((BOOLEAN)(a&1)) != bit)
525 return len;
526 len++;
527 a>>=1;
528 j++;
529 }
530 j=0;
531While_3:
532 i++;
533 a = Bitmap[i];
534
535 if(i<Lim) {
536 if((bit && (a==0xffffffff)) ||
537 (!bit && !a)) {
538 len+=32;
539 goto While_3;
540 }
541 }
542 }
543
544 return len;
545
546#endif // _X86_
547
548} // end UDFGetBitmapLen()
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define a
Definition: ke_i.h:78
#define UDFGetBit(arr, bit)
Definition: udf_info.h:1180

Referenced by UDFAddXSpaceBitmap(), UDFFindMinSuitableExtent(), and UDFResizeExtent().

◆ UDFGetCachedAllocation()

OSSTATUS UDFGetCachedAllocation ( IN PVCB  Vcb,
IN uint32  ParentLocation,
OUT PEXTENT_INFO  Ext,
OUT uint32 Items,
IN uint32  AllocClass 
)

Definition at line 1417 of file extent.cpp.

1424{
1425 PUDF_ALLOCATION_CACHE_ITEM AllocCache;
1426 uint32 i, lim;
1428
1429 UDFAcquireResourceExclusive(&(Vcb->PreallocResource),TRUE);
1430
1431 status = UDFInitAllocationCache(Vcb, AllocClass, &AllocCache, &lim, FALSE);
1432 if(!OS_SUCCESS(status)) {
1433 UDFReleaseResource(&(Vcb->PreallocResource));
1434 return status;
1435 }
1436 UDFPrint(("Get AllocationCache for %x\n", ParentLocation));
1437
1438 for(i=0; i<lim; i++) {
1439 if(AllocCache[i].ParentLocation == ParentLocation) {
1440 (*Ext) = AllocCache[i].Ext;
1441 AdPrint((" map %x (%x)\n", Ext->Mapping, i));
1442 if(Items) {
1443 (*Items) = AllocCache[i].Items;
1444 }
1445 RtlZeroMemory(&(AllocCache[i]), sizeof(AllocCache[i]));
1446 AllocCache[i].ParentLocation = LBA_NOT_ALLOCATED;
1447 UDFReleaseResource(&(Vcb->PreallocResource));
1448 return STATUS_SUCCESS;
1449 }
1450 }
1451 AdPrint((" no map\n"));
1452 UDFReleaseResource(&(Vcb->PreallocResource));
1453 return STATUS_UNSUCCESSFUL;
1454} // end UDFGetCachedAllocation()

Referenced by UDFAllocateFESpace(), and UDFResizeExtent().

◆ UDFGetDirIndexByFileInfo()

◆ UDFGetDiskInfoAndVerify()

OSSTATUS UDFGetDiskInfoAndVerify ( IN PDEVICE_OBJECT  DeviceObject,
IN PVCB  Vcb 
)

Definition at line 2983 of file mount.cpp.

2987{
2990 lb_addr fileset;
2991 PFILE_SET_DESC FileSetDesc = NULL;
2992
2993 int8* Buf = NULL;
2995
2996 UDFPrint(("UDFGetDiskInfoAndVerify\n"));
2997 _SEH2_TRY {
2998
2999 if(!UDFFindAnchor(Vcb)) {
3000 if(Vcb->FsDeviceType == FILE_DEVICE_CD_ROM_FILE_SYSTEM) {
3001 // check if this disc is mountable for CDFS
3002 UDFPrint((" FILE_DEVICE_CD_ROM_FILE_SYSTEM\n"));
3003check_NSR:
3005 if(!(NSRDesc & VRS_ISO9660_FOUND)) {
3006 // no CDFS VRS found
3007 UDFPrint(("UDFGetDiskInfoAndVerify: no CDFS VRS found\n"));
3008 if(!Vcb->TrackMap[Vcb->LastTrackNum].LastLba &&
3009 !Vcb->TrackMap[Vcb->FirstTrackNum].LastLba) {
3010 // such a stupid method of Audio-CD detection...
3011 UDFPrint(("UDFGetDiskInfoAndVerify: set UDF_VCB_FLAGS_RAW_DISK\n"));
3012 Vcb->VCBFlags |= UDF_VCB_FLAGS_RAW_DISK;
3013 }
3014 }
3015 Vcb->NSRDesc = NSRDesc;
3016
3017 Buf = (int8*)MyAllocatePool__(NonPagedPool, 0x10000);
3019 RC = UDFReadData(Vcb, FALSE, 0, 0x10000, FALSE, Buf, &ReadBytes);
3020 if(!OS_SUCCESS(RC))
3023 if(!UDFCheckZeroBuf(Buf,0x10000)) {
3024 UDFPrint(("UDFGetDiskInfoAndVerify: possible FS detected, remove UDF_VCB_FLAGS_RAW_DISK\n"));
3025 Vcb->VCBFlags &= ~UDF_VCB_FLAGS_RAW_DISK;
3026 }
3027 MyFreePool__(Buf);
3028 Buf = NULL;
3029 }
3031 }
3032
3033 RC = UDFLoadPartition(DeviceObject,Vcb,&fileset);
3034 if(!OS_SUCCESS(RC)) {
3035 if(RC == STATUS_UNRECOGNIZED_VOLUME) {
3036 UDFPrint(("UDFGetDiskInfoAndVerify: check NSR presence\n"));
3037 goto check_NSR;
3038 }
3039 try_return(RC);
3040 }
3041
3042 FileSetDesc = (PFILE_SET_DESC)MyAllocatePool__(NonPagedPool,Vcb->BlockSize);
3043 if(!FileSetDesc) try_return(RC = STATUS_INSUFFICIENT_RESOURCES);
3044
3045 RC = UDFFindLastFileSet(Vcb,&fileset,FileSetDesc);
3046 if(!OS_SUCCESS(RC)) try_return(RC);
3047
3048 UDFLoadFileset(Vcb,FileSetDesc, &(Vcb->RootLbAddr), &(Vcb->SysStreamLbAddr));
3049
3050 Vcb->FSBM_OldBitmap = (int8*)DbgAllocatePool(NonPagedPool, Vcb->FSBM_ByteCount);
3051 if(!(Vcb->FSBM_OldBitmap)) try_return(RC = STATUS_INSUFFICIENT_RESOURCES);
3052 RtlCopyMemory(Vcb->FSBM_OldBitmap, Vcb->FSBM_Bitmap, Vcb->FSBM_ByteCount);
3053
3054try_exit: NOTHING;
3055 } _SEH2_FINALLY {
3056 if(FileSetDesc) MyFreePool__(FileSetDesc);
3057 if(Buf) MyFreePool__(Buf);
3058 } _SEH2_END;
3059
3060 return(RC);
3061
3062} // end UDFGetDiskInfoAndVerify()
struct _FILE_SET_DESC * PFILE_SET_DESC
OSSTATUS UDFLoadPartition(IN PDEVICE_OBJECT DeviceObject, IN PVCB Vcb, OUT lb_addr *fileset)
Definition: mount.cpp:2607
lba_t UDFFindAnchor(PVCB Vcb)
Definition: mount.cpp:1011
OSSTATUS UDFFindLastFileSet(IN PVCB Vcb, IN lb_addr *Addr, IN OUT PFILE_SET_DESC FileSetDesc)
Definition: mount.cpp:2739
BOOLEAN UDFCheckZeroBuf(IN int8 *Buf, IN uint32 Length)
Definition: mount.cpp:2936
uint32 UDFFindVRS(PVCB Vcb)
Definition: mount.cpp:1108
void UDFLoadFileset(IN PVCB Vcb, IN PFILE_SET_DESC fset, OUT lb_addr *root, OUT lb_addr *sysstream)
Definition: mount.cpp:2539
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM
Definition: winioctl.h:109
#define UDF_VCB_FLAGS_RAW_DISK
Definition: udf_common.h:476
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055

Referenced by UDFMountVolume(), and UDFVerifyVolume().

◆ UDFGetExtentLength()

int64 UDFGetExtentLength ( IN PEXTENT_MAP  Extent)

Definition at line 142 of file extent.cpp.

145{
146 if(!Extent) return 0;
147 int64 i=0;
148
149#if defined(_X86_) && defined(_MSC_VER) && !defined(__clang__)
150
151 __asm push ebx
152 __asm push ecx
153 __asm push esi
154
155 __asm lea ebx,i
156 __asm mov esi,Extent
157 __asm xor ecx,ecx
158While_1:
159 __asm mov eax,[esi+ecx*8] // Extent[j].extLength
161 __asm jz EO_While
162 __asm add [ebx],eax
163 __asm adc [ebx+4],0
164 __asm inc ecx
165 __asm jmp While_1
166EO_While:;
167 __asm pop esi
168 __asm pop ecx
169 __asm pop ebx
170
171#else // NO X86 optimization , use generic C/C++
172
173 while(Extent->extLength) {
174 i += (Extent->extLength & UDF_EXTENT_LENGTH_MASK);
175 Extent++;
176 }
177
178#endif // _X86_
179
180 return i;
181} // UDFGetExtentLength()

Referenced by UDFAllocFreeExtent_(), UDFBuildLongAllocDescs(), UDFBuildShortAllocDescs(), UDFFlushFE(), UDFLoadExtInfo(), UDFMarkAllocatedAsRecorded(), UDFPackMapping(), UDFRecordDirectory__(), UDFResizeExtent(), UDFResizeFile__(), UDFUnPackMapping(), UDFUpdateNonAllocated(), and UDFWriteFile__().

◆ UDFGetFileEALength()

uint32 UDFGetFileEALength ( IN PUDF_FILE_INFO  FileInfo)

Definition at line 1420 of file udf_info.cpp.

1423{
1424 uint16 Ident;
1425
1427
1428 if(!FileInfo->Dloc->FileEntry)
1429 return 1;
1430 Ident = FileInfo->Dloc->FileEntry->tagIdent;
1431
1432 if(Ident == TID_FILE_ENTRY) {
1433 return ((PFILE_ENTRY)(FileInfo->Dloc->FileEntry))->lengthExtendedAttr;
1434 } else if(Ident == TID_EXTENDED_FILE_ENTRY) {
1435 return ((PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry))->lengthExtendedAttr;
1436 }
1437 return 0;
1438} // end UDFGetFileEALength()

Referenced by UDFHardLinkFile__(), and UDFRenameMoveFile__().

◆ UDFGetFileLinkCount()

uint16 UDFGetFileLinkCount ( IN PUDF_FILE_INFO  FileInfo)

Definition at line 1355 of file udf_info.cpp.

1358{
1359 uint16 Ident;
1360 uint16 d;
1361
1363
1364 if(!FileInfo->Dloc->FileEntry)
1365 return 1;
1366 Ident = FileInfo->Dloc->FileEntry->tagIdent;
1367 // UDF engine assumes that LinkCount is a counter
1368 // of FileIdents, referencing this FE.
1369 // UDF 2.0 states, that it should be counter of ALL
1370 // references (including SDir) - 1.
1371 // Thus we'll write to media UDF-required value, but return
1372 // cooked value to callers
1373 d = UDFHasAStreamDir(FileInfo) ? 0 : 1;
1374 if(Ident == TID_FILE_ENTRY) {
1375 return ((PFILE_ENTRY)(FileInfo->Dloc->FileEntry))->fileLinkCount + d;
1376 } else if(Ident == TID_EXTENDED_FILE_ENTRY) {
1377 return ((PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry))->fileLinkCount + d;
1378 }
1380} // end UDFGetFileLinkCount()

Referenced by UDFCleanUpFile__(), UDFCloseFile__(), UDFCommonCleanup(), UDFFileDirInfoToNT(), UDFGetStandardInformation(), UDFHardLinkFile__(), UDFMarkStreamsForDeletion(), UDFOpenFile__(), UDFPrepareForRenameMoveLink(), UDFRenameMoveFile__(), UDFSetDispositionInformation(), UDFSetEOF(), and UDFUnlinkFile__().

◆ UDFGetFileSize()

int64 UDFGetFileSize ( IN PUDF_FILE_INFO  FileInfo)

Definition at line 1236 of file udf_info.cpp.

1239{
1240 uint16 Ident;
1241
1243
1244 Ident = FileInfo->Dloc->FileEntry->tagIdent;
1245 if(Ident == TID_FILE_ENTRY) {
1246 PFILE_ENTRY fe = (PFILE_ENTRY)(FileInfo->Dloc->FileEntry);
1247 return fe->informationLength;
1248 } else if(Ident == TID_EXTENDED_FILE_ENTRY) {
1249 PEXTENDED_FILE_ENTRY fe = (PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry);
1250 return fe->informationLength;
1251 }
1252 return (-1);
1253} // end UDFGetFileSize()

Referenced by UDFCloseFile__(), UDFCompleteMount(), UDFFlushFE(), UDFFlushFile__(), UDFGetNetworkInformation(), UDFGetStandardInformation(), UDFLoadVAT(), UDFReadSecurity(), UDFRecordDirectory__(), UDFRecordVAT(), UDFResizeFile__(), and UDFWriteFile__().

◆ UDFGetFileSizeFromDirNdx()

int64 UDFGetFileSizeFromDirNdx ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo 
)

Definition at line 1256 of file udf_info.cpp.

1260{
1261 PDIR_INDEX_ITEM DirIndex;
1262
1264
1266 if(!DirIndex)
1267 return -1;
1268
1269 return DirIndex->FileSize;
1270} // end UDFGetFileSizeFromDirNdx()
int64 FileSize
Definition: udf_rel.h:213

Referenced by UDFSetEOF().

◆ UDFGetFileUID()

int64 UDFGetFileUID ( IN PUDF_FILE_INFO  FileInfo)

Definition at line 1509 of file udf_info.cpp.

1512{
1514
1515 return UDFGetFileUID_(FileInfo->Dloc->FileEntry);
1516} // end UDFGetFileUID()
__inline int64 UDFGetFileUID_(IN tag *FileEntry)
Definition: udf_info.cpp:1491

◆ UDFGetFreeSpace()

int64 __fastcall UDFGetFreeSpace ( IN PVCB  Vcb)

Definition at line 1105 of file alloc.cpp.

1108{
1109 int64 s=0;
1110 uint32 i;
1111// uint32* cur = (uint32*)(Vcb->FSBM_Bitmap);
1112
1113 if(!Vcb->CDR_Mode &&
1114 !(Vcb->VCBFlags & UDF_VCB_FLAGS_RAW_DISK)) {
1115 for(i=0;i<Vcb->PartitionMaps;i++) {
1116/* lim = UDFPartEnd(Vcb,i);
1117 for(j=UDFPartStart(Vcb,i); j<lim && len; ) {
1118 len = UDFGetBitmapLen(cur, j, lim);
1119 if(UDFGetFreeBit(cur, j)) // is the extent found free or used ?
1120 s+=len;
1121 j+=len;
1122 }*/
1124 }
1125 } else {
1126 ASSERT(Vcb->LastPossibleLBA >= max(Vcb->NWA, Vcb->LastLBA));
1127 s = Vcb->LastPossibleLBA - max(Vcb->NWA, Vcb->LastLBA);
1128 //if(s & ((int64)1 << 64)) s=0;
1129 }
1130 return s >> Vcb->LB2B_Bits;
1131} // end UDFGetFreeSpace()
uint32 __fastcall UDFGetPartFreeSpace(IN PVCB Vcb, IN uint32 partNum)
Definition: alloc.cpp:1086

Referenced by UDFEjectReqWaiter(), UDFMountVolume(), UDFQueryFsFullSizeInfo(), UDFQueryFsSizeInfo(), and UDFSetAllocationInformation().

◆ UDFGetMappingLength()

uint32 UDFGetMappingLength ( IN PEXTENT_MAP  Extent)

Definition at line 223 of file extent.cpp.

226{
227 if(!Extent) return 0;
228 uint32 i=0;
229
230#if defined(_X86_) && defined(_MSC_VER) && !defined(__clang__)
231 __asm push ebx
232
233 __asm mov ebx,Extent
234 __asm xor eax,eax
235While_1:
236 __asm mov ecx,[ebx+eax*8]
237 __asm jecxz EO_While
238 __asm inc eax
239 __asm jmp While_1
240EO_While:
241 __asm inc eax
242 __asm shl eax,3
243 __asm mov i,eax
244
245 __asm pop ebx
246
247#else // NO X86 optimization , use generic C/C++
248
249 while(Extent->extLength) {
250 i++;
251 Extent++;
252 }
253 i++;
254 i*=sizeof(EXTENT_MAP);
255
256#endif // _X86_
257
258 return i; // i*sizeof(EXTENT_MAP)
259} // end UDFGetMappingLength()
EXTENT_AD EXTENT_MAP
Definition: ecma_167.h:134

Referenced by UDFMarkAllocatedAsNotXXX(), UDFMarkAllocatedAsRecorded(), UDFMarkNotAllocatedAsAllocated(), UDFMergeMappings(), UDFPackMapping(), UDFRecordVAT(), and UDFResizeExtent().

◆ UDFGetPartFreeSpace()

uint32 __fastcall UDFGetPartFreeSpace ( IN PVCB  Vcb,
IN uint32  partNum 
)

Definition at line 1086 of file alloc.cpp.

1090{
1091 uint32 lim/*, len=1*/;
1092 uint32 s=0;
1093 uint32 j;
1094 PUCHAR cur = (PUCHAR)(Vcb->FSBM_Bitmap);
1095
1096 lim = (UDFPartEnd(Vcb,partNum)+7)/8;
1097 for(j=(UDFPartStart(Vcb,partNum)+7)/8; j<lim/* && len*/; j++) {
1098 s+=bit_count_tab[cur[j]];
1099 }
1100 return s;
1101} // end UDFGetPartFreeSpace()
static const int8 bit_count_tab[]
Definition: alloc.cpp:22
unsigned char * PUCHAR
Definition: typedefs.h:53

Referenced by UDFGetFreeSpace(), and UDFUpdateLogicalVolInt().

◆ UDFGetPartNumByPhysLba()

uint32 __fastcall UDFGetPartNumByPhysLba ( IN PVCB  Vcb,
IN uint32  Lba 
)

Definition at line 201 of file alloc.cpp.

205{
206 uint32 i=Vcb->PartitionMaps-1, root;
207 PUDFPartMap pm = &(Vcb->Partitions[i]);
208 // walk through the partition maps to find suitable one
209 for(;i!=0xffffffff;i--,pm--) {
210 if( ((root = pm->PartitionRoot) <= Lba) &&
211 ((root + pm->PartitionLen) > Lba) ) return (uint16)pm->PartitionNum;
212 }
213 return LBA_OUT_OF_EXTENT; // Lba doesn't belong to any partition
214} // end UDFGetPartNumByPhysLba()
static LPMONITOREX pm
Definition: localmon.c:45

Referenced by UDFCloseFile__(), UDFConvertFEToNonInICB(), UDFCreateFile__(), UDFCreateStreamDir__(), UDFFlushFile__(), UDFIndexDirectory(), UDFMarkNotAllocatedAsAllocated(), UDFMarkSpaceAsXXXNoProtect_(), UDFPackDirectory__(), UDFRecordDirectory__(), UDFRenameMoveFile__(), UDFResizeFile__(), UDFReTagDirectory(), UDFUpdateNonAllocated(), UDFUpdateVAT(), and UDFWriteFile__().

◆ UDFGetTotalSpace()

int64 __fastcall UDFGetTotalSpace ( IN PVCB  Vcb)

Definition at line 1138 of file alloc.cpp.

1141{
1142 int64 s=0;
1143 uint32 i;
1144
1145 if(Vcb->VCBFlags & UDF_VCB_FLAGS_RAW_DISK) {
1146 s= Vcb->LastPossibleLBA;
1147 } else if(!Vcb->CDR_Mode) {
1148 for(i=0;i<Vcb->PartitionMaps;i++) {
1149 s+=Vcb->Partitions[i].PartitionLen;
1150 }
1151 } else {
1152 if(s & ((int64)1 << 63)) s=0; /* FIXME ReactOS this shift value was 64, which is undefiened behavior. */
1153 s= Vcb->LastPossibleLBA - Vcb->Partitions[0].PartitionRoot;
1154 }
1155 return s >> Vcb->LB2B_Bits;
1156} // end UDFGetTotalSpace()

Referenced by UDFMountVolume(), UDFQueryFsFullSizeInfo(), and UDFQueryFsSizeInfo().

◆ UDFHardLinkFile__()

OSSTATUS UDFHardLinkFile__ ( IN PVCB  Vcb,
IN BOOLEAN  IgnoreCase,
IN OUT BOOLEAN Replace,
IN PUNICODE_STRING  fn,
IN OUT PUDF_FILE_INFO  DirInfo1,
IN OUT PUDF_FILE_INFO  DirInfo2,
IN OUT PUDF_FILE_INFO  FileInfo 
)

Definition at line 4672 of file udf_info.cpp.

4681{
4682 PUDF_FILE_INFO FileInfo2;
4684 PDIR_INDEX_ITEM DirNdx1;
4685 PDIR_INDEX_ITEM DirNdx2;
4686 uint_di i;
4687 BOOLEAN Recovery = FALSE;
4688 BOOLEAN SameFE = FALSE;
4689 uint32 NTAttr = 0;
4690
4691 // validate FileInfo
4692 ValidateFileInfo(DirInfo1);
4693 ValidateFileInfo(DirInfo2);
4695
4697 // too many links to file...
4698 return STATUS_TOO_MANY_LINKS;
4699 }
4700
4701 i = 0;
4702 if(DirInfo1 == DirInfo2) {
4703 if(OS_SUCCESS(status = UDFFindFile(Vcb, IgnoreCase, TRUE, fn, DirInfo2, &i)) &&
4704 (i==FileInfo->Index) ) {
4705 // case-only difference
4707 }
4708 }
4709
4710 // PHASE 0
4711 // try to create new FileIdent & FileEntry in Dir2
4712
4713HLinkRetry:
4715 0, (FileInfo->Dloc->FileEntry->tagIdent == TID_EXTENDED_FILE_ENTRY),
4716 TRUE, DirInfo2, &FileInfo2))) {
4717 if(UDFCleanUpFile__(Vcb, FileInfo2) && FileInfo2)
4718 MyFreePool__(FileInfo2);
4720 // try to recover >;->
4721 if((*Replace) && !Recovery) {
4722 Recovery = TRUE;
4723 status = UDFOpenFile__(Vcb, IgnoreCase, TRUE, fn, DirInfo2, &FileInfo2, NULL);
4724 if(OS_SUCCESS(status)) {
4725 status = UDFDoesOSAllowFileToBeTargetForHLink__(FileInfo2);
4726 if(!OS_SUCCESS(status)) {
4727 UDFCloseFile__(Vcb, FileInfo2);
4728 goto cleanup_and_abort_hlink;
4729 }
4730 if((FileInfo->Dloc == FileInfo2->Dloc) &&
4731 (FileInfo != FileInfo2)) {
4732 SameFE = TRUE;
4733 // 'status' is already STATUS_SUCCESS here
4734 } else {
4735 status = UDFUnlinkFile__(Vcb, FileInfo2, TRUE);
4736 }
4737 UDFCloseFile__(Vcb, FileInfo2);
4738 if(UDFCleanUpFile__(Vcb, FileInfo2)) {
4739 MyFreePool__(FileInfo2);
4740 FileInfo2 = NULL;
4741 if(SameFE)
4742 return STATUS_SUCCESS;
4743 } else {
4744 // we get here if the FileInfo has associated
4745 // system-specific Fcb
4746 // Such fact means that not all system references
4747 // has already gone (except Linked file case)
4748 if(SameFE)
4749 return STATUS_SUCCESS;
4750 if(!OS_SUCCESS(status) ||
4753 }
4754 if(OS_SUCCESS(status)) goto HLinkRetry;
4755 }
4756cleanup_and_abort_hlink:
4757 if(FileInfo2 && UDFCleanUpFile__(Vcb, FileInfo2)) {
4758 MyFreePool__(FileInfo2);
4759 FileInfo2 = NULL;
4760 }
4761 } else {
4763 }
4764 }
4765 return status;
4766 }
4767 // update pointers
4768 DirNdx1 = UDFDirIndex(DirInfo1->Dloc->DirIndex, FileInfo->Index);
4769 DirNdx2 = UDFDirIndex(DirInfo2->Dloc->DirIndex, FileInfo2->Index);
4770
4771 // copy file attributes to newly created FileIdent
4772 NTAttr = UDFAttributesToNT(DirNdx1, FileInfo->Dloc->FileEntry);
4773 FileInfo2->FileIdent->fileVersionNum = FileInfo->FileIdent->fileVersionNum;
4774
4775 // PHASE 1
4776 // copy all necessary info from FileInfo to FileInfo2
4777
4778 FileInfo2->FileIdent->icb = FileInfo->FileIdent->icb;
4779 FileInfo2->FileIdent->fileCharacteristics = FileInfo->FileIdent->fileCharacteristics;
4780 FileInfo2->FileIdent->fileVersionNum = FileInfo->FileIdent->fileVersionNum;
4781
4782 DirNdx2->FileCharacteristics = DirNdx1->FileCharacteristics & ~FILE_DELETED;
4783 DirNdx2->FileEntryLoc = DirNdx1->FileEntryLoc;
4784 DirNdx2->FI_Flags = (DirNdx1->FI_Flags & ~UDF_FI_FLAG_SYS_ATTR) | UDF_FI_FLAG_FI_MODIFIED | UDF_FI_FLAG_LINKED;
4785
4786 UDFAttributesToUDF(DirNdx2, FileInfo2->Dloc->FileEntry, NTAttr);
4787
4788 // PHASE 2
4789 // update FileInfo
4790
4791 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_FE_MODIFIED;
4792 DirNdx1->FI_Flags = DirNdx2->FI_Flags;
4793 UDFIncFileLinkCount(FileInfo); // increase to 1
4794// UDFUpdateModifyTime(Vcb, FileInfo);
4795 FileInfo->Dloc->LinkRefCount += FileInfo2->Dloc->LinkRefCount;
4796 if(FileInfo2->FileIdent)
4797 ((FidADImpUse*)&(FileInfo2->FileIdent->icb.impUse))->uniqueID = (uint32)UDFAssingNewFUID(Vcb);
4798
4799 // PHASE 3
4800 // drop all unnecessary info from FileInfo2
4801
4802 UDFFreeFESpace(Vcb, DirInfo2, &(FileInfo2->Dloc->FELoc));
4803 UDFRemoveDloc(Vcb, FileInfo2->Dloc);
4804
4805 // PHASE 4
4806 // perform in-memory linkage (update driver's tree structures) and flush
4807
4808 FileInfo2->Dloc = FileInfo->Dloc;
4809 UDFInsertLinkedFile(FileInfo2, FileInfo);
4810
4811 UDFCloseFile__(Vcb, FileInfo2);
4812 if(UDFCleanUpFile__(Vcb, FileInfo2)) {
4813 MyFreePool__(FileInfo2);
4814 }
4815 // return 'delete target' status
4816 (*Replace) = Recovery;
4817
4818 return STATUS_SUCCESS;
4819} // end UDFHardLinkFile__()
ULONG UDFAttributesToNT(IN PDIR_INDEX_ITEM FileDirNdx, IN tag *FileEntry)
void UDFInsertLinkedFile(PUDF_FILE_INFO fi, PUDF_FILE_INFO fi2)
Definition: dirtree.cpp:1470
void Replace(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF fg, COLORREF bg, LONG radius)
Definition: drawing.cpp:132
uint8 fileCharacteristics
Definition: ecma_167.h:428
uint_di Index
Definition: udf_rel.h:392
PFILE_IDENT_DESC FileIdent
Definition: udf_rel.h:372
uint32 UDFGetFileEALength(IN PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:1420
OSSTATUS UDFCreateFile__(IN PVCB Vcb, IN BOOLEAN IgnoreCase, IN PUNICODE_STRING _fn, IN uint32 ExtAttrSz, IN uint32 ImpUseLen, IN BOOLEAN Extended, IN BOOLEAN CreateNew, IN OUT PUDF_FILE_INFO DirInfo, OUT PUDF_FILE_INFO *_FileInfo)
Definition: udf_info.cpp:2577
int64 UDFAssingNewFUID(IN PVCB Vcb)
Definition: udf_info.cpp:1445
#define UDF_MAX_LINK_COUNT
Definition: udf_rel.h:509
#define UDF_FI_FLAG_LINKED
Related FileEntry has more than one FileIdent. It happends when we use HardLinks.
Definition: udf_rel.h:223
#define STATUS_TOO_MANY_LINKS
Definition: udferr_usr.h:184
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150

Referenced by UDFHardLink().

◆ UDFIndexDirectory()

OSSTATUS UDFIndexDirectory ( IN PVCB  Vcb,
IN OUT PUDF_FILE_INFO  FileInfo 
)

Definition at line 507 of file dirtree.cpp.

511{
512 PDIR_INDEX_HDR hDirNdx;
513 PDIR_INDEX_ITEM DirNdx;
514 PFILE_IDENT_DESC FileId;
515 uint32 Offset = 0;
516// uint32 prevOffset = 0;
517 uint_di Count = 0;
519 int8* buff;
520 PEXTENT_INFO ExtInfo; // Extent array for directory
521 uint16 PartNum;
523 uint16 valueCRC;
524
527
528 ExtInfo = &(FileInfo->Dloc->DataLoc);
529 FileInfo->Dloc->DirIndex = NULL;
530 UDFPrint(("UDF: scaning directory\n"));
531 // allocate buffer for the whole directory
532 ASSERT((uint32)(ExtInfo->Length));
533 if(!ExtInfo->Length)
536 if(!buff)
538
540
541 // read FileIdents
542 status = UDFReadExtent(Vcb, ExtInfo, 0, (uint32)(ExtInfo->Length), FALSE, buff, &ReadBytes);
543 if(!OS_SUCCESS(status)) {
545 return status;
546 }
547 // scan Dir to get entry counter
548 FileId = (PFILE_IDENT_DESC)buff;
549 DirPrint((" ExtInfo->Length %x\n", ExtInfo->Length));
550// prevOffset = 0;
552 DirPrint((" Offset %x\n", Offset));
553 if(!FileId->descTag.tagIdent) {
554 DirPrint((" term item\n"));
555 break;
556 }
557 if(FileId->descTag.tagIdent != TID_FILE_IDENT_DESC) {
558 DirPrint((" Inv. tag %x\n", FileId->descTag.tagIdent));
559 Offset = UDFFindNextFI(buff, prevOffset, (ULONG)(ExtInfo->Length));
560 if(!Offset) {
561 DirPrint((" can't find next\n"));
562 break;
563 } else {
564 DirPrint((" found next offs %x\n", Offset));
565 FileId = (PFILE_IDENT_DESC)((buff)+Offset);
566 }
567 }
568 if(((ULONG)Offset & (Vcb->LBlockSize-1)) > (Vcb->LBlockSize-sizeof(FILE_IDENT_DESC))) {
569 DirPrint((" badly aligned\n", Offset));
570 if(Vcb->Modified) {
571 DirPrint((" queue repack request\n"));
572 FileInfo->Dloc->DirIndex->DelCount = Vcb->PackDirThreshold+1;
573 }
574 }
575// prevOffset = Offset;
576 Offset += (FileId->lengthFileIdent + FileId->lengthOfImpUse + sizeof(FILE_IDENT_DESC) + 3) & (~((uint32)3));
577 FileId = (PFILE_IDENT_DESC)((buff)+Offset);
578 Count++;
579 if(Offset+sizeof(FILE_IDENT_DESC) > ExtInfo->Length) {
580 if(Offset != ExtInfo->Length) {
581 UDFPrint((" Trash at the end of Dir\n"));
582 }
583// BrutePoint();
584 break;
585 }
586 }
587 DirPrint((" final Offset %x\n", Offset));
588 if(Offset > ExtInfo->Length) {
589 BrutePoint();
590 UDFPrint((" Unexpected end of Dir\n"));
593 }
594 // allocate buffer for directory index & zero it
595 DirPrint((" Count %x\n", Count));
596 hDirNdx = UDFDirIndexAlloc(Count+1);
597 if(!hDirNdx) {
600 }
601
602 Offset = Count = 0;
603 hDirNdx->DIFlags |= (ExtInfo->Offset ? UDF_DI_FLAG_INIT_IN_ICB : 0);
604 // add entry pointing to the directory itself
605 DirNdx = UDFDirIndex(hDirNdx,0);
606 ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation);
607 DirNdx->FileEntryLoc.partitionReferenceNum = PartNum =
608 (uint16)UDFGetPartNumByPhysLba(Vcb, FileInfo->Dloc->FELoc.Mapping[0].extLocation);
609 ASSERT(PartNum != -1);
611 UDFPhysLbaToPart(Vcb, PartNum, FileInfo->Dloc->FELoc.Mapping[0].extLocation);
612 if(DirNdx->FileEntryLoc.logicalBlockNum == (ULONG)-1) {
613 DirPrint((" err: FileEntryLoc=-1\n"));
615 UDFDirIndexFree(hDirNdx);
617 }
618 DirNdx->FileCharacteristics = (FileInfo->FileIdent) ?
619 FileInfo->FileIdent->fileCharacteristics :
621// DirNdx->Offset = 0;
622// DirNdx->Length = 0;
623 RtlInitUnicodeString(&DirNdx->FName, L".");
624 DirNdx->FileInfo = FileInfo;
626 DirNdx->FI_Flags |= UDFBuildHashEntry(Vcb, &(DirNdx->FName), &(DirNdx->hashes),
628 Count++;
629 FileId = (PFILE_IDENT_DESC)buff;
631// prevOffset = 0;
632 while((Offset<ExtInfo->Length) && FileId->descTag.tagIdent) {
633 // add new entry to index list
634 if(FileId->descTag.tagIdent != TID_FILE_IDENT_DESC) {
635 UDFPrint((" Invalid tagIdent %x (expected %x) offst %x\n", FileId->descTag.tagIdent, TID_FILE_IDENT_DESC, Offset));
636 DirPrint((" FileId: filen %x, iulen %x, charact %x\n",
637 FileId->lengthFileIdent, FileId->lengthOfImpUse, FileId->fileCharacteristics));
638 DirPrint((" loc: @%x\n", UDFExtentOffsetToLba(Vcb, ExtInfo->Mapping, Offset, NULL, NULL, NULL, NULL)));
639 KdDump(FileId, sizeof(FileId->descTag));
640 Offset = UDFFindNextFI(buff, prevOffset, (ULONG)(ExtInfo->Length));
641 if(!Offset) {
643 UDFDirIndexFree(hDirNdx);
645 } else {
646 DirPrint((" found next offs %x\n", Offset));
647 FileId = (PFILE_IDENT_DESC)((buff)+Offset);
648 }
649 }
650 DirNdx = UDFDirIndex(hDirNdx,Count);
651 // allocate buffer & fill it with decompressed unicode filename
652 if(FileId->fileCharacteristics & FILE_DELETED) {
653 DirPrint((" FILE_DELETED\n"));
654 hDirNdx->DelCount++;
655 }
656 DirPrint((" FileId: offs %x, filen %x, iulen %x\n", Offset, FileId->lengthFileIdent, FileId->lengthOfImpUse));
657 DirNdx->Length = (FileId->lengthFileIdent + FileId->lengthOfImpUse + sizeof(FILE_IDENT_DESC) + 3) & (~((uint32)3));
658 DirPrint((" DirNdx: Length %x, Charact %x\n", DirNdx->Length, FileId->fileCharacteristics));
659 if(FileId->fileCharacteristics & FILE_PARENT) {
660 DirPrint((" parent\n"));
661 // init 'parent' entry
662 // '..' points to Parent Object (if any),
663 // otherwise it points to the Dir itself
664 RtlInitUnicodeString(&DirNdx->FName, L"..");
665 DirNdx->FileInfo = (FileInfo->ParentFile) ?
666 FileInfo->ParentFile : FileInfo;
668 DirNdx->FI_Flags |= UDFBuildHashEntry(Vcb, &(DirNdx->FName), &(DirNdx->hashes), HASH_ALL | HASH_KEEP_NAME);
669 } else {
670 // init plain file/dir entry
671 ASSERT( (Offset+sizeof(FILE_IDENT_DESC)+FileId->lengthOfImpUse+FileId->lengthFileIdent) <=
672 ExtInfo->Length );
673 UDFDecompressUnicode(&(DirNdx->FName),
674 ((uint8*)(FileId+1)) + (FileId->lengthOfImpUse),
675 FileId->lengthFileIdent,
676 &valueCRC);
677 UDFNormalizeFileName(&(DirNdx->FName), valueCRC);
678 DirNdx->FI_Flags |= UDFBuildHashEntry(Vcb, &(DirNdx->FName), &(DirNdx->hashes), HASH_ALL);
679 }
681 ||
682 !DirNdx->FName.Buffer
683 ||
684 ((DirNdx->FName.Length >= sizeof(UDF_RESERVED_NAME_HDR)-sizeof(WCHAR)) &&
686 DirPrint((" metadata\n"));
688 }
689#if 0
690 UDFPrint(("%ws\n", DirNdx->FName.Buffer));
691#endif
692 DirPrint(("%ws\n", DirNdx->FName.Buffer));
693 // remember FileEntry location...
694 DirNdx->FileEntryLoc = FileId->icb.extLocation;
695 // ... and some file characteristics
697 DirNdx->Offset = Offset;
698#ifdef UDF_CHECK_DISK_ALLOCATION
699 if(!(FileId->fileCharacteristics & FILE_DELETED) &&
701 UDFGetFreeBit(((uint32*)(Vcb->FSBM_Bitmap)), UDFPartLbaToPhys(Vcb, &(DirNdx->FileEntryLoc)) )) {
702
703 AdPrint(("Ref to Discarded block %x\n",UDFPartLbaToPhys(Vcb, &(DirNdx->FileEntryLoc)) ));
704 BrutePoint();
706 } else
708 AdPrint(("Ref to Invalid block %x\n", UDFPartLbaToPhys(Vcb, &(DirNdx->FileEntryLoc)) ));
709 BrutePoint();
711 }
712#endif // UDF_CHECK_DISK_ALLOCATION
713// prevOffset = Offset;
714 Offset += DirNdx->Length;
715 FileId = (PFILE_IDENT_DESC)(((int8*)FileId)+DirNdx->Length);
716 Count++;
717 if(Offset+sizeof(FILE_IDENT_DESC) > ExtInfo->Length) {
718 if(Offset != ExtInfo->Length) {
719 UDFPrint((" Trash at the end of Dir (2)\n"));
720 }
721// BrutePoint();
722 break;
723 }
724 } // while()
725 // we needn't writing terminator 'cause the buffer is already zero-filled
727 if(Count < 2) {
728 UDFDirIndexFree(hDirNdx);
729 UDFPrint((" Directory too short\n"));
731 }
732 // store index
733 FileInfo->Dloc->DirIndex = hDirNdx;
734 return status;
735} // end UDFIndexDirectory()
VOID UDFNormalizeFileName(IN PUNICODE_STRING FName, IN USHORT valueCRC)
#define UDFFindNextFI(a, b, c)
Definition: dirtree.cpp:500
#define DirPrint(x)
Definition: dirtree.cpp:34
PDIR_INDEX_HDR UDFDirIndexAlloc(IN uint_di i)
Definition: dirtree.cpp:43
#define FILE_PARENT
Definition: ecma_167.h:441
#define FILE_DIRECTORY
Definition: ecma_167.h:439
#define FILE_METADATA
Definition: ecma_167.h:442
#define KdDump(a, b)
Definition: env_spec_w32.h:312
#define PagedPool
Definition: env_spec_w32.h:308
int Count
Definition: noreturn.cpp:7
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define UDF_RESERVED_NAME_HDR
Definition: osta_misc.h:343
ULONG DIFlags
Definition: udf_rel.h:142
void __fastcall UDFDecompressUnicode(IN OUT PUNICODE_STRING UName, IN uint8 *CS0, IN SIZE_T Length, OUT uint16 *valueCRC)
Definition: udf_info.cpp:170
#define UDF_FI_FLAG_FI_INTERNAL
Given entry represents the file used for internal FS purposes & must be invisible.
Definition: udf_rel.h:221
#define UDF_DI_FLAG_INIT_IN_ICB
Definition: udf_rel.h:147
#define UDF_FI_FLAG_KEEP_NAME
Definition: udf_rel.h:226
#define STATUS_FILE_CORRUPT_ERROR
Definition: udferr_usr.h:168

Referenced by UDFCleanUpFile__(), UDFOpenFile__(), UDFOpenRootFile__(), and UDFRecordDirectory__().

◆ UDFInsertLinkedFile()

void UDFInsertLinkedFile ( PUDF_FILE_INFO  fi,
PUDF_FILE_INFO  fi2 
)

Definition at line 1470 of file dirtree.cpp.

1474{
1475 fi->NextLinkedFile = fi2->NextLinkedFile;
1476 fi->PrevLinkedFile = fi2;
1477 fi->NextLinkedFile->PrevLinkedFile =
1478 fi->PrevLinkedFile->NextLinkedFile = fi;
1479 return;
1480} // end UDFInsertLinkedFile()
struct _UDF_FILE_INFO * PrevLinkedFile
Definition: udf_rel.h:409
struct _UDF_FILE_INFO * NextLinkedFile
Definition: udf_rel.h:408

Referenced by UDFHardLinkFile__(), UDFOpenFile__(), and UDFOpenStreamDir__().

◆ UDFIsBlockAllocated()

ULONG UDFIsBlockAllocated ( IN void _Vcb,
IN uint32  Lba 
)

Definition at line 1164 of file alloc.cpp.

1168{
1169 ULONG ret_val = 0;
1170 uint32* bm;
1171// return TRUE;
1172 if(!(((PVCB)_Vcb)->VCBFlags & UDF_VCB_ASSUME_ALL_USED)) {
1173 // check used
1174 if((bm = (uint32*)(((PVCB)_Vcb)->FSBM_Bitmap)))
1175 ret_val = (UDFGetUsedBit(bm, Lba) ? WCACHE_BLOCK_USED : 0);
1176 // check zero-filled
1177 if((bm = (uint32*)(((PVCB)_Vcb)->ZSBM_Bitmap)))
1178 ret_val |= (UDFGetZeroBit(bm, Lba) ? WCACHE_BLOCK_ZERO : 0);
1179 } else {
1180 ret_val = WCACHE_BLOCK_USED;
1181 }
1182 // check bad block
1183
1184 // WCache works with LOGICAL addresses, not PHYSICAL, BB check must be performed UNDER cache
1185/*
1186 if(bm = (uint32*)(((PVCB)_Vcb)->BSBM_Bitmap)) {
1187 ret_val |= (UDFGetBadBit(bm, Lba) ? WCACHE_BLOCK_BAD : 0);
1188 if(ret_val & WCACHE_BLOCK_BAD) {
1189 UDFPrint(("Marked BB @ %#x\n", Lba));
1190 }
1191 }
1192*/
1193 return ret_val;
1194} // end UDFIsBlockAllocated()
Definition: cdstruc.h:498
#define UDF_VCB_ASSUME_ALL_USED
Definition: udf_common.h:474
#define UDFGetUsedBit(arr, bit)
Definition: udf_info.h:1198
#define WCACHE_BLOCK_USED
Definition: wcache_lib.h:54
#define WCACHE_BLOCK_ZERO
Definition: wcache_lib.h:55

Referenced by UDFMountVolume(), and UDFVerifyVolume().

◆ UDFIsDirEmpty()

BOOLEAN UDFIsDirEmpty ( IN PDIR_INDEX_HDR  hCurDirNdx)

Definition at line 3844 of file udf_info.cpp.

3847{
3848 uint32 fc;
3849 uint_di i;
3850 PDIR_INDEX_ITEM CurDirNdx;
3851 // not empty
3852 for(i=2; (CurDirNdx = UDFDirIndex(hCurDirNdx,i)); i++) {
3853 fc = CurDirNdx->FileCharacteristics;
3854 if(!(fc & (FILE_PARENT | FILE_DELETED)) &&
3855 CurDirNdx->Length)
3856 return FALSE;
3857 }
3858 return TRUE;
3859} // end UDFIsDirEmpty()
PFOR_CONTEXT fc
Definition: for.c:57

Referenced by UDFUnlinkFile__().

◆ UDFIsExtentCached()

BOOLEAN UDFIsExtentCached ( IN PVCB  Vcb,
IN PEXTENT_INFO  ExtInfo,
IN int64  Offset,
IN uint32  Length,
IN BOOLEAN  ForWrite 
)

Definition at line 2918 of file extent.cpp.

2925{
2926 BOOLEAN retstat = FALSE;
2927 PEXTENT_MAP Extent = ExtInfo->Mapping; // Extent array
2929 uint32 Lba, sect_offs, flags, i;
2930
2931 WCacheStartDirect__(&(Vcb->FastCache), Vcb, TRUE/*FALSE*//*ForWrite*/);
2932 if(!ExtInfo || !ExtInfo->Mapping) goto EO_IsCached;
2933 if(!Length) {
2934 retstat = TRUE;
2935 goto EO_IsCached;
2936 }
2937
2938 // prevent reading out of data space
2939 if(Offset > ExtInfo->Length) goto EO_IsCached;
2940 if(Offset+Length > ExtInfo->Length) goto EO_IsCached;
2941 Offset += ExtInfo->Offset; // used for in-ICB data
2942 // read maximal possible part of each frag of extent
2943 Lba = UDFExtentOffsetToLba(Vcb, Extent, Offset, &sect_offs, &to_read, &flags, &i);
2944 while(((LONG)Length) > 0) {
2945 // EOF check
2946 if(Lba == LBA_OUT_OF_EXTENT) goto EO_IsCached;
2947 Extent += (i + 1);
2948 // check for reading tail
2951 retstat = UDFIsDataCached(Vcb, Lba, (to_read+sect_offs+Vcb->BlockSize-1)>>Vcb->BlockSizeBits);
2952 if(!retstat) goto EO_IsCached;
2953 } else if(ForWrite) {
2954 goto EO_IsCached;
2955 }
2956 Offset += to_read;
2957 Length -= to_read;
2959 }
2960 retstat = TRUE;
2961EO_IsCached:
2962 if(!retstat) {
2963 WCacheEODirect__(&(Vcb->FastCache), Vcb);
2964 }
2965 return retstat;
2966} // end UDFIsExtentCached()
ULONG to_read
Definition: btrfs.c:4260
#define EXTENT_RECORDED_ALLOCATED
Definition: ecma_167.h:367
uint32 UDFNextExtentToLba(IN PVCB Vcb, IN PEXTENT_MAP Extent, OUT PSIZE_T AvailLength, OUT uint32 *Flags, OUT uint32 *Index)
Definition: extent.cpp:79
OSSTATUS WCacheStartDirect__(IN PW_CACHE Cache, IN PVOID Context, IN BOOLEAN Exclusive)
OSSTATUS WCacheEODirect__(IN PW_CACHE Cache, IN PVOID Context)

◆ UDFIsIllegalChar()

BOOLEAN __fastcall UDFIsIllegalChar ( IN WCHAR  ch)

Definition at line 370 of file udf_info.cpp.

373{
374 // Genuine illegal char's for DOS.
375#if defined (_X86_) && defined (_MSC_VER)
376 _asm {
377 push ebx
378
379 xor eax,eax
380// mov ax,chr
381 mov ax,cx
382 or ah,ah
383 jnz ERR_IIC
384
385 lea ebx,[valid_char_arr]
386 xlatb
387 jmp short ERR_IIC2
388ERR_IIC:
389 mov al,1
390ERR_IIC2:
391
392 pop ebx
393 ret
394 }
395
396#else // NO X86 optimization , use generic C/C++
397 /* FIXME */
398 //return ((ch < 0x20) || UDFUnicodeInString((uint8*)&valid_char_arr, ch));
399 return ((chr < 0x20) || UDFUnicodeInString((uint8*)&valid_char_arr, chr));
400#endif // _X86_
401} // end UDFIsIllegalChar()
_Out_opt_ int * cx
Definition: commctrl.h:585
BOOLEAN UDFUnicodeInString(IN uint8 *string, IN WCHAR ch)
Definition: udf_info.cpp:336
static const char valid_char_arr[]
Definition: udf_info.cpp:41

Referenced by UDFDOSName100(), UDFDOSName200(), and UDFDOSName201().

◆ UDFLoadExtInfo()

OSSTATUS UDFLoadExtInfo ( IN PVCB  Vcb,
IN PFILE_ENTRY  fe,
IN PLONG_AD  fe_loc,
IN OUT PEXTENT_INFO  FExtInfo,
IN OUT PEXTENT_INFO  AExtInfo 
)

Definition at line 1062 of file udf_info.cpp.

1069{
1070 EXTENT_AD TmpExt;
1071
1072 UDFPrint((" UDFLoadExtInfo:\n"));
1073 FExtInfo->Mapping = UDFReadMappingFromXEntry(Vcb, fe_loc->extLocation.partitionReferenceNum,
1074 (tag*)fe, &(FExtInfo->Offset), AExtInfo);
1075 if(!(FExtInfo->Mapping)) {
1076 if(!(FExtInfo->Offset))
1077 return STATUS_UNSUCCESSFUL;
1078 TmpExt.extLength = fe_loc->extLength;
1079 TmpExt.extLocation = UDFPartLbaToPhys(Vcb, &(fe_loc->extLocation));
1080 if(TmpExt.extLocation == LBA_OUT_OF_EXTENT)
1082 FExtInfo->Mapping = UDFExtentToMapping(&TmpExt);
1083 }
1084 if(fe->descTag.tagIdent == TID_FILE_ENTRY) {
1085// UDFPrint(("Standard FileEntry\n"));
1086 FExtInfo->Length = fe->informationLength;
1087 } else /*if(fe->descTag.tagIdent == TID_EXTENDED_FILE_ENTRY) */ {
1088 FExtInfo->Length = ((PEXTENDED_FILE_ENTRY)fe)->informationLength;
1089 }
1090 UDFPrint((" FExtInfo->Length %x\n", FExtInfo->Length));
1091 ASSERT(FExtInfo->Length <= UDFGetExtentLength(FExtInfo->Mapping));
1092 FExtInfo->Modified = FALSE;
1093
1094 return STATUS_SUCCESS;
1095} // end UDFLoadExtInfo()
PEXTENT_MAP UDFReadMappingFromXEntry(IN PVCB Vcb, IN uint32 PartNum, IN tag *XEntry, IN OUT uint32 *Offset, OUT PEXTENT_INFO AllocLoc)
Definition: extent.cpp:735

Referenced by UDFOpenFile__(), and UDFOpenRootFile__().

◆ UDFLoadFileset()

void UDFLoadFileset ( IN PVCB  Vcb,
IN PFILE_SET_DESC  fset,
OUT lb_addr root,
OUT lb_addr sysstream 
)

Definition at line 2539 of file mount.cpp.

2545{
2546 *root = fset->rootDirectoryICB.extLocation;
2547 Vcb->SerialNumber = fset->descTag.tagSerialNum;
2548 UDFPrint(("Rootdir at block=%x, partition=%d\n",
2549 root->logicalBlockNum, root->partitionReferenceNum));
2550 if(sysstream) {
2551 *sysstream = fset->streamDirectoryICB.extLocation;
2552 UDFPrint(("SysStream at block=%x, partition=%d\n",
2553 sysstream->logicalBlockNum, sysstream->partitionReferenceNum));
2554 }
2555#define CUR_IDENT_SZ (sizeof(fset->logicalVolIdent))
2556 if (Vcb->VolIdent.Buffer) {
2557 MyFreePool__(Vcb->VolIdent.Buffer);
2558 }
2559 UDFGetDstring(&(Vcb->VolIdent), (dstring*)&(fset->logicalVolIdent), CUR_IDENT_SZ);
2560#undef CUR_IDENT_SZ
2561 UDFPrint(("volIdent[] = '%ws'\n", Vcb->VolIdent.Buffer));
2562 // Get current UDF revision
2563 // Get Read-Only flags
2564 UDFReadEntityID_Domain(Vcb, &(fset->domainIdent));
2565
2566} // end UDFLoadFileset()
uint8 dstring
Definition: ecma_167.h:20
void __fastcall UDFGetDstring(IN OUT PUNICODE_STRING UName, IN dstring *Dest, IN uint32 Length)
Definition: mount.cpp:783
#define CUR_IDENT_SZ
void UDFReadEntityID_Domain(PVCB Vcb, EntityID *eID)
Definition: udf_info.cpp:1559

Referenced by UDFGetDiskInfoAndVerify().

◆ UDFLoadLogicalVol()

OSSTATUS UDFLoadLogicalVol ( PDEVICE_OBJECT  DeviceObject,
PVCB  Vcb,
int8 Buf,
lb_addr fileset 
)

Definition at line 1374 of file mount.cpp.

1380{
1381 LogicalVolDesc *lvd = (LogicalVolDesc *)Buf;
1382 uint16 i, offset;
1383 uint8 type;
1385 UDFPrint(("UDF: LogicalVolDesc\n"));
1386 // Validate partition map counter
1387 if(!(Vcb->Partitions)) {
1388 Vcb->PartitionMaps = lvd->numPartitionMaps;
1389 Vcb->Partitions = (PUDFPartMap)MyAllocatePool__(NonPagedPool, sizeof(UDFPartMap) * Vcb->PartitionMaps );
1390 if(!Vcb->Partitions)
1392 } else {
1393 if(Vcb->PartitionMaps != lvd->numPartitionMaps)
1395 }
1396 UDFPrint(("UDF: volDescSeqNum = %x\n", lvd->volDescSeqNum));
1397 // Get logical block size (may be different from physical)
1398 Vcb->LBlockSize = lvd->logicalBlockSize;
1399 // Get current UDF revision
1400 // Get Read-Only flags
1402
1403 if(Vcb->LBlockSize < Vcb->BlockSize)
1405 switch(Vcb->LBlockSize) {
1406 case 512: Vcb->LBlockSizeBits = 9; break;
1407 case 1024: Vcb->LBlockSizeBits = 10; break;
1408 case 2048: Vcb->LBlockSizeBits = 11; break;
1409 case 4096: Vcb->LBlockSizeBits = 12; break;
1410 case 8192: Vcb->LBlockSizeBits = 13; break;
1411 case 16384: Vcb->LBlockSizeBits = 14; break;
1412 case 32768: Vcb->LBlockSizeBits = 15; break;
1413 case 65536: Vcb->LBlockSizeBits = 16; break;
1414 default:
1415 UDFPrint(("UDF: Bad block size (%ld)\n", Vcb->LBlockSize));
1417 }
1418 UDFPrint(("UDF: logical block size (%ld)\n", Vcb->LBlockSize));
1419 Vcb->LB2B_Bits = Vcb->LBlockSizeBits - Vcb->BlockSizeBits;
1420 UDFPrint(("UDF: mapTableLength = %x\n", lvd->mapTableLength));
1421 UDFPrint(("UDF: numPartitionMaps = %x\n", lvd->numPartitionMaps));
1422 // walk through all available part maps
1423 for (i=0,offset=0;
1424 i<Vcb->PartitionMaps && offset<lvd->mapTableLength;
1425 i++,offset+=((GenericPartitionMap *)( ((uint8*)(lvd+1))+offset) )->partitionMapLength)
1426 {
1427 GenericPartitionMap* gpm = (GenericPartitionMap *)(((uint8*)(lvd+1))+offset);
1428 type = gpm->partitionMapType;
1429 UDFPrint(("Partition (%d) type %x, len %x\n", i, type, gpm->partitionMapLength));
1431 {
1432 GenericPartitionMap1 *gpm1 = (GenericPartitionMap1 *)(((uint8*)(lvd+1))+offset);
1433
1434 Vcb->Partitions[i].PartitionType = UDF_TYPE1_MAP15;
1435 Vcb->Partitions[i].VolumeSeqNum = gpm1->volSeqNum;
1436 Vcb->Partitions[i].PartitionNum = gpm1->partitionNum;
1438 }
1439 else if(type == PARTITION_MAP_TYPE_2)
1440 {
1441 UdfPartitionMap2* upm2 = (UdfPartitionMap2 *)(((uint8*)(lvd+1))+offset);
1443 {
1444 UDFIdentSuffix* udfis =
1446
1447 if( (udfis->currentRev == 0x0150)/* ||
1448 (Vcb->CurrentUDFRev == 0x0150)*/ ) {
1449 UDFPrint(("Found VAT 1.50\n"));
1450 Vcb->Partitions[i].PartitionType = UDF_VIRTUAL_MAP15;
1451 } else
1452 if( (udfis->currentRev == 0x0200) ||
1453 (udfis->currentRev == 0x0201) /*||
1454 (Vcb->CurrentUDFRev == 0x0200) ||
1455 (Vcb->CurrentUDFRev == 0x0201)*/ ) {
1456 UDFPrint(("Found VAT 2.00\n"));
1457 Vcb->Partitions[i].PartitionType = UDF_VIRTUAL_MAP20;
1458 }
1460 }
1462 {
1463 UDFPrint(("Load sparing table\n"));
1465 Vcb->Partitions[i].PartitionType = UDF_SPARABLE_MAP15;
1467 }
1469 {
1470 UDFPrint(("Found metadata partition\n"));
1471// PMETADATA_PARTITION_MAP mpm = (PMETADATA_PARTITION_MAP)(((uint8*)(lvd+1))+offset);
1472 Vcb->Partitions[i].PartitionType = UDF_METADATA_MAP25;
1473 //status = UDFLoadSparingTable(Vcb, spm);
1474 }
1475 else
1476 {
1477 UDFPrint(("Unknown ident: %s\n", upm2->partIdent.ident));
1478 continue;
1479 }
1480 Vcb->Partitions[i].VolumeSeqNum = upm2->volSeqNum;
1481 Vcb->Partitions[i].PartitionNum = upm2->partitionNum;
1482 }
1483 }
1484
1485 if(fileset) {
1486 // remember FileSet location
1487 long_ad *la = (long_ad *)&(lvd->logicalVolContentsUse[0]);
1488 *fileset = (la->extLocation);
1489 UDFPrint(("FileSet found in LogicalVolDesc at block=%x, partition=%d\n",
1490 fileset->logicalBlockNum,
1491 fileset->partitionReferenceNum));
1492 }
1493 if(OS_SUCCESS(status)) {
1494 // load Integrity Desc if any
1495 if(lvd->integritySeqExt.extLength)
1497 }
1498 return status;
1499} // end UDFLoadLogicalVol()
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define PARTITION_MAP_TYPE_2
Definition: ecma_167.h:302
#define PARTITION_MAP_TYPE_1
Definition: ecma_167.h:301
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
OSSTATUS UDFLoadSparingTable(IN PVCB Vcb, IN PSPARABLE_PARTITION_MAP PartMap)
Definition: mount.cpp:2783
OSSTATUS UDFLoadLogicalVolInt(PDEVICE_OBJECT DeviceObject, PVCB Vcb, extent_ad loc)
Definition: mount.cpp:1239
#define UDF_TYPE1_MAP15
Definition: osta_misc.h:92
#define UDF_VIRTUAL_MAP20
Definition: osta_misc.h:94
#define UDF_ID_SPARABLE
Definition: osta_misc.h:276
#define UDF_ID_METADATA
Definition: osta_misc.h:277
#define UDF_METADATA_MAP25
Definition: osta_misc.h:96
#define UDF_ID_VIRTUAL
Definition: osta_misc.h:275
#define UDF_SPARABLE_MAP15
Definition: osta_misc.h:95
struct _SPARABLE_PARTITION_MAP * PSPARABLE_PARTITION_MAP
#define UDF_VIRTUAL_MAP15
Definition: osta_misc.h:93
uint8 ident[23]
Definition: ecma_167.h:61
uint8 identSuffix[8]
Definition: ecma_167.h:62
uint8 partitionMapType
Definition: ecma_167.h:294
uint8 partitionMapLength
Definition: ecma_167.h:295
uint32 numPartitionMaps
Definition: ecma_167.h:285
uint32 mapTableLength
Definition: ecma_167.h:284
extent_ad integritySeqExt
Definition: ecma_167.h:288
uint8 logicalVolContentsUse[16]
Definition: ecma_167.h:283
EntityID domainIdent
Definition: ecma_167.h:282
uint32 logicalBlockSize
Definition: ecma_167.h:281
uint32 volDescSeqNum
Definition: ecma_167.h:278
uint16 currentRev
Definition: osta_misc.h:226
EntityID partIdent
Definition: osta_misc.h:53
uint16 partitionNum
Definition: osta_misc.h:55
uint16 volSeqNum
Definition: osta_misc.h:54
struct _UDFPartMap * PUDFPartMap

Referenced by UDFProcessSequence().

◆ UDFLoadLogicalVolInt()

OSSTATUS UDFLoadLogicalVolInt ( PDEVICE_OBJECT  DeviceObject,
PVCB  Vcb,
extent_ad  loc 
)

Definition at line 1239 of file mount.cpp.

1244{
1246 uint32 len;
1247 SIZE_T _ReadBytes;
1248 int8* Buf = NULL;
1249 uint16 ident;
1251 LogicalVolHeaderDesc* LVID_hd;
1252 extent_ad last_loc;
1253 BOOLEAN read_last = FALSE;
1254 uint32 lvid_count = 0;
1255
1256 ASSERT(!Vcb->LVid);
1257 if(Vcb->LVid) {
1258 MyFreePool__(Vcb->LVid);
1259 Vcb->LVid = NULL;
1260 }
1261 // walk through all sectors inside LogicalVolumeIntegrityDesc
1262 while(loc.extLength) {
1263 UDFPrint(("UDF: Reading LVID @%x (%x)\n", loc.extLocation, loc.extLength));
1264 len = max(loc.extLength, Vcb->BlockSize);
1266 if(!Buf)
1268 RC = UDFReadTagged(Vcb,Buf, loc.extLocation, loc.extLocation, &ident);
1269 if(!OS_SUCCESS(RC)) {
1270exit_with_err:
1271 UDFPrint(("UDF: Reading LVID @%x (%x) failed.\n", loc.extLocation, loc.extLength));
1272 switch(Vcb->PartitialDamagedVolumeAction) {
1274 UDFPrint(("UDF: Switch to r/o mode.\n"));
1276 Vcb->UserFSFlags |= UDF_USER_FS_FLAGS_MEDIA_DEFECT_RO;
1277 RC = STATUS_SUCCESS;
1278 break;
1280 UDFPrint(("UDF: Switch to raw mount mode, return UNRECOGNIZED_VOLUME.\n"));
1281 Vcb->VCBFlags |= UDF_VCB_FLAGS_RAW_DISK;
1282 //RC = STATUS_WRONG_VOLUME;
1283 break;
1285 default:
1286 UDFPrint(("UDF: Keep r/w mode for your own risk.\n"));
1287 RC = STATUS_SUCCESS;
1288 // asume we have INTEGRITY_TYPE_CLOSE
1289 Vcb->IntegrityType = INTEGRITY_TYPE_CLOSE;
1290 break;
1291 }
1292
1293 MyFreePool__(Buf);
1294 return RC;
1295 }
1297 // handle Terminal Entry
1298 if(ident == TID_TERMINAL_ENTRY) {
1299 read_last = TRUE;
1300 MyFreePool__(Buf);
1301 Vcb->LVid = NULL;
1302 loc = last_loc;
1303 continue;
1304 } else
1307 goto exit_with_err;
1308 }
1309
1310 Vcb->LVid = (LogicalVolIntegrityDesc *)Buf;
1311 RC = UDFReadData(Vcb, TRUE, ((uint64)(loc.extLocation)) << Vcb->BlockSizeBits, len, FALSE, Buf, &_ReadBytes);
1312 // update info
1313 if( !read_last &&
1314 Vcb->LVid->nextIntegrityExt.extLength) {
1315 // go to next LVID
1316 last_loc = loc;
1317 loc = Vcb->LVid->nextIntegrityExt;
1318 Vcb->LVid = NULL;
1319 lvid_count++;
1320 if(lvid_count > UDF_MAX_LVID_CHAIN_LENGTH) {
1322 goto exit_with_err;
1323 }
1324 MyFreePool__(Buf);
1325 continue;
1326 }
1327 // process last LVID
1328 Vcb->origIntegrityType =
1329 Vcb->IntegrityType = Vcb->LVid->integrityType;
1330 Vcb->LVid_loc = loc;
1331
1332 LVID_iUse = UDFGetLVIDiUse(Vcb);
1333
1334 UDFPrint(("UDF: Last LVID:\n"));
1335 UDFPrint((" minR: %x\n",LVID_iUse->minUDFReadRev ));
1336 UDFPrint((" minW: %x\n",LVID_iUse->minUDFWriteRev));
1337 UDFPrint((" maxW: %x\n",LVID_iUse->maxUDFWriteRev));
1338 UDFPrint((" Type: %s\n",!Vcb->IntegrityType ? "Open" : "Close"));
1339
1340 Vcb->minUDFReadRev = LVID_iUse->minUDFReadRev;
1341 Vcb->minUDFWriteRev = LVID_iUse->minUDFWriteRev;
1342 Vcb->maxUDFWriteRev = LVID_iUse->maxUDFWriteRev;
1343
1344 Vcb->numFiles = LVID_iUse->numFiles;
1345 Vcb->numDirs = LVID_iUse->numDirs;
1346 UDFPrint((" nFiles: %x\n",Vcb->numFiles ));
1347 UDFPrint((" nDirs: %x\n",Vcb->numDirs ));
1348
1349 // Check if we can understand this format
1350 if(Vcb->minUDFReadRev > UDF_MAX_READ_REVISION)
1352 // Check if we know how to write here
1353 if(Vcb->minUDFWriteRev > UDF_MAX_WRITE_REVISION) {
1354 UDFPrint((" Target FS requires: %x Revision => ReadOnly\n",Vcb->minUDFWriteRev));
1356 Vcb->UserFSFlags |= UDF_USER_FS_FLAGS_NEW_FS_RO;
1357 }
1358
1359 LVID_hd = (LogicalVolHeaderDesc*)&(Vcb->LVid->logicalVolContentsUse);
1360 Vcb->NextUniqueId = LVID_hd->uniqueID;
1361 UDFPrint((" Next FID: %x\n",Vcb->NextUniqueId));
1362
1363 break;
1364 }
1365
1366 return RC;
1367} // end UDFLoadLogicalVolInt()
#define TID_LOGICAL_VOL_INTEGRITY_DESC
Definition: ecma_167.h:162
#define INTEGRITY_TYPE_CLOSE
Definition: ecma_167.h:358
#define TID_TERMINAL_ENTRY
Definition: ecma_167.h:169
#define UDFGetLVIDiUse(Vcb)
Definition: udf_info.h:884
#define UDF_MAX_LVID_CHAIN_LENGTH
Definition: udf_rel.h:516
#define UDF_MAX_WRITE_REVISION
Definition: udf_rel.h:514
#define UDF_MAX_READ_REVISION
Definition: udf_rel.h:513
#define UDF_PART_DAMAGED_RW
Definition: udfpubl.h:120
#define UDF_USER_FS_FLAGS_MEDIA_DEFECT_RO
Definition: udfpubl.h:114
#define UDF_USER_FS_FLAGS_NEW_FS_RO
Definition: udfpubl.h:116
#define UDF_PART_DAMAGED_NO
Definition: udfpubl.h:122
#define UDF_PART_DAMAGED_RO
Definition: udfpubl.h:121

Referenced by UDFLoadLogicalVol().

◆ UDFLoadPartDesc()

OSSTATUS UDFLoadPartDesc ( PVCB  Vcb,
int8 Buf 
)

Definition at line 2023 of file mount.cpp.

2027{
2028 PartitionDesc *p = (PartitionDesc *)Buf;
2029 uint32 i;
2030 OSSTATUS RC;
2032 UDFPrint(("UDF: Pard Descr:\n"));
2033 UDFPrint((" volDescSeqNum = %x\n", p->volDescSeqNum));
2034 UDFPrint((" partitionFlags = %x\n", p->partitionFlags));
2035 UDFPrint((" partitionNumber = %x\n", p->partitionNumber));
2036 UDFPrint((" accessType = %x\n", p->accessType));
2037 UDFPrint((" partitionStartingLocation = %x\n", p->partitionStartingLocation));
2038 UDFPrint((" partitionLength = %x\n", p->partitionLength));
2039 // There is nothing interesting to comment here
2040 // Just look at Names & Messages....
2041 for (i=0; i<Vcb->PartitionMaps; i++) {
2042 UDFPrint(("Searching map: (%d == %d)\n",
2043 Vcb->Partitions[i].PartitionNum, (p->partitionNumber) ));
2044 if(Vcb->Partitions[i].PartitionNum == (p->partitionNumber)) {
2045 Found = TRUE;
2046 Vcb->Partitions[i].PartitionRoot = p->partitionStartingLocation + Vcb->FirstLBA;
2047 Vcb->Partitions[i].PartitionLen = p->partitionLength;
2048 Vcb->Partitions[i].UspaceBitmap = 0xFFFFFFFF;
2049 Vcb->Partitions[i].FspaceBitmap = 0xFFFFFFFF;
2050 Vcb->Partitions[i].AccessType = p->accessType;
2051 UDFPrint(("Access mode %x\n", p->accessType));
2052 if(p->accessType == PARTITION_ACCESS_WO) {
2053 Vcb->CDR_Mode = TRUE;
2054// Vcb->Partitions[i].PartitionLen = Vcb->LastPossibleLBA - p->partitionStartingLocation;
2055 } else if(p->accessType < PARTITION_ACCESS_WO) {
2056 // Soft-read-only volume
2057 UDFPrint(("Soft Read-only volume\n"));
2059 Vcb->UserFSFlags |= UDF_USER_FS_FLAGS_PART_RO;
2060 } else if(p->accessType > PARTITION_ACCESS_MAX_KNOWN) {
2062 }
2063
2064 if(!strcmp((int8*)&(p->partitionContents.ident), PARTITION_CONTENTS_NSR02) ||
2065 !strcmp((int8*)&(p->partitionContents.ident), PARTITION_CONTENTS_NSR03))
2066 {
2068
2069 phd = (PPARTITION_HEADER_DESC)(p->partitionContentsUse);
2070#ifdef UDF_DBG
2072 UDFPrint(("unallocatedSpaceTable (part %d)\n", i));
2073#endif // UDF_DBG
2075 Vcb->Partitions[i].UspaceBitmap =
2077 UDFPrint(("unallocatedSpaceBitmap (part %d) @ %x\n",
2078 i, Vcb->Partitions[i].UspaceBitmap ));
2079 }
2080#ifdef UDF_DBG
2082 UDFPrint(("partitionIntegrityTable (part %d)\n", i));
2083 if(phd->freedSpaceTable.extLength)
2084 UDFPrint(("freedSpaceTable (part %d)\n", i));
2085#endif // UDF_DBG
2086 if(phd->freedSpaceBitmap.extLength) {
2087 Vcb->Partitions[i].FspaceBitmap =
2089 UDFPrint(("freedSpaceBitmap (part %d)\n", i));
2090 }
2091 RC = UDFBuildFreeSpaceBitmap(Vcb, i, phd, 0);
2092 //Vcb->Modified = FALSE;
2095 if(!OS_SUCCESS(RC))
2096 return RC;
2097
2098 if ((Vcb->Partitions[i].PartitionType == UDF_VIRTUAL_MAP15) ||
2099 (Vcb->Partitions[i].PartitionType == UDF_VIRTUAL_MAP20)) {
2100 RC = UDFLoadVAT(Vcb, i);
2101 if(!OS_SUCCESS(RC))
2102 return RC;
2103 WCacheFlushAll__(&(Vcb->FastCache), Vcb);
2104 WCacheSetMode__(&(Vcb->FastCache), WCACHE_MODE_R);
2105 Vcb->LastModifiedTrack = 0;
2106 }
2107 }
2108 }
2109 }
2110#ifdef UDF_DBG
2111 if(!Found) {
2112 UDFPrint(("Partition (%d) not found in partition map\n", (p->partitionNumber) ));
2113 } else {
2114 UDFPrint(("Partition (%d:%d type %x) starts at physical %x, length %x\n",
2115 p->partitionNumber, i-1, Vcb->Partitions[i-1].PartitionType,
2116 Vcb->Partitions[i-1].PartitionRoot, Vcb->Partitions[i-1].PartitionLen));
2117 }
2118#endif // UDF_DBG
2119 return STATUS_SUCCESS;
2120} // end UDFLoadPartDesc()
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
return Found
Definition: dirsup.c:1270
#define PARTITION_CONTENTS_NSR02
Definition: ecma_167.h:264
#define PARTITION_ACCESS_MAX_KNOWN
Definition: ecma_167.h:273
#define PARTITION_ACCESS_WO
Definition: ecma_167.h:270
#define PARTITION_CONTENTS_NSR03
Definition: ecma_167.h:265
struct _PARTITION_HEADER_DESC * PPARTITION_HEADER_DESC
GLfloat GLfloat p
Definition: glext.h:8902
VOID UDFPreClrModified(IN PVCB Vcb)
Definition: misc_common.cpp:18
VOID UDFClrModified(IN PVCB Vcb)
Definition: misc_common.cpp:26
OSSTATUS UDFBuildFreeSpaceBitmap(IN PVCB Vcb, IN uint32 PartNdx, IN PPARTITION_HEADER_DESC phd, IN uint32 Lba)
Definition: mount.cpp:1910
short_ad unallocatedSpaceBitmap
Definition: ecma_167.h:416
short_ad partitionIntegrityTable
Definition: ecma_167.h:417
short_ad unallocatedSpaceTable
Definition: ecma_167.h:415
short_ad freedSpaceTable
Definition: ecma_167.h:418
short_ad freedSpaceBitmap
Definition: ecma_167.h:419
uint32 extLength
Definition: ecma_167.h:407
uint32 extPosition
Definition: ecma_167.h:408
OSSTATUS UDFLoadVAT(IN PVCB Vcb, IN uint32 PartNdx)
Definition: udf_info.cpp:3602
#define STATUS_UNRECOGNIZED_MEDIA
Definition: udferr_usr.h:142
#define UDF_USER_FS_FLAGS_PART_RO
Definition: udfpubl.h:115
VOID WCacheFlushAll__(IN PW_CACHE Cache, IN PVOID Context)
OSSTATUS WCacheSetMode__(IN PW_CACHE Cache, IN ULONG Mode)
#define WCACHE_MODE_R
Definition: wcache_lib.h:126

Referenced by UDFProcessSequence().

◆ UDFLoadPartition()

OSSTATUS UDFLoadPartition ( IN PDEVICE_OBJECT  DeviceObject,
IN PVCB  Vcb,
OUT lb_addr fileset 
)

Definition at line 2607 of file mount.cpp.

2612{
2615 AnchorVolDescPtr *anchor;
2616 uint16 ident;
2617 int8* Buf = (int8*)MyAllocatePool__(NonPagedPool,Vcb->BlockSize);
2618 uint32 main_s, main_e;
2619 uint32 reserve_s, reserve_e;
2620 int i;
2621
2622 if(!Buf) return STATUS_INSUFFICIENT_RESOURCES;
2623 // walk through all available Anchors & load data
2624 for (i=0; i<MAX_ANCHOR_LOCATIONS; i++)
2625 {
2626 if(Vcb->Anchor[i] && (OS_SUCCESS(UDFReadTagged(Vcb, Buf,
2627 Vcb->Anchor[i], Vcb->Anchor[i] - Vcb->FirstLBA, &ident))))
2628 {
2629 anchor = (AnchorVolDescPtr *)Buf;
2630
2631 // Locate the main sequence
2632 main_s = ( anchor->mainVolDescSeqExt.extLocation );
2633 main_e = ( anchor->mainVolDescSeqExt.extLength );
2634 main_e = main_e >> Vcb->BlockSizeBits;
2635 main_e += main_s;
2636
2637 // Locate the reserve sequence
2638 reserve_s = (anchor->reserveVolDescSeqExt.extLocation);
2639 reserve_e = (anchor->reserveVolDescSeqExt.extLength);
2640 reserve_e = reserve_e >> Vcb->BlockSizeBits;
2641 reserve_e += reserve_s;
2642
2643 // Check if it is known bad sequence
2644 RC = UDFIsCachedBadSequence(Vcb, main_s);
2645 if(OS_SUCCESS(RC)) {
2646 // Process the main & reserve sequences
2647 // responsible for finding the PartitionDesc(s)
2648 UDFPrint(("-----------------------------------\n"));
2649 UDFPrint(("UDF: Main sequence:\n"));
2650 RC = UDFProcessSequence(DeviceObject, Vcb, main_s, main_e, fileset);
2651 }
2652
2653 if(!OS_SUCCESS(RC)) {
2654 // Remenber bad sequence
2655 UDFRememberBadSequence(Vcb, main_s, RC);
2656
2657 UDFPrint(("-----------------------------------\n"));
2658 UDFPrint(("UDF: Main sequence failed.\n"));
2659 UDFPrint(("UDF: Reserve sequence\n"));
2660 if(Vcb->LVid) MyFreePool__(Vcb->LVid);
2661 Vcb->LVid = NULL;
2662
2663 RC2 = UDFIsCachedBadSequence(Vcb, reserve_s);
2664 if(OS_SUCCESS(RC2)) {
2665 RC2 = UDFProcessSequence(DeviceObject, Vcb, reserve_s, reserve_e, fileset);
2666 }
2667
2668 if(OS_SUCCESS(RC2)) {
2669 UDFPrint(("-----------------------------------\n"));
2670 Vcb->VDS2_Len = reserve_e - reserve_s;
2671 Vcb->VDS2 = reserve_s;
2672 RC = STATUS_SUCCESS;
2673 // Vcb is already Zero-filled
2674// Vcb->VDS1_Len = 0;
2675// Vcb->VDS1 = 0;
2676 break;
2677 } else {
2678 // This is also bad sequence. Remenber it too
2679 UDFRememberBadSequence(Vcb, reserve_s, RC);
2680 }
2681 } else {
2682 // remember these values for umount__
2683 Vcb->VDS1_Len = main_e - main_s;
2684 Vcb->VDS1 = main_s;
2685/* if(Vcb->LVid) MyFreePool__(Vcb->LVid);
2686 Vcb->LVid = NULL;*/
2687 if(OS_SUCCESS(UDFVerifySequence(DeviceObject, Vcb, reserve_s, reserve_e, fileset)))
2688 {
2689 UDFPrint(("-----------------------------------\n"));
2690 Vcb->VDS2_Len = reserve_e - reserve_s;
2691 Vcb->VDS2 = reserve_s;
2692 break;
2693 } else {
2694 UDFPrint(("UDF: Reserve sequence verification failed.\n"));
2695 switch(Vcb->PartitialDamagedVolumeAction) {
2697 UDFPrint(("UDF: Switch to r/o mode.\n"));
2699 break;
2701 UDFPrint(("UDF: Switch to raw mount mode, return UNRECOGNIZED_VOLUME.\n"));
2702 Vcb->VCBFlags |= UDF_VCB_FLAGS_RAW_DISK;
2704 break;
2706 default:
2707 UDFPrint(("UDF: Keep r/w mode for your own risk.\n"));
2708 break;
2709 }
2710 }
2711 break;
2712 }
2713 }
2714 }
2715
2716 if(Vcb->SparingCount &&
2717 (Vcb->NoFreeRelocationSpaceVolumeAction != UDF_PART_DAMAGED_RW)) {
2718 UDFPrint(("UDF: No free Sparing Entries -> Switch to r/o mode.\n"));
2720 }
2721
2722 if(i == sizeof(Vcb->Anchor)/sizeof(int)) {
2723 UDFPrint(("No Anchor block found\n"));
2725#ifdef UDF_DBG
2726 } else {
2727 UDFPrint(("Using anchor in block %x\n", Vcb->Anchor[i]));
2728#endif // UDF_DBG
2729 }
2730 MyFreePool__(Buf);
2731 return RC;
2732} // end UDFLoadPartition()
OSSTATUS UDFIsCachedBadSequence(IN PVCB Vcb, IN uint32 Lba)
Definition: mount.cpp:2569
OSSTATUS UDFProcessSequence(IN PDEVICE_OBJECT DeviceObject, IN PVCB Vcb, IN uint32 block, IN uint32 lastblock, OUT lb_addr *fileset)
Definition: mount.cpp:2360
VOID UDFRememberBadSequence(IN PVCB Vcb, IN uint32 Lba, IN OSSTATUS RC)
Definition: mount.cpp:2587
OSSTATUS UDFVerifySequence(IN PDEVICE_OBJECT DeviceObject, IN PVCB Vcb, IN uint32 block, IN uint32 lastblock, OUT lb_addr *fileset)
Definition: mount.cpp:2461
extent_ad reserveVolDescSeqExt
Definition: ecma_167.h:219
extent_ad mainVolDescSeqExt
Definition: ecma_167.h:218
#define MAX_ANCHOR_LOCATIONS
Definition: udf_common.h:35
#define STATUS_WRONG_VOLUME
Definition: udferr_usr.h:140

Referenced by UDFGetDiskInfoAndVerify().

◆ UDFLoadPVolDesc()

void UDFLoadPVolDesc ( PVCB  Vcb,
int8 Buf 
)

Definition at line 1194 of file mount.cpp.

1198{
1199 PrimaryVolDesc *pvoldesc;
1200// OSSTATUS RC = STATUS_SUCCESS;
1201
1202 pvoldesc = (PrimaryVolDesc *)Buf;
1203 UDFPrint(("UDF: PrimaryVolDesc:\n"));
1204 UDFPrint(("volDescSeqNum = %d\n", pvoldesc->volDescSeqNum));
1205 UDFPrint(("primaryVolDescNum = %d\n", pvoldesc->primaryVolDescNum));
1206 // remember recording time...
1207 Vcb->VolCreationTime = UDFTimeToNT(&(pvoldesc->recordingDateAndTime));
1208 // ...VolIdent...
1209#define CUR_IDENT_SZ (sizeof(pvoldesc->volIdent))
1210 if (Vcb->VolIdent.Buffer) {
1211 MyFreePool__(Vcb->VolIdent.Buffer);
1212 }
1213 UDFGetDstring(&(Vcb->VolIdent), (dstring*)&(pvoldesc->volIdent), CUR_IDENT_SZ);
1214#undef CUR_IDENT_SZ
1215 UDFPrint(("volIdent[] = '%ws'\n", Vcb->VolIdent.Buffer));
1216#ifdef UDF_DBG
1217 UDFPrint(("volSeqNum = %d\n", pvoldesc->volSeqNum));
1218 UDFPrint(("maxVolSeqNum = %d\n", pvoldesc->maxVolSeqNum));
1219 UDFPrint(("interchangeLvl = %d\n", pvoldesc->interchangeLvl));
1220 UDFPrint(("maxInterchangeLvl = %d\n", pvoldesc->maxInterchangeLvl));
1221 UDFPrint(("charSetList = %d\n", pvoldesc->charSetList));
1222 UDFPrint(("maxCharSetList = %d\n", pvoldesc->maxCharSetList));
1223 // ...& just print VolSetIdent
1224 UNICODE_STRING instr;
1225#define CUR_IDENT_SZ (sizeof(pvoldesc->volSetIdent))
1226 UDFGetDstring(&instr, (dstring*)&(pvoldesc->volSetIdent), CUR_IDENT_SZ);
1227#undef CUR_IDENT_SZ
1228 UDFPrint(("volSetIdent[] = '%ws'\n", instr.Buffer));
1229// UDFPrint(("maxInterchangeLvl = %d\n", pvoldesc->maxInterchangeLvl));
1230 UDFPrint(("flags = %x\n", pvoldesc->flags));
1231 if(instr.Buffer) MyFreePool__(instr.Buffer);
1232#endif // UDF_DBG
1233} // end UDFLoadPVolDesc()
LONGLONG UDFTimeToNT(IN PUDF_TIME_STAMP UdfTime)
uint16 maxInterchangeLvl
Definition: ecma_167.h:195
uint32 charSetList
Definition: ecma_167.h:196
dstring volSetIdent[128]
Definition: ecma_167.h:198
timestamp recordingDateAndTime
Definition: ecma_167.h:204
uint16 volSeqNum
Definition: ecma_167.h:192
uint32 maxCharSetList
Definition: ecma_167.h:197
uint32 primaryVolDescNum
Definition: ecma_167.h:190
uint16 flags
Definition: ecma_167.h:208
uint16 interchangeLvl
Definition: ecma_167.h:194
uint32 volDescSeqNum
Definition: ecma_167.h:189
dstring volIdent[32]
Definition: ecma_167.h:191
uint16 maxVolSeqNum
Definition: ecma_167.h:193

Referenced by UDFProcessSequence().

◆ UDFLoadSparingTable()

OSSTATUS UDFLoadSparingTable ( IN PVCB  Vcb,
IN PSPARABLE_PARTITION_MAP  PartMap 
)

Definition at line 2783 of file mount.cpp.

2787{
2788 PSPARING_MAP RelocMap;
2789 PSPARING_MAP NewRelocMap;
2791 uint32 i=0, BC, BC2;
2792 PSPARING_TABLE SparTable;
2793 uint32 TabSize, NewSize;
2795 uint32 SparTableLoc;
2796#ifdef UDF_TRACK_FS_STRUCTURES
2797 uint32 j;
2798#endif //UDF_TRACK_FS_STRUCTURES
2799 uint32 n,m;
2800 BOOLEAN merged;
2801
2802 Vcb->SparingCountFree = -1;
2803
2804 UDFPrint(("UDF: Sparable Part Map:\n"));
2805 Vcb->SparingTableLength = PartMap->sizeSparingTable;
2806 BC = (PartMap->sizeSparingTable >> Vcb->BlockSizeBits) + 1;
2807 UDFPrint((" partitionMapType = %x\n", PartMap->partitionMapType));
2808 UDFPrint((" partitionMapLength = %x\n", PartMap->partitionMapLength));
2809 UDFPrint((" volSeqNum = %x\n", PartMap->volSeqNum));
2810 UDFPrint((" partitionNum = %x\n", PartMap->partitionNum));
2811 UDFPrint((" packetLength = %x\n", PartMap->packetLength));
2812 UDFPrint((" numSparingTables = %x\n", PartMap->numSparingTables));
2813 UDFPrint((" sizeSparingTable = %x\n", PartMap->sizeSparingTable));
2814 SparTable = (PSPARING_TABLE)MyAllocatePool__(NonPagedPool, BC*Vcb->BlockSize);
2815 if(!SparTable) return STATUS_INSUFFICIENT_RESOURCES;
2816 if(Vcb->SparingTable) {
2817 // if a part of Sparing Table is already loaded,
2818 // update it with data from another one
2819 RelocMap = Vcb->SparingTable;
2820 TabSize = Vcb->SparingCount * sizeof(SPARING_ENTRY);
2821 } else {
2822 // do some init to load first part of Sparing Table
2824 if(!RelocMap) {
2825 MyFreePool__(SparTable);
2827 }
2828 TabSize = RELOC_MAP_GRAN;
2829 Vcb->SparingBlockSize = PartMap->packetLength;
2830 }
2831 // walk through all available Sparing Tables
2832 for(i=0;i<PartMap->numSparingTables;i++) {
2833 // read (next) table
2834 SparTableLoc = ((uint32*)(PartMap+1))[i];
2835 for(n=0; n<Vcb->SparingTableCount; n++) {
2836 if(Vcb->SparingTableLoc[i] == SparTableLoc) {
2837 UDFPrint((" already processed @%x\n",
2838 SparTableLoc
2839 ));
2840 continue;
2841 }
2842 }
2843 status = UDFReadSectors(Vcb, FALSE, SparTableLoc, 1, FALSE, (int8*)SparTable, &ReadBytes);
2844 // tag should be set to TID_UNUSED_DESC
2845 if(OS_SUCCESS(status) && (SparTable->descTag.tagIdent == TID_UNUSED_DESC)) {
2846
2847 UDFRegisterFsStructure(Vcb, SparTableLoc, Vcb->BlockSize);
2848 BC2 = ((sizeof(SPARING_TABLE) +
2849 SparTable->reallocationTableLen*sizeof(SparingEntry) +
2850 Vcb->BlockSize-1)
2851 >> Vcb->BlockSizeBits);
2852 if(BC2 > BC) {
2853 UDFPrint((" sizeSparingTable @%x too long: %x > %x\n",
2854 SparTableLoc, BC2, BC
2855 ));
2856 continue;
2857 }
2858 status = UDFReadSectors(Vcb, FALSE, SparTableLoc,
2859 BC2, FALSE, (int8*)SparTable, &ReadBytes);
2860 UDFRegisterFsStructure(Vcb, SparTableLoc, BC2<<Vcb->BlockSizeBits);
2861
2862 if(!OS_SUCCESS(status)) {
2863 UDFPrint((" Error reading sizeSparingTable @%x (%x)\n",
2864 SparTableLoc, BC2
2865 ));
2866 continue;
2867 }
2868 // process sparing table
2869 NewSize = sizeof(SparingEntry)*SparTable->reallocationTableLen;
2870 TabSize = MyReallocPool__((int8*)RelocMap, TabSize, (int8**)&RelocMap, TabSize+NewSize);
2871 if(!TabSize) {
2872 MyFreePool__(SparTable);
2874 }
2875
2876#ifdef UDF_TRACK_FS_STRUCTURES
2877 for(j=0; j<SparTable->reallocationTableLen; j++) {
2878 UDFRegisterFsStructure(Vcb, ((SparingEntry*)(SparTable+1))[j].mappedLocation, Vcb->WriteBlockSize);
2879 }
2880#endif //UDF_TRACK_FS_STRUCTURES
2881
2882 Vcb->SparingTableLoc[Vcb->SparingTableCount] = SparTableLoc;
2883 Vcb->SparingTableCount++;
2884
2885 NewRelocMap = (PSPARING_MAP)(SparTable+1);
2886 for(n=0; n<SparTable->reallocationTableLen; n++) {
2887 merged = TRUE;
2888 for(m=0; m<Vcb->SparingCount; m++) {
2889 if(RelocMap[m].mappedLocation == NewRelocMap[n].mappedLocation) {
2890 UDFPrint((" dup @%x (%x) vs @%x (%x)\n",
2891 RelocMap[m].origLocation, RelocMap[m].mappedLocation,
2892 NewRelocMap[m].origLocation, NewRelocMap[m].mappedLocation));
2893 merged = FALSE;
2894 }
2895 if((RelocMap[m].origLocation == NewRelocMap[n].origLocation) &&
2896 (RelocMap[m].mappedLocation != NewRelocMap[n].mappedLocation) &&
2897 (RelocMap[m].origLocation != SPARING_LOC_AVAILABLE) &&
2898 (RelocMap[m].origLocation != SPARING_LOC_CORRUPTED)) {
2899 UDFPrint((" conflict @%x (%x) vs @%x (%x)\n",
2900 RelocMap[m].origLocation, RelocMap[m].mappedLocation,
2901 NewRelocMap[n].origLocation, NewRelocMap[n].mappedLocation));
2902 merged = FALSE;
2903 }
2904 }
2905 if(merged) {
2906 RelocMap[Vcb->SparingCount] = NewRelocMap[n];
2907 UDFPrint((" reloc %x -> %x\n",
2908 RelocMap[Vcb->SparingCount].origLocation, RelocMap[Vcb->SparingCount].mappedLocation));
2909 Vcb->SparingCount++;
2910 if(RelocMap[Vcb->SparingCount].origLocation == SPARING_LOC_AVAILABLE) {
2911 Vcb->NoFreeRelocationSpaceVolumeAction = UDF_PART_DAMAGED_RW;
2912 }
2913 }
2914 }
2915
2916/*
2917 RtlCopyMemory((int8*)(RelocMap+Vcb->SparingCount),
2918 (int8*)(SparTable+1), NewSize);
2919 Vcb->SparingCount += NewSize/sizeof(SPARING_ENTRY);
2920*/
2921 if(Vcb->SparingTableCount >= MAX_SPARING_TABLE_LOCATIONS) {
2922 UDFPrint((" too many Sparing Tables\n"));
2923 break;
2924 }
2925 }
2926 }
2927 Vcb->SparingTable = RelocMap;
2928 MyFreePool__(SparTable);
2929 return STATUS_SUCCESS;
2930} // end UDFLoadSparingTable()
#define TID_UNUSED_DESC
Definition: ecma_167.h:153
_Must_inspect_result_ _In_ USHORT NewSize
Definition: fltkernel.h:975
GLdouble n
Definition: glext.h:7729
const GLfloat * m
Definition: glext.h:10848
#define SPARING_LOC_CORRUPTED
Definition: osta_misc.h:196
PSPARING_ENTRY PSPARING_MAP
Definition: osta_misc.h:202
#define SPARING_LOC_AVAILABLE
Definition: osta_misc.h:195
SparingEntry SPARING_ENTRY
Definition: osta_misc.h:198
struct _SPARING_TABLE SPARING_TABLE
struct _SPARING_TABLE * PSPARING_TABLE
struct _SparingEntry SparingEntry
uint16 reallocationTableLen
Definition: osta_misc.h:208
#define MAX_SPARING_TABLE_LOCATIONS
Definition: udf_common.h:36
#define RELOC_MAP_GRAN
Definition: udf_rel.h:119

Referenced by UDFLoadLogicalVol().

◆ UDFLoadVAT()

OSSTATUS UDFLoadVAT ( IN PVCB  Vcb,
IN uint32  PartNdx 
)

Definition at line 3602 of file udf_info.cpp.

3606{
3607 lb_addr VatFELoc;
3609 PUDF_FILE_INFO VatFileInfo;
3610 uint32 len, i=0, j, to_read;
3611 uint32 Offset, hdrOffset;
3613 uint32 root;
3614 uint16 PartNum;
3615// uint32 VatFirstLba = 0;
3616 int8* VatOldData;
3617 uint32 VatLba[6] = { Vcb->LastLBA,
3618 Vcb->LastLBA - 2,
3619 Vcb->LastLBA - 3,
3620 Vcb->LastLBA - 5,
3621 Vcb->LastLBA - 7,
3622 0 };
3623
3624 if(Vcb->Vat) return STATUS_SUCCESS;
3625 if(!Vcb->CDR_Mode) return STATUS_SUCCESS;
3626 // disable VAT for now. We'll reenable it if VAT is successfuly loaded
3627 Vcb->CDR_Mode = FALSE;
3628 PartNum = Vcb->Partitions[PartNdx].PartitionNum;
3629 root = Vcb->Partitions[PartNdx].PartitionRoot;
3630 if(Vcb->LBlockSize != Vcb->BlockSize) {
3631 // don't know how to operate... :(((
3633 }
3634 if((Vcb->LastTrackNum > 1) &&
3635 (Vcb->LastLBA == Vcb->TrackMap[Vcb->LastTrackNum-1].LastLba)) {
3636 UDFPrint(("Hardware Read-only volume\n"));
3638 }
3639
3641 if(!VatFileInfo) return STATUS_INSUFFICIENT_RESOURCES;
3642 // load VAT FE (we know its location)
3643 VatFELoc.partitionReferenceNum = PartNum;
3644retry_load_vat:
3645 VatFELoc.logicalBlockNum = UDFPhysLbaToPart(Vcb, PartNum, VatLba[i]);
3646 if(!OS_SUCCESS(status = UDFOpenRootFile__(Vcb, &VatFELoc, VatFileInfo))) {
3647 UDFCleanUpFile__(Vcb, VatFileInfo);
3648 // try another location
3649 i++;
3650 if( VatLba[i] &&
3652 (status != STATUS_CRC_ERROR)) goto retry_load_vat;
3653 MyFreePool__(VatFileInfo);
3654 Vcb->VatFileInfo = NULL;
3655 return status;
3656 }
3657 len = (uint32)UDFGetFileSize(VatFileInfo);
3658 if(Vcb->Partitions[PartNdx].PartitionType == UDF_VIRTUAL_MAP15) {
3659 // load Vat 1.50 header
3660 UDFPrint(("Load VAT 1.50\n"));
3662 if(((icbtag*)(VatFileInfo->Dloc->FileEntry+1))->fileType != UDF_FILE_TYPE_VAT15) {
3664 goto err_vat_15;
3665 }
3667 if(!Buf) {
3668err_vat_15_2:
3670err_vat_15:
3671 UDFCloseFile__(Vcb, VatFileInfo);
3672 UDFCleanUpFile__(Vcb, VatFileInfo);
3673 MyFreePool__(VatFileInfo);
3674 Vcb->VatFileInfo = NULL;
3675 return status;
3676 }
3677 Offset = 0;
3678 to_read =
3679 hdrOffset = len - sizeof(VirtualAllocationTable15);
3680 MyFreePool__(Buf);
3681
3682 Vcb->minUDFReadRev =
3683 Vcb->minUDFWriteRev =
3684 Vcb->maxUDFWriteRev = 0x0150;
3685
3686 Vcb->numFiles =
3687 Vcb->numDirs = -1;
3688
3689 } else
3690 if(Vcb->Partitions[PartNdx].PartitionType == UDF_VIRTUAL_MAP20) {
3691 // load Vat 2.00 header
3692 UDFPrint(("Load VAT 2.00\n"));
3694 if(((icbtag*)(VatFileInfo->Dloc->FileEntry+1))->fileType != UDF_FILE_TYPE_VAT20) {
3696 goto err_vat_15;
3697 }
3699 if(!Buf) goto err_vat_15_2;
3700 Offset = Buf->lengthHeader;
3701 to_read = len - Offset;
3702 hdrOffset = 0;
3703 MyFreePool__(Buf);
3704
3705 Vcb->minUDFReadRev = Buf->minReadRevision;
3706 Vcb->minUDFWriteRev = Buf->minWriteRevision;
3707 Vcb->maxUDFWriteRev = Buf->maxWriteRevision;
3708
3709 Vcb->numFiles = Buf->numFIDSFiles;
3710 Vcb->numDirs = Buf->numFIDSDirectories;
3711
3712 } else {
3713 // unknown (or wrong) VAT format
3714 UDFPrint(("unknown (or wrong) VAT format\n"));
3716 goto err_vat_15;
3717 }
3718 // read VAT & remember old version
3719 Vcb->Vat = (uint32*)DbgAllocatePool(NonPagedPool, (Vcb->LastPossibleLBA+1)*sizeof(uint32) );
3720 if(!Vcb->Vat) {
3721 goto err_vat_15_2;
3722 }
3723 // store base version of VAT in memory
3724 VatOldData = (int8*)DbgAllocatePool(PagedPool, len);
3725 if(!VatOldData) {
3726 DbgFreePool(Vcb->Vat);
3727 Vcb->Vat = NULL;
3728 goto err_vat_15_2;
3729 }
3730 status = UDFReadFile__(Vcb, VatFileInfo, 0, len, FALSE, VatOldData, &ReadBytes);
3731 if(!OS_SUCCESS(status)) {
3732 UDFCloseFile__(Vcb, VatFileInfo);
3733 UDFCleanUpFile__(Vcb, VatFileInfo);
3734 MyFreePool__(VatFileInfo);
3735 DbgFreePool(Vcb->Vat);
3736 DbgFreePool(VatOldData);
3737 Vcb->Vat = NULL;
3738 Vcb->VatFileInfo = NULL;
3739 } else {
3740 // initialize VAT
3741 // !!! NOTE !!!
3742 // Both VAT copies - in-memory & on-disc
3743 // contain _relative_ addresses
3744 len = Vcb->NWA - root;
3745 for(i=0; i<=len; i++) {
3746 Vcb->Vat[i] = i;
3747 }
3748 RtlCopyMemory(Vcb->Vat, VatOldData+Offset, to_read);
3749 Vcb->InitVatCount =
3750 Vcb->VatCount = to_read/sizeof(uint32);
3751 Vcb->VatPartNdx = PartNdx;
3752 Vcb->CDR_Mode = TRUE;
3753 len = Vcb->VatCount;
3754 RtlFillMemory(&(Vcb->Vat[Vcb->NWA-root]), (Vcb->LastPossibleLBA-Vcb->NWA+1)*sizeof(uint32), 0xff);
3755 // sync VAT and FSBM
3756 for(i=0; i<len; i++) {
3757 if(Vcb->Vat[i] == UDF_VAT_FREE_ENTRY) {
3758 UDFSetFreeBit(Vcb->FSBM_Bitmap, root+i);
3759 }
3760 }
3761 len = Vcb->LastPossibleLBA;
3762 // "pre-format" reserved area
3763 for(i=Vcb->NWA; i<len;) {
3764 for(j=0; (j<PACKETSIZE_UDF) && (i<len); j++, i++)
3765 UDFSetFreeBit(Vcb->FSBM_Bitmap, i);
3766 for(j=0; (j<7) && (i<len); j++, i++)
3767 UDFSetUsedBit(Vcb->FSBM_Bitmap, i);
3768 }
3769 DbgFreePool(VatOldData);
3770 }
3771 return status;
3772} // end UDFLoadVAT()
#define PACKETSIZE_UDF
Definition: cdrw_usr.h:1753
#define UDF_FILE_TYPE_VAT15
Definition: osta_misc.h:159
#define UDF_FILE_TYPE_VAT20
Definition: osta_misc.h:171
OSSTATUS UDFOpenRootFile__(IN PVCB Vcb, IN lb_addr *RootLoc, OUT PUDF_FILE_INFO FileInfo)
Definition: udf_info.cpp:2187
#define UDFSetUsedBit(arr, bit)
Definition: udf_info.h:1200
#define MEM_VATFINF_TAG
Definition: udf_rel.h:490
#define STATUS_CRC_ERROR
Definition: udferr_usr.h:153

Referenced by UDFLoadPartDesc().

◆ UDFLocateAnyParallelFI()

PUDF_FILE_INFO UDFLocateAnyParallelFI ( PUDF_FILE_INFO  fi)

Definition at line 1439 of file dirtree.cpp.

1442{
1443 if(!fi->ParentFile) {
1444 if(fi->NextLinkedFile == fi)
1445 return NULL;
1446 return fi->NextLinkedFile;
1447 }
1448 PUDF_FILE_INFO ParFileInfo = fi->NextLinkedFile;
1449 PUDF_DATALOC_INFO Dloc = fi->ParentFile->Dloc;
1450 uint_di i = fi->Index;
1451 BOOLEAN NotFound = TRUE;
1452 while((ParFileInfo != fi) &&
1453 (NotFound =
1454 ((ParFileInfo->Index != i) ||
1455 (ParFileInfo->ParentFile->Dloc != Dloc))) ) {
1456 ParFileInfo = ParFileInfo->NextLinkedFile;
1457 }
1458/* if(NotFound) {
1459 if((ParFileInfo->Index == i) &&
1460 (ParFileInfo->ParentFile->Dloc == Dloc))
1461 return ParFileInfo;
1462 return NULL;
1463 }
1464 return ParFileInfo;*/
1465 return NotFound ? NULL : ParFileInfo;
1466// BrutePoint();
1467} // end UDFLocateAnyParallelFI()

Referenced by UDFCleanUpFile__().

◆ UDFLocateLbaInExtent()

ULONG UDFLocateLbaInExtent ( IN PVCB  Vcb,
IN PEXTENT_MAP  Extent,
IN lba_t  lba 
)

Definition at line 116 of file extent.cpp.

121{
122 uint32 l, BSh = Vcb->BlockSizeBits;
123 uint32 i=0;
124
125 while((l = ((Extent->extLength & UDF_EXTENT_LENGTH_MASK) >> BSh))) {
126
127 if(Extent->extLocation >= lba &&
128 Extent->extLocation+l < lba) {
129 return i;
130 }
131 i++; //frag offset
132 Extent++;
133 }
134 return LBA_OUT_OF_EXTENT;// index of item in extent, containing out Lba
135} // end UDFLocateLbaInExtent()

Referenced by UDFUpdateNonAllocated().

◆ UDFLocateParallelFI()

PUDF_FILE_INFO UDFLocateParallelFI ( PUDF_FILE_INFO  di,
uint_di  i,
PUDF_FILE_INFO  fi 
)

Definition at line 1417 of file dirtree.cpp.

1422{
1423 PUDF_FILE_INFO ParFileInfo = fi->NextLinkedFile;
1424// PUDF_DATALOC_INFO Dloc = di->Dloc;
1425 while((ParFileInfo != fi) &&
1426 ((ParFileInfo->ParentFile != di) ||
1427 (ParFileInfo->Index != i)) ) {
1428 ParFileInfo = ParFileInfo->NextLinkedFile;
1429 }
1430 return ParFileInfo;
1431// BrutePoint();
1432} // end UDFLocateParallelFI()

Referenced by UDFDirIndexScan(), UDFOpenFile__(), and UDFOpenStreamDir__().

◆ UDFLongAllocDescToMapping()

PEXTENT_MAP UDFLongAllocDescToMapping ( IN PVCB  Vcb,
IN PLONG_AD  AllocDesc,
IN uint32  AllocDescLength,
IN uint32  SubCallCount,
OUT PEXTENT_INFO  AllocLoc 
)

Definition at line 457 of file extent.cpp.

464{
465 uint32 i, lim, l, len, type;
466// uint32 BSh;
467 PEXTENT_MAP Extent, Extent2, AllocMap;
468 EXTENT_AD AllocExt;
469 PALLOC_EXT_DESC NextAllocDesc;
471 EXTENT_INFO NextAllocLoc;
472
473 ExtPrint(("UDFLongAllocDescToMapping: len=%x\n", AllocDescLength));
474
475 if(SubCallCount > ALLOC_DESC_MAX_RECURSE) return NULL;
476
477// BSh = Vcb->BlockSizeBits;
478 l = ((lim = (AllocDescLength/sizeof(LONG_AD))) + 1 ) * sizeof(EXTENT_AD);
480 if(!Extent) return NULL;
481
482 NextAllocLoc.Offset = 0;
483
484 for(i=0;i<lim;i++) {
485 type = AllocDesc[i].extLength >> 30;
486 len = AllocDesc[i].extLength & UDF_EXTENT_LENGTH_MASK;
487 ExtPrint(("LnExt: type %x, loc %x (%x:%x), len %x\n", type, UDFPartLbaToPhys(Vcb,&(AllocDesc[i].extLocation)),
488 AllocDesc[i].extLocation.partitionReferenceNum, AllocDesc[i].extLocation.logicalBlockNum,
489 len));
491 // read next frag of allocation descriptors if encountered
492 if(len < sizeof(ALLOC_EXT_DESC)) {
494 return NULL;
495 }
497 if(!NextAllocDesc) {
499 return NULL;
500 }
501 // record information about this frag
502 AllocExt.extLength = len;
503 AllocExt.extLocation = UDFPartLbaToPhys(Vcb,&(AllocDesc[i].extLocation));
504 if(AllocExt.extLocation == LBA_OUT_OF_EXTENT) {
505 UDFPrint(("bad address\n"));
506 MyFreePool__(NextAllocDesc);
508 return NULL;
509 }
510 NextAllocLoc.Mapping =
511 AllocMap = UDFExtentToMapping(&AllocExt);
512 NextAllocLoc.Length = len;
513 if(!AllocMap) {
514 MyFreePool__(NextAllocDesc);
516 return NULL;
517 }
518 AllocLoc->Mapping = UDFMergeMappings(AllocLoc->Mapping, AllocMap);
519 if(!AllocLoc->Mapping ||
520 // read this frag
521 !OS_SUCCESS(UDFReadExtent(Vcb, &NextAllocLoc,
522 0, len, FALSE, (int8*)NextAllocDesc, &ReadBytes)))
523 {
524 MyFreePool__(AllocMap);
525 MyFreePool__(NextAllocDesc);
527 return NULL;
528 }
529 MyFreePool__(AllocMap);
530 // check integrity
531 if((NextAllocDesc->descTag.tagIdent != TID_ALLOC_EXTENT_DESC) ||
532 (NextAllocDesc->lengthAllocDescs > (len - sizeof(ALLOC_EXT_DESC))) ) {
533 UDFPrint(("Integrity check failed\n"));
534 UDFPrint(("NextAllocDesc->descTag.tagIdent = %x\n", NextAllocDesc->descTag.tagIdent));
535 UDFPrint(("NextAllocDesc->lengthAllocDescs = %x\n", NextAllocDesc->lengthAllocDescs));
536 UDFPrint(("len = %x\n", len));
537 MyFreePool__(NextAllocDesc);
539 return NULL;
540 }
541 // perform recursive call to obtain mapping
542 Extent2 = UDFLongAllocDescToMapping(Vcb, (PLONG_AD)(NextAllocDesc+1),
543 NextAllocDesc->lengthAllocDescs, SubCallCount+1, AllocLoc);
544 if(!Extent2) {
545 MyFreePool__(NextAllocDesc);
547 return NULL;
548 }
549 // and merge this 2 mappings into 1
550 Extent[i].extLength = 0;
551 Extent[i].extLocation = 0;
552 Extent = UDFMergeMappings(Extent, Extent2);
553 MyFreePool__(Extent2);
554 return Extent;
555 }
556 //
557 Extent[i].extLength = len;
558#ifdef UDF_CHECK_EXTENT_SIZE_ALIGNMENT
559 ASSERT(!(len & (Vcb->LBlockSize-1) ));
560#endif //UDF_CHECK_EXTENT_SIZE_ALIGNMENT
561 Extent[i].extLength = (len+Vcb->LBlockSize-1) & ~(Vcb->LBlockSize-1);
562 // Note: for compatibility Adaptec DirectCD we check 'len' here
563 // That strange implementation records bogus extLocation in terminal entries
565 Extent[i].extLocation = UDFPartLbaToPhys(Vcb,&(AllocDesc[i].extLocation));
566 if(Extent[i].extLocation == LBA_OUT_OF_EXTENT) {
567 UDFPrint(("bad address (2)\n"));
569 return NULL;
570 }
571 } else {
572 Extent[i].extLocation = 0;
573 }
574 if(!len) {
575 // some UDF implementations set strange AllocDesc sequence length,
576 // but terminates it with zeros in proper place, so handle
577 // this case
578 Extent[i].extLocation = 0;
579 return Extent;
580 }
581 Extent[i].extLength |= (type << 30);
582 }
583 // set terminator
584 Extent[i].extLength = 0;
585 Extent[i].extLocation = 0;
586
587 return Extent;
588} // end UDFLongAllocDescToMapping()
struct _EXTENT_AD EXTENT_AD
PEXTENT_MAP UDFLongAllocDescToMapping(IN PVCB Vcb, IN PLONG_AD AllocDesc, IN uint32 AllocDescLength, IN uint32 SubCallCount, OUT PEXTENT_INFO AllocLoc)
Definition: extent.cpp:457
#define ALLOC_DESC_MAX_RECURSE
Definition: udf_rel.h:120
#define MEM_ALLOCDESC_TAG
Definition: udf_rel.h:493

Referenced by UDFLongAllocDescToMapping(), and UDFReadMappingFromXEntry().

◆ UDFMarkAllocatedAsNotXXX()

OSSTATUS UDFMarkAllocatedAsNotXXX ( IN PVCB  Vcb,
IN int64  Offset,
IN uint32  Length,
IN PEXTENT_INFO  ExtInfo,
IN BOOLEAN  Deallocate 
)

Definition at line 2094 of file extent.cpp.

2101{
2102 uint32 i, len, /*lba, d,*/ l, BOffs, j;
2103 PEXTENT_MAP Extent = ExtInfo->Mapping; // Extent array
2104 PEXTENT_MAP NewExtent;
2105// EXTENT_MAP TmpExtent;
2106// uint32 BS = Vcb->BlockSize;
2107 uint32 BSh = Vcb->BlockSizeBits;
2108// OSSTATUS status;
2109 EXTENT_INFO TmpExtInf;
2110 uint32 aLen, sLen;
2111 uint32 flags;
2112 uint32 target_flags = Deallocate ?
2115 SIZE_T LBS = Vcb->LBlockSize;
2116 EXTENT_MAP DeadMapping[2];
2117 // I don't know what else comment can be added here.
2118 // Just belive that it works
2119 /*lba = */
2120#ifndef ALLOW_SPARSE
2121 if(Deallocate) {
2122 BrutePoint();
2123 }
2124#endif
2125
2126 AdPrint(("Alloc->Not ExtInfo %x, Extent %x\n", ExtInfo, Extent));
2127
2128 DeadMapping[0].extLocation =
2129 UDFExtentOffsetToLba(Vcb, ExtInfo->Mapping, Offset, NULL, NULL, NULL, &i);
2130 if(i == (ULONG)-1) {
2131 BrutePoint();
2133 }
2134 DeadMapping[0].extLength = Extent[i].extLength;
2135 DeadMapping[1].extLocation =
2136 DeadMapping[1].extLength = 0;
2137 TmpExtInf.Mapping = (PEXTENT_MAP)&DeadMapping;
2138 TmpExtInf.Offset = 0;
2139 TmpExtInf.Length = Extent[i].extLength & UDF_EXTENT_LENGTH_MASK;
2140
2141 flags = Extent[i].extLength >> 30;
2142 if(flags == target_flags) return STATUS_SUCCESS;
2143
2144// uint32 PartNum = UDFGetPartNumByPhysLba(Vcb, Extent[0].extLocation);
2145 BOffs = (uint32)(Offset >> BSh);
2146 // length of existing Alloc-(Not-)Rec frag (in sectors)
2147 sLen = (( (((uint32)Offset) & (LBS-1)) + Length+LBS-1) & ~(LBS-1)) >> BSh;
2148 // required deallocation length increment (in bytes)
2149 aLen = (uint32)( ((Offset+Length+LBS-1) & ~(LBS-1)) - (Offset & ~(LBS-1)) );
2150
2151 l=0;
2152 for(j=0; j<i; j++) {
2153 l += (uint32)((Extent[j].extLength & UDF_EXTENT_LENGTH_MASK) >> BSh);
2154 }
2155 flags <<= 30;
2156 if( (l == BOffs) && (((Extent[j].extLength & UDF_EXTENT_LENGTH_MASK) >> BSh) == sLen) ) {
2157 // xxxxxx -> RRRRRR
2158 Extent[i].extLocation = 0;
2159 Extent[i].extLength = (Extent[i].extLength & UDF_EXTENT_LENGTH_MASK) | flags;
2160 NewExtent = Extent;
2161 Extent = NULL;
2162 AdPrint(("Alloc->Not (1) NewExtent = Extent = %x\n", NewExtent));
2163 } else
2164 if(l < BOffs) {
2165 // .ExtLength, BOffs & l are already aligned...
2166 if( (((Extent[i].extLength & UDF_EXTENT_LENGTH_MASK) >> BSh) - (BOffs-l)) > sLen ) {
2167 // xxxxxx -> xxRRxx
2169 if(!NewExtent) {
2171 }
2172 RtlCopyMemory((int8*)NewExtent, (int8*)Extent, i*sizeof(EXTENT_MAP));
2173 RtlCopyMemory((int8*)&(NewExtent[i+3]), (int8*)&(Extent[i+1]), len = UDFGetMappingLength(&(Extent[i+1])) );
2174 NewExtent[i].extLength = (BOffs - l) << BSh;
2175 NewExtent[i].extLength |= flags;
2176 NewExtent[i+1].extLocation = 0;
2177 NewExtent[i+1].extLength = aLen | (target_flags << 30);
2178 NewExtent[i+2].extLength = (Extent[i].extLength & UDF_EXTENT_LENGTH_MASK) -
2179 (NewExtent[i].extLength & UDF_EXTENT_LENGTH_MASK) - aLen ;
2180 NewExtent[i+2].extLocation = Extent[i].extLocation +
2181 (NewExtent[i+2].extLength >> BSh);
2182 NewExtent[i+2].extLength |= flags;
2183 AdPrint(("Alloc->Not (2) new %x\n", NewExtent));
2184 } else {
2185 // xxxxxx -> xxRRRR
2187 if(!NewExtent) {
2189 }
2190 RtlCopyMemory((int8*)NewExtent, (int8*)Extent, i*sizeof(EXTENT_MAP));
2191 RtlCopyMemory((int8*)&(NewExtent[i+2]), (int8*)&(Extent[i+1]), len = UDFGetMappingLength(&(Extent[i+1])) );
2192 NewExtent[i].extLength = ((BOffs - l) << BSh) | flags;
2193 NewExtent[i+1].extLocation = 0;
2194 NewExtent[i+1].extLength = aLen | (target_flags << 30);
2195 AdPrint(("Alloc->Not (3) new %x\n", NewExtent));
2196 }
2197 } else {
2198 // xxxxxx -> RRRRxx
2200 if(!NewExtent) {
2202 }
2203 RtlCopyMemory((int8*)NewExtent, (int8*)Extent, i*sizeof(EXTENT_MAP));
2204 RtlCopyMemory((int8*)&(NewExtent[i+2]), (int8*)&(Extent[i+1]), len = UDFGetMappingLength(&(Extent[i+1])) );
2205 NewExtent[i+1].extLength = (Extent[i].extLength & UDF_EXTENT_LENGTH_MASK) - aLen;
2206 NewExtent[i+1].extLength |= flags;
2207 NewExtent[i].extLocation = 0;
2208 NewExtent[i].extLength = aLen | (target_flags << 30);
2209 AdPrint(("Alloc->Not (4) new %x\n", NewExtent));
2210 }
2211
2212 if(Deallocate)
2213 UDFMarkSpaceAsXXX(Vcb, (-1), TmpExtInf.Mapping, AS_DISCARDED); // mark as free
2214
2215 ExtInfo->Modified = TRUE;
2216 ExtInfo->Mapping = NewExtent;
2217
2218 AdPrint(("Alloc->Not: ExtInfo %x, Extent %x\n", ExtInfo, ExtInfo->Mapping));
2219
2220 if(Extent) {
2221 AdPrint(("Alloc->Not kill %x\n", Extent));
2223 } else {
2224 AdPrint(("Alloc->Not keep %x\n", Extent));
2225 }
2226
2227 return STATUS_SUCCESS;
2228} // end UDFMarkAllocatedAsNotXXX()
uint32 UDFGetMappingLength(IN PEXTENT_MAP Extent)
Definition: extent.cpp:223

◆ UDFMarkAllocatedAsRecorded()

OSSTATUS UDFMarkAllocatedAsRecorded ( IN PVCB  Vcb,
IN int64  Offset,
IN uint32  Length,
IN PEXTENT_INFO  ExtInfo 
)

Definition at line 1814 of file extent.cpp.

1820{
1821 uint32 i, len, lba, sLen;
1822 PEXTENT_MAP Extent = ExtInfo->Mapping; // Extent array
1823 PEXTENT_MAP NewExtent;
1824 uint32 BS = Vcb->BlockSize;
1825 uint32 LBS = Vcb->LBlockSize;
1826 uint32 BSh = Vcb->BlockSizeBits;
1827 BOOLEAN TryPack = TRUE;
1828#ifdef UDF_DBG
1829 int64 check_size;
1830#endif //UDF_DBG
1831 // I don't know what else comment can be added here.
1832 // Just belive that it works
1833 lba = UDFExtentOffsetToLba(Vcb, ExtInfo->Mapping, (Offset & ~((int64)LBS-1)), NULL, NULL, NULL, &i);
1834 if(i == (ULONG)-1) return STATUS_INVALID_PARAMETER;
1835#ifdef UDF_DBG
1836 check_size = UDFGetExtentLength(ExtInfo->Mapping);
1837 ASSERT(!(check_size & (LBS-1)));
1838#endif //UDF_DBG
1839 AdPrint(("Alloc->Rec ExtInfo %x, Extent %x\n", ExtInfo, Extent));
1840 if((Extent[i].extLength >> 30) == EXTENT_RECORDED_ALLOCATED) return STATUS_SUCCESS;
1841 if((Extent[i].extLength >> 30) == EXTENT_NOT_RECORDED_NOT_ALLOCATED) return STATUS_INVALID_PARAMETER;
1842 ASSERT((((uint32)Offset) & (LBS-1)) + Length <= (Extent[i].extLength & UDF_EXTENT_LENGTH_MASK));
1843 sLen = (( (((uint32)Offset) & (LBS-1)) + Length+LBS-1) & ~(LBS-1)) >> BSh;
1844 if((Extent[i].extLocation == lba) && (((Extent[i].extLength & UDF_EXTENT_LENGTH_MASK ) >> BSh) == sLen)) {
1845 // xxxxxx -> RRRRRR
1846 Extent[i].extLength &= UDF_EXTENT_LENGTH_MASK;
1847// Extent[i].extLength |= (EXTENT_RECORDED_ALLOCATED << 30); // = 0;
1848 ExtInfo->Modified = TRUE;
1849 if(i &&
1850 ((Extent[i-1].extLength >> 30) == EXTENT_RECORDED_ALLOCATED) &&
1851 (lba == (Extent[i-1].extLocation + ((len = Extent[i-1].extLength & UDF_EXTENT_LENGTH_MASK) >> BSh))) &&
1852 ((len + (Extent[i].extLength & UDF_EXTENT_LENGTH_MASK)) <= UDF_MAX_EXTENT_LENGTH) &&
1853 (i == ((UDFGetMappingLength(Extent) / sizeof(EXTENT_MAP)) - 2)) &&
1854 TRUE) {
1855 // make optimization for sequentially written files
1856 Extent[i-1].extLength += Extent[i].extLength;
1857 Extent[i].extLocation = 0;
1858 Extent[i].extLength = 0;
1859 } else {
1860 UDFPackMapping(Vcb, ExtInfo);
1861 }
1862 AdPrint(("Alloc->Rec (1) new %x\n", ExtInfo->Mapping));
1863#ifdef UDF_DBG
1864 ASSERT(check_size == UDFGetExtentLength(ExtInfo->Mapping));
1865#endif
1866 AdPrint(("Alloc->Rec: ExtInfo %x, Extent %x\n", ExtInfo, ExtInfo->Mapping));
1867 return STATUS_SUCCESS;
1868 }
1869 if(Extent[i].extLocation < lba) {
1870 if( (((Extent[i].extLength & UDF_EXTENT_LENGTH_MASK) >> BSh) - (lba - Extent[i].extLocation))
1871 > sLen ) {
1872 // xxxxxx -> xxRRxx
1875 if(!NewExtent) return STATUS_INSUFFICIENT_RESOURCES;
1876 Extent[i].extLength &= UDF_EXTENT_LENGTH_MASK;
1877 RtlCopyMemory((int8*)NewExtent, (int8*)Extent, i*sizeof(EXTENT_MAP));
1878 RtlCopyMemory((int8*)&(NewExtent[i+3]), (int8*)&(Extent[i+1]), len = UDFGetMappingLength(&(Extent[i+1])) );
1879 NewExtent[i].extLocation = Extent[i].extLocation;
1880 NewExtent[i].extLength = (lba - Extent[i].extLocation) << BSh;
1881 NewExtent[i+1].extLength = (Length+BS-1) & ~(BS-1);
1882 NewExtent[i+1].extLocation = lba;
1883 NewExtent[i+2].extLength = Extent[i].extLength - NewExtent[i].extLength - NewExtent[i+1].extLength;
1884 NewExtent[i+2].extLocation = lba + ((Length+BS-1) >> BSh);
1885 ASSERT(!(NewExtent[i].extLength >> 30));
1886 ASSERT(!(NewExtent[i+2].extLength >> 30));
1887 NewExtent[i].extLength |= (EXTENT_NOT_RECORDED_ALLOCATED << 30);
1888 NewExtent[i+2].extLength |= (EXTENT_NOT_RECORDED_ALLOCATED << 30);
1889 TryPack = FALSE;
1890 AdPrint(("Alloc->Rec (2) new %x\n", NewExtent));
1891 } else {
1892 // xxxxxx -> xxRRRR
1895 if(!NewExtent) return STATUS_INSUFFICIENT_RESOURCES;
1896 Extent[i].extLength &= UDF_EXTENT_LENGTH_MASK;
1897 RtlCopyMemory((int8*)NewExtent, (int8*)Extent, i*sizeof(EXTENT_MAP));
1898 RtlCopyMemory((int8*)&(NewExtent[i+2]), (int8*)&(Extent[i+1]), len = UDFGetMappingLength(&(Extent[i+1])) );
1899 NewExtent[i].extLocation = Extent[i].extLocation;
1900 NewExtent[i].extLength = (lba - Extent[i].extLocation) << BSh;
1901 NewExtent[i+1].extLength = Extent[i].extLength - NewExtent[i].extLength;
1902 NewExtent[i+1].extLocation = lba;
1903 ASSERT(!(NewExtent[i].extLength >> 30));
1904 NewExtent[i].extLength |= (EXTENT_NOT_RECORDED_ALLOCATED << 30);
1905 AdPrint(("Alloc->Rec (3) new %x\n", NewExtent));
1906 }
1907 } else {
1908 // xxxxxx -> RRRRxx
1911 if(!NewExtent) return STATUS_INSUFFICIENT_RESOURCES;
1912 Extent[i].extLength &= UDF_EXTENT_LENGTH_MASK;
1913 RtlCopyMemory((int8*)NewExtent, (int8*)Extent, i*sizeof(EXTENT_MAP));
1914 RtlCopyMemory((int8*)&(NewExtent[i+2]), (int8*)&(Extent[i+1]), len = UDFGetMappingLength(&(Extent[i+1])) );
1915 NewExtent[i].extLocation = Extent[i].extLocation;
1916 NewExtent[i].extLength = (Length+BS-1) & ~(BS-1);
1917 NewExtent[i+1].extLength = Extent[i].extLength - NewExtent[i].extLength;
1918 NewExtent[i+1].extLocation = Extent[i].extLocation + (NewExtent[i].extLength >> BSh);
1919 ASSERT(!(NewExtent[i+1].extLength >> 30));
1920 NewExtent[i+1].extLength |= (EXTENT_NOT_RECORDED_ALLOCATED << 30);
1921 AdPrint(("Alloc->Rec (4) new %x\n", NewExtent));
1922 }
1923
1924 //ASSERT(check_size == UDFGetExtentLength(Extent));
1925 //ASSERT(!(check_size & (LBS-1)));
1926
1927 AdPrint(("Free Extent %x (new %x)\n", Extent, NewExtent));
1929 ExtInfo->Modified = TRUE;
1930 ExtInfo->Mapping = NewExtent;
1931 if(TryPack)
1932 UDFPackMapping(Vcb, ExtInfo);
1933#ifdef UDF_DBG
1934 ASSERT(check_size == UDFGetExtentLength(ExtInfo->Mapping));
1935 ASSERT(!(check_size & (LBS-1)));
1936#endif
1937
1938 AdPrint(("Alloc->Rec: ExtInfo %x, Extent %x\n", ExtInfo, ExtInfo->Mapping));
1939
1940 return STATUS_SUCCESS;
1941} // end UDFMarkAllocatedAsRecorded()
void __fastcall UDFPackMapping(IN PVCB Vcb, IN PEXTENT_INFO ExtInfo)
Definition: extent.cpp:2747

Referenced by UDFWriteExtent().

◆ UDFMarkNotAllocatedAsAllocated()

OSSTATUS UDFMarkNotAllocatedAsAllocated ( IN PVCB  Vcb,
IN int64  Offset,
IN uint32  Length,
IN PEXTENT_INFO  ExtInfo 
)

Definition at line 1948 of file extent.cpp.

1954{
1955 uint32 i, len, /*lba,*/ d, l, BOffs, j;
1956 PEXTENT_MAP Extent = ExtInfo->Mapping; // Extent array
1957 PEXTENT_MAP NewExtent;
1958// uint32 BS = Vcb->BlockSize;
1959 uint32 BSh = Vcb->BlockSizeBits;
1961 EXTENT_INFO TmpExtInf;
1962 SIZE_T aLen, sLen;
1963 SIZE_T LBS = Vcb->LBlockSize;
1964 // I don't know what else comment can be added here.
1965 // Just belive that it works
1966 /*lba = */
1967#ifndef ALLOW_SPARSE
1968 BrutePoint();
1969#endif
1970 AdPrint(("Not->Alloc ExtInfo %x, Extent %x\n", ExtInfo, Extent));
1971 UDFExtentOffsetToLba(Vcb, ExtInfo->Mapping, Offset, NULL, NULL, NULL, &i);
1972 if(i == (ULONG)-1) return STATUS_INVALID_PARAMETER;
1973 if((Extent[i].extLength >> 30) != EXTENT_NOT_RECORDED_NOT_ALLOCATED) return STATUS_SUCCESS;
1974
1975 uint32 PartNum = UDFGetPartNumByPhysLba(Vcb, Extent[0].extLocation);
1976 BOffs = (uint32)(Offset >> BSh);
1977 // length of existing Not-Alloc-Not-Rec frag
1978 sLen = (( (((uint32)Offset) & (LBS-1)) + Length+LBS-1) & ~(LBS-1)) >> BSh;
1979 // required allocation length increment (in bytes)
1980 aLen = (uint32)( ((Offset+Length+LBS-1) & ~(LBS-1)) - (Offset & ~(LBS-1)));
1981
1982 // try to extend previous frag or allocate space _after_ it to
1983 // avoid backward seeks, if previous frag is not Not-Rec-Not-Alloc
1984 if(i && ((Extent[i-1].extLength >> 30) != EXTENT_NOT_RECORDED_NOT_ALLOCATED) ) {
1986 Extent[i-1].extLocation + ((Extent[i-1].extLength & UDF_EXTENT_LENGTH_MASK) >> BSh),
1987 min(UDFPartEnd(Vcb, PartNum), Extent[i-1].extLocation + ((Extent[i-1].extLength & UDF_EXTENT_LENGTH_MASK) >> BSh) + sLen ),
1988 &TmpExtInf, ExtInfo->Flags /*& EXTENT_FLAG_ALLOC_MASK*/);
1990 // if there are not enough free blocks after that frag...
1991 goto try_alloc_anywhere;
1992 } else {
1993try_alloc_anywhere:
1994 // ... try to alloc required disk space anywhere
1996 UDFPartStart(Vcb, PartNum),
1997 UDFPartEnd(Vcb, PartNum),
1998 &TmpExtInf, ExtInfo->Flags /*& EXTENT_FLAG_ALLOC_MASK*/);
1999 }
2000 // check for successfull allocation
2001 if(!OS_SUCCESS(status)) {
2002 AdPrint(("Not->Alloc no free\n"));
2003 return status;
2004 }
2005 // get number of frags in allocated block
2006 d = (UDFGetMappingLength(TmpExtInf.Mapping) / sizeof(EXTENT_MAP)) - 1;
2007 // calculate number of existing blocks before the frag to be changed
2008 l=0;
2009 for(j=0; j<i; j++) {
2010 l += (uint32)((Extent[j].extLength & UDF_EXTENT_LENGTH_MASK) >> BSh);
2011 }
2012 // and now just update mapping...
2013 if( (l == BOffs) && (((Extent[j].extLength & UDF_EXTENT_LENGTH_MASK) >> BSh) == sLen) ) {
2014 // xxxxxx -> RRRRRR
2015 // (d-1) - since we have to raplace last frag of Extent with 1 or more frags of TmpExtInf.Mapping
2017 if(!NewExtent) {
2018 MyFreePool__(TmpExtInf.Mapping);
2020 }
2021 RtlCopyMemory((int8*)NewExtent, (int8*)Extent, i*sizeof(EXTENT_MAP));
2022 RtlCopyMemory((int8*)&(NewExtent[i]), (int8*)(TmpExtInf.Mapping), d*sizeof(EXTENT_MAP) );
2023 RtlCopyMemory((int8*)&(NewExtent[i+d]), (int8*)&(Extent[i+1]), len = UDFGetMappingLength(&(Extent[i+1])) );
2024 AdPrint(("Not->Alloc (1) new %x\n", NewExtent));
2025 } else
2026 if(l < BOffs) {
2027 // .ExtLength, BOffs & l are already aligned...
2028 if( (((Extent[i].extLength & UDF_EXTENT_LENGTH_MASK) >> BSh) - (BOffs-l)) > sLen ) {
2029 // xxxxxx -> xxRRxx
2031 if(!NewExtent) {
2032 MyFreePool__(TmpExtInf.Mapping);
2034 }
2035 RtlCopyMemory((int8*)NewExtent, (int8*)Extent, i*sizeof(EXTENT_MAP));
2036 RtlCopyMemory((int8*)&(NewExtent[i+1]), (int8*)(TmpExtInf.Mapping), d*sizeof(EXTENT_MAP) );
2037 RtlCopyMemory((int8*)&(NewExtent[i+d+2]), (int8*)&(Extent[i+1]), len = UDFGetMappingLength(&(Extent[i+1])) );
2038 NewExtent[i].extLocation = 0;
2039 NewExtent[i].extLength = (BOffs - l) << BSh;
2040 NewExtent[i+d+1].extLength = Extent[i].extLength - NewExtent[i].extLength - aLen;
2041 NewExtent[i+d+1].extLocation = 0;
2042 NewExtent[i].extLength |= (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30);
2043 NewExtent[i+d+1].extLength |= (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30);
2044 AdPrint(("Not->Alloc (2) new %x\n", NewExtent));
2045 } else {
2046 // xxxxxx -> xxRRRR
2048 if(!NewExtent) {
2049 MyFreePool__(TmpExtInf.Mapping);
2051 }
2052 RtlCopyMemory((int8*)NewExtent, (int8*)Extent, i*sizeof(EXTENT_MAP));
2053 RtlCopyMemory((int8*)&(NewExtent[i+1]), (int8*)(TmpExtInf.Mapping), d*sizeof(EXTENT_MAP) );
2054 RtlCopyMemory((int8*)&(NewExtent[i+d+1]), (int8*)&(Extent[i+1]), len = UDFGetMappingLength(&(Extent[i+1])) );
2055 NewExtent[i].extLocation = 0;
2056 NewExtent[i].extLength = (BOffs - l) << BSh;
2057 NewExtent[i].extLength |= (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30);
2058 AdPrint(("Not->Alloc (3) new %x\n", NewExtent));
2059 }
2060 } else {
2061 // xxxxxx -> RRRRxx
2063 if(!NewExtent) {
2064 MyFreePool__(TmpExtInf.Mapping);
2066 }
2067 RtlCopyMemory((int8*)NewExtent, (int8*)Extent, i*sizeof(EXTENT_MAP));
2068 RtlCopyMemory((int8*)&(NewExtent[i]), (int8*)(TmpExtInf.Mapping), d*sizeof(EXTENT_MAP) );
2069 RtlCopyMemory((int8*)&(NewExtent[i+d+1]), (int8*)&(Extent[i+1]), len = UDFGetMappingLength(&(Extent[i+1])) );
2070 NewExtent[i+d].extLength = (Extent[i].extLength & UDF_EXTENT_LENGTH_MASK) - aLen;
2071 NewExtent[i+d].extLocation = 0;
2072 NewExtent[i+d].extLength |= (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30);
2073 AdPrint(("Not->Alloc (4) new %x\n", NewExtent));
2074 }
2075
2076 AdPrint(("Free Extent %x, TmpExtInf.Mapping, (new %x)\n", Extent, TmpExtInf.Mapping, NewExtent));
2078 MyFreePool__(TmpExtInf.Mapping);
2079 ExtInfo->Modified = TRUE;
2080 ExtInfo->Mapping = NewExtent;
2081
2082 AdPrint(("Not->Alloc: ExtInfo %x, Extent %x\n", ExtInfo, ExtInfo->Mapping));
2083
2084 return STATUS_SUCCESS;
2085} // end UDFMarkNotAllocatedAsAllocated()
struct _EXTENT_AD * PEXTENT_AD

Referenced by UDFWriteExtent().

◆ UDFMarkSpaceAsXXX_()

void UDFMarkSpaceAsXXX_ ( IN PVCB  Vcb,
IN PEXTENT_MAP  Map,
IN uint32  asXXX 
)

Definition at line 928 of file alloc.cpp.

938{
939 if(!Map) return;
940 if(!Map[0].extLength) {
941#ifdef UDF_DBG
942 ASSERT(!Map[0].extLocation);
943#endif // UDF_DBG
944 return;
945 }
946
947 UDFAcquireResourceExclusive(&(Vcb->BitMapResource1),TRUE);
948#ifdef UDF_TRACK_ONDISK_ALLOCATION
949 UDFMarkSpaceAsXXXNoProtect_(Vcb, Map, asXXX, FE_lba, BugCheckId, Line);
950#else //UDF_TRACK_ONDISK_ALLOCATION
951 UDFMarkSpaceAsXXXNoProtect_(Vcb, Map, asXXX);
952#endif //UDF_TRACK_ONDISK_ALLOCATION
953 UDFReleaseResource(&(Vcb->BitMapResource1));
954
955} // end UDFMarkSpaceAsXXX_()
void UDFMarkSpaceAsXXXNoProtect_(IN PVCB Vcb, IN PEXTENT_MAP Map, IN uint32 asXXX)
Definition: alloc.cpp:782
Definition: ncftp.h:79

◆ UDFMarkSpaceAsXXXNoProtect_()

void UDFMarkSpaceAsXXXNoProtect_ ( IN PVCB  Vcb,
IN PEXTENT_MAP  Map,
IN uint32  asXXX 
)

Definition at line 782 of file alloc.cpp.

792{
793 uint32 i=0;
794 uint32 lba, j, len, BS, BSh;
795 uint32 root;
796 BOOLEAN asUsed = (asXXX == AS_USED || (asXXX & AS_BAD));
797#ifdef UDF_TRACK_ONDISK_ALLOCATION
798 BOOLEAN bit_before, bit_after;
799#endif //UDF_TRACK_ONDISK_ALLOCATION
800
802
803 if(!Map) return;
804
805 BS = Vcb->BlockSize;
806 BSh = Vcb->BlockSizeBits;
807 Vcb->BitmapModified = TRUE;
809 // walk through all frags in data area specified
810 while(Map[i].extLength & UDF_EXTENT_LENGTH_MASK) {
811 if((Map[i].extLength >> 30) == EXTENT_NOT_RECORDED_NOT_ALLOCATED) {
812 // skip unallocated frags
813 i++;
814 continue;
815 }
816 ASSERT(Map[i].extLocation);
817
818#ifdef UDF_TRACK_ONDISK_ALLOCATION
819 AdPrint(("Alloc:%x:%s:%x:@:%x:File:%x:Line:%d\n",
820 FE_lba,
821 asUsed ? ((asXXX & AS_BAD) ? "B" : "U") : "F",
822 (Map[i].extLength & UDF_EXTENT_LENGTH_MASK) >> Vcb->BlockSizeBits,
823 Map[i].extLocation,
824 BugCheckId,
825 Line
826 ));
827#endif //UDF_TRACK_ONDISK_ALLOCATION
828
829#ifdef UDF_DBG
830#ifdef UDF_CHECK_EXTENT_SIZE_ALIGNMENT
831 ASSERT(!(Map[i].extLength & (BS-1)));
832#endif //UDF_CHECK_EXTENT_SIZE_ALIGNMENT
833// len = ((Map[i].extLength & UDF_EXTENT_LENGTH_MASK)+BS-1) >> BSh;
834#else // UDF_DBG
835// len = (Map[i].extLength & UDF_EXTENT_LENGTH_MASK) >> BSh;
836#endif // UDF_DBG
837 len = ((Map[i].extLength & UDF_EXTENT_LENGTH_MASK)+BS-1) >> BSh;
838 lba = Map[i].extLocation;
839 if((lba+len) > Vcb->LastPossibleLBA) {
840 // skip blocks beyond media boundary
841 if(lba > Vcb->LastPossibleLBA) {
842 ASSERT(FALSE);
843 i++;
844 continue;
845 }
846 len = Vcb->LastPossibleLBA - lba;
847 }
848
849#ifdef UDF_TRACK_ONDISK_ALLOCATION
850 if(lba)
851 bit_before = UDFGetBit(Vcb->FSBM_Bitmap, lba-1);
852 bit_after = UDFGetBit(Vcb->FSBM_Bitmap, lba+len);
853#endif //UDF_TRACK_ONDISK_ALLOCATION
854
855 // mark frag as XXX (see asUsed parameter)
856 if(asUsed) {
857/* for(j=0;j<len;j++) {
858 UDFSetUsedBit(Vcb->FSBM_Bitmap, lba+j);
859 }*/
860 ASSERT(len);
861 UDFSetUsedBits(Vcb->FSBM_Bitmap, lba, len);
862#ifdef UDF_TRACK_ONDISK_ALLOCATION
863 for(j=0;j<len;j++) {
864 ASSERT(UDFGetUsedBit(Vcb->FSBM_Bitmap, lba+j));
865 }
866#endif //UDF_TRACK_ONDISK_ALLOCATION
867
868 if(Vcb->Vat) {
869 // mark logical blocks in VAT as used
870 for(j=0;j<len;j++) {
872 if((Vcb->Vat[lba-root+j] == UDF_VAT_FREE_ENTRY) &&
873 (lba > Vcb->LastLBA)) {
874 Vcb->Vat[lba-root+j] = 0x7fffffff;
875 }
876 }
877 }
878 } else {
879/* for(j=0;j<len;j++) {
880 UDFSetFreeBit(Vcb->FSBM_Bitmap, lba+j);
881 }*/
882 ASSERT(len);
883 UDFSetFreeBits(Vcb->FSBM_Bitmap, lba, len);
884#ifdef UDF_TRACK_ONDISK_ALLOCATION
885 for(j=0;j<len;j++) {
886 ASSERT(UDFGetFreeBit(Vcb->FSBM_Bitmap, lba+j));
887 }
888#endif //UDF_TRACK_ONDISK_ALLOCATION
889 if(asXXX & AS_BAD) {
890 UDFSetBits(Vcb->BSBM_Bitmap, lba, len);
891 }
893
894 if(asXXX & AS_DISCARDED) {
896 WCacheDiscardBlocks__(&(Vcb->FastCache), Vcb, lba, len);
897 UDFSetZeroBits(Vcb->ZSBM_Bitmap, lba, len);
898 }
899 if(Vcb->Vat) {
900 // mark logical blocks in VAT as free
901 // this operation can decrease resulting VAT size
902 for(j=0;j<len;j++) {
905 }
906 }
907 // mark discarded extent as Not-Alloc-Not-Rec to
908 // prevent writes there
909 Map[i].extLength = (len << BSh) | (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30);
910 Map[i].extLocation = 0;
911 }
912
913#ifdef UDF_TRACK_ONDISK_ALLOCATION
914 if(lba)
915 ASSERT(bit_before == UDFGetBit(Vcb->FSBM_Bitmap, lba-1));
916 ASSERT(bit_after == UDFGetBit(Vcb->FSBM_Bitmap, lba+len));
917#endif //UDF_TRACK_ONDISK_ALLOCATION
918
919 i++;
920 }
921} // end UDFMarkSpaceAsXXXNoProtect_()
VOID UDFSetModified(IN PVCB Vcb)
Definition: misc_common.cpp:9
OSSTATUS __fastcall UDFUnmapRange(IN PVCB Vcb, IN uint32 Lba, IN uint32 BCount)
Definition: remap.cpp:894
#define UDFSetBits(arr, bit, bc)
Definition: udf_info.h:1184
#define UDFSetFreeBits(arr, bit, bc)
Definition: udf_info.h:1203
#define UDFSetUsedBits(arr, bit, bc)
Definition: udf_info.h:1202
VOID WCacheDiscardBlocks__(IN PW_CACHE Cache, IN PVOID Context, IN lba_t ReqLba, IN ULONG BCount)

Referenced by UDFMarkSpaceAsXXX_().

◆ UDFMemRealloc()

uint32 UDFMemRealloc ( IN int8 OldBuff,
IN uint32  OldLength,
OUT int8 **  NewBuff,
IN uint32  NewLength 
)

◆ UDFMergeMappings()

PEXTENT_MAP __fastcall UDFMergeMappings ( IN PEXTENT_MAP  Extent,
IN PEXTENT_MAP  Extent2 
)

Definition at line 266 of file extent.cpp.

270{
271 PEXTENT_MAP NewExt;
272 uint32 len, len2;
273
275 len2 = UDFGetMappingLength(Extent2);
276 ASSERT(len2 && len);
277 if(!len2) {
278 return Extent;
279 }
280 if(MyReallocPool__((int8*)Extent, len, (int8**)(&NewExt), len+len2-sizeof(EXTENT_MAP))) {
281 RtlCopyMemory(((int8*)NewExt)+len-sizeof(EXTENT_MAP), (int8*)Extent2, len2);
282 } else {
283 ExtPrint(("UDFMergeMappings failed\n"));
284 BrutePoint();
285 }
286 return NewExt;
287} // end UDFMergeMappings()

Referenced by UDFAllocFreeExtent_(), UDFBuildFreeSpaceBitmap(), UDFExtAllocDescToMapping(), UDFLongAllocDescToMapping(), UDFRelocateSectors(), UDFResizeExtent(), UDFShortAllocDescToMapping(), UDFUpdateNonAllocated(), and UDFVerifyFreeSpaceBitmap().

◆ UDFModifyVAT()

OSSTATUS UDFModifyVAT ( IN PVCB  Vcb,
IN uint32  Lba,
IN uint32  Length 
)

◆ UDFOpenFile__()

OSSTATUS UDFOpenFile__ ( IN PVCB  Vcb,
IN BOOLEAN  IgnoreCase,
IN BOOLEAN  NotDeleted,
IN PUNICODE_STRING  fn,
IN PUDF_FILE_INFO  DirInfo,
OUT PUDF_FILE_INFO _FileInfo,
IN uint_di IndexToOpen 
)

Definition at line 2004 of file udf_info.cpp.

2014{
2016 uint_di i=0;
2017 EXTENT_AD FEExt;
2018 uint16 Ident;
2019 PDIR_INDEX_HDR hDirNdx = DirInfo->Dloc->DirIndex;
2020 PDIR_INDEX_ITEM DirNdx;
2022 PUDF_FILE_INFO ParFileInfo;
2024 *_FileInfo = NULL;
2025 if(!hDirNdx) return STATUS_NOT_A_DIRECTORY;
2026
2027 // find specified file in directory index
2028 // if it is already known, skip this foolish code
2029 if(IndexToOpen) {
2030 i=*IndexToOpen;
2031 } else
2032 if(!OS_SUCCESS(status = UDFFindFile(Vcb, IgnoreCase, NotDeleted, fn, DirInfo, &i)))
2033 return status;
2034 // do this check for OpenByIndex
2035 // some routines may send invalid Index
2036 if(!(DirNdx = UDFDirIndex(hDirNdx,i)))
2038 if((FileInfo = DirNdx->FileInfo)) {
2039 // file is already opened.
2040 if((DirNdx->FileCharacteristics & FILE_DELETED) && NotDeleted) {
2041 AdPrint((" FILE_DELETED on open\n"));
2042 return STATUS_FILE_DELETED;
2043 }
2044 if((FileInfo->ParentFile != DirInfo) &&
2045 (FileInfo->Index >= 2)) {
2046 ParFileInfo = UDFLocateParallelFI(DirInfo, i, FileInfo);
2047 BrutePoint();
2048 if(ParFileInfo->ParentFile != DirInfo) {
2050 *_FileInfo = FileInfo;
2052 RtlCopyMemory(FileInfo, DirNdx->FileInfo, sizeof(UDF_FILE_INFO));
2053 // FileInfo->NextLinkedFile = DirNdx->FileInfo->NextLinkedFile; // is already done
2055 DirNdx->FI_Flags |= UDF_FI_FLAG_LINKED;
2056 FileInfo->RefCount = 0;
2057 FileInfo->ParentFile = DirInfo;
2058 FileInfo->Fcb = NULL;
2059 } else {
2060 FileInfo = ParFileInfo;
2061 }
2062 }
2063 // Just increase some counters & exit
2065
2066 ASSERT(FileInfo->ParentFile == DirInfo);
2068
2069 *_FileInfo = FileInfo;
2070 return STATUS_SUCCESS;
2071 } else
2072 if(IndexToOpen) {
2073 if((DirNdx->FileCharacteristics & FILE_DELETED) && NotDeleted) {
2074 AdPrint((" FILE_DELETED on open (2)\n"));
2075 return STATUS_FILE_DELETED;
2076 }
2077 }
2079 *_FileInfo = FileInfo;
2082 // init horizontal links
2083 FileInfo->NextLinkedFile =
2084 FileInfo->PrevLinkedFile = FileInfo;
2085 // read FileIdent
2087 if(!(FileInfo->FileIdent)) return STATUS_INSUFFICIENT_RESOURCES;
2088 FileInfo->FileIdentLen = DirNdx->Length;
2089 if(!OS_SUCCESS(status = UDFReadExtent(Vcb, &(DirInfo->Dloc->DataLoc), DirNdx->Offset,
2090 DirNdx->Length, FALSE, (int8*)(FileInfo->FileIdent), &ReadBytes) ))
2091 return status;
2092 if(FileInfo->FileIdent->descTag.tagIdent != TID_FILE_IDENT_DESC) {
2093 BrutePoint();
2095 }
2096 // check for opened links
2097 if(!OS_SUCCESS(status = UDFStoreDloc(Vcb, FileInfo, UDFPartLbaToPhys(Vcb, &(FileInfo->FileIdent->icb.extLocation)))))
2098 return status;
2099 // init pointer to parent object
2100 FileInfo->Index = i;
2101 FileInfo->ParentFile = DirInfo;
2102 // init pointers to linked files (if any)
2103 if(FileInfo->Dloc->LinkedFileInfo != FileInfo)
2104 UDFInsertLinkedFile(FileInfo, FileInfo->Dloc->LinkedFileInfo);
2105 if(FileInfo->Dloc->FileEntry)
2106 goto init_tree_entry;
2107 // read (Ex)FileEntry
2108 FileInfo->Dloc->FileEntry = (tag*)MyAllocatePoolTag__(NonPagedPool, Vcb->LBlockSize, MEM_FE_TAG);
2109 if(!(FileInfo->Dloc->FileEntry)) return STATUS_INSUFFICIENT_RESOURCES;
2110 if(!OS_SUCCESS(status = UDFReadFileEntry(Vcb, &(FileInfo->FileIdent->icb), (PFILE_ENTRY)(FileInfo->Dloc->FileEntry), &Ident)))
2111 return status;
2112 // build mappings for Data & AllocDescs
2113 if(!FileInfo->Dloc->AllocLoc.Mapping) {
2114 FEExt.extLength = FileInfo->FileIdent->icb.extLength;
2115 FEExt.extLocation = UDFPartLbaToPhys(Vcb, &(FileInfo->FileIdent->icb.extLocation) );
2116 if(FEExt.extLocation == LBA_OUT_OF_EXTENT)
2118 FileInfo->Dloc->AllocLoc.Mapping = UDFExtentToMapping(&FEExt);
2119 if(!(FileInfo->Dloc->AllocLoc.Mapping))
2121 }
2122 // read location info
2123 status = UDFLoadExtInfo(Vcb, (PFILE_ENTRY)(FileInfo->Dloc->FileEntry), &(FileInfo->FileIdent->icb),
2124 &(FileInfo->Dloc->DataLoc), &(FileInfo->Dloc->AllocLoc) );
2125 if(!OS_SUCCESS(status))
2126 return status;
2127 // init (Ex)FileEntry mapping
2128 FileInfo->Dloc->FELoc.Length = (FileInfo->Dloc->DataLoc.Offset) ? FileInfo->Dloc->DataLoc.Offset :
2129 FileInfo->Dloc->AllocLoc.Offset;
2130// FileInfo->Dloc->FELoc.Offset = 0;
2131 FileInfo->Dloc->FELoc.Mapping = UDFExtentToMapping(&FEExt);
2132 FileInfo->Dloc->FileEntryLen = (uint32)(FileInfo->Dloc->FELoc.Length);
2133 // we get here immediately when opened link encountered
2134init_tree_entry:
2135 // init back pointer from parent object
2136 ASSERT(!DirNdx->FileInfo);
2137 DirNdx->FileInfo = FileInfo;
2138 // init DirIndex
2139 if(UDFGetFileLinkCount(FileInfo) > 1) {
2140 DirNdx->FI_Flags |= UDF_FI_FLAG_LINKED;
2141 } else {
2142 DirNdx->FI_Flags &= ~UDF_FI_FLAG_LINKED;
2143 }
2144 // resize FE cache (0x800 instead of 0x40 is not a good idea)
2145 if(!MyReallocPool__((int8*)((FileInfo->Dloc->FileEntry)), Vcb->LBlockSize,
2146 (int8**)&((FileInfo->Dloc->FileEntry)), FileInfo->Dloc->FileEntryLen))
2148 // check if this file has a SDir
2149 if((FileInfo->Dloc->FileEntry->tagIdent == TID_EXTENDED_FILE_ENTRY) &&
2150 ((PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry))->streamDirectoryICB.extLength )
2151 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_HAS_SDIR;
2152 if(!(FileInfo->FileIdent->fileCharacteristics & FILE_DIRECTORY)) {
2154 ASSERT(FileInfo->ParentFile == DirInfo);
2155 UDFReleaseDloc(Vcb, FileInfo->Dloc);
2156 return STATUS_SUCCESS;
2157 }
2158
2159 UDFCheckSpaceAllocation(Vcb, 0, FileInfo->Dloc->DataLoc.Mapping, AS_USED); // check if used
2160
2161 // build index for directories
2162 if(!FileInfo->Dloc->DirIndex) {
2164 if(!OS_SUCCESS(status))
2165 return status;
2166#ifndef UDF_READ_ONLY_BUILD
2167 if((FileInfo->Dloc->DirIndex->DelCount > Vcb->PackDirThreshold) &&
2168 !(Vcb->VCBFlags & UDF_VCB_FLAGS_VOLUME_READ_ONLY)) {
2170 if(!OS_SUCCESS(status))
2171 return status;
2172 }
2173#endif //UDF_READ_ONLY_BUILD
2174 }
2176 UDFReleaseDloc(Vcb, FileInfo->Dloc);
2177 ASSERT(FileInfo->ParentFile == DirInfo);
2178
2179 return status;
2180} // end UDFOpenFile__()
OSSTATUS UDFPackDirectory__(IN PVCB Vcb, IN OUT PUDF_FILE_INFO FileInfo)
Definition: dirtree.cpp:743
OSSTATUS UDFReadFileEntry(IN PVCB Vcb, IN long_ad *Icb, IN OUT PFILE_ENTRY FileEntry, IN OUT uint16 *Ident)
Definition: udf_info.cpp:306
OSSTATUS UDFLoadExtInfo(IN PVCB Vcb, IN PFILE_ENTRY fe, IN PLONG_AD fe_loc, IN OUT PEXTENT_INFO FExtInfo, IN OUT PEXTENT_INFO AExtInfo)
Definition: udf_info.cpp:1062

Referenced by UDFCommonCreate(), UDFCompleteMount(), UDFCreateFile__(), UDFHardLinkFile__(), UDFMarkStreamsForDeletion(), UDFReadSecurity(), UDFRenameMoveFile__(), UDFUnlinkAllFilesInDir(), and UDFWriteSecurity().

◆ UDFOpenRootFile__()

OSSTATUS UDFOpenRootFile__ ( IN PVCB  Vcb,
IN lb_addr RootLoc,
OUT PUDF_FILE_INFO  FileInfo 
)

Definition at line 2187 of file udf_info.cpp.

2192{
2193 uint32 RootLBA;
2195// uint32 PartNum = RootLoc->partitionReferenceNum;
2196 uint32 LBS = Vcb->LBlockSize;
2197 uint16 Ident;
2198 LONG_AD FELoc;
2199 EXTENT_AD FEExt;
2201
2203 RootLBA = UDFPartLbaToPhys(Vcb,RootLoc);
2204 if(RootLBA == LBA_OUT_OF_EXTENT)
2206 FELoc.extLocation = *RootLoc;
2207 FELoc.extLength = LBS;
2208 // init horizontal links
2209 FileInfo->NextLinkedFile =
2210 FileInfo->PrevLinkedFile = FileInfo;
2211 // check for opened links
2212 if(!OS_SUCCESS(status = UDFStoreDloc(Vcb, FileInfo, RootLBA)))
2213 return status;
2214 if(FileInfo->Dloc->FileEntry)
2215 goto init_tree_entry;
2216 // read (Ex)FileEntry
2217 FileInfo->Dloc->FileEntry = (tag*)MyAllocatePoolTag__(NonPagedPool, LBS, MEM_FE_TAG);
2218 if(!(FileInfo->Dloc->FileEntry)) return STATUS_INSUFFICIENT_RESOURCES;
2219
2220 if(!OS_SUCCESS(status = UDFReadFileEntry(Vcb, &FELoc, (PFILE_ENTRY)(FileInfo->Dloc->FileEntry), &Ident)))
2221 return status;
2222 // build mappings for Data & AllocDescs
2223 FEExt.extLength = LBS;
2224 FEExt.extLocation = UDFPartLbaToPhys(Vcb, &(FELoc.extLocation) );
2225 if(FEExt.extLocation == LBA_OUT_OF_EXTENT)
2227 FileInfo->Dloc->FELoc.Mapping = UDFExtentToMapping(&FEExt);
2228 if(!(FileInfo->Dloc->FELoc.Mapping)) return STATUS_INSUFFICIENT_RESOURCES;
2229 // build mappings for AllocDescs
2230 if(!FileInfo->Dloc->AllocLoc.Mapping) {
2231 FileInfo->Dloc->AllocLoc.Mapping = UDFExtentToMapping(&FEExt);
2232 if(!(FileInfo->Dloc->AllocLoc.Mapping)) return STATUS_INSUFFICIENT_RESOURCES;
2233 }
2234 if(!OS_SUCCESS(status = UDFLoadExtInfo(Vcb, (PFILE_ENTRY)(FileInfo->Dloc->FileEntry), &FELoc,
2235 &(FileInfo->Dloc->DataLoc), &(FileInfo->Dloc->AllocLoc) ) ))
2236 return status;
2237 FileInfo->Dloc->FileEntryLen = (uint32)
2238 (FileInfo->Dloc->FELoc.Length = (FileInfo->Dloc->DataLoc.Offset) ? FileInfo->Dloc->DataLoc.Offset :
2239 FileInfo->Dloc->AllocLoc.Offset);
2240init_tree_entry:
2241 // resize FE cache (0x800 instead of 0x40 is not a good idea)
2242 if(!MyReallocPool__((int8*)((FileInfo->Dloc->FileEntry)), LBS,
2243 (int8**)&((FileInfo->Dloc->FileEntry)), FileInfo->Dloc->FileEntryLen))
2245 // init DirIndex
2246 if( (FileType = ((icbtag*)((FileInfo->Dloc->FileEntry)+1))->fileType) != UDF_FILE_TYPE_DIRECTORY &&
2249 UDFReleaseDloc(Vcb, FileInfo->Dloc);
2250 return STATUS_SUCCESS;
2251 }
2252 // build index for directories
2253 if(!FileInfo->Dloc->DirIndex) {
2255 if(!OS_SUCCESS(status))
2256 return status;
2257#ifndef UDF_READ_ONLY_BUILD
2258 if((FileInfo->Dloc->DirIndex->DelCount > Vcb->PackDirThreshold) &&
2259 !(Vcb->VCBFlags & UDF_VCB_FLAGS_VOLUME_READ_ONLY)) {
2261 if(!OS_SUCCESS(status))
2262 return status;
2263 }
2264#endif //UDF_READ_ONLY_BUILD
2265 }
2267 UDFReleaseDloc(Vcb, FileInfo->Dloc);
2268
2269 return status;
2270} // end UDFOpenRootFile__()
#define UDF_FILE_TYPE_DIRECTORY
Definition: ecma_167.h:468
_In_ WDFDEVICE _In_ WDF_SPECIAL_FILE_TYPE FileType
Definition: wdfdevice.h:2741

Referenced by UDFCompareVcb(), UDFCompleteMount(), UDFLoadVAT(), and UDFOpenStreamDir__().

◆ UDFOpenStreamDir__()

OSSTATUS UDFOpenStreamDir__ ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo,
OUT PUDF_FILE_INFO _SDirInfo 
)

Definition at line 4965 of file udf_info.cpp.

4971{
4973 PUDF_FILE_INFO SDirInfo;
4974 PUDF_FILE_INFO ParSDirInfo;
4975 uint16 Ident;
4976
4977 *_SDirInfo = NULL;
4979 // check if this file has ExtendedFileEntry
4980 if((Ident = FileInfo->Dloc->FileEntry->tagIdent) != TID_EXTENDED_FILE_ENTRY) {
4981 return STATUS_NOT_FOUND;
4982 }
4983 if((SDirInfo = FileInfo->Dloc->SDirInfo)) {
4984 // it is already opened. Good...
4985
4986 // check if we have Deleted SDir
4987 if(FileInfo->Dloc->SDirInfo &&
4988 UDFIsSDirDeleted(FileInfo->Dloc->SDirInfo))
4989 return STATUS_FILE_DELETED;
4990 // All right. Look for parallel SDir (if any)
4991 if(SDirInfo->ParentFile != FileInfo) {
4992 ParSDirInfo = UDFLocateParallelFI(FileInfo, 0, SDirInfo);
4993 BrutePoint();
4994 if(ParSDirInfo->ParentFile != FileInfo) {
4996 *_SDirInfo = SDirInfo;
4997 if(!SDirInfo) return STATUS_INSUFFICIENT_RESOURCES;
4998 RtlCopyMemory(SDirInfo, FileInfo->Dloc->SDirInfo, sizeof(UDF_FILE_INFO));
4999 // SDirInfo->NextLinkedFile = FileInfo->Dloc->SDirInfo->NextLinkedFile; // is already done
5000 UDFInsertLinkedFile(SDirInfo, FileInfo->Dloc->SDirInfo);
5001 SDirInfo->RefCount = 0;
5002 SDirInfo->ParentFile = FileInfo;
5003 SDirInfo->Fcb = NULL;
5004 } else {
5005 SDirInfo = ParSDirInfo;
5006 }
5007 }
5008 UDFReferenceFile__(SDirInfo);
5009 *_SDirInfo = SDirInfo;
5010 return STATUS_SUCCESS;
5011 }
5012 // normal open
5013 if(!((PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry))->streamDirectoryICB.extLength)
5014 return STATUS_NOT_FOUND;
5016 if(!SDirInfo) return STATUS_INSUFFICIENT_RESOURCES;
5017 *_SDirInfo = SDirInfo;
5018 status = UDFOpenRootFile__(Vcb, &(((PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry))->streamDirectoryICB.extLocation) ,SDirInfo);
5019 if(!OS_SUCCESS(status)) return status;
5020 // open & finalize linkage
5021 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_HAS_SDIR;
5022 SDirInfo->Dloc->FE_Flags |= UDF_FE_FLAG_IS_SDIR;
5023 FileInfo->Dloc->SDirInfo = SDirInfo;
5024 SDirInfo->ParentFile = FileInfo;
5025
5026 UDFInterlockedIncrement((PLONG)&(FileInfo->OpenCount));
5027
5028 return STATUS_SUCCESS;
5029} // end UDFOpenStreamDir__()
#define STATUS_NOT_FOUND
Definition: shellext.h:72
struct _UDFFileControlBlock * Fcb
Definition: udf_rel.h:362
uint32 RefCount
Definition: udf_rel.h:399
#define MEM_SDFINF_TAG
Definition: udf_rel.h:491

Referenced by UDFCommonCreate(), UDFMarkStreamsForDeletion(), UDFReadSecurity(), UDFUnlinkFile__(), and UDFWriteSecurity().

◆ UDFPackDirectory__()

OSSTATUS UDFPackDirectory__ ( IN PVCB  Vcb,
IN OUT PUDF_FILE_INFO  FileInfo 
)

Definition at line 743 of file dirtree.cpp.

747{
748#ifdef UDF_PACK_DIRS
749 uint32 d, LBS;
750 uint_di i, j;
751 uint32 IUl, FIl, l;
752 uint32 DataLocOffset;
753 uint32 Offset, curOffset;
754 int8* Buf;
757 int8* storedFI;
758 PUDF_FILE_INFO curFileInfo;
759 PDIR_INDEX_ITEM DirNdx, DirNdx2;
760 UDF_DIR_SCAN_CONTEXT ScanContext;
761 uint_di dc=0;
762 uint16 PartNum;
763#endif //UDF_PACK_DIRS
764
766 PDIR_INDEX_HDR hDirNdx = FileInfo->Dloc->DirIndex;
767 if(!hDirNdx) return STATUS_NOT_A_DIRECTORY;
768#ifndef UDF_PACK_DIRS
769 return STATUS_SUCCESS;
770#else // UDF_PACK_DIRS
771
772 // do not pack dirs on unchanged disks
773 if(!Vcb->Modified)
774 return STATUS_SUCCESS;
775 // start packing
776 LBS = Vcb->LBlockSize;
777 Buf = (int8*)DbgAllocatePool(PagedPool, LBS*2);
778 if(!Buf) return STATUS_INSUFFICIENT_RESOURCES;
779 // we shall never touch 1st entry 'cause it can't be deleted
780 Offset = UDFDirIndex(hDirNdx,2)->Offset;
781 DataLocOffset = FileInfo->Dloc->DataLoc.Offset;
782
783 i=j=2;
784
785 if(!UDFDirIndexInitScan(FileInfo, &ScanContext, i)) {
786 DbgFreePool(Buf);
787 return STATUS_SUCCESS;
788 }
789
790 ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation);
791 PartNum = (uint16)UDFGetPartNumByPhysLba(Vcb, FileInfo->Dloc->FELoc.Mapping[0].extLocation);
792 ASSERT(PartNum != -1);
793
794 while((DirNdx = UDFDirIndexScan(&ScanContext, NULL))) {
795
796 if(UDFIsDeleted(DirNdx))
797 dc++;
798
799 if(!UDFIsDeleted(DirNdx) ||
800 DirNdx->FileInfo) {
801 // move down valid entry
802 status = UDFReadFile__(Vcb, FileInfo, curOffset = DirNdx->Offset,
803 l = DirNdx->Length, FALSE, Buf, &ReadBytes);
804 if(!OS_SUCCESS(status)) {
805 DbgFreePool(Buf);
806 return status;
807 }
808 // remove ImpUse field
809 IUl = ((PFILE_IDENT_DESC)Buf)->lengthOfImpUse;
810 curFileInfo = DirNdx->FileInfo;
811 // align next entry
812 if((d = LBS - ((curOffset + (l - IUl) + DataLocOffset) & (LBS-1)) ) < sizeof(FILE_IDENT_DESC)) {
813
814 // insufficient space at the end of last sector for
815 // next FileIdent's tag. fill it with ImpUse data
816
817 // generally, all data should be DWORD-aligned, but if it is not so
818 // this opearation will help us to avoid glitches
819 d = (d+3) & ~(3);
820 if(d != IUl) {
821 l = l + d - IUl;
822 FIl = ((PFILE_IDENT_DESC)Buf)->lengthFileIdent;
823 // copy filename to upper addr
824 RtlMoveMemory(Buf+sizeof(FILE_IDENT_DESC)+d,
825 Buf+sizeof(FILE_IDENT_DESC)+IUl, FIl);
826 RtlZeroMemory(Buf+sizeof(FILE_IDENT_DESC), d);
827 ((PFILE_IDENT_DESC)Buf)->lengthOfImpUse = (uint16)d;
828
829 if(curFileInfo && curFileInfo->FileIdent) {
830 // update stored FI if any
831 if(!MyReallocPool__((int8*)(curFileInfo->FileIdent), l,
832 (int8**)&(curFileInfo->FileIdent), (l+IUl-d) )) {
833 DbgFreePool(Buf);
835 }
836 storedFI = (int8*)(curFileInfo->FileIdent);
837 RtlMoveMemory(storedFI+sizeof(FILE_IDENT_DESC)+d,
838 storedFI+sizeof(FILE_IDENT_DESC)+IUl, FIl);
839 RtlZeroMemory(storedFI+sizeof(FILE_IDENT_DESC), d);
840 ((PFILE_IDENT_DESC)storedFI)->lengthOfImpUse = (uint16)d;
841 FileInfo->Dloc->FELoc.Modified = TRUE;
842 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_FE_MODIFIED;
843 }
844 }
845 } else {
846 d = 0;
847 }
848 // write modified to new addr
849 if((d != IUl) ||
850 (curOffset != Offset)) {
851
852 UDFSetUpTag(Vcb, (tag*)Buf, (uint16)l,
853 UDFPhysLbaToPart(Vcb, PartNum,
854 UDFExtentOffsetToLba(Vcb, FileInfo->Dloc->DataLoc.Mapping,
855 Offset, NULL, NULL, NULL, NULL)));
856
858 if(!OS_SUCCESS(status)) {
859 DbgFreePool(Buf);
860 return status;
861 }
862 }
863 DirNdx2 = UDFDirIndex(hDirNdx, j);
864 *DirNdx2 = *DirNdx;
865 DirNdx2->Offset = Offset;
866 DirNdx2->Length = l;
867 if(curFileInfo) {
868 curFileInfo->Index = j;
870 }
871 Offset += l;
872 j++;
873 }
874 }
875 // resize DirIndex
876 DbgFreePool(Buf);
877 if(dc) {
878 if(!OS_SUCCESS(status = UDFDirIndexTrunc(&(FileInfo->Dloc->DirIndex), dc))) {
879 return status;
880 }
881 }
882 // terminator is set by UDFDirIndexTrunc()
883 FileInfo->Dloc->DirIndex->DelCount = 0;
884 ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation);
885
886 // now Offset points to EOF. Let's truncate directory
888#endif // UDF_PACK_DIRS
889} // end UDFPackDirectory__()
static const WCHAR dc[]

Referenced by UDFOpenFile__(), and UDFOpenRootFile__().

◆ UDFPackMapping()

void __fastcall UDFPackMapping ( IN PVCB  Vcb,
IN PEXTENT_INFO  ExtInfo 
)

Definition at line 2747 of file extent.cpp.

2751{
2752 PEXTENT_MAP NewMap, OldMap;
2753 uint32 i, j, l;
2754 uint32 LastLba, LastType, OldLen;
2755 uint32 OldSize, NewSize;
2756#ifdef UDF_DBG
2757 int64 check_size;
2758#endif //UDF_DBG
2759
2760 AdPrint(("Pack ExtInfo %x, Mapping %x\n", ExtInfo, ExtInfo->Mapping));
2761 AdPrint((" Length %x\n", ExtInfo->Length));
2762
2763 OldMap = ExtInfo->Mapping;
2764 LastLba = OldMap[0].extLocation;
2765 OldLen = (OldMap[0].extLength & UDF_EXTENT_LENGTH_MASK) >> Vcb->BlockSizeBits;
2766 LastType = OldMap[0].extLength >> 30;
2767 OldSize =
2768 NewSize = UDFGetMappingLength(OldMap);
2769#ifdef UDF_DBG
2770 check_size = UDFGetExtentLength(ExtInfo->Mapping);
2771 ASSERT(!(check_size & (2048-1)));
2772#endif //UDF_DBG
2773
2775 // calculate required length
2776 for(i=1; OldMap[i].extLength; i++) {
2777 if((LastType == (OldMap[i].extLength >> 30))
2778 &&
2779 ((OldMap[i].extLocation == LastLba + OldLen) ||
2780 (!OldMap[i].extLocation && !LastLba && (LastType == EXTENT_NOT_RECORDED_NOT_ALLOCATED)))
2781 &&
2782 (l + (OldMap[i].extLength & UDF_EXTENT_LENGTH_MASK) <= UDF_MAX_EXTENT_LENGTH)) {
2783 // we can pack two blocks in one
2784 l += OldMap[i].extLength & UDF_EXTENT_LENGTH_MASK;
2785 NewSize -= sizeof(EXTENT_MAP);
2786 } else {
2787 l = OldMap[i].extLength & UDF_EXTENT_LENGTH_MASK;
2788 }
2789 LastLba = OldMap[i].extLocation;
2790 LastType = OldMap[i].extLength >> 30;
2791 OldLen = (OldMap[i].extLength & UDF_EXTENT_LENGTH_MASK) >> Vcb->BlockSizeBits;
2792 }
2793 // no changes ?
2794 if(OldSize <= (NewSize + PACK_MAPPING_THRESHOLD)) {
2795 if(OldSize == NewSize)
2796 return;
2798 return;
2799 }
2800 AdPrint(("Pack ExtInfo %x, Mapping %x, realloc\n", ExtInfo, ExtInfo->Mapping));
2803 // can't alloc ?
2804 if(!NewMap) return;
2805 // Ok, lets pack it...
2806 j=0;
2807 NewMap[0] = OldMap[0];
2808 LastLba = OldMap[0].extLocation;
2809 OldLen = (OldMap[0].extLength & UDF_EXTENT_LENGTH_MASK) >> Vcb->BlockSizeBits;
2810 LastType = OldMap[0].extLength >> 30;
2811 for(i=1; OldMap[i].extLength; i++) {
2812
2813 ExtPrint(("oShExt: type %x, loc %x, len %x\n",
2814 OldMap[i].extLength >> 30, OldMap[i].extLocation, OldMap[i].extLength & UDF_EXTENT_LENGTH_MASK));
2815
2816 if((LastType == (OldMap[i].extLength >> 30))
2817 &&
2818 ((OldMap[i].extLocation == LastLba + OldLen) ||
2819 (!OldMap[i].extLocation && !LastLba && (LastType == EXTENT_NOT_RECORDED_NOT_ALLOCATED)))
2820 &&
2821 ((NewMap[j].extLength & UDF_EXTENT_LENGTH_MASK) + (OldMap[i].extLength & UDF_EXTENT_LENGTH_MASK) <= UDF_MAX_EXTENT_LENGTH)) {
2822 NewMap[j].extLength += OldMap[i].extLength & UDF_EXTENT_LENGTH_MASK;
2823 } else {
2824 j++;
2825 NewMap[j] = OldMap[i];
2826 }
2827
2828 ExtPrint(("nShExt: type %x, loc %x, len %x\n",
2829 NewMap[j].extLength >> 30, NewMap[j].extLocation, NewMap[j].extLength & UDF_EXTENT_LENGTH_MASK));
2830
2831 LastLba = OldMap[i].extLocation;
2832 LastType = OldMap[i].extLength >> 30;
2833 OldLen = (OldMap[i].extLength & UDF_EXTENT_LENGTH_MASK) >> Vcb->BlockSizeBits;
2834 }
2835 // write terminator
2836 j++;
2837 ASSERT(NewSize == (j+1)*sizeof(EXTENT_MAP));
2838 NewMap[j].extLength =
2839 NewMap[j].extLocation = 0;
2840
2841#ifdef UDF_DBG
2842 ASSERT(check_size == UDFGetExtentLength(ExtInfo->Mapping));
2843 ASSERT(check_size == UDFGetExtentLength(NewMap));
2844#endif
2845
2846 AdPrint(("Pack ExtInfo %x, NewMap %x, OldMap %x\n", ExtInfo, NewMap, OldMap));
2847
2848 ExtInfo->Mapping = NewMap;
2849 MyFreePool__(OldMap);
2850
2851 AdPrint(("Pack ExtInfo %x, Mapping %x\n", ExtInfo, ExtInfo->Mapping));
2852 AdPrint((" Length %x\n", ExtInfo->Length));
2853} // end UDFPackMapping()
#define PACK_MAPPING_THRESHOLD
Definition: udf_rel.h:62

Referenced by UDFMarkAllocatedAsRecorded(), UDFRecordVAT(), UDFResizeExtent(), and UDFUpdateNonAllocated().

◆ UDFPadLastSector()

OSSTATUS UDFPadLastSector ( IN PVCB  Vcb,
IN PEXTENT_INFO  ExtInfo 
)

Definition at line 2962 of file udf_info.cpp.

2966{
2967 if(!ExtInfo || !(ExtInfo->Mapping) || !(ExtInfo->Length)) return STATUS_INVALID_PARAMETER;
2968
2969 PEXTENT_MAP Extent = ExtInfo->Mapping; // Extent array
2970 SIZE_T to_write, WrittenBytes;
2971 uint32 Lba, sect_offs, flags;
2973 // Length should not be zero
2974 int64 Offset = ExtInfo->Length + ExtInfo->Offset;
2975 // data is sector-size-aligned, we needn't any padding
2976 if(Offset && !((uint32)Offset & (Vcb->LBlockSize-1) )) return STATUS_SUCCESS;
2977 // get Lba of the last sector
2978 Lba = UDFExtentOffsetToLba(Vcb, Extent, Offset, &sect_offs, &to_write, &flags, NULL);
2979 // EOF check. If we have valid ExtInfo this will not happen, but who knows..
2980 if((Lba == (uint32)-1) ||
2982 return STATUS_END_OF_FILE;
2983 // write tail
2984 status = UDFWriteData(Vcb, TRUE, (((int64)Lba) << Vcb->BlockSizeBits) + sect_offs, to_write, FALSE, Vcb->ZBuffer, &WrittenBytes);
2985 return status;
2986} // UDFPadLastSector()
#define STATUS_END_OF_FILE
Definition: shellext.h:67

Referenced by UDFFlushFE().

◆ UDFPartEnd()

uint32 __fastcall UDFPartEnd ( PVCB  Vcb,
uint32  PartNum 
)

Definition at line 242 of file alloc.cpp.

246{
247 uint32 i;
248 if(PartNum == (uint32)-1) return Vcb->LastLBA;
249 if(PartNum == (uint32)-2) PartNum = Vcb->PartitionMaps-1;
250 for(i=PartNum; i<Vcb->PartitionMaps; i++) {
251 if(Vcb->Partitions[i].PartitionNum == PartNum)
252 return (Vcb->Partitions[i].PartitionRoot +
253 Vcb->Partitions[i].PartitionLen);
254 }
255 return (Vcb->Partitions[i-1].PartitionRoot +
256 Vcb->Partitions[i-1].PartitionLen);
257} // end UDFPartEnd()

Referenced by UDFAllocateFESpace(), UDFGetPartFreeSpace(), UDFMarkNotAllocatedAsAllocated(), UDFPartLen(), UDFPrepareXSpaceBitmap(), and UDFResizeExtent().

◆ UDFPartLbaToPhys()

uint32 __fastcall UDFPartLbaToPhys ( IN PVCB  Vcb,
IN lb_addr Addr 
)

Definition at line 114 of file alloc.cpp.

118{
119 uint32 i, a;
120 if(Addr->partitionReferenceNum >= Vcb->PartitionMaps) {
121 AdPrint(("UDFPartLbaToPhys: part %x, lbn %x (err)\n",
122 Addr->partitionReferenceNum, Addr->logicalBlockNum));
123 if(Vcb->PartitionMaps &&
125 AdPrint(("UDFPartLbaToPhys: try to recover: part %x -> %x\n",
126 Addr->partitionReferenceNum, Vcb->PartitionMaps-1));
127 Addr->partitionReferenceNum = (USHORT)(Vcb->PartitionMaps-1);
128 } else {
129 return LBA_OUT_OF_EXTENT;
130 }
131 }
132 // walk through partition maps & transform relative address
133 // to physical
134 for(i=Addr->partitionReferenceNum; i<Vcb->PartitionMaps; i++) {
135 if(Vcb->Partitions[i].PartitionNum == Addr->partitionReferenceNum) {
136 a = Vcb->Partitions[i].PartitionRoot +
137 (Addr->logicalBlockNum << Vcb->LB2B_Bits);
138 if(a > Vcb->LastPossibleLBA) {
139 AdPrint(("UDFPartLbaToPhys: root %x, lbn %x, lba %x (err1)\n",
140 Vcb->Partitions[i].PartitionRoot, Addr->logicalBlockNum, a));
141 BrutePoint();
142 return LBA_OUT_OF_EXTENT;
143 }
144 return a;
145 }
146 }
147 a = Vcb->Partitions[i-1].PartitionRoot +
148 (Addr->logicalBlockNum << Vcb->LB2B_Bits);
149 if(a > Vcb->LastPossibleLBA) {
150 AdPrint(("UDFPartLbaToPhys: i %x, root %x, lbn %x, lba %x (err2)\n",
151 i, Vcb->Partitions[i-1].PartitionRoot, Addr->logicalBlockNum, a));
152 BrutePoint();
153 return LBA_OUT_OF_EXTENT;
154 }
155 return a;
156} // end UDFPartLbaToPhys()
unsigned short USHORT
Definition: pedump.c:61
#define UDF_VCB_IC_INSTANT_COMPAT_ALLOC_DESCS
Definition: udf_common.h:513

Referenced by UDFAddXSpaceBitmap(), UDFBuildFreeSpaceBitmap(), UDFExtAllocDescToMapping(), UDFFindLastFileSet(), UDFIndexDirectory(), UDFLoadExtInfo(), UDFLongAllocDescToMapping(), UDFOpenFile__(), UDFOpenRootFile__(), UDFPhysLbaToPart(), UDFPrepareXSpaceBitmap(), UDFReadFileEntry(), UDFShortAllocDescToMapping(), UDFVerifyFreeSpaceBitmap(), and UDFVerifyXSpaceBitmap().

◆ UDFPartLen()

uint32 __fastcall UDFPartLen ( PVCB  Vcb,
uint32  PartNum 
)

Definition at line 265 of file alloc.cpp.

269{
270
271 if(PartNum == (uint32)-2) return UDFPartEnd(Vcb, -2) - UDFPartStart(Vcb, -2);
272/*#ifdef _X86_
273 uint32 ret_val;
274 __asm {
275 mov ebx,Vcb
276 mov eax,PartNum
277 cmp eax,-1
278 jne short NOT_last_gpl
279 mov eax,[ebx]Vcb.LastLBA
280 jmp short EO_gpl
281NOT_last_gpl:
282 mov esi,eax
283 xor eax,eax
284 mov ecx,[ebx]Vcb.PartitionMaps
285 jecxz EO_gpl
286
287 mov eax,esi
288 mov edx,size UDFTrackMap
289 mul edx
290 add ebx,eax
291 mov eax,esi
292gpl_loop:
293 cmp [ebx]Vcb.PartitionMaps.PartitionNum,ax
294 je short EO_gpl_1
295 add ebx,size UDFTrackMap
296 inc eax
297 cmp eax,ecx
298 jb short gpl_loop
299 sub ebx,size UDFTrackMap
300EO_gpl_1:
301 mov eax,[ebx]Vcb.PartitionMaps.PartitionLen
302 add eax,[ebx]Vcb.PartitionMaps.PartitionRoot
303EO_gpl:
304 mov ret_val,eax
305 }
306 return ret_val;
307#else // NO X86 optimization , use generic C/C++*/
308 uint32 i;
309 if(PartNum == (uint32)-1) return Vcb->LastLBA;
310 for(i=PartNum; i<Vcb->PartitionMaps; i++) {
311 if(Vcb->Partitions[i].PartitionNum == PartNum)
312 return Vcb->Partitions[i].PartitionLen;
313 }
314 return (Vcb->Partitions[i-1].PartitionRoot +
315 Vcb->Partitions[i-1].PartitionLen);
316/*#endif // _X86_*/
317} // end UDFPartLen()

Referenced by UDFPrepareXSpaceBitmap(), UDFRecordVAT(), UDFUpdateNonAllocated(), and UDFUpdateXSpaceBitmaps().

◆ UDFPartStart()

uint32 __fastcall UDFPartStart ( PVCB  Vcb,
uint32  PartNum 
)

Definition at line 222 of file alloc.cpp.

226{
227 uint32 i;
228 if(PartNum == (uint32)-1) return 0;
229 if(PartNum == (uint32)-2) return Vcb->Partitions[0].PartitionRoot;
230 for(i=PartNum; i<Vcb->PartitionMaps; i++) {
231 if(Vcb->Partitions[i].PartitionNum == PartNum) return Vcb->Partitions[i].PartitionRoot;
232 }
233 return 0;
234} // end UDFPartStart(

Referenced by UDFAddXSpaceBitmap(), UDFAllocateFESpace(), UDFGetPartFreeSpace(), UDFMarkNotAllocatedAsAllocated(), UDFMarkSpaceAsXXXNoProtect_(), UDFPartLen(), UDFPrepareXSpaceBitmap(), UDFRecordVAT(), UDFResizeExtent(), UDFUpdateNonAllocated(), and UDFUpdateXSpaceBitmaps().

◆ UDFPhysLbaToPart()

uint32 UDFPhysLbaToPart ( IN PVCB  Vcb,
IN uint32  PartNum,
IN uint32  Addr 
)

Definition at line 46 of file alloc.cpp.

51{
52 PUDFPartMap pm = Vcb->Partitions;
53#if defined (_X86_) && defined (_MSC_VER) && !defined(__clang__)
54 uint32 retval;
55 __asm {
56 push ebx
57 push ecx
58 push edx
59
60 mov ebx,Vcb
61 mov edx,[ebx]Vcb.PartitionMaps
62 mov ebx,pm
63 mov ecx,PartNum
64 xor eax,eax
65loop_pl2p:
66 cmp ecx,edx
67 jae short EO_pl2p
68 cmp [ebx]pm.PartitionNum,cx
69 jne short cont_pl2p
70 mov eax,Addr
71 sub eax,[ebx]pm.PartitionRoot
72 mov ecx,Vcb
73 mov ecx,[ecx]Vcb.LB2B_Bits
74 shr eax,cl
75 jmp short EO_pl2p
76cont_pl2p:
78 inc ecx
79 jmp short loop_pl2p
80EO_pl2p:
81 mov retval,eax
82
83 pop edx
84 pop ecx
85 pop ebx
86 }
87#ifdef UDF_DBG
88 {
89 // validate return value
90 lb_addr locAddr;
91 locAddr.logicalBlockNum = retval;
92 locAddr.partitionReferenceNum = (uint16)PartNum;
93 UDFPartLbaToPhys(Vcb, &locAddr);
94 }
95#endif // UDF_DBG
96 return retval;
97#else // NO X86 optimization , use generic C/C++
98 uint32 i;
99 // walk through partition maps to find suitable one...
100 for(i=PartNum; i<Vcb->PartitionMaps; i++, pm++) {
101 if(pm->PartitionNum == PartNum)
102 // wow! return relative address
103 return (Addr - pm->PartitionRoot) >> Vcb->LB2B_Bits;
104 }
105 return 0;
106#endif // _X86_
107} // end UDFPhysLbaToPart()
GLsizeiptr size
Definition: glext.h:5919
#define cmp(status, error)
Definition: error.c:114

Referenced by UDFBuildFileEntry(), UDFBuildLongAllocDescs(), UDFBuildShortAllocDescs(), UDFCloseFile__(), UDFCreateFile__(), UDFCreateRootFile__(), UDFCreateStreamDir__(), UDFFlushFE(), UDFFlushFI(), UDFIndexDirectory(), UDFLoadVAT(), UDFPackDirectory__(), UDFPrepareXSpaceBitmap(), UDFRecordDirectory__(), UDFRecordVAT(), and UDFReTagDirectory().

◆ UDFPrepareXSpaceBitmap()

OSSTATUS UDFPrepareXSpaceBitmap ( IN PVCB  Vcb,
IN OUT PSHORT_AD  XSpaceBitmap,
IN OUT PEXTENT_INFO  XSBMExtInfo,
IN OUT int8 **  XSBM,
IN OUT uint32 XSl 
)

Definition at line 52 of file mount.cpp.

59{
60 uint32 BS, j, LBS;
61 uint32 plen;
63 EXTENT_MAP TmpExt;
64 lb_addr locAddr;
65 int8* _XSBM;
66 uint16 Ident;
68 uint32 PartNum;
69
70 if(!(XSpaceBitmap->extLength)) {
71 *XSl = 0;
72 *XSBM = NULL;
73 return STATUS_SUCCESS;
74 }
75
76 PartNum = UDFGetPartNumByPartNdx(Vcb, Vcb->PartitionMaps-1);
77 locAddr.partitionReferenceNum = (uint16)PartNum;
78 plen = UDFPartStart(Vcb, PartNum) + UDFPartLen(Vcb, PartNum);
79
80 BS = Vcb->BlockSize;
81 LBS = Vcb->LBlockSize;
82
83 *XSl = sizeof(SPACE_BITMAP_DESC) + ((plen+7)>>3);
84 _XSBM = (int8*)DbgAllocatePool(NonPagedPool, (*XSl + BS - 1) & ~(BS-1) );
85 *XSBM = _XSBM;
86
87 switch (XSpaceBitmap->extLength >> 30) {
89 locAddr.logicalBlockNum = XSpaceBitmap->extPosition;
90 *XSl = min(XSpaceBitmap->extLength, *XSl);
91 TmpExt.extLength = XSpaceBitmap->extLength = *XSl;
92 TmpExt.extLocation = UDFPartLbaToPhys(Vcb, &locAddr);
93 if(TmpExt.extLocation == LBA_OUT_OF_EXTENT) {
94 BrutePoint();
95 }
96 XSBMExtInfo->Mapping = UDFExtentToMapping(&TmpExt);
97 XSBMExtInfo->Offset = 0;
98 XSBMExtInfo->Length = *XSl;
99 break;
100 }
103 // allocate space for bitmap
105 UDFPartStart(Vcb, PartNum), UDFPartEnd(Vcb, PartNum), XSBMExtInfo, EXTENT_FLAG_ALLOC_SEQUENTIAL) ))
106 return status;
107 if(XSBMExtInfo->Mapping[1].extLength) {
108 UDFPrint(("Can't allocate space for Freed Space bitmap\n"));
109 *XSl = 0;
110 } else {
111 *XSl = (uint32)(XSBMExtInfo->Length);
112 XSpaceBitmap->extPosition = UDFPhysLbaToPart(Vcb, PartNum, XSBMExtInfo->Mapping[0].extLocation);
113 }
114 break;
115 }
117 // record Alloc-Not-Rec
118 locAddr.logicalBlockNum = XSpaceBitmap->extPosition;
119 *XSl = min((XSpaceBitmap->extLength & UDF_EXTENT_LENGTH_MASK), *XSl);
120 TmpExt.extLength = XSpaceBitmap->extLength = *XSl;
121 TmpExt.extLocation = UDFPartLbaToPhys(Vcb, &locAddr);
122 if(TmpExt.extLocation == LBA_OUT_OF_EXTENT) {
123 BrutePoint();
124 }
125 XSBMExtInfo->Mapping = UDFExtentToMapping(&TmpExt);
126 XSBMExtInfo->Offset = 0;
127 XSBMExtInfo->Length = *XSl;
128 break;
129 }
130 }
131
132 if(!_XSBM) {
133 BrutePoint();
135 }
136
137 switch (XSpaceBitmap->extLength >> 30) {
139 // read descriptor & bitmap
140 if((!OS_SUCCESS(status = UDFReadTagged(Vcb, *XSBM, (j = TmpExt.extLocation),
141 locAddr.logicalBlockNum, &Ident))) ||
142 (Ident != TID_SPACE_BITMAP_DESC) ||
143 (!OS_SUCCESS(status = UDFReadExtent(Vcb, XSBMExtInfo, 0, *XSl, FALSE, *XSBM, &ReadBytes))) ) {
144 if(OS_SUCCESS(status)) {
145 BrutePoint();
147 }
148 if(XSBMExtInfo->Mapping) {
149 MyFreePool__(XSBMExtInfo->Mapping);
150 XSBMExtInfo->Mapping = NULL;
151 }
152 DbgFreePool(*XSBM);
153 *XSl = 0;
154 *XSBM = NULL;
155 return status;
156 } else {
157// BrutePoint();
158 }
159 return STATUS_SUCCESS;
160 }
161#if 0
165 break;
166 }
167#endif
168 }
169
170 PSPACE_BITMAP_DESC XSDesc = (PSPACE_BITMAP_DESC)(*XSBM);
171
172 XSpaceBitmap->extLength = (*XSl + LBS -1) & ~(LBS-1);
173 RtlZeroMemory(*XSBM, *XSl);
175 UDFSetUpTag(Vcb, &(XSDesc->descTag), 0, XSpaceBitmap->extPosition);
176 XSDesc->numOfBits = plen;
177 XSDesc->numOfBytes = (*XSl)-sizeof(SPACE_BITMAP_DESC);
178
179 return STATUS_SUCCESS;
180} // end UDFPrepareXSpaceBitmap()
uint32 __fastcall UDFPartLen(PVCB Vcb, uint32 PartNum)
Definition: alloc.cpp:265
struct _SPACE_BITMAP_DESC * PSPACE_BITMAP_DESC

Referenced by UDFUpdateXSpaceBitmaps().

◆ UDFPretendFileDeleted__()

OSSTATUS UDFPretendFileDeleted__ ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo 
)

Definition at line 5566 of file udf_info.cpp.

5570{
5571 AdPrint(("UDFPretendFileDeleted__:\n"));
5572
5573 NTSTATUS RC;
5575 if(!hDirNdx) return STATUS_CANNOT_DELETE;
5576 PDIR_INDEX_ITEM DirNdx = UDFDirIndex(hDirNdx, FileInfo->Index);
5577 if(!DirNdx) return STATUS_CANNOT_DELETE;
5578
5579
5580 // we can't hide file that is not marked as deleted
5582 if(!NT_SUCCESS(RC))
5583 return RC;
5584
5585 AdPrint(("UDFPretendFileDeleted__: set UDF_FI_FLAG_FI_INTERNAL\n"));
5586
5588 if(DirNdx->FName.Buffer) {
5589 MyFreePool__(DirNdx->FName.Buffer);
5590 DirNdx->FName.Buffer = NULL;
5591 DirNdx->FName.Length =
5592 DirNdx->FName.MaximumLength = 0;
5593 }
5594 return STATUS_SUCCESS;
5595} // end UDFPretendFileDeleted__()
NTSTATUS UDFDoesOSAllowFilePretendDeleted__(IN PUDF_FILE_INFO FileInfo)
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32

Referenced by UDFCommonCleanup(), and UDFCreateFile__().

◆ UDFProcessSequence()

OSSTATUS UDFProcessSequence ( IN PDEVICE_OBJECT  DeviceObject,
IN PVCB  Vcb,
IN uint32  block,
IN uint32  lastblock,
OUT lb_addr fileset 
)

Definition at line 2360 of file mount.cpp.

2367{
2369 int8* Buf = (int8*)MyAllocatePool__(NonPagedPool,Vcb->BlockSize);
2371// GenericDesc *gd;
2372 uint32 i,j;
2373 uint16 ident;
2374 int8* Buf2 = NULL;
2375
2376 _SEH2_TRY {
2379 if(!OS_SUCCESS(RC = UDFReadVDS(Vcb, block, lastblock, (PUDF_VDS_RECORD)&vds, Buf)))
2380 try_return(RC);
2381 // walk through Vol Desc Sequence according to locations gained by
2382 // UDFReadVDS() & do some procesing for each one
2383 // It is very simple dispath routine...
2384 for (i=0; i<VDS_POS_LENGTH; i++)
2385 {
2386 if(vds[i].block)
2387 {
2388 if(!OS_SUCCESS(RC = UDFReadTagged(Vcb, Buf, vds[i].block, vds[i].block, &ident)))
2389 try_return(RC);
2390 UDFRegisterFsStructure(Vcb, vds[i].block, Vcb->BlockSize);
2391
2393 UDFLoadPVolDesc(Vcb,Buf);
2394 if(!Vcb->PVolDescAddr.block) {
2395 Vcb->PVolDescAddr = vds[i];
2396 } else {
2397 Vcb->PVolDescAddr2 = vds[i];
2398 }
2399 } else
2401 RC = UDFLoadLogicalVol(DeviceObject,Vcb, Buf, fileset);
2402 if(!OS_SUCCESS(RC)) try_return(RC);
2403 } else
2404
2407 } else
2410 } else
2411
2413 {
2414 Buf2 = (int8*)MyAllocatePool__(NonPagedPool,Vcb->BlockSize);
2416 RC = UDFLoadPartDesc(Vcb,Buf);
2417 if(!OS_SUCCESS(RC)) try_return(RC);
2418 for (j=vds[i].block+1; j<vds[VDS_POS_TERMINATING_DESC].block; j++)
2419 {
2420 RC = UDFReadTagged(Vcb,Buf2, j, j, &ident);
2421 if(!OS_SUCCESS(RC)) try_return(RC);
2422 UDFRegisterFsStructure(Vcb, j, Vcb->BlockSize);
2423// gd = (struct GenericDesc *)Buf2;
2424 if(ident == TID_PARTITION_DESC) {
2425 RC = UDFLoadPartDesc(Vcb,Buf2);
2426 if(!OS_SUCCESS(RC)) try_return(RC);
2427 } else if(ident == TID_UNALLOC_SPACE_DESC) {
2429 //Vcb->Modified = FALSE;
2432 if(!OS_SUCCESS(RC))
2433 try_return(RC);
2434 }
2435 }
2436 MyFreePool__(Buf2);
2437 Buf2 = NULL;
2438 }
2439 } else {
2441 RC = UDFLoadBogusLogicalVol(DeviceObject,Vcb, Buf, fileset);
2442 if(!OS_SUCCESS(RC)) try_return(RC);
2443 }
2444 }
2445 }
2446
2447try_exit: NOTHING;
2448
2449 } _SEH2_FINALLY {
2450 if(Buf) MyFreePool__(Buf);
2451 if(Buf2) MyFreePool__(Buf2);
2452 } _SEH2_END;
2453
2454 return RC;
2455} // end UDFProcessSequence()
#define TID_PARTITION_DESC
Definition: ecma_167.h:158
OSSTATUS UDFLoadUnallocatedSpaceDesc(IN PVCB Vcb, int8 *Buf)
Definition: mount.cpp:2346
OSSTATUS UDFLoadBogusLogicalVol(PDEVICE_OBJECT DeviceObject, PVCB Vcb, int8 *Buf, lb_addr *fileset)
Definition: mount.cpp:1502
OSSTATUS UDFLoadImpUseVolDesc(IN PVCB Vcb, int8 *Buf)
Definition: mount.cpp:2329
OSSTATUS UDFReadVDS(IN PVCB Vcb, IN uint32 block, IN uint32 lastblock, IN PUDF_VDS_RECORD vds, IN int8 *Buf)
Definition: mount.cpp:2239
void UDFLoadPVolDesc(PVCB Vcb, int8 *Buf)
Definition: mount.cpp:1194
OSSTATUS UDFLoadLogicalVol(PDEVICE_OBJECT DeviceObject, PVCB Vcb, int8 *Buf, lb_addr *fileset)
Definition: mount.cpp:1374
OSSTATUS UDFLoadPartDesc(PVCB Vcb, int8 *Buf)
Definition: mount.cpp:2023
uint32 block
Definition: udf_rel.h:108
#define VDS_POS_LENGTH
Definition: udf_rel.h:105
#define VDS_POS_UNALLOC_SPACE_DESC
Definition: udf_rel.h:98
#define VDS_POS_PARTITION_DESC
Definition: udf_rel.h:100
#define VDS_POS_TERMINATING_DESC
Definition: udf_rel.h:103
#define VDS_POS_LOGICAL_VOL_DESC
Definition: udf_rel.h:99
#define VDS_POS_PRIMARY_VOL_DESC
Definition: udf_rel.h:97
#define VDS_POS_IMP_USE_VOL_DESC
Definition: udf_rel.h:101
static unsigned int block
Definition: xmlmemory.c:101

Referenced by UDFLoadPartition().

◆ UDFReadEntityID_Domain()

void UDFReadEntityID_Domain ( PVCB  Vcb,
EntityID eID 
)

Definition at line 1559 of file udf_info.cpp.

1563{
1564 domainIdentSuffix* dis;
1565 uint8 flags;
1566
1567 dis = (domainIdentSuffix*)&(eID->identSuffix);
1568
1569 UDFPrint(("UDF: Entity Id:\n"));
1570 UDFPrint(("flags: %x\n", eID->flags));
1571 UDFPrint(("ident[0]: %x\n", eID->ident[0]));
1572 UDFPrint(("ident[1]: %x\n", eID->ident[1]));
1573 UDFPrint(("ident[2]: %x\n", eID->ident[2]));
1574 UDFPrint(("ident[3]: %x\n", eID->ident[3]));
1575 UDFPrint(("UDF: Entity Id Domain:\n"));
1576 // Get current UDF revision
1577 Vcb->CurrentUDFRev = max(dis->currentRev, Vcb->CurrentUDFRev);
1578 UDFPrint(("Effective Revision: %x\n", Vcb->CurrentUDFRev));
1579 // Get Read-Only flags
1580 flags = dis->flags;
1581 UDFPrint(("Flags: %x\n", flags));
1583 (Vcb->CompatFlags & UDF_VCB_IC_SOFT_RO)) {
1585 Vcb->UserFSFlags |= UDF_USER_FS_FLAGS_SOFT_RO;
1586 UDFPrint((" Soft-RO\n"));
1587 }
1589 (Vcb->CompatFlags & UDF_VCB_IC_HW_RO)) {
1591 Vcb->UserFSFlags |= UDF_USER_FS_FLAGS_HW_RO;
1592 UDFPrint((" Hard-RO\n"));
1593 }
1594
1595} // end UDFReadEntityID_Domain()
#define ENTITYID_FLAGS_SOFT_RO
Definition: osta_misc.h:223
#define ENTITYID_FLAGS_HARD_RO
Definition: osta_misc.h:222
uint8 flags
Definition: ecma_167.h:60
#define UDF_VCB_IC_HW_RO
Definition: udf_common.h:502
#define UDF_VCB_FLAGS_MEDIA_READ_ONLY
Definition: udf_common.h:481
#define UDF_VCB_IC_SOFT_RO
Definition: udf_common.h:514
#define UDF_USER_FS_FLAGS_HW_RO
Definition: udfpubl.h:113
#define UDF_USER_FS_FLAGS_SOFT_RO
Definition: udfpubl.h:112

Referenced by UDFLoadFileset(), and UDFLoadLogicalVol().

◆ UDFReadExtent()

OSSTATUS UDFReadExtent ( IN PVCB  Vcb,
IN PEXTENT_INFO  ExtInfo,
IN int64  Offset,
IN SIZE_T  Length,
IN BOOLEAN  Direct,
OUT int8 Buffer,
OUT PSIZE_T  ReadBytes 
)

Definition at line 3021 of file extent.cpp.

3030{
3031 (*ReadBytes) = 0;
3032 if(!ExtInfo || !ExtInfo->Mapping) return STATUS_INVALID_PARAMETER;
3033 ASSERT((uintptr_t)Buffer > 0x1000);
3034
3035 AdPrint(("Read ExtInfo %x, Mapping %x\n", ExtInfo, ExtInfo->Mapping));
3036
3037 PEXTENT_MAP Extent = ExtInfo->Mapping; // Extent array
3038 SIZE_T to_read, _ReadBytes;
3039 uint32 Lba, sect_offs, flags;
3040 uint32 index;
3042 // prevent reading out of data space
3043 if(Offset > ExtInfo->Length) return STATUS_END_OF_FILE;
3044 if(Offset+Length > ExtInfo->Length) Length = (uint32)(ExtInfo->Length - Offset);
3045 Offset += ExtInfo->Offset; // used for in-ICB data
3046 // read maximal possible part of each frag of extent
3047 Lba = UDFExtentOffsetToLba(Vcb, Extent, Offset, &sect_offs, &to_read, &flags, &index);
3048 _ReadBytes = index;
3049 while(Length) {
3050 // EOF check
3051 if(Lba == LBA_OUT_OF_EXTENT) return STATUS_END_OF_FILE;
3052 Extent += (_ReadBytes + 1);
3053 // check for reading tail
3056 status = UDFReadData(Vcb, TRUE, ( ((uint64)Lba) << Vcb->BlockSizeBits) + sect_offs, to_read, Direct, Buffer, &_ReadBytes);
3057 (*ReadBytes) += _ReadBytes;
3058 if(!OS_SUCCESS(status)) return status;
3059 } else {
3061 (*ReadBytes) += to_read;
3062 }
3063 // prepare for reading next frag...
3064 Length -= to_read;
3065 if(!Length)
3066 break;
3067 ASSERT(to_read);
3068 Buffer += to_read;
3069// Offset += to_read;
3071 _ReadBytes = index;
3072 sect_offs = 0;
3073 }
3074 return STATUS_SUCCESS;
3075} // end UDFReadExtent()
Definition: bufpool.h:45
unsigned int uintptr_t
Definition: crtdefs.h:321

Referenced by UDFConvertFEToNonInICB(), UDFCreateFile__(), UDFExtAllocDescToMapping(), UDFIndexDirectory(), UDFLongAllocDescToMapping(), UDFOpenFile__(), UDFPrepareXSpaceBitmap(), UDFReadFile__(), UDFResizeFile__(), UDFShortAllocDescToMapping(), and UDFWriteFile__().

◆ UDFReadExtentLocation()

OSSTATUS UDFReadExtentLocation ( IN PVCB  Vcb,
IN PEXTENT_INFO  ExtInfo,
IN int64  Offset,
OUT PEXTENT_MAP _SubExtInfo,
IN OUT uint32 _SubExtInfoSz,
OUT int64 _NextOffset 
)

Definition at line 3083 of file extent.cpp.

3092{
3093 if(!ExtInfo || !ExtInfo->Mapping)
3095
3096 PEXTENT_MAP Extent = ExtInfo->Mapping; // Extent array
3097 PEXTENT_MAP SubExtInfo;
3099 uint32 Lba, sect_offs, flags, Skip_MapEntries;
3100 int32 SubExtInfoSz = *_SubExtInfoSz;
3101 int64 Length;
3102 int64 NextOffset;
3103// OSSTATUS status = STATUS_BUFFER_OVERFLOW;
3104
3105 (*_SubExtInfo) = NULL;
3106 (*_SubExtInfoSz) = 0;
3107 NextOffset = Offset;
3108 // prevent reading out of data space
3109 if(Offset >= ExtInfo->Length)
3110 return STATUS_END_OF_FILE;
3111 Length = ExtInfo->Length - Offset;
3112 Offset += ExtInfo->Offset; // used for in-ICB data
3113 // read maximal possible part of each frag of extent
3114 SubExtInfo = (PEXTENT_MAP)MyAllocatePoolTag__(NonPagedPool , SubExtInfoSz*sizeof(EXTENT_MAP),
3116 (*_SubExtInfo) = SubExtInfo;
3117 if(!SubExtInfo)
3119
3120 Lba = UDFExtentOffsetToLba(Vcb, Extent, Offset, &sect_offs, &to_read, &flags, &Skip_MapEntries);
3121 while(Length && SubExtInfoSz) {
3122 // EOF check
3123 if(Lba == LBA_OUT_OF_EXTENT) {
3124 BrutePoint();
3125 return STATUS_END_OF_FILE;
3126 }
3127 Extent += (Skip_MapEntries + 1);
3128 // check for reading tail
3130 SubExtInfo->extLength = to_read;
3132 SubExtInfo->extLocation = LBA_NOT_ALLOCATED;
3133 } else
3135 ASSERT(!(Lba & 0x80000000));
3136 SubExtInfo->extLocation = Lba | 0x80000000;
3137 } else {
3138 SubExtInfo->extLocation = Lba;
3139 }
3140 (*_SubExtInfoSz)++;
3141 SubExtInfoSz--;
3142 NextOffset += to_read;
3143 // prepare for reading next frag...
3144 Length -= to_read;
3145 if(!Length) {
3146// status = STATUS_SUCCESS;
3147 break;
3148 }
3149 ASSERT(to_read);
3150 Lba = UDFNextExtentToLba(Vcb, Extent, &to_read, &flags, &Skip_MapEntries);
3151 sect_offs = 0;
3152 }
3153 (*_NextOffset) = NextOffset;
3154 return STATUS_SUCCESS;
3155} // end UDFReadExtentLocation()

Referenced by UDFReadFileLocation__().

◆ UDFReadFile__()

__inline OSSTATUS UDFReadFile__ ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo,
IN int64  Offset,
IN SIZE_T  Length,
IN BOOLEAN  Direct,
OUT int8 Buffer,
OUT PSIZE_T  ReadBytes 
)

Definition at line 666 of file udf_info.h.

673{
675
676 return UDFReadExtent(Vcb, &(FileInfo->Dloc->DataLoc), Offset, Length, Direct, Buffer, ReadBytes);
677} // end UDFReadFile__()*/
OSSTATUS UDFReadExtent(IN PVCB Vcb, IN PEXTENT_INFO ExtInfo, IN int64 Offset, IN SIZE_T Length, IN BOOLEAN Direct, OUT int8 *Buffer, OUT PSIZE_T ReadBytes)
Definition: extent.cpp:3021

Referenced by UDFCommonRead(), UDFCompleteMount(), UDFConvertFEToExtended(), UDFLoadVAT(), UDFPackDirectory__(), UDFReadSecurity(), UDFRecordVAT(), and UDFReTagDirectory().

◆ UDFReadFileEntry()

OSSTATUS UDFReadFileEntry ( IN PVCB  Vcb,
IN long_ad Icb,
IN OUT PFILE_ENTRY  FileEntry,
IN OUT uint16 Ident 
)

Definition at line 306 of file udf_info.cpp.

312{
314
315 if(!OS_SUCCESS(status = UDFReadTagged(Vcb, (int8*)FileEntry,
316 UDFPartLbaToPhys(Vcb,&(Icb->extLocation)),
317 Icb->extLocation.logicalBlockNum,
318 Ident))) return status;
319 if((FileEntry->descTag.tagIdent != TID_FILE_ENTRY) &&
320 (FileEntry->descTag.tagIdent != TID_EXTENDED_FILE_ENTRY)) {
321 UDFPrint((" Not a FileEntry (lbn=%x, tag=%x)\n", Icb->extLocation.logicalBlockNum, FileEntry->descTag.tagIdent));
323 }
324 return STATUS_SUCCESS;
325} // UDFReadFileEntry()

Referenced by UDFFileDirInfoToNT(), UDFOpenFile__(), and UDFOpenRootFile__().

◆ UDFReadFileLocation__()

__inline OSSTATUS UDFReadFileLocation__ ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo,
IN int64  Offset,
OUT PEXTENT_MAP SubExtInfo,
IN OUT uint32 SubExtInfoSz,
OUT int64 NextOffset 
)

Definition at line 683 of file udf_info.h.

691{
693
694 return UDFReadExtentLocation(Vcb, &(FileInfo->Dloc->DataLoc), Offset, SubExtInfo, SubExtInfoSz, NextOffset);
695} // end UDFReadFile__()*/
OSSTATUS UDFReadExtentLocation(IN PVCB Vcb, IN PEXTENT_INFO ExtInfo, IN int64 Offset, OUT PEXTENT_MAP *_SubExtInfo, IN OUT uint32 *_SubExtInfoSz, OUT int64 *_NextOffset)
Definition: extent.cpp:3083

Referenced by UDFGetRetrievalPointers().

◆ UDFReadMappingFromXEntry()

PEXTENT_MAP UDFReadMappingFromXEntry ( IN PVCB  Vcb,
IN uint32  PartNum,
IN tag XEntry,
IN OUT uint32 Offset,
OUT PEXTENT_INFO  AllocLoc 
)

Definition at line 735 of file extent.cpp.

742{
744 uint16 AllocMode;
745 int8* AllocDescs;
746 uint32 len;
747// EntityID* eID; // for compatibility with Adaptec DirectCD
748
749 Extent = NULL;
750 (*Offset) = 0;
751
752
753 if(XEntry->tagIdent == TID_FILE_ENTRY) {
754// UDFPrint(("Standard FileEntry\n"));
755 PFILE_ENTRY FileEntry = (PFILE_ENTRY)XEntry;
756 ExtPrint(("Standard FileEntry\n"));
757
758 AllocDescs = (int8*)(((int8*)(FileEntry+1))+(FileEntry->lengthExtendedAttr));
759 len = FileEntry->lengthAllocDescs;
760 AllocLoc->Offset = sizeof(FILE_ENTRY) + FileEntry->lengthExtendedAttr;
761// eID = &(FileEntry->impIdent);
762
763 AllocMode = FileEntry->icbTag.flags & ICB_FLAG_ALLOC_MASK;
764
765 } else if(XEntry->tagIdent == TID_EXTENDED_FILE_ENTRY) {
766// UDFPrint(("Extended FileEntry\n"));
767 ExtPrint(("Extended FileEntry\n"));
768 PEXTENDED_FILE_ENTRY ExFileEntry = (PEXTENDED_FILE_ENTRY)XEntry;
769
770 AllocDescs = (((int8*)(ExFileEntry+1))+(ExFileEntry->lengthExtendedAttr));
771 len = ExFileEntry->lengthAllocDescs;
772 AllocLoc->Offset = sizeof(EXTENDED_FILE_ENTRY) + ExFileEntry->lengthExtendedAttr;
773// eID = &(FileEntry->impIdent);
774
775 AllocMode = ExFileEntry->icbTag.flags & ICB_FLAG_ALLOC_MASK;
776
777 } else {
778 return NULL;
779 }
780
781 // for compatibility with Adaptec DirectCD
782// if(!(Vcb->UDF_VCB_IC_ADAPTEC_NONALLOC_COMPAT))
783
784 AllocLoc->Length=len;
785 AllocLoc->Flags |= EXTENT_FLAG_VERIFY; // for metadata
786
787 switch (AllocMode) {
788 case ICB_FLAG_AD_SHORT: {
789 Extent = UDFShortAllocDescToMapping(Vcb, PartNum, (PSHORT_AD)AllocDescs, len, 0, AllocLoc);
790 break;
791 }
792 case ICB_FLAG_AD_LONG: {
793 Extent = UDFLongAllocDescToMapping(Vcb, (PLONG_AD)AllocDescs, len, 0, AllocLoc);
794 break;
795 }
797 Extent = UDFExtAllocDescToMapping(Vcb, (PEXT_AD)AllocDescs, len, 0, AllocLoc);
798 break;
799 }
800 default : { // case ICB_FLAG_AD_IN_ICB
801 Extent = NULL;
802 *Offset = (uintptr_t)AllocDescs - (uintptr_t)XEntry;
803 AllocLoc->Offset=0;
804 AllocLoc->Length=0;
805 if(AllocLoc->Mapping) MyFreePool__(AllocLoc->Mapping);
806 AllocLoc->Mapping=NULL;
807 break;
808 }
809 }
810
811 ExtPrint(("UDFReadMappingFromXEntry: mode %x, loc %x, len %x\n", AllocMode,
812 AllocLoc->Mapping ? AllocLoc->Mapping[0].extLocation : -1, len));
813
814 UDFCheckSpaceAllocation(Vcb, 0, Extent, AS_USED); // check if used
815
816 return Extent;
817}// end UDFReadMappingFromXEntry()
#define ICB_FLAG_AD_EXTENDED
Definition: ecma_167.h:495
PEXTENT_MAP UDFShortAllocDescToMapping(IN PVCB Vcb, IN uint32 PartNum, IN PSHORT_AD AllocDesc, IN uint32 AllocDescLength, IN uint32 SubCallCount, OUT PEXTENT_INFO AllocLoc)
Definition: extent.cpp:294
PEXTENT_MAP UDFExtAllocDescToMapping(IN PVCB Vcb, IN PEXT_AD AllocDesc, IN uint32 AllocDescLength, IN uint32 SubCallCount, OUT PEXTENT_INFO AllocLoc)
Definition: extent.cpp:595

Referenced by UDFLoadExtInfo().

◆ UDFReadTagged()

OSSTATUS UDFReadTagged ( IN PVCB  Vcb,
IN int8 Buf,
IN uint32  Block,
IN uint32  Location,
OUT uint16 Ident 
)

◆ UDFReadVDS()

OSSTATUS UDFReadVDS ( IN PVCB  Vcb,
IN uint32  block,
IN uint32  lastblock,
IN PUDF_VDS_RECORD  vds,
IN int8 Buf 
)

Definition at line 2239 of file mount.cpp.

2246{
2248 GenericDesc* gd;
2249 BOOLEAN done=FALSE;
2250 uint32 vdsn;
2251 uint16 ident;
2252
2253 UDFPrint(("UDF: Read VDS (%x - %x)\n", block, lastblock ));
2254 // Read the main descriptor sequence
2255 for (;(!done && block <= lastblock); block++)
2256 {
2258 if(!OS_SUCCESS(status))
2259 return status;
2260 UDFRegisterFsStructure(Vcb, block, Vcb->BlockSize);
2261
2262 // Process each descriptor (ISO 13346 3/8.3-8.4)
2263 gd = (struct GenericDesc *)Buf;
2264 vdsn = gd->volDescSeqNum;
2265 UDFPrint(("LBA %x, Ident = %x, vdsn = %x\n", block, ident, vdsn ));
2266 switch (ident)
2267 {
2268 case TID_PRIMARY_VOL_DESC: // ISO 13346 3/10.1
2270 {
2271 vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum = vdsn;
2272 vds[VDS_POS_PRIMARY_VOL_DESC].block = block;
2273 }
2274 break;
2275 case TID_VOL_DESC_PTR: // ISO 13346 3/10.3
2276 struct VolDescPtr* pVDP;
2277 if(vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum)
2278 {
2280 vds[VDS_POS_VOL_DESC_PTR].block = block;
2281 vds[VDS_POS_RECURSION_COUNTER].volDescSeqNum++;
2283 UDFPrint(("too long multipart VDS -> abort\n"));
2285 }
2286 pVDP = (struct VolDescPtr*)Buf;
2287 UDFPrint(("multipart VDS...\n"));
2289 pVDP->nextVolDescSeqExt.extLocation + (pVDP->nextVolDescSeqExt.extLocation >> Vcb->BlockSizeBits),
2290 vds, Buf);
2291 }
2292 break;
2293 case TID_IMP_USE_VOL_DESC: // ISO 13346 3/10.4
2295 {
2296 vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum = vdsn;
2297 vds[VDS_POS_IMP_USE_VOL_DESC].block = block;
2298 }
2299 break;
2300 case TID_PARTITION_DESC: // ISO 13346 3/10.5
2302 vds[VDS_POS_PARTITION_DESC].block = block;
2303 break;
2304 case TID_LOGICAL_VOL_DESC: // ISO 13346 3/10.6
2305 case TID_ADAPTEC_LOGICAL_VOL_DESC: // Adaptec Compressed UDF extesion
2307 {
2308 vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum = vdsn;
2309 vds[VDS_POS_LOGICAL_VOL_DESC].block = block;
2310 }
2311 break;
2312 case TID_UNALLOC_SPACE_DESC: // ISO 13346 3/10.8
2314 {
2315 vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum = vdsn;
2316 vds[VDS_POS_UNALLOC_SPACE_DESC].block = block;
2317 }
2318 break;
2319 case TID_TERMINATING_DESC: // ISO 13346 3/10.9
2320 vds[VDS_POS_TERMINATING_DESC].block = block;
2321 done = TRUE;
2322 break;
2323 }
2324 }
2325 return STATUS_SUCCESS;
2326} // UDFReadVDS()
#define TID_TERMINATING_DESC
Definition: ecma_167.h:161
#define TID_PRIMARY_VOL_DESC
Definition: ecma_167.h:154
#define TID_IMP_USE_VOL_DESC
Definition: ecma_167.h:157
#define MAX_VDS_PARTS
Definition: ecma_167.h:231
#define TID_VOL_DESC_PTR
Definition: ecma_167.h:156
#define TID_LOGICAL_VOL_DESC
Definition: ecma_167.h:159
#define TID_ADAPTEC_LOGICAL_VOL_DESC
Definition: osta_misc.h:349
uint32 volDescSeqNum
Definition: ecma_167.h:338
uint32 volDescSeqNum
Definition: ecma_167.h:226
extent_ad nextVolDescSeqExt
Definition: ecma_167.h:227
#define VDS_POS_RECURSION_COUNTER
Definition: udf_rel.h:104
#define VDS_POS_VOL_DESC_PTR
Definition: udf_rel.h:102

Referenced by UDFProcessSequence(), UDFReadVDS(), UDFUpdateVDS(), and UDFVerifySequence().

◆ UDFRecordDirectory__()

OSSTATUS UDFRecordDirectory__ ( IN PVCB  Vcb,
IN OUT PUDF_FILE_INFO  DirInfo 
)

Definition at line 3384 of file udf_info.cpp.

3388{
3390 LONG_AD FEicb;
3392 UDF_DATALOC_INFO Dloc;
3393 UNICODE_STRING PName;
3394 uint32 PartNum;
3395 SIZE_T WrittenBytes;
3396 PDIR_INDEX_ITEM CurDirNdx;
3397 uint32 lba;
3398
3399 // validate DirInfo
3400 ValidateFileInfo(DirInfo);
3401 if(DirInfo->ParentFile && UDFIsAStreamDir(DirInfo->ParentFile))
3402 return STATUS_ACCESS_DENIED;
3403 // file should be empty
3404 if(UDFGetFileSize(DirInfo)) {
3405 if( DirInfo->FileIdent &&
3406 (DirInfo->FileIdent->fileCharacteristics & FILE_DIRECTORY)) return STATUS_FILE_IS_A_DIRECTORY;
3408 }
3409 if(DirInfo->Dloc->DirIndex) return STATUS_FILE_IS_A_DIRECTORY;
3410 // create empty DirIndex
3411 if(DirInfo->FileIdent) DirInfo->FileIdent->fileCharacteristics |= FILE_DIRECTORY;
3412 if((CurDirNdx = UDFDirIndex(UDFGetDirIndexByFileInfo(DirInfo),DirInfo->Index)))
3413 CurDirNdx->FileCharacteristics |= FILE_DIRECTORY;
3414 ((icbtag*)(DirInfo->Dloc->FileEntry+1))->fileType = UDF_FILE_TYPE_DIRECTORY;
3415 // init temporary FileInfo
3417 FileInfo.Dloc = &Dloc;
3418 FileInfo.Dloc->FileEntry = DirInfo->ParentFile->Dloc->FileEntry;
3419 FileInfo.Dloc->FileEntryLen = DirInfo->ParentFile->Dloc->FileEntryLen;
3420 FileInfo.Dloc->DataLoc = DirInfo->Dloc->DataLoc;
3421 FileInfo.Dloc->FELoc = DirInfo->Dloc->FELoc;
3422 FileInfo.ParentFile = DirInfo;
3423 // prepare FileIdent for 'parent Dir'
3424 lba = DirInfo->Dloc->FELoc.Mapping[0].extLocation;
3425 ASSERT(lba);
3426 PartNum = UDFGetPartNumByPhysLba(Vcb, lba);
3427 FEicb.extLength = Vcb->LBlockSize;
3429 FEicb.extLocation.partitionReferenceNum = (uint16)PartNum;
3430 RtlZeroMemory(&(FEicb.impUse), sizeof(FEicb.impUse));
3431 PName.Buffer = (PWCH)L"";
3432 PName.Length = (PName.MaximumLength = sizeof(L"")) - sizeof(WCHAR);
3433 if(!OS_SUCCESS(status =
3434 UDFBuildFileIdent(Vcb, &PName, &FEicb, 0,
3435 &(FileInfo.FileIdent), &(FileInfo.FileIdentLen)) ))
3436 return status;
3437 FileInfo.FileIdent->fileCharacteristics |= (FILE_PARENT | FILE_DIRECTORY);
3440 // init structure
3441 UDFSetUpTag(Vcb, &(FileInfo.FileIdent->descTag), (uint16)(FileInfo.FileIdentLen),
3443 FileInfo.Dloc->DataLoc.Flags |= EXTENT_FLAG_VERIFY; // for metadata
3444 // flush
3445 status = UDFWriteFile__(Vcb, DirInfo, 0, FileInfo.FileIdentLen, FALSE, (int8*)(FileInfo.FileIdent), &WrittenBytes);
3446// status = UDFFlushFI(Vcb, &FileInfo, PartNum);
3447
3448#ifdef UDF_DBG
3449 if(Vcb->CompatFlags & UDF_VCB_IC_W2K_COMPAT_ALLOC_DESCS) {
3450 ASSERT(UDFGetFileSize(DirInfo) <= UDFGetExtentLength(DirInfo->Dloc->DataLoc.Mapping));
3451 } else {
3452 ASSERT(((UDFGetFileSize(DirInfo)+Vcb->LBlockSize-1) & (Vcb->LBlockSize-1)) ==
3453 ((UDFGetExtentLength(DirInfo->Dloc->DataLoc.Mapping)+Vcb->LBlockSize-1) & (Vcb->LBlockSize-1)));
3454 }
3455#endif // UDF_DBG
3456
3457 MyFreePool__(FileInfo.FileIdent);
3458 if(!OS_SUCCESS(status)) return status;
3459 if(CurDirNdx) CurDirNdx->FileCharacteristics =
3460 DirInfo->FileIdent->fileCharacteristics;
3461 return UDFIndexDirectory(Vcb, DirInfo);
3462} // end UDFRecordDirectory__()
WCHAR * PWCH
Definition: ntbasedef.h:410
#define UDFIncDirCounter(Vcb)
Definition: udf_info.h:616
#define UDFDecFileCounter(Vcb)
Definition: udf_info.h:615
#define STATUS_FILE_IS_A_DIRECTORY
Definition: udferr_usr.h:164

Referenced by UDFCommonCreate(), and UDFCreateStreamDir__().

◆ UDFRecordVAT()

OSSTATUS UDFRecordVAT ( IN PVCB  Vcb)

Definition at line 5036 of file udf_info.cpp.

5039{
5040 uint32 Offset;
5042 uint32 hdrOffset, hdrOffsetNew;
5043 uint32 hdrLen;
5046 uint32 len;
5047 uint16 PartNdx = (uint16)Vcb->VatPartNdx;
5048 uint16 PartNum = UDFGetPartNumByPartNdx(Vcb, PartNdx);
5049 uint32 root = UDFPartStart(Vcb, PartNum);
5050 PUDF_FILE_INFO VatFileInfo = Vcb->VatFileInfo;
5051 uint32 i;
5053 uint32 off, BS, NWA;
5054 int8* Old;
5055 int8* New;
5056 uint32* Vat;
5057 uint8 AllocMode;
5058 uint32 VatLen;
5059 uint32 PacketOffset;
5060 uint32 BSh = Vcb->BlockSizeBits;
5061 uint32 MaxPacket = Vcb->WriteBlockSize >> BSh;
5062 uint32 OldLen;
5063 EntityID* eID;
5064
5065 if(!(Vat = Vcb->Vat) || !VatFileInfo) return STATUS_INVALID_PARAMETER;
5066 // Disable VAT-based translation
5067 Vcb->Vat = NULL;
5068 // sync VAT and FSBM
5069 len = min(UDFPartLen(Vcb, PartNum), Vcb->FSBM_BitCount - root);
5070 len = min(Vcb->VatCount, len);
5071 for(i=0; i<len; i++) {
5072 if(UDFGetFreeBit(Vcb->FSBM_Bitmap, root+i))
5073 Vat[i] = UDF_VAT_FREE_ENTRY;
5074 }
5075 // Ok, now we shall construct new VAT image...
5076 // !!! NOTE !!!
5077 // Both VAT copies - in-memory & on-disc
5078 // contain _relative_ addresses
5079 OldLen = len = (uint32)UDFGetFileSize(Vcb->VatFileInfo);
5080 VatLen = (Vcb->LastLBA - root + 1) * sizeof(uint32);
5081 Old = (int8*)DbgAllocatePool(PagedPool, OldLen);
5082 if(!Old) {
5083 DbgFreePool(Vat);
5085 }
5086 // read old one
5087 status = UDFReadFile__(Vcb, VatFileInfo, 0, OldLen, FALSE, Old, &ReadBytes);
5088 if(!OS_SUCCESS(status)) {
5089 DbgFreePool(Vat);
5090 DbgFreePool(Old);
5091 return status;
5092 }
5093 // prepare some pointers
5094 // and fill headers
5095 if(Vcb->Partitions[PartNdx].PartitionType == UDF_VIRTUAL_MAP15) {
5096 Offset = 0;
5097 to_read =
5098 hdrOffset = len - sizeof(VirtualAllocationTable15);
5099 hdrLen = sizeof(VirtualAllocationTable15);
5100 hdrOffsetNew = VatLen;
5101 New = (int8*)DbgAllocatePool(PagedPool, VatLen + hdrLen);
5102 if(!New) {
5103 DbgFreePool(Vat);
5105 }
5106 RtlCopyMemory(New+hdrOffsetNew, Old+hdrOffset, hdrLen);
5107 ((VirtualAllocationTable15*)(New + hdrOffset))->previousVATICB =
5108 VatFileInfo->Dloc->FELoc.Mapping[0].extLocation - root;
5109 eID = &(((VirtualAllocationTable15*)(New + hdrOffset))->ident);
5110
5112
5113/* RtlCopyMemory((int8*)&(eID->ident), UDF_ID_ALLOC, sizeof(UDF_ID_ALLOC) );
5114 iis = (impIdentSuffix*)&(eID->identSuffix);
5115 iis->OSClass = UDF_OS_CLASS_WINNT;
5116 iis->OSIdent = UDF_OS_ID_WINNT;*/
5117 } else {
5119
5121 to_read = len - Offset;
5122 hdrOffset = 0;
5123 hdrLen = sizeof(VirtualAllocationTable20);
5124 hdrOffsetNew = 0;
5125 New = (int8*)DbgAllocatePool(PagedPool, VatLen + hdrLen);
5126 if(!New) {
5127 DbgFreePool(Vat);
5129 }
5130 RtlCopyMemory(New+hdrOffsetNew, Old+hdrOffset, hdrLen);
5131 ((VirtualAllocationTable20*)New)->previousVatICBLoc =
5132 VatFileInfo->Dloc->FELoc.Mapping[0].extLocation - root;
5133
5135
5136 Buf->minReadRevision = Vcb->minUDFReadRev;
5137 Buf->minWriteRevision = Vcb->minUDFWriteRev;
5138 Buf->maxWriteRevision = Vcb->maxUDFWriteRev;
5139
5140 Buf->numFIDSFiles = Vcb->numFiles;
5141 Buf->numFIDSDirectories = Vcb->numDirs;
5142 }
5143
5144 RtlCopyMemory(New+Offset, Vat, VatLen);
5145 //
5146 if(VatFileInfo->Dloc->FileEntry->tagIdent == TID_EXTENDED_FILE_ENTRY) {
5147 eID = &(((PEXTENDED_FILE_ENTRY)(VatFileInfo->Dloc->FileEntry))->impIdent);
5148 } else {
5149 eID = &(((PFILE_ENTRY)(VatFileInfo->Dloc->FileEntry))->impIdent);
5150 }
5151
5152#if 0
5154#endif
5155
5156/* RtlCopyMemory((int8*)&(eID->ident), UDF_ID_DEVELOPER, sizeof(UDF_ID_DEVELOPER) );
5157 iis = (impIdentSuffix*)&(eID->identSuffix);
5158 iis->OSClass = UDF_OS_CLASS_WINNT;
5159 iis->OSIdent = UDF_OS_ID_WINNT;*/
5160
5161 VatFileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_FE_MODIFIED;
5162 // drop VAT
5163 DbgFreePool(Vat);
5164 len = VatLen;
5165 // the operation of resize can modifiy WriteCount in WCache due to movement
5166 // of the data from FE. That's why we should remember PacketOffset now
5167 if(to_read < VatLen) {
5168 status = UDFResizeFile__(Vcb, VatFileInfo, len = hdrLen + VatLen);
5169 if(!OS_SUCCESS(status)) {
5170 return status;
5171 }
5172 UDFMarkSpaceAsXXX(Vcb, VatFileInfo->Dloc, VatFileInfo->Dloc->DataLoc.Mapping, AS_DISCARDED); //free
5173 }
5174 PacketOffset = WCacheGetWriteBlockCount__(&(Vcb->FastCache));
5175 if( ((((PFILE_ENTRY)(VatFileInfo->Dloc->FileEntry))->icbTag.flags & ICB_FLAG_ALLOC_MASK) == ICB_FLAG_AD_IN_ICB) ) {
5176 // now we'll place FE & built-in data to the last sector of
5177 // the last packet will be recorded
5178 if(!PacketOffset) {
5179 // add padding
5180 UDFWriteData(Vcb, TRUE, ((uint64)Vcb->NWA) << Vcb->BlockSizeBits, 1, FALSE, Old, &ReadBytes);
5181 PacketOffset++;
5182 } else {
5183 Vcb->Vat = (uint32*)(New+Offset);
5184 WCacheSyncReloc__(&(Vcb->FastCache), Vcb);
5185 Vcb->Vat = NULL;
5186 }
5187 VatFileInfo->Dloc->FELoc.Mapping[0].extLocation =
5188 VatFileInfo->Dloc->DataLoc.Mapping[0].extLocation =
5189 Vcb->NWA+PacketOffset;
5190 VatFileInfo->Dloc->FELoc.Modified = TRUE;
5191 // setup descTag
5192 ((PFILE_ENTRY)(VatFileInfo->Dloc->FileEntry))->descTag.tagLocation =
5193 UDFPhysLbaToPart(Vcb, PartNum, VatFileInfo->Dloc->DataLoc.Mapping[0].extLocation);
5194 // record data
5195 if(OS_SUCCESS(status = UDFWriteFile__(Vcb, VatFileInfo, 0, VatLen + hdrLen, FALSE, New, &ReadBytes))) {
5196 status = UDFFlushFile__(Vcb, VatFileInfo);
5197 }
5198 return status;
5199 }
5200 // We can't fit the whole VAT in FE tail
5201 // Now lets 'unpack' VAT's mapping to make updating easier
5202 status = UDFUnPackMapping(Vcb, &(VatFileInfo->Dloc->DataLoc));
5203 if(!OS_SUCCESS(status)) return status;
5204 // update VAT with locations of not flushed blocks
5205 if(PacketOffset) {
5206 Vcb->Vat = (uint32*)(New+Offset);
5207 WCacheSyncReloc__(&(Vcb->FastCache), Vcb);
5208 Vcb->Vat = NULL;
5209 }
5210
5211 Mapping = VatFileInfo->Dloc->DataLoc.Mapping;
5212 off=0;
5213 BS = Vcb->BlockSize;
5214 NWA = Vcb->NWA;
5215 VatLen += hdrLen;
5216 // record modified parts of VAT & update mapping
5217 for(i=0; Mapping[i].extLength; i++) {
5218 to_read = (VatLen>=BS) ? BS : VatLen;
5219 if((OldLen < off) || (RtlCompareMemory(Old+off, New+off, to_read) != to_read)) {
5220 // relocate frag
5221 Mapping[i].extLocation = NWA+PacketOffset;
5222 Mapping[i].extLength &= UDF_EXTENT_LENGTH_MASK;
5223 PacketOffset++;
5224 if(PacketOffset >= MaxPacket) {
5225 NWA += (MaxPacket + 7);
5226 PacketOffset = 0;
5227 }
5228 status = UDFWriteFile__(Vcb, VatFileInfo, off, to_read, FALSE, New+off, &ReadBytes);
5229 if(!OS_SUCCESS(status)) {
5230 return status;
5231 }
5232 }
5233 VatLen-=BS;
5234 off+=BS;
5235 }
5236 // pack mapping
5237 UDFPackMapping(Vcb, &(VatFileInfo->Dloc->DataLoc));
5238 len = UDFGetMappingLength(VatFileInfo->Dloc->DataLoc.Mapping)/sizeof(EXTENT_MAP) - 1;
5239 // obtain AllocMode
5240 AllocMode = ((PFILE_ENTRY)(VatFileInfo->Dloc->FileEntry))->icbTag.flags & ICB_FLAG_ALLOC_MASK;
5241 switch(AllocMode) {
5242 case ICB_FLAG_AD_SHORT: {
5243 AllocMode = sizeof(SHORT_AD);
5244 break;
5245 }
5246 case ICB_FLAG_AD_LONG: {
5247 AllocMode = sizeof(LONG_AD);
5248 break;
5249 }
5250 case ICB_FLAG_AD_EXTENDED: {
5251// break;
5252 }
5253 default: {
5255 }
5256 }
5257 // calculate actual AllocSequence length (in blocks)
5258 len = (len*AllocMode+BS-1+VatFileInfo->Dloc->AllocLoc.Offset) /
5259// (((BS - sizeof(ALLOC_EXT_DESC))/sizeof(SHORT_AD))*sizeof(SHORT_AD));
5260 ((BS - sizeof(ALLOC_EXT_DESC) + AllocMode - 1) & ~(AllocMode-1));
5261 // Re-init AllocLoc
5262 if(VatFileInfo->Dloc->AllocLoc.Mapping) MyFreePool__(VatFileInfo->Dloc->AllocLoc.Mapping);
5265 if(!(VatFileInfo->Dloc->AllocLoc.Mapping)) return STATUS_INSUFFICIENT_RESOURCES;
5266
5267 VatFileInfo->Dloc->AllocLoc.Offset = (uint32)(VatFileInfo->Dloc->FELoc.Length);
5268 VatFileInfo->Dloc->AllocLoc.Length = 0;
5269 Mapping = VatFileInfo->Dloc->AllocLoc.Mapping;
5270 Mapping[0].extLength = BS-VatFileInfo->Dloc->AllocLoc.Offset;
5271// Mapping[0].extLocation = ???;
5272 for(i=1; i<len; i++) {
5273 // relocate frag
5274 Mapping[i].extLocation = NWA+PacketOffset;
5275 Mapping[i].extLength = BS;
5276 PacketOffset++;
5277 if(PacketOffset >= MaxPacket) {
5278 NWA += (MaxPacket + 7);
5279 PacketOffset = 0;
5280 }
5281 }
5282 // Terminator
5283 Mapping[i].extLocation =
5284 Mapping[i].extLength = 0;
5285
5286 if( !PacketOffset &&
5287 (VatFileInfo->Dloc->AllocLoc.Length <= (Vcb->BlockSize - (uint32)(VatFileInfo->Dloc->AllocLoc.Offset)) ) ) {
5288 // add padding
5289 UDFWriteData(Vcb, TRUE, ((uint64)NWA) << Vcb->BlockSizeBits, 1, FALSE, Old, &ReadBytes);
5290 PacketOffset++;
5291 }
5292 // now we'll place FE & built-in data to the last sector of
5293 // the last packet will be recorded
5294 VatFileInfo->Dloc->FELoc.Mapping[0].extLocation =
5295 VatFileInfo->Dloc->AllocLoc.Mapping[0].extLocation =
5296 NWA+PacketOffset;
5297 VatFileInfo->Dloc->FELoc.Modified = TRUE;
5298 // setup descTag
5299 ((PFILE_ENTRY)(VatFileInfo->Dloc->FileEntry))->descTag.tagLocation =
5300 UDFPhysLbaToPart(Vcb, PartNum, VatFileInfo->Dloc->FELoc.Mapping[0].extLocation);
5301 VatFileInfo->Dloc->DataLoc.Modified = TRUE;
5302
5303 status = UDFFlushFile__(Vcb, VatFileInfo);
5304 if(!OS_SUCCESS(status))
5305 return status;
5306 WCacheFlushAll__(&(Vcb->FastCache), Vcb);
5307 return STATUS_SUCCESS;
5308} // end UDFRecordVAT()
#define UDF_ID_ALLOC
Definition: osta_misc.h:278
#define New(t)
Definition: rtf.h:1086
OSSTATUS UDFFlushFile__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN ULONG FlushFlags)
Definition: udf_info.cpp:4119
ULONG WCacheGetWriteBlockCount__(IN PW_CACHE Cache)
VOID WCacheSyncReloc__(IN PW_CACHE Cache, IN PVOID Context)

Referenced by UDFUmount__().

◆ UDFReleaseDloc()

OSSTATUS UDFReleaseDloc ( IN PVCB  Vcb,
IN PUDF_DATALOC_INFO  Dloc 
)

Definition at line 1224 of file dirtree.cpp.

1228{
1229 UDFAcquireResourceExclusive(&(Vcb->DlocResource2),TRUE);
1230 Dloc->FE_Flags &= ~UDF_FE_FLAG_UNDER_INIT;
1231 UDFReleaseResource(&(Vcb->DlocResource2));
1232 return STATUS_SUCCESS;
1233} // end UDFReleaseDloc()

Referenced by UDFCreateFile__(), UDFCreateRootFile__(), UDFOpenFile__(), UDFOpenRootFile__(), and UDFStoreDloc().

◆ UDFReleaseDlocList()

void UDFReleaseDlocList ( IN PVCB  Vcb)

Definition at line 1396 of file dirtree.cpp.

1399{
1400 if(!Vcb->DlocList) return;
1401 UDFAcquireResourceExclusive(&(Vcb->DlocResource),TRUE);
1402 for(uint32 i=0; i<Vcb->DlocCount; i++) {
1403 if(Vcb->DlocList[i].Dloc)
1404 MyFreePool__(Vcb->DlocList[i].Dloc);
1405 }
1406 MyFreePool__(Vcb->DlocList);
1407 Vcb->DlocList = NULL;
1408 Vcb->DlocCount = 0;
1409 UDFReleaseResource(&(Vcb->DlocResource));
1410} // end UDFReleaseDlocList()

Referenced by UDFCleanupVCB().

◆ UDFRelocateDloc()

void UDFRelocateDloc ( IN PVCB  Vcb,
IN PUDF_DATALOC_INFO  Dloc,
IN uint32  NewLba 
)

Definition at line 1374 of file dirtree.cpp.

1379{
1380 LONG i;
1381
1382 UDFAcquireResourceExclusive(&(Vcb->DlocResource),TRUE);
1383
1384 if((i = UDFFindDlocInMem(Vcb, Dloc)) != (-1)) {
1385 ASSERT(Vcb->DlocList);
1386 Vcb->DlocList[i].Lba = NewLba;
1387 }
1388 UDFReleaseResource(&(Vcb->DlocResource));
1389
1390} // end UDFRelocateDloc()

Referenced by UDFFlushFE().

◆ UDFRelocateSector()

uint32 __fastcall UDFRelocateSector ( IN PVCB  Vcb,
IN uint32  Lba 
)

Definition at line 934 of file remap.cpp.

938{
939 uint32 i, max, BS, orig;
940
941 if(Vcb->SparingTable) {
942 // use sparing table for relocation
943 uint32 _Lba;
944 PSPARING_MAP Map = Vcb->SparingTable;
945
946 max = Vcb->SparingCount;
947 BS = Vcb->SparingBlockSize;
948 _Lba = Lba & ~(BS-1);
949 for(i=0;i<max;i++,Map++) {
950 orig = Map->origLocation;
951 if(_Lba == (orig & ~(BS-1)) ) {
952 //if( (Lba >= (orig = Map->origLocation)) && (Lba < orig + BS) ) {
953 return Map->mappedLocation + Lba - orig;
954 }
955 }
956 } else if(Vcb->Vat) {
957 // use VAT for relocation
958 uint32* Map = Vcb->Vat;
959 uint32 root;
960 // check if given Lba lays in the partition covered by VAT
961 if(Lba >= Vcb->NWA)
962 return Vcb->NWA;
963 if(Lba < (root = Vcb->Partitions[Vcb->VatPartNdx].PartitionRoot))
964 return Lba;
965 Map = &(Vcb->Vat[(i = Lba - root)]);
966 if((i < Vcb->VatCount) && (i=(*Map)) ) {
967 if(i != UDF_VAT_FREE_ENTRY) {
968 return i + root;
969 } else {
970 return 0x7fffffff;
971 }
972 }
973 }
974 return Lba;
975} // end UDFRelocateSector()
uint32 mappedLocation
Definition: osta_misc.h:192

Referenced by UDFRelocateSectors().

◆ UDFRelocateSectors()

PEXTENT_MAP __fastcall UDFRelocateSectors ( IN PVCB  Vcb,
IN uint32  Lba,
IN uint32  BlockCount 
)

Definition at line 1029 of file remap.cpp.

1034{
1035 if(!UDFAreSectorsRelocated(Vcb, Lba, BlockCount)) return UDF_NO_EXTENT_MAP;
1036
1037 PEXTENT_MAP Extent=NULL, Extent2;
1038 uint32 NewLba, LastLba, j, i;
1039 EXTENT_AD locExt;
1040
1041 LastLba = UDFRelocateSector(Vcb, Lba);
1042 for(i=0, j=1; i<BlockCount; i++, j++) {
1043 // create new entry if the extent in not contigous
1044 if( ((NewLba = UDFRelocateSector(Vcb, Lba+i+1)) != (LastLba+1)) ||
1045 (i==(BlockCount-1)) ) {
1046 locExt.extLength = j << Vcb->BlockSizeBits;
1047 locExt.extLocation = LastLba-j+1;
1048 Extent2 = UDFExtentToMapping(&locExt);
1049 if(!Extent) {
1050 Extent = Extent2;
1051 } else {
1052 Extent = UDFMergeMappings(Extent, Extent2);
1053 MyFreePool__(Extent2);
1054 }
1055 if(!Extent) return NULL;
1056 j = 0;
1057 }
1058 LastLba = NewLba;
1059 }
1060 return Extent;
1061} // end UDFRelocateSectors()
BOOLEAN __fastcall UDFAreSectorsRelocated(IN PVCB Vcb, IN uint32 Lba, IN uint32 BlockCount)
Definition: remap.cpp:982
uint32 __fastcall UDFRelocateSector(IN PVCB Vcb, IN uint32 Lba)
Definition: remap.cpp:934
#define UDF_NO_EXTENT_MAP
Definition: udf_rel.h:519

Referenced by UDFTRead(), and UDFTWrite().

◆ UDFRemapPacket()

OSSTATUS __fastcall UDFRemapPacket ( IN PVCB  Vcb,
IN uint32  Lba,
IN BOOLEAN  RemapSpared 
)

Definition at line 810 of file remap.cpp.

815{
816 uint32 i, max, BS, orig;
817 PSPARING_MAP Map;
818 BOOLEAN verified = FALSE;
819
820 if(Vcb->SparingTable) {
821
822 max = Vcb->SparingCount;
823 BS = Vcb->SparingBlockSize;
824
825 // use sparing table for relocation
826 if(Vcb->SparingCountFree == (ULONG)-1) {
827 UDFPrint(("calculate free spare areas\n"));
828re_check:
829 UDFPrint(("verify spare area\n"));
830 Vcb->SparingCountFree = 0;
831 Map = Vcb->SparingTable;
832 for(i=0;i<max;i++,Map++) {
834 if(UDFCheckArea(Vcb, Map->mappedLocation, BS)) {
835 Vcb->SparingCountFree++;
836 } else {
837 UDFPrint(("initial check: bad spare block @ %x\n", Map->mappedLocation));
839 Vcb->SparingTableModified = TRUE;
840 }
841 }
842 }
843 }
844 if(!Vcb->SparingCountFree) {
845 UDFPrint(("sparing table full\n"));
846 return STATUS_DISK_FULL;
847 }
848
849 Map = Vcb->SparingTable;
850 Lba &= ~(BS-1);
851 for(i=0;i<max;i++,Map++) {
852 orig = Map->origLocation;
853 if(Lba == (orig & ~(BS-1)) ) {
854 // already remapped
855
856 UDFPrint(("remap remapped: bad spare block @ %x\n", Map->mappedLocation));
857 if(!verified) {
858 verified = TRUE;
859 goto re_check;
860 }
861
862 if(!RemapSpared) {
864 } else {
865 // look for another remap area
867 Vcb->SparingTableModified = TRUE;
868 Vcb->SparingCountFree--;
869 break;
870 }
871 }
872 }
873 Map = Vcb->SparingTable;
874 for(i=0;i<max;i++,Map++) {
876 UDFPrint(("remap %x -> %x\n", Lba, Map->mappedLocation));
877 Map->origLocation = Lba;
878 Vcb->SparingTableModified = TRUE;
879 Vcb->SparingCountFree--;
880 return STATUS_SUCCESS;
881 }
882 }
883 UDFPrint(("sparing table full\n"));
884 return STATUS_DISK_FULL;
885 }
886 return STATUS_UNSUCCESSFUL;
887} // end UDFRemapPacket()
#define STATUS_SHARING_VIOLATION
Definition: udferr_usr.h:154

◆ UDFRemoveDloc()

OSSTATUS UDFRemoveDloc ( IN PVCB  Vcb,
IN PUDF_DATALOC_INFO  Dloc 
)

Definition at line 1299 of file dirtree.cpp.

1303{
1304 LONG i;
1305
1306 UDFAcquireResourceExclusive(&(Vcb->DlocResource),TRUE);
1307
1308 if((i = UDFFindDlocInMem(Vcb, Dloc)) == (-1)) {
1309 // FE specified is not in cache. exit
1310 UDFReleaseResource(&(Vcb->DlocResource));
1312 }
1313 // remove from cache
1314 ASSERT(Vcb->DlocList);
1315 RtlZeroMemory(&(Vcb->DlocList[i]), sizeof(UDF_DATALOC_INDEX));
1316 UDFReleaseResource(&(Vcb->DlocResource));
1317 MyFreePool__(Dloc);
1318 return STATUS_SUCCESS;
1319} // end UDFRemoveDloc()

Referenced by UDFBuildFileEntry(), UDFCleanUpFile__(), and UDFHardLinkFile__().

◆ UDFRenameMoveFile__()

OSSTATUS UDFRenameMoveFile__ ( IN PVCB  Vcb,
IN BOOLEAN  IgnoreCase,
IN OUT BOOLEAN Replace,
IN PUNICODE_STRING  fn,
IN OUT PUDF_FILE_INFO  DirInfo1,
IN OUT PUDF_FILE_INFO  DirInfo2,
IN OUT PUDF_FILE_INFO  FileInfo 
)

Definition at line 3176 of file udf_info.cpp.

3185{
3186 PUDF_FILE_INFO FileInfo2;
3188 PDIR_INDEX_ITEM DirNdx1;
3189 PDIR_INDEX_ITEM DirNdx2;
3190 uint_di i,j;
3191 BOOLEAN Recovery = FALSE;
3192 BOOLEAN SameFE = FALSE;
3193 uint32 NTAttr = 0;
3194
3195 // validate FileInfo
3196 ValidateFileInfo(DirInfo1);
3197 ValidateFileInfo(DirInfo2);
3199
3200 i = j = 0;
3201 if(DirInfo1 == DirInfo2) {
3202 if(OS_SUCCESS(status = UDFFindFile(Vcb, IgnoreCase, TRUE, fn, DirInfo2, &j)) &&
3203 (j==FileInfo->Index) ) {
3204 // case-only rename
3205 uint8* CS0;
3206 SIZE_T Nlen, /* l, FIXME ReactOS */ IUl;
3207
3208 // prepare filename
3209 UDFCompressUnicode(fn, &CS0, &Nlen);
3210 if(!CS0) return STATUS_INSUFFICIENT_RESOURCES;
3211/* if(Nlen > UDF_NAME_LEN) {
3212 if(CS0) MyFreePool__(CS0);
3213 return STATUS_OBJECT_NAME_INVALID;
3214 }*/
3215 // allocate memory for FI
3216 DirNdx2 = UDFDirIndex(DirInfo2->Dloc->DirIndex,j);
3217 IUl = DirNdx2->FileInfo->FileIdent->lengthOfImpUse;
3218#if 0
3219 l = (sizeof(FILE_IDENT_DESC) + Nlen + IUl + 3) & ~((uint32)3);
3220#endif
3221
3222 RtlCopyMemory( ((uint8*)(DirNdx2->FileInfo->FileIdent+1))+IUl, CS0, Nlen);
3223 RtlCopyMemory(DirNdx2->FName.Buffer, fn->Buffer, fn->Length);
3224
3225 if(CS0) MyFreePool__(CS0);
3226
3228 UDFBuildHashEntry(Vcb, &(DirNdx2->FName), &(DirNdx2->hashes), HASH_ALL);
3229 return STATUS_SUCCESS;
3230/* } else
3231 if(!OS_SUCCESS(status) && (fn->Length == UDFDirIndex(DirInfo2->Dloc->DirIndex, j=FileInfo->Index)->FName.Length)) {
3232 // target file doesn't exist, but name lengthes are equal
3233 RtlCopyMemory((DirNdx1 = UDFDirIndex(DirInfo1->Dloc->DirIndex,j))->FName.Buffer, fn->Buffer, fn->Length);
3234 DirNdx1->FI_Flags |= UDF_FI_FLAG_FI_MODIFIED;
3235 UDFBuildHashEntry(Vcb, &(DirNdx1->FName), &(DirNdx1->hashes), HASH_ALL);
3236 return STATUS_SUCCESS;*/
3237 }
3238 }
3239
3240 // PHASE 0
3241 // try to create new FileIdent & FileEntry in Dir2
3242
3243RenameRetry:
3245 0, (FileInfo->Dloc->FileEntry->tagIdent == TID_EXTENDED_FILE_ENTRY),
3246 TRUE, DirInfo2, &FileInfo2))) {
3247 UDFCleanUpFile__(Vcb, FileInfo2);
3248 if(FileInfo2) MyFreePool__(FileInfo2);
3250 // try to recover >;->
3251 if((*Replace) && !Recovery) {
3252 Recovery = TRUE;
3253 status = UDFOpenFile__(Vcb, IgnoreCase, TRUE, fn, DirInfo2, &FileInfo2, NULL);
3254 if(OS_SUCCESS(status)) {
3256 if(!OS_SUCCESS(status)) {
3257 UDFCloseFile__(Vcb, FileInfo2);
3258 goto cleanup_and_abort_rename;
3259 }
3260 status = UDFUnlinkFile__(Vcb, FileInfo2, TRUE);
3261// UDFPretendFileDeleted__(Vcb, FileInfo2);
3262 UDFCloseFile__(Vcb, FileInfo2);
3263 if(UDFCleanUpFile__(Vcb, FileInfo2)) {
3264 MyFreePool__(FileInfo2);
3265 FileInfo2 = NULL;
3266 if(SameFE)
3267 return status;
3268 } else {
3269 // we get here if the FileInfo has associated
3270 // system-specific Fcb
3271 // Such fact means that not all system references
3272 // has already gone (except Linked file case)
3273/* if(SameFE)
3274 return status;*/
3275// UDFRemoveOSReferences__(FileInfo2);
3276 if(!OS_SUCCESS(status) ||
3277 (UDFGetFileLinkCount(FileInfo2) < 1))
3279 }
3280 if(OS_SUCCESS(status)) goto RenameRetry;
3281 }
3282cleanup_and_abort_rename:
3283 if(FileInfo2 && UDFCleanUpFile__(Vcb, FileInfo2)) {
3284 MyFreePool__(FileInfo2);
3285 FileInfo2 = NULL;
3286 }
3287 } else {
3289 }
3290 }
3291 return status;
3292 }
3293 // update pointers
3294 DirNdx1 = UDFDirIndex(DirInfo1->Dloc->DirIndex, i = FileInfo->Index);
3295 DirNdx2 = UDFDirIndex(DirInfo2->Dloc->DirIndex, j = FileInfo2->Index);
3296
3297 // copy file attributes to newly created FileIdent
3298 NTAttr = UDFAttributesToNT(DirNdx1, FileInfo->Dloc->FileEntry);
3299 FileInfo2->FileIdent->fileVersionNum = FileInfo->FileIdent->fileVersionNum;
3300 // unlink source FileIdent
3302 // kill newly created entry
3303 UDFFlushFile__(Vcb, FileInfo2);
3304 UDFUnlinkFile__(Vcb, FileInfo2, TRUE);
3305 UDFCloseFile__(Vcb, FileInfo2);
3306 UDFCleanUpFile__(Vcb, FileInfo2);
3307 MyFreePool__(FileInfo2);
3308 return status;
3309 }
3310
3311 // PHASE 1
3312 // drop all unnecessary info from FileInfo & flush FI
3313
3314 DirNdx1->FileInfo = NULL;
3315 ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation);
3316 UDFFlushFI(Vcb, FileInfo, UDFGetPartNumByPhysLba(Vcb, FileInfo->Dloc->FELoc.Mapping[0].extLocation));
3317 UDFInterlockedExchangeAdd((PLONG)&(DirInfo1->OpenCount),
3318 -((LONG)(FileInfo->RefCount)));
3319 // PHASE 2
3320 // copy all necessary info from FileInfo to FileInfo2
3321
3322 FileInfo2->FileIdent->icb = FileInfo->FileIdent->icb;
3323 FileInfo2->FileIdent->fileCharacteristics = FileInfo->FileIdent->fileCharacteristics;
3324 FileInfo2->FileIdent->fileVersionNum = FileInfo->FileIdent->fileVersionNum;
3325 MyFreePool__(FileInfo->FileIdent);
3326 FileInfo->FileIdent = NULL;
3327
3328 // PHASE 3
3329 // copy all necessary info from FileInfo2 to FileInfo
3330
3331 DirNdx2->FileInfo = FileInfo;
3332 DirNdx2->FileCharacteristics = DirNdx1->FileCharacteristics & ~FILE_DELETED;
3333 DirNdx2->FileEntryLoc = DirNdx1->FileEntryLoc;
3334 DirNdx2->FI_Flags = (DirNdx1->FI_Flags & ~UDF_FI_FLAG_SYS_ATTR) | UDF_FI_FLAG_FI_MODIFIED;
3335 UDFInterlockedExchangeAdd((PLONG)&(DirInfo2->OpenCount),
3336 FileInfo->RefCount - FileInfo2->RefCount);
3337
3338 UDFAttributesToUDF(DirNdx2, FileInfo2->Dloc->FileEntry, NTAttr);
3339
3340 FileInfo->Index = j;
3341 FileInfo->FileIdent = FileInfo2->FileIdent;
3342 FileInfo->FileIdentLen = FileInfo2->FileIdentLen;
3343 FileInfo->ParentFile = DirInfo2;
3344 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_FE_MODIFIED;
3345
3346 ((icbtag*)(FileInfo->Dloc->FileEntry+1))->parentICBLocation =
3347 ((icbtag*)(FileInfo2->Dloc->FileEntry+1))->parentICBLocation;
3348
3349 UDFIncFileLinkCount(FileInfo); // increase to 1
3350
3351// UDFUpdateModifyTime(Vcb, FileInfo);
3352
3353 // PHASE 4
3354 // drop all unnecessary info from FileInfo2
3355
3356 UDFFreeFESpace(Vcb, DirInfo2, &(FileInfo2->Dloc->FELoc));
3357 UDFUnlinkDloc(Vcb, FileInfo2->Dloc);
3358 UDFDecFileLinkCount(FileInfo2);
3359
3360 FileInfo2->Dloc->FE_Flags &= ~UDF_FE_FLAG_FE_MODIFIED;
3361/* MyFreePool__(FileInfo2->Dloc->FileEntry);
3362 FileInfo2->Dloc->FileEntry = NULL;*/
3363 FileInfo2->ParentFile = NULL;
3364 FileInfo2->FileIdent = NULL;
3365 FileInfo2->RefCount = 0;
3366 FileInfo2->Dloc->LinkRefCount = 0;
3367 ASSERT(FileInfo2->Dloc->DataLoc.Mapping);
3368 FileInfo2->Dloc->DataLoc.Mapping[0].extLocation = 0;
3369 FileInfo2->Dloc->DataLoc.Mapping[0].extLength = 0;
3370
3371 UDFCleanUpFile__(Vcb, FileInfo2);
3372 MyFreePool__(FileInfo2);
3373
3374 // return 'delete target' status
3375 (*Replace) = Recovery;
3376
3377 return STATUS_SUCCESS;
3378} // end UDFRenameMoveFile__()
NTSTATUS UDFDoesOSAllowFileToBeTargetForRename__(IN PUDF_FILE_INFO FileInfo)
OSSTATUS UDFUnlinkDloc(IN PVCB Vcb, IN PUDF_DATALOC_INFO Dloc)
Definition: dirtree.cpp:1327
uint32 FileIdentLen
Definition: udf_rel.h:376
#define UDFDecFileLinkCount(fi)
Definition: udf_info.h:581
#define UDFInterlockedExchangeAdd(addr, i)
Definition: udffs.h:257

Referenced by UDFRename().

◆ UDFResizeExtent()

OSSTATUS UDFResizeExtent ( IN PVCB  Vcb,
IN uint32  PartNum,
IN int64  Length,
IN BOOLEAN  AlwaysInIcb,
OUT PEXTENT_INFO  ExtInfo 
)

Definition at line 2235 of file extent.cpp.

2242{
2243 uint32 i, flags, lba;
2244 SIZE_T lim;
2245 int64 l;
2247 EXTENT_INFO TmpExtInf;
2248 EXTENT_MAP TmpMapping[2];
2249 uint32 s, pe, BSh, PS;
2250 SIZE_T req_s;
2251 SIZE_T LBS = Vcb->LBlockSize;
2252 BSh = Vcb->BlockSizeBits;
2253 PS = Vcb->WriteBlockSize >> Vcb->BlockSizeBits;
2254 uint32 MaxGrow = (UDF_MAX_EXTENT_LENGTH & ~(LBS-1));
2255 BOOLEAN Sequential = FALSE;
2256
2257 ASSERT(PartNum < 3);
2258
2259 ExtPrint(("Resize ExtInfo %x, %I64x -> %I64x\n", ExtInfo, ExtInfo->Length, Length));
2260
2261 if(ExtInfo->Flags & EXTENT_FLAG_CUT_PREALLOCATED) {
2262 AdPrint((" cut preallocated\n"));
2263 } else
2264 if(ExtInfo->Length == Length) {
2265 return STATUS_SUCCESS;
2266 }
2267 if((ExtInfo->Flags & EXTENT_FLAG_ALLOC_MASK) == EXTENT_FLAG_ALLOC_SEQUENTIAL) {
2268 MaxGrow &= ~(Vcb->WriteBlockSize-1);
2269 Sequential = TRUE;
2270 }
2271
2272 UDFCheckSpaceAllocation(Vcb, 0, ExtInfo->Mapping, AS_USED); // check if used
2273 if(ExtInfo->Offset) {
2274 if(ExtInfo->Offset + Length <= LBS) {
2275 ExtPrint(("Resize IN-ICB\n"));
2276 ExtInfo->Length = Length;
2277 return STATUS_SUCCESS;
2278 }
2279 if(!AlwaysInIcb) // simulate unused 1st sector in extent
2280 ExtInfo->Offset = LBS; // it'll be truncated later
2281 Length += ExtInfo->Offset; // convert to real offset in extent
2282 }
2283 lba = UDFExtentOffsetToLba(Vcb, ExtInfo->Mapping, Length, NULL, NULL, &flags, &i);
2284 if(ExtInfo->Length < Length) {
2285 // increase extent
2286 if(OS_SUCCESS(UDFGetCachedAllocation(Vcb, ExtInfo->Mapping[0].extLocation,
2287 &TmpExtInf, NULL, UDF_PREALLOC_CLASS_DIR))) {
2288 AdPrint(("Resize found cached(1)\n"));
2289 ExtInfo->Mapping = UDFMergeMappings(ExtInfo->Mapping, TmpExtInf.Mapping);
2290 MyFreePool__(TmpExtInf.Mapping);
2291 }
2292 if((l = UDFGetExtentLength(ExtInfo->Mapping)) >= Length) {
2293 // we have enough space inside extent
2294 ExtInfo->Length = Length;
2295 AdPrint(("Resize do nothing (1)\n"));
2296 } else /*if(lba == LBA_OUT_OF_EXTENT)*/ {
2297
2298 Length -= ExtInfo->Offset;
2299 if(/*Length && l &&*/ (l % MaxGrow) &&
2300 (Length-1)/MaxGrow != (l-1)/MaxGrow) {
2301 AdPrint(("Crossing MAX_FRAG boundary...\n"));
2302 int64 l2 = ((l-1)/MaxGrow + 1)*MaxGrow;
2303 status = UDFResizeExtent(Vcb, PartNum, l2, AlwaysInIcb, ExtInfo);
2304 if(!OS_SUCCESS(status)) {
2305 UDFPrint(("Sub-call to UDFResizeExtent() failed (%x)\n", status));
2306 return status;
2307 }
2308 l = ExtInfo->Length;
2309 ASSERT(l == l2);
2310 }
2311 while((Length - l) > MaxGrow) {
2312 status = UDFResizeExtent(Vcb, PartNum, l+MaxGrow, AlwaysInIcb, ExtInfo);
2313 if(!OS_SUCCESS(status)) {
2314 UDFPrint(("Sub-call (2) to UDFResizeExtent() failed (%x)\n", status));
2315 return status;
2316 }
2317 l = ExtInfo->Length;
2318 }
2319 Length += ExtInfo->Offset;
2320 // at first, try to resize existing frag
2321#ifndef UDF_ALLOW_FRAG_AD
2322 i = UDFGetMappingLength(ExtInfo->Mapping);
2323 if(i > (LBS-sizeof(EXTENDED_FILE_ENTRY))) {
2324 // this is very important check since we will not
2325 // be able to _record_ too long AllocDesc because of
2326 // some DEMO limitations in UDFBuildXXXAllocDescs()
2327 AdPrint((" DISK_FULL\n"));
2328 return STATUS_DISK_FULL;
2329 }
2330 i /= sizeof(EXTENT_MAP);
2331#else //UDF_ALLOW_FRAG_AD
2332 i = UDFGetMappingLength(ExtInfo->Mapping) / sizeof(EXTENT_MAP);
2333#endif //UDF_ALLOW_FRAG_AD
2334#ifdef ALLOW_SPARSE
2335 if(!AlwaysInIcb && !(ExtInfo->Offset) &&
2336 (Length - l >= (Vcb->SparseThreshold << BSh))) {
2337 // last frag will be Not-Alloc-Not-Rec...
2338 AdPrint(("Resize sparse (2)\n"));
2339 RtlZeroMemory(&TmpExtInf, sizeof(EXTENT_INFO));
2342 if(!TmpExtInf.Mapping) return STATUS_INSUFFICIENT_RESOURCES;
2343 TmpExtInf.Mapping[0].extLength = (((uint32)(Length - l) + LBS-1) & ~(LBS-1)) | (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30);
2344 TmpExtInf.Mapping[0].extLocation =// 0;
2345 TmpExtInf.Mapping[1].extLength =
2346 TmpExtInf.Mapping[1].extLocation = 0;
2347 l = Length;
2348 ExtInfo->Mapping = UDFMergeMappings(ExtInfo->Mapping, TmpExtInf.Mapping);
2349 MyFreePool__(TmpExtInf.Mapping);
2350 } else
2351#endif //ALLOW_SPARSE
2352 // allocate some sectors
2353 if(i>1 && !(ExtInfo->Offset)) {
2354 i-=2;
2355 // check if Not-Alloc-Not-Rec at the end of mapping
2356 if((uint32)Length - (uint32)l + (ExtInfo->Mapping[i].extLength & UDF_EXTENT_LENGTH_MASK) > MaxGrow) {
2357 // do nothing, but jump directly to allocator
2358 } else
2359 if((ExtInfo->Mapping[i].extLength >> 30) == EXTENT_NOT_RECORDED_NOT_ALLOCATED) {
2360 AdPrint(("Resize grow sparse (3)\n"));
2361 ExtInfo->Mapping[i].extLength +=
2362 (((uint32)Length-(uint32)l+LBS-1) & ~(LBS-1)) ;
2363 l = Length;
2364 // check if Alloc-Not-Rec at the end of mapping
2365 } else if((ExtInfo->Mapping[i].extLength >> 30) == EXTENT_NOT_RECORDED_ALLOCATED) {
2366 AdPrint(("Resize grow Not-Rec (3)\n"));
2367 // current length of last frag
2368 s = ((ExtInfo->Mapping[i].extLength & UDF_EXTENT_LENGTH_MASK) >> BSh);
2369 // prefered location of the next frag
2370 lba = ExtInfo->Mapping[i].extLocation + s;
2371 pe=UDFPartEnd(Vcb,PartNum);
2372 // maximum frag length
2373 if(Sequential) {
2374 lim = (((uint32)UDF_MAX_EXTENT_LENGTH) >> BSh) & ~(PS-1);
2375 } else {
2376 lim = (((uint32)UDF_MAX_EXTENT_LENGTH) >> BSh) & ~(LBS-1);
2377 }
2378 // required last extent length
2379 req_s = s + (uint32)( (((Length + LBS - 1) & ~(LBS-1)) -
2380 ((l + LBS - 1) & ~(LBS-1)) ) >> BSh);
2381 if(lim > req_s) {
2382 lim = req_s;
2383 }
2384 UDFAcquireResourceExclusive(&(Vcb->BitMapResource1),TRUE);
2385/* if((ExtInfo->Flags & EXTENT_FLAG_SEQUENTIAL) &&
2386 ((Length & ~(PS-1)) > (l & ~(PS-1))) &&
2387 TRUE) {
2388 status = UDFResizeExtent(Vcb, PartNum, l+MaxGrow, AlwaysInIcb, ExtInfo);
2389 }*/
2390 // how many sectors we should add
2391 req_s = lim - s;
2392 ASSERT(req_s);
2393 if((lba < pe) && UDFGetFreeBit(Vcb->FSBM_Bitmap, lba)) {
2394 s += UDFGetBitmapLen((uint32*)(Vcb->FSBM_Bitmap), lba, min(pe, lba+req_s-1));
2395 }
2396/* for(s1=lba; (s<lim) && (s1<pe) && UDFGetFreeBit(Vcb->FSBM_Bitmap, s1); s1++) {
2397 s++;
2398 }*/
2399 if(s==lim) {
2400 // we can just increase the last frag
2401 AdPrint(("Resize grow last Not-Rec (4)\n"));
2402 ExtInfo->Mapping[i].extLength = (lim << BSh) | (EXTENT_NOT_RECORDED_ALLOCATED << 30);
2403 l = Length;
2404 UDFMarkSpaceAsXXXNoProtect(Vcb, 0, &(ExtInfo->Mapping[i]), AS_USED); // mark as used
2405 } else {
2406 // we get here if simple increasing of last frag failed
2407 // it worth truncating last frag and try to allocate
2408 // all required data as a single frag
2409
2410/* if(Sequential && s>=PS) {
2411 s &= ~(PS-1);
2412 AdPrint(("Resize grow last Not-Rec (4/2)\n"));
2413 ExtInfo->Mapping[i].extLength = (s << BSh) | (EXTENT_NOT_RECORDED_ALLOCATED << 30);
2414 l += (s << BSh);
2415 UDFMarkSpaceAsXXXNoProtect(Vcb, 0, &(ExtInfo->Mapping[i]), AS_USED); // mark as used
2416 }*/
2417 AdPrint(("Resize reloc last Not-Rec (5)\n"));
2420 if(!TmpExtInf.Mapping) {
2421 UDFPrint(("UDFResizeExtent: !TmpExtInf.Mapping\n"));
2422 UDFReleaseResource(&(Vcb->BitMapResource1));
2424 }
2425 RtlCopyMemory(TmpExtInf.Mapping, ExtInfo->Mapping, i*sizeof(EXTENT_MAP));
2426 TmpExtInf.Mapping[i].extLength =
2427 TmpExtInf.Mapping[i].extLocation = 0;
2428 TmpExtInf.Offset = ExtInfo->Offset;
2429 l -= (ExtInfo->Mapping[i].extLength & UDF_EXTENT_LENGTH_MASK);
2430 TmpExtInf.Length = l;
2431 ASSERT(i || !ExtInfo->Offset);
2432 UDFMarkSpaceAsXXXNoProtect(Vcb, 0, &(ExtInfo->Mapping[i]), AS_DISCARDED); // mark as free
2433 MyFreePool__(ExtInfo->Mapping);
2434 (*ExtInfo) = TmpExtInf;
2435 }
2436 UDFCheckSpaceAllocation(Vcb, 0, ExtInfo->Mapping, AS_USED); // check if used
2437 UDFReleaseResource(&(Vcb->BitMapResource1));
2438 // check if Alloc-Rec
2439 } else {
2440 // current length of last frag
2441 s = ((ExtInfo->Mapping[i].extLength & UDF_EXTENT_LENGTH_MASK) >> BSh);
2442 // prefered location of the next frag
2443 lba = ExtInfo->Mapping[i].extLocation + s;
2444 pe=UDFPartEnd(Vcb,PartNum);
2445 // maximum frag length
2446 if(Sequential) {
2447 lim = (((uint32)UDF_MAX_EXTENT_LENGTH) >> BSh) & ~(PS-1);
2448 } else {
2449 lim = (((uint32)UDF_MAX_EXTENT_LENGTH) >> BSh) & ~(LBS-1);
2450 }
2451 // required last extent length
2452 req_s = s + (uint32)( (((Length + LBS - 1) & ~(LBS-1)) -
2453 ((l + LBS - 1) & ~(LBS-1)) ) >> BSh);
2454 if(lim > req_s) {
2455 lim = req_s;
2456 }
2457// s=0;
2458 // how many sectors we should add
2459 req_s = lim - s;
2460 if(req_s) {
2461 uint32 d=0;
2462
2463 UDFAcquireResourceExclusive(&(Vcb->BitMapResource1),TRUE);
2464 //ASSERT(req_s);
2465 if((lba < pe) && UDFGetFreeBit(Vcb->FSBM_Bitmap, lba)) {
2466 s += (d = UDFGetBitmapLen((uint32*)(Vcb->FSBM_Bitmap), lba, min(pe, lba+req_s-1)));
2467 }
2468 /* for(s1=lba; (s<lim) && (s1<pe) && UDFGetFreeBit(Vcb->FSBM_Bitmap, s1); s1++) {
2469 s++;
2470 }*/
2471
2472 if(s==lim) {
2473 AdPrint(("Resize grow last Rec (6)\n"));
2474 // we can just increase last frag
2475 TmpMapping[0].extLength = req_s << BSh;
2476 TmpMapping[0].extLocation = lba;
2477 TmpMapping[1].extLength =
2478 TmpMapping[1].extLocation = 0;
2479 UDFMarkSpaceAsXXXNoProtect(Vcb, 0, &TmpMapping[0], AS_USED); // mark as used
2480 l += (s << BSh) - (ExtInfo->Mapping[i].extLength & UDF_EXTENT_LENGTH_MASK);
2481 ExtInfo->Mapping[i].extLength = (ExtInfo->Mapping[i].extLength & UDF_EXTENT_FLAG_MASK) | (s << BSh);
2482 } else if(d) {
2483 AdPrint(("Resize part-grow last Rec (6)\n"));
2484 // increase last frag, then alloc rest
2485 TmpMapping[0].extLength = d << BSh;
2486 TmpMapping[0].extLocation = lba;
2487 TmpMapping[1].extLength =
2488 TmpMapping[1].extLocation = 0;
2489 UDFMarkSpaceAsXXXNoProtect(Vcb, 0, &TmpMapping[0], AS_USED); // mark as used
2490 l += (s << BSh) - (ExtInfo->Mapping[i].extLength & UDF_EXTENT_LENGTH_MASK);
2491 ExtInfo->Mapping[i].extLength = (ExtInfo->Mapping[i].extLength & UDF_EXTENT_FLAG_MASK) | (s << BSh);
2492 } else {
2493 AdPrint(("Can't grow last Rec (6)\n"));
2494 }
2495 UDFReleaseResource(&(Vcb->BitMapResource1));
2496 } else {
2497 AdPrint(("Max frag length reached (6)\n"));
2498 }
2499 }
2500 }
2501 if(l < Length) {
2502 // we get here if simple increasing of the last frag failed
2503 AdPrint(("Resize add new frag (7)\n"));
2504 if(l < LBS && Length >= LBS &&
2506 AdPrint(("Resize tune for SEQUENTIAL i/o\n"));
2507 }
2509 UDFPartStart(Vcb, PartNum),
2510 UDFPartEnd(Vcb, PartNum),
2511 &TmpExtInf,
2512 ExtInfo->Flags /*& EXTENT_FLAG_ALLOC_MASK*/);
2513 if(!OS_SUCCESS(status)) {
2514 UDFPrint(("UDFResizeExtent: UDFAllocFreeExtent() failed (%x)\n", status));
2515 return status;
2516 }
2517 ExtInfo->Mapping = UDFMergeMappings(ExtInfo->Mapping, TmpExtInf.Mapping);
2518 MyFreePool__(TmpExtInf.Mapping);
2519 }
2520 UDFPackMapping(Vcb, ExtInfo);
2521 }
2522 } else
2523 if(Length) {
2524 // decrease extent
2525 AdPrint(("Resize cut (8)\n"));
2526 lba = UDFExtentOffsetToLba(Vcb, ExtInfo->Mapping, Length-1, NULL, &lim, &flags, &i);
2527 i++;
2530 ASSERT(i);
2531 if(ExtInfo->Mapping[i].extLength) {
2532 UDFCheckSpaceAllocation(Vcb, 0, &(ExtInfo->Mapping[i]), AS_USED); // check if used
2533 if(!ExtInfo->Offset && (ExtInfo->Flags & EXTENT_FLAG_PREALLOCATED)) {
2534
2535 AdPrint(("Resize try save cutted (8)\n"));
2536 RtlZeroMemory(&TmpExtInf, sizeof(EXTENT_INFO));
2537 s = UDFGetMappingLength(&(ExtInfo->Mapping[i]));
2538
2540 if(TmpExtInf.Mapping) {
2541 RtlCopyMemory(TmpExtInf.Mapping, &(ExtInfo->Mapping[i]), s);
2542 AdPrint(("Resize save cutted (8)\n"));
2543 if(OS_SUCCESS(UDFStoreCachedAllocation(Vcb, ExtInfo->Mapping[0].extLocation,
2544 &TmpExtInf, 0, UDF_PREALLOC_CLASS_DIR))) {
2545 ExtInfo->Mapping[i].extLength = 0;
2546 ExtInfo->Mapping[i].extLocation = 0;
2547 goto tail_cached;
2548 }
2549 }
2550 }
2551 UDFMarkSpaceAsXXX(Vcb, 0, &(ExtInfo->Mapping[i]), AS_DISCARDED); // mark as free
2552tail_cached:;
2553 }
2554 if((lim-1 >= LBS) &&
2556 AdPrint(("i=%x, lba=%x, len=%x\n",i,lba,lim));
2557 ASSERT(lim);
2558// BrutePoint();
2559 EXTENT_MAP ClrMap[2];
2560 ClrMap[0].extLength = lim & ~(LBS-1);
2561 s = (ExtInfo->Mapping[i-1].extLength - ClrMap[0].extLength) & UDF_EXTENT_LENGTH_MASK;
2562 ClrMap[0].extLocation = ExtInfo->Mapping[i-1].extLocation +
2563 (s >> BSh);
2564 ClrMap[1].extLength =
2565 ClrMap[1].extLocation = 0;
2566 ASSERT((ExtInfo->Mapping[i].extLocation < ClrMap[0].extLocation) ||
2567 (ExtInfo->Mapping[i].extLocation >= (ClrMap[0].extLocation + (ClrMap[0].extLength >> BSh))));
2568 UDFCheckSpaceAllocation(Vcb, 0, (PEXTENT_MAP)(&ClrMap), AS_USED); // check if used
2569 UDFMarkSpaceAsXXX(Vcb, 0, (PEXTENT_MAP)(&ClrMap), AS_DISCARDED); // mark as free
2570 ExtInfo->Mapping[i-1].extLength = s | (flags << 30);
2571 }
2572
2573 s = UDFGetMappingLength(ExtInfo->Mapping);
2574 if(!MyReallocPool__((int8*)(ExtInfo->Mapping), s, (int8**)&(ExtInfo->Mapping), (i+1)*sizeof(EXTENT_MAP))) {
2575 // This must never happen on truncate !!!
2576 AdPrint(("ResizeExtent: MyReallocPool__(8) failed\n"));
2577 }
2578 ExtInfo->Mapping[i].extLength =
2579 ExtInfo->Mapping[i].extLocation = 0;
2580 } else {
2581 AdPrint(("Resize zero (9)\n"));
2582 ASSERT(!ExtInfo->Offset);
2583 UDFMarkSpaceAsXXX(Vcb, 0, ExtInfo->Mapping, AS_DISCARDED); // mark as free
2584 s = UDFGetMappingLength(ExtInfo->Mapping);
2585 if(!MyReallocPool__((int8*)(ExtInfo->Mapping), s, (int8**)&(ExtInfo->Mapping), 2*sizeof(EXTENT_MAP))) {
2586 // This must never happen on truncate !!!
2587 AdPrint(("ResizeExtent: MyReallocPool__(9) failed\n"));
2588 }
2589 ExtInfo->Mapping[0].extLength = LBS | (EXTENT_NOT_RECORDED_NOT_ALLOCATED << 30);
2590 ExtInfo->Mapping[0].extLocation =
2591 ExtInfo->Mapping[1].extLength =
2592 ExtInfo->Mapping[1].extLocation = 0;
2593 }
2594 if(ExtInfo->Offset) {
2595 if(!AlwaysInIcb) {
2596 // remove 1st entry pointing to FileEntry
2597 s = UDFGetMappingLength(ExtInfo->Mapping);
2598 RtlMoveMemory(&(ExtInfo->Mapping[0]), &(ExtInfo->Mapping[1]), s - sizeof(EXTENT_MAP));
2599 if(!MyReallocPool__((int8*)(ExtInfo->Mapping), s,
2600 (int8**)&(ExtInfo->Mapping), s - sizeof(EXTENT_MAP) )) {
2601 // This must never happen on truncate !!!
2602 AdPrint(("ResizeExtent: MyReallocPool__(10) failed\n"));
2603 }
2604 Length -= ExtInfo->Offset;
2605 ExtInfo->Offset = 0;
2606 } else {
2607 Length -= ExtInfo->Offset; // back to in-icb
2608 }
2609 }
2610 ExtInfo->Length = Length;
2611 UDFCheckSpaceAllocation(Vcb, 0, ExtInfo->Mapping, AS_USED); // check if used
2612
2613 for(i=0; (ExtInfo->Mapping[i].extLength & UDF_EXTENT_LENGTH_MASK); i++) {
2614 ExtPrint(("Resized Ext: type %x, loc %x, len %x\n",
2615 ExtInfo->Mapping[i].extLength >> 30, ExtInfo->Mapping[i].extLocation, ExtInfo->Mapping[i].extLength & UDF_EXTENT_LENGTH_MASK));
2616 }
2617
2618 return STATUS_SUCCESS;
2619} // end UDFResizeExtent()
#define UDF_EXTENT_FLAG_MASK
Definition: osta_misc.h:149

Referenced by UDFBuildLongAllocDescs(), UDFBuildShortAllocDescs(), UDFCloseFile__(), UDFConvertFEToNonInICB(), UDFFlushFile__(), UDFResizeExtent(), UDFResizeFile__(), and UDFWriteFile__().

◆ UDFResizeFile__()

OSSTATUS UDFResizeFile__ ( IN PVCB  Vcb,
IN OUT PUDF_FILE_INFO  FileInfo,
IN int64  NewLength 
)

Definition at line 3468 of file udf_info.cpp.

3473{
3474 SIZE_T WrittenBytes;
3476 uint32 PartNum;
3477 int8* OldInIcb = NULL;
3478 PEXTENT_MAP NewMap;
3479
3480 UDFPrint(("UDFResizeFile__: FI %x, -> %I64x\n", FileInfo, NewLength));
3482// ASSERT(FileInfo->RefCount >= 1);
3483
3484 if((NewLength >> Vcb->LBlockSizeBits) > Vcb->TotalAllocUnits) {
3485 UDFPrint(("STATUS_DISK_FULL\n"));
3486 return STATUS_DISK_FULL;
3487 }
3488 if (NewLength == FileInfo->Dloc->DataLoc.Length) return STATUS_SUCCESS;
3489 if(FileInfo->ParentFile && (FileInfo->Index >= 2)) {
3490 UDFDirIndex(FileInfo->ParentFile->Dloc->DirIndex,FileInfo->Index)->FI_Flags &= ~UDF_FI_FLAG_SYS_ATTR;
3491 }
3492 if(NewLength > FileInfo->Dloc->DataLoc.Length) {
3493 // grow file
3494 return UDFWriteFile__(Vcb, FileInfo, NewLength, 0, FALSE, NULL, &WrittenBytes);
3495 }
3496 // truncate file
3497 if(NewLength <= (Vcb->LBlockSize - FileInfo->Dloc->FileEntryLen)) {
3498 // check if we are already in IN_ICB mode
3499 if((((PFILE_ENTRY)(FileInfo->Dloc->FileEntry))->icbTag.flags & ICB_FLAG_ALLOC_MASK) != ICB_FLAG_AD_IN_ICB) {
3500 // read data from old location
3501 if(NewLength) {
3503 if(!OldInIcb) return STATUS_INSUFFICIENT_RESOURCES;
3504 status = UDFReadExtent(Vcb, &(FileInfo->Dloc->DataLoc), 0, (uint32)NewLength, FALSE, OldInIcb, &WrittenBytes);
3505 if(!OS_SUCCESS(status)) {
3506 MyFreePool__(OldInIcb);
3507 return status;
3508 }
3509 } else {
3510 OldInIcb = NULL;
3511 }
3512 // allocate storage for new mapping
3515 if(!(NewMap)) {
3516 MyFreePool__(OldInIcb);
3518 }
3519 // free old location...
3520 if(FileInfo->Dloc->DataLoc.Mapping[0].extLocation !=
3521 FileInfo->Dloc->FELoc.Mapping[0].extLocation) {
3522 ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation);
3523mark_data_map_0:
3524 UDFMarkSpaceAsXXX(Vcb, FileInfo->Dloc, FileInfo->Dloc->DataLoc.Mapping, AS_DISCARDED); // free
3525 } else {
3526 if((FileInfo->Dloc->DataLoc.Mapping[0].extLength & UDF_EXTENT_LENGTH_MASK)
3527 > Vcb->LBlockSize) {
3528 BrutePoint();
3529 FileInfo->Dloc->DataLoc.Mapping[0].extLength -= Vcb->LBlockSize;
3530 FileInfo->Dloc->DataLoc.Mapping[0].extLocation += (1 << Vcb->LB2B_Bits);
3531 goto mark_data_map_0;
3532 }
3533 UDFMarkSpaceAsXXX(Vcb, FileInfo->Dloc, &(FileInfo->Dloc->DataLoc.Mapping[1]), AS_DISCARDED); // free
3534 }
3535 if(FileInfo->Dloc->AllocLoc.Mapping) {
3536 if((FileInfo->Dloc->AllocLoc.Mapping[0].extLength & UDF_EXTENT_LENGTH_MASK)
3537 > Vcb->LBlockSize) {
3538 FileInfo->Dloc->AllocLoc.Mapping[0].extLength -= Vcb->LBlockSize;
3539 FileInfo->Dloc->AllocLoc.Mapping[0].extLocation += (1 << Vcb->LB2B_Bits);
3540 UDFMarkSpaceAsXXX(Vcb, FileInfo->Dloc, FileInfo->Dloc->AllocLoc.Mapping, AS_DISCARDED); // free
3541 } else {
3542 UDFMarkSpaceAsXXX(Vcb, FileInfo->Dloc, &(FileInfo->Dloc->AllocLoc.Mapping[1]), AS_DISCARDED); // free
3543 }
3544 MyFreePool__(FileInfo->Dloc->AllocLoc.Mapping);
3545 }
3546 MyFreePool__(FileInfo->Dloc->DataLoc.Mapping);
3547 FileInfo->Dloc->AllocLoc.Mapping = NULL;
3548 FileInfo->Dloc->AllocLoc.Length = 0;
3549 FileInfo->Dloc->AllocLoc.Offset = 0;
3550 FileInfo->Dloc->AllocLoc.Modified = TRUE;
3551 // switch to IN_ICB mode
3552 ((PFILE_ENTRY)(FileInfo->Dloc->FileEntry))->icbTag.flags &= ~ICB_FLAG_ALLOC_MASK;
3553 ((PFILE_ENTRY)(FileInfo->Dloc->FileEntry))->icbTag.flags |= ICB_FLAG_AD_IN_ICB;
3554 // init new data location descriptors
3555 FileInfo->Dloc->DataLoc.Mapping = NewMap;
3556 RtlZeroMemory((int8*)(FileInfo->Dloc->DataLoc.Mapping), 2*sizeof(EXTENT_MAP));
3557 FileInfo->Dloc->DataLoc.Mapping[0] = FileInfo->Dloc->FELoc.Mapping[0];
3558 FileInfo->Dloc->DataLoc.Length = NewLength;
3559 FileInfo->Dloc->DataLoc.Offset = FileInfo->Dloc->FileEntryLen;
3560 // write data to new location
3561 if(OldInIcb) {
3562 status = UDFWriteExtent(Vcb, &(FileInfo->Dloc->DataLoc), 0, (uint32)NewLength, FALSE, OldInIcb, &WrittenBytes);
3563 } else {
3565 }
3566 FileInfo->Dloc->DataLoc.Modified = TRUE;
3567 if(OldInIcb) MyFreePool__(OldInIcb);
3568 } else {
3569 // just modify Length field
3570 FileInfo->Dloc->DataLoc.Length = NewLength;
3572 }
3573 } else {
3574 // resize extent
3575 ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation);
3576 PartNum = UDFGetPartNumByPhysLba(Vcb, FileInfo->Dloc->FELoc.Mapping[0].extLocation);
3577 status = UDFResizeExtent(Vcb, PartNum, NewLength, FALSE, &(FileInfo->Dloc->DataLoc));
3578 FileInfo->Dloc->DataLoc.Modified = TRUE;
3579 FileInfo->Dloc->AllocLoc.Modified = TRUE;
3580 }
3581 if(OS_SUCCESS(status)) {
3583 }
3584
3585#ifdef UDF_DBG
3586 if(Vcb->CompatFlags & UDF_VCB_IC_W2K_COMPAT_ALLOC_DESCS) {
3587 ASSERT(UDFGetFileSize(FileInfo) <= UDFGetExtentLength(FileInfo->Dloc->DataLoc.Mapping));
3588 } else {
3589 ASSERT(((UDFGetFileSize(FileInfo)+Vcb->LBlockSize-1) & (Vcb->LBlockSize-1)) ==
3590 ((UDFGetExtentLength(FileInfo->Dloc->DataLoc.Mapping)+Vcb->LBlockSize-1) & (Vcb->LBlockSize-1)));
3591 }
3592#endif // UDF_DBG
3593
3594 return status;
3595} // end UDFResizeFile__()

Referenced by UDFCommonCleanup(), UDFCommonCreate(), UDFCommonWrite(), UDFConvertFEToExtended(), UDFCreateFile__(), UDFPackDirectory__(), UDFRecordVAT(), UDFSetAllocationInformation(), and UDFSetEOF().

◆ UDFReTagDirectory()

OSSTATUS UDFReTagDirectory ( IN PVCB  Vcb,
IN OUT PUDF_FILE_INFO  FileInfo 
)

Definition at line 895 of file dirtree.cpp.

899{
900 uint32 l;
902 int8* Buf;
905 PUDF_FILE_INFO curFileInfo;
906 PDIR_INDEX_ITEM DirNdx;
907 UDF_DIR_SCAN_CONTEXT ScanContext;
908 uint16 PartNum;
909
911 PDIR_INDEX_HDR hDirNdx = FileInfo->Dloc->DirIndex;
912 if(!hDirNdx) return STATUS_NOT_A_DIRECTORY;
913
914 // do not pack dirs on unchanged disks
915 if(!Vcb->Modified)
916 return STATUS_SUCCESS;
917
918 if( ((hDirNdx->DIFlags & UDF_DI_FLAG_INIT_IN_ICB) ? TRUE : FALSE) ==
919 ((FileInfo->Dloc->DataLoc.Offset) ? TRUE : FALSE) ) {
920 return STATUS_SUCCESS;
921 }
922
923 // start packing
924 Buf = (int8*)DbgAllocatePool(PagedPool, Vcb->LBlockSize*2);
925 if(!Buf) return STATUS_INSUFFICIENT_RESOURCES;
926
927 Offset = UDFDirIndex(hDirNdx,1)->Offset;
928
929 if(!UDFDirIndexInitScan(FileInfo, &ScanContext, 1)) {
930 DbgFreePool(Buf);
931 return STATUS_SUCCESS;
932 }
933
934 ASSERT(FileInfo->Dloc->FELoc.Mapping[0].extLocation);
935 PartNum = (uint16)UDFGetPartNumByPhysLba(Vcb, FileInfo->Dloc->FELoc.Mapping[0].extLocation);
936 ASSERT(PartNum != -1);
937
938 while((DirNdx = UDFDirIndexScan(&ScanContext, NULL))) {
939
941 l = DirNdx->Length, FALSE, Buf, &ReadBytes);
942 if(!OS_SUCCESS(status)) {
943 DbgFreePool(Buf);
944 return status;
945 }
946 curFileInfo = DirNdx->FileInfo;
947 // write modified
948 UDFSetUpTag(Vcb, (tag*)Buf, (uint16)l,
949 UDFPhysLbaToPart(Vcb, PartNum,
950 UDFExtentOffsetToLba(Vcb, FileInfo->Dloc->DataLoc.Mapping,
951 Offset, NULL, NULL, NULL, NULL)));
952
953 if(curFileInfo && curFileInfo->FileIdent) {
954 FileInfo->Dloc->FELoc.Modified = TRUE;
955 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_FE_MODIFIED;
956 }
957
959 if(!OS_SUCCESS(status)) {
960 DbgFreePool(Buf);
961 return status;
962 }
963 if(curFileInfo) {
965 }
966 }
967 // resize DirIndex
968 DbgFreePool(Buf);
969
970 hDirNdx->DIFlags &= ~UDF_DI_FLAG_INIT_IN_ICB;
971 hDirNdx->DIFlags |= (FileInfo->Dloc->DataLoc.Offset ? UDF_DI_FLAG_INIT_IN_ICB : 0);
972 return status;
973
974} // end UDFReTagDirectory()

Referenced by UDFFlushFE().

◆ UDFSetAllocDescLen()

void UDFSetAllocDescLen ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo 
)

Definition at line 1277 of file udf_info.cpp.

1281{
1282 uint16 Ident;
1283
1285
1286 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_FE_MODIFIED;
1287 Ident = FileInfo->Dloc->FileEntry->tagIdent;
1288 if(Ident == TID_FILE_ENTRY) {
1289 PFILE_ENTRY fe = (PFILE_ENTRY)(FileInfo->Dloc->FileEntry);
1290 if(FileInfo->Dloc->AllocLoc.Length) {
1291 fe->lengthAllocDescs = min(FileInfo->Dloc->AllocLoc.Mapping[0].extLength -
1292 FileInfo->Dloc->AllocLoc.Offset,
1293 (uint32)(FileInfo->Dloc->AllocLoc.Length));
1294 } else
1295 if(Vcb->CompatFlags & UDF_VCB_IC_W2K_COMPAT_ALLOC_DESCS) {
1296 fe->lengthAllocDescs = (uint32)(FileInfo->Dloc->DataLoc.Length);
1297 }
1298 } else if(Ident == TID_EXTENDED_FILE_ENTRY) {
1299 PEXTENDED_FILE_ENTRY fe = (PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry);
1300 if(FileInfo->Dloc->AllocLoc.Length) {
1301 fe->lengthAllocDescs = min(FileInfo->Dloc->AllocLoc.Mapping[0].extLength -
1302 FileInfo->Dloc->AllocLoc.Offset,
1303 (uint32)(FileInfo->Dloc->AllocLoc.Length));
1304 } else
1305 if(Vcb->CompatFlags & UDF_VCB_IC_W2K_COMPAT_ALLOC_DESCS) {
1306 fe->lengthAllocDescs = (uint32)(FileInfo->Dloc->DataLoc.Length);
1307 }
1308 }
1309} // end UDFSetAllocDescLen()

Referenced by UDFFlushFE().

◆ UDFSetEntityID_imp_()

void UDFSetEntityID_imp_ ( IN EntityID eID,
IN uint8 Str,
IN uint32  Len 
)

Definition at line 1542 of file udf_info.cpp.

1547{
1548 impIdentSuffix* iis;
1549
1550 RtlCopyMemory( (int8*)&(eID->ident), Str, Len );
1551 iis = (impIdentSuffix*)&(eID->identSuffix);
1553 iis->OSIdent = UDF_OS_ID_WINNT;
1554
1555} // end UDFSetEntityID_imp_()
#define UDF_OS_ID_WINNT
Definition: osta_misc.h:300
#define UDF_OS_CLASS_WINNT
Definition: osta_misc.h:288

◆ UDFSetFileSize()

void UDFSetFileSize ( IN PUDF_FILE_INFO  FileInfo,
IN int64  Size 
)

Definition at line 1157 of file udf_info.cpp.

1161{
1162 uint16 Ident;
1163// PDIR_INDEX_ITEM DirIndex;
1164
1166 AdPrint(("UDFSetFileSize: %I64x, FI %x\n", Size, FileInfo));
1167
1168 //AdPrint((" Dloc %x\n", FileInfo->Dloc));
1169 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_FE_MODIFIED;
1170 //AdPrint((" FileEntry %x\n", FileInfo->Dloc->FileEntry));
1171 Ident = FileInfo->Dloc->FileEntry->tagIdent;
1172 //AdPrint((" Ident %x\n", Ident));
1173 if(Ident == TID_FILE_ENTRY) {
1174 PFILE_ENTRY fe = (PFILE_ENTRY)(FileInfo->Dloc->FileEntry);
1175 //AdPrint((" fe %x\n", fe));
1176 fe->informationLength = Size;
1177 } else if(Ident == TID_EXTENDED_FILE_ENTRY) {
1178 PEXTENDED_FILE_ENTRY fe = (PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry);
1179 //AdPrint((" ext-fe %x\n", fe));
1180 fe->informationLength = Size;
1181 }
1182/* if(DirIndex = UDFDirIndex(UDFGetDirIndexByFileInfo(FileInfo),FileInfo->Index) ) {
1183 DirIndex->FileSize = Size;
1184 }*/
1185 //AdPrint(("UDFSetFileSize: ok\n"));
1186 return;
1187} // end UDFSetFileSize()

Referenced by UDFCreateFile__(), UDFCreateRootFile__(), UDFResizeFile__(), and UDFWriteFile__().

◆ UDFSetFileSizeInDirNdx()

void UDFSetFileSizeInDirNdx ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo,
IN int64 ASize 
)

Definition at line 1190 of file udf_info.cpp.

1195{
1196 uint16 Ident;
1197 PDIR_INDEX_ITEM DirIndex;
1198
1200 if(ASize) {
1201 AdPrint(("UDFSetFileSizeInDirNdx: %I64x\n", *ASize));
1202 } else {
1203 AdPrint(("UDFSetFileSizeInDirNdx: sync\n"));
1204 }
1205
1207 if(!DirIndex)
1208 return;
1209
1210 Ident = FileInfo->Dloc->FileEntry->tagIdent;
1211 if(Ident == TID_FILE_ENTRY) {
1212 PFILE_ENTRY fe = (PFILE_ENTRY)(FileInfo->Dloc->FileEntry);
1213 DirIndex->FileSize = fe->informationLength;
1214 if(ASize) {
1215 DirIndex->AllocationSize = *ASize;
1216// } else {
1217// DirIndex->AllocationSize = (fe->informationLength + Vcb->LBlockSize - 1) & ~(Vcb->LBlockSize - 1);
1218 }
1219 } else if(Ident == TID_EXTENDED_FILE_ENTRY) {
1220 PEXTENDED_FILE_ENTRY fe = (PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry);
1221 DirIndex->FileSize = fe->informationLength;
1222 if(ASize) {
1223 DirIndex->AllocationSize = *ASize;
1224// } else {
1225// DirIndex->AllocationSize = (fe->informationLength + Vcb->LBlockSize - 1) & ~(Vcb->LBlockSize - 1);
1226 }
1227 }
1228 return;
1229} // end UDFSetFileSizeInDirNdx()
int64 AllocationSize
Definition: udf_rel.h:214

Referenced by UDFCommonCleanup(), UDFCommonWrite(), UDFFlushAFile(), UDFSetBasicInformation(), and UDFSetEOF().

◆ UDFSetFileUID()

void UDFSetFileUID ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo 
)

Definition at line 1456 of file udf_info.cpp.

1460{
1461 uint16 Ident;
1462 int64 UID;
1463
1465
1467
1468/* UID = FileInfo->Dloc->FELoc.Mapping[0].extLocation |
1469 ( FileInfo->ParentFile ? (((int64)(FileInfo->ParentFile->Dloc->FELoc.Mapping[0].extLocation)) << 32) : 0);*/
1470
1471 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_FE_MODIFIED;
1472 Ident = FileInfo->Dloc->FileEntry->tagIdent;
1473 if(Ident == TID_FILE_ENTRY) {
1474 PFILE_ENTRY fe = (PFILE_ENTRY)(FileInfo->Dloc->FileEntry);
1475 fe->uniqueID = UID;
1476 } else if(Ident == TID_EXTENDED_FILE_ENTRY) {
1477 PEXTENDED_FILE_ENTRY fe = (PEXTENDED_FILE_ENTRY)(FileInfo->Dloc->FileEntry);
1478 fe->uniqueID = UID;
1479 }
1480 if(FileInfo->FileIdent)
1481 ((FidADImpUse*)&(FileInfo->FileIdent->icb.impUse))->uniqueID = (uint32)UID;
1482 return;
1483} // end UDFSetFileUID()
#define UID
Definition: ext2fs.h:154

Referenced by UDFCreateFile__(), and UDFCreateRootFile__().

◆ UDFSetUpTag()

void UDFSetUpTag ( IN PVCB  Vcb,
IN tag Tag,
IN uint16  DataLen,
IN uint32  TagLoc 
)

Definition at line 936 of file udf_info.cpp.

942{
943 uint32 i;
944 int8* tb;
945
946 AdPrint(("UDF: SetTag Loc=%x(%x), tagIdent=%x\n", TagLoc, Tag->tagLocation, Tag->tagIdent));
947
948 if(DataLen) DataLen -= sizeof(tag);
949// int8* Data = ((int8*)Tag) + sizeof(tag);
950 // Ecma-167 states, that all implementations
951 // shall set this field to '3' even if
952 // disc contains descriptors recorded with
953 // value '2'
954 // But we should ignore this to make happy othe UDF implementations :(
955 Tag->descVersion = (Vcb->NSRDesc & VRS_NSR03_FOUND) ? 3 : 2;
956 Tag->tagLocation = TagLoc;
957 Tag->tagSerialNum = (uint16)(Vcb->SerialNumber + 1);
958 Tag->descCRCLength = DataLen;
959 Tag->descCRC = UDFCrc((uint8*)(Tag+1), DataLen);
960 Tag->tagChecksum = 0;
961 tb = ((int8*)Tag);
962 for (i=0; i<sizeof(tag); i++,tb++)
963 Tag->tagChecksum += (i!=4) ? (*tb) : 0;
964} // end UDFSetUpTag()
static const WCHAR tb[]
Definition: suminfo.c:285

Referenced by UDFBuildLongAllocDescs(), UDFBuildShortAllocDescs(), UDFFlushFE(), UDFFlushFI(), UDFPackDirectory__(), UDFPrepareXSpaceBitmap(), UDFRecordDirectory__(), UDFReTagDirectory(), UDFUpdateLogicalVol(), UDFUpdateLogicalVolInt(), UDFUpdatePartDesc(), and UDFUpdateVolIdent().

◆ UDFShortAllocDescToMapping()

PEXTENT_MAP UDFShortAllocDescToMapping ( IN PVCB  Vcb,
IN uint32  PartNum,
IN PLONG_AD  AllocDesc,
IN uint32  AllocDescLength,
IN uint32  SubCallCount,
OUT PEXTENT_INFO  AllocLoc 
)

◆ UDFSparseFile__()

__inline OSSTATUS UDFSparseFile__ ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo,
IN int64  Offset,
IN uint32  Length,
IN BOOLEAN  Direct,
OUT uint32 ReadBytes 
)

◆ UDFStoreCachedAllocation()

OSSTATUS UDFStoreCachedAllocation ( IN PVCB  Vcb,
IN uint32  ParentLocation,
IN PEXTENT_INFO  Ext,
IN uint32  Items,
IN uint32  AllocClass 
)

Definition at line 1457 of file extent.cpp.

1464{
1465 PUDF_ALLOCATION_CACHE_ITEM AllocCache;
1466 uint32 i, lim;
1468
1469 UDFAcquireResourceExclusive(&(Vcb->PreallocResource),TRUE);
1470
1471 status = UDFInitAllocationCache(Vcb, AllocClass, &AllocCache, &lim, TRUE);
1472 if(!OS_SUCCESS(status)) {
1473 UDFReleaseResource(&(Vcb->PreallocResource));
1474 return status;
1475 }
1476 UDFPrint(("Store AllocationCache for %x, map %x\n", ParentLocation, Ext->Mapping));
1477
1478 for(i=0; i<lim; i++) {
1479 if(AllocCache[i].ParentLocation == LBA_NOT_ALLOCATED) {
1480 AdPrint((" stored in %x\n", i));
1481 AllocCache[i].Ext = (*Ext);
1482 AllocCache[i].Items = Items;
1483 AllocCache[i].ParentLocation = ParentLocation;
1484 UDFReleaseResource(&(Vcb->PreallocResource));
1485 return STATUS_SUCCESS;
1486 }
1487 }
1488 //
1489 AdPrint((" drop map %x (%x)\n", AllocCache[lim-1].Ext.Mapping, lim-1));
1490 switch(AllocClass) {
1492 UDFDiscardFESpace(Vcb, AllocCache[lim-1].Ext.Mapping, AllocCache[lim-1].Items);
1493 break;
1495 UDFMarkSpaceAsXXX(Vcb, 0, AllocCache[lim-1].Ext.Mapping, AS_DISCARDED);
1496 break;
1497 }
1498 RtlMoveMemory(&(AllocCache[1]), &(AllocCache[0]), sizeof(UDF_ALLOCATION_CACHE_ITEM)*(lim-1));
1499 AllocCache[0].Ext = (*Ext);
1500 AllocCache[0].Items = Items;
1501 AllocCache[0].ParentLocation = ParentLocation;
1502 AdPrint((" stored in 0\n"));
1503 UDFReleaseResource(&(Vcb->PreallocResource));
1504 return STATUS_SUCCESS;
1505} // end UDFStoreCachedAllocation()

Referenced by UDFFlushFESpace(), and UDFResizeExtent().

◆ UDFStoreDloc()

OSSTATUS UDFStoreDloc ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  fi,
IN uint32  Lba 
)

Definition at line 1240 of file dirtree.cpp.

1245{
1246 LONG i;
1247 PUDF_DATALOC_INFO Dloc;
1248
1249 if(!Lba) return STATUS_INVALID_PARAMETER;
1250 if(Lba == (ULONG)-1) return STATUS_INVALID_PARAMETER;
1251
1252 UDFAcquireResourceExclusive(&(Vcb->DlocResource),TRUE);
1253
1254 // check if FE specified is already in use
1255 if((i = UDFFindDloc(Vcb, Lba)) == (-1)) {
1256 // not used
1257 if((i = UDFFindFreeDloc(Vcb, Lba)) == (-1)) {
1258 UDFReleaseResource(&(Vcb->DlocResource));
1260 }
1261 } else {
1262 if(!OS_SUCCESS(UDFAcquireDloc(Vcb, Dloc = Vcb->DlocList[i].Dloc))) {
1263 UDFReleaseResource(&(Vcb->DlocResource));
1264 return STATUS_SHARING_PAUSED;
1265 }
1266 // update caller's structures & exit
1267 fi->Dloc = Dloc;
1268 UDFReleaseDloc(Vcb, Dloc);
1269#if defined UDF_DBG && !defined _CONSOLE
1270 if(fi->Dloc->CommonFcb) {
1271 ASSERT((uint32)(fi->Dloc->CommonFcb) != 0xDEADDA7A);
1272 ASSERT(fi->Dloc->CommonFcb->CommonFCBHeader.NodeTypeCode == UDF_NODE_TYPE_NT_REQ_FCB);
1273 }
1274#endif // UDF_DBG
1275 UDFReleaseResource(&(Vcb->DlocResource));
1276 return STATUS_SUCCESS;
1277 }
1278 // allocate common DataLocation (Dloc) descriptor
1280 if(!Dloc) {
1281 UDFReleaseResource(&(Vcb->DlocResource));
1283 }
1284 Vcb->DlocList[i].Lba = Lba;
1285 Vcb->DlocList[i].Dloc = Dloc;
1286 RtlZeroMemory(Dloc, sizeof(UDF_DATALOC_INFO));
1287 Dloc->LinkedFileInfo = fi;
1288 UDFAcquireDloc(Vcb, Dloc);
1289 UDFReleaseResource(&(Vcb->DlocResource));
1290 return STATUS_SUCCESS;
1291} // end UDFStoreDloc()
OSSTATUS UDFAcquireDloc(IN PVCB Vcb, IN PUDF_DATALOC_INFO Dloc)
Definition: dirtree.cpp:1206
LONG UDFFindFreeDloc(IN PVCB Vcb, IN uint32 Lba)
Definition: dirtree.cpp:1171
#define UDF_NODE_TYPE_NT_REQ_FCB
Definition: struct.h:57
struct _UDF_FILE_INFO * LinkedFileInfo
Definition: udf_rel.h:313
#define MEM_DLOC_INF_TAG
Definition: udf_rel.h:482
#define UDF_DATALOC_INFO_MT
Definition: udf_rel.h:228
struct _UDF_DATALOC_INFO * PUDF_DATALOC_INFO

Referenced by UDFBlankMount(), UDFBuildFileEntry(), UDFOpenFile__(), and UDFOpenRootFile__().

◆ UDFUmount__()

OSSTATUS UDFUmount__ ( IN PVCB  Vcb)

Definition at line 921 of file mount.cpp.

924{
925#ifndef UDF_READ_ONLY_BUILD
926 uint32 flags = 0;
927
928 if((Vcb->VCBFlags & UDF_VCB_FLAGS_VOLUME_READ_ONLY)
929 || !Vcb->Modified)
930 return STATUS_SUCCESS;
931 // prevent discarding metadata
932 Vcb->VCBFlags |= UDF_VCB_ASSUME_ALL_USED;
933 if(Vcb->CDR_Mode) {
934 // flush internal cache
935 if(WCacheGetWriteBlockCount__(&(Vcb->FastCache)) >= (Vcb->WriteBlockSize >> Vcb->BlockSizeBits) )
936 WCacheFlushAll__(&(Vcb->FastCache), Vcb);
937 // record VAT
938 return UDFRecordVAT(Vcb);
939 }
940
943
944 if(Vcb->VerifyOnWrite) {
945 UDFPrint(("UDF: Flushing cache for verify\n"));
946 //WCacheFlushAll__(&(Vcb->FastCache), Vcb);
947 WCacheFlushBlocks__(&(Vcb->FastCache), Vcb, 0, Vcb->LastLBA);
948 UDFVFlush(Vcb);
949 }
950
951 // synchronize BAD Block bitmap and NonAllocatable
953
954 UDFAcquireResourceExclusive(&(Vcb->BitMapResource1),TRUE);
955
956 // RAM mode
957#ifdef UDF_DBG
958 if(!OS_SUCCESS(UDFUpdateVolIdent(Vcb, Vcb->PVolDescAddr, &(Vcb->VolIdent))))
959 UDFPrint(("Error updating VolIdent (1)\n"));
960 if(!OS_SUCCESS(UDFUpdateVolIdent(Vcb, Vcb->PVolDescAddr2, &(Vcb->VolIdent))))
961 UDFPrint(("Error updating VolIdent (2)\n"));
962#else
963 UDFUpdateVolIdent(Vcb, Vcb->PVolDescAddr, &(Vcb->VolIdent));
964 UDFUpdateVolIdent(Vcb, Vcb->PVolDescAddr2, &(Vcb->VolIdent));
965#endif // UDF_DBG
966
968 // check if we should update BM
969 if(Vcb->FSBM_ByteCount == RtlCompareMemory(Vcb->FSBM_Bitmap, Vcb->FSBM_OldBitmap, Vcb->FSBM_ByteCount)) {
970 flags &= ~1;
971 } else {
972 flags |= 1;
973 }
974
975#ifdef UDF_DBG
976 if(!OS_SUCCESS(UDFUpdateVDS(Vcb, Vcb->VDS1, Vcb->VDS1 + Vcb->VDS1_Len, flags)))
977 UDFPrint(("Error updating Main VDS\n"));
978 if(!OS_SUCCESS(UDFUpdateVDS(Vcb, Vcb->VDS2, Vcb->VDS2 + Vcb->VDS2_Len, flags)))
979 UDFPrint(("Error updating Reserve VDS\n"));
980#else
981 UDFUpdateVDS(Vcb, Vcb->VDS1, Vcb->VDS1 + Vcb->VDS1_Len, flags);
982 UDFUpdateVDS(Vcb, Vcb->VDS2, Vcb->VDS2 + Vcb->VDS2_Len, flags);
983#endif // UDF_DBG
984
985 // Update Integrity Desc if any
986 if(Vcb->LVid && Vcb->origIntegrityType == INTEGRITY_TYPE_CLOSE) {
988 }
989
990 if(flags & 1)
991 RtlCopyMemory(Vcb->FSBM_OldBitmap, Vcb->FSBM_Bitmap, Vcb->FSBM_ByteCount);
992
993//skip_update_bitmap:
994
995 Vcb->VCBFlags &= ~UDF_VCB_ASSUME_ALL_USED;
996
997 UDFReleaseResource(&(Vcb->BitMapResource1));
998#endif //UDF_READ_ONLY_BUILD
999
1000 return STATUS_SUCCESS;
1001} // end UDFUmount__()
OSSTATUS UDFFlushAllCachedAllocations(IN PVCB Vcb, IN uint32 AllocClass)
Definition: extent.cpp:1508
OSSTATUS UDFUpdateVolIdent(IN PVCB Vcb, IN UDF_VDS_RECORD Lba, IN PUNICODE_STRING VolIdent)
Definition: mount.cpp:801
OSSTATUS UDFUpdateVDS(IN PVCB Vcb, IN uint32 block, IN uint32 lastblock, IN uint32 flags)
Definition: mount.cpp:673
OSSTATUS UDFUpdateLogicalVolInt(PVCB Vcb, BOOLEAN Close)
Definition: mount.cpp:361
OSSTATUS UDFUpdateNonAllocated(IN PVCB Vcb)
Definition: mount.cpp:857
VOID UDFVFlush(IN PVCB Vcb)
Definition: remap.cpp:742
OSSTATUS UDFRecordVAT(IN PVCB Vcb)
Definition: udf_info.cpp:5036
OSSTATUS WCacheFlushBlocks__(IN PW_CACHE Cache, IN PVOID Context, IN lba_t Lba, IN ULONG BCount)

Referenced by UDFFlushLogicalVolume().

◆ UDFUnicodeCksum()

uint16 __fastcall UDFUnicodeCksum ( PWCHAR  s,
uint32  n 
)

Definition at line 4356 of file udf_info.cpp.

4360{
4361#if defined(_X86_) && defined(_MSC_VER) && !defined(__clang__)
4362// uint32 _Size = n;
4363
4364 __asm {
4365 push ebx
4366 push ecx
4367 push edx
4368 push esi
4369
4370 xor eax,eax
4371 mov esi,ecx
4372 mov ecx,edx
4373
4374 jecxz EO_uCRC
4375
4376 lea ebx,[CrcTable]
4377 xor edx,edx
4378
4379uCRC_loop:
4380
4381 mov dl,ah // dl = (Crc >> 8)
4382 xor dl,[esi+1] // dl = ((Crc >> 8) ^ (*s >> 8)) & 0xff
4383 mov ah,al
4384 mov al,dh // ax = (Crc << 8)
4385 xor ax,[word ptr ebx+edx*2] // ax = ...........
4386
4387 mov dl,ah
4388 xor dl,[esi]
4389 mov ah,al
4390 mov al,dh
4391 xor ax,[word ptr ebx+edx*2]
4392
4393 inc esi
4394 inc esi
4395 loop uCRC_loop
4396
4397EO_uCRC:
4398
4399 pop esi
4400 pop edx
4401 pop ecx
4402 pop ebx
4403
4404 ret
4405 }
4406#else // NO X86 optimization , use generic C/C++
4407 uint16 Crc = 0;
4408 while (n--) {
4409 Crc = CrcTable[(Crc >> 8 ^ (*s >> 8)) & 0xff] ^ (Crc << 8);
4410 Crc = CrcTable[(Crc >> 8 ^ (*s++ & 0xff)) & 0xff] ^ (Crc << 8);
4411 }
4412 return Crc;
4413
4414#endif // _X86_
4415} // end UDFUnicodeCksum()

Referenced by UDFDOSName100(), UDFDOSName200(), and UDFDOSName201().

◆ UDFUnicodeCksum150()

uint16 __fastcall UDFUnicodeCksum150 ( PWCHAR  s,
uint32  n 
)

Definition at line 4422 of file udf_info.cpp.

4426{
4427#if defined(_X86_) && defined(_MSC_VER) && !defined(__clang__)
4428// uint32 _Size = n;
4429
4430 __asm {
4431 push ebx
4432 push ecx
4433 push edx
4434 push esi
4435 push edi
4436
4437 xor eax,eax
4438 mov esi,ecx
4439 mov ecx,edx
4440 xor edi,edi
4441
4442 jecxz EO_uCRC
4443
4444 //lea ebx,[CrcTable]
4445 xor edx,edx
4446 xor ebx,ebx
4447
4448uCRC_loop:
4449
4450 mov dl,ah // dl = (Crc >> 8)
4451 or edi,edx // if(*s & 0xff00) Use16 = TRUE;
4452 xor dl,[esi+1] // dl = ((Crc >> 8) ^ (*s >> 8)) & 0xff
4453 mov ah,al
4454 mov al,0 // ax = (Crc << 8)
4455 xor ax,[word ptr CrcTable+edx*2] // ax = ...........
4456
4457 mov dl,ah
4458 xor dl,[esi]
4459 mov ah,al
4460 mov al,0
4462
4463 or edi,edi // if(!Use16) {
4464 jnz use16_1
4465
4466 rol eax,16
4467
4468 mov bl,ah // dl = (Crc >> 8)
4469 xor bl,[esi] // dl = ((Crc >> 8) ^ (*s >> 8)) & 0xff
4470 mov ah,al
4471 mov al,0 // ax = (Crc << 8)
4472 xor ax,[word ptr CrcTable+ebx*2] // ax = ...........
4473
4474 rol eax,16
4475use16_1:
4476 inc esi
4477 inc esi
4478 loop uCRC_loop
4479
4480EO_uCRC:
4481
4482 or edi,edi // if(!Use16) {
4483 jnz use16_2
4484
4485 rol eax,16 // }
4486use16_2:
4487 and eax,0xffff
4488
4489 pop edi
4490 pop esi
4491 pop edx
4492 pop ecx
4493 pop ebx
4494
4495 ret
4496 }
4497#else // NO X86 optimization , use generic C/C++
4498 uint16 Crc = 0;
4499 uint16 Crc2 = 0;
4500 BOOLEAN Use16 = FALSE;
4501 while (n--) {
4502 if(!Use16) {
4503 if((*s) & 0xff00) {
4504 Use16 = TRUE;
4505 } else {
4506 Crc2 = CrcTable[(Crc2 >> 8 ^ (*s >> 8)) & 0xff] ^ (Crc2 << 8);
4507 }
4508 }
4509 Crc = CrcTable[(Crc >> 8 ^ (*s >> 8)) & 0xff] ^ (Crc << 8);
4510 Crc = CrcTable[(Crc >> 8 ^ (*s++ & 0xff)) & 0xff] ^ (Crc << 8);
4511 }
4512 return Use16 ? Crc : Crc2;
4513#endif // _X86_
4514} // end UDFUnicodeCksum150()
#define rol(value, bits)
Definition: sha1.c:24
ecx edi movl ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx movl TEMP incl eax andl eax ecx incl ebx testl eax jnz xchgl ecx incl TEMP esp ecx subl ebx pushl ecx ecx edx ecx shrl ecx mm0 mm4 mm0 mm4 mm1 mm5 mm1 mm5 mm2 mm6 mm2 mm6 mm3 mm7 mm3 mm7 paddd mm0 paddd mm4 paddd mm0 paddd mm4 paddd mm0 paddd mm4 movq mm1 movq mm5 psrlq mm1 psrlq mm5 paddd mm0 paddd mm4 psrad mm0 psrad mm4 packssdw mm0 packssdw mm4 mm1 punpckldq mm0 pand mm1 pand mm0 por mm1 movq edi esi edx edi decl ecx jnz popl ecx andl ecx jecxz mm0 mm0 mm1 mm1 mm2 mm2 mm3 mm3 paddd mm0 paddd mm0 paddd mm0 movq mm1 psrlq mm1 paddd mm0 psrad mm0 packssdw mm0 movd eax movw edi esi edx edi
Definition: synth_sse3d.h:185

Referenced by UDFDOSName200().

◆ UDFUnicodeInString()

BOOLEAN UDFUnicodeInString ( IN uint8 string,
IN WCHAR  ch 
)

Definition at line 336 of file udf_info.cpp.

340{
341 BOOLEAN found = FALSE;
342
343 while(*string != '\0' && !found) {
344 // These types should compare, since both are unsigned numbers.
345 if(*string == ch) {
346 found = TRUE;
347 }
348 string++;
349 }
350 return(found);
351} // end UDFUnicodeInString()

Referenced by UDFIsIllegalChar().

◆ UDFUnlinkAllFilesInDir()

OSSTATUS UDFUnlinkAllFilesInDir ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  DirInfo 
)

Definition at line 1945 of file udf_info.cpp.

1949{
1950 PDIR_INDEX_HDR hCurDirNdx;
1951 PDIR_INDEX_ITEM CurDirNdx;
1954 uint_di i;
1955
1956 hCurDirNdx = DirInfo->Dloc->DirIndex;
1957 // check if we can delete all files
1958 for(i=2; (CurDirNdx = UDFDirIndex(hCurDirNdx,i)); i++) {
1959 // try to open Stream
1960 if(CurDirNdx->FileInfo)
1961 return STATUS_CANNOT_DELETE;
1962 }
1963 // start deletion
1964 for(i=2; (CurDirNdx = UDFDirIndex(hCurDirNdx,i)); i++) {
1965 // try to open Stream
1966 status = UDFOpenFile__(Vcb, FALSE, TRUE, NULL, DirInfo, &FileInfo, &i);
1968 // we should not release on-disk allocation for
1969 // deleted streams twice
1970 if(CurDirNdx->FileInfo) {
1971 BrutePoint();
1972 goto err_del_stream;
1973 }
1974 goto skip_del_stream;
1975 } else
1976 if(!OS_SUCCESS(status)) {
1977 // Error :(((
1978err_del_stream:
1980 if(FileInfo)
1982 return status;
1983 }
1984
1986 AdPrint((" "));
1989skip_del_stream:
1992 }
1993 }
1994 return STATUS_SUCCESS;
1995} // end UDFUnlinkAllFilesInDir()

Referenced by UDFUnlinkFile__().

◆ UDFUnlinkDloc()

OSSTATUS UDFUnlinkDloc ( IN PVCB  Vcb,
IN PUDF_DATALOC_INFO  Dloc 
)

Definition at line 1327 of file dirtree.cpp.

1331{
1332 LONG i;
1333
1334 UDFAcquireResourceExclusive(&(Vcb->DlocResource),TRUE);
1335
1336 if((i = UDFFindDlocInMem(Vcb, Dloc)) == (-1)) {
1337 // FE specified is not in cache. exit
1338 UDFReleaseResource(&(Vcb->DlocResource));
1340 }
1341 // remove from cache
1342 ASSERT(Vcb->DlocList);
1343 RtlZeroMemory(&(Vcb->DlocList[i]), sizeof(UDF_DATALOC_INDEX));
1344 UDFReleaseResource(&(Vcb->DlocResource));
1345 return STATUS_SUCCESS;
1346} // end UDFUnlinkDloc()

Referenced by UDFRenameMoveFile__(), and UDFUnlinkFile__().

◆ UDFUnlinkFile__()

OSSTATUS UDFUnlinkFile__ ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo,
IN BOOLEAN  FreeSpace 
)

Definition at line 1766 of file udf_info.cpp.

1771{
1772 uint_di Index; // index of file to be deleted
1773 uint16 lc;
1774 PUDF_DATALOC_INFO Dloc;
1775 PUDF_FILE_INFO DirInfo;
1776 PUDF_FILE_INFO SDirInfo;
1777 PDIR_INDEX_HDR hDirNdx;
1778 PDIR_INDEX_HDR hCurDirNdx;
1779 PDIR_INDEX_ITEM DirNdx;
1781 BOOLEAN IsSDir;
1782
1783 AdPrint(("UDFUnlinkFile__:\n"));
1784 if(!FileInfo) return STATUS_SUCCESS;
1785
1787
1788#ifndef _CONSOLE
1789 // now we can't call this if there is no OS-specific File Desc. present
1790 if(FileInfo->Fcb)
1792#endif //_CONSOLE
1793 // check references
1794 Dloc = FileInfo->Dloc;
1795 if((FileInfo->OpenCount /*> (uint32)(UDFHasAStreamDir(FileInfo) ? 1 : 0)*/) ||
1796 (FileInfo->RefCount>1)) return STATUS_CANNOT_DELETE;
1797 if(Dloc->SDirInfo)
1798 return STATUS_CANNOT_DELETE;
1799 ASSERT(FileInfo->RefCount == 1);
1800 DirInfo = FileInfo->ParentFile;
1801 // root dir or self
1802 if(!DirInfo || ((FileInfo->Index < 2) && !UDFIsAStreamDir(FileInfo))) return STATUS_CANNOT_DELETE;
1803 hDirNdx = DirInfo->Dloc->DirIndex;
1804 Index = FileInfo->Index;
1805 // we can't delete modified file
1806 // it should be closed & reopened (or flushed) before deletion
1807 DirNdx = UDFDirIndex(hDirNdx,Index);
1808#if defined UDF_DBG || defined PRINT_ALWAYS
1809 if(DirNdx && DirNdx->FName.Buffer) {
1810 AdPrint(("Unlink: %ws\n",DirNdx->FName.Buffer));
1811 }
1812#endif // UDF_DBG
1813 if(FreeSpace &&
1814 ((Dloc->FE_Flags & UDF_FE_FLAG_FE_MODIFIED) ||
1815 Dloc->DataLoc.Modified ||
1816 Dloc->AllocLoc.Modified ||
1817 Dloc->FELoc.Modified ||
1818 (DirNdx && (DirNdx->FI_Flags & UDF_FI_FLAG_FI_MODIFIED)) )) {
1819// BrutePoint();
1820 return STATUS_CANNOT_DELETE;
1821 }
1822 SDirInfo = Dloc->SDirInfo;
1823/* if(FreeSpace && SDirInfo) {
1824 UDFPrint(("Unlink: SDirInfo should be NULL !!!\n"));
1825 BrutePoint();
1826 return STATUS_CANNOT_DELETE;
1827 }*/
1828 // stream directory can be deleted even being not empty
1829 // otherwise we should perform some checks
1830 if(!(IsSDir = UDFIsAStreamDir(FileInfo))) {
1831 // check if not empty direcory
1832 if((DirNdx->FileCharacteristics & FILE_DIRECTORY) &&
1833 (hCurDirNdx = Dloc->DirIndex) &&
1834 FreeSpace) {
1835 if(!UDFIsDirEmpty(hCurDirNdx))
1837 }
1840 FileInfo->FileIdent->fileCharacteristics |= FILE_DELETED;
1841 hDirNdx->DelCount++;
1843 }
1844 UDFDecFileLinkCount(FileInfo); // decrease
1846 if(DirNdx && FreeSpace) {
1847 // FileIdent marked as 'deleted' should have an empty ICB
1848 // We shall do it only if object has parent Dir
1849 // (for ex. SDir has parent object, but has no parent Dir)
1851 DirNdx->FI_Flags &= ~UDF_FI_FLAG_SYS_ATTR;
1852 // Root Files (Root/SDir/Vat/etc.) has no FileIdent...
1853 if(FileInfo->FileIdent)
1854 RtlZeroMemory(&(FileInfo->FileIdent->icb), sizeof(long_ad));
1855 }
1856 // caller wishes to free allocation, but we can't do it due to
1857 // alive links. In this case we should just remove reference
1858 if(FreeSpace && lc) {
1859 ((icbtag*)(Dloc->FileEntry+1))->parentICBLocation.logicalBlockNum = 0;
1860 ((icbtag*)(Dloc->FileEntry+1))->parentICBLocation.partitionReferenceNum = 0;
1862 } else
1863 // if caller wishes to free file allocation &
1864 // there are no more references(links) to this file, lets do it >;->
1865 if(FreeSpace && !lc) {
1867 !UDFIsSDirDeleted(Dloc->SDirInfo) ) {
1868 // we have a Stream Dir associated...
1869 PUDF_FILE_INFO SFileInfo;
1870 // ... try to open it
1871 if(Dloc->SDirInfo) {
1873 return STATUS_CANNOT_DELETE;
1874 }
1875 // open SDir
1877 if(!OS_SUCCESS(status)) {
1878 // abort Unlink on error
1879 SFileInfo = Dloc->SDirInfo;
1880cleanup_SDir:
1881 UDFCleanUpFile__(Vcb, SFileInfo);
1882 if(SFileInfo) MyFreePool__(SFileInfo);
1884 return status;
1885 }
1886 SDirInfo = Dloc->SDirInfo;
1887 // try to perform deltree for Streams
1888 status = UDFUnlinkAllFilesInDir(Vcb, SDirInfo);
1889 if(!OS_SUCCESS(status)) {
1890 // abort Unlink on error
1891 UDFCloseFile__(Vcb, SDirInfo);
1892 SFileInfo = SDirInfo;
1893 BrutePoint();
1894 goto cleanup_SDir;
1895 }
1896 // delete SDir
1897 UDFFlushFile__(Vcb, SDirInfo);
1898 AdPrint((" "));
1899 UDFUnlinkFile__(Vcb, SDirInfo, TRUE);
1900 // close SDir
1901 UDFCloseFile__(Vcb, SDirInfo);
1902 if(UDFCleanUpFile__(Vcb, SDirInfo)) {
1903 MyFreePool__(SDirInfo);
1904#ifdef UDF_DBG
1905 } else {
1906 BrutePoint();
1907#endif // UDF_DBG
1908 }
1909 // update FileInfo
1910 ASSERT(Dloc->FileEntry);
1911 RtlZeroMemory( &(((PEXTENDED_FILE_ENTRY)(Dloc->FileEntry))->streamDirectoryICB), sizeof(long_ad));
1912 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_FE_MODIFIED;
1913 } else
1914 if(IsSDir) {
1915 // do deltree for Streams
1917 if(!OS_SUCCESS(status)) {
1919 return status;
1920 }
1921 // update parent FileInfo
1922 ASSERT(FileInfo->ParentFile->Dloc->FileEntry);
1923 RtlZeroMemory( &(((PEXTENDED_FILE_ENTRY)(FileInfo->ParentFile->Dloc->FileEntry))->streamDirectoryICB), sizeof(long_ad));
1924 FileInfo->ParentFile->Dloc->FE_Flags &= ~UDF_FE_FLAG_HAS_SDIR;
1925 FileInfo->ParentFile->Dloc->FE_Flags |= (UDF_FE_FLAG_FE_MODIFIED |
1927 FileInfo->Dloc->FE_Flags |= UDF_FE_FLAG_IS_DEL_SDIR;
1928 UDFDecFileLinkCount(FileInfo->ParentFile);
1929 }
1930 if(Dloc->DirIndex) {
1932 }
1933 // flush file
1935 UDFUnlinkDloc(Vcb, Dloc);
1936 // free allocation
1938 ASSERT(!(FileInfo->Dloc->FE_Flags & UDF_FE_FLAG_FE_MODIFIED));
1939 FileInfo->Dloc->FE_Flags &= ~UDF_FE_FLAG_FE_MODIFIED;
1940 }
1941 return STATUS_SUCCESS;
1942} // end UDFUnlinkFile__()
void UDFFreeFileAllocation(IN PVCB Vcb, IN PUDF_FILE_INFO DirInfo, IN PUDF_FILE_INFO FileInfo)
Definition: extent.cpp:2696
#define UDFRemoveFileId__(Vcb, fi)
Definition: protos.h:407
void UDFChangeFileCounter(IN PVCB Vcb, IN BOOLEAN FileCounter, IN BOOLEAN Increase)
Definition: udf_info.cpp:1520
OSSTATUS UDFOpenStreamDir__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, OUT PUDF_FILE_INFO *_SDirInfo)
Definition: udf_info.cpp:4965
BOOLEAN UDFIsDirEmpty(IN PDIR_INDEX_HDR hCurDirNdx)
Definition: udf_info.cpp:3844
OSSTATUS UDFUnlinkAllFilesInDir(IN PVCB Vcb, IN PUDF_FILE_INFO DirInfo)
Definition: udf_info.cpp:1945
#define FLUSH_FE_FOR_DEL
Definition: udf_info.h:396
#define UDFIsADirectory(FileInfo)
Definition: udf_info.h:792
#define UDF_FE_FLAG_IS_DEL_SDIR
File is Deleted Stream Dir.
Definition: udf_rel.h:333
#define UDF_FE_FLAG_HAS_DEL_SDIR
File contains pointer to Deleted Stream Dir.
Definition: udf_rel.h:331
#define STATUS_DIRECTORY_NOT_EMPTY
Definition: udferr_usr.h:167

Referenced by UDFCleanUpFcbChain(), UDFCommonCleanup(), UDFCommonCreate(), UDFCreateStreamDir__(), UDFHardLinkFile__(), UDFRenameMoveFile__(), UDFUnlinkAllFilesInDir(), UDFUnlinkFile__(), and UDFWriteSecurity().

◆ UDFUnmapRange()

OSSTATUS __fastcall UDFUnmapRange ( IN PVCB  Vcb,
IN uint32  Lba,
IN uint32  BCount 
)

Definition at line 894 of file remap.cpp.

899{
900 uint32 i, max, BS, orig;
901 PSPARING_MAP Map;
902
903 if(Vcb->SparingTable) {
904 // use sparing table for relocation
905
906 max = Vcb->SparingCount;
907 BS = Vcb->SparingBlockSize;
908 Map = Vcb->SparingTable;
909 for(i=0;i<max;i++,Map++) {
910 orig = Map->origLocation;
911 switch(orig) {
914 continue;
915 }
916 if(orig >= Lba &&
917 (orig+BS) <= (Lba+BCount)) {
918 // unmap
919 UDFPrint(("unmap %x -> %x\n", orig, Map->mappedLocation));
921 Vcb->SparingTableModified = TRUE;
922 Vcb->SparingCountFree++;
923 }
924 }
925 }
926 return STATUS_SUCCESS;
927} // end UDFUnmapRange()

Referenced by UDFMarkSpaceAsXXXNoProtect_().

◆ UDFUnPackMapping()

OSSTATUS __fastcall UDFUnPackMapping ( IN PVCB  Vcb,
IN PEXTENT_INFO  ExtInfo 
)

Definition at line 2860 of file extent.cpp.

2864{
2865 PEXTENT_MAP NewMapping;
2866 PEXTENT_MAP Mapping = ExtInfo->Mapping;
2867 uint32 LBS = Vcb->LBlockSize;
2868 uint32 len = (uint32)(UDFGetExtentLength(Mapping) >> Vcb->LBlockSizeBits);
2869 uint32 i,j, type, base, d;
2870 LONG l;
2871
2872 NewMapping = (PEXTENT_MAP)MyAllocatePoolTag__(NonPagedPool , (len+1)*sizeof(EXTENT_MAP),
2874 if(!NewMapping) return STATUS_INSUFFICIENT_RESOURCES;
2875
2876 j=0;
2877 d = LBS >> Vcb->BlockSizeBits;
2878 for(i=0; (l = (Mapping[i].extLength & UDF_EXTENT_LENGTH_MASK)); i++) {
2879 base = Mapping[i].extLocation;
2880 type = Mapping[i].extLength & UDF_EXTENT_FLAG_MASK;
2881 for(; l>=(LONG)LBS; j++) {
2882 NewMapping[j].extLength = LBS | type;
2883 NewMapping[j].extLocation = base;
2884 base+=d;
2885 l-=LBS;
2886 }
2887 }
2888 // record terminator
2889 ASSERT(NewMapping);
2890 RtlZeroMemory(&(NewMapping[j]), sizeof(EXTENT_MAP));
2892 ExtInfo->Mapping = NewMapping;
2893
2894 return STATUS_SUCCESS;
2895} // end UDFUnPackMapping()

Referenced by UDFAllocateFESpace(), and UDFRecordVAT().

◆ UDFUpdateLogicalVolInt()

OSSTATUS UDFUpdateLogicalVolInt ( PVCB  Vcb,
BOOLEAN  Close 
)

Definition at line 361 of file mount.cpp.

365{
367 uint32 i, len;
368 SIZE_T WrittenBytes;
369// uint32 lvid_count = 0;
370 uint32 pSize;
371 tag* PTag;
374 LogicalVolHeaderDesc* LVID_hd;
375 uint32* partFreeSpace;
377
378 if(Vcb->CDR_Mode)
379 return STATUS_SUCCESS;
380 if(!Vcb->LVid) {
381 return STATUS_UNSUCCESSFUL;
382 }
383
384 UDFPrint(("UDF: Updating LVID @%x (%x)\n", Vcb->LVid_loc.extLocation, Vcb->LVid_loc.extLength));
385 len = max(Vcb->LVid_loc.extLength, Vcb->BlockSize);
386 lvid = Vcb->LVid;
387 if(lvid->descTag.tagSerialNum > UDF_LVID_TTL) {
388 // TODO: allocate space for new LVID
389 }
390
391 LVID_iUse = UDFGetLVIDiUse(Vcb);
392
393 if((LVID_iUse->minUDFReadRev == Vcb->minUDFReadRev) &&
394 (LVID_iUse->minUDFWriteRev == Vcb->minUDFWriteRev) &&
395 (LVID_iUse->maxUDFWriteRev == Vcb->maxUDFWriteRev) &&
396 (LVID_iUse->numFiles == Vcb->numFiles) &&
397 (LVID_iUse->numDirs == Vcb->numDirs))
398 equal = TRUE;
399
400 LVID_iUse->minUDFReadRev = Vcb->minUDFReadRev;
401 LVID_iUse->minUDFWriteRev = Vcb->minUDFWriteRev;
402 LVID_iUse->maxUDFWriteRev = Vcb->maxUDFWriteRev;
403
404 LVID_iUse->numFiles = Vcb->numFiles;
405 LVID_iUse->numDirs = Vcb->numDirs;
406
407#if 0
409#endif
410
411 if(Close){
412 UDFPrint(("UDF: Opening LVID\n"));
414 } else {
415 UDFPrint(("UDF: Closing LVID\n"));
417 }
418
419 equal = equal && (Vcb->IntegrityType == lvid->integrityType);
420
421 // update Free Space Table
422 partFreeSpace = (uint32*)(lvid+1);
423 for(i=0; i<lvid->numOfPartitions; i++) {
424 pSize = UDFGetPartFreeSpace(Vcb, i) >> Vcb->LB2B_Bits;
425 equal = equal && (partFreeSpace[i] == pSize);
426 partFreeSpace[i] = pSize;
427 }
428
429 // Update LVID Header Descriptor
430 LVID_hd = (LogicalVolHeaderDesc*)&(lvid->logicalVolContentsUse);
431 equal = equal && (LVID_hd->uniqueID == Vcb->NextUniqueId);
432 LVID_hd->uniqueID = Vcb->NextUniqueId;
433
434 if(equal) {
435 UDFPrint(("UDF: equal Ids\n"));
436 return STATUS_SUCCESS;
437 }
438
439 PTag = &(lvid->descTag);
440 lvid->lengthOfImpUse =
442 UDFSetUpTag(Vcb, PTag,
444 sizeof(uint32)*2*lvid->numOfPartitions +
446 PTag->tagLocation);
447
448 Vcb->IntegrityType = INTEGRITY_TYPE_OPEN; // make happy auto-dirty
449 RC = UDFWriteSectors(Vcb, TRUE, PTag->tagLocation, len >> Vcb->BlockSizeBits, FALSE, (int8*)(lvid), &WrittenBytes);
450 WCacheFlushBlocks__(&(Vcb->FastCache), Vcb, PTag->tagLocation, len >> Vcb->BlockSizeBits);
451 // update it here to prevent recursion
452 Vcb->IntegrityType = lvid->integrityType;
453
454 return RC;
455} // end UDFUpdateLogicalVolInt()
#define INTEGRITY_TYPE_OPEN
Definition: ecma_167.h:357
OSSTATUS UDFWriteSectors(IN PVCB Vcb, IN BOOLEAN Translate, IN uint32 Lba, IN uint32 BCount, IN BOOLEAN Direct, IN int8 *Buffer, OUT PSIZE_T WrittenBytes)
Definition: phys_lib.cpp:4012
#define equal(x, y)
Definition: reader.cc:56
@ Close
Definition: sacdrv.h:268
uint8 logicalVolContentsUse[32]
Definition: ecma_167.h:348
uint16 tagSerialNum
Definition: ecma_167.h:143
#define UDF_LVID_TTL
Definition: udf_rel.h:517

Referenced by UDFEjectReqWaiter(), UDFUmount__(), UDFWriteInSector(), and UDFWriteSectors().

◆ UDFUpdatePartDesc()

OSSTATUS UDFUpdatePartDesc ( PVCB  Vcb,
int8 Buf 
)

Definition at line 299 of file mount.cpp.

303{
304 PartitionDesc *p = (PartitionDesc *)Buf;
305 uint32 i; // PartNdx
306 tag* PTag;
307 SIZE_T WrittenBytes;
308
309 for(i=0; i<Vcb->PartitionMaps; i++)
310 {
311 if((UDFGetPartNumByPartNdx(Vcb,i) == p->partitionNumber) &&
312 (!strcmp((int8*)&(p->partitionContents.ident), PARTITION_CONTENTS_NSR02) ||
313 !strcmp((int8*)&(p->partitionContents.ident), PARTITION_CONTENTS_NSR03)))
314 {
316
317 phd = (PPARTITION_HEADER_DESC)(p->partitionContentsUse);
318#ifdef UDF_DBG
320 // rebuild unallocatedSpaceTable
321 UDFPrint(("unallocatedSpaceTable (part %d)\n", i));
322 }
323 if(phd->freedSpaceTable.extLength) {
324 // rebuild freedSpaceTable
325 UDFPrint(("freedSpaceTable (part %d)\n", i));
326 }
327#endif // UDF_DBG
328 UDFUpdateXSpaceBitmaps(Vcb, p->partitionNumber, phd);
329 PTag = (tag*)Buf;
330 UDFSetUpTag(Vcb, PTag, PTag->descCRCLength, PTag->tagLocation);
331 UDFWriteSectors(Vcb, TRUE, PTag->tagLocation, 1, FALSE, Buf, &WrittenBytes);
332 }
333 }
334 return STATUS_SUCCESS;
335} // end UDFUpdatePartDesc()
OSSTATUS UDFUpdateXSpaceBitmaps(IN PVCB Vcb, IN uint32 PartNum, IN PPARTITION_HEADER_DESC phd)
Definition: mount.cpp:186
uint16 descCRCLength
Definition: ecma_167.h:145

Referenced by UDFUpdateVDS().

◆ UDFUpdateUSpaceDesc()

OSSTATUS UDFUpdateUSpaceDesc ( IN PVCB  Vcb,
int8 Buf 
)

◆ UDFUpdateVAT()

OSSTATUS UDFUpdateVAT ( IN void _Vcb,
IN uint32  Lba,
IN uint32 RelocTab,
IN uint32  BCount 
)

Definition at line 5316 of file udf_info.cpp.

5322{
5323#ifndef UDF_READ_ONLY_BUILD
5324 PVCB Vcb = (PVCB)_Vcb;
5325 uint16 PartNdx = (uint16)(Vcb->VatPartNdx);
5326 uint16 PartNum = (uint16)(Lba ? UDFGetPartNumByPhysLba(Vcb, Lba) : UDFGetPartNumByPartNdx(Vcb, PartNdx));
5327 if(PartNum != UDFGetPartNumByPartNdx(Vcb, PartNdx)) {
5328 UDFPrint(("UDFUpdateVAT: Write to Write-Protected partition\n"));
5330 }
5331 // !!! NOTE !!!
5332 // Both VAT copies - in-memory & on-disc
5333 // contain _relative_ addresses
5334 uint32 root = Vcb->Partitions[PartNdx].PartitionRoot;
5335 uint32 NWA = Vcb->NWA-root;
5336 uint32 i;
5337 uint32 CurLba;
5338
5339 if(!Vcb->Vat) return STATUS_SUCCESS;
5340
5341 for(i=0; i<BCount; i++, NWA++) {
5342 if((CurLba = (RelocTab ? RelocTab[i] : (Lba+i)) - root) >= Vcb->VatCount)
5343 Vcb->VatCount = CurLba+1;
5344 Vcb->Vat[CurLba] = NWA;
5345 }
5346 return STATUS_SUCCESS;
5347#else //UDF_READ_ONLY_BUILD
5349#endif //UDF_READ_ONLY_BUILD
5350} // end UDFUpdateVAT()
struct _VCB * PVCB
Definition: fatstruc.h:557
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161

Referenced by UDFMountVolume(), and UDFVerifyVolume().

◆ UDFUpdateVDS()

OSSTATUS UDFUpdateVDS ( IN PVCB  Vcb,
IN uint32  block,
IN uint32  lastblock,
IN uint32  flags 
)

Definition at line 673 of file mount.cpp.

679{
681 int8* Buf = (int8*)DbgAllocatePool(NonPagedPool,Vcb->LBlockSize);
683 uint32 i,j;
685
686 if (!Buf) return STATUS_INSUFFICIENT_RESOURCES;
688 if(!OS_SUCCESS(status = UDFReadVDS(Vcb, block, lastblock, (PUDF_VDS_RECORD)&vds, Buf))) {
689 DbgFreePool(Buf);
690 return status;
691 }
692
693/*
694 // update USD (if any)
695 for (i=0; i<VDS_POS_LENGTH; i++) {
696 if (vds[i].block) {
697 status = UDFReadTagged(Vcb, Buf, vds[i].block, vds[i].block, &ident);
698 if(OS_SUCCESS(status) && (i == VDS_POS_PARTITION_DESC)) {
699 // load partition descriptor(s)
700 int8* Buf2 = (int8*)DbgAllocatePool(NonPagedPool,Vcb->BlockSize);
701 if (!Buf2) {
702 DbgFreePool(Buf);
703 return STATUS_INSUFFICIENT_RESOURCES;
704 }
705 for (j=vds[i].block+1; j<vds[VDS_POS_TERMINATING_DESC].block; j++) {
706 UDFReadTagged(Vcb,Buf2, j, j, &ident);
707 if (ident == TID_UNALLOC_SPACE_DESC)
708 // This implememtation doesn't support USD ;) recording
709 // So, we'll make'em blank, but record all bitmaps
710 UDFUpdateUSpaceDesc(Vcb,Buf2);
711 }
712 DbgFreePool(Buf2);
713 break;
714 }
715 }
716 }*/
717 for (i=0; i<VDS_POS_LENGTH; i++) {
718 if (vds[i].block) {
719 status = UDFReadTagged(Vcb, Buf, vds[i].block, vds[i].block, &ident);
720 if(!OS_SUCCESS(status))
721 continue;
722 // update XBMs
724 if(!(flags & 1))
725 continue;
726 // update partition descriptor(s)
727 int8* Buf2 = (int8*)DbgAllocatePool(NonPagedPool,Vcb->BlockSize);
728 if (!Buf2) {
729 DbgFreePool(Buf);
731 }
733 for (j=vds[i].block+1; j<vds[VDS_POS_TERMINATING_DESC].block; j++) {
734 UDFReadTagged(Vcb,Buf2, j, j, &ident);
737 }
738 DbgFreePool(Buf2);
739// continue;
740 } else
741 // update Vol Ident Desc
744 if(!OS_SUCCESS(status))
745 continue;
746 }
747 }
748 }
749
750 DbgFreePool(Buf);
751 return status;
752} // end UDFUpdateVDS()
OSSTATUS UDFUpdateLogicalVol(IN PVCB Vcb, IN UDF_VDS_RECORD Lba, IN PUNICODE_STRING VolIdent)
Definition: mount.cpp:598
OSSTATUS UDFUpdatePartDesc(PVCB Vcb, int8 *Buf)
Definition: mount.cpp:299

Referenced by UDFEjectReqWaiter(), and UDFUmount__().

◆ UDFUpdateVolIdent()

OSSTATUS UDFUpdateVolIdent ( IN PVCB  Vcb,
IN UDF_VDS_RECORD  Lba,
IN PUNICODE_STRING  VolIdent 
)

Definition at line 801 of file mount.cpp.

806{
807#define CUR_IDENT_SZ (sizeof(pvoldesc->volIdent))
812 SIZE_T WrittenBytes;
813
814 if(!pvoldesc) return STATUS_INSUFFICIENT_RESOURCES;
815
816 UDFPrint(("UDF: Updating PVD @%x (%x)\n", Lba.block, Vcb->BlockSize));
817
818 status = UDFSetDstring(&(Vcb->VolIdent), (dstring*)&CS0, CUR_IDENT_SZ);
819 if(!OS_SUCCESS(status)) {
822 }
823 goto Err_SetVI;
824 }
825
826 if(!Lba.block) {
828 goto Err_SetVI;
829 }
830 status = UDFReadTagged(Vcb, (int8*)pvoldesc, Lba.block, Lba.block, &ident);
831 if(!OS_SUCCESS(status)) goto Err_SetVI;
834 goto Err_SetVI;
835 }
836
837 if(RtlCompareMemory(pvoldesc->volIdent, CS0, CUR_IDENT_SZ) == CUR_IDENT_SZ) {
838 // no changes
840 goto Err_SetVI;
841 }
842 RtlCopyMemory(pvoldesc->volIdent, CS0, CUR_IDENT_SZ);
843
844 pvoldesc->descTag.tagSerialNum --;
845 UDFSetUpTag(Vcb, (tag*)pvoldesc, pvoldesc->descTag.descCRCLength, Lba.block);
846
847 status = UDFWriteSectors(Vcb, TRUE, Lba.block, 1, FALSE, (int8*)pvoldesc, &WrittenBytes);
848Err_SetVI:
849 MyFreePool__(pvoldesc);
850 return status;
851
852#undef CUR_IDENT_SZ
853} // end UDFUpdateVolIdent()
OSSTATUS __fastcall UDFSetDstring(IN PUNICODE_STRING UName, IN dstring *Dest, IN uint32 Length)
Definition: mount.cpp:757
#define STATUS_INVALID_VOLUME_LABEL
Definition: udferr_usr.h:156

Referenced by UDFEjectReqWaiter(), and UDFUmount__().

◆ UDFUpdateXSpaceBitmaps()

OSSTATUS UDFUpdateXSpaceBitmaps ( IN PVCB  Vcb,
IN uint32  PartNum,
IN PPARTITION_HEADER_DESC  phd 
)

Definition at line 186 of file mount.cpp.

191{
192 uint32 i,j,d;
193 uint32 plen, pstart, pend;
194 int8* bad_bm;
195 int8* old_bm;
196 int8* new_bm;
197 int8* fpart_bm;
198 int8* upart_bm;
199 OSSTATUS status, status2;
200 int8* USBM=NULL;
201 int8* FSBM=NULL;
202 uint32 USl, FSl;
203 EXTENT_INFO FSBMExtInfo, USBMExtInfo;
204// lb_addr locAddr;
205 SIZE_T WrittenBytes;
206
208
209 plen = UDFPartLen(Vcb, PartNum);
210// locAddr.partitionReferenceNum = (uint16)PartNum;
211 // prepare bitmaps for updating
212
213 status = UDFPrepareXSpaceBitmap(Vcb, &(phd->unallocatedSpaceBitmap), &USBMExtInfo, &USBM, &USl);
214 status2 = UDFPrepareXSpaceBitmap(Vcb, &(phd->freedSpaceBitmap), &FSBMExtInfo, &FSBM, &FSl);
215 if(!OS_SUCCESS(status) ||
216 !OS_SUCCESS(status2)) {
217 BrutePoint();
218 }
219
220 pstart = UDFPartStart(Vcb, PartNum);
221 new_bm = Vcb->FSBM_Bitmap;
222 old_bm = Vcb->FSBM_OldBitmap;
223 bad_bm = Vcb->BSBM_Bitmap;
224
226 (status2 == STATUS_INSUFFICIENT_RESOURCES)) {
227 // try to recover insufficient resources
228 if(USl && USBMExtInfo.Mapping) {
229 USl -= sizeof(SPACE_BITMAP_DESC);
230 status = UDFWriteExtent(Vcb, &USBMExtInfo, sizeof(SPACE_BITMAP_DESC), USl, FALSE, new_bm, &WrittenBytes);
231#ifdef UDF_DBG
232 } else {
233 UDFPrint(("Can't update USBM\n"));
234#endif // UDF_DBG
235 }
236 if(USBMExtInfo.Mapping) MyFreePool__(USBMExtInfo.Mapping);
237
238 if(FSl && FSBMExtInfo.Mapping) {
239 FSl -= sizeof(SPACE_BITMAP_DESC);
240 status2 = UDFWriteExtent(Vcb, &FSBMExtInfo, sizeof(SPACE_BITMAP_DESC), FSl, FALSE, new_bm, &WrittenBytes);
241 } else {
242 status2 = status;
243 UDFPrint(("Can't update FSBM\n"));
244 }
245 if(FSBMExtInfo.Mapping) MyFreePool__(FSBMExtInfo.Mapping);
246 } else {
247 // normal way to record BitMaps
248 if(USBM) upart_bm = USBM + sizeof(SPACE_BITMAP_DESC);
249 if(FSBM) fpart_bm = FSBM + sizeof(SPACE_BITMAP_DESC);
250 pend = min(pstart + plen, Vcb->FSBM_BitCount);
251
252 d=1<<Vcb->LB2B_Bits;
253 // if we have some bad bits, mark corresponding area as BAD
254 if(bad_bm) {
255 for(i=pstart; i<pend; i++) {
256 if(UDFGetBadBit(bad_bm, i)) {
257 // TODO: would be nice to add these blocks to unallocatable space
258 UDFSetUsedBits(new_bm, i & ~(d-1), d);
259 }
260 }
261 }
262 j=0;
263 for(i=pstart; i<pend; i+=d) {
264 if(UDFGetUsedBit(old_bm, i) && UDFGetFreeBit(new_bm, i)) {
265 // sector was deallocated during last session
266 if(USBM) UDFSetFreeBit(upart_bm, j);
267 if(FSBM) UDFSetFreeBit(fpart_bm, j);
268 } else if(UDFGetUsedBit(new_bm, i)) {
269 // allocated
270 if(USBM) UDFSetUsedBit(upart_bm, j);
271 if(FSBM) UDFSetUsedBit(fpart_bm, j);
272 }
273 j++;
274 }
275 // flush updates
276 if(USBM) {
277 status = UDFWriteExtent(Vcb, &USBMExtInfo, 0, USl, FALSE, USBM, &WrittenBytes);
278 DbgFreePool(USBM);
279 MyFreePool__(USBMExtInfo.Mapping);
280 }
281 if(FSBM) {
282 status2 = UDFWriteExtent(Vcb, &FSBMExtInfo, 0, FSl, FALSE, FSBM, &WrittenBytes);
283 DbgFreePool(FSBM);
284 MyFreePool__(FSBMExtInfo.Mapping);
285 } else {
286 status2 = status;
287 }
288 }
289
290 if(!OS_SUCCESS(status))
291 return status;
292 return status2;
293} // end UDFUpdateXSpaceBitmaps()
OSSTATUS UDFPrepareXSpaceBitmap(IN PVCB Vcb, IN OUT PSHORT_AD XSpaceBitmap, IN OUT PEXTENT_INFO XSBMExtInfo, IN OUT int8 **XSBM, IN OUT uint32 *XSl)
Definition: mount.cpp:52

Referenced by UDFUpdatePartDesc().

◆ UDFVerifySequence()

OSSTATUS UDFVerifySequence ( IN PDEVICE_OBJECT  DeviceObject,
IN PVCB  Vcb,
IN uint32  block,
IN uint32  lastblock,
OUT lb_addr fileset 
)

Definition at line 2461 of file mount.cpp.

2468{
2470 int8* Buf = (int8*)MyAllocatePool__(NonPagedPool,Vcb->BlockSize);
2472// GenericDesc *gd;
2473 uint32 i,j;
2474 uint16 ident;
2475 int8* Buf2 = NULL;
2476
2477 _SEH2_TRY {
2479 if(!block) try_return (RC = STATUS_SUCCESS);
2481 if(!OS_SUCCESS(RC = UDFReadVDS(Vcb, block, lastblock, (PUDF_VDS_RECORD)&vds, Buf)))
2482 try_return(RC);
2483
2484 for (i=0; i<VDS_POS_LENGTH; i++)
2485 {
2486 if(vds[i].block)
2487 {
2488 if(!OS_SUCCESS(RC = UDFReadTagged(Vcb, Buf, vds[i].block, vds[i].block, &ident)))
2489 try_return(RC);
2490 UDFRegisterFsStructure(Vcb, vds[i].block, Vcb->BlockSize);
2491
2492 /* if(i == VDS_POS_PRIMARY_VOL_DESC)
2493 UDFLoadPVolDesc(Vcb,Buf);
2494 else if(i == VDS_POS_LOGICAL_VOL_DESC) {
2495 RC = UDFLoadLogicalVol(DeviceObject,Vcb, Buf, fileset);
2496 if(!OS_SUCCESS(RC)) try_return(RC);
2497 }
2498 else*/ if(i == VDS_POS_PARTITION_DESC)
2499 {
2500 Buf2 = (int8*)MyAllocatePool__(NonPagedPool,Vcb->BlockSize);
2502 RC = UDFVerifyPartDesc(Vcb,Buf);
2503 if(!OS_SUCCESS(RC)) try_return(RC);
2504 for (j=vds[i].block+1; j<vds[VDS_POS_TERMINATING_DESC].block; j++)
2505 {
2506 RC = UDFReadTagged(Vcb,Buf2, j, j, &ident);
2507 if(!OS_SUCCESS(RC)) try_return(RC);
2508 UDFRegisterFsStructure(Vcb, j, Vcb->BlockSize);
2509// gd = (struct GenericDesc *)Buf2;
2510 if(ident == TID_PARTITION_DESC) {
2511 RC = UDFVerifyPartDesc(Vcb,Buf2);
2512 if(!OS_SUCCESS(RC)) try_return(RC);
2513 } else if(ident == TID_UNALLOC_SPACE_DESC) {
2515 Vcb->Modified = FALSE;
2516 if(!OS_SUCCESS(RC))
2517 try_return(RC);
2518 }
2519 }
2520 MyFreePool__(Buf2);
2521 Buf2 = NULL;
2522 }
2523 }
2524 }
2525try_exit: NOTHING;
2526
2527 } _SEH2_FINALLY {
2528 if(Buf) MyFreePool__(Buf);
2529 if(Buf2) MyFreePool__(Buf2);
2530 } _SEH2_END;
2531
2532 return RC;
2533} // end UDFVerifySequence()
OSSTATUS UDFVerifyPartDesc(PVCB Vcb, int8 *Buf)
Definition: mount.cpp:2126
OSSTATUS UDFVerifyFreeSpaceBitmap(IN PVCB Vcb, IN uint32 PartNdx, IN PPARTITION_HEADER_DESC phd, IN uint32 Lba)
Definition: mount.cpp:1821

Referenced by UDFLoadPartition().

◆ UDFVFlush()

VOID UDFVFlush ( IN PVCB  Vcb)

Definition at line 742 of file remap.cpp.

745{
746 PUDF_VERIFY_CTX VerifyCtx = &Vcb->VerifyCtx;
747
748 if(!VerifyCtx->VInited) {
749 return;
750 }
751
752 UDFPrint(("UDFVFlush: wait for completion\n"));
753 UDFVWaitQueued(VerifyCtx);
754
756
757 UDFPrint(("UDFVFlush: wait for completion (2)\n"));
758 UDFVWaitQueued(VerifyCtx);
759} // end UDFVFlush()
VOID UDFVWaitQueued(PUDF_VERIFY_CTX VerifyCtx)
Definition: remap.cpp:109
VOID UDFVVerify(IN PVCB Vcb, IN ULONG Flags)
Definition: remap.cpp:601
BOOLEAN VInited
Definition: udf_rel.h:553
#define UFD_VERIFY_FLAG_FORCE
Definition: udf_info.h:1302

Referenced by UDFCommonDeviceControl(), UDFEjectReqWaiter(), UDFFlushLogicalVolume(), and UDFUmount__().

◆ UDFVForget()

OSSTATUS UDFVForget ( IN PVCB  Vcb,
IN uint32  BCount,
IN uint32  LBA,
IN uint32  Flags 
)

Definition at line 486 of file remap.cpp.

492{
494 PUDF_VERIFY_ITEM vItem;
495 PUDF_VERIFY_CTX VerifyCtx = &Vcb->VerifyCtx;
496 ULONG i;
497 ULONG n;
499
500 if(!VerifyCtx->VInited) {
501 return STATUS_UNSUCCESSFUL;
502 }
503
505
506 for(i=0, n=0; i<BCount; i++) {
507 if(UDFGetBit(VerifyCtx->StoredBitMap, LBA+i)) {
508 // some blocks are remembered
509 n++;
510 }
511 }
512
513 if(!n) {
514 // no blocks are remembered
515 UDFReleaseResource(&(VerifyCtx->VerifyLock));
516 return STATUS_SUCCESS;
517 }
518
519 Link = VerifyCtx->vrfList.Flink;
520 i = 0;
521 while(Link != &(VerifyCtx->vrfList)) {
522 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
523 Link = Link->Flink;
524 if(vItem->lba >= LBA && vItem->lba < LBA+BCount) {
525 i++;
526 UDFVRemoveBlock(VerifyCtx, vItem);
527 if(i >= n) {
528 // no more blocks expected
529 break;
530 }
531 }
532 }
533
534 UDFReleaseResource(&(VerifyCtx->VerifyLock));
535 return status;
536
537} // end UDFVForget()
VOID UDFVRemoveBlock(PUDF_VERIFY_CTX VerifyCtx, PUDF_VERIFY_ITEM vItem)
Definition: remap.cpp:211
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
ERESOURCE VerifyLock
Definition: udf_rel.h:549
LIST_ENTRY vrfList
Definition: udf_rel.h:548
uint8 * StoredBitMap
Definition: udf_rel.h:546
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
static int Link(const char **args)
Definition: vfdcmd.c:2414

◆ UDFVInit()

OSSTATUS UDFVInit ( IN PVCB  Vcb)

Definition at line 54 of file remap.cpp.

57{
58 PUDF_VERIFY_CTX VerifyCtx = &Vcb->VerifyCtx;
59 uint32 i;
61 BOOLEAN res_inited = FALSE;
62
63 if(VerifyCtx->VInited) {
64 UDFPrint(("Already inited\n"));
65 return STATUS_SUCCESS;
66 }
67
68 _SEH2_TRY {
69 RtlZeroMemory(VerifyCtx, sizeof(UDF_VERIFY_CTX));
70 if(!Vcb->VerifyOnWrite) {
71 UDFPrint(("Verify is disabled\n"));
72 return STATUS_SUCCESS;
73 }
74 if(Vcb->CDR_Mode) {
75 UDFPrint(("Verify is not intended for CD/DVD-R\n"));
76 return STATUS_SUCCESS;
77 }
80 }
81 res_inited = TRUE;
82 VerifyCtx->ItemCount = 0;
83 VerifyCtx->StoredBitMap = (uint8*)DbgAllocatePoolWithTag(PagedPool, (i = (Vcb->LastPossibleLBA+1+7)>>3), 'mNWD' );
84 if(VerifyCtx->StoredBitMap) {
85 RtlZeroMemory(VerifyCtx->StoredBitMap, i);
86 } else {
87 UDFPrint(("Can't alloc verify bitmap for %x blocks\n", Vcb->LastPossibleLBA));
89 }
90 InitializeListHead(&(VerifyCtx->vrfList));
92 VerifyCtx->WaiterCount = 0;
93 VerifyCtx->VInited = TRUE;
94
95try_exit: NOTHING;
96
98
99 if(!OS_SUCCESS(status)) {
100 if(res_inited) {
101 ExDeleteResourceLite(&(VerifyCtx->VerifyLock));
102 }
103 }
104 } _SEH2_END;
105 return status;
106} // end UDFVInit()
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ExDeleteResourceLite(res)
Definition: env_spec_w32.h:647
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
@ SynchronizationEvent
ULONG ItemCount
Definition: udf_rel.h:547
KEVENT vrfEvent
Definition: udf_rel.h:550
uint32 WaiterCount
Definition: udf_rel.h:551

Referenced by UDFCommonDeviceControl(), UDFMountVolume(), and UDFVerifyVolume().

◆ UDFVIsStored()

__inline BOOLEAN __fastcall UDFVIsStored ( IN PVCB  Vcb,
IN lba_t  lba 
)

Definition at line 1320 of file udf_info.h.

1324{
1325 if(!Vcb->VerifyCtx.VInited)
1326 return FALSE;
1327 return UDFGetBit(Vcb->VerifyCtx.StoredBitMap, lba);
1328} // end UDFVIsStored()

◆ UDFVRead()

OSSTATUS UDFVRead ( IN PVCB  Vcb,
IN void Buffer,
IN uint32  BCount,
IN uint32  LBA,
IN uint32  Flags 
)

Definition at line 375 of file remap.cpp.

383{
385 PUDF_VERIFY_ITEM vItem;
386 PUDF_VERIFY_CTX VerifyCtx = &Vcb->VerifyCtx;
387 ULONG crc;
388 ULONG i;
389 ULONG n;
391 uint32* bm;
392
393 if(!VerifyCtx->VInited) {
394 return STATUS_SUCCESS;
395 //return STATUS_UNSUCCESSFUL;
396 }
397
399
400 for(i=0, n=0; i<BCount; i++) {
401 if(UDFGetBit(VerifyCtx->StoredBitMap, LBA+i)) {
402 // some blocks are remembered
403 n++;
404 }
405 }
406
407 if(!n) {
408 // no blocks are remembered
409 UDFReleaseResource(&(VerifyCtx->VerifyLock));
410 return STATUS_SUCCESS;
411 }
412
413 Link = VerifyCtx->vrfList.Flink;
414 i=0;
415 while(Link != &(VerifyCtx->vrfList)) {
416 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
417 Link = Link->Flink;
418 if(vItem->lba >= LBA && vItem->lba < LBA+BCount) {
419 ASSERT(UDFGetBit(VerifyCtx->StoredBitMap, vItem->lba));
420 i++;
421 if(!(Flags & PH_READ_VERIFY_CACHE)) {
422 crc = crc32((PUCHAR)Buffer+(vItem->lba - LBA)*Vcb->BlockSize, Vcb->BlockSize);
423 if(vItem->crc != crc) {
424 UDFPrint(("UDFVRead: stored %x != %x\n", vItem->crc, crc));
425 RtlCopyMemory((PUCHAR)Buffer+(vItem->lba - LBA)*Vcb->BlockSize, vItem->Buffer, Vcb->BlockSize);
427
428 if(!(bm = (uint32*)(Vcb->BSBM_Bitmap))) {
429 crc = (Vcb->LastPossibleLBA+1+7) >> 3; // reuse 'crc' variable
430 bm = (uint32*)(Vcb->BSBM_Bitmap = (int8*)DbgAllocatePoolWithTag(NonPagedPool, crc, 'mNWD' ));
431 if(bm) {
432 RtlZeroMemory(bm, crc);
433 } else {
434 UDFPrint(("Can't alloc BSBM for %x blocks\n", Vcb->LastPossibleLBA));
435 }
436 }
437 if(bm) {
438 UDFSetBit(bm, vItem->lba);
439 UDFPrint(("Set BB @ %#x\n", vItem->lba));
440 }
441#ifdef _BROWSE_UDF_
442 bm = (uint32*)(Vcb->FSBM_Bitmap);
443 if(bm) {
444 UDFSetUsedBit(bm, vItem->lba);
445 UDFPrint(("Set BB @ %#x as used\n", vItem->lba));
446 }
447#endif //_BROWSE_UDF_
448 } else {
449 // ok
450 }
451 } else {
452 UDFPrint(("UDFVRead: get cached @ %x\n", vItem->lba));
453 RtlCopyMemory((PUCHAR)Buffer+(vItem->lba - LBA)*Vcb->BlockSize, vItem->Buffer, Vcb->BlockSize);
454 }
455 if(i >= n) {
456 // no more blocks expected
457 break;
458 }
459 }
460 }
461
463 // ok, forget this, no errors found
464 Link = VerifyCtx->vrfList.Flink;
465 i = 0;
466 while(Link != &(VerifyCtx->vrfList)) {
467 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
468 Link = Link->Flink;
469 if(vItem->lba >= LBA && vItem->lba < LBA+BCount) {
470 i++;
471 UDFVRemoveBlock(VerifyCtx, vItem);
472 if(i >= n) {
473 // no more blocks expected
474 break;
475 }
476 }
477 }
478 }
479
480 UDFReleaseResource(&(VerifyCtx->VerifyLock));
481 return status;
482
483} // end UDFVRead()
PUCHAR Buffer
Definition: remap.cpp:25
#define PH_READ_VERIFY_CACHE
Definition: udf_info.h:1271
#define UDFSetBit(arr, bit)
Definition: udf_info.h:1181
#define PH_FORGET_VERIFIED
Definition: udf_info.h:1270
#define PH_KEEP_VERIFY_CACHE
Definition: udf_info.h:1272
#define STATUS_FT_WRITE_RECOVERY
Definition: udferr_usr.h:126

Referenced by UDFPhReadSynchronous(), and UDFVWorkItem().

◆ UDFVRelease()

VOID UDFVRelease ( IN PVCB  Vcb)

Definition at line 132 of file remap.cpp.

135{
136 PUDF_VERIFY_CTX VerifyCtx = &Vcb->VerifyCtx;
138 PUDF_VERIFY_ITEM vItem;
139
140 if(!VerifyCtx->VInited) {
141 return;
142 }
143
144 UDFPrint(("UDFVRelease: wait for completion\n"));
145 UDFVWaitQueued(VerifyCtx);
146
148
149 Link = VerifyCtx->vrfList.Flink;
150
151 while(Link != &(VerifyCtx->vrfList)) {
152 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
153 Link = Link->Flink;
154 //DbgFreePool(vItem);
155 UDFVRemoveBlock(VerifyCtx, vItem);
156 }
157 VerifyCtx->VInited = FALSE;
158
159 UDFReleaseResource(&(VerifyCtx->VerifyLock));
160
161 ExDeleteResourceLite(&(VerifyCtx->VerifyLock));
162 DbgFreePool(VerifyCtx->StoredBitMap);
163
164 RtlZeroMemory(VerifyCtx, sizeof(UDF_VERIFY_CTX));
165
166 return;
167} // end UDFVRelease()

Referenced by UDFCommonDeviceControl(), and UDFReleaseVCB().

◆ UDFVVerify()

VOID UDFVVerify ( IN PVCB  Vcb,
IN ULONG  Flags 
)

Definition at line 601 of file remap.cpp.

605{
606 PUDF_VERIFY_CTX VerifyCtx = &Vcb->VerifyCtx;
608 PUDF_VERIFY_ITEM vItem;
609 PUDF_VERIFY_REQ VerifyReq = NULL;
610 ULONG len, max_len=0;
611 lba_t prev_lba;
612 //PUCHAR tmp_buff;
613 ULONG i;
614 BOOLEAN do_vrf = FALSE;
615
616 if(!VerifyCtx->VInited) {
617 return;
618 }
619 if(VerifyCtx->QueuedCount) {
621 UDFPrint((" wait for verify flush\n"));
622 goto wait;
623 }
624 UDFPrint((" verify flush already queued\n"));
625 return;
626 }
627
629 if(VerifyCtx->ItemCount < UDF_MAX_VERIFY_CACHE) {
630 return;
631 }
632
633 }
636 }
637
639 i = VerifyCtx->ItemCount;
640 } else {
641 if(VerifyCtx->ItemCount >= UDF_MAX_VERIFY_CACHE) {
642 i = VerifyCtx->ItemCount - UDF_VERIFY_CACHE_LOW;
643 } else {
644 i = min(UDF_VERIFY_CACHE_GRAN, VerifyCtx->ItemCount);
645 }
646 }
647
648 Link = VerifyCtx->vrfList.Flink;
649 prev_lba = -2;
650 len = 0;
651
652 while(i) {
653 ASSERT(Link != &(VerifyCtx->vrfList));
654/*
655 if(Link == &(VerifyCtx->vrfList)) {
656 if(!len)
657 break;
658 i=1;
659 goto queue_req;
660 }
661*/
662 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
663 Link = Link->Flink;
664
665 //
666 if(!vItem->queued && (prev_lba+len == vItem->lba)) {
667 vItem->queued = TRUE;
668 len++;
669 } else {
670 if(len) {
671 do_vrf = TRUE;
672 } else {
673 len = 1;
674 prev_lba = vItem->lba;
675 }
676 }
677 if((i == 1) && len) {
678 do_vrf = TRUE;
679 }
680 if(len >= 0x100) {
681 do_vrf = TRUE;
682 }
683 if(do_vrf) {
684//queue_req:
685 if(!VerifyReq) {
687 if(VerifyReq) {
688 RtlZeroMemory(VerifyReq, sizeof(UDF_VERIFY_REQ));
689 VerifyReq->Vcb = Vcb;
690 }
691 }
692 if(VerifyReq) {
693
694 VerifyReq->vr[VerifyReq->nReq].lba = prev_lba;
695 VerifyReq->vr[VerifyReq->nReq].BCount = len;
696 VerifyReq->nReq++;
697 if(max_len < len) {
698 max_len = len;
699 }
700
701 if((VerifyReq->nReq >= MAX_VREQ_RANGES) || (i == 1)) {
702
703 VerifyReq->Buffer = (PUCHAR)DbgAllocatePoolWithTag(NonPagedPool, max_len * Vcb->BlockSize, 'bNWD');
704 if(VerifyReq->Buffer) {
705 InterlockedIncrement((PLONG)&(VerifyCtx->QueuedCount));
706#ifndef _CONSOLE
707 ExInitializeWorkItem( &(VerifyReq->VerifyItem),
709 VerifyReq );
711#else
712 UDFVWorkItem(VerifyReq);
713#endif
714 } else {
715 DbgFreePool(VerifyReq);
716 }
717 VerifyReq = NULL;
718 max_len = 0;
719 } else {
720 }
721 }
722 len = 1;
723 prev_lba = vItem->lba;
724 do_vrf = FALSE;
725 }
726 i--;
727 }
728
730 UDFReleaseResource(&(VerifyCtx->VerifyLock));
731 }
733wait:
734 UDFPrint(("UDFVVerify: wait for completion\n"));
735 UDFVWaitQueued(VerifyCtx);
736 }
737
738 return;
739} // end UDFVVerify()
#define InterlockedIncrement
Definition: armddk.h:53
uint32 lba_t
Definition: platform.h:20
#define MAX_VREQ_RANGES
Definition: remap.cpp:35
struct _UDF_VERIFY_REQ * PUDF_VERIFY_REQ
VOID NTAPI UDFVWorkItem(PVOID Context)
Definition: remap.cpp:541
uint32 QueuedCount
Definition: udf_rel.h:552
BOOLEAN queued
Definition: remap.cpp:27
PUCHAR Buffer
Definition: remap.cpp:39
ULONG nReq
Definition: remap.cpp:40
WORK_QUEUE_ITEM VerifyItem
Definition: remap.cpp:43
UDF_VERIFY_REQ_RANGE vr[MAX_VREQ_RANGES]
Definition: remap.cpp:41
#define UDF_MAX_VERIFY_CACHE
Definition: udf_info.h:1255
#define UFD_VERIFY_FLAG_WAIT
Definition: udf_info.h:1303
#define UDF_VERIFY_CACHE_GRAN
Definition: udf_info.h:1257
#define UFD_VERIFY_FLAG_BG
Definition: udf_info.h:1304
#define UFD_VERIFY_FLAG_LOCKED
Definition: udf_info.h:1305
#define UDF_VERIFY_CACHE_LOW
Definition: udf_info.h:1256
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:723
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
@ CriticalWorkQueue
Definition: extypes.h:189

Referenced by UDFCommonWrite(), UDFEjectReqWaiter(), UDFVFlush(), and UDFVWrite().

◆ UDFVWrite()

OSSTATUS UDFVWrite ( IN PVCB  Vcb,
IN void Buffer,
IN uint32  BCount,
IN uint32  LBA,
IN uint32  Flags 
)

Definition at line 225 of file remap.cpp.

233{
235 PUDF_VERIFY_ITEM vItem;
236 //PUDF_VERIFY_ITEM vItem1;
237 PUDF_VERIFY_CTX VerifyCtx = &Vcb->VerifyCtx;
238 ULONG i;
239 ULONG n;
240 //uint32 prev_lba;
241
242 if(!VerifyCtx->VInited) {
243 return STATUS_SUCCESS;
244 }
245
247
248 for(i=0, n=0; i<BCount; i++) {
249 if(UDFGetBit(VerifyCtx->StoredBitMap, LBA+i)) {
250 // some blocks are remembered
251 n++;
252 }
253 }
254
255 if(n == BCount) {
256 // update all blocks
257 n = 0;
258 Link = VerifyCtx->vrfList.Blink;
259 while(Link != &(VerifyCtx->vrfList)) {
260 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
261 Link = Link->Blink;
262 if(vItem->lba >= LBA && vItem->lba < LBA+BCount) {
263 ASSERT(UDFGetBit(VerifyCtx->StoredBitMap, vItem->lba));
264 UDFVUpdateBlock(Vcb, ((PUCHAR)Buffer)+(vItem->lba-LBA)*Vcb->BlockSize, vItem);
265 n++;
266 if(n == BCount) {
267 // all updated
268 break;
269 }
270 }
271 }
272 } else
273 if(n) {
274#if 0
275 // find remembered blocks (the 1st one)
276 Link = VerifyCtx->vrfList.Blink;
277 while(Link != &(VerifyCtx->vrfList)) {
278 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
279 Link = Link->Blink;
280 if(vItem->lba >= LBA && vItem->lba < LBA+BCount) {
281 //UDFVRemoveBlock(VerifyCtx, vItem);
282 break;
283 }
284 }
285
286 // check if contiguous
287 i=1;
288 prev_lba = vItem->lba;
289 vItem1 = vItem;
290 Link = Link->Blink;
291 while((i < n) && (Link != &(VerifyCtx->vrfList))) {
292 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
293 Link = Link->Blink;
294 if(vItem->lba > LBA || vItem->lba >= LBA+BCount) {
295 // end
296 break;
297 }
298 if(vItem->lba < prev_lba) {
299 // not sorted
300 break;
301 }
302 prev_lba = vItem->lba;
303 i++;
304 }
305
306 if(i == n) {
307 // cont
308 } else {
309 // drop all and add again
310 }
311
312 vItem1 = vItem;
313 for(i=0; i<BCount; i++) {
314 if(vItem->lba == LBA+i) {
315 ASSERT(UDFGetBit(VerifyCtx->StoredBitMap, LBA+i));
316 UDFVUpdateBlock(Vcb, ((PUCHAR)Buffer)+i*Vcb->BlockSize, vItem);
317 continue;
318 }
319 if(vItem1->lba == LBA+i) {
320 ASSERT(UDFGetBit(VerifyCtx->StoredBitMap, LBA+i));
321 UDFVUpdateBlock(Vcb, ((PUCHAR)Buffer)+i*Vcb->BlockSize, vItem1);
322 continue;
323 }
324 if(vItem1->lba > LBA+i) {
325 // just insert this block
326 ASSERT(!UDFGetBit(VerifyCtx->StoredBitMap, LBA+i));
327 UDFVStoreBlock(Vcb, LBA+i, ((PUCHAR)Buffer)+i*Vcb->BlockSize, &(vItem1->vrfList));
328 } else {
329 vItem = CONTAINING_RECORD( vItem->vrfList.Blink, UDF_VERIFY_ITEM, vrfList );
330 }
331 }
332#else
333 Link = VerifyCtx->vrfList.Blink;
334 i=0;
335 while(Link != &(VerifyCtx->vrfList)) {
336 vItem = CONTAINING_RECORD( Link, UDF_VERIFY_ITEM, vrfList );
337 Link = Link->Blink;
338 if(vItem->lba >= LBA && vItem->lba < LBA+BCount) {
339 UDFVRemoveBlock(VerifyCtx, vItem);
340 i++;
341 if(i == n) {
342 // all killed
343 break;
344 }
345 }
346 }
347 goto remember_all;
348#endif
349
350 } else {
351remember_all:
352 // remember all blocks
353 for(i=0; i<BCount; i++) {
354 ASSERT(!UDFGetBit(VerifyCtx->StoredBitMap, LBA+i));
355 UDFVStoreBlock(Vcb, LBA+i, ((PUCHAR)Buffer)+i*Vcb->BlockSize, &(VerifyCtx->vrfList));
356 }
357 }
358
359 if(VerifyCtx->ItemCount > UDF_MAX_VERIFY_CACHE) {
361 }
362
363 UDFReleaseResource(&(VerifyCtx->VerifyLock));
364
365 if(VerifyCtx->ItemCount > UDF_MAX_VERIFY_CACHE*2) {
366 //UDFVVerify(Vcb, UFD_VERIFY_FLAG_LOCKED);
367 // TODO: make some delay
368 }
369
370 return STATUS_SUCCESS;
371
372} // end UDFVWrite()
PUDF_VERIFY_ITEM UDFVStoreBlock(IN PVCB Vcb, IN uint32 LBA, IN PVOID Buffer, PLIST_ENTRY Link)
Definition: remap.cpp:170
VOID UDFVUpdateBlock(IN PVCB Vcb, IN PVOID Buffer, PUDF_VERIFY_ITEM vItem)
Definition: remap.cpp:198
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
LIST_ENTRY vrfList
Definition: remap.cpp:26

Referenced by UDFPhWriteSynchronous().

◆ UDFWriteExtent()

OSSTATUS UDFWriteExtent ( IN PVCB  Vcb,
IN PEXTENT_INFO  ExtInfo,
IN int64  Offset,
IN SIZE_T  Length,
IN BOOLEAN  Direct,
IN int8 Buffer,
OUT PSIZE_T  WrittenBytes 
)

Definition at line 3186 of file extent.cpp.

3196{
3197 if(!ExtInfo || !ExtInfo->Mapping)
3199
3200 PEXTENT_MAP Extent = ExtInfo->Mapping; // Extent array
3201 uint32 Lba, sect_offs, flags;
3203 SIZE_T to_write, _WrittenBytes;
3204 BOOLEAN reread_lba;
3205// BOOLEAN already_prepared = FALSE;
3206// BOOLEAN prepare = !Buffer;
3207
3208 AdPrint(("Write ExtInfo %x, Mapping %x\n", ExtInfo, ExtInfo->Mapping));
3209
3210 Offset += ExtInfo->Offset; // used for in-ICB data
3211 // write maximal possible part of each frag of extent
3212 while(((LONG)Length) > 0) {
3213 UDFCheckSpaceAllocation(Vcb, 0, Extent, AS_USED); // check if used
3214 Lba = UDFExtentOffsetToLba(Vcb, Extent, Offset, &sect_offs, &to_write, &flags, NULL);
3215 // EOF check
3216 if(Lba == LBA_OUT_OF_EXTENT) {
3217 return STATUS_END_OF_FILE;
3218 }
3219/* if((to_write < Length) &&
3220 !Direct && !prepare && !already_prepared) {
3221 // rebuild mapping, allocate space, etc.
3222 // to indicate this, set Buffer to NULL
3223 AdPrint(("UDFWriteExtent: Prepare\n"));
3224 BrutePoint();
3225 _WrittenBytes = 0;
3226 status = UDFWriteExtent(Vcb, ExtInfo, Offset, Length, *//*Direct*//*FALSE, NULL, &_WrittenBytes);
3227 if(!OS_SUCCESS(status)) {
3228 return status;
3229 }
3230 Extent = ExtInfo->Mapping;
3231 Lba = UDFExtentOffsetToLba(Vcb, Extent, Offset, &sect_offs, &to_write, &flags, NULL);
3232 already_prepared = TRUE;
3233 }*/
3235 // here we should allocate space for this extent
3236 if(!OS_SUCCESS(status = UDFMarkNotAllocatedAsAllocated(Vcb, Offset, to_write, ExtInfo)))
3237 return status;
3238 Extent = ExtInfo->Mapping;
3239 UDFCheckSpaceAllocation(Vcb, 0, Extent, AS_USED); // check if used
3240 Lba = UDFExtentOffsetToLba(Vcb, Extent, Offset, &sect_offs, &to_write, &flags, NULL);
3241 if(Lba == LBA_OUT_OF_EXTENT) {
3242 return STATUS_END_OF_FILE;
3243 }
3244 // we have already re-read Lba
3245 reread_lba = FALSE;
3246 } else {
3247 // we may need to re-read Lba if some changes are
3248 // made while converting from Alloc-Not-Rec
3249 reread_lba = TRUE;
3250 }
3251 // check if writing to not recorded allocated
3252 // in this case we must pad blocks with zeros around
3253 // modified area
3254 //
3255 // ...|xxxxxxxx|xxxxxxxx|xxxxxxxx|...
3256 // . .
3257 // . || .
3258 // . \/ .
3259 // . .
3260 // ...|000ddddd|dddddddd|dd000000|...
3261 // . .
3262 // ^ ^
3263 // sect_offs sect_offs+to_write
3264 // . .
3265 // .<-- to_write -->.
3266 //
3267 to_write = min(to_write, Length);
3269 if(!OS_SUCCESS(status = UDFMarkAllocatedAsRecorded(Vcb, Offset, to_write, ExtInfo)))
3270 return status;
3271 Extent = ExtInfo->Mapping;
3272 UDFCheckSpaceAllocation(Vcb, 0, Extent, AS_USED); // check if used
3273 if(reread_lba) {
3274 Lba = UDFExtentOffsetToLba(Vcb, Extent, Offset, &sect_offs, &to_write, &flags, NULL);
3275 to_write = min(to_write, Length);
3276 }
3277 /*
3278 we must fill 1st block with zeros in 1 of 2 cases:
3279 1) start offset is not aligned on LBlock boundary
3280 OR
3281 2) end offset is not aligned on LBlock boundary and lays in
3282 the same LBlock
3283
3284 we must fill last block with zeros if both
3285 1) end offset is not aligned on LBlock boundary
3286 AND
3287 2) end offset DOESN'T lay in the 1st LBlock
3288 */
3289
3290// if(!prepare) {
3291 // pad 1st logical block
3292 if((sect_offs || (sect_offs + to_write < Vcb->LBlockSize) )
3293 &&
3294 !Vcb->CDR_Mode) {
3296 ( ((uint64)Lba) << Vcb->BlockSizeBits),
3297 Vcb->LBlockSize, Direct, Vcb->ZBuffer, &_WrittenBytes);
3298 if(!OS_SUCCESS(status))
3299 return status;
3300 }
3301 // pad last logical block
3302 if((sect_offs + to_write > Vcb->LBlockSize) &&
3303 (sect_offs + to_write) & (Vcb->LBlockSize - 1)) {
3305 (( ((uint64)Lba) << Vcb->BlockSizeBits) + sect_offs + to_write) & ~((int64)(Vcb->LBlockSize)-1),
3306 Vcb->LBlockSize, Direct, Vcb->ZBuffer, &_WrittenBytes);
3307 }
3308 if(!OS_SUCCESS(status))
3309 return status;
3310/* } else {
3311 status = STATUS_SUCCESS;
3312 }*/
3313 }
3314 ASSERT(to_write);
3315// if(!prepare) {
3316 status = UDFWriteData(Vcb, TRUE, ( ((uint64)Lba) << Vcb->BlockSizeBits) + sect_offs, to_write, Direct, Buffer, &_WrittenBytes);
3317 *WrittenBytes += _WrittenBytes;
3318 if(!OS_SUCCESS(status)) return status;
3319/* } else {
3320 status = STATUS_SUCCESS;
3321 *WrittenBytes += to_write;
3322 }*/
3323 // prepare for writing next frag...
3324 Buffer += to_write;
3325 Offset += to_write;
3326 Length -= to_write;
3327 }
3328 AdPrint(("Write: ExtInfo %x, Mapping %x\n", ExtInfo, ExtInfo->Mapping));
3329 return STATUS_SUCCESS;
3330} // end UDFWriteExtent()
OSSTATUS UDFMarkNotAllocatedAsAllocated(IN PVCB Vcb, IN int64 Offset, IN uint32 Length, IN PEXTENT_INFO ExtInfo)
Definition: extent.cpp:1948
OSSTATUS UDFMarkAllocatedAsRecorded(IN PVCB Vcb, IN int64 Offset, IN uint32 Length, IN PEXTENT_INFO ExtInfo)
Definition: extent.cpp:1814

Referenced by UDFConvertFEToNonInICB(), UDFFlushFE(), UDFResizeFile__(), UDFUpdateXSpaceBitmaps(), and UDFWriteFile__().

◆ UDFWriteFile__()

OSSTATUS UDFWriteFile__ ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo,
IN int64  Offset,
IN SIZE_T  Length,
IN BOOLEAN  Direct,
IN int8 Buffer,
OUT PSIZE_T  WrittenBytes 
)

Definition at line 1605 of file udf_info.cpp.

1614{
1615 int64 t, elen;
1617 int8* OldInIcb = NULL;
1620 SIZE_T _WrittenBytes;
1621 PUDF_DATALOC_INFO Dloc;
1622 // unwind staff
1623 BOOLEAN WasInIcb = FALSE;
1624 uint64 OldLen;
1625
1626// ASSERT(FileInfo->RefCount >= 1);
1627
1628 Dloc = FileInfo->Dloc;
1629 ASSERT(Dloc->FELoc.Mapping[0].extLocation);
1631 (*WrittenBytes) = 0;
1632
1633 AdPrint(("UDFWriteFile__ FE %x, FileInfo %x, ExtInfo %x, Mapping %x\n",
1634 Dloc->FELoc.Mapping[0].extLocation, FileInfo, &(Dloc->DataLoc), Dloc->DataLoc.Mapping));
1635
1636 t = Offset + Length;
1637// UDFUpdateModifyTime(Vcb, FileInfo);
1638 if(t <= Dloc->DataLoc.Length) {
1639 // write Alloc-Rec area
1640 ExtPrint((" WAlloc-Rec: %I64x <= %I64x\n", t, Dloc->DataLoc.Length));
1641 status = UDFWriteExtent(Vcb, &(Dloc->DataLoc), Offset, Length, Direct, Buffer, WrittenBytes);
1642 return status;
1643 }
1644 elen = UDFGetExtentLength(Dloc->DataLoc.Mapping);
1645 ExtPrint((" DataLoc Offs %x, Len %I64x\n",
1646 Dloc->DataLoc.Offset, Dloc->DataLoc.Length));
1647 if(t <= (elen - Dloc->DataLoc.Offset)) {
1648 // write Alloc-Not-Rec area
1649 ExtPrint((" WAlloc-Not-Rec: %I64x <= %I64x (%I64x - %I64x)\n",
1650 t, elen - Dloc->DataLoc.Offset - Dloc->DataLoc.Length,
1651 elen - Dloc->DataLoc.Offset,
1652 Dloc->DataLoc.Length));
1654 if(Vcb->CompatFlags & UDF_VCB_IC_W2K_COMPAT_ALLOC_DESCS) {
1655 ExtPrint((" w2k-compat -> rebuild allocs\n"));
1656 Dloc->DataLoc.Modified = TRUE;
1657 } else
1658 if((ULONG)((elen+Vcb->LBlockSize-1) >> Vcb->LBlockSizeBits) != (ULONG)((t+Vcb->LBlockSize-1) >> Vcb->LBlockSizeBits)) {
1659 ExtPrint((" LBS boundary crossed -> rebuild allocs\n"));
1660 Dloc->DataLoc.Modified = TRUE;
1661 }
1662 Dloc->DataLoc.Length = t;
1663 return UDFWriteExtent(Vcb, &(Dloc->DataLoc), Offset, Length, Direct, Buffer, WrittenBytes);
1664 }
1665 // We should not get here if Direct=TRUE
1666 if(Direct) return STATUS_INVALID_PARAMETER;
1667 OldLen = Dloc->DataLoc.Length;
1668 if(Dloc->DataLoc.Offset && Dloc->DataLoc.Length) {
1669 // read in-icb data. it'll be replaced after resize
1670 ExtPrint((" read in-icb data\n"));
1671 OldInIcb = (int8*)MyAllocatePool__(NonPagedPool, (uint32)(Dloc->DataLoc.Length));
1672 if(!OldInIcb) return STATUS_INSUFFICIENT_RESOURCES;
1673 status = UDFReadExtent(Vcb, &(Dloc->DataLoc), 0, (uint32)OldLen, FALSE, OldInIcb, &ReadBytes);
1674 if(!OS_SUCCESS(status)) {
1675 MyFreePool__(OldInIcb);
1676 return status;
1677 }
1678 }
1679 // init Alloc mode
1680 ExtPrint((" init Alloc mode\n"));
1681 if((((PFILE_ENTRY)(Dloc->FileEntry))->icbTag.flags & ICB_FLAG_ALLOC_MASK) == ICB_FLAG_AD_IN_ICB) {
1682 ((PFILE_ENTRY)(Dloc->FileEntry))->icbTag.flags &= ~ICB_FLAG_ALLOC_MASK;
1683 ((PFILE_ENTRY)(Dloc->FileEntry))->icbTag.flags |= Vcb->DefaultAllocMode;
1684 WasInIcb = TRUE;
1685 }
1686 // increase extent
1687 ExtPrint((" %s %s %s\n",
1688 UDFIsADirectory(FileInfo) ? "DIR" : "FILE",
1689 WasInIcb ? "In-Icb" : "",
1690 Vcb->LowFreeSpace ? "LowSpace" : ""));
1691 if(UDFIsADirectory(FileInfo) && !WasInIcb && !Vcb->LowFreeSpace) {
1692 FileInfo->Dloc->DataLoc.Flags |= EXTENT_FLAG_ALLOC_SEQUENTIAL;
1693 status = UDFResizeExtent(Vcb, PartNum, (t*2+Vcb->WriteBlockSize-1) & ~(SIZE_T)(Vcb->WriteBlockSize-1), FALSE, &(Dloc->DataLoc));
1694 if(OS_SUCCESS(status)) {
1695 AdPrint((" preallocated space for Dir\n"));
1696 FileInfo->Dloc->DataLoc.Flags |= EXTENT_FLAG_PREALLOCATED;
1697 //UDFSetFileSize(FileInfo, t);
1698 Dloc->DataLoc.Length = t;
1699 } else
1700 if(status == STATUS_DISK_FULL) {
1701 status = UDFResizeExtent(Vcb, PartNum, t, FALSE, &(Dloc->DataLoc));
1702 }
1703 } else {
1704 status = UDFResizeExtent(Vcb, PartNum, t, FALSE, &(Dloc->DataLoc));
1705 }
1706 ExtPrint((" DataLoc Offs %x, Len %I64x\n",
1707 Dloc->DataLoc.Offset, Dloc->DataLoc.Length));
1708 AdPrint(("UDFWriteFile__ (2) FileInfo %x, ExtInfo %x, Mapping %x\n", FileInfo, &(Dloc->DataLoc), Dloc->DataLoc.Mapping));
1709 if(!OS_SUCCESS(status)) {
1710 // rollback
1711 ExtPrint((" err -> rollback\n"));
1712 if(WasInIcb) {
1713 // restore Alloc mode
1714 ((PFILE_ENTRY)(Dloc->FileEntry))->icbTag.flags &= ~ICB_FLAG_ALLOC_MASK;
1715 ((PFILE_ENTRY)(Dloc->FileEntry))->icbTag.flags |= ICB_FLAG_AD_IN_ICB;
1716 if(Dloc->AllocLoc.Mapping) {
1718 Dloc->AllocLoc.Mapping = NULL;
1719 }
1720 }
1721 if(OldInIcb) {
1722 UDFWriteExtent(Vcb, &(Dloc->DataLoc), 0, (uint32)OldLen, FALSE, OldInIcb, &_WrittenBytes);
1723 MyFreePool__(OldInIcb);
1724 }
1725 if((int64)OldLen != Dloc->DataLoc.Length) {
1726 // restore file size
1727 AdPrint((" restore alloc\n"));
1728 FileInfo->Dloc->DataLoc.Flags |= EXTENT_FLAG_CUT_PREALLOCATED;
1729 UDFResizeExtent(Vcb, PartNum, OldLen, FALSE, &(Dloc->DataLoc));
1730 FileInfo->Dloc->DataLoc.Flags &= ~EXTENT_FLAG_CUT_PREALLOCATED;
1731 }
1732 return status;
1733 }
1734 if(OldInIcb) {
1735 // replace data from ICB (if any) & free buffer
1736 ExtPrint((" write old in-icd data\n"));
1737 status = UDFWriteExtent(Vcb, &(Dloc->DataLoc), 0, (uint32)OldLen, FALSE, OldInIcb, &_WrittenBytes);
1738 MyFreePool__(OldInIcb);
1739 if(!OS_SUCCESS(status))
1740 return status;
1741 }
1742 // ufff...
1743 // & now we'll write out data to well prepared extent...
1744 // ... like all normal people do...
1745 ExtPrint((" write user data\n"));
1746 if(!OS_SUCCESS(status = UDFWriteExtent(Vcb, &(Dloc->DataLoc), Offset, Length, FALSE, Buffer, WrittenBytes)))
1747 return status;
1749 Dloc->DataLoc.Modified = TRUE;
1750#ifdef UDF_DBG
1751 if(Vcb->CompatFlags & UDF_VCB_IC_W2K_COMPAT_ALLOC_DESCS) {
1752 ASSERT(UDFGetFileSize(FileInfo) <= UDFGetExtentLength(FileInfo->Dloc->DataLoc.Mapping));
1753 } else {
1754 ASSERT(((UDFGetFileSize(FileInfo)+Vcb->LBlockSize-1) & (Vcb->LBlockSize-1)) ==
1755 ((UDFGetExtentLength(FileInfo->Dloc->DataLoc.Mapping)+Vcb->LBlockSize-1) & (Vcb->LBlockSize-1)));
1756 }
1757#endif // UDF_DBG
1758 return STATUS_SUCCESS;
1759} // end UDFWriteFile__()
GLdouble GLdouble t
Definition: gl.h:2047

Referenced by UDFCommonWrite(), UDFConvertFEToExtended(), UDFFlushFI(), UDFPackDirectory__(), UDFRecordDirectory__(), UDFRecordVAT(), UDFResizeFile__(), UDFReTagDirectory(), and UDFWriteSecurity().

◆ UDFZeroExtent()

OSSTATUS UDFZeroExtent ( IN PVCB  Vcb,
IN PEXTENT_INFO  ExtInfo,
IN int64  Offset,
IN SIZE_T  Length,
IN BOOLEAN  Deallocate,
IN BOOLEAN  Direct,
OUT PSIZE_T  WrittenBytes 
)

Definition at line 3337 of file extent.cpp.

3347{
3348 if(!ExtInfo || !ExtInfo->Mapping)
3350
3351 PEXTENT_MAP Extent = ExtInfo->Mapping; // Extent array
3352 uint32 Lba, sect_offs, flags;
3354 SIZE_T to_write, _WrittenBytes;
3355 SIZE_T LBS = Vcb->LBlockSize;
3356
3357 AdPrint(("Zero ExtInfo %x, Mapping %x\n", ExtInfo, ExtInfo->Mapping));
3358
3359 Offset += ExtInfo->Offset; // used for in-ICB data
3360 // fill/deallocate maximal possible part of each frag of extent
3361 while(((LONG)Length) > 0) {
3362 Lba = UDFExtentOffsetToLba(Vcb, Extent, Offset, &sect_offs, &to_write, &flags, NULL);
3363 // EOF check
3364 if(Lba == LBA_OUT_OF_EXTENT) {
3365 return STATUS_END_OF_FILE;
3366 }
3367 // check for writing tail
3368 to_write = min(to_write, Length);
3369
3371 // here we should do nothing
3372 *WrittenBytes += to_write;
3373 } else
3375 // we should just deallocate this frag
3376 if(Deallocate) {
3377 if(!OS_SUCCESS(status = UDFMarkAllocatedAsNotAllocated(Vcb, Offset, to_write, ExtInfo)))
3378 return status;
3379 }
3380 Extent = ExtInfo->Mapping;
3381 *WrittenBytes += to_write;
3382 } else {
3383 // fill tail of the 1st Block with ZEROs
3384 if(sect_offs) {
3385 status = UDFWriteData(Vcb, TRUE, ( ((uint64)Lba) << Vcb->BlockSizeBits) + sect_offs,
3386 min(to_write, LBS-sect_offs),
3387 Direct, Vcb->ZBuffer, &_WrittenBytes);
3388 *WrittenBytes += _WrittenBytes;
3389 if(!OS_SUCCESS(status))
3390 return status;
3391 Offset += _WrittenBytes;
3392 Length -= _WrittenBytes;
3393 to_write -= _WrittenBytes;
3394 Lba = UDFExtentOffsetToLba(Vcb, Extent, Offset, &sect_offs, &to_write, &flags, NULL);
3397 ASSERT(!sect_offs);
3398 }
3399 // deallocate Blocks
3400 if(to_write >= LBS) {
3401 // use 'sect_offs' as length of extent to be deallocated
3402 sect_offs = to_write & ~(LBS - 1);
3403 if(Deallocate) {
3404 status = UDFMarkAllocatedAsNotAllocated(Vcb, Offset, sect_offs, ExtInfo);
3405 } else {
3406 status = UDFMarkRecordedAsAllocated(Vcb, Offset, sect_offs, ExtInfo);
3407 }
3408 if(!OS_SUCCESS(status))
3409 return status;
3410 // reload extent mapping
3411 Extent = ExtInfo->Mapping;
3412 Offset += sect_offs;
3413 Length -= sect_offs;
3414 *WrittenBytes += sect_offs;
3415 to_write -= sect_offs;
3416 Lba = UDFExtentOffsetToLba(Vcb, Extent, Offset, &sect_offs, &to_write, &flags, NULL);
3419 ASSERT(!sect_offs);
3420 }
3421 // fill beginning of the last Block with ZEROs
3422 if(to_write) {
3423 status = UDFWriteData(Vcb, TRUE, ( ((uint64)Lba) << Vcb->BlockSizeBits), to_write, Direct, Vcb->ZBuffer, &_WrittenBytes);
3424 *WrittenBytes += _WrittenBytes;
3425 if(!OS_SUCCESS(status))
3426 return status;
3427 ASSERT(to_write == _WrittenBytes);
3428 }
3429 }
3430 AdPrint(("Zero... ExtInfo %x, Mapping %x\n", ExtInfo, ExtInfo->Mapping));
3431 // prepare for filling next frag...
3432 Offset += to_write;
3433 Length -= to_write;
3434 }
3435 AdPrint(("Zero: ExtInfo %x, Mapping %x\n", ExtInfo, ExtInfo->Mapping));
3436 return STATUS_SUCCESS;
3437} // end UDFZeroExtent()
#define UDFMarkAllocatedAsNotAllocated(Vcb, Off, Len, Ext)
Definition: udf_info.h:503
#define UDFMarkRecordedAsAllocated(Vcb, Off, Len, Ext)
Definition: udf_info.h:516

◆ UDFZeroFile__()

__inline OSSTATUS UDFZeroFile__ ( IN PVCB  Vcb,
IN PUDF_FILE_INFO  FileInfo,
IN int64  Offset,
IN uint32  Length,
IN BOOLEAN  Direct,
OUT uint32 ReadBytes 
)

Variable Documentation

◆ hexChar

const char hexChar[]
extern