//allocates a free block number int balloc(int dev) { int i; char buf[BLKSIZE]; //read block_map block get_block(dev, bmap, buf); for(i = 0; i < nblocks; i++) { if(tst_bit(buf, i) == 0) { set_bit(buf, i); decFreeInodes(dev); put_block(dev, bmap, buf); return i + 1; } } printf("ERROR: no more free blocks\n"); return 0; }
int ialloc(int fd) { fputs("ialloc: ##################################################", stdout); char buf[BLOCK_SIZE]; _get_block(fd, 1, buf); Super * super = (Super *) buf; int ninodes = (int) super->s_inodes_count; printf("ninodes = %d\n", ninodes); _get_block(fd, 2, buf); GroupDesc * gp = (GroupDesc *) buf; int imap = (int) gp->bg_inode_bitmap; printf("imap = %d\n", imap); // read inode_bitmap block _get_block(fd, imap, buf); for (int i = 0; i < ninodes; i++) { if (tst_bit(buf, i) == 0) { set_bit(buf, i); decFreeInodes(fd); put_block(fd, imap, buf); return i + 1; } } printf("ialloc(): no more free inodes\n"); return 0; }