1 /* This file contains mount and unmount functionality. 2 * 3 * The entry points into this file are: 4 * do_mount 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_mount * 15 *===========================================================================*/ 16 int do_mount(dev_t __unused dev, unsigned int flags, 17 struct fsdriver_node *root_node, unsigned int *res_flags) 18 { 19 /* Mount the file system. 20 */ 21 char path[PATH_MAX]; 22 struct inode *ino; 23 struct sffs_attr attr; 24 int r; 25 26 dprintf(("%s: mount (dev %"PRIx64", flags %x)\n", sffs_name, dev, flags)); 27 28 if (flags & REQ_ISROOT) { 29 printf("%s: attempt to mount as root device\n", sffs_name); 30 31 return EINVAL; 32 } 33 34 read_only = !!(flags & REQ_RDONLY); 35 36 init_dentry(); 37 ino = init_inode(); 38 39 attr.a_mask = SFFS_ATTR_MODE | SFFS_ATTR_SIZE; 40 41 /* We cannot continue if we fail to get the properties of the root inode at 42 * all, because we cannot guess the details of the root node to return to 43 * VFS. Print a (hopefully) helpful error message, and abort the mount. 44 */ 45 if ((r = verify_inode(ino, path, &attr)) != OK) { 46 if (r == EAGAIN) 47 printf("%s: shared folders disabled\n", sffs_name); 48 else if (sffs_params->p_prefix[0] && (r == ENOENT || r == EACCES)) 49 printf("%s: unable to access the given prefix directory\n", 50 sffs_name); 51 else 52 printf("%s: unable to access shared folders\n", sffs_name); 53 54 return r; 55 } 56 57 root_node->fn_ino_nr = INODE_NR(ino); 58 root_node->fn_mode = get_mode(ino, attr.a_mode); 59 root_node->fn_size = attr.a_size; 60 root_node->fn_uid = sffs_params->p_uid; 61 root_node->fn_gid = sffs_params->p_gid; 62 root_node->fn_dev = NO_DEV; 63 64 *res_flags = RES_64BIT; 65 66 return OK; 67 } 68 69 /*===========================================================================* 70 * do_unmount * 71 *===========================================================================*/ 72 void do_unmount(void) 73 { 74 /* Unmount the file system. 75 */ 76 struct inode *ino; 77 78 dprintf(("%s: unmount\n", sffs_name)); 79 80 /* Decrease the reference count of the root inode. */ 81 if ((ino = find_inode(ROOT_INODE_NR)) == NULL) 82 return; 83 84 put_inode(ino); 85 86 /* There should not be any referenced inodes anymore now. */ 87 if (have_used_inode()) 88 printf("%s: in-use inodes left at unmount time!\n", sffs_name); 89 } 90