Rev 427 | Rev 433 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 427 | Rev 431 | ||
---|---|---|---|
Line 1089... | Line 1089... | ||
1089 | u16 end_of_directory_not_reached = 0; |
1089 | u16 end_of_directory_not_reached = 0; |
1090 | u8 i = 0; |
1090 | u8 i = 0; |
1091 | u8 direntry_exist = 0; |
1091 | u8 direntry_exist = 0; |
1092 | DirEntry_t * dir; |
1092 | DirEntry_t * dir; |
Line 1093... | Line 1093... | ||
1093 | 1093 | ||
1094 | // if incomming pointers are useless return immediatly |
1094 | // incomming pointers are useless? |
Line 1095... | Line 1095... | ||
1095 | if((!Partition.IsValid) || (file == NULL) || (dirname == NULL)) return(direntry_exist); |
1095 | if((!Partition.IsValid) || (file == NULL) || (dirname == NULL)) return(direntry_exist); |
1096 | - | ||
- | 1096 | ||
1097 | // dir entries can be searched only in filesclusters that have |
1097 | // check sector range to be searched |
1098 | // a corresponding dir entry with a dir-flag set in its attribute |
1098 | |
1099 | // or direct within the root directory area |
- | |
1100 | file->FirstSectorOfFirstCluster = SECTOR_UNDEFINED; |
- | |
1101 | // no current directory exist therefore assume searching in the root |
1099 | // no search area defined? |
1102 | if(file->DirectorySector == SECTOR_UNDEFINED) |
- | |
1103 | { |
1100 | if(file->FirstSectorOfFirstCluster == SECTOR_UNDEFINED) |
1104 | max_dir_sector = (Partition.MaxRootEntries * DIRENTRY_SIZE)/BYTES_PER_SECTOR; |
1101 | { |
1105 | file->FirstSectorOfFirstCluster = Partition.FirstRootDirSector; |
1102 | return(direntry_exist); |
1106 | } |
1103 | } |
1107 | // within the root directory area we can read sectors sequentially until the end of this area |
1104 | //is search area the root? |
1108 | else if((Partition.FirstRootDirSector <= file->DirectorySector) && (file->DirectorySector < Partition.FirstDataSector)) |
1105 | else if(Partition.FirstRootDirSector == file->FirstSectorOfFirstCluster) |
1109 | { |
1106 | { |
1110 | max_dir_sector = (Partition.MaxRootEntries * DIRENTRY_SIZE)/BYTES_PER_SECTOR; |
1107 | max_dir_sector = (Partition.MaxRootEntries * DIRENTRY_SIZE)/BYTES_PER_SECTOR; // limit to size of root |
1111 | file->FirstSectorOfFirstCluster = Partition.FirstRootDirSector; |
1108 | file->DirectorySector = SECTOR_UNDEFINED; // if we have to search within the root, there is no corresponding directory entry available |
1112 | } |
1109 | } |
1113 | // within the data clusters we can read sectors sequentially only within the cluster |
1110 | // is search area within the data cluster range? |
1114 | else if((Partition.FirstDataSector <= file->DirectorySector) && (file->DirectorySector <= Partition.LastDataSector)) |
1111 | else if((Partition.FirstDataSector <= file->FirstSectorOfFirstCluster) && (file->FirstSectorOfFirstCluster <= Partition.LastDataSector)) |
- | 1112 | { |
|
- | 1113 | max_dir_sector = Partition.SectorsPerCluster; // limit max sectors before next cluster |
|
- | 1114 | /* |
|
- | 1115 | //there must be a corresponding directory entry |
|
- | 1116 | if(file->DirectorySector == SECTOR_UNDEFINED) |
|
1115 | { |
1117 | { |
1116 | max_dir_sector = Partition.SectorsPerCluster; // limit max sectors before next cluster |
1118 | return (direntry_exist); |
1117 | } |
- | |
1118 | else return (direntry_exist); // bad sector range for directory sector of the file |
- | |
1119 | // if search area is not defined yet, i.e. not in the root directory area |
1119 | } |
1120 | if(file->FirstSectorOfFirstCluster == SECTOR_UNDEFINED) |
- | |
1121 | { |
1120 | else // check directory entry |
1122 | // check if the directory entry of current file is existent and has the dir-flag set |
1121 | { |
1123 | file->SectorInCache = file->DirectorySector; // update the sector number of file cache. |
1122 | file->SectorInCache = file->DirectorySector; // update the sector number of file cache. |
1124 | if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read in the sector. |
1123 | if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read in the sector. |
1125 | { |
1124 | { |
1126 | Fat16_Deinit(); |
1125 | Fat16_Deinit(); |
1127 | return(0); |
1126 | return (direntry_exist); |
1128 | } |
1127 | } |
1129 | dir = (DirEntry_t *)file->Cache; // set pointer to directory |
1128 | dir = (DirEntry_t *)file->Cache; // set pointer to directory |
1130 | switch((u8)dir[file->DirectoryIndex].Name[0]) // check if current directory exist |
1129 | switch((u8)dir[file->DirectoryIndex].Name[0]) // check if current directory exist |
Line 1135... | Line 1134... | ||
1135 | // therefore no file or subdirectory exist here |
1134 | // therefore no file or subdirectory exist here |
1136 | return (direntry_exist); |
1135 | return(direntry_exist); |
1137 | break; |
1136 | break; |
1138 | default: // and is a real directory |
1137 | default: // and is a real directory |
1139 | if((dir[file->DirectoryIndex].Attribute & ATTR_SUBDIRECTORY) != ATTR_SUBDIRECTORY) |
1138 | if((dir[file->DirectoryIndex].Attribute & ATTR_SUBDIRECTORY) != ATTR_SUBDIRECTORY) |
1140 | { // current file is not a directory therefore no file or subdirectory can be created here |
1139 | { // current file is not a directory therefore no file or subdirectory can be searched here |
1141 | return (direntry_exist); |
1140 | return(direntry_exist); |
1142 | } |
1141 | } |
1143 | break; |
1142 | break; |
1144 | } |
1143 | } |
- | 1144 | // check that search area matches directory entry |
|
1145 | file->FirstSectorOfFirstCluster = Fat16ClusterToSector(dir[file->DirectoryIndex].StartCluster); |
1145 | if(file->FirstSectorOfFirstCluster != Fat16ClusterToSector(dir[file->DirectoryIndex].StartCluster)) |
- | 1146 | { |
|
- | 1147 | return (direntry_exist); |
|
- | 1148 | } |
|
- | 1149 | |
|
- | 1150 | } */ |
|
1146 | } |
1151 | } |
- | 1152 | else return (direntry_exist); // bad sector range for search area |
|
- | 1153 | ||
1147 | // update current file data area position to start of first cluster |
1154 | // update current file data area position to start of first cluster |
1148 | file->FirstSectorOfCurrCluster = file->FirstSectorOfFirstCluster; |
1155 | file->FirstSectorOfCurrCluster = file->FirstSectorOfFirstCluster; |
1149 | file->SectorOfCurrCluster = 0; |
1156 | file->SectorOfCurrCluster = 0; |
1150 | file->ByteOfCurrSector = 0; |
1157 | file->ByteOfCurrSector = 0; |
Line 1157... | Line 1164... | ||
1157 | curr_sector = file->FirstSectorOfCurrCluster + dir_sector; // calculate sector number |
1164 | curr_sector = file->FirstSectorOfCurrCluster + dir_sector; // calculate sector number |
1158 | file->SectorInCache = curr_sector; // upate the sector number of file cache. |
1165 | file->SectorInCache = curr_sector; // upate the sector number of file cache. |
1159 | if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read the sector |
1166 | if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read the sector |
1160 | { |
1167 | { |
1161 | Fat16_Deinit(); |
1168 | Fat16_Deinit(); |
1162 | return(0); |
1169 | return(direntry_exist); |
1163 | } |
1170 | } |
1164 | dir = (DirEntry_t *)file->Cache; // set pointer to directory |
1171 | dir = (DirEntry_t *)file->Cache; // set pointer to directory |
1165 | // search all directory entries within that sector |
1172 | // search all directory entries within that sector |
1166 | for(dir_entry = 0; dir_entry < DIRENTRIES_PER_SECTOR; dir_entry++) |
1173 | for(dir_entry = 0; dir_entry < DIRENTRIES_PER_SECTOR; dir_entry++) |
1167 | { // check for existing dir entry |
1174 | { // check for existing dir entry |
Line 1198... | Line 1205... | ||
1198 | // if we are seaching in the data area and the file not found in this cluster so take next cluster. |
1205 | // if we are seaching in the data area and the file not found in this cluster so take next cluster. |
1199 | if(!direntry_exist && ( Partition.FirstDataSector <= file->FirstSectorOfCurrCluster)) |
1206 | if(!direntry_exist && ( Partition.FirstDataSector <= file->FirstSectorOfCurrCluster)) |
1200 | { |
1207 | { |
1201 | end_of_directory_not_reached = GetNextCluster(file); // updates File->FirstSectorOfCurrCluster |
1208 | end_of_directory_not_reached = GetNextCluster(file); // updates File->FirstSectorOfCurrCluster |
1202 | } |
1209 | } |
1203 | }while((end_of_directory_not_reached) && (!direntry_exist)); // repeat until a next cluster exist an no |
1210 | }while((end_of_directory_not_reached) && (!direntry_exist)); // repeat until a next cluster exist an no match has been found |
1204 | return(direntry_exist); |
1211 | return(direntry_exist); |
1205 | } |
1212 | } |
Line 1206... | Line 1213... | ||
1206 | 1213 | ||
Line 1221... | Line 1228... | ||
1221 | u16 end_of_directory_not_reached = 0; |
1228 | u16 end_of_directory_not_reached = 0; |
1222 | u8 i = 0; |
1229 | u8 i = 0; |
1223 | u8 retvalue = 0; |
1230 | u8 retvalue = 0; |
1224 | DirEntry_t *dir; |
1231 | DirEntry_t *dir; |
Line -... | Line 1232... | ||
- | 1232 | ||
1225 | 1233 | // incomming pointers are useless? |
|
1226 | if((!Partition.IsValid) || (file == NULL) || (dirname == NULL)) return (retvalue); |
- | |
Line 1227... | Line 1234... | ||
1227 | // It is not checked here that the dir entry that should be created is already existent! |
1234 | if((!Partition.IsValid) || (file == NULL) || (dirname == NULL)) return(retvalue); |
1228 | - | ||
Line 1229... | Line -... | ||
1229 | // Dir entries can be created only in file-clusters that have |
- | |
1230 | // the dir-flag set in its attribute or within the root directory |
1235 | |
1231 | 1236 | // check sector range to be searched |
|
1232 | file->FirstSectorOfFirstCluster = SECTOR_UNDEFINED; |
1237 | |
1233 | // no current directory exist therefore assume creating in the root |
- | |
1234 | if(file->DirectorySector == SECTOR_UNDEFINED) |
1238 | // no creation area defined? |
1235 | { |
- | |
1236 | max_dir_sector = (Partition.MaxRootEntries * DIRENTRY_SIZE)/BYTES_PER_SECTOR; |
1239 | if(file->FirstSectorOfFirstCluster == SECTOR_UNDEFINED) |
1237 | dircluster = 0; |
1240 | { |
1238 | file->FirstSectorOfFirstCluster = Partition.FirstRootDirSector; |
1241 | return(retvalue); |
1239 | } |
1242 | } |
1240 | // within the root directory area we can read sectors sequentially until the end of this area |
1243 | //is creation area the root? |
1241 | else if((Partition.FirstRootDirSector <= file->DirectorySector) && (file->DirectorySector < Partition.FirstDataSector)) |
- | |
1242 | { |
1244 | else if(Partition.FirstRootDirSector == file->FirstSectorOfFirstCluster) |
1243 | max_dir_sector = (Partition.MaxRootEntries * DIRENTRY_SIZE)/BYTES_PER_SECTOR; |
1245 | { |
1244 | dircluster = 0; |
1246 | max_dir_sector = (Partition.MaxRootEntries * DIRENTRY_SIZE)/BYTES_PER_SECTOR; // limit to size of root |
1245 | file->FirstSectorOfFirstCluster = Partition.FirstRootDirSector; |
1247 | file->DirectorySector = SECTOR_UNDEFINED; // if we have to search within the root, there is no corresponding directory entry available |
1246 | } |
1248 | } |
1247 | // within the data clusters we can read sectors sequentially only within the cluster |
1249 | // is creation area within the data cluster range? |
1248 | else if((Partition.FirstDataSector <= file->DirectorySector) && (file->DirectorySector <= Partition.LastDataSector)) |
1250 | else if((Partition.FirstDataSector <= file->FirstSectorOfFirstCluster) && (file->FirstSectorOfFirstCluster <= Partition.LastDataSector)) |
- | 1251 | { |
|
- | 1252 | max_dir_sector = Partition.SectorsPerCluster; // limit max sectors before next cluster |
|
- | 1253 | // there must be a corresponding directory entry |
|
1249 | { |
1254 | if(file->DirectorySector == SECTOR_UNDEFINED) |
1250 | max_dir_sector = Partition.SectorsPerCluster; |
- | |
1251 | file->FirstSectorOfFirstCluster = Partition.CurrentWorkingDirectory; |
1255 | { |
1252 | } |
- | |
1253 | else return (retvalue); // bad sector range for directory sector of the file |
1256 | return (retvalue); |
1254 | // if search area is not defined yet |
- | |
1255 | if(file->FirstSectorOfFirstCluster == SECTOR_UNDEFINED) |
1257 | } |
1256 | { |
1258 | else // check directory entry |
1257 | // check if the directory entry of current file is existent and has the dir-flag set |
1259 | { |
1258 | file->SectorInCache = file->DirectorySector; // update the sector number of file cache. |
1260 | file->SectorInCache = file->DirectorySector; // update the sector number of file cache. |
1259 | if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read in the sector. |
1261 | if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache)) // read in the sector. |
1260 | { |
1262 | { |
1261 | Fat16_Deinit(); |
1263 | Fat16_Deinit(); |
1262 | return(0); |
1264 | return (retvalue); |
1263 | } |
1265 | } |
1264 | dir = (DirEntry_t *)file->Cache; // set pointer to directory |
1266 | dir = (DirEntry_t *)file->Cache; // set pointer to directory |
1265 | switch((u8)dir[file->DirectoryIndex].Name[0]) // check if current directory exist |
1267 | switch((u8)dir[file->DirectoryIndex].Name[0]) // check if current directory exist |
- | 1268 | { |
|
- | 1269 | case SLOT_EMPTY: |
|
1266 | { |
1270 | case SLOT_DELETED: |
1267 | case SLOT_EMPTY: |
1271 | // the directrory pointer of this file points to a deleted or not existen directory |
1268 | case SLOT_DELETED: |
1272 | // therefore no file or subdirectory exist here |
1269 | return (retvalue); |
1273 | return(retvalue); |
1270 | break; |
1274 | break; |
1271 | default: // and is a real directory |
1275 | default: // and is a real directory |
1272 | if((dir[file->DirectoryIndex].Attribute & ATTR_SUBDIRECTORY) != ATTR_SUBDIRECTORY) |
1276 | if((dir[file->DirectoryIndex].Attribute & ATTR_SUBDIRECTORY) != ATTR_SUBDIRECTORY) |
1273 | { // current file is not a directory therefore no file or subdirectory can be created here |
1277 | { // current file is not a directory therefore no file or subdirectory can be created here |
1274 | return (retvalue); |
1278 | return(retvalue); |
1275 | } |
1279 | } |
1276 | break; |
1280 | break; |
- | 1281 | } |
|
- | 1282 | // check that search area matches directory entry |
|
- | 1283 | if(file->FirstSectorOfFirstCluster != Fat16ClusterToSector(dir[file->DirectoryIndex].StartCluster)) |
|
- | 1284 | { |
|
1277 | } |
1285 | return (retvalue); |
- | 1286 | } |
|
Line 1278... | Line 1287... | ||
1278 | dircluster = dir[file->DirectoryIndex].StartCluster; |
1287 | } |
1279 | file->FirstSectorOfFirstCluster = Fat16ClusterToSector(dircluster); |
1288 | } |
1280 | } |
1289 | else return(retvalue); // bad sector range for search area |
1281 | 1290 | ||
1282 | // if the new direntry is a subdirectory |
1291 | // if the new directory entry is a subdirectory |
1283 | if((attrib & ATTR_SUBDIRECTORY) == ATTR_SUBDIRECTORY) |
1292 | if((attrib & ATTR_SUBDIRECTORY) == ATTR_SUBDIRECTORY) |
Line 1299... | Line 1308... | ||
1299 | curr_sector = file->FirstSectorOfCurrCluster + dir_sector; // calculate sector number |
1308 | curr_sector = file->FirstSectorOfCurrCluster + dir_sector; // calculate sector number |
1300 | file->SectorInCache = curr_sector; // update the sector number of file cache. |
1309 | file->SectorInCache = curr_sector; // update the sector number of file cache. |
1301 | if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read in the sector. |
1310 | if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read in the sector. |
1302 | { |
1311 | { |
1303 | Fat16_Deinit(); |
1312 | Fat16_Deinit(); |
1304 | return(0); |
1313 | return(retvalue); |
1305 | } |
1314 | } |
Line 1306... | Line 1315... | ||
1306 | 1315 | ||
1307 | dir = (DirEntry_t *)file->Cache; // set pointer to directory |
1316 | dir = (DirEntry_t *)file->Cache; // set pointer to directory |
1308 | // search all directory entries of a sector |
1317 | // search all directory entries of a sector |
Line 1325... | Line 1334... | ||
1325 | dir[dir_entry].StartCluster = subdircluster; // copy the location of the first datacluster to the directoryentry. |
1334 | dir[dir_entry].StartCluster = subdircluster; // copy the location of the first datacluster to the directoryentry. |
1326 | dir[dir_entry].Size = 0; // the new createted file has no content yet. |
1335 | dir[dir_entry].Size = 0; // the new createted file has no content yet. |
1327 | if(SD_SUCCESS != SDC_PutSector(file->SectorInCache, file->Cache)) // write back to card |
1336 | if(SD_SUCCESS != SDC_PutSector(file->SectorInCache, file->Cache)) // write back to card |
1328 | { |
1337 | { |
1329 | Fat16_Deinit(); |
1338 | Fat16_Deinit(); |
1330 | return(0); |
1339 | return(retvalue); |
1331 | } |
1340 | } |
1332 | file->FirstSectorOfFirstCluster = Fat16ClusterToSector(subdircluster); // Calculate absolute sectorposition of first datacluster. |
1341 | file->FirstSectorOfFirstCluster = Fat16ClusterToSector(subdircluster); // Calculate absolute sectorposition of first datacluster. |
1333 | file->FirstSectorOfCurrCluster = file->FirstSectorOfFirstCluster; // Start reading the file with the first sector of the first datacluster. |
1342 | file->FirstSectorOfCurrCluster = file->FirstSectorOfFirstCluster; // Start reading the file with the first sector of the first datacluster. |
1334 | file->SectorOfCurrCluster = 0; // reset sector of cureen cluster |
1343 | file->SectorOfCurrCluster = 0; // reset sector of cureen cluster |
1335 | file->ByteOfCurrSector = 0; // reset the byte location within the current sector |
1344 | file->ByteOfCurrSector = 0; // reset the byte location within the current sector |
Line 1343... | Line 1352... | ||
1343 | ClearCurrCluster(file); // fill cluster with zeros |
1352 | ClearCurrCluster(file); // fill cluster with zeros |
1344 | file->SectorInCache = file->FirstSectorOfFirstCluster; |
1353 | file->SectorInCache = file->FirstSectorOfFirstCluster; |
1345 | if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read in the sector. |
1354 | if(SD_SUCCESS != SDC_GetSector(file->SectorInCache, file->Cache))// read in the sector. |
1346 | { |
1355 | { |
1347 | Fat16_Deinit(); |
1356 | Fat16_Deinit(); |
1348 | return(0); |
1357 | return(retvalue); |
1349 | } |
1358 | } |
1350 | dir = (DirEntry_t *)file->Cache; |
1359 | dir = (DirEntry_t *)file->Cache; |
1351 | // create direntry "." to current dir |
1360 | // create direntry "." to current dir |
1352 | dir[0].Name[0] = 0x2E; |
1361 | dir[0].Name[0] = 0x2E; |
1353 | for(i = 1; i < 11; i++) dir[0].Name[i] = ' '; |
1362 | for(i = 1; i < 11; i++) dir[0].Name[i] = ' '; |
Line 1362... | Line 1371... | ||
1362 | dir[1].StartCluster = dircluster; |
1371 | dir[1].StartCluster = dircluster; |
1363 | dir[1].Size = 0; |
1372 | dir[1].Size = 0; |
1364 | if(SD_SUCCESS != SDC_PutSector(file->SectorInCache, file->Cache))// read in the sector. |
1373 | if(SD_SUCCESS != SDC_PutSector(file->SectorInCache, file->Cache))// read in the sector. |
1365 | { |
1374 | { |
1366 | Fat16_Deinit(); |
1375 | Fat16_Deinit(); |
1367 | return(0); |
1376 | return(retvalue); |
1368 | } |
1377 | } |
1369 | } |
1378 | } |
1370 | retvalue = 1; |
1379 | retvalue = 1; |
1371 | dir_entry = DIRENTRIES_PER_SECTOR; // stop for-loop |
1380 | dir_entry = DIRENTRIES_PER_SECTOR; // stop for-loop |
1372 | } |
1381 | } |
Line 1400... | Line 1409... | ||
1400 | { |
1409 | { |
1401 | DirEntry_t *DirectoryEntry = NULL; |
1410 | DirEntry_t *DirectoryEntry = NULL; |
1402 | u8 retval = 0; |
1411 | u8 retval = 0; |
Line 1403... | Line 1412... | ||
1403 | 1412 | ||
- | 1413 | if((!Partition.IsValid) || (file == NULL)) return (retval); |
|
- | 1414 | // valid directory sector? |
|
1404 | if((!Partition.IsValid) || (file == NULL)) return (retval); |
1415 | if((Partition.FirstRootDirSector <= file->DirectorySector) && (file->DirectorySector < Partition.LastDataSector)) |
1405 | 1416 | { |
|
1406 | // try to read the sector containing the directoryentry of the file to be deleted |
1417 | // try to read the sector containing the directory entry of the file to be deleted |
1407 | if(SD_SUCCESS != SDC_GetSector((u32) file->DirectorySector,file->Cache)) return(retval); |
1418 | if(SD_SUCCESS != SDC_GetSector((u32) file->DirectorySector,file->Cache)) return(retval); |
1408 | // get access to the elements of the directoryentry |
1419 | // get access to the elements of the directoryentry |
1409 | DirectoryEntry = (DirEntry_t *)file->Cache; |
1420 | DirectoryEntry = (DirEntry_t *)file->Cache; |
1410 | // delete the directoryentry |
1421 | // delete the directoryentry |
1411 | DirectoryEntry[file->DirectoryIndex].Name[0] = SLOT_DELETED; |
1422 | DirectoryEntry[file->DirectoryIndex].Name[0] = SLOT_DELETED; |
1412 | DirectoryEntry[file->DirectoryIndex].Attribute = 0; |
1423 | DirectoryEntry[file->DirectoryIndex].Attribute = 0; |
1413 | DirectoryEntry[file->DirectoryIndex].Size = 0; |
1424 | DirectoryEntry[file->DirectoryIndex].Size = 0; |
1414 | // the file has been deleted from the directory, save the modified sector back to the filesystem |
1425 | // the file has been deleted from the directory, save the modified sector back to the filesystem |
- | 1426 | if(SD_SUCCESS == SDC_PutSector((u32) file->DirectorySector,file->Cache)) retval = 1; |
|
1415 | if(SD_SUCCESS == SDC_PutSector((u32) file->DirectorySector,file->Cache)) retval = 1; |
1427 | } |
1416 | return(retval); |
1428 | return(retval); |
Line 1417... | Line 1429... | ||
1417 | } |
1429 | } |
1418 | 1430 | ||
Line 1434... | Line 1446... | ||
1434 | // if incomming pointers are useless return immediatly |
1446 | // if incomming pointers are useless return immediatly |
1435 | if ((filename == NULL) || (file == NULL) || (!Partition.IsValid)) return 0; |
1447 | if ((filename == NULL) || (file == NULL) || (!Partition.IsValid)) return 0; |
Line 1436... | Line 1448... | ||
1436 | 1448 | ||
1437 | // trace along the filepath |
1449 | // trace along the filepath |
1438 | path = (s8*)filename; // start at the beginning of the filename string |
1450 | path = (s8*)filename; // start at the beginning of the filename string |
1439 | file->DirectoryIndex = 0; |
1451 | file->DirectoryIndex = 0; // start search at first dir entry of cluster |
1440 | if(path[0] == '/') // if a path begins with a '/' the search starts at RootDirectory with file search |
1452 | if(path[0] == '/') // if a path begins with a '/' the search starts at RootDirectory with file search |
1441 | { |
1453 | { |
1442 | file->DirectorySector = Partition.FirstRootDirSector; // start at RootDirectory with file search |
1454 | file->FirstSectorOfFirstCluster = Partition.FirstRootDirSector; // start at RootDirectory with file search |
1443 | } |
1455 | } |
1444 | else // if a path begins not with a '/' the search starts relative to the CWD |
1456 | else // if a path begins not with a '/' the search starts relative to the CWD |
1445 | { |
1457 | { |
1446 | file->DirectorySector = Partition.CurrentWorkingDirectory; |
1458 | file->FirstSectorOfFirstCluster = Partition.CurrentWorkingDirectory; |
1447 | } |
1459 | } |
1448 | // as long as the file was not found and the remaining path is not empty |
1460 | // as long as the file was not found and the remaining path is not empty |
1449 | while((*path != 0) && !file_exist) |
1461 | while((*path != 0) && !file_exist) |
1450 | { // separate dirname and subpath from filepath string |
1462 | { // separate dirname and subpath from filepath string |
Line 1473... | Line 1485... | ||
1473 | } |
1485 | } |
1474 | } |
1486 | } |
1475 | } |
1487 | } |
1476 | else // error seperating the subpath |
1488 | else // error seperating the subpath |
1477 | { |
1489 | { |
1478 | return file_exist; // bad subdir format |
1490 | return(file_exist); // bad subdir format |
1479 | } |
1491 | } |
1480 | path = subpath; |
1492 | path = subpath; |
1481 | subpath = 0; |
1493 | subpath = 0; |
1482 | } |
1494 | } |
1483 | return (file_exist); |
1495 | return(file_exist); |
Line 1497... | Line 1509... | ||
1497 | { |
1509 | { |
1498 | s8 *path = 0; |
1510 | s8 *path = 0; |
1499 | s8 *subpath = 0; |
1511 | s8 *subpath = 0; |
1500 | u8 af, am, file_created = 0; |
1512 | u8 af, am, file_created = 0; |
1501 | s8 dirname[12]; |
1513 | s8 dirname[12]; |
- | 1514 | s8 txt[60]; |
|
- | 1515 | u8 i=0; |
|
Line 1502... | Line 1516... | ||
1502 | 1516 | ||
1503 | // if incomming pointers are useless return immediatly |
1517 | // if incomming pointers are useless return immediatly |
Line 1504... | Line 1518... | ||
1504 | if ((filename == NULL) || (file == NULL) || (!Partition.IsValid)) return(0); |
1518 | if ((filename == NULL) || (file == NULL) || (!Partition.IsValid)) return(0); |
1505 | 1519 | ||
Line 1506... | Line 1520... | ||
1506 | // trace along the filepath |
1520 | // trace along the filepath |
1507 | path = (s8*)filename; |
1521 | path = (s8*)filename; |
1508 | 1522 | ||
1509 | if(path[0] == '/') // if a path begins with a '/' the search starts at RootDirectory with file search |
1523 | if(path[0] == '/') // if a path begins with a '/' the search starts at RootDirectory with file search |
1510 | { |
1524 | { |
1511 | file->DirectorySector = Partition.FirstRootDirSector; // start at RootDirectory with file search |
1525 | file->FirstSectorOfFirstCluster = Partition.FirstRootDirSector; // start at RootDirectory with file search |
1512 | } |
1526 | } |
1513 | else // if a path begins not with a '/' the search starts relative to the CWD |
1527 | else // if a path begins not with a '/' the search starts relative to the CWD |
1514 | { |
1528 | { |
Line 1515... | Line 1529... | ||
1515 | file->DirectorySector = Partition.CurrentWorkingDirectory; |
1529 | file->FirstSectorOfFirstCluster = Partition.CurrentWorkingDirectory; |
1516 | } |
1530 | } |
Line 1539... | Line 1553... | ||
1539 | { // could not be created |
1553 | { // could not be created |
1540 | return(file_created); |
1554 | return(file_created); |
1541 | } |
1555 | } |
1542 | else if(*subpath == 0) file_created = 1; // last element of path chain was created |
1556 | else if(*subpath == 0) file_created = 1; // last element of path chain was created |
1543 | } |
1557 | } |
- | 1558 | sprintf(txt+i, "s:%06d",file->FirstSectorOfFirstCluster); |
|
- | 1559 | i+=8; |
|
1544 | } |
1560 | } |
1545 | else // error seperating the subpath |
1561 | else // error seperating the subpath |
1546 | { |
1562 | { |
1547 | return file_created; // bad subdir format |
1563 | return(file_created); // bad subdir format |
1548 | } |
1564 | } |
1549 | path = subpath; |
1565 | path = subpath; |
1550 | subpath = NULL; |
1566 | subpath = NULL; |
1551 | } |
1567 | } |
- | 1568 | Debug(txt); |
|
1552 | return (file_created); |
1569 | return(file_created); |
1553 | } |
1570 | } |
Line 1554... | Line 1571... | ||
1554 | 1571 | ||
Line 2161... | Line 2178... | ||
2161 | File_t file; |
2178 | File_t file; |
Line 2162... | Line 2179... | ||
2162 | 2179 | ||
2163 | if(filepath == NULL) return(0); |
2180 | if(filepath == NULL) return(0); |
2164 | // correct filepath formatting |
2181 | // correct filepath formatting |
- | 2182 | Slashing_Path(filepath); |
|
- | 2183 | file.FirstSectorOfFirstCluster = SECTOR_UNDEFINED; // First sector of the first cluster of the file. |
|
- | 2184 | file.FirstSectorOfCurrCluster = SECTOR_UNDEFINED; // First sector of the cluster which is edited at the moment. |
|
- | 2185 | file.FirstSectorOfLastCluster = SECTOR_UNDEFINED; // First sector of the last cluster of the file |
|
- | 2186 | file.SectorOfCurrCluster = SECTOR_UNDEFINED; // The sector within the current cluster. |
|
- | 2187 | file.ByteOfCurrSector = 0; // The byte location within the current sector. |
|
- | 2188 | file.Mode = 0; // Mode of fileoperation (read,write) |
|
- | 2189 | file.Size = 0; // The size of the opend file in bytes. |
|
- | 2190 | file.Position = 0; // Pointer to a character within the file 0 < fileposition < filesize |
|
- | 2191 | file.DirectorySector = SECTOR_UNDEFINED; // the sectorposition where the directoryentry has been made. |
|
- | 2192 | file.DirectoryIndex = 0; // The index to the directoryentry within the specified sector. |
|
- | 2193 | file.Attribute = 0; // The attribute of the file opened. |
|
- | 2194 | file.SectorInCache = SECTOR_UNDEFINED; // The last sector read, which is still in the sector cache. |
|
- | 2195 | file.State = FSTATE_USED; // mark it as used |
|
2165 | Slashing_Path(filepath); |
2196 | |
2166 | // if file is existent |
2197 | // if file is existent |
2167 | if(FileExist(filepath, ATTR_NONE, ATTR_SUBDIRECTORY|ATTR_VOLUMELABEL, &file)) |
2198 | if(FileExist(filepath, ATTR_NONE, ATTR_SUBDIRECTORY|ATTR_VOLUMELABEL, &file)) |
2168 | { |
2199 | { |
2169 | // and is not marked as readonly? |
2200 | // and is not marked as readonly? |
Line 2683... | Line 2714... | ||
2683 | { |
2714 | { |
2684 | retvalue = 0; |
2715 | retvalue = 0; |
2685 | // we have modified the result of the findfirst_ operation therefore we have to redo findfirst_ to get detailed infos about the directory entry to be deleted |
2716 | // we have modified the result of the findfirst_ operation therefore we have to redo findfirst_ to get detailed infos about the directory entry to be deleted |
2686 | if(findfirst_(dn, 0xff, &fe)) |
2717 | if(findfirst_(dn, 0xff, &fe)) |
2687 | { |
2718 | { |
- | 2719 | Debug("found"); |
|
2688 | // try to clear the allocated clusters within the fat |
2720 | // try to clear the allocated clusters within the fat |
2689 | if(DeleteClusterChain(fe.fp.FirstSectorOfFirstCluster)) |
2721 | if(DeleteClusterChain(fe.fp.FirstSectorOfFirstCluster)) |
2690 | { |
2722 | { |
2691 | // delete the directoryentry within the specified directory |
2723 | // delete the directoryentry within the specified directory |
2692 | if(DeleteDirectoryEntry(&(fe.fp))) retvalue = 1; |
2724 | if(DeleteDirectoryEntry(&(fe.fp))) retvalue = 1; |
Line 2717... | Line 2749... | ||
2717 | File_t file; |
2749 | File_t file; |
Line 2718... | Line 2750... | ||
2718 | 2750 | ||
2719 | if(dirpath == NULL) return(0); |
2751 | if(dirpath == NULL) return(0); |
2720 | // correct filepath formatting |
2752 | // correct filepath formatting |
- | 2753 | Slashing_Path(dirpath); |
|
- | 2754 | file.FirstSectorOfFirstCluster = SECTOR_UNDEFINED; // First sector of the first cluster of the file. |
|
- | 2755 | file.FirstSectorOfCurrCluster = SECTOR_UNDEFINED; // First sector of the cluster which is edited at the moment. |
|
- | 2756 | file.FirstSectorOfLastCluster = SECTOR_UNDEFINED; // First sector of the last cluster of the file |
|
- | 2757 | file.SectorOfCurrCluster = SECTOR_UNDEFINED; // The sector within the current cluster. |
|
- | 2758 | file.ByteOfCurrSector = 0; // The byte location within the current sector. |
|
- | 2759 | file.Mode = 0; // Mode of fileoperation (read,write) |
|
- | 2760 | file.Size = 0; // The size of the opend file in bytes. |
|
- | 2761 | file.Position = 0; // Pointer to a character within the file 0 < fileposition < filesize |
|
- | 2762 | file.DirectorySector = SECTOR_UNDEFINED; // the sectorposition where the directoryentry has been made. |
|
- | 2763 | file.DirectoryIndex = 0; // The index to the directoryentry within the specified sector. |
|
- | 2764 | file.Attribute = 0; // The attribute of the file opened. |
|
- | 2765 | file.SectorInCache = SECTOR_UNDEFINED; // The last sector read, which is still in the sector cache. |
|
2721 | Slashing_Path(dirpath); |
2766 | file.State = FSTATE_USED; // mark it as used |
2722 | // if directory is not existent |
2767 | // if directory is not existent |
2723 | if(!FileExist(dirpath, ATTR_SUBDIRECTORY, ATTR_SUBDIRECTORY|ATTR_VOLUMELABEL, &file)) |
2768 | if(!FileExist(dirpath, ATTR_SUBDIRECTORY, ATTR_SUBDIRECTORY|ATTR_VOLUMELABEL, &file)) |
2724 | { |
2769 | { |
2725 | retvalue = FileCreate(dirpath, ATTR_SUBDIRECTORY, &file); |
2770 | retvalue = FileCreate(dirpath, ATTR_SUBDIRECTORY, &file); |