2 * Functions to manage the superblock of the filesystem. These functions are
3 * are called at the beginning and at the end of the server.
10 #include <minix/bdev.h>
12 int release_vol_pri_desc(struct iso9660_vol_pri_desc
*vol_pri
)
14 /* Release the root dir root. */
15 if (vol_pri
->i_count
> 0) {
16 put_inode(vol_pri
->inode_root
);
17 vol_pri
->inode_root
= NULL
;
24 static int create_vol_pri_desc(struct iso9660_vol_pri_desc
*vol_pri
, char *buf
)
27 * This function fullfill the super block data structure using the
28 * information contained in the buffer.
30 struct iso9660_dir_record
*root_record
;
31 struct inode_dir_entry dir_entry
;
32 struct dir_extent extent
;
33 size_t dummy_offset
= 0;
35 if (vol_pri
->i_count
> 0)
36 release_vol_pri_desc(vol_pri
);
38 memcpy(vol_pri
, buf
, 2048);
40 /* Check various fields for consistency. */
41 if ((memcmp(vol_pri
->standard_id
, "CD001",
42 ISO9660_SIZE_STANDARD_ID
) != 0)
43 || (vol_pri
->vd_version
!= 1)
44 || (vol_pri
->logical_block_size_l
< 2048))
47 lmfs_set_blocksize(vol_pri
->logical_block_size_l
);
48 lmfs_set_blockusage(vol_pri
->volume_space_size_l
,
49 vol_pri
->volume_space_size_l
);
51 /* Read root directory record. */
52 root_record
= (struct iso9660_dir_record
*)vol_pri
->root_directory
;
55 root_record
->loc_extent_l
+ root_record
->ext_attr_rec_length
;
57 root_record
->data_length_l
/ vol_pri
->logical_block_size_l
;
60 if (root_record
->data_length_l
% vol_pri
->logical_block_size_l
)
63 if (read_inode(&dir_entry
, &extent
, &dummy_offset
) != OK
) {
67 dir_entry
.i_node
->i_count
= 1;
69 vol_pri
->inode_root
= dir_entry
.i_node
;
75 int read_vds(struct iso9660_vol_pri_desc
*vol_pri
, dev_t dev
)
78 * This function reads from a ISO9660 filesystem (in the device dev)
79 * the super block and saves it in vol_pri.
82 int vol_ok
= FALSE
, vol_pri_flag
= FALSE
;
84 static char sbbuf
[ISO9660_MIN_BLOCK_SIZE
];
87 for(offset
= ISO9660_SUPER_BLOCK_POSITION
;
88 !vol_ok
&& i
++ < MAX_ATTEMPTS
;
89 offset
+= ISO9660_MIN_BLOCK_SIZE
) {
90 /* Read the sector of the super block. */
91 r
= bdev_read(dev
, offset
, sbbuf
, ISO9660_MIN_BLOCK_SIZE
,
94 if (r
!= ISO9660_MIN_BLOCK_SIZE
) {
95 /* Damaged sector or what? */
99 if ((sbbuf
[0] & BYTE
) == VD_PRIMARY
) {
100 /* Free already parsed descriptor, if any. */
101 if (vol_pri_flag
== TRUE
) {
102 release_vol_pri_desc(vol_pri
);
103 vol_pri_flag
= FALSE
;
105 /* Copy the buffer in the data structure. */
106 if (create_vol_pri_desc(vol_pri
, sbbuf
) == OK
) {
111 if ((sbbuf
[0] & BYTE
) == VD_SET_TERM
) {
112 /* I dont need to save anything about it */
117 if (vol_ok
== FALSE
|| vol_pri_flag
== FALSE
)
118 return EINVAL
; /* If no superblock was found... */
120 return OK
; /* otherwise. */