From 6c090c9a7b46fd75a51893efdc3a41e33492fe47 Mon Sep 17 00:00:00 2001 From: Vreixo Formoso Date: Sat, 24 Nov 2007 16:58:36 +0100 Subject: [PATCH] Added more files, mainly beginning of filesystem sources implementation. --- Makefile.am | 9 ++-- TODO | 2 + src/error.h | 21 +++++++++ src/{tree.c => fs_local.c} | 15 +++--- src/fsource.h | 97 ++++++++++++++++++++++++++++++++++++++ src/libisofs.h | 25 +++++++++- src/node.c | 56 ++++++++++++++++++++++ src/{tree.h => node.h} | 42 +++++++++++------ src/stream.h | 44 +++++++++++++++++ test/iso.c | 2 +- 10 files changed, 283 insertions(+), 30 deletions(-) create mode 100644 src/error.h rename src/{tree.c => fs_local.c} (64%) create mode 100644 src/fsource.h create mode 100644 src/node.c rename src/{tree.h => node.h} (70%) create mode 100644 src/stream.h diff --git a/Makefile.am b/Makefile.am index 99edae9..1398ec3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,9 +10,12 @@ lib_LTLIBRARIES = src/libisofs.la src_libisofs_la_LDFLAGS = \ -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) src_libisofs_la_SOURCES = \ - src/tree.h \ - src/tree.c \ - src/image.h + src/node.h \ + src/node.c \ + src/image.h \ + src/fsource.h \ + src/fs_local.c \ + src/stream.h libinclude_HEADERS = \ src/libisofs.h diff --git a/TODO b/TODO index 1a1259e..fc794bc 100644 --- a/TODO +++ b/TODO @@ -6,6 +6,8 @@ TODO ==== #00001 (tree.h) -> consider adding new timestamps to IsoTreeNode +#00002 (tree.h) -> handle deletion of each kind of node +#00003 make error.h header public FIXME ===== diff --git a/src/error.h b/src/error.h new file mode 100644 index 0000000..306e6ea --- /dev/null +++ b/src/error.h @@ -0,0 +1,21 @@ +/* + * 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. + */ +#ifndef LIBISO_ERROR_H_ +#define LIBISO_ERROR_H_ + +/* + * Return values for libisofs functions, mainly error codes + * TODO #00003 make this header public + */ + +#define ISO_SUCCESS 1 +#define ISO_NULL_POINTER -1 + + + +#endif /*LIBISO_ERROR_H_*/ diff --git a/src/tree.c b/src/fs_local.c similarity index 64% rename from src/tree.c rename to src/fs_local.c index c35d53f..d335439 100644 --- a/src/tree.c +++ b/src/fs_local.c @@ -6,13 +6,10 @@ * published by the Free Software Foundation. See COPYING file for details. */ -#include "tree.h" -#include "libisofs.h" - - -/** - * Increments the reference counting of the given node. + +/* + * Filesystem/FileSource implementation to access the local filesystem. */ -void iso_node_ref(IsoTreeNode *node) { - node->refcount++; -} + +#include "fsource.h" + diff --git a/src/fsource.h b/src/fsource.h new file mode 100644 index 0000000..0aef81f --- /dev/null +++ b/src/fsource.h @@ -0,0 +1,97 @@ +/* + * 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. + */ + +#ifndef LIBISO_FSOURCE_H_ +#define LIBISO_FSOURCE_H_ + +/* + * Definitions for the file sources. + */ + +/* + * Some functions here will be moved to libisofs.h when we expose + * Sources. + */ + +#include + +typedef struct Iso_File_Source IsoFileSource; +typedef struct Iso_Filesystem IsoFilesystem; + +struct Iso_Filesystem +{ + + /** + * + * @return + * 1 on success, < 0 on error + */ + int (*get_root)(IsoFilesystem *fs, IsoFileSource *root); + + +}; + +struct Iso_File_Source +{ + + /** + * + * @return + * 1 success, < 0 error + */ + int (*lstat)(IsoFileSource *src, struct stat *info); + + //stat? + + /** + * Opens the source. + * @return 1 on success, < 0 on error + */ + int (*open)(IsoFileSource *src); + + + void (*close)(IsoFileSource *src); + + /** + * Attempts to read up to count bytes from the given source into + * the buffer starting at buf. + * + * The file src must be open() before calling this, and close() when no + * more needed. Not valid for dirs. On symlinks it reads the destination + * file. + * + * @return + * number of bytes read, 0 if EOF, < 0 on error + */ + int (*read)(IsoFileSource *src, void *buf, size_t count); + + /** + * Read a directory. + * + * Each call to this function will return a new children, until we reach + * the end of file (i.e, no more children), in that case it returns 0. + * + * The dir must be open() before calling this, and close() when no more + * needed. Only valid for dirs. + * + * @param child + * pointer to be filled with the given child. Undefined on error or OEF + * @return + * 1 on success, 0 if EOF (no more children), < 0 on error + */ + int (*readdir)(IsoFileSource *src, IsoFileSource **child); + + /** + * + */ + int (*readlink)(IsoFileSource *src, char *buf, size_t bufsiz); + +}; + + +#endif /*LIBISO_FSOURCE_H_*/ diff --git a/src/libisofs.h b/src/libisofs.h index 234ca11..bb369ab 100644 --- a/src/libisofs.h +++ b/src/libisofs.h @@ -8,12 +8,33 @@ #ifndef LIBISO_LIBISOFS_H_ #define LIBISO_LIBISOFS_H_ -typedef struct Iso_Tree_Node IsoTreeNode; +typedef struct Iso_Node IsoNode; +typedef struct Iso_Dir IsoDir; /** * Increments the reference counting of the given node. */ -void iso_node_ref(IsoTreeNode *node); +void iso_node_ref(IsoNode *node); +/** + * Decrements the reference couting of the given node. + * If it reach 0, the node is free, and, if the node is a directory, + * its children will be unref() too. + */ +void iso_node_unref(IsoNode *node); + +/** + * Set the name of a node. + * + * @param name The name in UTF-8 encoding + */ +void iso_node_set_name(IsoNode *node, const char *name); + +/** + * Get the name of a node (in UTF-8). + * The returned string belongs to the node and should not be modified nor + * freed. Use strdup if you really need your own copy. + */ +const char *iso_node_get_name(IsoNode *node); #endif /*LIBISO_LIBISOFS_H_*/ diff --git a/src/node.c b/src/node.c new file mode 100644 index 0000000..4299741 --- /dev/null +++ b/src/node.c @@ -0,0 +1,56 @@ +/* + * 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 "node.h" +#include "libisofs.h" + +#include +#include + +/** + * Increments the reference counting of the given node. + */ +void iso_node_ref(IsoNode *node) +{ + ++node->refcount; +} + +/** + * Decrements the reference couting of the given node. + * If it reach 0, the node is free, and, if the node is a directory, + * its children will be unref() too. + */ +void iso_node_unref(IsoNode *node) +{ + if (--node->refcount == 0) { + /* TODO #00002 handle deletion of each kind of node */ + free(node->name); + free(node); + } +} + +/** + * Set the name of a node. + * + * @param name The name in UTF-8 encoding + */ +void iso_node_set_name(IsoNode *node, const char *name) +{ + free(node->name); + node->name = strdup(name); +} + +/** + * Get the name of a node (in UTF-8). + * The returned string belongs to the node and should not be modified nor + * freed. Use strdup if you really need your own copy. + */ +const char *iso_node_get_name(IsoNode *node) +{ + return node->name; +} diff --git a/src/tree.h b/src/node.h similarity index 70% rename from src/tree.h rename to src/node.h index 0636200..11da0c9 100644 --- a/src/tree.h +++ b/src/node.h @@ -5,8 +5,8 @@ * 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. */ -#ifndef LIBISO_TREE_H_ -#define LIBISO_TREE_H_ +#ifndef LIBISO_NODE_H_ +#define LIBISO_NODE_H_ /* * Definitions for the public iso tree @@ -19,9 +19,9 @@ #include /** - * The type of an IsoTreeNode. + * The type of an IsoNode. */ -enum IsoTreeNodeType { +enum IsoNodeType { LIBISO_DIR, LIBISO_FILE, LIBISO_SYMLINK, @@ -32,18 +32,19 @@ enum IsoTreeNodeType { /** * */ -struct Iso_Tree_Node { +struct Iso_Node +{ /* * Initilized to 1, originally owned by user, until added to another node. * Then it is owned by the parent node, so the user must take his own ref * if needed. With the exception of the creation functions, none of the - * other libisofs functions that return an IsoTreeNode increment its + * other libisofs functions that return an IsoNode increment its * refcount. This is responsablity of the client, if (s)he needs it. */ int refcount; - /**< Type of the IsoTreeNode, do not confuse with mode */ - enum IsoTreeNodeType type; + /**< Type of the IsoNode, do not confuse with mode */ + enum IsoNodeType type; char *name; /**< Real name, supossed to be in UTF-8 */ @@ -63,18 +64,29 @@ struct Iso_Tree_Node { * It is a circular list where the last child points to the first * and viceversa. */ - IsoTreeNode *prev; - IsoTreeNode *next; + IsoNode *prev; + IsoNode *next; }; -struct IsoDir { - IsoTreeNode node; +struct Iso_Dir +{ + IsoNode node; size_t nchildren; /**< The number of children of this directory. */ - struct IsoTreeNode *children; /**< list of children. ptr to first child */ + struct IsoNode *children; /**< list of children. ptr to first child */ }; -//void iso_node_unref(IsoTreeNode *node); +struct Iso_File +{ + IsoNode node; + + /** + * It sorts the order in which the file data is written to the CD image. + * Higher weighting filesare written at the beginning of image + */ + int sort_weight; + +}; -#endif /*TREE_H_*/ +#endif /*LIBISO_NODE_H_*/ diff --git a/src/stream.h b/src/stream.h new file mode 100644 index 0000000..6c20479 --- /dev/null +++ b/src/stream.h @@ -0,0 +1,44 @@ +/* + * 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. + */ +#ifndef LIBISO_STREAM_H_ +#define LIBISO_STREAM_H_ + +/* + * Definitions of streams. + */ + +/* + * Some functions here will be moved to libisofs.h when we expose + * Streams. + */ + +typedef struct Iso_Stream IsoStream; + +struct Iso_Stream +{ + /** + * Opens the stream. + * @return 1 on success, < 0 on error + */ + int (*open)(IsoStream *stream); + + /** + * Close the Stream. + */ + void (*close)(IsoStream *stream); + + // Stream should read in 2k blocks! + //... + + int refcount; + + + +} + +#endif /*STREAM_H_*/ diff --git a/test/iso.c b/test/iso.c index 9fa0890..d257f89 100644 --- a/test/iso.c +++ b/test/iso.c @@ -11,6 +11,6 @@ int main(int argc, char **argv) { - IsoTreeNode *node; + IsoNode *node; } \ No newline at end of file