void initSFS(int dev) { //Assuming only predefined sizes are used char buf[4096]; int i; init_superblock(&sb); write(devfd[dev],(&sb),BLOCK); init_inodetable(&inodetable); //initialising root directory inode head=init_inode(getinode(dev),1,1,BLOCK,IS_DIR,6); //4+2=>read+write tail=head; head->INODE->i_blocks[0]=alloc_data(dev); strcpy(dentry.dirname,"."); dentry.i_node=head->i_node; head->INODE->file_size=sizeof(dentry); write(devfd[dev],head->INODE,sizeof(head->INODE)); for(i=1;i<INODETABSIZE;i++) write(devfd[dev],&inodetable,sizeof(inodetable)); // printf("%d\n",p); bzero(buf,PAGECOMP); write(devfd[dev],buf,PAGECOMP); write(devfd[dev],&dentry,BLOCK); head->offset=sizeof(dentry); for(i=1;i<DATABLOCK;i++) { if(i==DATABLOCK-1) db.next=-1; else db.next=i+1; db.cur=i; write(devfd[dev],&db,BLOCK); } }
int rd_creat(char* pathname){ char *dir_path; char *filename; split_dir_file(pathname, &dir_path, &filename); int dir_inode_num = get_dir_inode(dir_path, 1); //check if dir_path exists if(dir_inode_num == -1){ return -1; } int tmp = get_dir_entry(dir_inode_num, filename, 1); if(tmp != -1){ //directory already exists printf("error: dir already exists\n"); return -1; } //get ready to allocate inode int index = get_free_inode(); if(index == -1){ printf("no free inodes\n"); return -1; } s_block->free_inodes = s_block->free_inodes - 1; init_inode(index, 2); //type = 2, regular file inode_array[dir_inode_num].size = inode_array[dir_inode_num].size + sizeof(dir_entry); dir_entry* new_dir = get_free_dir_entry(dir_inode_num); new_dir->inode_number = index; strcpy(new_dir->filename, filename); printf("rd_creat created a file\n"); return 1; }
static void mkfs(){ MESSAGE message; HD_PART_INFO part_info; message.type=INFO_FS_IOCTL; message.subtype=DIOCTL_GET_PART_INFO; message.device=ROOT_DEVICE;//-------------需要指定到具体分区-------------------- message.arg_pointer=(void*)&part_info; message.source_pid=TASK_FS; assert(dd_map[DRIVER(message.device)].driver_pid!=PID_INVALID,"driver not exist!"); send_receive(BOTH,dd_map[DRIVER(message.device)].driver_pid,&message); #ifdef DEBUG_FS printl("device=%d base=%d size=%d (in sector)\n",DEVICE(message.device),part_info.base,part_info.size); #endif SUPER_BLOCK sb; //super block int super_block_first_index=get_super_block_first_index(); init_super_block(&sb,super_block_first_index,part_info.size); #ifdef DEBUG_FS printl("init_super_block ok(start_sector=%d)\n",super_block_first_index); #endif //imap /* int imap_first_index=super_block_first_index+SUPER_SECTORS_LENGTH; */ int imap_first_index=get_imap_first_index(sb); int imap_sectors_length=get_imap_length(sb)/* sb.imap_sectors_length */; init_imap(imap_first_index,imap_sectors_length); #ifdef DEBUG_FS printl("init_imap ok(start_sector=%d)\n",imap_first_index); #endif //smap /* int smap_first_index=imap_first_index+imap_sectors_length; */ int smap_first_index=get_smap_first_index(sb); int smap_sectors_length=get_smap_length(sb)/* sb.smap_sectors_length */; init_smap(smap_first_index,smap_sectors_length); #ifdef DEBUG_FS printl("init_smap ok(start_sector=%d)\n",smap_first_index); #endif //inode /* int inode_first_index=smap_first_index+smap_sectors_length; */ int inode_first_index=get_inode_first_index(sb); /* int inode_sectors_length=get_inode_length(sb)/\* sb.inodes_sectors_length *\/; */ int root_dir_start_index=get_data_block_first_index(sb)/* sb.data_first_sector_index */; init_inode(inode_first_index,root_dir_start_index); #ifdef DEBUG_FS printl("init_inode ok(start_sector=%d)\n",inode_first_index); #endif //data /* int data_block_first_index=inode_first_index+inode_sectors_length; */ int data_block_first_index=get_data_block_first_index(sb); init_data_block(data_block_first_index); #ifdef DEBUG_FS printl("init_data_block ok(start_sector=%d)\n",data_block_first_index); #endif }
/*===========================================================================* * do_readsuper * *===========================================================================*/ PUBLIC int do_readsuper() { /* Mount the file system. */ char path[PATH_MAX]; struct inode *ino; struct hgfs_attr attr; int r; dprintf(("HGFS: readsuper (dev %x, flags %x)\n", (dev_t) m_in.REQ_DEV, m_in.REQ_FLAGS)); if (m_in.REQ_FLAGS & REQ_ISROOT) { printf("HGFS: attempt to mount as root device\n"); return EINVAL; } state.read_only = !!(m_in.REQ_FLAGS & REQ_RDONLY); state.dev = m_in.REQ_DEV; init_dentry(); ino = init_inode(); attr.a_mask = HGFS_ATTR_MODE | HGFS_ATTR_SIZE; /* We cannot continue if we fail to get the properties of the root inode at * all, because we cannot guess the details of the root node to return to * VFS. Print a (hopefully) helpful error message, and abort the mount. */ if ((r = verify_inode(ino, path, &attr)) != OK) { if (r == EAGAIN) printf("HGFS: shared folders disabled\n"); else if (opt.prefix[0] && (r == ENOENT || r == EACCES)) printf("HGFS: unable to access the given prefix directory\n"); else printf("HGFS: unable to access shared folders\n"); return r; } m_out.RES_INODE_NR = INODE_NR(ino); m_out.RES_MODE = get_mode(ino, attr.a_mode); m_out.RES_FILE_SIZE_HI = ex64hi(attr.a_size); m_out.RES_FILE_SIZE_LO = ex64lo(attr.a_size); m_out.RES_UID = opt.uid; m_out.RES_GID = opt.gid; m_out.RES_DEV = NO_DEV; m_out.RES_CONREQS = 1; /* We can handle only 1 request at a time */ state.mounted = TRUE; return OK; }
static void init_root_inode (void) { struct { inode_s inode; char name[1]; } root; FN; init_inode( &root.inode, ROOT_INO, S_IFDIR, ""); root.name[0] = '\0'; insert_inode( &root.inode); }
info_s *new_info (info_s *parent, char *name, unint mode) { info_s *info; u64 ino; FN; ino = alloc_ino(parent->in_tree.t_dev); info = alloc_info(strlen(name) + 1, get_species(mode), parent->in_tree.t_dev); init_inode( &info->in_inode, ino, mode, name); add_info(ino, info); return info; }
int get_inode(const char * path, struct inode * out) { init_inode(out); return get_inode_impl(path, out); }
int main(int argc, char *argv[]) { init_inode(); return fuse_main(argc, argv, &hello_oper, NULL); }