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;
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);
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;
}
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);
#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];
#ifndef _INODE_H
#define _INODE_H
-#define NR_ZONE_NUMS 9
+#define NR_DZONES 7
+#define NR_TZONES 9
struct inode {
unsigned char gid;
unsigned char i_nlinks;
- unsigned char i_zone[2 * NR_ZONE_NUMS];
+ unsigned char i_zone[NR_TZONES * 2];
};
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;
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;
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;
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));
+ }
+
}
}
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);
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);
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;
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;
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;
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));
+ }
+
}
}