For API stablility reasons, make iso_read_opts private.

This commit is contained in:
Vreixo Formoso 2008-01-26 14:00:46 +01:00
parent 74c82d181b
commit 29058378fd
7 changed files with 285 additions and 115 deletions

View File

@ -24,17 +24,7 @@ int main(int argc, char **argv)
IsoFileSource *file; IsoFileSource *file;
struct stat info; struct stat info;
IsoDataSource *src; IsoDataSource *src;
struct iso_read_opts opts = { IsoReadOpts *opts;
0, /* block */
0, /* norock */
0, /* nojoliet */
0, /* noiso1999 */
0, /* preferjoliet */
0, /* uid; */
0, /* gid; */
0, /* mode */
"UTF-8" /* input_charset */
};
if (argc != 3) { if (argc != 3) {
fprintf(stderr, "Usage: isocat /path/to/image /path/to/file\n"); fprintf(stderr, "Usage: isocat /path/to/image /path/to/file\n");
@ -53,11 +43,17 @@ int main(int argc, char **argv)
return 1; return 1;
} }
res = iso_image_filesystem_new(src, &opts, 1, &fs); res = iso_read_opts_new(&opts, 0);
if (res < 0) {
fprintf(stderr, "Error creating read options\n");
return 1;
}
res = iso_image_filesystem_new(src, opts, 1, &fs);
if (res < 0) { if (res < 0) {
fprintf(stderr, "Error creating filesystem\n"); fprintf(stderr, "Error creating filesystem\n");
return 1; return 1;
} }
iso_read_opts_free(opts);
res = fs->get_by_path(fs, argv[2], &file); res = fs->get_by_path(fs, argv[2], &file);
if (res < 0) { if (res < 0) {

View File

@ -34,17 +34,7 @@ int main(int argc, char **argv)
int ret = 0; int ret = 0;
struct iso_read_image_features features; struct iso_read_image_features features;
uint32_t ms_block; uint32_t ms_block;
struct iso_read_opts ropts = { IsoReadOpts *ropts;
0, /* block */
0, /* norock */
0, /* nojoliet */
0, /* noiso1999 */
0, /* preferjoliet */
0, /* uid; */
0, /* gid; */
0, /* mode */
"UTF-8" /* input_charset */
};
if (argc < 3) { if (argc < 3) {
usage(argv); usage(argv);
@ -106,13 +96,18 @@ int main(int argc, char **argv)
} }
/* import previous image */ /* import previous image */
ropts.block = 0; /* image always start on first block */ ret = iso_read_opts_new(&ropts, 0);
result = iso_image_import(image, src, &ropts, &features); if (ret < 0) {
fprintf(stderr, "Error creating read options\n");
return 1;
}
result = iso_image_import(image, src, ropts, &features);
iso_data_source_unref(src); iso_data_source_unref(src);
if (result < 0) { if (result < 0) {
printf ("Error importing previous session %d\n", result); printf ("Error importing previous session %d\n", result);
return 1; return 1;
} }
iso_read_opts_free(ropts);
/* add new dir */ /* add new dir */
result = iso_tree_add_dir_rec(image, iso_image_get_root(image), argv[2]); result = iso_tree_add_dir_rec(image, iso_image_get_root(image), argv[2]);

View File

@ -28,17 +28,7 @@ int main(int argc, char **argv)
unsigned char buf[2048]; unsigned char buf[2048];
FILE *fd; FILE *fd;
IsoWriteOpts *opts; IsoWriteOpts *opts;
struct iso_read_opts ropts = { IsoReadOpts *ropts;
0, /* block */
0, /* norock */
0, /* nojoliet */
0, /* noiso1999 */
0, /* preferjoliet */
0, /* uid; */
0, /* gid; */
0, /* mode */
"UTF-8" /* input_charset */
};
if (argc < 4) { if (argc < 4) {
usage(argv); usage(argv);
@ -70,7 +60,13 @@ int main(int argc, char **argv)
iso_tree_set_ignore_hidden(image, 0); iso_tree_set_ignore_hidden(image, 0);
/* import previous image */ /* import previous image */
result = iso_image_import(image, src, &ropts, NULL); result = iso_read_opts_new(&ropts, 0);
if (result < 0) {
fprintf(stderr, "Error creating read options\n");
return 1;
}
result = iso_image_import(image, src, ropts, NULL);
iso_read_opts_free(ropts);
iso_data_source_unref(src); iso_data_source_unref(src);
if (result < 0) { if (result < 0) {
printf ("Error importing previous session %d\n", result); printf ("Error importing previous session %d\n", result);

View File

@ -28,18 +28,8 @@ int main(int argc, char **argv)
unsigned char buf[2048]; unsigned char buf[2048];
FILE *fd; FILE *fd;
IsoWriteOpts *opts; IsoWriteOpts *opts;
IsoReadOpts *ropts;
uint32_t ms_block; uint32_t ms_block;
struct iso_read_opts ropts = {
0, /* block */
0, /* norock */
0, /* nojoliet */
0, /* noiso1999 */
0, /* preferjoliet */
0, /* uid; */
0, /* gid; */
0, /* mode */
"UTF-8" /* input_charset */
};
if (argc < 6) { if (argc < 6) {
usage(argv); usage(argv);
@ -71,8 +61,14 @@ int main(int argc, char **argv)
iso_tree_set_ignore_hidden(image, 0); iso_tree_set_ignore_hidden(image, 0);
/* import previous image */ /* import previous image */
ropts.block = atoi(argv[1]); result = iso_read_opts_new(&ropts, 0);
result = iso_image_import(image, src, &ropts, NULL); if (result < 0) {
fprintf(stderr, "Error creating read options\n");
return 1;
}
iso_read_opts_set_start_block(ropts, atoi(argv[1]));
result = iso_image_import(image, src, ropts, NULL);
iso_read_opts_free(ropts);
iso_data_source_unref(src); iso_data_source_unref(src);
if (result < 0) { if (result < 0) {
printf ("Error importing previous session %d\n", result); printf ("Error importing previous session %d\n", result);

View File

@ -107,17 +107,7 @@ int main(int argc, char **argv)
IsoImageFilesystem *fs; IsoImageFilesystem *fs;
IsoDataSource *src; IsoDataSource *src;
IsoFileSource *root; IsoFileSource *root;
struct iso_read_opts opts = { IsoReadOpts *ropts;
0, /* block */
0, /* norock */
0, /* nojoliet */
0, /* noiso1999 */
0, /* preferjoliet */
0, /* uid; */
0, /* gid; */
0444, /* mode */
NULL /* input_charset */
};
if (argc != 2) { if (argc != 2) {
printf ("You need to specify a valid path\n"); printf ("You need to specify a valid path\n");
@ -133,7 +123,13 @@ int main(int argc, char **argv)
return 1; return 1;
} }
result = iso_image_filesystem_new(src, &opts, 1, &fs); result = iso_read_opts_new(&ropts, 0);
if (result < 0) {
fprintf(stderr, "Error creating read options\n");
return 1;
}
result = iso_image_filesystem_new(src, ropts, 1, &fs);
iso_read_opts_free(ropts);
if (result < 0) { if (result < 0) {
printf ("Error creating filesystem\n"); printf ("Error creating filesystem\n");
return 1; return 1;

View File

@ -27,6 +27,56 @@
#include <limits.h> #include <limits.h>
/**
* Options for image reading.
* There are four kind of options:
* - Related to multisession support.
* In most cases, an image begins at LBA 0 of the data source. However,
* in multisession discs, the later image begins in the last session on
* disc. The block option can be used to specify the start of that last
* session.
* - Related to the tree that will be read.
* As default, when Rock Ridge extensions are present in the image, that
* will be used to get the tree. If RR extensions are not present, libisofs
* will use the Joliet extensions if available. Finally, the plain ISO-9660
* tree is used if neither RR nor Joliet extensions are available. With
* norock, nojoliet, and preferjoliet options, you can change this
* default behavior.
* - Related to default POSIX attributes.
* When Rock Ridege extensions are not used, libisofs can't figure out what
* are the the permissions, uid or gid for the files. You should supply
* default values for that.
*/
struct iso_read_opts
{
/**
* Block where the image begins, usually 0, can be different on a
* multisession disc.
*/
uint32_t block;
unsigned int norock : 1; /*< Do not read Rock Ridge extensions */
unsigned int nojoliet : 1; /*< Do not read Joliet extensions */
unsigned int noiso1999 : 1; /*< Do not read ISO 9660:1999 enhanced tree */
/**
* When both Joliet and RR extensions are present, the RR tree is used.
* If you prefer using Joliet, set this to 1.
*/
unsigned int preferjoliet : 1;
uid_t uid; /**< Default uid when no RR */
gid_t gid; /**< Default uid when no RR */
mode_t mode; /**< Default mode when no RR (only permissions) */
/* TODO #00023 : let different default file and dir mode for iso reading */
/* TODO #00024 : option to convert names to lower case for iso reading */
/**
* Input charset for RR file names. NULL to use default locale charset.
*/
char *input_charset;
};
static int ifs_fs_open(IsoImageFilesystem *fs); static int ifs_fs_open(IsoImageFilesystem *fs);
static int ifs_fs_close(IsoImageFilesystem *fs); static int ifs_fs_close(IsoImageFilesystem *fs);
static int iso_file_source_new_ifs(IsoImageFilesystem *fs, static int iso_file_source_new_ifs(IsoImageFilesystem *fs,
@ -2381,3 +2431,115 @@ const char *iso_image_fs_get_biblio_file_id(IsoImageFilesystem *fs)
_ImageFsData *data = (_ImageFsData*) fs->data; _ImageFsData *data = (_ImageFsData*) fs->data;
return data->biblio_file_id; return data->biblio_file_id;
} }
int iso_read_opts_new(IsoReadOpts **opts, int profile)
{
IsoReadOpts *ropts;
if (opts == NULL) {
return ISO_NULL_POINTER;
}
if (profile != 0) {
return ISO_WRONG_ARG_VALUE;
}
ropts = calloc(1, sizeof(IsoReadOpts));
if (ropts == NULL) {
return ISO_OUT_OF_MEM;
}
ropts->mode = 0555;
*opts = ropts;
return ISO_SUCCESS;
}
void iso_read_opts_free(IsoReadOpts *opts)
{
if (opts == NULL) {
return;
}
free(opts->input_charset);
free(opts);
}
int iso_read_opts_set_start_block(IsoReadOpts *opts, uint32_t block)
{
if (opts == NULL) {
return ISO_NULL_POINTER;
}
opts->block = block;
return ISO_SUCCESS;
}
int iso_read_opts_set_no_rockridge(IsoReadOpts *opts, int norr)
{
if (opts == NULL) {
return ISO_NULL_POINTER;
}
opts->norock = norr ? 1 :0;
return ISO_SUCCESS;
}
int iso_read_opts_set_no_joliet(IsoReadOpts *opts, int nojoliet)
{
if (opts == NULL) {
return ISO_NULL_POINTER;
}
opts->nojoliet = nojoliet ? 1 :0;
return ISO_SUCCESS;
}
int iso_read_opts_set_no_iso1999(IsoReadOpts *opts, int noiso1999)
{
if (opts == NULL) {
return ISO_NULL_POINTER;
}
opts->noiso1999 = noiso1999 ? 1 :0;
return ISO_SUCCESS;
}
int iso_read_opts_set_preferjoliet(IsoReadOpts *opts, int preferjoliet)
{
if (opts == NULL) {
return ISO_NULL_POINTER;
}
opts->preferjoliet = preferjoliet ? 1 :0;
return ISO_SUCCESS;
}
int iso_read_opts_set_default_uid(IsoReadOpts *opts, uid_t uid)
{
if (opts == NULL) {
return ISO_NULL_POINTER;
}
opts->uid = uid;
return ISO_SUCCESS;
}
int iso_read_opts_set_default_gid(IsoReadOpts *opts, gid_t gid)
{
if (opts == NULL) {
return ISO_NULL_POINTER;
}
opts->gid = gid;
return ISO_SUCCESS;
}
int iso_read_opts_set_default_permissions(IsoReadOpts *opts, mode_t perm)
{
if (opts == NULL) {
return ISO_NULL_POINTER;
}
opts->mode = perm;
return ISO_SUCCESS;
}
int iso_read_opts_set_input_charset(IsoReadOpts *opts, const char *charset)
{
if (opts == NULL) {
return ISO_NULL_POINTER;
}
opts->input_charset = charset ? strdup(charset) : NULL;
return ISO_SUCCESS;
}

View File

@ -94,6 +94,7 @@ enum iso_replace_mode {
}; };
typedef struct iso_write_opts IsoWriteOpts; typedef struct iso_write_opts IsoWriteOpts;
typedef struct iso_read_opts IsoReadOpts;
typedef struct iso_data_source IsoDataSource; typedef struct iso_data_source IsoDataSource;
/** /**
@ -163,56 +164,6 @@ struct iso_data_source {
void *data; void *data;
}; };
/**
* Options for image reading.
* There are four kind of options:
* - Related to multisession support.
* In most cases, an image begins at LBA 0 of the data source. However,
* in multisession discs, the later image begins in the last session on
* disc. The block option can be used to specify the start of that last
* session.
* - Related to the tree that will be read.
* As default, when Rock Ridge extensions are present in the image, that
* will be used to get the tree. If RR extensions are not present, libisofs
* will use the Joliet extensions if available. Finally, the plain ISO-9660
* tree is used if neither RR nor Joliet extensions are available. With
* norock, nojoliet, and preferjoliet options, you can change this
* default behavior.
* - Related to default POSIX attributes.
* When Rock Ridege extensions are not used, libisofs can't figure out what
* are the the permissions, uid or gid for the files. You should supply
* default values for that.
*/
struct iso_read_opts
{
/**
* Block where the image begins, usually 0, can be different on a
* multisession disc.
*/
uint32_t block;
unsigned int norock : 1; /*< Do not read Rock Ridge extensions */
unsigned int nojoliet : 1; /*< Do not read Joliet extensions */
unsigned int noiso1999 : 1; /*< Do not read ISO 9660:1999 enhanced tree */
/**
* When both Joliet and RR extensions are present, the RR tree is used.
* If you prefer using Joliet, set this to 1.
*/
unsigned int preferjoliet : 1;
uid_t uid; /**< Default uid when no RR */
gid_t gid; /**< Default uid when no RR */
mode_t mode; /**< Default mode when no RR (only permissions) */
/* TODO #00023 : let different default file and dir mode for iso reading */
/* TODO #00024 : option to convert names to lower case for iso reading */
/**
* Input charset for RR file names. NULL to use default locale charset.
*/
char *input_charset;
};
/** /**
* Return information for image. * Return information for image.
* Both size, hasRR and hasJoliet will be filled by libisofs with suitable * Both size, hasRR and hasJoliet will be filled by libisofs with suitable
@ -903,6 +854,84 @@ int iso_write_opts_set_fifo_size(IsoWriteOpts *opts, size_t fifo_size);
int iso_image_create_burn_source(IsoImage *image, IsoWriteOpts *opts, int iso_image_create_burn_source(IsoImage *image, IsoWriteOpts *opts,
struct burn_source **burn_src); struct burn_source **burn_src);
/**
* Creates an IsoReadOpts for reading an existent image. You should set the
* options desired with the correspondent setters. Note that you may want to
* set the start block value.
*
* Options by default are determined by the selected profile.
*
* @param profile
* Default profile for image reading. For now the following values are
* defined:
* ---> 0 [STANDARD]
* Suitable for most situations. All extension are read. When both
* Joliet and RR extension are present, RR is used.
* @return
* 1 success, < 0 error
*/
int iso_read_opts_new(IsoReadOpts **opts, int profile);
/**
* Free an IsoReadOpts previously allocated with iso_read_opts_new().
*/
void iso_read_opts_free(IsoReadOpts *opts);
/**
* Set the block where the image begins. It is usually 0, but may be different
* on a multisession disc.
*/
int iso_read_opts_set_start_block(IsoReadOpts *opts, uint32_t block);
/**
* Do not read Rock Ridge extensions.
* In most cases you don't want to use this. It could be useful if RR info
* is damaged, or if you want to use the Joliet tree.
*/
int iso_read_opts_set_no_rockridge(IsoReadOpts *opts, int norr);
/**
* Do not read Joliet extensions.
*/
int iso_read_opts_set_no_joliet(IsoReadOpts *opts, int nojoliet);
/**
* Do not read ISO 9660:1999 enhanced tree
*/
int iso_read_opts_set_no_iso1999(IsoReadOpts *opts, int noiso1999);
/**
* Whether to prefer Joliet over RR. libisofs usually prefers RR over
* Joliet, as it give us much more info about files. So, if both extensions
* are present, RR is used. You can set this if you prefer Joliet, but
* note that this is not very recommended. This doesn't mean than RR
* extensions are not read: if no Joliet is present, libisofs will read
* RR tree.
*/
int iso_read_opts_set_preferjoliet(IsoReadOpts *opts, int preferjoliet);
/**
* Set default uid for files when RR extensions are not present.
*/
int iso_read_opts_set_default_uid(IsoReadOpts *opts, uid_t uid);
/**
* Set default gid for files when RR extensions are not present.
*/
int iso_read_opts_set_default_gid(IsoReadOpts *opts, gid_t gid);
/**
* Set default permissions for files when RR extensions are not present.
*/
int iso_read_opts_set_default_permissions(IsoReadOpts *opts, mode_t perm);
/**
* Set the input charset of the file names on the image. NULL to use locale
* charset. You have to specify a charset if the image filenames are encoded
* in a charset different that the local one.
*/
int iso_read_opts_set_input_charset(IsoReadOpts *opts, const char *charset);
/** /**
* Import a previous session or image, for growing or modify. * Import a previous session or image, for growing or modify.
* *
@ -923,7 +952,7 @@ int iso_image_create_burn_source(IsoImage *image, IsoWriteOpts *opts,
* 1 on success, < 0 on error * 1 on success, < 0 on error
*/ */
int iso_image_import(IsoImage *image, IsoDataSource *src, int iso_image_import(IsoImage *image, IsoDataSource *src,
struct iso_read_opts *opts, IsoReadOpts *opts,
struct iso_read_image_features *features); struct iso_read_image_features *features);
/** /**
@ -2081,7 +2110,7 @@ void iso_filesystem_unref(IsoFilesystem *fs);
* @param * @param
* 1 on success, < 0 on error * 1 on success, < 0 on error
*/ */
int iso_image_filesystem_new(IsoDataSource *src, struct iso_read_opts *opts, int iso_image_filesystem_new(IsoDataSource *src, IsoReadOpts *opts,
int msgid, IsoImageFilesystem **fs); int msgid, IsoImageFilesystem **fs);
/** /**