2007-12-02 18:10:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Vreixo Formoso
|
2009-05-30 16:00:21 +00:00
|
|
|
* Copyright (c) 2009 Thomas Schmitt
|
2008-09-07 14:32:18 +00:00
|
|
|
*
|
|
|
|
* 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
|
2007-12-02 18:10:30 +00:00
|
|
|
* published by the Free Software Foundation. See COPYING file for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libisofs.h"
|
|
|
|
#include "image.h"
|
|
|
|
#include "node.h"
|
2007-12-02 19:11:44 +00:00
|
|
|
#include "messages.h"
|
2008-01-10 16:22:53 +00:00
|
|
|
#include "eltorito.h"
|
2007-12-02 18:10:30 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-04-28 20:40:15 +00:00
|
|
|
#include <stdio.h>
|
2007-12-02 18:10:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new image, empty.
|
2008-09-07 14:32:18 +00:00
|
|
|
*
|
2007-12-02 18:10:30 +00:00
|
|
|
* The image will be owned by you and should be unref() when no more needed.
|
2008-09-07 14:32:18 +00:00
|
|
|
*
|
2007-12-02 18:10:30 +00:00
|
|
|
* @param name
|
|
|
|
* Name of the image. This will be used as volset_id and volume_id.
|
|
|
|
* @param image
|
|
|
|
* Location where the image pointer will be stored.
|
|
|
|
* @return
|
|
|
|
* 1 sucess, < 0 error
|
|
|
|
*/
|
|
|
|
int iso_image_new(const char *name, IsoImage **image)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
IsoImage *img;
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-02 18:10:30 +00:00
|
|
|
if (image == NULL) {
|
|
|
|
return ISO_NULL_POINTER;
|
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-02 18:10:30 +00:00
|
|
|
img = calloc(1, sizeof(IsoImage));
|
|
|
|
if (img == NULL) {
|
2008-01-20 21:28:27 +00:00
|
|
|
return ISO_OUT_OF_MEM;
|
2007-12-02 18:10:30 +00:00
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-07 02:02:46 +00:00
|
|
|
/* local filesystem will be used by default */
|
|
|
|
res = iso_local_filesystem_new(&(img->fs));
|
|
|
|
if (res < 0) {
|
|
|
|
free(img);
|
2008-01-20 21:28:27 +00:00
|
|
|
return ISO_OUT_OF_MEM;
|
2007-12-07 02:02:46 +00:00
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-07 02:02:46 +00:00
|
|
|
/* use basic builder as default */
|
|
|
|
res = iso_node_basic_builder_new(&(img->builder));
|
|
|
|
if (res < 0) {
|
|
|
|
iso_filesystem_unref(img->fs);
|
|
|
|
free(img);
|
2008-01-20 21:28:27 +00:00
|
|
|
return ISO_OUT_OF_MEM;
|
2007-12-07 02:02:46 +00:00
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-02 18:10:30 +00:00
|
|
|
/* fill image fields */
|
|
|
|
res = iso_node_new_root(&img->root);
|
|
|
|
if (res < 0) {
|
2007-12-07 02:02:46 +00:00
|
|
|
iso_node_builder_unref(img->builder);
|
|
|
|
iso_filesystem_unref(img->fs);
|
2007-12-02 18:10:30 +00:00
|
|
|
free(img);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
img->refcount = 1;
|
2008-01-19 01:48:12 +00:00
|
|
|
img->id = iso_message_id++;
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-02 18:10:30 +00:00
|
|
|
if (name != NULL) {
|
|
|
|
img->volset_id = strdup(name);
|
|
|
|
img->volume_id = strdup(name);
|
|
|
|
}
|
2009-01-23 08:32:32 +00:00
|
|
|
img->builder_ignore_acl = 1;
|
|
|
|
img->builder_ignore_ea = 1;
|
2009-04-28 20:40:15 +00:00
|
|
|
img->inode_counter = 0;
|
|
|
|
img->used_inodes = NULL;
|
|
|
|
img->used_inodes_start = 0;
|
2009-08-10 11:56:06 +00:00
|
|
|
|
|
|
|
#ifdef Libisofs_with_checksumS
|
|
|
|
img->checksum_start_lba = 0;
|
|
|
|
img->checksum_end_lba = 0;
|
|
|
|
img->checksum_idx_count = 0;
|
|
|
|
img->checksum_array = NULL;
|
|
|
|
#endif
|
|
|
|
|
2007-12-02 18:10:30 +00:00
|
|
|
*image = img;
|
|
|
|
return ISO_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Increments the reference counting of the given image.
|
|
|
|
*/
|
|
|
|
void iso_image_ref(IsoImage *image)
|
|
|
|
{
|
|
|
|
++image->refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decrements the reference couting of the given image.
|
2008-09-07 14:32:18 +00:00
|
|
|
* If it reaches 0, the image is free, together with its tree nodes (whether
|
2007-12-02 18:10:30 +00:00
|
|
|
* their refcount reach 0 too, of course).
|
|
|
|
*/
|
|
|
|
void iso_image_unref(IsoImage *image)
|
|
|
|
{
|
|
|
|
if (--image->refcount == 0) {
|
2008-01-29 19:43:59 +00:00
|
|
|
int nexcl;
|
|
|
|
|
2007-12-02 18:10:30 +00:00
|
|
|
/* we need to free the image */
|
2008-02-07 11:31:09 +00:00
|
|
|
if (image->user_data_free != NULL) {
|
2008-01-28 23:12:33 +00:00
|
|
|
/* free attached data */
|
|
|
|
image->user_data_free(image->user_data);
|
|
|
|
}
|
2008-01-29 19:43:59 +00:00
|
|
|
|
|
|
|
for (nexcl = 0; nexcl < image->nexcludes; ++nexcl) {
|
|
|
|
free(image->excludes[nexcl]);
|
|
|
|
}
|
|
|
|
free(image->excludes);
|
|
|
|
|
2007-12-02 18:10:30 +00:00
|
|
|
iso_node_unref((IsoNode*)image->root);
|
2007-12-07 02:02:46 +00:00
|
|
|
iso_node_builder_unref(image->builder);
|
|
|
|
iso_filesystem_unref(image->fs);
|
2008-01-10 16:22:53 +00:00
|
|
|
el_torito_boot_catalog_free(image->bootcat);
|
2007-12-02 18:10:30 +00:00
|
|
|
free(image->volset_id);
|
|
|
|
free(image->volume_id);
|
|
|
|
free(image->publisher_id);
|
|
|
|
free(image->data_preparer_id);
|
|
|
|
free(image->system_id);
|
|
|
|
free(image->application_id);
|
|
|
|
free(image->copyright_file_id);
|
|
|
|
free(image->abstract_file_id);
|
|
|
|
free(image->biblio_file_id);
|
2009-04-28 20:40:15 +00:00
|
|
|
if (image->used_inodes != NULL)
|
|
|
|
free(image->used_inodes);
|
2009-08-20 15:08:07 +00:00
|
|
|
iso_image_free_checksums(image, 0);
|
2007-12-28 21:45:56 +00:00
|
|
|
free(image);
|
2007-12-02 18:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-02 18:49:11 +00:00
|
|
|
|
2009-08-20 15:08:07 +00:00
|
|
|
|
|
|
|
int iso_image_free_checksums(IsoImage *image, int flag)
|
|
|
|
{
|
|
|
|
#ifdef Libisofs_with_checksumS
|
|
|
|
|
|
|
|
image->checksum_start_lba = 0;
|
|
|
|
image->checksum_end_lba = 0;
|
|
|
|
image->checksum_idx_count = 0;
|
|
|
|
if (image->checksum_array != NULL)
|
|
|
|
free(image->checksum_array);
|
|
|
|
image->checksum_array = NULL;
|
|
|
|
|
|
|
|
#endif /* Libisofs_with_checksumS */
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-28 23:12:33 +00:00
|
|
|
/**
|
|
|
|
* Attach user defined data to the image. Use this if your application needs
|
|
|
|
* to store addition info together with the IsoImage. If the image already
|
|
|
|
* has data attached, the old data will be freed.
|
2008-09-07 14:32:18 +00:00
|
|
|
*
|
2008-01-28 23:12:33 +00:00
|
|
|
* @param data
|
|
|
|
* Pointer to application defined data that will be attached to the
|
|
|
|
* image. You can pass NULL to remove any already attached data.
|
2008-02-07 11:31:09 +00:00
|
|
|
* @param give_up
|
2008-01-28 23:12:33 +00:00
|
|
|
* Function that will be called when the image does not need the data
|
|
|
|
* any more. It receives the data pointer as an argumente, and eventually
|
2008-02-07 11:31:09 +00:00
|
|
|
* causes data to be free. It can be NULL if you don't need it.
|
2008-01-28 23:12:33 +00:00
|
|
|
*/
|
2008-02-07 11:31:09 +00:00
|
|
|
int iso_image_attach_data(IsoImage *image, void *data, void (*give_up)(void*))
|
2008-01-28 23:12:33 +00:00
|
|
|
{
|
|
|
|
if (image == NULL || (data != NULL && free == NULL)) {
|
|
|
|
return ISO_NULL_POINTER;
|
|
|
|
}
|
2008-09-07 14:32:18 +00:00
|
|
|
|
2008-01-28 23:12:33 +00:00
|
|
|
if (image->user_data != NULL) {
|
|
|
|
/* free previously attached data */
|
2008-02-07 11:31:09 +00:00
|
|
|
if (image->user_data_free) {
|
|
|
|
image->user_data_free(image->user_data);
|
|
|
|
}
|
2008-01-28 23:12:33 +00:00
|
|
|
image->user_data = NULL;
|
2008-02-07 11:31:09 +00:00
|
|
|
image->user_data_free = NULL;
|
2008-01-28 23:12:33 +00:00
|
|
|
}
|
2008-09-07 14:32:18 +00:00
|
|
|
|
2008-01-28 23:12:33 +00:00
|
|
|
if (data != NULL) {
|
|
|
|
image->user_data = data;
|
2008-02-07 11:31:09 +00:00
|
|
|
image->user_data_free = give_up;
|
2008-01-28 23:12:33 +00:00
|
|
|
}
|
|
|
|
return ISO_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The the data previously attached with iso_image_attach_data()
|
|
|
|
*/
|
|
|
|
void *iso_image_get_attached_data(IsoImage *image)
|
|
|
|
{
|
|
|
|
return image->user_data;
|
|
|
|
}
|
|
|
|
|
2007-12-02 18:49:11 +00:00
|
|
|
IsoDir *iso_image_get_root(const IsoImage *image)
|
|
|
|
{
|
|
|
|
return image->root;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iso_image_set_volset_id(IsoImage *image, const char *volset_id)
|
|
|
|
{
|
|
|
|
free(image->volset_id);
|
|
|
|
image->volset_id = strdup(volset_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *iso_image_get_volset_id(const IsoImage *image)
|
|
|
|
{
|
|
|
|
return image->volset_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iso_image_set_volume_id(IsoImage *image, const char *volume_id)
|
|
|
|
{
|
|
|
|
free(image->volume_id);
|
|
|
|
image->volume_id = strdup(volume_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *iso_image_get_volume_id(const IsoImage *image)
|
|
|
|
{
|
|
|
|
return image->volume_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iso_image_set_publisher_id(IsoImage *image, const char *publisher_id)
|
|
|
|
{
|
|
|
|
free(image->publisher_id);
|
|
|
|
image->publisher_id = strdup(publisher_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *iso_image_get_publisher_id(const IsoImage *image)
|
|
|
|
{
|
|
|
|
return image->publisher_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iso_image_set_data_preparer_id(IsoImage *image,
|
2007-12-28 21:10:17 +00:00
|
|
|
const char *data_preparer_id)
|
2007-12-02 18:49:11 +00:00
|
|
|
{
|
|
|
|
free(image->data_preparer_id);
|
|
|
|
image->data_preparer_id = strdup(data_preparer_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *iso_image_get_data_preparer_id(const IsoImage *image)
|
|
|
|
{
|
|
|
|
return image->data_preparer_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iso_image_set_system_id(IsoImage *image, const char *system_id)
|
|
|
|
{
|
|
|
|
free(image->system_id);
|
|
|
|
image->system_id = strdup(system_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *iso_image_get_system_id(const IsoImage *image)
|
|
|
|
{
|
|
|
|
return image->system_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iso_image_set_application_id(IsoImage *image, const char *application_id)
|
|
|
|
{
|
|
|
|
free(image->application_id);
|
|
|
|
image->application_id = strdup(application_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *iso_image_get_application_id(const IsoImage *image)
|
|
|
|
{
|
|
|
|
return image->application_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iso_image_set_copyright_file_id(IsoImage *image,
|
2007-12-28 21:10:17 +00:00
|
|
|
const char *copyright_file_id)
|
2007-12-02 18:49:11 +00:00
|
|
|
{
|
|
|
|
free(image->copyright_file_id);
|
|
|
|
image->copyright_file_id = strdup(copyright_file_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *iso_image_get_copyright_file_id(const IsoImage *image)
|
|
|
|
{
|
|
|
|
return image->copyright_file_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iso_image_set_abstract_file_id(IsoImage *image,
|
2007-12-28 21:10:17 +00:00
|
|
|
const char *abstract_file_id)
|
2007-12-02 18:49:11 +00:00
|
|
|
{
|
|
|
|
free(image->abstract_file_id);
|
|
|
|
image->abstract_file_id = strdup(abstract_file_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *iso_image_get_abstract_file_id(const IsoImage *image)
|
|
|
|
{
|
|
|
|
return image->abstract_file_id;
|
|
|
|
}
|
|
|
|
|
2007-12-28 21:10:17 +00:00
|
|
|
void iso_image_set_biblio_file_id(IsoImage *image, const char *biblio_file_id)
|
2007-12-02 18:49:11 +00:00
|
|
|
{
|
|
|
|
free(image->biblio_file_id);
|
|
|
|
image->biblio_file_id = strdup(biblio_file_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *iso_image_get_biblio_file_id(const IsoImage *image)
|
|
|
|
{
|
|
|
|
return image->biblio_file_id;
|
|
|
|
}
|
2008-01-27 17:20:33 +00:00
|
|
|
|
|
|
|
int iso_image_get_msg_id(IsoImage *image)
|
|
|
|
{
|
|
|
|
return image->id;
|
|
|
|
}
|
2008-09-07 14:32:18 +00:00
|
|
|
|
|
|
|
static
|
|
|
|
int dir_update_size(IsoImage *image, IsoDir *dir)
|
|
|
|
{
|
|
|
|
IsoNode *pos;
|
|
|
|
pos = dir->children;
|
|
|
|
while (pos) {
|
|
|
|
int ret = 1;
|
|
|
|
if (pos->type == LIBISO_FILE) {
|
|
|
|
ret = iso_stream_update_size(ISO_FILE(pos)->stream);
|
|
|
|
} else if (pos->type == LIBISO_DIR) {
|
|
|
|
/* recurse */
|
|
|
|
ret = dir_update_size(image, ISO_DIR(pos));
|
|
|
|
}
|
|
|
|
if (ret < 0) {
|
|
|
|
ret = iso_msg_submit(image->id, ret, 0, NULL);
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret; /* cancel due error threshold */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pos = pos->next;
|
|
|
|
}
|
|
|
|
return ISO_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int iso_image_update_sizes(IsoImage *image)
|
|
|
|
{
|
|
|
|
if (image == NULL) {
|
|
|
|
return ISO_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dir_update_size(image, image->root);
|
|
|
|
}
|
2009-01-23 08:32:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
void iso_image_set_ignore_aclea(IsoImage *image, int what)
|
|
|
|
{
|
|
|
|
image->builder_ignore_acl = (what & 1);
|
|
|
|
image->builder_ignore_ea = !!(what & 2);
|
|
|
|
}
|
|
|
|
|
2009-04-28 20:40:15 +00:00
|
|
|
|
|
|
|
static
|
|
|
|
int img_register_ino(IsoImage *image, IsoNode *node, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
ino_t ino;
|
|
|
|
unsigned int fs_id;
|
|
|
|
dev_t dev_id;
|
|
|
|
|
|
|
|
ret = iso_node_get_id(node, &fs_id, &dev_id, &ino, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
if (ret > 0 && ino >= image->used_inodes_start &&
|
2009-04-29 10:52:32 +00:00
|
|
|
ino <= image->used_inodes_start + (ISO_USED_INODE_RANGE - 1)) {
|
|
|
|
/* without -1 : rollover hazard on 32 bit */
|
2009-04-28 20:40:15 +00:00
|
|
|
image->used_inodes[(ino - image->used_inodes_start) / 8]
|
|
|
|
|= (1 << (ino % 8));
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Collect the bitmap of used inode numbers in the range of
|
|
|
|
_ImageFsData.used_inodes_start + ISO_USED_INODE_RANGE
|
|
|
|
@param flag bit0= recursion is active
|
|
|
|
*/
|
|
|
|
int img_collect_inos(IsoImage *image, IsoDir *dir, int flag)
|
|
|
|
{
|
|
|
|
int ret, register_dir = 1;
|
2009-04-29 10:52:32 +00:00
|
|
|
IsoDirIter *iter = NULL;
|
2009-04-28 20:40:15 +00:00
|
|
|
IsoNode *node;
|
|
|
|
IsoDir *subdir;
|
|
|
|
|
|
|
|
if (dir == NULL)
|
|
|
|
dir = image->root;
|
|
|
|
if (image->used_inodes == NULL) {
|
|
|
|
image->used_inodes = calloc(ISO_USED_INODE_RANGE / 8, 1);
|
|
|
|
if (image->used_inodes == NULL)
|
|
|
|
return ISO_OUT_OF_MEM;
|
|
|
|
} else if(!(flag & 1)) {
|
|
|
|
memset(image->used_inodes, 0, ISO_USED_INODE_RANGE / 8);
|
|
|
|
} else {
|
|
|
|
register_dir = 0;
|
|
|
|
}
|
|
|
|
if (register_dir) {
|
|
|
|
node = (IsoNode *) dir;
|
|
|
|
ret = img_register_ino(image, node, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = iso_dir_get_children(dir, &iter);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
while (iso_dir_iter_next(iter, &node) == 1 ) {
|
|
|
|
ret = img_register_ino(image, node, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
goto ex;
|
|
|
|
if (iso_node_get_type(node) == LIBISO_DIR) {
|
|
|
|
subdir = (IsoDir *) node;
|
|
|
|
ret = img_collect_inos(image, subdir, flag | 1);
|
|
|
|
if (ret < 0)
|
|
|
|
goto ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret = 1;
|
|
|
|
ex:;
|
2009-04-29 10:52:32 +00:00
|
|
|
if (iter != NULL)
|
|
|
|
iso_dir_iter_free(iter);
|
2009-04-28 20:40:15 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A global counter for inode numbers for the ISO image filesystem.
|
|
|
|
* On image import it gets maxed by the eventual inode numbers from PX
|
|
|
|
* entries. Up to the first 32 bit rollover it simply increments the counter.
|
|
|
|
* After the first rollover it uses a look ahead bitmap which gets filled
|
|
|
|
* by a full tree traversal. It covers the next inode numbers to come
|
|
|
|
* (somewhere between 1 and ISO_USED_INODE_RANGE which is quite many)
|
|
|
|
* and advances when being exhausted.
|
|
|
|
* @param image The image where the number shall be used
|
|
|
|
* @param flag bit0= reset count (Caution: image must get new inos then)
|
|
|
|
* @return
|
|
|
|
* Since ino_t 0 is used as default and considered self-unique,
|
|
|
|
* the value 0 should only be returned in case of error.
|
|
|
|
*/
|
|
|
|
ino_t img_give_ino_number(IsoImage *image, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
ino_t new_ino, ino_idx;
|
|
|
|
static uint64_t limit = 0xffffffff;
|
|
|
|
|
|
|
|
if (flag & 1) {
|
|
|
|
image->inode_counter = 0;
|
|
|
|
if (image->used_inodes != NULL)
|
|
|
|
free(image->used_inodes);
|
|
|
|
image->used_inodes = NULL;
|
|
|
|
image->used_inodes_start = 0;
|
|
|
|
}
|
|
|
|
new_ino = image->inode_counter + 1;
|
|
|
|
if (image->used_inodes == NULL) {
|
|
|
|
if (new_ino > 0 && new_ino <= limit) {
|
|
|
|
image->inode_counter = new_ino;
|
|
|
|
return image->inode_counter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Look for free number in used territory */
|
|
|
|
while (1) {
|
|
|
|
if (new_ino <= 0 || new_ino > limit ||
|
|
|
|
new_ino >= image->used_inodes_start + ISO_USED_INODE_RANGE ) {
|
|
|
|
|
|
|
|
/* Collect a bitmap of used inode numbers ahead */
|
|
|
|
|
|
|
|
image->used_inodes_start += ISO_USED_INODE_RANGE;
|
|
|
|
if (image->used_inodes_start > 0xffffffff ||
|
|
|
|
image->used_inodes_start <= 0)
|
|
|
|
image->used_inodes_start = 0;
|
|
|
|
ret = img_collect_inos(image, NULL, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
goto return_result; /* >>> need error return value */
|
|
|
|
|
|
|
|
new_ino = image->used_inodes_start + !image->used_inodes_start;
|
|
|
|
}
|
|
|
|
ino_idx = (new_ino - image->used_inodes_start) / 8;
|
|
|
|
if (!(image->used_inodes[ino_idx] & (1 << (new_ino % 8)))) {
|
|
|
|
image->used_inodes[ino_idx] |= (1 << (new_ino % 8));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
new_ino++;
|
|
|
|
}
|
|
|
|
return_result:;
|
|
|
|
image->inode_counter = new_ino;
|
|
|
|
return image->inode_counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* @param flag bit0= overwrite any ino, else only ino == 0
|
|
|
|
bit1= install inode with non-data, non-directory files
|
|
|
|
bit2= install inode with directories
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
int img_update_ino(IsoImage *image, IsoNode *node, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
ino_t ino;
|
|
|
|
unsigned int fs_id;
|
|
|
|
dev_t dev_id;
|
|
|
|
|
|
|
|
ret = iso_node_get_id(node, &fs_id, &dev_id, &ino, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
if (ret == 0)
|
|
|
|
ino = 0;
|
|
|
|
if (((flag & 1) || ino == 0) &&
|
2009-05-01 10:49:37 +00:00
|
|
|
(iso_node_get_type(node) == LIBISO_FILE || (flag & (2 | 4))) &&
|
2009-04-28 20:40:15 +00:00
|
|
|
((flag & 4) || iso_node_get_type(node) != LIBISO_DIR)) {
|
|
|
|
ret = iso_node_set_unique_id(node, image, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* @param flag bit0= overwrite any ino, else only ino == 0
|
|
|
|
bit1= install inode with non-data, non-directory files
|
|
|
|
bit2= install inode with directories
|
|
|
|
bit3= with bit2: install inode on parameter dir
|
|
|
|
*/
|
|
|
|
int img_make_inos(IsoImage *image, IsoDir *dir, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
2009-04-29 10:52:32 +00:00
|
|
|
IsoDirIter *iter = NULL;
|
2009-04-28 20:40:15 +00:00
|
|
|
IsoNode *node;
|
|
|
|
IsoDir *subdir;
|
|
|
|
|
|
|
|
if (flag & 8) {
|
|
|
|
node = (IsoNode *) dir;
|
|
|
|
ret = img_update_ino(image, node, flag & 7);
|
|
|
|
if (ret < 0)
|
|
|
|
goto ex;
|
|
|
|
}
|
|
|
|
ret = iso_dir_get_children(dir, &iter);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
while (iso_dir_iter_next(iter, &node) == 1) {
|
|
|
|
ret = img_update_ino(image, node, flag & 7);
|
|
|
|
if (ret < 0)
|
|
|
|
goto ex;
|
|
|
|
if (iso_node_get_type(node) == LIBISO_DIR) {
|
|
|
|
subdir = (IsoDir *) node;
|
|
|
|
ret = img_make_inos(image, subdir, flag & ~8);
|
|
|
|
if (ret < 0)
|
|
|
|
goto ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret = 1;
|
|
|
|
ex:;
|
2009-04-29 10:52:32 +00:00
|
|
|
if (iter != NULL)
|
|
|
|
iso_dir_iter_free(iter);
|
2009-04-28 20:40:15 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-08-10 11:56:06 +00:00
|
|
|
|
|
|
|
/* API */
|
|
|
|
int iso_image_get_session_md5(IsoImage *image, uint32_t *start_lba,
|
|
|
|
uint32_t *end_lba, char md5[16], int flag)
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef Libisofs_with_checksumS
|
|
|
|
|
|
|
|
if (image->checksum_array == NULL || image->checksum_idx_count < 1)
|
|
|
|
return 0;
|
|
|
|
*start_lba = image->checksum_start_lba;
|
|
|
|
*end_lba = image->checksum_end_lba;
|
|
|
|
memcpy(md5, image->checksum_array, 16);
|
|
|
|
return ISO_SUCCESS;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
#endif /* ! Libisofs_with_checksumS */
|
|
|
|
|
|
|
|
}
|
2009-08-20 15:08:07 +00:00
|
|
|
|
|
|
|
int iso_image_set_checksums(IsoImage *image, char *checksum_array,
|
|
|
|
uint32_t start_lba, uint32_t end_lba,
|
|
|
|
uint32_t idx_count, int flag)
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef Libisofs_with_checksumS
|
|
|
|
|
|
|
|
iso_image_free_checksums(image, 0);
|
|
|
|
image->checksum_array = checksum_array;
|
|
|
|
image->checksum_start_lba = start_lba;
|
|
|
|
image->checksum_end_lba = end_lba;
|
|
|
|
image->checksum_idx_count = idx_count;
|
|
|
|
|
|
|
|
#endif /* Libisofs_with_checksumS */
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|