Changeset 10064 for trunk/src/kernel32/hmfile.cpp
- Timestamp:
- May 5, 2003, 12:51:05 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/hmfile.cpp
r9975 r10064 1 /* $Id: hmfile.cpp,v 1.4 2 2003-04-02 12:58:29sandervl Exp $ */1 /* $Id: hmfile.cpp,v 1.43 2003-05-05 10:51:05 sandervl Exp $ */ 2 2 3 3 /* … … 38 38 #define DBG_LOCALLOG DBG_hmfile 39 39 #include "dbglocal.h" 40 41 static void ParsePath(LPCSTR lpszFileName, LPSTR lpszParsedFileName, DWORD length); 40 42 41 43 /***************************************************************************** … … 103 105 return(GetLastError()); 104 106 } 105 }106 107 //*****************************************************************************108 //Parses and copies path109 //OpenFile in NT4, SP6 accepts double (or more) backslashes as separators for directories!110 //(OS/2 doesn't)111 //Girotel 2.0 (Dutch banking app) seems to depend on this behaviour112 //*****************************************************************************113 void HMDeviceFileClass::ParsePath(LPCSTR lpszFileName, LPSTR lpszParsedFileName, DWORD length)114 {115 int i=0;116 117 while(*lpszFileName != 0 && i < length-1) {118 *lpszParsedFileName++ = *lpszFileName;119 if(*lpszFileName == '\\') {120 while(*lpszFileName == '\\') {121 lpszFileName++;122 }123 }124 else {125 lpszFileName++;126 }127 i++;128 }129 *lpszParsedFileName = 0;130 107 } 131 108 … … 1090 1067 // arg4)); 1091 1068 } 1069 1070 //****************************************************************************** 1071 //****************************************************************************** 1072 // File information handle class 1073 // 1074 // When the application opens a file with CreateFile and 0 for desired access, 1075 // then we need to create a handle with limited access. 1076 // 1077 // MSDN: 1078 // 1079 // If this parameter is zero, the application can query file and device attributes 1080 // without accessing the device. This is useful if an application wants to determine 1081 // the size of a floppy disk drive and the formats it supports without requiring 1082 // a floppy in the drive. It can also be used to test for the file's or directory's 1083 // existence without opening it for read or write access. 1084 // 1085 //****************************************************************************** 1086 //****************************************************************************** 1087 1088 /****************************************************************************** 1089 * Name : DWORD HMDeviceInfoFileClass::CreateFile 1090 * Purpose : this is called from the handle manager if a CreateFile() is 1091 * performed on a handle 1092 * Parameters: LPCSTR lpFileName name of the file / device 1093 * PHMHANDLEDATA pHMHandleData data of the NEW handle 1094 * PVOID lpSecurityAttributes ignored 1095 * PHMHANDLEDATA pHMHandleDataTemplate data of the template handle 1096 * Variables : 1097 * Result : 1098 * Remark : 1099 * Status : NO_ERROR - API succeeded 1100 * other - what is to be set in SetLastError 1101 * 1102 * Author : SvL 1103 *****************************************************************************/ 1104 DWORD HMDeviceInfoFileClass::CreateFile (LPCSTR lpFileName, 1105 PHMHANDLEDATA pHMHandleData, 1106 PVOID lpSecurityAttributes, 1107 PHMHANDLEDATA pHMHandleDataTemplate) 1108 { 1109 char filepath[260]; 1110 DWORD dwAttr; 1111 1112 dprintfl(("KERNEL32: HMDeviceInfoFileClass::CreateFile %s(%s,%08x,%08x,%08x)\n", 1113 lpHMDeviceName, 1114 lpFileName, 1115 pHMHandleData, 1116 lpSecurityAttributes, 1117 pHMHandleDataTemplate)); 1118 1119 ParsePath(lpFileName, filepath, sizeof(filepath)); 1120 1121 //convert to long file name if in 8.3 hashed format 1122 GetLongPathNameA(filepath, filepath, sizeof(filepath)); 1123 lpFileName = filepath; 1124 1125 1126 dwAttr = GetFileAttributesA(lpFileName); 1127 if(dwAttr == -1) { 1128 return GetLastError(); 1129 } 1130 1131 pHMHandleData->dwUserData = (DWORD) new HMFileInfo((LPSTR)lpFileName, lpSecurityAttributes); 1132 pHMHandleData->hHMHandle = 0x8000000; 1133 return (NO_ERROR); 1134 1135 } 1136 /****************************************************************************** 1137 * Name : BOOL HMDeviceFileClass::CloseHandle 1138 * Purpose : close the handle 1139 * Parameters: PHMHANDLEDATA pHMHandleData 1140 * Variables : 1141 * Result : API returncode 1142 * Remark : 1143 * Status : 1144 * 1145 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 1146 *****************************************************************************/ 1147 BOOL HMDeviceInfoFileClass::CloseHandle(PHMHANDLEDATA pHMHandleData) 1148 { 1149 HMFileInfo *fileInfo = (HMFileInfo *)pHMHandleData->dwUserData; 1150 1151 dprintfl(("KERNEL32: HMDeviceInfoFileClass::CloseHandle(%08x)\n", 1152 pHMHandleData->hHMHandle)); 1153 1154 if(fileInfo) { 1155 delete fileInfo; 1156 } 1157 return TRUE; 1158 } 1159 /****************************************************************************** 1160 * Name : BOOL HMDeviceInfoFileClass::GetFileTime 1161 * Purpose : Get file time 1162 * Parameters: PHMHANDLEDATA pHMHandleData 1163 * PFILETIME pFT1 1164 * PFILETIME pFT2 1165 * PFILETIME pFT3 1166 * Variables : 1167 * Result : API returncode 1168 * Remark : 1169 * Status : 1170 * 1171 * Author : SvL 1172 *****************************************************************************/ 1173 BOOL HMDeviceInfoFileClass::GetFileTime (PHMHANDLEDATA pHMHandleData, 1174 LPFILETIME pFT1, 1175 LPFILETIME pFT2, 1176 LPFILETIME pFT3) 1177 { 1178 HMFileInfo *fileInfo = (HMFileInfo *)pHMHandleData->dwUserData; 1179 1180 if(!pFT1 && !pFT2 && !pFT3) {//TODO: does NT do this? 1181 dprintf(("ERROR: GetFileTime: invalid parameter!")); 1182 SetLastError(ERROR_INVALID_PARAMETER); 1183 return FALSE; 1184 } 1185 WIN32_FIND_DATAA finddata; 1186 HANDLE hFind; 1187 1188 hFind = FindFirstFileA(fileInfo->lpszFileName, &finddata); 1189 if(hFind == INVALID_HANDLE_VALUE) { 1190 return GetLastError(); 1191 } 1192 if(pFT1) { 1193 *pFT1 = finddata.ftCreationTime; 1194 } 1195 if(pFT2) { 1196 *pFT2 = finddata.ftLastAccessTime; 1197 } 1198 if(pFT3) { 1199 *pFT3 = finddata.ftLastWriteTime; 1200 } 1201 FindClose(hFind); 1202 SetLastError(ERROR_SUCCESS); 1203 return TRUE; 1204 } 1205 /****************************************************************************** 1206 * Name : DWORD HMDeviceInfoFileClass::GetFileSize 1207 * Purpose : get file size 1208 * Parameters: PHMHANDLEDATA pHMHandleData 1209 * PDWORD pSize 1210 * Variables : 1211 * Result : API returncode 1212 * Remark : Doesn't fail for directories; just returns 0 (verified in NT4, SP6) 1213 * Status : 1214 * 1215 * Author : SvL 1216 *****************************************************************************/ 1217 DWORD HMDeviceInfoFileClass::GetFileSize(PHMHANDLEDATA pHMHandleData, 1218 PDWORD lpdwFileSizeHigh) 1219 { 1220 HMFileInfo *fileInfo = (HMFileInfo *)pHMHandleData->dwUserData; 1221 1222 SetLastError(ERROR_SUCCESS); 1223 1224 if(lpdwFileSizeHigh) 1225 *lpdwFileSizeHigh = 0; 1226 1227 if(fileInfo == NULL) { 1228 DebugInt3(); 1229 SetLastError(ERROR_INVALID_PARAMETER); //TODO 1230 return -1; //INVALID_FILE_SIZE; 1231 } 1232 1233 WIN32_FIND_DATAA finddata; 1234 HANDLE hFind; 1235 1236 hFind = FindFirstFileA(fileInfo->lpszFileName, &finddata); 1237 if(hFind == INVALID_HANDLE_VALUE) { 1238 return GetLastError(); 1239 } 1240 if(lpdwFileSizeHigh) { 1241 *lpdwFileSizeHigh = finddata.nFileSizeHigh; 1242 } 1243 FindClose(hFind); 1244 return finddata.nFileSizeLow; 1245 } 1246 /****************************************************************************** 1247 * Name : DWORD HMDeviceFileClass::GetFileType 1248 * Purpose : determine the handle type 1249 * Parameters: PHMHANDLEDATA pHMHandleData 1250 * Variables : 1251 * Result : API returncode 1252 * Remark : Returns FILE_TYPE_DISK for both files and directories 1253 * Status : 1254 * 1255 * Author : Patrick Haller [Wed, 1998/02/11 20:44] 1256 ******************************************************************************/ 1257 DWORD HMDeviceInfoFileClass::GetFileType(PHMHANDLEDATA pHMHandleData) 1258 { 1259 dprintfl(("KERNEL32: HMDeviceInfoFileClass::GetFileType %s(%08x)\n", 1260 lpHMDeviceName, 1261 pHMHandleData)); 1262 1263 return FILE_TYPE_DISK; 1264 } 1092 1265 //****************************************************************************** 1093 1266 //****************************************************************************** … … 1110 1283 } 1111 1284 } 1285 1286 //***************************************************************************** 1287 //Parses and copies path 1288 //OpenFile in NT4, SP6 accepts double (or more) backslashes as separators for directories! 1289 //(OS/2 doesn't) 1290 //Girotel 2.0 (Dutch banking app) seems to depend on this behaviour 1291 //***************************************************************************** 1292 static void ParsePath(LPCSTR lpszFileName, LPSTR lpszParsedFileName, DWORD length) 1293 { 1294 int i=0; 1295 1296 while(*lpszFileName != 0 && i < length-1) { 1297 *lpszParsedFileName++ = *lpszFileName; 1298 if(*lpszFileName == '\\') { 1299 while(*lpszFileName == '\\') { 1300 lpszFileName++; 1301 } 1302 } 1303 else { 1304 lpszFileName++; 1305 } 1306 i++; 1307 } 1308 *lpszParsedFileName = 0; 1309 } 1112 1310 //****************************************************************************** 1113 1311 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.