xref: /minix3/minix/lib/libsffs/mount.c (revision eda6f5931d42c77e1480347b1fc3eef2f8d33806)
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 dev, unsigned int flags, struct fsdriver_node *root_node,
17 	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   state.s_read_only = !!(flags & REQ_RDONLY);
35   state.s_dev = dev;
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   root_node->fn_ino_nr = INODE_NR(ino);
59   root_node->fn_mode = get_mode(ino, attr.a_mode);
60   root_node->fn_size = attr.a_size;
61   root_node->fn_uid = sffs_params->p_uid;
62   root_node->fn_gid = sffs_params->p_gid;
63   root_node->fn_dev = NO_DEV;
64 
65   *res_flags = RES_64BIT;
66 
67   return OK;
68 }
69 
70 /*===========================================================================*
71  *				do_unmount				     *
72  *===========================================================================*/
73 void do_unmount(void)
74 {
75 /* Unmount the file system.
76  */
77   struct inode *ino;
78 
79   dprintf(("%s: unmount\n", sffs_name));
80 
81   /* Decrease the reference count of the root inode. */
82   if ((ino = find_inode(ROOT_INODE_NR)) == NULL)
83 	return;
84 
85   put_inode(ino);
86 
87   /* There should not be any referenced inodes anymore now. */
88   if (have_used_inode())
89 	printf("%s: in-use inodes left at unmount time!\n", sffs_name);
90 }
91