3 #include "fatvol_local.h"
6 HANDLE FatVol_Open(C_FATVOL *self, const char *pszPath, int iMode)
8 unsigned char ubBuf[32];
12 char szEntryName[8+3+1];
20 if ( *pszPath == '/' )
26 hDir = FatVol_CreateFile(self, self->uiRootDirCluster, 0, 0, FILE_MODE_READ | FILE_MODE_WRITE);
31 for ( iNameLen = 0; pszPath[iNameLen] != '\0'; iNameLen++ )
33 if ( pszPath[iNameLen] == '/' )
35 szName[iNameLen] = '\0';
40 if ( pszPath[iNameLen] >= 'a' && pszPath[iNameLen] <= 'z' )
42 szName[iNameLen] = pszPath[iNameLen] - ('a' - 'A');
46 szName[iNameLen] = pszPath[iNameLen];
52 for ( i = 0; File_Read(hDir, ubBuf, 32, 0) == 32; i++ )
55 if ( ubBuf[0] == 0x00 )
62 for ( j = 0; j < 8; j++ )
64 if ( ubBuf[0+j] == ' ' || ubBuf[0+j] == '\0' )
68 szEntryName[iEntryNameLen++] = (char)ubBuf[0+j];
70 szEntryName[iEntryNameLen++] = '.';
71 for ( j = 0; j < 3; j++ )
73 if ( ubBuf[8+j] == ' ' || ubBuf[8+j] == '\0' )
77 szEntryName[iEntryNameLen++] = (char)ubBuf[8+j];
79 szEntryName[iEntryNameLen++] = '\0';
80 if ( iEntryNameLen > 2 && szEntryName[iEntryNameLen-1] == '.' )
82 szEntryName[--iEntryNameLen] = '\0';
85 if ( strcmp(szEntryName, szName) == 0 )
93 uiCluster = ubBuf[0x1a] + ubBuf[0x1b]*256;
94 if ( self->iFatType == FATVOL_TYPE_FAT32 )
96 uiCluster += ubBuf[0x14]*256*256 + ubBuf[0x15]*256*256*256;
99 /* パス部分の解析が終わっていればここで抜ける */
100 if ( pszPath[iNameLen] == '\0' )
107 /* サブディレクトリがなければエラー */
108 if ( iDirEntry < 0 || !(ubBuf[0x0b] & 0x10) )
114 hDir = FatVol_CreateFile(self, uiCluster, 0, 0, FILE_MODE_READ | FILE_MODE_WRITE);
120 if ( iDirEntry >= 0 )
122 hFile = FatVol_CreateFile(self, uiCluster, hDir, iDirEntry, iMode);
123 if ( hFile == HANDLE_NULL )