4 #include <minix/vfsif.h>
5 #include <minix/bdev.h>
7 static int cleanmount
= 1;
9 /*===========================================================================*
11 *===========================================================================*/
14 /* This function reads the superblock of the partition, gets the root inode
15 * and sends back the details of them. Note, that the FS process does not
16 * know the index of the vmnt object which refers to it, whenever the pathname
17 * lookup leaves a partition an ELEAVEMOUNT error is transferred back
18 * so that the VFS knows that it has to find the vnode on which this FS
19 * process' partition is mounted on.
21 struct inode
*root_ip
;
22 cp_grant_id_t label_gid
;
27 fs_dev
= (dev_t
) fs_m_in
.REQ_DEV
;
28 label_gid
= (cp_grant_id_t
) fs_m_in
.REQ_GRANT
;
29 label_len
= (size_t) fs_m_in
.REQ_PATH_LEN
;
30 readonly
= (fs_m_in
.REQ_FLAGS
& REQ_RDONLY
) ? 1 : 0;
31 isroot
= (fs_m_in
.REQ_FLAGS
& REQ_ISROOT
) ? 1 : 0;
33 if (label_len
> sizeof(fs_dev_label
))
36 r
= sys_safecopyfrom(fs_m_in
.m_source
, label_gid
, (vir_bytes
) 0,
37 (vir_bytes
) fs_dev_label
, label_len
);
39 printf("MFS %s:%d safecopyfrom failed: %d\n", __FILE__
, __LINE__
, r
);
43 /* Map the driver label for this major. */
44 bdev_driver(fs_dev
, fs_dev_label
);
46 /* Open the device the file system lives on. */
47 if (bdev_open(fs_dev
, readonly
? R_BIT
: (R_BIT
|W_BIT
) ) != OK
) {
51 /* Fill in the super block. */
52 superblock
.s_dev
= fs_dev
; /* read_super() needs to know which dev */
53 r
= read_super(&superblock
);
55 /* Is it recognized as a Minix filesystem? */
57 superblock
.s_dev
= NO_DEV
;
62 /* Remember whether we were mounted cleanly so we know what to
65 if(superblock
.s_flags
& MFSFLAG_CLEAN
)
68 /* clean check: if rw and not clean, switch to readonly */
69 if(!(superblock
.s_flags
& MFSFLAG_CLEAN
) && !readonly
) {
70 if(bdev_close(fs_dev
) != OK
)
71 panic("couldn't bdev_close after found unclean FS");
74 if (bdev_open(fs_dev
, R_BIT
) != OK
) {
75 panic("couldn't bdev_open after found unclean FS");
78 printf("MFS: WARNING: FS 0x%x unclean, mounting readonly\n", fs_dev
);
81 lmfs_set_blocksize(superblock
.s_block_size
, major(fs_dev
));
83 /* Get the root inode of the mounted file system. */
84 if( (root_ip
= get_inode(fs_dev
, ROOT_INODE
)) == NULL
) {
85 printf("MFS: couldn't get root inode\n");
86 superblock
.s_dev
= NO_DEV
;
91 if(root_ip
->i_mode
== 0) {
92 printf("%s:%d zero mode for root inode?\n", __FILE__
, __LINE__
);
94 superblock
.s_dev
= NO_DEV
;
99 superblock
.s_rd_only
= readonly
;
100 superblock
.s_is_root
= isroot
;
102 /* Root inode properties */
103 fs_m_out
.RES_INODE_NR
= root_ip
->i_num
;
104 fs_m_out
.RES_MODE
= root_ip
->i_mode
;
105 fs_m_out
.RES_FILE_SIZE_LO
= root_ip
->i_size
;
106 fs_m_out
.RES_UID
= root_ip
->i_uid
;
107 fs_m_out
.RES_GID
= root_ip
->i_gid
;
109 fs_m_out
.RES_CONREQS
= 1; /* We can handle only 1 request at a time */
112 if(!superblock
.s_rd_only
) {
113 superblock
.s_flags
&= ~MFSFLAG_CLEAN
;
114 if(write_super(&superblock
) != OK
)
115 panic("mounting: couldn't write dirty superblock");
122 /*===========================================================================*
124 *===========================================================================*/
127 /* This function looks up the mount point, it checks the condition whether
128 * the partition can be mounted on the inode or not.
130 register struct inode
*rip
;
134 /* Temporarily open the file. */
135 if( (rip
= get_inode(fs_dev
, (ino_t
) fs_m_in
.REQ_INODE_NR
)) == NULL
)
139 if(rip
->i_mountpoint
) r
= EBUSY
;
141 /* It may not be special. */
142 bits
= rip
->i_mode
& I_TYPE
;
143 if (bits
== I_BLOCK_SPECIAL
|| bits
== I_CHAR_SPECIAL
) r
= ENOTDIR
;
147 if(r
== OK
) rip
->i_mountpoint
= TRUE
;
153 /*===========================================================================*
155 *===========================================================================*/
158 /* Unmount a file system by device number. */
160 struct inode
*rip
, *root_ip
;
162 if(superblock
.s_dev
!= fs_dev
) return(EINVAL
);
164 /* See if the mounted device is busy. Only 1 inode using it should be
165 * open --the root inode-- and that inode only 1 time. */
167 for (rip
= &inode
[0]; rip
< &inode
[NR_INODES
]; rip
++)
168 if (rip
->i_count
> 0 && rip
->i_dev
== fs_dev
) count
+= rip
->i_count
;
170 if ((root_ip
= find_inode(fs_dev
, ROOT_INODE
)) == NULL
) {
171 panic("MFS: couldn't find root inode\n");
175 if (count
> 1) return(EBUSY
); /* can't umount a busy file system */
178 /* force any cached blocks out of memory */
181 /* Mark it clean if we're allowed to write _and_ it was clean originally. */
182 if(cleanmount
&& !superblock
.s_rd_only
) {
183 superblock
.s_flags
|= MFSFLAG_CLEAN
;
184 write_super(&superblock
);
187 /* Close the device the file system lives on. */
190 /* Finish off the unmount. */
191 superblock
.s_dev
= NO_DEV
;