10 changed files with 282 additions and 29 deletions
@ -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_*/ |
@ -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 <sys/stat.h> |
||||
|
||||
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_*/ |
@ -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 <stdlib.h> |
||||
#include <string.h> |
||||
|
||||
/**
|
||||
* 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; |
||||
} |
@ -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_*/ |
Loading…
Reference in new issue