2009-10-01 16:00:27 +02:00
|
|
|
/* Functions to manage the superblock of the filesystem. These functions are
|
|
|
|
* are called at the beginning and at the end of the server. */
|
|
|
|
|
|
|
|
#include "inc.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <minix/com.h>
|
|
|
|
#include <minix/u64.h>
|
2011-11-09 14:29:12 +01:00
|
|
|
#include <minix/bdev.h>
|
2009-10-01 16:00:27 +02:00
|
|
|
|
|
|
|
/* This function is called when the filesystem is umounted. It releases the
|
|
|
|
* super block. */
|
2012-03-25 20:25:53 +02:00
|
|
|
int release_v_pri(v_pri)
|
2009-10-01 16:00:27 +02:00
|
|
|
register struct iso9660_vd_pri *v_pri;
|
|
|
|
{
|
|
|
|
/* Release the root dir record */
|
|
|
|
release_dir_record(v_pri->dir_rec_root);
|
|
|
|
v_pri->count = 0;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function fullfill the super block data structure using the information
|
|
|
|
* contained in the stream buf. Such stream is physically read from the device
|
|
|
|
* . */
|
2012-03-25 20:25:53 +02:00
|
|
|
int create_v_pri(v_pri,buf,address)
|
2009-10-01 16:00:27 +02:00
|
|
|
register struct iso9660_vd_pri *v_pri;
|
|
|
|
register char* buf;
|
|
|
|
register unsigned long address;
|
|
|
|
{
|
|
|
|
struct dir_record *dir;
|
|
|
|
|
|
|
|
v_pri->vd_type = buf[0];
|
|
|
|
memcpy(v_pri->standard_id,buf + 1,sizeof(v_pri->standard_id));
|
|
|
|
v_pri->vd_version = buf[6];
|
|
|
|
memcpy(v_pri->system_id,buf + 8,sizeof(v_pri->system_id));
|
|
|
|
memcpy(v_pri->volume_id,buf + 40,sizeof(v_pri->volume_id));
|
|
|
|
memcpy(&v_pri->volume_space_size_l,buf + 80,
|
|
|
|
sizeof(v_pri->volume_space_size_l));
|
|
|
|
memcpy(&v_pri->volume_space_size_m,buf + 84,
|
|
|
|
sizeof(v_pri->volume_space_size_m));
|
|
|
|
memcpy(&v_pri->volume_set_size,buf + 120,sizeof(v_pri->volume_set_size));
|
|
|
|
memcpy(&v_pri->volume_sequence_number,buf + 124,
|
|
|
|
sizeof(v_pri->volume_sequence_number));
|
|
|
|
memcpy(&v_pri->logical_block_size_l,buf + 128,
|
|
|
|
sizeof(v_pri->logical_block_size_l));
|
|
|
|
memcpy(&v_pri->logical_block_size_m,buf + 130,
|
|
|
|
sizeof(v_pri->logical_block_size_m));
|
|
|
|
memcpy(&v_pri->path_table_size_l,buf + 132,
|
|
|
|
sizeof(v_pri->path_table_size_l));
|
|
|
|
memcpy(&v_pri->path_table_size_m,buf + 136,
|
|
|
|
sizeof(v_pri->path_table_size_m));
|
|
|
|
memcpy(&v_pri->loc_l_occ_path_table,buf + 140,
|
|
|
|
sizeof(v_pri->loc_l_occ_path_table));
|
|
|
|
memcpy(&v_pri->loc_opt_l_occ_path_table,buf + 144,
|
|
|
|
sizeof(v_pri->loc_opt_l_occ_path_table));
|
|
|
|
memcpy(&v_pri->loc_m_occ_path_table, buf + 148,
|
|
|
|
sizeof(v_pri->loc_m_occ_path_table));
|
|
|
|
memcpy(&v_pri->loc_opt_m_occ_path_table,buf + 152,
|
|
|
|
sizeof(v_pri->loc_opt_m_occ_path_table));
|
|
|
|
|
|
|
|
dir = get_free_dir_record();
|
|
|
|
if (dir == NULL) return EINVAL;
|
|
|
|
create_dir_record(dir,buf + 156,(u32_t)(address + 156));
|
|
|
|
v_pri->dir_rec_root = dir;
|
|
|
|
dir->d_ino_nr = ROOT_INO_NR;
|
|
|
|
|
|
|
|
memcpy(v_pri->volume_set_id,buf + 190,sizeof(v_pri->volume_set_id));
|
|
|
|
memcpy(v_pri->publisher_id,buf + 318,sizeof(v_pri->publisher_id));
|
|
|
|
memcpy(v_pri->data_preparer_id,buf + 446,sizeof(v_pri->data_preparer_id));
|
|
|
|
memcpy(v_pri->application_id,buf + 574,sizeof(v_pri->application_id));
|
|
|
|
memcpy(v_pri->copyright_file_id,buf + 702,sizeof(v_pri->copyright_file_id));
|
|
|
|
memcpy(v_pri->abstract_file_id,buf + 739,sizeof(v_pri->abstract_file_id));
|
|
|
|
memcpy(v_pri->bibl_file_id,buf + 776,sizeof(v_pri->bibl_file_id));
|
|
|
|
memcpy(v_pri->volume_cre_date,buf + 813,sizeof(v_pri->volume_cre_date));
|
|
|
|
memcpy(v_pri->volume_mod_date,buf + 830,sizeof(v_pri->volume_mod_date));
|
|
|
|
memcpy(v_pri->volume_exp_date,buf + 847,sizeof(v_pri->volume_exp_date));
|
|
|
|
memcpy(v_pri->volume_eff_date,buf + 864,sizeof(v_pri->volume_eff_date));
|
|
|
|
v_pri->file_struct_ver = buf[881];
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function reads from a ISO9660 filesystem (in the device dev) the
|
|
|
|
* super block and saves it in v_pri. */
|
2012-03-25 20:25:53 +02:00
|
|
|
int read_vds(
|
2010-04-13 12:58:41 +02:00
|
|
|
register struct iso9660_vd_pri *v_pri,
|
|
|
|
register dev_t dev
|
|
|
|
)
|
2009-10-01 16:00:27 +02:00
|
|
|
{
|
|
|
|
u64_t offset;
|
|
|
|
int vol_ok = FALSE;
|
|
|
|
int r;
|
|
|
|
static char sbbuf[ISO9660_MIN_BLOCK_SIZE];
|
|
|
|
int i = 0;
|
|
|
|
|
2013-06-17 10:31:12 +02:00
|
|
|
offset = ((u64_t)(ISO9660_SUPER_BLOCK_POSITION));
|
2009-10-01 16:00:27 +02:00
|
|
|
while (!vol_ok && i++<MAX_ATTEMPTS) {
|
|
|
|
|
|
|
|
/* Read the sector of the super block. */
|
2011-11-09 14:29:12 +01:00
|
|
|
r = bdev_read(dev, offset, sbbuf, ISO9660_MIN_BLOCK_SIZE, BDEV_NOFLAGS);
|
2009-10-01 16:00:27 +02:00
|
|
|
|
|
|
|
if (r != ISO9660_MIN_BLOCK_SIZE) /* Damaged sector or what? */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((sbbuf[0] & BYTE) == VD_PRIMARY) {
|
2013-06-17 10:31:12 +02:00
|
|
|
create_v_pri(v_pri,sbbuf,offset); /* copy the buffer in the data structure. */
|
2009-10-01 16:00:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((sbbuf[0] & BYTE) == VD_SET_TERM)
|
|
|
|
/* I dont need to save anything about it */
|
|
|
|
vol_ok = TRUE;
|
|
|
|
|
|
|
|
offset = add64u(offset,ISO9660_MIN_BLOCK_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vol_ok == FALSE)
|
|
|
|
return EINVAL; /* If no superblock was found... */
|
|
|
|
else
|
|
|
|
return OK; /* otherwise. */
|
|
|
|
}
|