First functions and structures for image import.

This commit is contained in:
Vreixo Formoso 2008-01-03 19:17:55 +01:00
parent 2f535abe85
commit 58a7d8e853
5 changed files with 149 additions and 71 deletions

View File

@ -27,6 +27,7 @@ int main(int argc, char **argv)
IsoFileSource *file;
struct stat info;
IsoDataSource *src;
struct libiso_msgs *messenger;
struct iso_read_opts opts = {
0, /* block */
0, /* norock */
@ -35,7 +36,6 @@ int main(int argc, char **argv)
0, /* uid; */
0, /* gid; */
0, /* mode */
NULL, /* messenger */
"UTF-8" /* input_charset */
};
@ -44,12 +44,12 @@ int main(int argc, char **argv)
return 1;
}
res = libiso_msgs_new(&opts.messenger, 0);
res = libiso_msgs_new(&messenger, 0);
if (res <= 0) {
printf ("Can't create messenger\n");
return 1;
}
libiso_msgs_set_severities(opts.messenger, LIBISO_MSGS_SEV_NEVER,
libiso_msgs_set_severities(messenger, LIBISO_MSGS_SEV_NEVER,
LIBISO_MSGS_SEV_ALL, "", 0);
res = iso_data_source_new_from_file(argv[1], &src);
@ -58,7 +58,7 @@ int main(int argc, char **argv)
return 1;
}
res = iso_image_filesystem_new(src, &opts, &fs);
res = iso_image_filesystem_new(src, &opts, messenger, &fs);
if (res < 0) {
printf ("Error creating filesystem\n");
return 1;
@ -99,6 +99,6 @@ int main(int argc, char **argv)
iso_file_source_unref(file);
iso_filesystem_unref(fs);
iso_data_source_unref(src);
libiso_msgs_destroy(&opts.messenger, 0);
libiso_msgs_destroy(&messenger, 0);
return 0;
}

View File

@ -111,6 +111,7 @@ int main(int argc, char **argv)
IsoImageFilesystem *fs;
IsoDataSource *src;
IsoFileSource *root;
struct libiso_msgs *messenger;
struct iso_read_opts opts = {
0, /* block */
0, /* norock */
@ -119,7 +120,6 @@ int main(int argc, char **argv)
0, /* uid; */
0, /* gid; */
0, /* mode */
NULL, /* messenger */
"UTF-8" /* input_charset */
};
@ -128,12 +128,12 @@ int main(int argc, char **argv)
return 1;
}
result = libiso_msgs_new(&opts.messenger, 0);
result = libiso_msgs_new(&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_set_severities(messenger, LIBISO_MSGS_SEV_NEVER,
LIBISO_MSGS_SEV_ALL, "", 0);
result = iso_data_source_new_from_file(argv[1], &src);
@ -142,7 +142,7 @@ int main(int argc, char **argv)
return 1;
}
result = iso_image_filesystem_new(src, &opts, &fs);
result = iso_image_filesystem_new(src, &opts, messenger, &fs);
if (result < 0) {
printf ("Error creating filesystem\n");
return 1;
@ -160,6 +160,6 @@ int main(int argc, char **argv)
fs->close(fs);
iso_filesystem_unref((IsoFilesystem*)fs);
iso_data_source_unref(src);
libiso_msgs_destroy(&opts.messenger, 0);
libiso_msgs_destroy(&messenger, 0);
return 0;
}

View File

