kernel: restore setting KTS_NONE
[minix.git] / servers / iso9660fs / super.c
blob6d1381b0ccfdc4e228af764250f44e8c84ff81a1
1 /* Functions to manage the superblock of the filesystem. These functions are
2 * are called at the beginning and at the end of the server. */
4 #include "inc.h"
5 #include <string.h>
6 #include <minix/com.h>
7 #include <minix/u64.h>
8 #include <minix/bdev.h>
10 /* This function is called when the filesystem is umounted. It releases the
11 * super block. */
12 int release_v_pri(v_pri)
13 register struct iso9660_vd_pri *v_pri;
15 /* Release the root dir record */
16 release_dir_record(v_pri->dir_rec_root);
17 v_pri->count = 0;
18 return OK;
21 /* This function fullfill the super block data structure using the information
22 * contained in the stream buf. Such stream is physically read from the device
23 * . */
24 int create_v_pri(v_pri,buf,address)
25 register struct iso9660_vd_pri *v_pri;
26 register char* buf;
27 register unsigned long address;
29 struct dir_record *dir;
31 v_pri->vd_type = buf[0];
32 memcpy(v_pri->standard_id,buf + 1,sizeof(v_pri->standard_id));
33 v_pri->vd_version = buf[6];
34 memcpy(v_pri->system_id,buf + 8,sizeof(v_pri->system_id));
35 memcpy(v_pri->volume_id,buf + 40,sizeof(v_pri->volume_id));
36 memcpy(&v_pri->volume_space_size_l,buf + 80,
37 sizeof(v_pri->volume_space_size_l));
38 memcpy(&v_pri->volume_space_size_m,buf + 84,
39 sizeof(v_pri->volume_space_size_m));
40 memcpy(&v_pri->volume_set_size,buf + 120,sizeof(v_pri->volume_set_size));
41 memcpy(&v_pri->volume_sequence_number,buf + 124,
42 sizeof(v_pri->volume_sequence_number));
43 memcpy(&v_pri->logical_block_size_l,buf + 128,
44 sizeof(v_pri->logical_block_size_l));
45 memcpy(&v_pri->logical_block_size_m,buf + 130,
46 sizeof(v_pri->logical_block_size_m));
47 memcpy(&v_pri->path_table_size_l,buf + 132,
48 sizeof(v_pri->path_table_size_l));
49 memcpy(&v_pri->path_table_size_m,buf + 136,
50 sizeof(v_pri->path_table_size_m));
51 memcpy(&v_pri->loc_l_occ_path_table,buf + 140,
52 sizeof(v_pri->loc_l_occ_path_table));
53 memcpy(&v_pri->loc_opt_l_occ_path_table,buf + 144,
54 sizeof(v_pri->loc_opt_l_occ_path_table));
55 memcpy(&v_pri->loc_m_occ_path_table, buf + 148,
56 sizeof(v_pri->loc_m_occ_path_table));
57 memcpy(&v_pri->loc_opt_m_occ_path_table,buf + 152,
58 sizeof(v_pri->loc_opt_m_occ_path_table));
60 dir = get_free_dir_record();
61 if (dir == NULL) return EINVAL;
62 create_dir_record(dir,buf + 156,(u32_t)(address + 156));
63 v_pri->dir_rec_root = dir;
64 dir->d_ino_nr = ROOT_INO_NR;
66 memcpy(v_pri->volume_set_id,buf + 190,sizeof(v_pri->volume_set_id));
67 memcpy(v_pri->publisher_id,buf + 318,sizeof(v_pri->publisher_id));
68 memcpy(v_pri->data_preparer_id,buf + 446,sizeof(v_pri->data_preparer_id));
69 memcpy(v_pri->application_id,buf + 574,sizeof(v_pri->application_id));
70 memcpy(v_pri->copyright_file_id,buf + 702,sizeof(v_pri->copyright_file_id));
71 memcpy(v_pri->abstract_file_id,buf + 739,sizeof(v_pri->abstract_file_id));
72 memcpy(v_pri->bibl_file_id,buf + 776,sizeof(v_pri->bibl_file_id));
73 memcpy(v_pri->volume_cre_date,buf + 813,sizeof(v_pri->volume_cre_date));
74 memcpy(v_pri->volume_mod_date,buf + 830,sizeof(v_pri->volume_mod_date));
75 memcpy(v_pri->volume_exp_date,buf + 847,sizeof(v_pri->volume_exp_date));
76 memcpy(v_pri->volume_eff_date,buf + 864,sizeof(v_pri->volume_eff_date));
77 v_pri->file_struct_ver = buf[881];
78 return OK;
81 /* This function reads from a ISO9660 filesystem (in the device dev) the
82 * super block and saves it in v_pri. */
83 int read_vds(
84 register struct iso9660_vd_pri *v_pri,
85 register dev_t dev
88 u64_t offset;
89 int vol_ok = FALSE;
90 int r;
91 static char sbbuf[ISO9660_MIN_BLOCK_SIZE];
92 int i = 0;
94 offset = cvul64(ISO9660_SUPER_BLOCK_POSITION);
95 while (!vol_ok && i++<MAX_ATTEMPTS) {
97 /* Read the sector of the super block. */
98 r = bdev_read(dev, offset, sbbuf, ISO9660_MIN_BLOCK_SIZE, BDEV_NOFLAGS);
100 if (r != ISO9660_MIN_BLOCK_SIZE) /* Damaged sector or what? */
101 continue;
103 if ((sbbuf[0] & BYTE) == VD_PRIMARY) {
104 create_v_pri(v_pri,sbbuf,cv64ul(offset)); /* copy the buffer in the data structure. */
107 if ((sbbuf[0] & BYTE) == VD_SET_TERM)
108 /* I dont need to save anything about it */
109 vol_ok = TRUE;
111 offset = add64u(offset,ISO9660_MIN_BLOCK_SIZE);
114 if (vol_ok == FALSE)
115 return EINVAL; /* If no superblock was found... */
116 else
117 return OK; /* otherwise. */