11 #include <minix/vfsif.h>
14 /*===========================================================================*
16 *===========================================================================*/
17 PUBLIC
int fs_readsuper()
19 /* This function reads the superblock of the partition, gets the root inode
20 * and sends back the details of them. Note, that the FS process does not
21 * know the index of the vmnt object which refers to it, whenever the pathname
22 * lookup leaves a partition an ELEAVEMOUNT error is transferred back
23 * so that the VFS knows that it has to find the vnode on which this FS
24 * process' partition is mounted on.
26 struct inode
*root_ip
;
27 cp_grant_id_t label_gid
;
33 fs_dev
= fs_m_in
.REQ_DEV
;
34 label_gid
= fs_m_in
.REQ_GRANT
;
35 label_len
= fs_m_in
.REQ_PATH_LEN
;
36 readonly
= (fs_m_in
.REQ_FLAGS
& REQ_RDONLY
) ? 1 : 0;
37 isroot
= (fs_m_in
.REQ_FLAGS
& REQ_ISROOT
) ? 1 : 0;
39 if (label_len
> sizeof(fs_dev_label
))
42 r
= sys_safecopyfrom(fs_m_in
.m_source
, label_gid
, 0,
43 (vir_bytes
)fs_dev_label
, label_len
, D
);
45 printf("%s:%d fs_readsuper: safecopyfrom failed: %d\n",
46 __FILE__
, __LINE__
, r
);
50 r
= ds_retrieve_label_endpt(fs_dev_label
, &driver_e
);
53 printf("mfs:fs_readsuper: ds_retrieve_label_endpt failed for '%s': %d\n",
58 /* Map the driver endpoint for this major */
59 driver_endpoints
[(fs_dev
>> MAJOR
) & BYTE
].driver_e
= driver_e
;
60 use_getuptime2
= TRUE
; /* Should be removed with old getuptime call. */
61 vfs_slink_storage
= (char *)0xdeadbeef; /* Should be removed together
62 * with old lookup code.
65 /* Open the device the file system lives on. */
66 if (dev_open(driver_e
, fs_dev
, driver_e
,
67 readonly
? R_BIT
: (R_BIT
|W_BIT
)) != OK
) {
71 /* Fill in the super block. */
72 superblock
.s_dev
= fs_dev
; /* read_super() needs to know which dev */
73 r
= read_super(&superblock
);
75 /* Is it recognized as a Minix filesystem? */
77 superblock
.s_dev
= NO_DEV
;
78 dev_close(driver_e
, fs_dev
);
82 set_blocksize(superblock
.s_block_size
);
84 /* Get the root inode of the mounted file system. */
85 if( (root_ip
= get_inode(fs_dev
, ROOT_INODE
)) == NIL_INODE
) {
86 printf("MFS: couldn't get root inode\n");
87 superblock
.s_dev
= NO_DEV
;
88 dev_close(driver_e
, fs_dev
);
92 if(root_ip
!= NIL_INODE
&& root_ip
->i_mode
== 0) {
93 printf("%s:%d zero mode for root inode?\n", __FILE__
, __LINE__
);
95 superblock
.s_dev
= NO_DEV
;
96 dev_close(driver_e
, fs_dev
);
100 superblock
.s_rd_only
= readonly
;
101 superblock
.s_is_root
= isroot
;
103 /* Root inode properties */
104 fs_m_out
.RES_INODE_NR
= root_ip
->i_num
;
105 fs_m_out
.RES_MODE
= root_ip
->i_mode
;
106 fs_m_out
.RES_FILE_SIZE_LO
= root_ip
->i_size
;
107 fs_m_out
.RES_UID
= root_ip
->i_uid
;
108 fs_m_out
.RES_GID
= root_ip
->i_gid
;
114 /*===========================================================================*
116 *===========================================================================*/
117 PUBLIC
int fs_mountpoint()
119 /* This function looks up the mount point, it checks the condition whether
120 * the partition can be mounted on the inode or not.
122 register struct inode
*rip
;
126 /* Temporarily open the file. */
127 if( (rip
= get_inode(fs_dev
, fs_m_in
.REQ_INODE_NR
)) == NIL_INODE
)
131 if(rip
->i_mountpoint
) r
= EBUSY
;
133 /* It may not be special. */
134 bits
= rip
->i_mode
& I_TYPE
;
135 if (bits
== I_BLOCK_SPECIAL
|| bits
== I_CHAR_SPECIAL
) r
= ENOTDIR
;
139 if(r
== OK
) rip
->i_mountpoint
= TRUE
;
145 /*===========================================================================*
147 *===========================================================================*/
148 PUBLIC
int fs_unmount()
150 /* Unmount a file system by device number. */
152 struct inode
*rip
, *root_ip
;
154 if(superblock
.s_dev
!= fs_dev
) return(EINVAL
);
156 /* See if the mounted device is busy. Only 1 inode using it should be
157 * open --the root inode-- and that inode only 1 time. */
159 for (rip
= &inode
[0]; rip
< &inode
[NR_INODES
]; rip
++)
160 if (rip
->i_count
> 0 && rip
->i_dev
== fs_dev
) count
+= rip
->i_count
;
162 if ((root_ip
= find_inode(fs_dev
, ROOT_INODE
)) == NIL_INODE
) {
163 printf("MFS: couldn't find root inode. Unmount failed.\n");
164 panic("MFS: couldn't find root inode: %d", EINVAL
);
168 if (count
> 1) return(EBUSY
); /* can't umount a busy file system */
171 /* force any cached blocks out of memory */
174 /* Close the device the file system lives on. */
175 dev_close(driver_endpoints
[(fs_dev
>> MAJOR
) & BYTE
].driver_e
, fs_dev
);
177 /* Finish off the unmount. */
178 superblock
.s_dev
= NO_DEV
;