/* * IsoLookupFile() * This function searches the file system for the * specified filename and fills in an ISO_FILE_INFO structure * with info describing the file, etc. returns ARC error code */ static LONG IsoLookupFile(PCSTR FileName, ULONG DeviceId, PISO_FILE_INFO IsoFileInfoPointer) { UCHAR Buffer[SECTORSIZE]; PPVD Pvd = (PPVD)Buffer; UINT32 i; ULONG NumberOfPathParts; CHAR PathPart[261]; PVOID DirectoryBuffer; ULONG DirectorySector; ULONG DirectoryLength; ISO_FILE_INFO IsoFileInfo; LARGE_INTEGER Position; ULONG Count; LONG ret; TRACE("IsoLookupFile() FileName = %s\n", FileName); RtlZeroMemory(IsoFileInfoPointer, sizeof(ISO_FILE_INFO)); RtlZeroMemory(&IsoFileInfo, sizeof(ISO_FILE_INFO)); // // Read The Primary Volume Descriptor // Position.HighPart = 0; Position.LowPart = 16 * SECTORSIZE; ret = ArcSeek(DeviceId, &Position, SeekAbsolute); if (ret != ESUCCESS) return ret; ret = ArcRead(DeviceId, Pvd, SECTORSIZE, &Count); if (ret != ESUCCESS || Count < sizeof(PVD)) return EIO; DirectorySector = Pvd->RootDirRecord.ExtentLocationL; DirectoryLength = Pvd->RootDirRecord.DataLengthL; // // Figure out how many sub-directories we are nested in // NumberOfPathParts = FsGetNumPathParts(FileName); // // Loop once for each part // for (i=0; i<NumberOfPathParts; i++) { // // Get first path part // FsGetFirstNameFromPath(PathPart, FileName); // // Advance to the next part of the path // for (; (*FileName != '\\') && (*FileName != '/') && (*FileName != '\0'); FileName++) { } FileName++; // // Buffer the directory contents // ret = IsoBufferDirectory(DeviceId, DirectorySector, DirectoryLength, &DirectoryBuffer); if (ret != ESUCCESS) return ret; // // Search for file name in directory // if (!IsoSearchDirectoryBufferForFile(DirectoryBuffer, DirectoryLength, PathPart, &IsoFileInfo)) { MmHeapFree(DirectoryBuffer); return ENOENT; } MmHeapFree(DirectoryBuffer); // // If we have another sub-directory to go then // grab the start sector and file size // if ((i+1) < NumberOfPathParts) { DirectorySector = IsoFileInfo.FileStart; DirectoryLength = IsoFileInfo.FileSize; } } RtlCopyMemory(IsoFileInfoPointer, &IsoFileInfo, sizeof(ISO_FILE_INFO)); return ESUCCESS; }
/* * FatLookupFile() * This function searches the file system for the * specified filename and fills in an FAT_FILE_INFO structure * with info describing the file, etc. returns ARC error code */ LONG FatLookupFile(PFAT_VOLUME_INFO Volume, PCSTR FileName, ULONG DeviceId, PFAT_FILE_INFO FatFileInfoPointer) { UINT32 i; ULONG NumberOfPathParts; CHAR PathPart[261]; PVOID DirectoryBuffer; ULONG DirectoryStartCluster = 0; ULONG DirectorySize; FAT_FILE_INFO FatFileInfo; TRACE("FatLookupFile() FileName = %s\n", FileName); memset(FatFileInfoPointer, 0, sizeof(FAT_FILE_INFO)); // // Figure out how many sub-directories we are nested in // NumberOfPathParts = FsGetNumPathParts(FileName); // // Loop once for each part // for (i=0; i<NumberOfPathParts; i++) { // // Get first path part // FsGetFirstNameFromPath(PathPart, FileName); // // Advance to the next part of the path // for (; (*FileName != '\\') && (*FileName != '/') && (*FileName != '\0'); FileName++) { } FileName++; // // Buffer the directory contents // DirectoryBuffer = FatBufferDirectory(Volume, DirectoryStartCluster, &DirectorySize, (i == 0) ); if (DirectoryBuffer == NULL) { return ENOMEM; } // // Search for file name in directory // if (ISFATX(Volume->FatType)) { if (!FatXSearchDirectoryBufferForFile(Volume, DirectoryBuffer, DirectorySize, PathPart, &FatFileInfo)) { MmFreeMemory(DirectoryBuffer); return ENOENT; } } else { if (!FatSearchDirectoryBufferForFile(Volume, DirectoryBuffer, DirectorySize, PathPart, &FatFileInfo)) { MmFreeMemory(DirectoryBuffer); return ENOENT; } } MmFreeMemory(DirectoryBuffer); // // If we have another sub-directory to go then // grab the start cluster and free the fat chain array // if ((i+1) < NumberOfPathParts) { // // Check if current entry is a directory // if (!(FatFileInfo.Attributes & ATTR_DIRECTORY)) { MmFreeMemory(FatFileInfo.FileFatChain); return ENOTDIR; } DirectoryStartCluster = FatFileInfo.FileFatChain[0]; } MmFreeMemory(FatFileInfo.FileFatChain); } memcpy(FatFileInfoPointer, &FatFileInfo, sizeof(FAT_FILE_INFO)); return ESUCCESS; }