Add IsoImage, equivalent to old libisofs volume and volset.
IsoImage will be a context for image creation and modification.
This commit is contained in:
parent
f2deae8503
commit
c83bac7d9e
|
@ -10,9 +10,12 @@ lib_LTLIBRARIES = src/libisofs.la
|
||||||
src_libisofs_la_LDFLAGS = \
|
src_libisofs_la_LDFLAGS = \
|
||||||
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
|
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
|
||||||
src_libisofs_la_SOURCES = \
|
src_libisofs_la_SOURCES = \
|
||||||
|
src/builder.h \
|
||||||
|
src/error.h \
|
||||||
src/node.h \
|
src/node.h \
|
||||||
src/node.c \
|
src/node.c \
|
||||||
src/image.h \
|
src/image.h \
|
||||||
|
src/image.c \
|
||||||
src/fsource.h \
|
src/fsource.h \
|
||||||
src/fsource.c \
|
src/fsource.c \
|
||||||
src/fs_local.c \
|
src/fs_local.c \
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "libisofs.h"
|
||||||
|
#include "image.h"
|
||||||
|
#include "error.h"
|
||||||
|
#include "node.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new image, empty.
|
||||||
|
*
|
||||||
|
* The image will be owned by you and should be unref() when no more needed.
|
||||||
|
*
|
||||||
|
* @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;
|
||||||
|
|
||||||
|
if (image == NULL) {
|
||||||
|
return ISO_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
img = calloc(1, sizeof(IsoImage));
|
||||||
|
if (img == NULL) {
|
||||||
|
return ISO_MEM_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* fill image fields */
|
||||||
|
res = iso_node_new_root(&img->root);
|
||||||
|
if (res < 0) {
|
||||||
|
free(img);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
img->refcount = 1;
|
||||||
|
if (name != NULL) {
|
||||||
|
img->volset_id = strdup(name);
|
||||||
|
img->volume_id = strdup(name);
|
||||||
|
}
|
||||||
|
*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.
|
||||||
|
* If it reaches 0, the image is free, together with its tree nodes (whether
|
||||||
|
* their refcount reach 0 too, of course).
|
||||||
|
*/
|
||||||
|
void iso_image_unref(IsoImage *image)
|
||||||
|
{
|
||||||
|
if (--image->refcount == 0) {
|
||||||
|
/* we need to free the image */
|
||||||
|
iso_node_unref((IsoNode*)image->root);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
24
src/image.h
24
src/image.h
|
@ -8,10 +8,10 @@
|
||||||
#ifndef LIBISO_IMAGE_H_
|
#ifndef LIBISO_IMAGE_H_
|
||||||
#define LIBISO_IMAGE_H_
|
#define LIBISO_IMAGE_H_
|
||||||
|
|
||||||
|
#include "libisofs.h"
|
||||||
|
#include "node.h"
|
||||||
|
|
||||||
struct IsoImage {
|
/*
|
||||||
|
|
||||||
/*
|
|
||||||
* Image is a context for image manipulation.
|
* Image is a context for image manipulation.
|
||||||
* Global objects such as the message_queues must belogn to that
|
* Global objects such as the message_queues must belogn to that
|
||||||
* context. Thus we will have, for example, a msg queue per image,
|
* context. Thus we will have, for example, a msg queue per image,
|
||||||
|
@ -20,6 +20,24 @@ struct IsoImage {
|
||||||
* [The stuff we have in init belongs really to image!]
|
* [The stuff we have in init belongs really to image!]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
struct Iso_Image {
|
||||||
|
|
||||||
|
int refcount;
|
||||||
|
|
||||||
|
IsoDir *root;
|
||||||
|
|
||||||
|
char *volset_id;
|
||||||
|
|
||||||
|
char *volume_id; /**< Volume identifier. */
|
||||||
|
char *publisher_id; /**< Volume publisher. */
|
||||||
|
char *data_preparer_id; /**< Volume data preparer. */
|
||||||
|
char *system_id; /**< Volume system identifier. */
|
||||||
|
char *application_id; /**< Volume application id */
|
||||||
|
char *copyright_file_id;
|
||||||
|
char *abstract_file_id;
|
||||||
|
char *biblio_file_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /*LIBISO_IMAGE_H_*/
|
#endif /*LIBISO_IMAGE_H_*/
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
typedef struct Iso_Image IsoImage;
|
||||||
|
|
||||||
typedef struct Iso_Node IsoNode;
|
typedef struct Iso_Node IsoNode;
|
||||||
typedef struct Iso_Dir IsoDir;
|
typedef struct Iso_Dir IsoDir;
|
||||||
typedef struct Iso_Symlink IsoSymlink;
|
typedef struct Iso_Symlink IsoSymlink;
|
||||||
|
@ -17,6 +19,32 @@ typedef struct Iso_File IsoFile;
|
||||||
|
|
||||||
typedef struct Iso_Dir_Iter IsoDirIter;
|
typedef struct Iso_Dir_Iter IsoDirIter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new image, empty.
|
||||||
|
*
|
||||||
|
* The image will be owned by you and should be unref() when no more needed.
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increments the reference counting of the given image.
|
||||||
|
*/
|
||||||
|
void iso_image_ref(IsoImage *image);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrements the reference couting of the given image.
|
||||||
|
* If it reaches 0, the image is free, together with its tree nodes (whether
|
||||||
|
* their refcount reach 0 too, of course).
|
||||||
|
*/
|
||||||
|
void iso_image_unref(IsoImage *image);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the reference counting of the given node.
|
* Increments the reference counting of the given node.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue