Changeset 747

Show
Ignore:
Timestamp:
07/07/08 20:09:17 (5 months ago)
Author:
mwhitworth
Message:

Add ext3 directory to Makefile.

Location:
Whitix/branches/fs/fs
Files:
2 added
10 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/fs/fs/Makefile

    r702 r747  
    66        $(MAKE) -C devfs 
    77        $(MAKE) -C reiserfs 
     8        $(MAKE) -C journal 
    89 
    910modules_install: 
     
    1112        $(MAKE) -C vfs modules_install 
    1213        $(MAKE) -C devfs modules_install 
     14        $(MAKE) -C ext3 modules_install 
    1315        $(MAKE) -C reiserfs modules_install 
     16        $(MAKE) -C journal modules_install 
    1417 
    1518clean: 
     
    2023        $(MAKE) -C devfs clean 
    2124        $(MAKE) -C reiserfs clean 
     25        $(MAKE) -C journal clean 
  • Whitix/branches/fs/fs/ext3/Makefile

    r703 r747  
    11DEPTH=../../ 
    2 MODULES = super.sys inode.sys 
     2MODULES = super.sys inode.sys file.sys 
    33 
    44build: $(MODULES) 
    55        ld $(LD_R_FLAGS) $(MODULES) -o ext3.sys 
    66 
     7modules_install: 
     8        cp ext3.sys ../../CdRoot/System/Modules/Core 
     9 
    710include $(DEPTH)make.inc 
    811-include $(DEPS) 
  • Whitix/branches/fs/fs/ext3/ext3.h

    r608 r747  
    2323#include <init.h> 
    2424 
     25/* EXT3 features */ 
     26#define EXT3_FEATURE_COMPAT_JOURNAL             0x4 
     27 
     28#define EXT3_FEATURE_COMPAT(sb, feature) ((sb)->featureCompat & (feature)) 
     29 
    2530struct Ext3SuperBlock 
    2631{ 
    27         DWORD iNodesCount; /* Inodes Count */ 
    28         DWORD blocksCount; /* Blocks Count */ 
    29         DWORD reservedBlocks; /* Reserved Blocks Count */ 
    30         DWORD freeBlocks; /* Free Blocks Count */ 
    31         DWORD freeInodes; /* Free inode Count */ 
    32         DWORD firstDataBlock; /* First Data Block */ 
    33         DWORD logBlockSize; /* Block Size as a power of 2. The unit is 1024. Thus  
     32        DWORD iNodesCount;              /* Inodes Count */ 
     33        DWORD blocksCount;              /* Blocks Count */ 
     34        DWORD reservedBlocks;   /* Reserved Blocks Count */ 
     35        DWORD freeBlocks;               /* Free Blocks Count */ 
     36        DWORD freeInodes;               /* Free inode Count */ 
     37        DWORD firstDataBlock;   /* First Data Block */ 
     38        DWORD logBlockSize;     /* Block Size as a power of 2. The unit is 1024. Thus  
    3439        0 == 1024 , 1 = 2048 , 2 = 4096*/ 
    35         DWORD logFragSize; /* Fragments are not yet implemented int ext3. So  
     40        DWORD logFragSize;              /* Fragments are not yet implemented int ext3. So  
    3641        logFragSize .equal. logBlockSize */ 
    37         DWORD blocksPerGrp; /* Number of Blocks in each block group */ 
     42        DWORD blocksPerGrp;     /* Number of Blocks in each block group */ 
    3843        DWORD fragsPerGrp; /* Number of Fragments in each block group */ 
    3944        DWORD iNodesPerGrp; /* Number of Inodes in each block group */ 
     
    8792{ 
    8893        DWORD iNodesCount,groupCount,iNodesPerGrp; 
     94        DWORD firstDataBlock, blocksPerGrp; 
    8995        struct Buffer** descs; 
    9096}; 
     
    98104 
    99105/*   
    100  * Each block group has its own group discriptor 
     106 * Each block group has its own group descriptor 
    101107 */ 
    102108struct Ext3GroupDesc 
     
    144150{ 
    145151        DWORD iNodeNum; // Inode number 
    146         WORD recLen; // Directoy entry length 
     152        WORD recLen; // Directory entry length 
    147153        BYTE nameLen;// filename length 
    148154        BYTE fileType; // file type 
     
    152158/* Common functions */ 
    153159int Ext3ReadVNode(struct VNode* vNode); 
     160int Ext3WriteVNode(struct VNode* vNode); 
     161int Ext3DirtyVNode(struct VNode* vNode); 
    154162int Ext3Lookup(struct VNode** retVal,struct VNode* dir,char* name,int nameLength); 
    155163int Ext3ReadDir(struct File* file,void* dirEntries); 
    156 int Ext3BlockMap(struct VNode* vNode,int block); 
     164int Ext3BlockMap(struct VNode* vNode, DWORD block, int flags); 
    157165struct Buffer* Ext3BlockRead(struct VNode* vNode,int block); 
    158 int Ext3Read(struct File* file,BYTE* buffer,DWORD len); 
     166 
     167int Ext3FileWrite(struct File* file,BYTE* buffer,DWORD len); 
    159168 
    160169extern struct VNodeOps ext3VNodeOps; 
     
    167176#define DESCS_PER_BLOCK(s) (BYTES_PER_SECTOR(s)/sizeof(struct Ext3GroupDesc)) 
    168177#define INODES_PER_BLOCK(s) (BYTES_PER_SECTOR(s)/sizeof(struct Ext3INode)) 
     178#define EXT3_SUPERINFO(s) ((struct Ext3SbInfo*)((s)->privData)) 
    169179 
    170180#define EXT3_SB_MAGIC   0xEF53 
  • Whitix/branches/fs/fs/ext3/file.c

    r1 r747  
     1#include "ext3.h" 
     2 
     3#include <print.h> 
     4 
     5int Ext3FileWrite(struct File* file, BYTE* buffer, DWORD size) 
     6{ 
     7        return FileGenericWrite(file, buffer, size); 
     8} 
  • Whitix/branches/fs/fs/ext3/inode.c

    r705 r747  
    2626        /* Get the group descriptor for the inode */ 
    2727        groupDesc=blockGroup/DESCS_PER_BLOCK(vNode->superBlock); 
    28         desc=blockGroup % DESCS_PER_BLOCK(vNode->superBlock); 
     28        desc=blockGroup & (DESCS_PER_BLOCK(vNode->superBlock)-1); 
     29 
    2930        groupDescs=(struct Ext3GroupDesc*)(sbInfo->descs[groupDesc]->data); 
     31 
     32        if (!groupDescs) 
     33                return -EFAULT; 
    3034 
    3135        block=groupDescs[desc].iNodeTable+((vNo % sbInfo->iNodesPerGrp)/INODES_PER_BLOCK(vNode->superBlock)); 
     
    3943 
    4044        iNodeInfo=(struct Ext3INodeInfo*)malloc(sizeof(struct Ext3INodeInfo)); 
    41         vNode->extraInfo=iNodeInfo; 
     45 
    4246        if (!iNodeInfo) 
    4347        { 
     
    5862        vNode->fileOps=&ext3FileOps; 
    5963        vNode->mode=VFS_ATTR_WRITE | VFS_ATTR_READ; 
     64        vNode->extraInfo=iNodeInfo; 
     65 
    6066        if ((iNode->mode & 0xF000) == 0x4000) 
    6167                vNode->mode|=VFS_ATTR_DIR; 
     
    6672 
    6773        BlockFree(buffer); 
     74        return 0; 
     75} 
     76 
     77int Ext3WriteVNode(struct VNode* vNode) 
     78{ 
     79        KePrint("Ext3WriteVNode\n"); 
     80        return 0; 
     81} 
     82 
     83int Ext3DirtyVNode(struct VNode* vNode) 
     84{ 
     85        KePrint("Ext3DirtyVNode\n"); 
     86        cli(); hlt(); 
    6887        return 0; 
    6988} 
     
    106125} 
    107126 
    108 int Ext3BlockMap(struct VNode* vNode,int block) 
     127int Ext3BlockMap(struct VNode* vNode, DWORD block, int flags) 
    109128{ 
    110129        struct Ext3INodeInfo* iNodeInfo=(struct Ext3INodeInfo*)vNode->extraInfo; 
     
    115134                if (!iNodeInfo->blocks[block]) 
    116135                { 
    117                         KePrint("Ext3: BlockMap, iNodeInfo->blocks[block] = 0\n"); 
     136                        if (!(flags & VFS_MAP_CREATE)) 
     137                                return -EIO; 
     138 
     139                        KePrint("Ext3: BlockMap, iNodeInfo->blocks[%d] = 0\n", block); 
    118140                        cli(); hlt(); 
    119141                } 
     
    158180struct Buffer* Ext3BlockRead(struct VNode* vNode,int block) 
    159181{ 
    160         int realBlock=Ext3BlockMap(vNode,block); 
    161         if (realBlock == -1) 
     182        int realBlock=Ext3BlockMap(vNode,block, 0); 
     183        if (realBlock < 0) 
    162184                return NULL; 
    163185         
  • Whitix/branches/fs/fs/ext3/super.c

    r608 r747  
    2121#include <malloc.h> 
    2222#include <error.h> 
     23#include <print.h> 
    2324 
    2425struct SuperBlockOps ext3SbOps={ 
    2526        .readVNode = Ext3ReadVNode, 
     27        .writeVNode = Ext3WriteVNode, 
     28        .dirtyVNode = Ext3DirtyVNode, 
    2629}; 
    2730 
     
    3437        .readDir = Ext3ReadDir, 
    3538        .read = FileGenericRead, 
     39        .write = Ext3FileWrite, 
    3640}; 
     41 
     42int Ext3JournalSetup(struct VfsSuperBlock* superBlock, struct Ext3SuperBlock* sb, DWORD iNo) 
     43{ 
     44        struct VNode* journal; 
     45 
     46        journal=VNodeGet(superBlock, iNo); 
     47 
     48        if (!journal) 
     49        { 
     50                KePrint("EXT3: no journal found\n"); 
     51                return 0; 
     52        } 
     53 
     54        /* The journal node must be used (i.e. linked to somewhere). Check! */ 
     55 
     56        KePrint("EXT3: Found journal at %#X: size = %#X\n", iNo, journal->size); 
     57 
     58        return 0; 
     59} 
     60 
     61int Ext3JournalInit(struct VfsSuperBlock* superBlock, struct Ext3SuperBlock* sb) 
     62{ 
     63        /* TODO: Recovery? */ 
     64 
     65        if (sb->journalINum) 
     66        { 
     67                Ext3JournalSetup(superBlock, sb, sb->journalINum); 
     68        }else 
     69                KePrint("Ext3JournalInit: get dev journal\n"); 
     70 
     71        return 0; 
     72} 
     73 
     74DWORD Ext3GetDescriptorLoc(struct VfsSuperBlock* superBlock, int i) 
     75{ 
     76        struct Ext3SbInfo* sb=EXT3_SUPERINFO(superBlock); 
     77        unsigned long block; 
     78 
     79        /* TODO: Figure out logic superblock sector. */ 
     80 
     81        return i+1; 
     82 
     83        /* Check features for meta block group */ 
     84#if 0 
     85        block=DESCS_PER_BLOCK(superBlock)*i; 
     86 
     87        return sb->firstDataBlock+(block*sb->blocksPerGrp); 
     88#endif 
     89} 
    3790 
    3891struct VfsSuperBlock* Ext3ReadSuper(struct StorageDevice* dev,int flags,char* data) 
     
    4093        struct VfsSuperBlock* retVal; 
    4194        struct Buffer* buff; 
    42         struct Ext3SuperBlock* sb; 
     95        struct Ext3SuperBlock sb; 
    4396        struct Ext3SbInfo* sbInfo; 
    4497        int descCount,i; 
     
    54107                goto error; 
    55108 
    56         sb=(struct Ext3SuperBlock*)buff->data; 
     109        /* The buffer will be freed if we set the block size to something other than 
     110         * 1024, so save the data off now. 
     111         */ 
     112 
     113        memcpy(&sb, buff->data, sizeof(struct Ext3SuperBlock)); 
    57114 
    58115        /* Sanity check. */ 
    59         if (sb->magic != EXT3_SB_MAGIC) 
     116        if (sb.magic != EXT3_SB_MAGIC) 
    60117                goto blockReadError; 
    61118 
     
    64121                goto blockReadError; 
    65122 
     123        /* Ext3 block sizes are a multiple of 1024. */ 
     124        BlockSetSize(dev,1024 << sb.logBlockSize); 
     125 
    66126        /* Copy some useful information over into the private superblock structure. */ 
    67127        sbInfo=(struct Ext3SbInfo*)malloc(sizeof(struct Ext3SbInfo)); 
     
    69129                goto superFreeError; 
    70130 
    71         sbInfo->iNodesCount=sb->iNodesCount; 
    72         sbInfo->groupCount=(sb->blocksCount-sb->firstDataBlock+sb->blocksPerGrp-1)/sb->blocksPerGrp; 
    73         sbInfo->iNodesPerGrp=sb->iNodesPerGrp; 
     131        sbInfo->iNodesCount=sb.iNodesCount; 
     132        sbInfo->blocksPerGrp=sb.blocksPerGrp; 
     133        sbInfo->groupCount=(sb.blocksCount-sb.firstDataBlock+sb.blocksPerGrp-1)/sb.blocksPerGrp; 
     134        sbInfo->iNodesPerGrp=sb.iNodesPerGrp; 
     135 
     136        sbInfo->firstDataBlock=sb.firstDataBlock; 
     137 
     138        /* And set the Ext3-specific parts of the superblock structure. */ 
     139        retVal->privData=sbInfo; 
     140        retVal->sbOps=&ext3SbOps; 
    74141 
    75142        /* Read in the block descriptors as pointers to buffers. */ 
     
    77144        sbInfo->descs=(struct Buffer**)malloc(descCount*sizeof(struct Buffer*)); 
    78145 
     146        if (!descCount) 
     147                goto superFreeError; 
     148 
    79149        for (i=0; i<descCount; i++) 
    80                 sbInfo->descs[i]=BlockRead(dev,2+i); 
     150                sbInfo->descs[i]=BlockRead(dev, Ext3GetDescriptorLoc(retVal, i)); 
    81151 
    82         /* And set the Ext3-specific parts of the superblock structure. */ 
    83         retVal->privData=sbInfo; 
    84         retVal->sbOps=&ext3SbOps; 
     152        /* If we have a journal, read it in. We read the journal in before the root 
     153         * node, because it may have been modified in the journal. */ 
    85154 
    86         /* For now */ 
    87         retVal->flags|=SB_RDONLY; 
    88  
    89         /* Ext3 block sizes are a multiple of 1024. */ 
    90         BlockSetSize(dev,1024 << sb->logBlockSize); 
     155        if (EXT3_FEATURE_COMPAT(&sb, EXT3_FEATURE_COMPAT_JOURNAL)) 
     156        { 
     157                Ext3JournalInit(retVal, &sb); 
     158        } 
    91159 
    92160        retVal->mount=VNodeGet(retVal, EXT3_ROOT_VNO); 
  • Whitix/branches/fs/fs/fat/fat.h

    r705 r747  
    193193/* Block mapping and reading functions */ 
    194194struct Buffer* FatBlockRead(struct VNode* vNode,int offset); 
    195 int FatBlockMap(struct VNode* vNode, DWORD offset); 
     195int FatBlockMap(struct VNode* vNode, DWORD offset, int flags); 
    196196 
    197197static inline void FatPosToSecOffset(struct VNode* vNode,int pos,int* sec,int* offset) 
    198198{ 
    199199        /* Is this the right way to do things? */ 
    200         *sec=FatBlockMap(vNode,FAT_DIR_POS(pos)/BYTES_PER_SECTOR(vNode->superBlock)); 
     200        *sec=FatBlockMap(vNode,FAT_DIR_POS(pos)/BYTES_PER_SECTOR(vNode->superBlock), 0); 
    201201        *offset=pos % (BYTES_PER_SECTOR(vNode->superBlock)/sizeof(struct FatDirEntry)); 
    202202} 
  • Whitix/branches/fs/fs/fat/file.c

    r705 r747  
    4242        int sector; 
    4343 
    44         sector=FatBlockMap(vNode,offset); 
     44        sector=FatBlockMap(vNode,offset, 0); 
    4545        if (sector == -1) /* Couldn't map the sector */ 
    4646                return NULL; 
     
    6363 ***********************************************************************/ 
    6464 
    65 int FatBlockMap(struct VNode* vNode, DWORD offset) 
     65int FatBlockMap(struct VNode* vNode, DWORD offset, int flags) 
    6666{ 
    6767        struct FatSbInfo* fatSbInfo=FatGetSbPriv(vNode->superBlock); 
     
    102102                                return -1; 
    103103 
     104                        /* FIXME: Check for flags! */ 
    104105                        /* Add a new cluster if the block requested is one more than needed. */ 
    105106                        while (offset--) 
  • Whitix/branches/fs/fs/fat/vnode.c

    r705 r747  
    480480        entry->attribute=attr; 
    481481 
    482         *vNum=SS_TO_VNUM(FatBlockMap(dir,sector),sOffset/sizeof(struct FatDirEntry)); 
     482        *vNum=SS_TO_VNUM(FatBlockMap(dir,sector, 0),sOffset/sizeof(struct FatDirEntry)); 
    483483 
    484484        BlockWrite(dir->superBlock->sDevice,buffer); 
  • Whitix/branches/fs/fs/isofs/dir.c

    r704 r747  
    2626#include "isofs.h" 
    2727 
    28 int IsoBlockMap(struct VNode* vNode, DWORD block) 
     28int IsoBlockMap(struct VNode* vNode, DWORD block, int flags) 
    2929{ 
    3030        /* Block mapping in ISO filesystems is fairly simple, as the blocks 
     
    3434        struct IsoSbPriv* sbPriv=IsoGetSbPriv(vNode->superBlock); 
    3535 
     36        if (flags & VFS_MAP_CREATE) 
     37                return -ENOENT; 
     38 
    3639        /* Is the block to be mapped past the end of the file? */ 
    3740        if ((block*sbPriv->sectorSize) > vNode->size) 
     
    4346struct Buffer* IsoBlockRead(struct VNode* vNode,int block) 
    4447{ 
    45         int sector=IsoBlockMap(vNode,block); 
     48        int sector=IsoBlockMap(vNode, block, 0); 
    4649 
    4750        if (sector == -1) 
     
    242245                if (nameLength == aNameLen && !strnicmp(name,dirEntry->name,aNameLen)) 
    243246                { 
    244                         *retVal=VNodeGet(dir->superBlock, ISO_TO_VNUM(IsoBlockMap(dir,sector), offset)); 
     247                        *retVal=VNodeGet(dir->superBlock, ISO_TO_VNUM(IsoBlockMap(dir,sector, 0), offset)); 
    245248                        err=0; 
    246249                        goto out; 
     
    320323                len=IsoParseFileName(name,dirEntry->name,dirEntry->nameLen); 
    321324 
    322                 if (FillDir(dirEntries,name,len,ISO_TO_VNUM(IsoBlockMap(file->vNode,sector), offset-dirEntry->entryLength))) 
     325                if (FillDir(dirEntries,name,len,ISO_TO_VNUM(IsoBlockMap(file->vNode,sector, 0), offset-dirEntry->entryLength))) 
    323326                        break; 
    324327        }