1433d6423SLionel Sambuc /* This file contains mount and unmount functionality.
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * The entry points into this file are:
4a99c939dSDavid van Moolenbroek * do_mount perform the READSUPER file system call
5433d6423SLionel Sambuc * do_unmount perform the UNMOUNT file system call
6433d6423SLionel Sambuc *
7433d6423SLionel Sambuc * Created:
8433d6423SLionel Sambuc * April 2009 (D.C. van Moolenbroek)
9433d6423SLionel Sambuc */
10433d6423SLionel Sambuc
11433d6423SLionel Sambuc #include "inc.h"
12433d6423SLionel Sambuc
13433d6423SLionel Sambuc /*===========================================================================*
14a99c939dSDavid van Moolenbroek * do_mount *
15433d6423SLionel Sambuc *===========================================================================*/
do_mount(dev_t __unused dev,unsigned int flags,struct fsdriver_node * root_node,unsigned int * res_flags)16*289b0467SDavid van Moolenbroek int do_mount(dev_t __unused dev, unsigned int flags,
17*289b0467SDavid van Moolenbroek struct fsdriver_node *root_node, unsigned int *res_flags)
18433d6423SLionel Sambuc {
19433d6423SLionel Sambuc /* Mount the file system.
20433d6423SLionel Sambuc */
21433d6423SLionel Sambuc char path[PATH_MAX];
22433d6423SLionel Sambuc struct inode *ino;
23433d6423SLionel Sambuc struct sffs_attr attr;
24433d6423SLionel Sambuc int r;
25433d6423SLionel Sambuc
26a99c939dSDavid van Moolenbroek dprintf(("%s: mount (dev %"PRIx64", flags %x)\n", sffs_name, dev, flags));
27433d6423SLionel Sambuc
28a99c939dSDavid van Moolenbroek if (flags & REQ_ISROOT) {
29433d6423SLionel Sambuc printf("%s: attempt to mount as root device\n", sffs_name);
30433d6423SLionel Sambuc
31433d6423SLionel Sambuc return EINVAL;
32433d6423SLionel Sambuc }
33433d6423SLionel Sambuc
34*289b0467SDavid van Moolenbroek read_only = !!(flags & REQ_RDONLY);
35433d6423SLionel Sambuc
36433d6423SLionel Sambuc init_dentry();
37433d6423SLionel Sambuc ino = init_inode();
38433d6423SLionel Sambuc
39433d6423SLionel Sambuc attr.a_mask = SFFS_ATTR_MODE | SFFS_ATTR_SIZE;
40433d6423SLionel Sambuc
41433d6423SLionel Sambuc /* We cannot continue if we fail to get the properties of the root inode at
42433d6423SLionel Sambuc * all, because we cannot guess the details of the root node to return to
43433d6423SLionel Sambuc * VFS. Print a (hopefully) helpful error message, and abort the mount.
44433d6423SLionel Sambuc */
45433d6423SLionel Sambuc if ((r = verify_inode(ino, path, &attr)) != OK) {
46433d6423SLionel Sambuc if (r == EAGAIN)
47433d6423SLionel Sambuc printf("%s: shared folders disabled\n", sffs_name);
48433d6423SLionel Sambuc else if (sffs_params->p_prefix[0] && (r == ENOENT || r == EACCES))
49433d6423SLionel Sambuc printf("%s: unable to access the given prefix directory\n",
50433d6423SLionel Sambuc sffs_name);
51433d6423SLionel Sambuc else
52433d6423SLionel Sambuc printf("%s: unable to access shared folders\n", sffs_name);
53433d6423SLionel Sambuc
54433d6423SLionel Sambuc return r;
55433d6423SLionel Sambuc }
56433d6423SLionel Sambuc
57a99c939dSDavid van Moolenbroek root_node->fn_ino_nr = INODE_NR(ino);
58a99c939dSDavid van Moolenbroek root_node->fn_mode = get_mode(ino, attr.a_mode);
59a99c939dSDavid van Moolenbroek root_node->fn_size = attr.a_size;
60a99c939dSDavid van Moolenbroek root_node->fn_uid = sffs_params->p_uid;
61a99c939dSDavid van Moolenbroek root_node->fn_gid = sffs_params->p_gid;
62a99c939dSDavid van Moolenbroek root_node->fn_dev = NO_DEV;
63433d6423SLionel Sambuc
64a99c939dSDavid van Moolenbroek *res_flags = RES_64BIT;
65433d6423SLionel Sambuc
66433d6423SLionel Sambuc return OK;
67433d6423SLionel Sambuc }
68433d6423SLionel Sambuc
69433d6423SLionel Sambuc /*===========================================================================*
70433d6423SLionel Sambuc * do_unmount *
71433d6423SLionel Sambuc *===========================================================================*/
do_unmount(void)72a99c939dSDavid van Moolenbroek void do_unmount(void)
73433d6423SLionel Sambuc {
74433d6423SLionel Sambuc /* Unmount the file system.
75433d6423SLionel Sambuc */
76433d6423SLionel Sambuc struct inode *ino;
77433d6423SLionel Sambuc
78a99c939dSDavid van Moolenbroek dprintf(("%s: unmount\n", sffs_name));
79433d6423SLionel Sambuc
80433d6423SLionel Sambuc /* Decrease the reference count of the root inode. */
81433d6423SLionel Sambuc if ((ino = find_inode(ROOT_INODE_NR)) == NULL)
82a99c939dSDavid van Moolenbroek return;
83433d6423SLionel Sambuc
84433d6423SLionel Sambuc put_inode(ino);
85433d6423SLionel Sambuc
86433d6423SLionel Sambuc /* There should not be any referenced inodes anymore now. */
87433d6423SLionel Sambuc if (have_used_inode())
88433d6423SLionel Sambuc printf("%s: in-use inodes left at unmount time!\n", sffs_name);
89433d6423SLionel Sambuc }
90