Define interface for IsoDataSource to access existent images.

This commit is contained in:
Vreixo Formoso 2007-12-30 17:47:44 +01:00
parent f9ee153a97
commit 48e243d5da
3 changed files with 153 additions and 1 deletions

View File

@ -39,7 +39,8 @@ src_libisofs_la_SOURCES = \
src/writer.h \
src/buffer.c \
src/rockridge.h \
src/rockridge.c
src/rockridge.c \
src/data_source.c
libinclude_HEADERS = \
src/libisofs.h

56
src/data_source.c Normal file
View File

@ -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 "libisofs.h"
#include "error.h"
#include <stdlib.h>
/**
* Increments the reference counting of the given IsoDataSource.
*/
void iso_data_source_ref(IsoDataSource *src)
{
src->refcount++;
}
/**
* Decrements the reference counting of the given IsoDataSource, freeing it
* if refcount reach 0.
*/
void iso_data_source_unref(IsoDataSource *src)
{
if (--src->refcount == 0) {
src->free_data(src);
free(src);
}
}
/**
* Create a new IsoDataSource from a local file. This is suitable for
* accessing regular .iso images, or to acces drives via its block device
* and standard POSIX I/O calls.
*
* @param path
* The path of the file
* @param src
* Will be filled with the pointer to the newly created data source.
* @return
* 1 on success, < 0 on error.
*/
int iso_data_source_new_from_file(const char *path, IsoDataSource **src)
{
if (path == NULL || src == NULL) {
return ISO_MEM_ERROR;
}
//TODO implement
return -1;
}

View File

@ -135,6 +135,72 @@ typedef struct
// */
} Ecma119WriteOpts;
typedef struct Iso_Data_Source IsoDataSource;
/**
* Data source used by libisofs for reading an existing image.
*
* It offers homogeneous read access to arbitrary blocks to different sources
* for images, such as .iso files, CD/DVD drives, etc...
*
* To create a multisession image, libisofs needs a IsoDataSource, that the
* user must provide. The function iso_data_source_new_from_file() constructs
* an IsoDataSource that uses POSIX I/O functions to access data. You can use
* it with regular .iso images, and also with block devices that represent a
* drive.
*/
struct Iso_Data_Source {
/**
* Reference count for the data source. Should be 1 when a new source
* is created. Don't access it directly, but with iso_data_source_ref()
* and iso_data_source_unref() functions.
*/
unsigned int refcount;
/**
* Opens the given source. You must open() the source before any attempt
* to read data from it. The open is the right place for grabbing the
* underlying resources.
*
* @return
* 1 if success, < 0 on error
*/
int (*open)(IsoDataSource *src);
/**
* Close a given source, freeing all system resources previously grabbed in
* open().
*
* @return
* 1 if success, < 0 on error
*/
int (*close)(IsoDataSource *src);
/**
* Read an arbitrary block (2048 bytes) of data from the source.
*
* @param lba
* Block to be read.
* @param buffer
* Buffer where the data will be written. It should have at least
* 2048 bytes.
* @return
* 1 if success, < 0 on error
*/
int (*read_block)(IsoDataSource *src, int lba, unsigned char *buffer);
/**
* Clean up the source specific data. Never call this directly, it is
* automatically called by iso_data_source_unref() when refcount reach
* 0.
*/
void (*free_data)(IsoDataSource *);
/** Source specific data */
void *data;
};
/**
* Create a new image, empty.
*
@ -149,6 +215,10 @@ typedef struct
*/
int iso_image_new(const char *name, IsoImage **image);
/**
* TODO we should have two "create" methods, one for grow images, another
* for images from scratch. Or we can just have a flag in Ecma119WriteOpts.
*/
int iso_image_create(IsoImage *image, Ecma119WriteOpts *opts,
struct burn_source **burn_src);
@ -830,6 +900,31 @@ int iso_tree_add_dir_rec(IsoImage *image, IsoDir *parent, const char *dir);
*/
int iso_tree_path_to_node(IsoImage *image, const char *path, IsoNode **node);
/**
* Increments the reference counting of the given IsoDataSource.
*/
void iso_data_source_ref(IsoDataSource *src);
/**
* Decrements the reference counting of the given IsoDataSource, freeing it
* if refcount reach 0.
*/
void iso_data_source_unref(IsoDataSource *src);
/**
* Create a new IsoDataSource from a local file. This is suitable for
* accessing regular .iso images, or to acces drives via its block device
* and standard POSIX I/O calls.
*
* @param path
* The path of the file
* @param src
* Will be filled with the pointer to the newly created data source.
* @return
* 1 on success, < 0 on error.
*/
int iso_data_source_new_from_file(const char *path, IsoDataSource **src);
#define ISO_MSGS_MESSAGE_LEN 4096
/**