From: Ben Gras Date: Wed, 7 Nov 2012 16:41:52 +0000 (+0100) Subject: mkfs: separate inode retrieval function X-Git-Tag: v3.2.1~242 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/Bv9ARM.ch10.html?a=commitdiff_plain;h=ca2255201be4a53808e710eff0fa6d21b4bbec2a;p=minix.git mkfs: separate inode retrieval function --- diff --git a/usr.sbin/mkfs.mfs/mkfs.c b/usr.sbin/mkfs.mfs/mkfs.c index b06f273ed..ecbb56f35 100644 --- a/usr.sbin/mkfs.mfs/mkfs.c +++ b/usr.sbin/mkfs.mfs/mkfs.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,7 @@ #if defined(__minix) #include #include +#include #include #endif #include @@ -132,7 +134,7 @@ void mx_read(int blocknr, char *buf); void mx_write(int blocknr, char *buf); void dexit(char *s, int sectnum, int err); void usage(void); -char *alloc_block(void); +void *alloc_block(void); ino_t inocount; zone_t zonecount; @@ -278,13 +280,9 @@ char *argv[]; grpid = atoi(token[2]); if(blocks <= 0 && inodes <= 0){ - block_t extrablocks = 0; - ino_t extrainodes = 0; - if(blocks < 0) extrablocks = -blocks; - if(inodes < 0) extrainodes = -inodes; detect_fs_size(); - blocks = blockcount + extrablocks; - inodes = inocount + extrainodes; + blocks = blockcount; + inodes = inocount; blocks += blocks*extra_space_percent/100; inodes += inodes*extra_space_percent/100; printf("dynamically sized filesystem: %d blocks, %d inodes\n", blocks, @@ -766,6 +764,17 @@ int f; free(buf); } +d2_inode *get_inoblock(ino_t i, block_t *blockno, d2_inode **ino) +{ + int off; + d2_inode *inoblock = alloc_block(); + *blockno = ((i - 1) / inodes_per_block) + inode_offset; + off = (i - 1) % inodes_per_block; + get_block(*blockno, (char *) inoblock); + *ino = inoblock + off; + return inoblock; +} + /*================================================================ * directory & inode management assist group *===============================================================*/ @@ -775,30 +784,23 @@ char *name; { /* Enter child in parent directory */ /* Works for dir > 1 block and zone > block */ - unsigned int i, j, k, l, off; + unsigned int i, j, k, l; block_t b; zone_t z; char *p1, *p2; - struct direct *dir_entry; - d2_inode *ino2; + struct direct *dir_entry = alloc_block(); + d2_inode *ino; + d2_inode *inoblock = get_inoblock(parent, &b, &ino); int nr_dzones; - b = ((parent - 1) / inodes_per_block) + inode_offset; - off = (parent - 1) % inodes_per_block; - - if(!(dir_entry = malloc(NR_DIR_ENTRIES(block_size) * sizeof(*dir_entry)))) - pexit("couldn't allocate directory entry"); - - if(!(ino2 = malloc(V2_INODES_PER_BLOCK(block_size) * sizeof(*ino2)))) - pexit("couldn't allocate block of inodes entry"); + assert(!(block_size % sizeof(struct direct))); - get_block(b, (char *) ino2); nr_dzones = V2_NR_DZONES; for (k = 0; k < nr_dzones; k++) { - z = ino2[off].d2_zone[k]; + z = ino->d2_zone[k]; if (z == 0) { z = alloc_zone(); - ino2[off].d2_zone[k] = z; + ino->d2_zone[k] = z; } for (l = 0; l < zone_size; l++) { @@ -815,9 +817,9 @@ char *name; if (*p1 != 0) p1++; } put_block((z << zone_shift) + l, (char *) dir_entry); - put_block(b, (char *) ino2); + put_block(b, (char *) inoblock); free(dir_entry); - free(ino2); + free(inoblock); return; } } @@ -1277,7 +1279,7 @@ size_t count; while (count--) *to++ = *from++; } -char *alloc_block() +void *alloc_block() { char *buf;