@ -16,6 +16,7 @@
#include "ecma119.h"
#include "messages.h"
#include "rockridge.h"
#include "image.h"
#include <stdlib.h>
#include <string.h>
@ -1424,6 +1425,7 @@ int read_pvm(_ImageFsData *data, uint32_t block)
}
int iso_image_filesystem_new(IsoDataSource *src, struct iso_read_opts *opts,
struct libiso_msgs *messenger,
IsoImageFilesystem **fs)
{
int ret;
@ -1460,7 +1462,7 @@ int iso_image_filesystem_new(IsoDataSource *src, struct iso_read_opts *opts,
data->uid = opts->uid;
data->mode = opts->mode & ~S_IFMT;
data->input_charset = strdup(opts->input_charset);
data->messenger = opts->messenger;
data->messenger = messenger;
ifs->open = ifs_fs_open;
ifs->close = ifs_fs_close;
@ -1582,3 +1584,49 @@ int iso_image_filesystem_new(IsoDataSource *src, struct iso_read_opts *opts,
free(ifs);
return ret;
}
int iso_image_import(IsoImage *image, IsoDataSource *src,
struct iso_read_opts *opts,
struct iso_read_image_features *features)
{
int ret;
IsoImageFilesystem *fs;
IsoFilesystem *fsback;
if (image == NULL || src == NULL || opts == NULL) {
return ISO_NULL_POINTER;
}
ret = iso_image_filesystem_new(src, opts, image->messenger, &fs);
if (ret < 0) {
return ret;
}
/* backup image filesystem and builder */
fsback = image->fs;
//TODO
/* get root from filesystem */
/* remove root node */
/* recursively add image */
/* recover backed fs and builder */
/* set volume attributes */
if (features != NULL) {
//TODO
}
//TODO
return -1;
}

View File

@ -12,65 +12,7 @@
#include "libisofs.h"
#include "fsource.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.
* - Return information for image.
* Both size, hasRR and hasJoliet will be filled by libisofs with suitable values.
* Also, error is set to non-0 if some error happens (error codes are
* private now)
*/
struct iso_read_opts
{
uint32_t block; /** Block where the image begins, usually 0, can be
* different on a multisession disc.
*/
unsigned int norock : 1; /*< Do not read Rock Ridge extensions */
unsigned int nojoliet : 1; /*< Do not read Joliet extensions */
/**
* 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 differ file and dir mode
//option to convert names to lower case?
struct libiso_msgs *messenger;
char *input_charset;
/* modified by the function */
// unsigned int hasRR:1; /*< It will be set to 1 if RR extensions are present,
// to 0 if not. */
// unsigned int hasJoliet:1; /*< It will be set to 1 if Joliet extensions are
// present, to 0 if not. */
// uint32_t size; /**< Will be filled with the size (in 2048 byte block) of
// * the image, as reported in the PVM. */
//int error;
};
struct libiso_msgs;
typedef struct Iso_Image_Filesystem IsoImageFilesystem;
/**
@ -102,6 +44,7 @@ struct Iso_Image_Filesystem
};
int iso_image_filesystem_new(IsoDataSource *src, struct iso_read_opts *opts,
struct libiso_msgs *messenger,
IsoImageFilesystem **fs);
#endif /*LIBISO_FS_IMAGE_H_*/

View File

@ -202,6 +202,72 @@ struct Iso_Data_Source {
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 */
/**
* 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 differ file and dir mode
//option to convert names to lower case?
char *input_charset;
};
/**
* Return information for image.
* Both size, hasRR and hasJoliet will be filled by libisofs with suitable
* values.
*/
struct iso_read_image_features
{
/** It will be set to 1 if RR extensions are present, to 0 if not. */
unsigned int hasRR:1;
/** It will be set to 1 if Joliet extensions are present, to 0 if not. */
unsigned int hasJoliet:1;
/**
* Will be filled with the size (in 2048 byte block) of the image, as
* reported in the PVM.
*/
uint32_t size;
};
/**
* Create a new image, empty.
*
@ -223,6 +289,27 @@ int iso_image_new(const char *name, IsoImage **image);
int iso_image_create(IsoImage *image, Ecma119WriteOpts *opts,
struct burn_source **burn_src);
/**
* Import a previous session or image, for growing or modify.
*
* @param image
* The image context to which old image will be imported. Note that all
* files added to image, and image attributes, will be replaced with the
* contents of the old image. TODO support for merging old image files
* @param src
* Data Source from which old image will be read.
* @param opts
* Options for image import
* @param features
* Will be filled with the features of the old image. You can pass NULL
* if you're not interested on them.
* @return
* 1 on success, < 0 on error
*/
int iso_image_import(IsoImage *image, IsoDataSource *src,
struct iso_read_opts *opts,
struct iso_read_image_features *features);
/**
* Increments the reference counting of the given image.
*/