Init builder implementation.
This commit is contained in:
parent
6616eae76b
commit
14f4aa7d07
@ -11,6 +11,7 @@ src_libisofs_la_LDFLAGS = \
|
||||
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
|
||||
src_libisofs_la_SOURCES = \
|
||||
src/builder.h \
|
||||
src/builder.c \
|
||||
src/error.h \
|
||||
src/node.h \
|
||||
src/node.c \
|
||||
|
109
src/builder.c
Normal file
109
src/builder.c
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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 "builder.h"
|
||||
#include "error.h"
|
||||
#include "node.h"
|
||||
#include "fsource.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void iso_node_builder_ref(IsoNodeBuilder *builder)
|
||||
{
|
||||
++builder->refcount;
|
||||
}
|
||||
|
||||
void iso_node_builder_unref(IsoNodeBuilder *builder)
|
||||
{
|
||||
if (--builder->refcount == 0) {
|
||||
/* free private data */
|
||||
builder->free(builder);
|
||||
free(builder);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
int default_create_file(IsoNodeBuilder *builder, IsoFileSource *src,
|
||||
IsoFile **file)
|
||||
{
|
||||
int res;
|
||||
struct stat info;
|
||||
IsoStream *stream;
|
||||
IsoFile *node;
|
||||
|
||||
if (builder == NULL || src == NULL || file == NULL) {
|
||||
return ISO_NULL_POINTER;
|
||||
}
|
||||
|
||||
res = src->stat(src, &info);
|
||||
if (res < 0) {
|
||||
return res;
|
||||
}
|
||||
|
||||
/* this will fail if src is a dir, is not accessible... */
|
||||
res = iso_file_source_stream_new(src, &stream);
|
||||
if (res < 0) {
|
||||
return res;
|
||||
}
|
||||
|
||||
node = malloc(sizeof(IsoFile));
|
||||
if (node == NULL) {
|
||||
/* the stream has taken our ref to src, so we need to add one */
|
||||
iso_file_source_ref(src);
|
||||
iso_stream_unref(stream);
|
||||
return ISO_MEM_ERROR;
|
||||
}
|
||||
|
||||
/* fill node fields */
|
||||
node->node.refcount = 1;
|
||||
node->node.type = LIBISO_FILE;
|
||||
node->node.name = strdup(src->get_name(src));
|
||||
node->node.mode = S_IFREG | (info.st_mode & ~S_IFMT);
|
||||
node->node.uid = info.st_uid;
|
||||
node->node.gid = info.st_gid;
|
||||
node->node.atime = info.st_atime;
|
||||
node->node.ctime = info.st_ctime;
|
||||
node->node.mtime = info.st_mtime;
|
||||
node->node.hidden = 0;
|
||||
node->node.parent = NULL;
|
||||
node->node.next = NULL;
|
||||
node->sort_weight = 0;
|
||||
node->stream = stream;
|
||||
node->msblock = 0;
|
||||
|
||||
*file = node;
|
||||
return ISO_SUCCESS;
|
||||
}
|
||||
|
||||
void default_free(IsoNodeBuilder *builder)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int iso_node_basic_builder_new(IsoNodeBuilder **builder)
|
||||
{
|
||||
IsoNodeBuilder *b;
|
||||
|
||||
if (builder == NULL) {
|
||||
return ISO_NULL_POINTER;
|
||||
}
|
||||
|
||||
b = malloc(sizeof(IsoNodeBuilder));
|
||||
if (b == NULL) {
|
||||
return ISO_MEM_ERROR;
|
||||
}
|
||||
|
||||
b->refcount = 1;
|
||||
b->data = NULL;
|
||||
b->create_file = default_create_file;
|
||||
b->free = default_free;
|
||||
|
||||
*builder = b;
|
||||
return ISO_SUCCESS;
|
||||
}
|
@ -18,7 +18,8 @@
|
||||
* Builder.
|
||||
*/
|
||||
|
||||
#include "node.h"
|
||||
#include "libisofs.h"
|
||||
#include "fsource.h"
|
||||
|
||||
typedef struct Iso_Node_Builder IsoNodeBuilder;
|
||||
|
||||
@ -26,18 +27,41 @@ struct Iso_Node_Builder
|
||||
{
|
||||
|
||||
/**
|
||||
* Create a new IsoFile from an IsoFileSource. Name, permissions
|
||||
* and other attributes are taken from src, but a regular file will
|
||||
* always be created, even if src is another kind of file.
|
||||
*
|
||||
* In that case, if the implementation can't do the conversion, it
|
||||
* should fail propertly.
|
||||
*
|
||||
* On sucess, the ref. to src will be owned by file, so you musn't
|
||||
* unref it.
|
||||
*
|
||||
* @return
|
||||
* 1 on success, < 0 on error
|
||||
*/
|
||||
int (*create_file)(const IsoFileSource *src, IsoFile **file);
|
||||
|
||||
int (*create_file)(IsoNodeBuilder *builder, IsoFileSource *src,
|
||||
IsoFile **file);
|
||||
|
||||
/**
|
||||
* Free implementation specific data. Should never be called by user.
|
||||
* Use iso_node_builder_unref() instead.
|
||||
*/
|
||||
void (*free)(IsoNodeBuilder *builder);
|
||||
|
||||
int refcount;
|
||||
void *data;
|
||||
};
|
||||
|
||||
void iso_node_builder_ref(IsoNodeBuilder *builder);
|
||||
void iso_node_builder_unref(IsoNodeBuilder *builder);
|
||||
|
||||
/**
|
||||
* Create a new basic builder ...
|
||||
*
|
||||
* @return
|
||||
* 1 success, < 0 error
|
||||
*/
|
||||
int iso_node_basic_builder_new(IsoNodeBuilder **builder);
|
||||
|
||||
#endif /*LIBISO_BUILDER_H_*/
|
||||
|
@ -19,6 +19,17 @@ typedef struct Iso_File IsoFile;
|
||||
|
||||
typedef struct Iso_Dir_Iter IsoDirIter;
|
||||
|
||||
/**
|
||||
* The type of an IsoNode.
|
||||
*/
|
||||
enum IsoNodeType {
|
||||
LIBISO_DIR,
|
||||
LIBISO_FILE,
|
||||
LIBISO_SYMLINK,
|
||||
LIBISO_SPECIAL,
|
||||
LIBISO_BOOT
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new image, empty.
|
||||
*
|
||||
|
17
src/node.h
17
src/node.h
@ -18,17 +18,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/**
|
||||
* The type of an IsoNode.
|
||||
*/
|
||||
enum IsoNodeType {
|
||||
LIBISO_DIR,
|
||||
LIBISO_FILE,
|
||||
LIBISO_SYMLINK,
|
||||
LIBISO_SPECIAL,
|
||||
LIBISO_BOOT
|
||||
};
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Flag used to hide a file in the RR/ISO or Joliet tree.
|
||||
@ -90,6 +80,11 @@ struct Iso_File
|
||||
{
|
||||
IsoNode node;
|
||||
|
||||
/**
|
||||
* Location of a file extent in a ms disc, 0 for newly added file
|
||||
*/
|
||||
uint32_t msblock;
|
||||
|
||||
/**
|
||||
* It sorts the order in which the file data is written to the CD image.
|
||||
* Higher weighting filesare written at the beginning of image
|
||||
|
Loading…
Reference in New Issue
Block a user