Changeset 1096 for Whitix

Show
Ignore:
Timestamp:
10/07/08 16:28:15 (2 months ago)
Author:
mwhitworth
Message:

Add FatFsToSector call when allocating first sector, clean up comments and misc formatting fixes.

Location:
Whitix/branches/keobject/fs/fat
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/keobject/fs/fat/dir.c

    r705 r1096  
    167167         */ 
    168168 
    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)); 
    170170 
    171171        if (!FatIsLong(name,nameLength)) 
     
    224224                } 
    225225        } 
    226  
     226         
    227227        return -ENOENT; 
    228228} 
  • Whitix/branches/keobject/fs/fat/fat.c

    r929 r1096  
    5656        } 
    5757 
    58         /* Due to the lovely FAT12 format, where entries can strech over blocks, 2 blocks have to be read in in the worst 
    59            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 */ 
    6060 
    6161        /* Get the index number into the FAT */ 
     
    100100                        retVal=(*pFirst+(*pLast << 8)) & 0xFFF; 
    101101        }else if (fatInfo->fatType == 16) 
    102                 /* Much simpler =) */ 
    103102                retVal=*(WORD*)&buff->data[first % BYTES_PER_SECTOR(sBlock)]; 
    104103        else if (fatInfo->fatType == 32) 
     
    211210                return 0; 
    212211 
     212        if (fatInfo->fatType != 32 && cluster == fatInfo->rootDirStart) 
     213                return fatInfo->rootDirLength*sizeof(struct FatDirEntry); 
     214 
    213215        while (cluster < fatInfo->invalidCluster) 
    214216        { 
     
    247249                        if (val >= sbInfo->invalidCluster) 
    248250                                break; 
     251                                 
    249252                        last=val; 
    250253                } 
     
    263266 
    264267        /* 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); 
    268271        BlockFree(buff); 
    269272 
    270273        /* Now add an EOF marker in that last cluster */ 
    271         FatAccess(vNode->superBlock,ret,sbInfo->invalidCluster); 
     274        FatAccess(vNode->superBlock, ret, sbInfo->invalidCluster); 
    272275 
    273276        if (!fatVNodeInfo->startCluster) 
     
    275278        else if (last) 
    276279                /* Add the new cluster onto the end of last */ 
    277                 FatAccess(vNode->superBlock,last,ret); 
     280                FatAccess(vNode->superBlock, last, ret); 
    278281 
    279282        if (lastCluster) 
  • Whitix/branches/keobject/fs/fat/file.c

    r929 r1096  
    6464 ***********************************************************************/ 
    6565 
     66/* FIXME: Needs simplify, especially the main while case. */ 
     67 
    6668int FatBlockMap(struct VNode* vNode, DWORD offset, int flags) 
    6769{ 
     
    7476         * is given in the FAT's superblock), so make sure the offset is within limits. 
    7577         * 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. 
    7979         */ 
    8080 
     
    8686                return fatSbInfo->rootDirStart+offset; 
    8787        } 
     88         
     89        offset/=fatSbInfo->secsPerClus; 
    8890 
    8991        /* The vNode might not have a start cluster because it has just been created. */ 
     
    9294                if (flags & VFS_MAP_CREATE) 
    9395                { 
    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; 
    96101                }else 
    97102                        return -1; 
    98103        } 
    99  
    100         offset/=fatSbInfo->secsPerClus; 
    101104 
    102105        while (offset--) 
     
    105108                if (retVal >= fatSbInfo->invalidCluster) 
    106109                { 
    107                         DWORD lastCluster=0; 
     110                        DWORD lastCluster; 
    108111 
    109112                        if (!(flags & VFS_MAP_CREATE)) 
    110113                                return -1; 
    111114 
     115                        offset++; 
     116 
    112117                        /* Add a new cluster if the block requested is one more than needed. */ 
    113118                        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); 
    119126                } 
    120127        } 
  • Whitix/branches/keobject/fs/fat/vnode.c

    r929 r1096  
    132132                                                         struct FatDirEntry* retVal,DWORD* vNum,DWORD* wantedStart) 
    133133{ 
    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         
    138137        int err=0; 
     138        int i=0; 
    139139        struct FatSbInfo* sbInfo=FatGetSbPriv(superBlock); 
    140140 
    141         while (i<sbInfo->rootDirLength) 
     141        while ( i < sbInfo->rootDirLength) 
    142142        { 
    143143                DWORD cluster=0; 
    144                 cluster=FatToSector(superBlock,cluster)+i; 
     144                cluster=start+i; 
    145145                err=FatDirScanSector(superBlock,cluster,name,retVal,vNum,wantedStart); 
    146146 
     
    168168{ 
    169169        struct FatSbInfo* sbInfo=FatGetSbPriv(superBlock); 
    170         if (!start && sbInfo->fatType != 32) 
     170        if (sbInfo->fatType != 32 && start == sbInfo->rootDirStart) 
    171171                return FatScanDirRootRaw(superBlock,start,name,retVal,vNum,wantedStart); 
    172172        else 
     
    191191} 
    192192 
    193 int FatParentVNo(struct VNode* dir,DWORD* vNum) 
     193int FatParentVNo(struct VNode* dir, DWORD* vNum) 
    194194{ 
    195195        int err; 
     
    204204                FAT_DOTDOT, NULL, NULL, &startCluster); 
    205205                 
     206        if (err) 
     207                return err; 
     208                 
    206209        /* Is the root directory then */ 
    207210        if (startCluster == FatGetSbPriv(dir->superBlock)->rootDirStart) 
     
    227230                /* Find the (proper) parent vNode number, and jump ahead. */ 
    228231                err=FatParentVNo(dir, &vNum); 
    229  
     232                 
    230233                if (err) 
    231234                        return err; 
     
    233236                goto getVNode; 
    234237        } 
    235  
     238         
    236239        /* Otherwise, for a normal entry, just scan the directory. */ 
    237240        err=FatScanDir(dir,name,nameLength,NULL,&vNum,NULL); 
     
    576579 
    577580        err=FatCreateEntry(dir,name,nameLength,ATTR_ARCHIVE,&vNum); 
     581         
    578582        if (err) 
    579583                return err; 
     
    608612        /* Add the '.' entry */ 
    609613        err=FatAddShortName(*retVal,FAT_DOT,-1,&vNum,ATTR_DIR); 
     614         
    610615        if (err) 
    611616                goto error; 
    612617 
    613618        buffer=BlockRead(dir->superBlock->sDevice,VNUM_TO_SECTOR(vNum)); 
     619         
    614620        dirEntry=(struct FatDirEntry*)(buffer->data+VNUM_TO_OFFSET(vNum)*sizeof(struct FatDirEntry)); 
    615621 
     
    637643         
    638644error: 
     645        KePrint(KERN_DEBUG "Could not add %s, %d\n", name, err); 
    639646        return err; 
    640647}