From: Robert Pengelly Date: Tue, 29 Oct 2024 03:46:41 +0000 (+0000) Subject: Bug fixes X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;ds=sidebyside;p=minixfstools.git Bug fixes --- diff --git a/common.c b/common.c index 515dde5..48b1ee1 100644 --- a/common.c +++ b/common.c @@ -57,14 +57,15 @@ extern int alloc_zone (FILE *fp); void add_zone (FILE *fp, int n, int z, unsigned long bytes, unsigned long curr_time) { struct inode *p, inode[INODES_PER_BLOCK]; + unsigned char blk[NR_INDIRECTS * 2]; - unsigned long b, off, blk[NR_INDIRECTS], indir, i; + unsigned long block, off, i; unsigned long i_size, zone; - b = ((n - 1) / INODES_PER_BLOCK) + inode_offset; + block = ((n - 1) / INODES_PER_BLOCK) + inode_offset; memset (inode, 0, sizeof (inode)); - get_block (fp, b, inode); + get_block (fp, block, inode); off = (n - 1) % INODES_PER_BLOCK; @@ -76,7 +77,7 @@ void add_zone (FILE *fp, int n, int z, unsigned long bytes, unsigned long curr_t write_to_byte_array (p->i_size, i_size, 4); write_to_byte_array (p->i_mod_time, curr_time, 4); - for (i = 0; i < NR_DZONE_NUM * 2; i += 2) { + for (i = 0; i < NR_DZONES * 2; i += 2) { zone = ((unsigned long) p->i_zone[i]) | (((unsigned long) p->i_zone[i + 1]) << 8); @@ -84,38 +85,37 @@ void add_zone (FILE *fp, int n, int z, unsigned long bytes, unsigned long curr_t write_to_byte_array (p->i_zone + i, z, 2); - put_block (fp, b, inode); + put_block (fp, block, inode); return; } } - put_block (fp, b, inode); - zone = ((unsigned long) p->i_zone[NR_DZONE_NUM * 2]) | (((unsigned long) p->i_zone[(NR_DZONE_NUM * 2) + 1]) << 8); + zone = ((unsigned long) p->i_zone[i]) | (((unsigned long) p->i_zone[i + 1]) << 8); if (!zone) { zone = alloc_zone (fp); - write_to_byte_array (p->i_zone + (NR_DZONE_NUM * 2), zone, 2); + write_to_byte_array (p->i_zone + i, zone, 2); } - indir = zone; - put_block (fp, b, inode); - - b = indir << zone_shift; + put_block (fp, block, inode); + block = (zone << zone_shift); memset (blk, 0, sizeof (blk)); - get_block (fp, b, blk); + get_block (fp, block, blk); - for (i = 0; i < NR_INDIRECTS; i++) { + for (i = 0; i < NR_INDIRECTS * 2; i += 2) { - if (!blk[i]) { + zone = ((unsigned long) blk[i]) | (((unsigned long) blk[i + 1]) << 8); + + if (!zone) { - blk[i] = z; + write_to_byte_array (blk + i, z, 2); - put_block (fp, b, blk); + put_block (fp, block, blk); return; } @@ -144,7 +144,7 @@ void enter_dir (FILE *fp, int parent, char *name, int child) { off = (parent - 1) % INODES_PER_BLOCK; - for (k = 0; k < NR_DZONE_NUM * 2; k += 2) { + for (k = 0; k < NR_DZONES * 2; k += 2) { struct inode inode = ino[off]; zone = ((unsigned long) inode.i_zone[k]) | (((unsigned long) inode.i_zone[k + 1]) << 8); diff --git a/common.h b/common.h index f22c23e..a5d4c62 100644 --- a/common.h +++ b/common.h @@ -26,9 +26,7 @@ void write_to_byte_array (unsigned char *arr, unsigned long value, int size); #define N_BLOCKS16 (128L * 1024L) #define MAX_INIT (sizeof (char *) == 2 ? N_BLOCKS16 : N_BLOCKS) - #define NR_INDIRECTS (BLOCK_SIZE / sizeof (unsigned short)) -#define NR_DZONE_NUM (NR_ZONE_NUMS - 2) extern char buffer[BLOCK_SIZE]; diff --git a/inode.h b/inode.h index 6caf1aa..4ec5c79 100644 --- a/inode.h +++ b/inode.h @@ -4,7 +4,8 @@ #ifndef _INODE_H #define _INODE_H -#define NR_ZONE_NUMS 9 +#define NR_DZONES 7 +#define NR_TZONES 9 struct inode { @@ -17,7 +18,7 @@ struct inode { unsigned char gid; unsigned char i_nlinks; - unsigned char i_zone[2 * NR_ZONE_NUMS]; + unsigned char i_zone[NR_TZONES * 2]; }; diff --git a/mcopy.c b/mcopy.c index 8e4b29a..2b956b5 100644 --- a/mcopy.c +++ b/mcopy.c @@ -284,16 +284,16 @@ static unsigned long first_inode = 1; static int alloc_inode (FILE *fp, int mode, int userid, int groupid) { struct inode inode[INODES_PER_BLOCK]; - unsigned long ino, b, off; + unsigned long ino, block, off; for (ino = first_inode; ino < ninodes; ino++) { if (!get_bit (fp, INODE_MAP, ino)) { - b = ((ino - 1) / INODES_PER_BLOCK) + inode_offset; + block = ((ino - 1) / INODES_PER_BLOCK) + inode_offset; memset (inode, 0, sizeof (inode)); - get_block (fp, b, inode); + get_block (fp, block, inode); off = (ino - 1) % INODES_PER_BLOCK; @@ -301,7 +301,7 @@ static int alloc_inode (FILE *fp, int mode, int userid, int groupid) { write_to_byte_array (inode[off].uid, userid, 2); inode[off].gid = groupid; - put_block (fp, b, inode); + put_block (fp, block, inode); insert_bit (fp, INODE_MAP, ino); return ino; @@ -354,7 +354,7 @@ static int find_entry (int ino, char *name) { struct inode inode[INODES_PER_BLOCK], *p; struct dirent de[NR_DIR_ENTRIES]; - unsigned long b, off, i, j, zone; + unsigned long off, zone, b, i, j, k; unsigned long mode; b = ((ino - 1) / INODES_PER_BLOCK) + inode_offset; @@ -370,21 +370,27 @@ static int find_entry (int ino, char *name) { return 0; } - for (i = 0; i < NR_DZONE_NUM * 2; i += 2) { + for (i = 0; i < NR_DZONES * 2; i += 2) { zone = ((unsigned long) p->i_zone[i]) | (((unsigned long) p->i_zone[1]) << 8); + zone <<= zone_shift; if (!zone) { continue; } memset (de, 0, sizeof (de)); - get_block (ofp, zone, de); - for (j = 0; j < NR_DIR_ENTRIES; j++) { + for (j = 0; j < zone_size; j++) { - if (strcmp (de[j].d_name, name) == 0) { - return (((unsigned long) de[j].d_inum[0]) | (((unsigned long) de[j].d_inum[1]) << 8)); + get_block (ofp, zone + j, de); + + for (k = 0; k < NR_DIR_ENTRIES; k++) { + + if (strcmp (de[k].d_name, name) == 0) { + return (((unsigned long) de[k].d_inum[0]) | (((unsigned long) de[k].d_inum[1]) << 8)); + } + } } diff --git a/mls.c b/mls.c index 9411d92..58af299 100644 --- a/mls.c +++ b/mls.c @@ -337,7 +337,7 @@ static int find_entry (int ino, char *name) { p = &inode[off]; - for (i = 0; i < NR_DZONE_NUM * 2; i += 2) { + for (i = 0; i < NR_DZONES * 2; i += 2) { zone = ((unsigned long) p->i_zone[i]) | (((unsigned long) p->i_zone[1]) << 8); @@ -445,7 +445,7 @@ static int walk_dir (char *fn, int list, int multi) { if (multi) { printf ("%s:\n\n", fn); } - for (i = 0; i < NR_DZONE_NUM * 2; i += 2) { + for (i = 0; i < NR_DZONES * 2; i += 2) { unsigned long zone = ((unsigned long) ip1->i_zone[i]) | (((unsigned long) ip1->i_zone[i + 1]) << 8); diff --git a/mmd.c b/mmd.c index 985a72c..a349dd6 100644 --- a/mmd.c +++ b/mmd.c @@ -252,16 +252,16 @@ static unsigned long first_inode = 1; static int alloc_inode (FILE *fp, int mode, int userid, int groupid) { struct inode inode[INODES_PER_BLOCK]; - unsigned long ino, b, off; + unsigned long ino, block, off; for (ino = first_inode; ino < ninodes; ino++) { if (!get_bit (fp, INODE_MAP, ino)) { - b = ((ino - 1) / INODES_PER_BLOCK) + inode_offset; + block = ((ino - 1) / INODES_PER_BLOCK) + inode_offset; memset (inode, 0, sizeof (inode)); - get_block (fp, b, inode); + get_block (fp, block, inode); off = (ino - 1) % INODES_PER_BLOCK; @@ -269,7 +269,7 @@ static int alloc_inode (FILE *fp, int mode, int userid, int groupid) { write_to_byte_array (inode[off].uid, userid, 2); inode[off].gid = groupid; - put_block (fp, b, inode); + put_block (fp, block, inode); insert_bit (fp, INODE_MAP, ino); return ino; @@ -322,7 +322,7 @@ static int find_entry (int ino, char *name) { struct inode inode[INODES_PER_BLOCK], *p; struct dirent de[NR_DIR_ENTRIES]; - unsigned long b, off, i, j, zone; + unsigned long off, zone, b, i, j, k; unsigned long mode; b = ((ino - 1) / INODES_PER_BLOCK) + inode_offset; @@ -338,21 +338,27 @@ static int find_entry (int ino, char *name) { return 0; } - for (i = 0; i < NR_DZONE_NUM * 2; i += 2) { + for (i = 0; i < NR_DZONES * 2; i += 2) { zone = ((unsigned long) p->i_zone[i]) | (((unsigned long) p->i_zone[1]) << 8); + zone <<= zone_shift; if (!zone) { continue; } memset (de, 0, sizeof (de)); - get_block (ofp, zone, de); - for (j = 0; j < NR_DIR_ENTRIES; j++) { + for (j = 0; j < zone_size; j++) { - if (strcmp (de[j].d_name, name) == 0) { - return (((unsigned long) de[j].d_inum[0]) | (((unsigned long) de[j].d_inum[1]) << 8)); + get_block (ofp, zone + j, de); + + for (k = 0; k < NR_DIR_ENTRIES; k++) { + + if (strcmp (de[k].d_name, name) == 0) { + return (((unsigned long) de[k].d_inum[0]) | (((unsigned long) de[k].d_inum[1]) << 8)); + } + } }