- Timestamp:
- 10/07/08 16:28:15 (2 months ago)
- Location:
- Whitix/branches/keobject/fs/fat
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
Whitix/branches/keobject/fs/fat/dir.c
r705 r1096 167 167 */ 168 168 169 // printf("%s, nameLen = %d, base len = %d, extension len = %d\n",name,nameLength,FatBaseNameLen(name,nameLength),FatExtensionLen(name,nameLength));169 // KePrint("%s, nameLen = %d, base len = %d, extension len = %d\n",name,nameLength,FatBaseNameLen(name,nameLength),FatExtensionLen(name,nameLength)); 170 170 171 171 if (!FatIsLong(name,nameLength)) … … 224 224 } 225 225 } 226 226 227 227 return -ENOENT; 228 228 } -
Whitix/branches/keobject/fs/fat/fat.c
r929 r1096 56 56 } 57 57 58 /* Due to the lovely FAT12 format, where entries can strech over blocks, 2 blocks have to be read in in the worst59 case scenario */58 /* Due to the lovely FAT12 format, where entries can strech over blocks, 59 * 2 blocks have to be read in in the worst case scenario */ 60 60 61 61 /* Get the index number into the FAT */ … … 100 100 retVal=(*pFirst+(*pLast << 8)) & 0xFFF; 101 101 }else if (fatInfo->fatType == 16) 102 /* Much simpler =) */103 102 retVal=*(WORD*)&buff->data[first % BYTES_PER_SECTOR(sBlock)]; 104 103 else if (fatInfo->fatType == 32) … … 211 210 return 0; 212 211 212 if (fatInfo->fatType != 32 && cluster == fatInfo->rootDirStart) 213 return fatInfo->rootDirLength*sizeof(struct FatDirEntry); 214 213 215 while (cluster < fatInfo->invalidCluster) 214 216 { … … 247 249 if (val >= sbInfo->invalidCluster) 248 250 break; 251 249 252 last=val; 250 253 } … … 263 266 264 267 /* Zero out the new sector*/ 265 buff=BlockRead(vNode->superBlock->sDevice, FatToSector(vNode->superBlock, ret));266 ZeroMemory(buff->data, BYTES_PER_SECTOR(vNode->superBlock));267 BlockWrite(vNode->superBlock->sDevice, buff);268 buff=BlockRead(vNode->superBlock->sDevice, FatToSector(vNode->superBlock, ret)); 269 ZeroMemory(buff->data, BYTES_PER_SECTOR(vNode->superBlock)); 270 BlockWrite(vNode->superBlock->sDevice, buff); 268 271 BlockFree(buff); 269 272 270 273 /* Now add an EOF marker in that last cluster */ 271 FatAccess(vNode->superBlock, ret,sbInfo->invalidCluster);274 FatAccess(vNode->superBlock, ret, sbInfo->invalidCluster); 272 275 273 276 if (!fatVNodeInfo->startCluster) … … 275 278 else if (last) 276 279 /* Add the new cluster onto the end of last */ 277 FatAccess(vNode->superBlock, last,ret);280 FatAccess(vNode->superBlock, last, ret); 278 281 279 282 if (lastCluster) -
Whitix/branches/keobject/fs/fat/file.c
r929 r1096 64 64 ***********************************************************************/ 65 65 66 /* FIXME: Needs simplify, especially the main while case. */ 67 66 68 int FatBlockMap(struct VNode* vNode, DWORD offset, int flags) 67 69 { … … 74 76 * is given in the FAT's superblock), so make sure the offset is within limits. 75 77 * In FAT32, this is not a problem as a root directory operates like a normal 76 * directory. 77 * Why couldn't FAT12 and FAT16 have done that in the first place? 78 * 78 * directory. 79 79 */ 80 80 … … 86 86 return fatSbInfo->rootDirStart+offset; 87 87 } 88 89 offset/=fatSbInfo->secsPerClus; 88 90 89 91 /* The vNode might not have a start cluster because it has just been created. */ … … 92 94 if (flags & VFS_MAP_CREATE) 93 95 { 94 FatAddCluster(vNode, NULL); 95 return FatGetPriv(vNode)->startCluster; 96 if (FatAddCluster(vNode, NULL)) 97 return -1; 98 99 return FatToSector(vNode->superBlock, FatGetPriv(vNode)->startCluster) 100 + offset; 96 101 }else 97 102 return -1; 98 103 } 99 100 offset/=fatSbInfo->secsPerClus;101 104 102 105 while (offset--) … … 105 108 if (retVal >= fatSbInfo->invalidCluster) 106 109 { 107 DWORD lastCluster =0;110 DWORD lastCluster; 108 111 109 112 if (!(flags & VFS_MAP_CREATE)) 110 113 return -1; 111 114 115 offset++; 116 112 117 /* Add a new cluster if the block requested is one more than needed. */ 113 118 while (offset--) 114 FatAddCluster(vNode, &lastCluster); 115 116 KePrint("lastCluster = %#X\n", lastCluster); 117 118 return lastCluster+(origOffset % fatSbInfo->secsPerClus); 119 { 120 if (FatAddCluster(vNode, &lastCluster)) 121 return -1; 122 } 123 124 return FatToSector(vNode->superBlock, lastCluster)+ 125 (origOffset % fatSbInfo->secsPerClus); 119 126 } 120 127 } -
Whitix/branches/keobject/fs/fat/vnode.c
r929 r1096 132 132 struct FatDirEntry* retVal,DWORD* vNum,DWORD* wantedStart) 133 133 { 134 /* Scanning the root directory (of fat12 and fat16) is a special case because it is linear and it's not possible 135 to GetNextCluster() on it */ 136 137 DWORD i=start; 134 /* Scanning the root directory (of fat12 and fat16) is a special case 135 * because it is linear and it's not possible to GetNextCluster() on it */ 136 138 137 int err=0; 138 int i=0; 139 139 struct FatSbInfo* sbInfo=FatGetSbPriv(superBlock); 140 140 141 while ( i<sbInfo->rootDirLength)141 while ( i < sbInfo->rootDirLength) 142 142 { 143 143 DWORD cluster=0; 144 cluster= FatToSector(superBlock,cluster)+i;144 cluster=start+i; 145 145 err=FatDirScanSector(superBlock,cluster,name,retVal,vNum,wantedStart); 146 146 … … 168 168 { 169 169 struct FatSbInfo* sbInfo=FatGetSbPriv(superBlock); 170 if ( !start && sbInfo->fatType != 32)170 if (sbInfo->fatType != 32 && start == sbInfo->rootDirStart) 171 171 return FatScanDirRootRaw(superBlock,start,name,retVal,vNum,wantedStart); 172 172 else … … 191 191 } 192 192 193 int FatParentVNo(struct VNode* dir, DWORD* vNum)193 int FatParentVNo(struct VNode* dir, DWORD* vNum) 194 194 { 195 195 int err; … … 204 204 FAT_DOTDOT, NULL, NULL, &startCluster); 205 205 206 if (err) 207 return err; 208 206 209 /* Is the root directory then */ 207 210 if (startCluster == FatGetSbPriv(dir->superBlock)->rootDirStart) … … 227 230 /* Find the (proper) parent vNode number, and jump ahead. */ 228 231 err=FatParentVNo(dir, &vNum); 229 232 230 233 if (err) 231 234 return err; … … 233 236 goto getVNode; 234 237 } 235 238 236 239 /* Otherwise, for a normal entry, just scan the directory. */ 237 240 err=FatScanDir(dir,name,nameLength,NULL,&vNum,NULL); … … 576 579 577 580 err=FatCreateEntry(dir,name,nameLength,ATTR_ARCHIVE,&vNum); 581 578 582 if (err) 579 583 return err; … … 608 612 /* Add the '.' entry */ 609 613 err=FatAddShortName(*retVal,FAT_DOT,-1,&vNum,ATTR_DIR); 614 610 615 if (err) 611 616 goto error; 612 617 613 618 buffer=BlockRead(dir->superBlock->sDevice,VNUM_TO_SECTOR(vNum)); 619 614 620 dirEntry=(struct FatDirEntry*)(buffer->data+VNUM_TO_OFFSET(vNum)*sizeof(struct FatDirEntry)); 615 621 … … 637 643 638 644 error: 645 KePrint(KERN_DEBUG "Could not add %s, %d\n", name, err); 639 646 return err; 640 647 }
