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);
}
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);
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);
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;
}
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;
}
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);
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;
}
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;
}