Changeset 747
- Timestamp:
- 07/07/08 20:09:17 (5 months ago)
- Location:
- Whitix/branches/fs/fs
- Files:
-
- 2 added
- 10 modified
-
Makefile (modified) (3 diffs)
-
ext3/Makefile (modified) (1 diff)
-
ext3/ext3.h (modified) (6 diffs)
-
ext3/file.c (modified) (1 diff)
-
ext3/inode.c (modified) (7 diffs)
-
ext3/super.c (modified) (7 diffs)
-
fat/fat.h (modified) (1 diff)
-
fat/file.c (modified) (3 diffs)
-
fat/vnode.c (modified) (1 diff)
-
isofs/dir.c (modified) (5 diffs)
-
journal (added)
-
journal/.deps (added)
Legend:
- Unmodified
- Added
- Removed
-
Whitix/branches/fs/fs/Makefile
r702 r747 6 6 $(MAKE) -C devfs 7 7 $(MAKE) -C reiserfs 8 $(MAKE) -C journal 8 9 9 10 modules_install: … … 11 12 $(MAKE) -C vfs modules_install 12 13 $(MAKE) -C devfs modules_install 14 $(MAKE) -C ext3 modules_install 13 15 $(MAKE) -C reiserfs modules_install 16 $(MAKE) -C journal modules_install 14 17 15 18 clean: … … 20 23 $(MAKE) -C devfs clean 21 24 $(MAKE) -C reiserfs clean 25 $(MAKE) -C journal clean -
Whitix/branches/fs/fs/ext3/Makefile
r703 r747 1 1 DEPTH=../../ 2 MODULES = super.sys inode.sys 2 MODULES = super.sys inode.sys file.sys 3 3 4 4 build: $(MODULES) 5 5 ld $(LD_R_FLAGS) $(MODULES) -o ext3.sys 6 6 7 modules_install: 8 cp ext3.sys ../../CdRoot/System/Modules/Core 9 7 10 include $(DEPTH)make.inc 8 11 -include $(DEPS) -
Whitix/branches/fs/fs/ext3/ext3.h
r608 r747 23 23 #include <init.h> 24 24 25 /* EXT3 features */ 26 #define EXT3_FEATURE_COMPAT_JOURNAL 0x4 27 28 #define EXT3_FEATURE_COMPAT(sb, feature) ((sb)->featureCompat & (feature)) 29 25 30 struct Ext3SuperBlock 26 31 { 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. Thus32 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 34 39 0 == 1024 , 1 = 2048 , 2 = 4096*/ 35 DWORD logFragSize; /* Fragments are not yet implemented int ext3. So40 DWORD logFragSize; /* Fragments are not yet implemented int ext3. So 36 41 logFragSize .equal. logBlockSize */ 37 DWORD blocksPerGrp; /* Number of Blocks in each block group */42 DWORD blocksPerGrp; /* Number of Blocks in each block group */ 38 43 DWORD fragsPerGrp; /* Number of Fragments in each block group */ 39 44 DWORD iNodesPerGrp; /* Number of Inodes in each block group */ … … 87 92 { 88 93 DWORD iNodesCount,groupCount,iNodesPerGrp; 94 DWORD firstDataBlock, blocksPerGrp; 89 95 struct Buffer** descs; 90 96 }; … … 98 104 99 105 /* 100 * Each block group has its own group d iscriptor106 * Each block group has its own group descriptor 101 107 */ 102 108 struct Ext3GroupDesc … … 144 150 { 145 151 DWORD iNodeNum; // Inode number 146 WORD recLen; // Directo y entry length152 WORD recLen; // Directory entry length 147 153 BYTE nameLen;// filename length 148 154 BYTE fileType; // file type … … 152 158 /* Common functions */ 153 159 int Ext3ReadVNode(struct VNode* vNode); 160 int Ext3WriteVNode(struct VNode* vNode); 161 int Ext3DirtyVNode(struct VNode* vNode); 154 162 int Ext3Lookup(struct VNode** retVal,struct VNode* dir,char* name,int nameLength); 155 163 int Ext3ReadDir(struct File* file,void* dirEntries); 156 int Ext3BlockMap(struct VNode* vNode, int block);164 int Ext3BlockMap(struct VNode* vNode, DWORD block, int flags); 157 165 struct Buffer* Ext3BlockRead(struct VNode* vNode,int block); 158 int Ext3Read(struct File* file,BYTE* buffer,DWORD len); 166 167 int Ext3FileWrite(struct File* file,BYTE* buffer,DWORD len); 159 168 160 169 extern struct VNodeOps ext3VNodeOps; … … 167 176 #define DESCS_PER_BLOCK(s) (BYTES_PER_SECTOR(s)/sizeof(struct Ext3GroupDesc)) 168 177 #define INODES_PER_BLOCK(s) (BYTES_PER_SECTOR(s)/sizeof(struct Ext3INode)) 178 #define EXT3_SUPERINFO(s) ((struct Ext3SbInfo*)((s)->privData)) 169 179 170 180 #define EXT3_SB_MAGIC 0xEF53 -
Whitix/branches/fs/fs/ext3/file.c
r1 r747 1 #include "ext3.h" 2 3 #include <print.h> 4 5 int 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 26 26 /* Get the group descriptor for the inode */ 27 27 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 29 30 groupDescs=(struct Ext3GroupDesc*)(sbInfo->descs[groupDesc]->data); 31 32 if (!groupDescs) 33 return -EFAULT; 30 34 31 35 block=groupDescs[desc].iNodeTable+((vNo % sbInfo->iNodesPerGrp)/INODES_PER_BLOCK(vNode->superBlock)); … … 39 43 40 44 iNodeInfo=(struct Ext3INodeInfo*)malloc(sizeof(struct Ext3INodeInfo)); 41 vNode->extraInfo=iNodeInfo; 45 42 46 if (!iNodeInfo) 43 47 { … … 58 62 vNode->fileOps=&ext3FileOps; 59 63 vNode->mode=VFS_ATTR_WRITE | VFS_ATTR_READ; 64 vNode->extraInfo=iNodeInfo; 65 60 66 if ((iNode->mode & 0xF000) == 0x4000) 61 67 vNode->mode|=VFS_ATTR_DIR; … … 66 72 67 73 BlockFree(buffer); 74 return 0; 75 } 76 77 int Ext3WriteVNode(struct VNode* vNode) 78 { 79 KePrint("Ext3WriteVNode\n"); 80 return 0; 81 } 82 83 int Ext3DirtyVNode(struct VNode* vNode) 84 { 85 KePrint("Ext3DirtyVNode\n"); 86 cli(); hlt(); 68 87 return 0; 69 88 } … … 106 125 } 107 126 108 int Ext3BlockMap(struct VNode* vNode, int block)127 int Ext3BlockMap(struct VNode* vNode, DWORD block, int flags) 109 128 { 110 129 struct Ext3INodeInfo* iNodeInfo=(struct Ext3INodeInfo*)vNode->extraInfo; … … 115 134 if (!iNodeInfo->blocks[block]) 116 135 { 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); 118 140 cli(); hlt(); 119 141 } … … 158 180 struct Buffer* Ext3BlockRead(struct VNode* vNode,int block) 159 181 { 160 int realBlock=Ext3BlockMap(vNode,block );161 if (realBlock == -1)182 int realBlock=Ext3BlockMap(vNode,block, 0); 183 if (realBlock < 0) 162 184 return NULL; 163 185 -
Whitix/branches/fs/fs/ext3/super.c
r608 r747 21 21 #include <malloc.h> 22 22 #include <error.h> 23 #include <print.h> 23 24 24 25 struct SuperBlockOps ext3SbOps={ 25 26 .readVNode = Ext3ReadVNode, 27 .writeVNode = Ext3WriteVNode, 28 .dirtyVNode = Ext3DirtyVNode, 26 29 }; 27 30 … … 34 37 .readDir = Ext3ReadDir, 35 38 .read = FileGenericRead, 39 .write = Ext3FileWrite, 36 40 }; 41 42 int 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 61 int 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 74 DWORD 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 } 37 90 38 91 struct VfsSuperBlock* Ext3ReadSuper(struct StorageDevice* dev,int flags,char* data) … … 40 93 struct VfsSuperBlock* retVal; 41 94 struct Buffer* buff; 42 struct Ext3SuperBlock *sb;95 struct Ext3SuperBlock sb; 43 96 struct Ext3SbInfo* sbInfo; 44 97 int descCount,i; … … 54 107 goto error; 55 108 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)); 57 114 58 115 /* Sanity check. */ 59 if (sb ->magic != EXT3_SB_MAGIC)116 if (sb.magic != EXT3_SB_MAGIC) 60 117 goto blockReadError; 61 118 … … 64 121 goto blockReadError; 65 122 123 /* Ext3 block sizes are a multiple of 1024. */ 124 BlockSetSize(dev,1024 << sb.logBlockSize); 125 66 126 /* Copy some useful information over into the private superblock structure. */ 67 127 sbInfo=(struct Ext3SbInfo*)malloc(sizeof(struct Ext3SbInfo)); … … 69 129 goto superFreeError; 70 130 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; 74 141 75 142 /* Read in the block descriptors as pointers to buffers. */ … … 77 144 sbInfo->descs=(struct Buffer**)malloc(descCount*sizeof(struct Buffer*)); 78 145 146 if (!descCount) 147 goto superFreeError; 148 79 149 for (i=0; i<descCount; i++) 80 sbInfo->descs[i]=BlockRead(dev, 2+i);150 sbInfo->descs[i]=BlockRead(dev, Ext3GetDescriptorLoc(retVal, i)); 81 151 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. */ 85 154 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 } 91 159 92 160 retVal->mount=VNodeGet(retVal, EXT3_ROOT_VNO); -
Whitix/branches/fs/fs/fat/fat.h
r705 r747 193 193 /* Block mapping and reading functions */ 194 194 struct Buffer* FatBlockRead(struct VNode* vNode,int offset); 195 int FatBlockMap(struct VNode* vNode, DWORD offset );195 int FatBlockMap(struct VNode* vNode, DWORD offset, int flags); 196 196 197 197 static inline void FatPosToSecOffset(struct VNode* vNode,int pos,int* sec,int* offset) 198 198 { 199 199 /* 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); 201 201 *offset=pos % (BYTES_PER_SECTOR(vNode->superBlock)/sizeof(struct FatDirEntry)); 202 202 } -
Whitix/branches/fs/fs/fat/file.c
r705 r747 42 42 int sector; 43 43 44 sector=FatBlockMap(vNode,offset );44 sector=FatBlockMap(vNode,offset, 0); 45 45 if (sector == -1) /* Couldn't map the sector */ 46 46 return NULL; … … 63 63 ***********************************************************************/ 64 64 65 int FatBlockMap(struct VNode* vNode, DWORD offset )65 int FatBlockMap(struct VNode* vNode, DWORD offset, int flags) 66 66 { 67 67 struct FatSbInfo* fatSbInfo=FatGetSbPriv(vNode->superBlock); … … 102 102 return -1; 103 103 104 /* FIXME: Check for flags! */ 104 105 /* Add a new cluster if the block requested is one more than needed. */ 105 106 while (offset--) -
Whitix/branches/fs/fs/fat/vnode.c
r705 r747 480 480 entry->attribute=attr; 481 481 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)); 483 483 484 484 BlockWrite(dir->superBlock->sDevice,buffer); -
Whitix/branches/fs/fs/isofs/dir.c
r704 r747 26 26 #include "isofs.h" 27 27 28 int IsoBlockMap(struct VNode* vNode, DWORD block )28 int IsoBlockMap(struct VNode* vNode, DWORD block, int flags) 29 29 { 30 30 /* Block mapping in ISO filesystems is fairly simple, as the blocks … … 34 34 struct IsoSbPriv* sbPriv=IsoGetSbPriv(vNode->superBlock); 35 35 36 if (flags & VFS_MAP_CREATE) 37 return -ENOENT; 38 36 39 /* Is the block to be mapped past the end of the file? */ 37 40 if ((block*sbPriv->sectorSize) > vNode->size) … … 43 46 struct Buffer* IsoBlockRead(struct VNode* vNode,int block) 44 47 { 45 int sector=IsoBlockMap(vNode, block);48 int sector=IsoBlockMap(vNode, block, 0); 46 49 47 50 if (sector == -1) … … 242 245 if (nameLength == aNameLen && !strnicmp(name,dirEntry->name,aNameLen)) 243 246 { 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)); 245 248 err=0; 246 249 goto out; … … 320 323 len=IsoParseFileName(name,dirEntry->name,dirEntry->nameLen); 321 324 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))) 323 326 break; 324 327 }