Read Volume Descriptors and identify RR extensions, if any.
parent
e18f5d8898
commit
263770ab4f
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Little program to output the contents of an iso image.
|
||||
* Note that this is not an API example, but a little program for test
|
||||
* purposes.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "messages.h"
|
||||
#include "libisofs.h"
|
||||
#include "fs_image.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int result;
|
||||
IsoImageFilesystem *fs;
|
||||
IsoDataSource *src;
|
||||
struct iso_read_opts opts = {
|
||||
0, /* block */
|
||||
0, /* norock */
|
||||
0, /* nojoliet */
|
||||
0, /* preferjoliet */
|
||||
0, /* uid; */
|
||||
0, /* gid; */
|
||||
0, /* mode */
|
||||
NULL, /* messenger */
|
||||
"UTF-8" /* input_charset */
|
||||
};
|
||||
|
||||
if (argc != 2) {
|
||||
printf ("You need to specify a valid path\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
result = libiso_msgs_new(&opts.messenger, 0);
|
||||
if (result <= 0) {
|
||||
printf ("Can't create messenger\n");
|
||||
return 1;
|
||||
}
|
||||
libiso_msgs_set_severities(opts.messenger, LIBISO_MSGS_SEV_NEVER,
|
||||
LIBISO_MSGS_SEV_ALL, "", 0);
|
||||
|
||||
result = iso_data_source_new_from_file(argv[1], &src);
|
||||
if (result < 0) {
|
||||
printf ("Error creating data source\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
result = iso_image_filesystem_new(src, &opts, &fs);
|
||||
if (result < 0) {
|
||||
printf ("Error creating filesystem\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
iso_filesystem_unref((IsoFilesystem*)fs);
|
||||
iso_data_source_unref(src);
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright (c) 2007 Vreixo Formoso
|
||||
*
|
||||
* This file is part of the libisofs project; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation. See COPYING file for details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains functions related to the reading of SUSP and
|
||||
* Rock Ridge extensions on an ECMA-119 image.
|
||||
*/
|
||||
|
||||
#include "libisofs.h"
|
||||
#include "ecma119.h"
|
||||
#include "util.h"
|
||||
#include "rockridge.h"
|
||||
#include "error.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct susp_iterator
|
||||
{
|
||||
uint8_t* base;
|
||||
int pos;
|
||||
int size;
|
||||
IsoDataSource *src;
|
||||
IsoMessenger *msgr;
|
||||
|
||||
/* block and offset for next continuation area */
|
||||
uint32_t ce_block;
|
||||
uint32_t ce_off;
|
||||
|
||||
/** Length of the next continuation area, 0 if no more CA are specified */
|
||||
uint32_t ce_len;
|
||||
|
||||
uint8_t *buffer; /*< If there are continuation areas */
|
||||
};
|
||||
|
||||
SuspIterator*
|
||||
susp_iter_new(IsoDataSource *src, struct ecma119_dir_record *record,
|
||||
uint8_t len_skp, IsoMessenger *msgr)
|
||||
{
|
||||
int pad = (record->len_fi[0] + 1) % 2;
|
||||
struct susp_iterator *iter = malloc(sizeof(struct susp_iterator));
|
||||
if (iter == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
iter->base = record->file_id + record->len_fi[0] + pad;
|
||||
iter->pos = len_skp; /* 0 in most cases */
|
||||
iter->size = record->len_dr[0] - record->len_fi[0] - 33 - pad;
|
||||
iter->src = src;
|
||||
iter->msgr = msgr;
|
||||
|
||||
iter->ce_len = 0;
|
||||
iter->buffer = NULL;
|
||||
|
||||
return iter;
|
||||
}
|
||||
|
||||
int susp_iter_next(SuspIterator *iter, struct susp_sys_user_entry **sue)
|
||||
{
|
||||
struct susp_sys_user_entry *entry;
|
||||
|
||||
entry = (struct susp_sys_user_entry*)(iter->base + iter->pos);
|
||||
|
||||
if ( (iter->pos + 4 > iter->size) || (SUSP_SIG(entry, 'S', 'T'))) {
|
||||
|
||||
/*
|
||||
* End of the System Use Area or Continuation Area.
|
||||
* Note that ST is not needed when the space left is less than 4.
|
||||
* (IEEE 1281, SUSP. section 4)
|
||||
*/
|
||||
if (iter->ce_len) {
|
||||
uint32_t block;
|
||||
int nblocks;
|
||||
|
||||
/* A CE has found, there is another continuation area */
|
||||
nblocks = div_up(iter->ce_off + iter->ce_len, BLOCK_SIZE);
|
||||
iter->buffer = realloc(iter->buffer, nblocks * BLOCK_SIZE);
|
||||
|
||||
/* read all blocks needed to cache the full CE */
|
||||
for (block = 0; block < nblocks; ++block) {
|
||||
int ret;
|
||||
ret = iter->src->read_block(iter->src, iter->ce_block + block,
|
||||
iter->buffer + block * BLOCK_SIZE);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
iter->base = iter->buffer + iter->ce_off;
|
||||
iter->pos = 0;
|
||||
iter->size = iter->ce_len;
|
||||
iter->ce_len = 0;
|
||||
entry = (struct susp_sys_user_entry*)iter->base;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (entry->len_sue[0] == 0) {
|
||||
/* a wrong image with this lead us to a infinity loop */
|
||||
iso_msg_sorry(iter->msgr, LIBISO_RR_ERROR,
|
||||
"Damaged RR/SUSP information.");
|
||||
return ISO_WRONG_RR;
|
||||
}
|
||||
|
||||
iter->pos += entry->len_sue[0];
|
||||
|
||||
if (SUSP_SIG(entry, 'C', 'E')) {
|
||||
/* Continuation entry */
|
||||
if (iter->ce_len) {
|
||||
iso_msg_sorry(iter->msgr, LIBISO_RR_ERROR, "More than one CE "
|
||||
"System user entry has found in a single System Use field or "
|
||||
"continuation area. This breaks SUSP standard and it's not "
|
||||
"supported. Ignoring last CE. Maybe the image is damaged.");
|
||||
} else {
|
||||
iter->ce_block = iso_read_bb(entry->data.CE.block, 4, NULL);
|
||||
iter->ce_off = iso_read_bb(entry->data.CE.offset, 4, NULL);
|
||||
iter->ce_len = iso_read_bb(entry->data.CE.len, 4, NULL);
|
||||
}
|
||||
|
||||
/* we don't want to return CE entry to the user */
|
||||
return susp_iter_next(iter, sue);
|
||||
} else if (SUSP_SIG(entry, 'P', 'D')) {
|
||||
/* skip padding */
|
||||
return susp_iter_next(iter, sue);
|
||||
}
|
||||
|
||||
*sue = entry;
|
||||
return ISO_SUCCESS;
|
||||
}
|
||||
|
||||
void susp_iter_free(SuspIterator *iter)
|
||||
{
|
||||
free(iter->buffer);
|
||||
free(iter);
|
||||
}
|
Loading…
Reference in New Issue