changeset 303:5217253368ad

rewrite ialloc
author menikon
date Fri, 31 Jan 2020 16:17:06 +0900
parents bc2f3d24faa9
children c5c4f9e233ad
files src/impl/fs_impl.cbc src/impl/fs_impl.h src/impl/fs_impl_private.cbc
diffstat 3 files changed, 40 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/impl/fs_impl.cbc	Thu Jan 30 17:14:45 2020 +0900
+++ b/src/impl/fs_impl.cbc	Fri Jan 31 16:17:06 2020 +0900
@@ -30,6 +30,8 @@
     fs->ialloc = C_iallocfs_impl;
     fs_impl->allocinode = C_allocinode;
     fs_impl->allocinode_loop = C_allocinode_loop;
+    fs_impl->allocinode_loopcheck = C_allocinode_loopcheck;
+    fs_impl->allocinode_noloop = C_allocinode_noloop;
     fs->iupdate = C_iupdatefs_impl;
     fs->idup = C_idupfs_impl;
     fs->ilock = C_ilockfs_impl;
--- a/src/impl/fs_impl.h	Thu Jan 30 17:14:45 2020 +0900
+++ b/src/impl/fs_impl.h	Fri Jan 31 16:17:06 2020 +0900
@@ -7,7 +7,9 @@
     struct dinode* dip;
     int inum;
 
-    __code allocinode(Type* fs_impl, uint dev, short type, __code next(...));
-    __code allocinode_loop(Type* fs_impl, int inum, uint dev, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(...));
+    __code allocinode(struct fs_impl* fs_impl, uint dev, short type, __code next(...));
+    __code allocinode_loop(struct fs_impl* fs_impl, int inum, uint dev, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(...));
+    __code allocinode_loopcheck(Type* fs_impl, int inum, uint dev, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(...));
+    __code allocinode_noloop(struct fs_impl* fs_impl, int inum, uint dev, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(...));
     __code next(...);
 } fs_impl;
--- a/src/impl/fs_impl_private.cbc	Thu Jan 30 17:14:45 2020 +0900
+++ b/src/impl/fs_impl_private.cbc	Fri Jan 31 16:17:06 2020 +0900
@@ -17,15 +17,45 @@
 __code allocinode(struct fs_impl* fs_impl, uint dev, struct superblock* sb, __code next(...)){ //:skip
 
     readsb(dev, sb);
-
-    goto allocinode_loop(fs_impl, inum, dev, sb, bp, dip, next(...));
+    Gearef(cbc_context, fs_impl)->inum = 1; 
+    goto allocinode_loopcheck(fs_impl, inum, dev, sb, bp, dip, next(...));
 
 }
 
 typedef struct buf buf;
 typedef struct dinode dinode;
-__code allocinode_loop(struct fs_impl* fs_impl, int inum, uint dev, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(...)){ //:skip
+
+__code allocinode_loopcheck(struct fs_impl* fs_impl, int inum, uint dev, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(...)){ //:skip
+    if( inum < sb->ninodes){
+        goto allocinode_loop(fs_impl, inum, dev, type, sb, bp, dip, next(...));
+    }
+/*
+    goto cbc_context->panic(...);
+*/
+}
 
-    goto next(...);
+__code allocinode_loop(struct fs_impl* fs_impl, int inum, uint dev, short type, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(...)){ //:skip
+    bp = bread(dev, IBLOCK(inum));
+    dip = (struct dinode*) bp->data + inum % IPB;
+    if(dip->type = 0){
+        goto allocinode_noloop(fs_impl, inum, dev, sb, bp, dip, next(...));
+    }
+    
+    brelse(bp);    
+    inum++;
+    goto allocinode_loopcheck(fs_impl, inum, dev, type, sb, bp, dip, next(...));
+}
+
+__code allocinode_noloop(struct fs_impl* fs_impl, int inum, uint dev, short type, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(...)){ //:skip
+
+    memset(dip, 0, sizeof(*dip));
+    dip->type = type;
+    log_write(bp);   
+    brelse(bp);
+    
+    int iget_val = iget(dev, inum);
+    goto next(iget_val, ...);
 
 }
+
+