changeset 304:c5c4f9e233ad

fix and build success
author menikon
date Fri, 31 Jan 2020 16:36:15 +0900
parents 5217253368ad
children a101eb88b1cd
files src/impl/fs_impl.h src/impl/fs_impl_private.cbc
diffstat 2 files changed, 55 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/impl/fs_impl.h	Fri Jan 31 16:17:06 2020 +0900
+++ b/src/impl/fs_impl.h	Fri Jan 31 16:36:15 2020 +0900
@@ -6,10 +6,11 @@
     struct buf* bp;
     struct dinode* dip;
     int inum;
+    int iget_val;
 
-    __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 allocinode(struct fs_impl* fs_impl, uint dev, short type, __code next(int iget_val, ...));
+    __code allocinode_loop(struct fs_impl* fs_impl, int inum, uint dev, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(int iget_val, ...));
+    __code allocinode_loopcheck(Type* fs_impl, int inum, uint dev, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(int iget_val, ...));
+    __code allocinode_noloop(struct fs_impl* fs_impl, int inum, uint dev, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(int iget_val, ...));
     __code next(...);
 } fs_impl;
--- a/src/impl/fs_impl_private.cbc	Fri Jan 31 16:17:06 2020 +0900
+++ b/src/impl/fs_impl_private.cbc	Fri Jan 31 16:36:15 2020 +0900
@@ -14,46 +14,87 @@
 fs_impl* createfs_impl2();
 */
 
-__code allocinode(struct fs_impl* fs_impl, uint dev, struct superblock* sb, __code next(...)){ //:skip
+__code allocinode(struct fs_impl* fs_impl, uint dev, struct superblock* sb, __code next(int iget_val, ...)){ //:skip
 
     readsb(dev, sb);
     Gearef(cbc_context, fs_impl)->inum = 1; 
-    goto allocinode_loopcheck(fs_impl, inum, dev, sb, bp, dip, next(...));
+    goto allocinode_loopcheck(fs_impl, inum, dev, sb, bp, dip, next(iget_val, ...));
 
 }
 
 typedef struct buf buf;
 typedef struct dinode dinode;
 
-__code allocinode_loopcheck(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(int iget_val, ...)){ //:skip
     if( inum < sb->ninodes){
-        goto allocinode_loop(fs_impl, inum, dev, type, sb, bp, dip, next(...));
+        goto allocinode_loop(fs_impl, inum, dev, type, sb, bp, dip, next(iget_val, ...));
     }
 /*
     goto cbc_context->panic(...);
 */
 }
 
-__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
+__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(int iget_val, ...)){ //: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(...));
+        goto allocinode_noloop(fs_impl, inum, dev, sb, bp, dip, next(iget_val, ...));
     }
     
     brelse(bp);    
     inum++;
-    goto allocinode_loopcheck(fs_impl, inum, dev, type, sb, bp, dip, next(...));
+    goto allocinode_loopcheck(fs_impl, inum, dev, type, sb, bp, dip, next(iget_val, ...));
 }
 
-__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
+struct {
+    struct spinlock lock;
+    struct inode inode[NINODE];
+} icache;
+
+static struct inode* iget (uint dev, uint inum)
+{
+    struct inode *ip, *empty;
+
+    acquire(&icache.lock);
+
+    // Is the inode already cached?
+    empty = 0;
+
+    for (ip = &icache.inode[0]; ip < &icache.inode[NINODE]; ip++) {
+        if (ip->ref > 0 && ip->dev == dev && ip->inum == inum) {
+            ip->ref++;
+            release(&icache.lock);
+            return ip;
+        }
+
+        if (empty == 0 && ip->ref == 0) {   // Remember empty slot.
+            empty = ip;
+        }
+    }
+
+    // Recycle an inode cache entry.
+    if (empty == 0) {
+        panic("iget: no inodes");
+    }
+
+    ip = empty;
+    ip->dev = dev;
+    ip->inum = inum;
+    ip->ref = 1;
+    ip->flags = 0;
+    release(&icache.lock);
+
+    return ip;
+}
+
+__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(int iget_val, ...)){ //:skip
 
     memset(dip, 0, sizeof(*dip));
     dip->type = type;
     log_write(bp);   
     brelse(bp);
     
-    int iget_val = iget(dev, inum);
+    iget_val = iget(dev, inum);
     goto next(iget_val, ...);
 
 }