xref: /minix3/minix/lib/libvtreefs/mount.c (revision eda6f5931d42c77e1480347b1fc3eef2f8d33806)
1 /* VTreeFS - mount.c - by Alen Stojanov and David van Moolenbroek */
2 
3 #include "inc.h"
4 #include <minix/vfsif.h>
5 
6 /*===========================================================================*
7  *				fs_mount				     *
8  *===========================================================================*/
9 int fs_mount(dev_t dev, unsigned int flags, struct fsdriver_node *root_node,
10 	unsigned int *res_flags)
11 {
12 	/* This function gets the root inode and sends back its details.
13 	 */
14 	struct inode *root;
15 
16 	/* Get the device number, for stat requests. */
17 	fs_dev = dev;
18 
19 	/* The VTreeFS must not be mounted as a root file system. */
20 	if (flags & REQ_ISROOT)
21 		return EINVAL;
22 
23 	/* Get the root inode and increase its reference count. */
24 	root = get_root_inode();
25 	ref_inode(root);
26 
27 	/* The system is now mounted. Call the initialization hook. */
28 	if (vtreefs_hooks->init_hook != NULL)
29 		vtreefs_hooks->init_hook();
30 
31 	/* Return the root inode's properties. */
32 	root_node->fn_ino_nr = get_inode_number(root);
33 	root_node->fn_mode = root->i_stat.mode;
34 	root_node->fn_size = root->i_stat.size;
35 	root_node->fn_uid = root->i_stat.uid;
36 	root_node->fn_gid = root->i_stat.gid;
37 	root_node->fn_dev = NO_DEV;
38 
39 	*res_flags = RES_NOFLAGS;
40 
41 	return OK;
42 }
43 
44 /*===========================================================================*
45  *				fs_unmount				     *
46  *===========================================================================*/
47 void fs_unmount(void)
48 {
49 	/* Unmount the file system.
50 	 */
51 	struct inode *root;
52 
53 	/* Decrease the count of the root inode. */
54 	root = get_root_inode();
55 
56 	put_inode(root);
57 
58 	/* The system is unmounted. Call the cleanup hook. */
59 	if (vtreefs_hooks->cleanup_hook != NULL)
60 		vtreefs_hooks->cleanup_hook();
61 }
62