int fd;
struct partition entry;
block_t d;
+ struct stat st;
if ((fd = open(device, O_RDONLY)) == -1) {
perror("sizeup open");
}
if (ioctl(fd, DIOCGETP, &entry) == -1) {
perror("sizeup ioctl");
- entry.size = cvu64(0);
+ if(fstat(fd, &st) < 0) {
+ perror("fstat");
+ entry.size = cvu64(0);
+ } else {
+ fprintf(stderr, "used fstat instead\n");
+ entry.size = cvu64(st.st_size);
+ }
}
close(fd);
d = div64u(entry.size, block_size);
if ((f = open(token[4], O_RDONLY)) < 0) {
fprintf(stderr, "%s: Can't open %s: %s\n",
progname, token[4], strerror(errno));
- } else
+ } else {
eat_file(n, f);
+ }
}
}
{
/* Increment the link count to inode n */
int off;
+ static int enter = 0;
block_t b;
+ if(enter) exit(1);
+
b = ((n - 1) / inodes_per_block) + inode_offset;
off = (n - 1) % inodes_per_block;
if (fs_version == 1) {
inode1[off].d1_nlinks++;
put_block(b, (char *) inode1);
} else {
- d2_inode *inode2;
+ static d2_inode *inode2 = NULL;
+ int n;
- if(!(inode2 = malloc(V2_INODES_PER_BLOCK(block_size))))
+ n = sizeof(*inode2) * V2_INODES_PER_BLOCK(block_size);
+ if(!inode2 && !(inode2 = malloc(n)))
pexit("couldn't allocate a block of inodes");
get_block(b, (char *) inode2);
inode2[off].d2_nlinks++;
put_block(b, (char *) inode2);
-
- free(inode2);
}
+ enter = 0;
}
put_block(b, (char *) inode1);
} else {
d2_inode *inode2;
- if(!(inode2 = malloc(V2_INODES_PER_BLOCK(block_size))))
+ if(!(inode2 = malloc(V2_INODES_PER_BLOCK(block_size) * sizeof(*inode2))))
pexit("couldn't allocate a block of inodes");
get_block(b, (char *) inode2);
block_t b;
num = next_inode++;
- if (num > nrinodes) pexit("File system does not have enough inodes");
+ if (num > nrinodes) {
+ fprintf(stderr, "have %d inodoes\n", nrinodes);
+ pexit("File system does not have enough inodes");
+ }
b = ((num - 1) / inodes_per_block) + inode_offset;
off = (num - 1) % inodes_per_block;
if (fs_version == 1) {
} else {
d2_inode *inode2;
- if(!(inode2 = malloc(V2_INODES_PER_BLOCK(block_size))))
+ if(!(inode2 = malloc(V2_INODES_PER_BLOCK(block_size) * sizeof(*inode2))))
pexit("couldn't allocate a block of inodes");
get_block(b, (char *) inode2);
block_t b, inode_limit;
struct direct *dir;
- if(!(inode2 = malloc(V2_INODES_PER_BLOCK(block_size))))
+ if(!(inode2 = malloc(V2_INODES_PER_BLOCK(block_size) * sizeof(*inode2))))
pexit("couldn't allocate a block of inodes");
if(!(dir = malloc(NR_DIR_ENTRIES(block_size)*sizeof(*dir))))