VM: restore >4k secondary cache functionality
[minix.git] / lib / libsffs / mount.c
blob1649f2c5cf10d05b143790e3f2625503e47913a3
1 /* This file contains mount and unmount functionality.
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
7 * Created:
8 * April 2009 (D.C. van Moolenbroek)
9 */
11 #include "inc.h"
13 /*===========================================================================*
14 * do_readsuper *
15 *===========================================================================*/
16 int do_readsuper()
18 /* Mount the file system.
20 char path[PATH_MAX];
21 struct inode *ino;
22 struct sffs_attr attr;
23 int r;
25 dprintf(("%s: readsuper (dev %x, flags %x)\n",
26 sffs_name, (dev_t) m_in.REQ_DEV, m_in.REQ_FLAGS));
28 if (m_in.REQ_FLAGS & REQ_ISROOT) {
29 printf("%s: attempt to mount as root device\n", sffs_name);
31 return EINVAL;
34 state.s_read_only = !!(m_in.REQ_FLAGS & REQ_RDONLY);
35 state.s_dev = m_in.REQ_DEV;
37 init_dentry();
38 ino = init_inode();
40 attr.a_mask = SFFS_ATTR_MODE | SFFS_ATTR_SIZE;
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.
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);
55 return r;
58 m_out.RES_INODE_NR = INODE_NR(ino);
59 m_out.RES_MODE = get_mode(ino, attr.a_mode);
60 m_out.RES_FILE_SIZE_HI = ex64hi(attr.a_size);
61 m_out.RES_FILE_SIZE_LO = ex64lo(attr.a_size);
62 m_out.RES_UID = sffs_params->p_uid;
63 m_out.RES_GID = sffs_params->p_gid;
64 m_out.RES_DEV = NO_DEV;
65 m_out.RES_CONREQS = 1; /* We can handle only 1 request at a time */
67 state.s_mounted = TRUE;
69 return OK;
72 /*===========================================================================*
73 * do_unmount *
74 *===========================================================================*/
75 int do_unmount()
77 /* Unmount the file system.
79 struct inode *ino;
81 dprintf(("%s: do_unmount\n", sffs_name));
83 /* Decrease the reference count of the root inode. */
84 if ((ino = find_inode(ROOT_INODE_NR)) == NULL)
85 return EINVAL;
87 put_inode(ino);
89 /* There should not be any referenced inodes anymore now. */
90 if (have_used_inode())
91 printf("%s: in-use inodes left at unmount time!\n", sffs_name);
93 state.s_mounted = FALSE;
95 return OK;