From: Ben Gras Date: Wed, 7 Nov 2012 17:59:03 +0000 (+0100) Subject: mkfs: support indirect blocks in directories X-Git-Tag: v3.2.1~238 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/man.arpaname.html?a=commitdiff_plain;h=77b6e2dcaacf83e8a405162ca6dfe6f521127486;p=minix.git mkfs: support indirect blocks in directories --- diff --git a/usr.sbin/mkfs.mfs/mkfs.c b/usr.sbin/mkfs.mfs/mkfs.c index 1d8419f54..d8c220338 100644 --- a/usr.sbin/mkfs.mfs/mkfs.c +++ b/usr.sbin/mkfs.mfs/mkfs.c @@ -421,7 +421,8 @@ void sizeup_dir() dir_zones = (dir_entries / (NR_DIR_ENTRIES(block_size))); if(dir_entries % (NR_DIR_ENTRIES(block_size))) dir_zones++; - /* Assumes directory fits in direct blocks */ + if(dir_zones > nr_dzones) + dir_zones++; /* Max single indir */ zonecount += dir_zones; return; } @@ -796,6 +797,7 @@ char *name; unsigned int k; block_t b; zone_t z; + zone_t *indirblock = alloc_block(); d2_inode *ino; d2_inode *inoblock = get_inoblock(parent, &b, &ino); @@ -811,6 +813,26 @@ char *name; if(dir_try_enter(z, child, name)) { put_block(b, (char *) inoblock); free(inoblock); + free(indirblock); + return; + } + } + + /* no space in directory using just direct blocks; try indirect */ + if (ino->d2_zone[V2_NR_DZONES] == 0) + ino->d2_zone[V2_NR_DZONES] = alloc_zone(); + + get_block(ino->d2_zone[V2_NR_DZONES], (char *) indirblock); + + for(k = 0; k < V2_INDIRECTS(block_size); k++) { + z = indirblock[k]; + if(!z) z = indirblock[k] = alloc_zone(); + + if(dir_try_enter(z, child, name)) { + put_block(b, (char *) inoblock); + put_block(ino->d2_zone[V2_NR_DZONES], (char *) indirblock); + free(inoblock); + free(indirblock); return; } }