int main(int argc, char *argv[]) { struct super_block *sb; int ret; if (argc != 2) { usage(argv[0]); } sb = testfs_make_super_block(argv[1]); testfs_make_inode_freemap(sb); testfs_make_block_freemap(sb); testfs_make_csum_table(sb); testfs_make_inode_blocks(sb); testfs_close_super_block(sb); ret = testfs_init_super_block(argv[1], 0, &sb); if (ret) { EXIT("testfs_init_super_block"); } testfs_make_root_dir(sb); testfs_close_super_block(sb); return 0; }
int main(int argc, char * const argv[]) { struct super_block *sb; char *line = NULL; size_t line_size = 0; ssize_t nr; int ret; struct context c; // context contains command line arguments/parameters, // inode of directory from which cmd was issued, and no of args. struct args * args = parse_arguments(argc, argv); // args->disk contains the name of the disk file. // initializes the in memory structure sb with data that is // read from the disk. after successful execution, we have // sb initialized to dsuper_block read from disk. ret = testfs_init_super_block(args->disk, args->corrupt, &sb); //fslice_clear(); if (ret) { EXIT("testfs_init_super_block"); } /* if the inode does not exist in the inode_hash_map (which is an inmemory map of all inode blocks, create a new inode by allocating memory to it. read the dinode from disk into that memory inode */ c.cur_dir = testfs_get_inode(sb, 0); /* root dir */ for (; PROMPT, (nr = getline(&line, &line_size, stdin)) != EOF;) { char * name; char * args; printf("command: %s\n", line); name = strtok(line, " \t\n"); args = strtok(NULL, "\n"); handle_command(sb, &c, name, args); if (can_quit) { break; } } free(line); // decrement inode count by 1. remove inode from in_memory hash map if // inode count has become 0. testfs_put_inode(c.cur_dir); testfs_close_super_block(sb); return 0; }