xref: /minix/minix/fs/isofs/mount.c (revision 9f988b79)
1 #include "inc.h"
2 #include <minix/vfsif.h>
3 
4 int fs_mount(dev_t dev, unsigned int __unused flags,
5 	struct fsdriver_node *root_node, unsigned int *res_flags)
6 {
7 	int r;
8 
9 	fs_dev = dev;
10 
11 	/* Open the device the file system lives on in read only mode */
12 	if (bdev_open(fs_dev, BDEV_R_BIT) != OK)
13 		return EINVAL;
14 
15 	/* Read the superblock */
16 	r = read_vds(&v_pri, fs_dev);
17 	if (r != OK) {
18 		bdev_close(fs_dev);
19 		return r;
20 	}
21 
22 	/* Return some root inode properties */
23 	root_node->fn_ino_nr = v_pri.inode_root->i_stat.st_ino;
24 	root_node->fn_mode = v_pri.inode_root->i_stat.st_mode;
25 	root_node->fn_size = v_pri.inode_root->i_stat.st_size;
26 	root_node->fn_uid = SYS_UID; /* Always root */
27 	root_node->fn_gid = SYS_GID; /* operator */
28 	root_node->fn_dev = NO_DEV;
29 
30 	*res_flags = RES_NOFLAGS;
31 
32 	return r;
33 }
34 
35 int fs_mountpt(ino_t ino_nr)
36 {
37 	/*
38 	 * This function looks up the mount point, it checks the condition
39 	 * whether the partition can be mounted on the inode or not.
40 	 */
41 	struct inode *rip;
42 
43 	if ((rip = find_inode(ino_nr)) == NULL)
44 		return EINVAL;
45 
46 	if (rip->i_mountpoint)
47 		return EBUSY;
48 
49 	/* The inode must be a directory. */
50 	if ((rip->i_stat.st_mode & I_TYPE) != I_DIRECTORY)
51 		return ENOTDIR;
52 
53 	rip->i_mountpoint = TRUE;
54 
55 	return OK;
56 }
57 
58 void fs_unmount(void)
59 {
60 	release_vol_pri_desc(&v_pri);	/* Release the super block */
61 
62 	bdev_close(fs_dev);
63 
64 	if (check_inodes() == FALSE)
65 		printf("ISOFS: unmounting with in-use inodes!\n");
66 }
67