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 super_block
*xp
;
27 struct inode
*root_ip
;
28 cp_grant_id_t label_gid
;
35 fs_dev
= fs_m_in
.REQ_DEV
;
36 label_gid
= fs_m_in
.REQ_GRANT
;
37 label_len
= fs_m_in
.REQ_PATH_LEN
;
38 readonly
= (fs_m_in
.REQ_FLAGS
& REQ_RDONLY
) ? 1 : 0;
39 isroot
= (fs_m_in
.REQ_FLAGS
& REQ_ISROOT
) ? 1 : 0;
41 if (label_len
> sizeof(fs_dev_label
))
44 r
= sys_safecopyfrom(fs_m_in
.m_source
, label_gid
, 0,
45 (vir_bytes
)fs_dev_label
, label_len
, D
);
47 printf("%s:%d fs_readsuper: safecopyfrom failed: %d\n",
48 __FILE__
, __LINE__
, r
);
52 r
= ds_retrieve_label_num(fs_dev_label
, &tasknr
);
55 printf("mfs:fs_readsuper: ds_retrieve_label_num failed for '%s': %d\n",
62 /* Map the driver endpoint for this major */
63 driver_endpoints
[(fs_dev
>> MAJOR
) & BYTE
].driver_e
= driver_e
;
64 use_getuptime2
= TRUE
; /* Should be removed with old getuptime call. */
65 vfs_slink_storage
= (char *)0xdeadbeef; /* Should be removed together
66 * with old lookup code.
69 /* Open the device the file system lives on. */
70 if (dev_open(driver_e
, fs_dev
, driver_e
,
71 readonly
? R_BIT
: (R_BIT
|W_BIT
)) != OK
) {
75 /* Fill in the super block. */
76 superblock
.s_dev
= fs_dev
; /* read_super() needs to know which dev */
77 r
= read_super(&superblock
);
79 /* Is it recognized as a Minix filesystem? */
81 superblock
.s_dev
= NO_DEV
;
82 dev_close(driver_e
, fs_dev
);
86 set_blocksize(superblock
.s_block_size
);
88 /* Get the root inode of the mounted file system. */
89 if( (root_ip
= get_inode(fs_dev
, ROOT_INODE
)) == NIL_INODE
) {
90 printf("MFS: couldn't get root inode\n");
91 superblock
.s_dev
= NO_DEV
;
92 dev_close(driver_e
, fs_dev
);
96 if(root_ip
!= NIL_INODE
&& root_ip
->i_mode
== 0) {
97 printf("%s:%d zero mode for root inode?\n", __FILE__
, __LINE__
);
99 superblock
.s_dev
= NO_DEV
;
100 dev_close(driver_e
, fs_dev
);
104 superblock
.s_rd_only
= readonly
;
105 superblock
.s_is_root
= isroot
;
107 /* Root inode properties */
108 fs_m_out
.RES_INODE_NR
= root_ip
->i_num
;
109 fs_m_out
.RES_MODE
= root_ip
->i_mode
;
110 fs_m_out
.RES_FILE_SIZE_LO
= root_ip
->i_size
;
111 fs_m_out
.RES_UID
= root_ip
->i_uid
;
112 fs_m_out
.RES_GID
= root_ip
->i_gid
;
118 /*===========================================================================*
120 *===========================================================================*/
121 PUBLIC
int fs_mountpoint()
123 /* This function looks up the mount point, it checks the condition whether
124 * the partition can be mounted on the inode or not.
126 register struct inode
*rip
;
130 /* Temporarily open the file. */
131 if( (rip
= get_inode(fs_dev
, fs_m_in
.REQ_INODE_NR
)) == NIL_INODE
)
135 if(rip
->i_mountpoint
) r
= EBUSY
;
137 /* It may not be special. */
138 bits
= rip
->i_mode
& I_TYPE
;
139 if (bits
== I_BLOCK_SPECIAL
|| bits
== I_CHAR_SPECIAL
) r
= ENOTDIR
;
143 if(r
== OK
) rip
->i_mountpoint
= TRUE
;
149 /*===========================================================================*
151 *===========================================================================*/
152 PUBLIC
int fs_unmount()
154 /* Unmount a file system by device number. */
155 struct super_block
*sp1
;
157 struct inode
*rip
, *root_ip
;
159 if(superblock
.s_dev
!= fs_dev
) return(EINVAL
);
161 /* See if the mounted device is busy. Only 1 inode using it should be
162 * open --the root inode-- and that inode only 1 time. */
164 for (rip
= &inode
[0]; rip
< &inode
[NR_INODES
]; rip
++)
165 if (rip
->i_count
> 0 && rip
->i_dev
== fs_dev
) count
+= rip
->i_count
;
167 if ((root_ip
= find_inode(fs_dev
, ROOT_INODE
)) == NIL_INODE
) {
168 printf("MFS: couldn't find root inode. Unmount failed.\n");
169 panic(__FILE__
, "MFS: couldn't find root inode", EINVAL
);
173 if (count
> 1) return(EBUSY
); /* can't umount a busy file system */
176 /* force any cached blocks out of memory */
179 /* Close the device the file system lives on. */
180 dev_close(driver_endpoints
[(fs_dev
>> MAJOR
) & BYTE
].driver_e
, fs_dev
);
182 /* Finish off the unmount. */
183 superblock
.s_dev
= NO_DEV
;