- Timestamp:
- 10/14/08 18:46:19 (1 month ago)
- Files:
-
- 1 modified
-
Whitix/branches/keobject/user/makefs/fat/main.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Whitix/branches/keobject/user/makefs/fat/main.c
r1094 r1125 36 36 /* Only used by FAT32 */ 37 37 DWORD secsPerFat32; 38 38 39 WORD extFlags; 39 40 WORD fsVer; … … 79 80 char emptySector[512]; 80 81 unsigned long numClusters,fatLength; 81 char* fatFirst ,*rootDir;82 char* fatFirst; 82 83 83 84 int GetDeviceInfo() … … 117 118 if (stat.mode & _SYS_STAT_BLOCK) 118 119 { 119 printf("Block device: TODO. Get sector size \n");120 printf("Block device: TODO. Get sector size. 512 for now.\n"); 120 121 blockSize=512; 121 122 }else … … 147 148 } 148 149 150 void FatMarkCluster(int index, DWORD value) 151 { 152 switch (fatSize) 153 { 154 case 12: 155 { 156 unsigned char* fat=(unsigned char*)fatFirst; 157 value &= 0x0FFF; 158 159 if (!((index * 3) & 0x1)) 160 { 161 fat[3*index/2]=value & 0xFF; 162 fat[(3*index/2)+1]=((fat[(3*index/2)+1] & 0xF0) 163 | ((value & 0xF00) >> 8)); 164 }else{ 165 printf("TODO\n"); 166 } 167 break; 168 } 169 170 case 16: 171 { 172 unsigned short* fat=(unsigned short*)fatFirst; 173 fat[index] = (unsigned short)value; 174 break; 175 } 176 177 default: 178 printf("TODO\n"); 179 } 180 } 181 149 182 int ConstructFs() 150 183 { … … 247 280 } 248 281 282 if (verbose) 283 printf("Number of reserved sectors: %u\n", reservedSectors); 284 249 285 /* TODO: Fill in boot code? */ 250 286 251 strncpy((char*)bootSec.oemID, "mkfatfs",11);287 strncpy((char*)bootSec.oemID, "mkfatfs", 8); 252 288 bootSec.bytesPerSec=blockSize; 253 289 bootSec.sectorsPerClus=secsPerClus; … … 255 291 bootSec.numFats=numFats; 256 292 bootSec.numRootDirEnts=numRootDirEnts; 257 bootSec. totalSecSmall=totalSize/blockSize;258 /* media ID byte */259 bootSec. secsPerTrack=bootSec.heads=0;293 bootSec.mediaIDByte=0xF8; 294 bootSec.secsPerTrack=32; 295 bootSec.heads=64; 260 296 bootSec.secsPerFat=(WORD)fatLength; 261 262 strncpy(bootSec.volLabel,(volumeName) ? volumeName : "mkfatfs",11); 297 bootSec.hiddenSectors=0; 298 bootSec.totalSecSmall=bootSec.totalSectorsLarge=totalSize/blockSize; 299 bootSec.volID=0xDEADBEEF; 300 bootSec.bootSig=0x28; 301 bootSec.driveNum=0x80; 302 strncpy(bootSec.volLabel,(volumeName) ? volumeName : "whitix",11); 303 strncpy(bootSec.fileSysType, "FAT16", 8); 263 304 264 305 /* Allocate the FAT and initiate special entries? */ … … 269 310 memset(fatFirst,0,blockSize); 270 311 271 /* Make the . and .. entries */ 272 rootDir=(char*)malloc(blockSize); 273 if (!rootDir) 274 { 275 free(fatFirst); 276 return 1; 277 } 278 279 memset(rootDir,0,blockSize); 280 281 dirEntry=(struct FatDirEntry*)rootDir; 282 283 /* '.' */ 284 memcpy(dirEntry->fileName,". ",11); 285 dirEntry->startClusterLow=dirEntry->startClusterHigh=0; 286 dirEntry->fileSize=0; 287 dirEntry->attribute=ATTR_DIR; 312 FatMarkCluster(0, 0xFFFFFFFF); 313 FatMarkCluster(1, 0xFFFFFFFF); 288 314 289 /* TODO: time */ 290 291 dirEntry++; 292 293 /* '..' */ 294 memcpy(dirEntry->fileName,".. ",11); 295 dirEntry->startClusterLow=dirEntry->startClusterHigh=0; 296 dirEntry->fileSize=0; 297 dirEntry->attribute=ATTR_DIR; 315 /* Put the media byte in the first byte. */ 316 fatFirst[0] = 0xF8; 298 317 299 318 return 0; … … 330 349 WriteBuffer(fatFirst,blockSize); 331 350 for (j=0; j<fatLength-1; j++) 332 WriteBuffer(emptySector, blockSize);351 WriteBuffer(emptySector, blockSize); 333 352 334 353 if (verbose) … … 336 355 } 337 356 338 /* Write root directory - again only the first sector is important */ 339 WriteBuffer(rootDir,blockSize); 357 /* Write root directory */ 340 358 341 for (i=0; i<((numRootDirEnts*32)/blockSize) -1; i++)359 for (i=0; i<((numRootDirEnts*32)/blockSize); i++) 342 360 WriteBuffer(emptySector,blockSize); 343 361 … … 345 363 printf("Wrote root directory\n"); 346 364 347 /* Free fat and root dir entries */ 348 free(rootDir); 365 /* Free fat entries */ 349 366 free(fatFirst); 350 367
