Fragment mkfs
// Write initial FS state to the device
// arg is
targ device: /dev/sdb or lv /dev/sdb1
fd = open(argv[1], O_RDWR);
if (fd == -1) {
perror("Error: cannot open the device!\n");
return -1;
}
// wipe out device before writing wipe_out_device(fd, 1));
// Write actual on disk structure
write_superblock(fd));
write_metadata(fd);
write_inode_table(fd);
write_root_inode(fd);
write_lostfound_inode(fd);
//write entries to inode table
write_root2itable(fd);
write_laf2itable(fd);
int write_root_inode (int fd) {
// construct root inode
struct dm_inode root_inode = {
.i_version = 1,
.i_flags = 0,
.i_mode = S_IFDIR | S_IRWXU | S_IROTH | S_IXOTH,
.i_uid = 0,
.i_ctime = dm_ctime,
.i_mtime = dm_ctime,
.i_size = 0,
.i_ino = DM_ROOT_INO,
.i_addrb = {DM_ROOT_INODE_OFFSET + 1, 0, 0},
.i_addre = {DM_ROOT_INODE_OFFSET + DM_EXALLOC+1, 0, 0},
};
lseek(fd, DM_ROOT_OFFSET * DM_BSIZE, SEEK_SET);
write(fd, &root_inode, sizeof(root_inode)));
// write root to the inode table as a first entry
lseek(fd, (DM_ITABLE_OFFSET + 1) * DM_BSIZE, SEEK_SET);
write(fd, &blk, sizeof(uint32_t))