Implement iso_file_get_old_image_sections() and deprecate old way to obtain image lba.

This commit is contained in:
Vreixo Formoso 2008-08-19 02:01:42 +02:00
parent 87f08d27ac
commit 3a503a3e85
4 changed files with 116 additions and 39 deletions

View File

@ -2889,3 +2889,54 @@ int iso_read_image_features_has_eltorito(IsoReadImageFeatures *f)
{
return f->hasElTorito;
}
/**
* Get the start addresses and the sizes of the data extents of a file node
* if it was imported from an old image.
*
* @param file
* The file
* @param section_count
* Returns the number of extent entries in sections arrays
* @param sections
* Returns the array of file sections. Apply free() to dispose it.
* @param flag
* Reserved for future usage, submit 0
* @return
* 1 if there are valid extents (file comes from old image),
* 0 if file was newly added, i.e. it does not come from an old image,
* < 0 error
*/
int iso_file_get_old_image_sections(IsoFile *file, int *section_count,
struct iso_file_section **sections,
int flag)
{
if (file == NULL || section_count == NULL || sections == NULL) {
return ISO_NULL_POINTER;
}
if (flag != 0) {
return ISO_WRONG_ARG_VALUE;
}
if (file->from_old_session != 0) {
/*
* When file is from old session, we retrieve the original IsoFileSource
* to get the sections. This break encapsultation, but safes memory as
* we don't need to store the sections in the IsoFile node.
*/
FSrcStreamData *data = file->stream->data;
ImageFileSourceData *ifsdata = data->src->data;
*section_count = ifsdata->nsections;
*sections = malloc(ifsdata->nsections *
sizeof(struct iso_file_section));
if (*sections == NULL) {
return ISO_OUT_OF_MEM;
}
memcpy(*sections, ifsdata->sections,
ifsdata->nsections * sizeof(struct iso_file_section));
return 1;
}
return 0;
}

View File

