1 /* This file contains mount and unmount functionality. 2 * 3 * The entry points into this file are: 4 * do_readsuper perform the READSUPER file system call 5 * do_unmount perform the UNMOUNT file system call 6 * 7 * Created: 8 * April 2009 (D.C. van Moolenbroek) 9 */ 10 11 #include "inc.h" 12 13 /*===========================================================================* 14 * do_readsuper * 15 *===========================================================================*/ 16 int do_readsuper(void) 17 { 18 /* Mount the file system. 19 */ 20 char path[PATH_MAX]; 21 struct inode *ino; 22 struct sffs_attr attr; 23 int r; 24 25 dprintf(("%s: readsuper (dev %x, flags %x)\n", 26 sffs_name, m_in.m_vfs_fs_readsuper.device, m_in.vfs_fs_readsuper.flags)); 27 28 if (m_in.m_vfs_fs_readsuper.flags & REQ_ISROOT) { 29 printf("%s: attempt to mount as root device\n", sffs_name); 30 31 return EINVAL; 32 } 33 34 state.s_read_only = !!(m_in.m_vfs_fs_readsuper.flags & REQ_RDONLY); 35 state.s_dev = m_in.m_vfs_fs_readsuper.device; 36 37 init_dentry(); 38 ino = init_inode(); 39 40 attr.a_mask = SFFS_ATTR_MODE | SFFS_ATTR_SIZE; 41 42 /* We cannot continue if we fail to get the properties of the root inode at 43 * all, because we cannot guess the details of the root node to return to 44 * VFS. Print a (hopefully) helpful error message, and abort the mount. 45 */ 46 if ((r = verify_inode(ino, path, &attr)) != OK) { 47 if (r == EAGAIN) 48 printf("%s: shared folders disabled\n", sffs_name); 49 else if (sffs_params->p_prefix[0] && (r == ENOENT || r == EACCES)) 50 printf("%s: unable to access the given prefix directory\n", 51 sffs_name); 52 else 53 printf("%s: unable to access shared folders\n", sffs_name); 54 55 return r; 56 } 57 58 m_out.m_fs_vfs_readsuper.inode = INODE_NR(ino); 59 m_out.m_fs_vfs_readsuper.mode = get_mode(ino, attr.a_mode); 60 m_out.m_fs_vfs_readsuper.file_size = attr.a_size; 61 m_out.m_fs_vfs_readsuper.uid = sffs_params->p_uid; 62 m_out.m_fs_vfs_readsuper.gid = sffs_params->p_gid; 63 m_out.m_fs_vfs_readsuper.device = NO_DEV; 64 m_out.m_fs_vfs_readsuper.flags = RES_64BIT; 65 66 state.s_mounted = TRUE; 67 68 return OK; 69 } 70 71 /*===========================================================================* 72 * do_unmount * 73 *===========================================================================*/ 74 int do_unmount(void) 75 { 76 /* Unmount the file system. 77 */ 78 struct inode *ino; 79 80 dprintf(("%s: do_unmount\n", sffs_name)); 81 82 /* Decrease the reference count of the root inode. */ 83 if ((ino = find_inode(ROOT_INODE_NR)) == NULL) 84 return EINVAL; 85 86 put_inode(ino); 87 88 /* There should not be any referenced inodes anymore now. */ 89 if (have_used_inode()) 90 printf("%s: in-use inodes left at unmount time!\n", sffs_name); 91 92 state.s_mounted = FALSE; 93 94 return OK; 95 } 96