xref: /minix3/minix/lib/libvtreefs/mount.c (revision 289b04677a1b234d09a045a727f5e614a6c8d716)
1693ad767SDavid van Moolenbroek /* VTreeFS - mount.c - mounting and unmounting */
2433d6423SLionel Sambuc 
3433d6423SLionel Sambuc #include "inc.h"
40dc5c83eSDavid van Moolenbroek #include <minix/vfsif.h>
5433d6423SLionel Sambuc 
6693ad767SDavid van Moolenbroek /*
7693ad767SDavid van Moolenbroek  * Mount the file system.  Obtain the root inode and send back its details.
8693ad767SDavid van Moolenbroek  */
9693ad767SDavid van Moolenbroek int
fs_mount(dev_t __unused dev,unsigned int flags,struct fsdriver_node * root_node,unsigned int * res_flags)10*289b0467SDavid van Moolenbroek fs_mount(dev_t __unused dev, unsigned int flags,
11*289b0467SDavid van Moolenbroek 	struct fsdriver_node * root_node, unsigned int * res_flags)
12433d6423SLionel Sambuc {
13433d6423SLionel Sambuc 	struct inode *root;
14433d6423SLionel Sambuc 
15693ad767SDavid van Moolenbroek 	/* VTreeFS must not be mounted as a root file system. */
160dc5c83eSDavid van Moolenbroek 	if (flags & REQ_ISROOT)
17433d6423SLionel Sambuc 		return EINVAL;
18433d6423SLionel Sambuc 
19433d6423SLionel Sambuc 	/* Get the root inode and increase its reference count. */
20433d6423SLionel Sambuc 	root = get_root_inode();
21433d6423SLionel Sambuc 	ref_inode(root);
22433d6423SLionel Sambuc 
23433d6423SLionel Sambuc 	/* The system is now mounted.  Call the initialization hook. */
24433d6423SLionel Sambuc 	if (vtreefs_hooks->init_hook != NULL)
25433d6423SLionel Sambuc 		vtreefs_hooks->init_hook();
26433d6423SLionel Sambuc 
27433d6423SLionel Sambuc 	/* Return the root inode's properties. */
280dc5c83eSDavid van Moolenbroek 	root_node->fn_ino_nr = get_inode_number(root);
290dc5c83eSDavid van Moolenbroek 	root_node->fn_mode = root->i_stat.mode;
300dc5c83eSDavid van Moolenbroek 	root_node->fn_size = root->i_stat.size;
310dc5c83eSDavid van Moolenbroek 	root_node->fn_uid = root->i_stat.uid;
320dc5c83eSDavid van Moolenbroek 	root_node->fn_gid = root->i_stat.gid;
330dc5c83eSDavid van Moolenbroek 	root_node->fn_dev = NO_DEV;
34433d6423SLionel Sambuc 
350dc5c83eSDavid van Moolenbroek 	*res_flags = RES_NOFLAGS;
36433d6423SLionel Sambuc 
37433d6423SLionel Sambuc 	return OK;
38433d6423SLionel Sambuc }
39433d6423SLionel Sambuc 
40693ad767SDavid van Moolenbroek /*
41693ad767SDavid van Moolenbroek  * Unmount the file system.
42433d6423SLionel Sambuc  */
43693ad767SDavid van Moolenbroek void
fs_unmount(void)44693ad767SDavid van Moolenbroek fs_unmount(void)
45693ad767SDavid van Moolenbroek {
46433d6423SLionel Sambuc 	struct inode *root;
47433d6423SLionel Sambuc 
48433d6423SLionel Sambuc 	/* Decrease the count of the root inode. */
49433d6423SLionel Sambuc 	root = get_root_inode();
50433d6423SLionel Sambuc 
51433d6423SLionel Sambuc 	put_inode(root);
52433d6423SLionel Sambuc 
53433d6423SLionel Sambuc 	/* The system is unmounted.  Call the cleanup hook. */
54433d6423SLionel Sambuc 	if (vtreefs_hooks->cleanup_hook != NULL)
55433d6423SLionel Sambuc 		vtreefs_hooks->cleanup_hook();
56433d6423SLionel Sambuc }
57