xref: /minix3/minix/lib/libpuffs/mount.c (revision ba736c796854b82e29da17267614db0a449419db)
1 /* Created (MFS based):
2  *   June 2011 (Evgeniy Ivanov)
3  */
4 
5 #include "fs.h"
6 #include <fcntl.h>
7 #include <minix/vfsif.h>
8 
9 /*===========================================================================*
10  *				fs_mount				     *
11  *===========================================================================*/
fs_mount(dev_t __unused dev,unsigned int flags,struct fsdriver_node * root_node,unsigned int * res_flags)12 int fs_mount(dev_t __unused dev, unsigned int flags,
13 	struct fsdriver_node *root_node, unsigned int *res_flags)
14 {
15   struct vattr *root_va;
16 
17   is_readonly_fs = !!(flags & REQ_RDONLY);
18 
19   /* Open root pnode */
20   global_pu->pu_pn_root->pn_count = 1;
21 
22   /* Root pnode properties */
23   root_va = &global_pu->pu_pn_root->pn_va;
24   root_node->fn_ino_nr = root_va->va_fileid;
25   root_node->fn_mode = root_va->va_mode;
26   root_node->fn_size = root_va->va_size;
27   root_node->fn_uid = root_va->va_uid;
28   root_node->fn_gid = root_va->va_gid;
29   root_node->fn_dev = NO_DEV;
30 
31   *res_flags = RES_NOFLAGS;
32 
33   mounted = TRUE;
34 
35   return(OK);
36 }
37 
38 
39 /*===========================================================================*
40  *				fs_mountpt				     *
41  *===========================================================================*/
fs_mountpt(ino_t ino_nr)42 int fs_mountpt(ino_t ino_nr)
43 {
44 /* This function looks up the mount point, it checks the condition whether
45  * the partition can be mounted on the pnode or not.
46  */
47   int r = OK;
48   struct puffs_node *pn;
49   mode_t bits;
50 
51   if ((pn = puffs_pn_nodewalk(global_pu, find_inode_cb, &ino_nr)) == NULL)
52 	return(EINVAL);
53 
54   if (pn->pn_mountpoint) r = EBUSY;
55 
56   /* It may not be special. */
57   bits = pn->pn_va.va_mode & I_TYPE;
58   if(bits == I_BLOCK_SPECIAL || bits == I_CHAR_SPECIAL) r = ENOTDIR;
59 
60   if (r == OK)
61 	pn->pn_mountpoint = TRUE;
62 
63   return(r);
64 }
65 
66 
67 /*===========================================================================*
68  *				fs_unmount				     *
69  *===========================================================================*/
fs_unmount(void)70 void fs_unmount(void)
71 {
72   int error;
73 
74   /* Always force unmounting, as VFS will not tolerate failure. */
75   error = global_pu->pu_ops.puffs_fs_unmount(global_pu, MNT_FORCE);
76   if (error) {
77 	lpuffs_debug("user handler failed to unmount filesystem!\
78 		Force unmount!\n");
79   }
80 
81   fs_sync();
82 
83   /* Finish off the unmount. */
84   PU_SETSTATE(global_pu, PUFFS_STATE_UNMOUNTED);
85   mounted = FALSE;
86   global_pu->pu_pn_root->pn_count--;
87 }
88