@ -2533,9 +2533,35 @@ IsoStream *iso_file_get_stream(IsoFile *file);
* added, i.e. it does not come from an old image, < 0 error
*
* @since 0.6.4
*
* @deprecated Use iso_file_get_old_image_sections(), as this function does
* not work with multi-extend files.
*/
int iso_file_get_old_image_lba(IsoFile *file, uint32_t *lba, int flag);
/**
* Get the start addresses and the sizes of the data extents of a file node
* if it was imported from an old image.
*
* @param file
* The file
* @param section_count
* Returns the number of extent entries in sections arrays
* @param sections
* Returns the array of file sections. Apply free() to dispose it.
* @param flag
* Reserved for future usage, submit 0
* @return
* 1 if there are valid extents (file comes from old image),
* 0 if file was newly added, i.e. it does not come from an old image,
* < 0 error
*
* @since 0.6.8
*/
int iso_file_get_old_image_sections(IsoFile *file, int *section_count,
struct iso_file_section **sections,
int flag);
/*
* Like iso_file_get_old_image_lba(), but take an IsoNode.
*

View File

@ -1,8 +1,8 @@
/*
* 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
*
* 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.
*/
@ -19,16 +19,6 @@ ino_t serial_id = (ino_t)1;
ino_t mem_serial_id = (ino_t)1;
ino_t cut_out_serial_id = (ino_t)1;
typedef struct
{
IsoFileSource *src;
/* key for file identification inside filesystem */
dev_t dev_id;
ino_t ino_id;
off_t size; /**< size of this file */
} FSrcStreamData;
static
int fsrc_open(IsoStream *stream)
{
@ -116,7 +106,7 @@ void fsrc_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
{
FSrcStreamData *data;
IsoFilesystem *fs;
data = (FSrcStreamData*)stream->data;
fs = iso_file_source_get_filesystem(data->src);
@ -164,7 +154,7 @@ int iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream)
if (S_ISDIR(info.st_mode)) {
return ISO_FILE_IS_DIR;
}
/* check for read access to contents */
r = iso_file_source_access(src);
if (r < 0) {
@ -184,7 +174,7 @@ int iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream)
/* take the ref to IsoFileSource */
data->src = src;
data->size = info.st_size;
/* get the id numbers */
{
IsoFilesystem *fs;
@ -193,7 +183,7 @@ int iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream)
fs_id = fs->get_id(fs);
if (fs_id == 0) {
/*
/*
* the filesystem implementation is unable to provide valid
* st_dev and st_ino fields. Use serial_id.
*/
@ -232,11 +222,11 @@ int cut_out_open(IsoStream *stream)
struct stat info;
IsoFileSource *src;
struct cut_out_stream *data;
if (stream == NULL) {
return ISO_NULL_POINTER;
}
data = stream->data;
src = data->src;
ret = iso_file_source_stat(data->src, &info);
@ -247,7 +237,7 @@ int cut_out_open(IsoStream *stream)
if (ret < 0) {
return ret;
}
{
off_t ret;
if (data->offset > info.st_size) {
@ -310,7 +300,7 @@ void cut_out_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
{
FSrcStreamData *data;
IsoFilesystem *fs;
data = (FSrcStreamData*)stream->data;
fs = iso_file_source_get_filesystem(data->src);
@ -339,7 +329,7 @@ IsoStreamIface cut_out_stream_class = {
cut_out_free
};
int iso_cut_out_stream_new(IsoFileSource *src, off_t offset, off_t size,
int iso_cut_out_stream_new(IsoFileSource *src, off_t offset, off_t size,
IsoStream **stream)
{
int r;
@ -364,7 +354,7 @@ int iso_cut_out_stream_new(IsoFileSource *src, off_t offset, off_t size,
if (offset > info.st_size) {
return ISO_FILE_OFFSET_TOO_BIG;
}
/* check for read access to contents */
r = iso_file_source_access(src);
if (r < 0) {
@ -384,10 +374,10 @@ int iso_cut_out_stream_new(IsoFileSource *src, off_t offset, off_t size,
/* take a new ref to IsoFileSource */
data->src = src;
iso_file_source_ref(src);
data->offset = offset;
data->size = MIN(info.st_size - offset, size);
/* get the id numbers */
data->dev_id = (dev_t) 0;
data->ino_id = cut_out_serial_id++;
@ -461,15 +451,15 @@ int mem_read(IsoStream *stream, void *buf, size_t count)
return ISO_WRONG_ARG_VALUE;
}
data = stream->data;
if (data->offset == -1) {
return ISO_FILE_NOT_OPENED;
}
if (data->offset >= data->size) {
return 0; /* EOF */
}
len = MIN(count, data->size - data->offset);
memcpy(buf, data->buf + data->offset, len);
data->offset += len;
@ -517,7 +507,7 @@ IsoStreamIface mem_stream_class = {
/**
* Create a stream for reading from a arbitrary memory buffer.
* When the Stream refcount reach 0, the buffer is free(3).
*
*
* @return
* 1 sucess, < 0 error
*/
@ -607,7 +597,7 @@ void iso_stream_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
void iso_stream_get_file_name(IsoStream *stream, char *name)
{
char *type = stream->class->type;
if (!strncmp(type, "fsrc", 4)) {
FSrcStreamData *data = stream->data;
char *path = iso_file_source_get_path(data->src);

View File

@ -1,8 +1,8 @@
/*
* 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
*
* 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_
@ -13,9 +13,19 @@
*/
#include "fsource.h"
typedef struct
{
IsoFileSource *src;
/* key for file identification inside filesystem */
dev_t dev_id;
ino_t ino_id;
off_t size; /**< size of this file */
} FSrcStreamData;
/**
* Get an identifier for the file of the source, for debug purposes
* @param name
* @param name
* Should provide at least PATH_MAX bytes
*/
void iso_stream_get_file_name(IsoStream *stream, char *name);
@ -25,28 +35,28 @@ void iso_stream_get_file_name(IsoStream *stream, char *name);
* The stream will take the ref. to the IsoFileSource, so after a successfully
* exectution of this function, you musn't unref() the source, unless you
* take an extra ref.
*
*
* @return
* 1 sucess, < 0 error
* Possible errors:
*
*
*/
int iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream);
/**
* Create a new stream to read a chunk of an IsoFileSource..
* The stream will add a ref. to the IsoFileSource.
*
*
* @return
* 1 sucess, < 0 error
*/
int iso_cut_out_stream_new(IsoFileSource *src, off_t offset, off_t size,
int iso_cut_out_stream_new(IsoFileSource *src, off_t offset, off_t size,
IsoStream **stream);
/**
* Create a stream for reading from a arbitrary memory buffer.
* When the Stream refcount reach 0, the buffer is free(3).
*
*
* @return
* 1 sucess, < 0 error
*/