From: Robert Pengelly Date: Mon, 28 Oct 2024 20:49:23 +0000 (+0000) Subject: Fixed get_bit and insert_bit X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=fc3750e047095938e2e9835c673c0b4b0b50affa;p=minixfstools.git Fixed get_bit and insert_bit --- diff --git a/common.c b/common.c index 15f3d72..515dde5 100644 --- a/common.c +++ b/common.c @@ -266,15 +266,15 @@ void incr_size (FILE *fp, int n, unsigned long count) { int get_bit (FILE *fp, unsigned long block, int bit) { - int w, s; + int w, s/*, b*/; memset (buffer, 0, sizeof (buffer)); get_block (fp, block, buffer); - w = bit / (8 * sizeof (unsigned short)); - s = bit % (8 * sizeof (unsigned short)); + w = bit / 8; + s = bit % 8; - return (buffer[w] & (1 << s)); + return ((buffer[w] >> s) & 0x01); } @@ -285,8 +285,8 @@ void insert_bit (FILE *fp, unsigned long block, int bit) { memset (buffer, 0, sizeof (buffer)); get_block (fp, block, buffer); - w = bit / (8 * sizeof (unsigned short)); - s = bit % (8 * sizeof (unsigned short)); + w = bit / 8; + s = bit % 8; buffer[w] |= (1 << s); put_block (fp, block, buffer); diff --git a/mcopy.c b/mcopy.c index 8f11136..8e4b29a 100644 --- a/mcopy.c +++ b/mcopy.c @@ -284,18 +284,18 @@ 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 int num, b, off; + unsigned long ino, b, off; - for (num = first_inode; num < ninodes; num++) { + for (ino = first_inode; ino < ninodes; ino++) { - if (!get_bit (fp, INODE_MAP, num)) { + if (!get_bit (fp, INODE_MAP, ino)) { - b = ((num - 1) / INODES_PER_BLOCK) + inode_offset; + b = ((ino - 1) / INODES_PER_BLOCK) + inode_offset; memset (inode, 0, sizeof (inode)); get_block (fp, b, inode); - off = (num - 1) % INODES_PER_BLOCK; + off = (ino - 1) % INODES_PER_BLOCK; write_to_byte_array (inode[off].i_mode, mode, 2); write_to_byte_array (inode[off].uid, userid, 2); @@ -303,8 +303,8 @@ static int alloc_inode (FILE *fp, int mode, int userid, int groupid) { inode[off].gid = groupid; put_block (fp, b, inode); - insert_bit (fp, INODE_MAP, num); - return num; + insert_bit (fp, INODE_MAP, ino); + return ino; } @@ -317,26 +317,26 @@ static int alloc_inode (FILE *fp, int mode, int userid, int groupid) { int alloc_zone (FILE *fp) { - unsigned long b, z, i; + unsigned long i, block, zone; - for (z = first_data_zone; z < nzones; z++) { + for (zone = first_data_zone; zone < nzones; zone++) { - if (!get_bit (ofp, zone_map, z - zone_off)) { + if (!get_bit (ofp, zone_map, zone - zone_off)) { - b = z << zone_shift; + block = zone << zone_shift; - if ((b + zone_size) > nzones) { + if ((block + zone_size) > nzones) { goto _zone_error; } memset (buf, 0, BLOCK_SIZE); for (i = 0; i < zone_size; i++) { - put_block (fp, b + i, buf); + put_block (fp, block + i, buf); } - insert_bit (fp, zone_map, z - zone_off); - return z; + insert_bit (fp, zone_map, zone - zone_off); + return zone; } diff --git a/mmd.c b/mmd.c index a22e6a9..985a72c 100644 --- a/mmd.c +++ b/mmd.c @@ -252,18 +252,18 @@ 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 int num, b, off; + unsigned long ino, b, off; - for (num = first_inode; num < ninodes; num++) { + for (ino = first_inode; ino < ninodes; ino++) { - if (!get_bit (fp, INODE_MAP, num)) { + if (!get_bit (fp, INODE_MAP, ino)) { - b = ((num - 1) / INODES_PER_BLOCK) + inode_offset; + b = ((ino - 1) / INODES_PER_BLOCK) + inode_offset; memset (inode, 0, sizeof (inode)); get_block (fp, b, inode); - off = (num - 1) % INODES_PER_BLOCK; + off = (ino - 1) % INODES_PER_BLOCK; write_to_byte_array (inode[off].i_mode, mode, 2); write_to_byte_array (inode[off].uid, userid, 2); @@ -271,8 +271,8 @@ static int alloc_inode (FILE *fp, int mode, int userid, int groupid) { inode[off].gid = groupid; put_block (fp, b, inode); - insert_bit (fp, INODE_MAP, num); - return num; + insert_bit (fp, INODE_MAP, ino); + return ino; } @@ -285,26 +285,26 @@ static int alloc_inode (FILE *fp, int mode, int userid, int groupid) { int alloc_zone (FILE *fp) { - unsigned long b, z, i; + unsigned long i, block, zone; - for (z = first_data_zone; z < nzones; z++) { + for (zone = first_data_zone; zone < nzones; zone++) { - if (!get_bit (ofp, zone_map, z - zone_off)) { + if (!get_bit (ofp, zone_map, zone - zone_off)) { - b = z << zone_shift; + block = zone << zone_shift; - if ((b + zone_size) > nzones) { + if ((block + zone_size) > nzones) { goto _zone_error; } memset (buf, 0, BLOCK_SIZE); for (i = 0; i < zone_size; i++) { - put_block (fp, b + i, buf); + put_block (fp, block + i, buf); } - insert_bit (fp, zone_map, z - zone_off); - return z; + insert_bit (fp, zone_map, zone - zone_off); + return zone; }