Changeset 1125 for Whitix

Show
Ignore:
Timestamp:
10/14/08 18:46:19 (1 month ago)
Author:
mwhitworth
Message:

Add to mkfatfs, bug fixes, put media byte in first FAT entry's first byte.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/keobject/user/makefs/fat/main.c

    r1094 r1125  
    3636        /* Only used by FAT32 */ 
    3737        DWORD secsPerFat32; 
     38         
    3839        WORD extFlags; 
    3940        WORD fsVer; 
     
    7980char emptySector[512]; 
    8081unsigned long numClusters,fatLength; 
    81 char* fatFirst,*rootDir; 
     82char* fatFirst; 
    8283 
    8384int GetDeviceInfo() 
     
    117118        if (stat.mode & _SYS_STAT_BLOCK) 
    118119        { 
    119                 printf("Block device: TODO. Get sector size\n"); 
     120                printf("Block device: TODO. Get sector size. 512 for now.\n"); 
    120121                blockSize=512; 
    121122        }else 
     
    147148} 
    148149 
     150void 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 
    149182int ConstructFs() 
    150183{ 
     
    247280        } 
    248281 
     282        if (verbose) 
     283                printf("Number of reserved sectors: %u\n", reservedSectors); 
     284 
    249285        /* TODO: Fill in boot code? */ 
    250286 
    251         strncpy((char*)bootSec.oemID,"mkfatfs",11); 
     287        strncpy((char*)bootSec.oemID, "mkfatfs", 8); 
    252288        bootSec.bytesPerSec=blockSize; 
    253289        bootSec.sectorsPerClus=secsPerClus; 
     
    255291        bootSec.numFats=numFats; 
    256292        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; 
    260296        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); 
    263304 
    264305        /* Allocate the FAT and initiate special entries? */ 
     
    269310        memset(fatFirst,0,blockSize); 
    270311 
    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); 
    288314         
    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; 
    298317 
    299318        return 0; 
     
    330349                WriteBuffer(fatFirst,blockSize); 
    331350                for (j=0; j<fatLength-1; j++) 
    332                         WriteBuffer(emptySector,blockSize); 
     351                        WriteBuffer(emptySector, blockSize); 
    333352 
    334353                if (verbose) 
     
    336355        } 
    337356 
    338         /* Write root directory - again only the first sector is important */ 
    339         WriteBuffer(rootDir,blockSize); 
     357        /* Write root directory */ 
    340358         
    341         for (i=0; i<((numRootDirEnts*32)/blockSize)-1; i++) 
     359        for (i=0; i<((numRootDirEnts*32)/blockSize); i++) 
    342360                WriteBuffer(emptySector,blockSize); 
    343361 
     
    345363                printf("Wrote root directory\n"); 
    346364 
    347         /* Free fat and root dir entries */ 
    348         free(rootDir); 
     365        /* Free fat entries */ 
    349366        free(fatFirst); 
    350367