panic() cleanup.
[minix.git] / servers / iso9660fs / mount.c
blob4367b71478c8a134b16257c6a39ec911bac1bd73
1 #include "inc.h"
2 #include <string.h>
3 #include <minix/com.h>
4 #include <minix/vfsif.h>
5 #include <minix/ds.h>
6 #include "const.h"
7 #include "glo.h"
10 /*===========================================================================*
11 * fs_readsuper *
12 *===========================================================================*/
13 PUBLIC int fs_readsuper() {
15 cp_grant_id_t label_gid;
16 size_t label_len;
17 int r = OK;
18 unsigned long tasknr;
19 endpoint_t driver_e;
20 int readonly;
22 fs_dev = fs_m_in.REQ_DEV;
23 label_gid = fs_m_in.REQ_GRANT;
24 label_len = fs_m_in.REQ_PATH_LEN;
25 readonly = 1; /* Always mount devices read only. */
27 if (label_len > sizeof(fs_dev_label))
28 return(EINVAL);
30 r = sys_safecopyfrom(fs_m_in.m_source, label_gid, 0, (vir_bytes)fs_dev_label,
31 label_len, D);
32 if (r != OK) {
33 printf("ISOFS %s:%d safecopyfrom failed: %d\n", __FILE__, __LINE__, r);
34 return(EINVAL);
37 r = ds_retrieve_label_num(fs_dev_label, &tasknr);
38 if (r != OK) {
39 printf("ISOFS %s:%d ds_retrieve_label_num failed for '%s': %d\n",
40 __FILE__, __LINE__, fs_dev_label, r);
41 return(EINVAL);
44 driver_e = tasknr;
46 /* Map the driver endpoint for this major */
47 driver_endpoints[(fs_dev >> MAJOR) & BYTE].driver_e = driver_e;
49 /* Open the device the file system lives on */
50 if (dev_open(driver_e, fs_dev, driver_e,
51 readonly ? R_BIT : (R_BIT|W_BIT)) != OK) {
52 return(EINVAL);
55 /* Read the superblock */
56 r = read_vds(&v_pri, fs_dev);
57 if (r != OK)
58 return(r);
60 /* Return some root inode properties */
61 fs_m_out.RES_INODE_NR = ID_DIR_RECORD(v_pri.dir_rec_root);
62 fs_m_out.RES_MODE = v_pri.dir_rec_root->d_mode;
63 fs_m_out.RES_FILE_SIZE_LO = v_pri.dir_rec_root->d_file_size;
64 fs_m_out.RES_UID = SYS_UID; /* Always root */
65 fs_m_out.RES_GID = SYS_GID; /* operator */
67 return(r);
71 /*===========================================================================*
72 * fs_mountpoint *
73 *===========================================================================*/
74 PUBLIC int fs_mountpoint() {
75 /* This function looks up the mount point, it checks the condition whether
76 * the partition can be mounted on the inode or not.
79 register struct dir_record *rip;
80 int r = OK;
81 mode_t bits;
83 /* Temporarily open the file. */
84 if ((rip = get_dir_record(fs_m_in.REQ_INODE_NR)) == NULL)
85 return(EINVAL);
87 if (rip->d_mountpoint)
88 r = EBUSY;
90 /* If the inode is not a dir returns error */
91 if ((rip->d_mode & I_TYPE) != I_DIRECTORY)
92 r = ENOTDIR;
94 release_dir_record(rip);
96 if (r == OK)
97 rip->d_mountpoint = TRUE;
99 return(r);
103 /*===========================================================================*
104 * fs_unmount *
105 *===========================================================================*/
106 PUBLIC int fs_unmount(void) {
107 release_v_pri(&v_pri); /* Release the super block */
108 dev_close(driver_endpoints[(fs_dev >> MAJOR) & BYTE].driver_e, fs_dev);
109 return(OK);