Compare commits
3 Commits
da00291519
...
011e2e85e6
Author | SHA1 | Date |
---|---|---|
Thomas Schmitt | 011e2e85e6 | |
Thomas Schmitt | f457a4f8b9 | |
Thomas Schmitt | 2af17490a0 |
|
@ -961,18 +961,18 @@ off_t ifs_lseek(IsoFileSource *src, off_t offset, int flag)
|
||||||
ImageFileSourceData *data;
|
ImageFileSourceData *data;
|
||||||
|
|
||||||
if (src == NULL) {
|
if (src == NULL) {
|
||||||
return (off_t)ISO_NULL_POINTER;
|
return (off_t)((int) ISO_NULL_POINTER);
|
||||||
}
|
}
|
||||||
if (offset < (off_t)0) {
|
if (offset < (off_t)0) {
|
||||||
return (off_t)ISO_WRONG_ARG_VALUE;
|
return (off_t)((int) ISO_WRONG_ARG_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
data = src->data;
|
data = src->data;
|
||||||
|
|
||||||
if (!data->opened) {
|
if (!data->opened) {
|
||||||
return (off_t)ISO_FILE_NOT_OPENED;
|
return (off_t)((int) ISO_FILE_NOT_OPENED);
|
||||||
} else if (data->opened != 1) {
|
} else if (data->opened != 1) {
|
||||||
return (off_t)ISO_FILE_IS_DIR;
|
return (off_t)((int) ISO_FILE_IS_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (flag) {
|
switch (flag) {
|
||||||
|
@ -987,7 +987,7 @@ off_t ifs_lseek(IsoFileSource *src, off_t offset, int flag)
|
||||||
data->data.offset = data->info.st_size + offset;
|
data->data.offset = data->info.st_size + offset;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return (off_t)ISO_WRONG_ARG_VALUE;
|
return (off_t)((int) ISO_WRONG_ARG_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -337,7 +337,7 @@ off_t lfs_lseek(IsoFileSource *src, off_t offset, int flag)
|
||||||
int whence;
|
int whence;
|
||||||
|
|
||||||
if (src == NULL) {
|
if (src == NULL) {
|
||||||
return (off_t)ISO_NULL_POINTER;
|
return (off_t)((int) ISO_NULL_POINTER);
|
||||||
}
|
}
|
||||||
switch (flag) {
|
switch (flag) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -347,7 +347,7 @@ off_t lfs_lseek(IsoFileSource *src, off_t offset, int flag)
|
||||||
case 2:
|
case 2:
|
||||||
whence = SEEK_END; break;
|
whence = SEEK_END; break;
|
||||||
default:
|
default:
|
||||||
return (off_t)ISO_WRONG_ARG_VALUE;
|
return (off_t)((int) ISO_WRONG_ARG_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
data = src->data;
|
data = src->data;
|
||||||
|
@ -360,19 +360,19 @@ off_t lfs_lseek(IsoFileSource *src, off_t offset, int flag)
|
||||||
/* error on read */
|
/* error on read */
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
case ESPIPE:
|
case ESPIPE:
|
||||||
ret = (off_t)ISO_FILE_ERROR;
|
ret = (off_t)((int) ISO_FILE_ERROR);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ret = (off_t)ISO_ERROR;
|
ret = (off_t)((int) ISO_ERROR);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
case 2: /* directory */
|
case 2: /* directory */
|
||||||
return (off_t)ISO_FILE_IS_DIR;
|
return (off_t)((int) ISO_FILE_IS_DIR);
|
||||||
default:
|
default:
|
||||||
return (off_t)ISO_FILE_NOT_OPENED;
|
return (off_t)((int) ISO_FILE_NOT_OPENED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Vreixo Formoso
|
* Copyright (c) 2007 Vreixo Formoso
|
||||||
|
* Copyright (c) 2022 Thomas Schmitt
|
||||||
*
|
*
|
||||||
* This file is part of the libisofs project; you can redistribute it and/or
|
* 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
|
* modify it under the terms of the GNU General Public License version 2
|
||||||
|
@ -133,3 +134,59 @@ int iso_file_source_get_aa_string(IsoFileSource *src,
|
||||||
return src->class->get_aa_string(src, aa_string, flag);
|
return src->class->get_aa_string(src, aa_string, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Determine whether src is random-access readable and return its capacity.
|
||||||
|
@flag bit0= Open and close src
|
||||||
|
@return <0 iso_file_source_lseek failed , >= 0 readable capacity
|
||||||
|
*/
|
||||||
|
off_t iso_file_source_lseek_capacity(IsoFileSource *src, int flag)
|
||||||
|
{
|
||||||
|
int ret, opened = 0;
|
||||||
|
off_t end, old, reset;
|
||||||
|
struct stat info;
|
||||||
|
|
||||||
|
ret = iso_file_source_stat(src, &info);
|
||||||
|
if (ret < 0) {
|
||||||
|
end = -1;
|
||||||
|
goto ex;
|
||||||
|
}
|
||||||
|
if (S_ISDIR(info.st_mode) || S_ISLNK(info.st_mode) ||
|
||||||
|
S_ISFIFO(info.st_mode) || S_ISSOCK(info.st_mode)) {
|
||||||
|
/* open(2) on fifo can block and have side effects.
|
||||||
|
Active Unix sockets have not been tested but they make as few sense
|
||||||
|
as directories or symbolic links.
|
||||||
|
*/
|
||||||
|
end = -1;
|
||||||
|
goto ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag & 1) {
|
||||||
|
ret = iso_file_source_open(src);
|
||||||
|
if (ret < 0) {
|
||||||
|
end = -1;
|
||||||
|
goto ex;
|
||||||
|
}
|
||||||
|
opened = 1;
|
||||||
|
}
|
||||||
|
old = iso_file_source_lseek(src, 0, 1);
|
||||||
|
if (old < 0) {
|
||||||
|
end = -1;
|
||||||
|
goto ex;
|
||||||
|
}
|
||||||
|
end = iso_file_source_lseek(src, 0, 2);
|
||||||
|
if (end < 0) {
|
||||||
|
end = -1;
|
||||||
|
goto ex;
|
||||||
|
}
|
||||||
|
reset = iso_file_source_lseek(src, old, 0);
|
||||||
|
if (reset != old) {
|
||||||
|
end = -1;
|
||||||
|
goto ex;
|
||||||
|
}
|
||||||
|
ex:;
|
||||||
|
if (opened) {
|
||||||
|
iso_file_source_close(src);
|
||||||
|
}
|
||||||
|
return end;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Vreixo Formoso
|
* Copyright (c) 2007 Vreixo Formoso
|
||||||
* Copyright (c) 2009 - 2016 Thomas Schmitt
|
* Copyright (c) 2009 - 2022 Thomas Schmitt
|
||||||
*
|
*
|
||||||
* This file is part of the libisofs project; you can redistribute it and/or
|
* 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
|
* modify it under the terms of the GNU General Public License version 2
|
||||||
|
@ -49,4 +49,10 @@ int iso_ifs_source_clone(IsoFileSource *old_source, IsoFileSource **new_source,
|
||||||
int flag);
|
int flag);
|
||||||
|
|
||||||
|
|
||||||
|
/* Determine whether src is random-access readable and return its capacity.
|
||||||
|
@return -1 iso_file_source_lseek failed , >= 0 readable capacity
|
||||||
|
*/
|
||||||
|
off_t iso_file_source_lseek_capacity(IsoFileSource *src, int flag);
|
||||||
|
|
||||||
|
|
||||||
#endif /*LIBISO_FSOURCE_H_*/
|
#endif /*LIBISO_FSOURCE_H_*/
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007-2008 Vreixo Formoso, Mario Danic
|
* Copyright (c) 2007-2008 Vreixo Formoso, Mario Danic
|
||||||
* Copyright (c) 2009-2021 Thomas Schmitt
|
* Copyright (c) 2009-2022 Thomas Schmitt
|
||||||
*
|
*
|
||||||
* This file is part of the libisofs project; you can redistribute it and/or
|
* 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
|
* modify it under the terms of the GNU General Public License version 2
|
||||||
|
@ -6349,8 +6349,9 @@ int iso_tree_add_new_node(IsoImage *image, IsoDir *parent, const char *name,
|
||||||
* according to iso_image_set_truncate_mode().
|
* according to iso_image_set_truncate_mode().
|
||||||
* Its directory path depends on the parent node.
|
* Its directory path depends on the parent node.
|
||||||
* @param path
|
* @param path
|
||||||
* The absolute path of the file in the local filesystem. For now
|
* The absolute path of the random-access capable file in the local
|
||||||
* only regular files and symlinks to regular files are supported.
|
* filesystem. Only regular files and device files are supported.
|
||||||
|
* On Linux, only regular files and block device offer random-access.
|
||||||
* @param offset
|
* @param offset
|
||||||
* Byte number in the given file from where to start reading data.
|
* Byte number in the given file from where to start reading data.
|
||||||
* @param size
|
* @param size
|
||||||
|
@ -6368,8 +6369,11 @@ int iso_tree_add_new_node(IsoImage *image, IsoDir *parent, const char *name,
|
||||||
* ISO_NODE_NAME_NOT_UNIQUE, a node with same name already exists
|
* ISO_NODE_NAME_NOT_UNIQUE, a node with same name already exists
|
||||||
* ISO_OUT_OF_MEM
|
* ISO_OUT_OF_MEM
|
||||||
* ISO_RR_NAME_TOO_LONG
|
* ISO_RR_NAME_TOO_LONG
|
||||||
|
* ISO_WRONG_ARG_VALUE, if path is not suitable for random access
|
||||||
*
|
*
|
||||||
* @since 0.6.4
|
* @since 0.6.4
|
||||||
|
*
|
||||||
|
* Device files as path: @since 1.5.6
|
||||||
*/
|
*/
|
||||||
int iso_tree_add_new_cut_out_node(IsoImage *image, IsoDir *parent,
|
int iso_tree_add_new_cut_out_node(IsoImage *image, IsoDir *parent,
|
||||||
const char *name, const char *path,
|
const char *name, const char *path,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Vreixo Formoso
|
* Copyright (c) 2007 Vreixo Formoso
|
||||||
* Copyright (c) 2009 - 2015 Thomas Schmitt
|
* Copyright (c) 2009 - 2022 Thomas Schmitt
|
||||||
*
|
*
|
||||||
* This file is part of the libisofs project; you can redistribute it and/or
|
* 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
|
* modify it under the terms of the GNU General Public License version 2
|
||||||
|
@ -330,6 +330,7 @@ int cut_out_open(IsoStream *stream)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct stat info;
|
struct stat info;
|
||||||
|
off_t src_size, pos;
|
||||||
IsoFileSource *src;
|
IsoFileSource *src;
|
||||||
struct cut_out_stream *data;
|
struct cut_out_stream *data;
|
||||||
|
|
||||||
|
@ -348,20 +349,25 @@ int cut_out_open(IsoStream *stream)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
if (S_ISREG(info.st_mode)) {
|
||||||
off_t ret;
|
src_size= info.st_size;
|
||||||
if (data->offset > info.st_size) {
|
} else {
|
||||||
/* file is smaller than expected */
|
/* Determine src_size and lseekability of device */
|
||||||
ret = iso_file_source_lseek(src, info.st_size, 0);
|
src_size = iso_file_source_lseek_capacity(src, 0);
|
||||||
} else {
|
if (src_size <= 0)
|
||||||
ret = iso_file_source_lseek(src, data->offset, 0);
|
return ISO_WRONG_ARG_VALUE;
|
||||||
}
|
}
|
||||||
if (ret < 0) {
|
if (data->offset > src_size) {
|
||||||
return (int) ret;
|
/* file is smaller than expected */
|
||||||
}
|
pos = iso_file_source_lseek(src, src_size, 0);
|
||||||
|
} else {
|
||||||
|
pos = iso_file_source_lseek(src, data->offset, 0);
|
||||||
|
}
|
||||||
|
if (pos < 0) {
|
||||||
|
return (int) pos;
|
||||||
}
|
}
|
||||||
data->pos = 0;
|
data->pos = 0;
|
||||||
if (data->offset + data->size > info.st_size) {
|
if (data->offset + data->size > src_size) {
|
||||||
return 3; /* file smaller than expected */
|
return 3; /* file smaller than expected */
|
||||||
} else {
|
} else {
|
||||||
return ISO_SUCCESS;
|
return ISO_SUCCESS;
|
||||||
|
@ -508,6 +514,7 @@ int iso_cut_out_stream_new(IsoFileSource *src, off_t offset, off_t size,
|
||||||
IsoStream **stream)
|
IsoStream **stream)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
off_t src_size;
|
||||||
struct stat info;
|
struct stat info;
|
||||||
IsoStream *str;
|
IsoStream *str;
|
||||||
struct cut_out_stream *data;
|
struct cut_out_stream *data;
|
||||||
|
@ -523,10 +530,16 @@ int iso_cut_out_stream_new(IsoFileSource *src, off_t offset, off_t size,
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
if (!S_ISREG(info.st_mode)) {
|
|
||||||
return ISO_WRONG_ARG_VALUE;
|
if (S_ISREG(info.st_mode)) {
|
||||||
|
src_size = info.st_size;
|
||||||
|
} else {
|
||||||
|
/* Open src, do iso_source_lseek(SEEK_END), close src */
|
||||||
|
src_size = iso_file_source_lseek_capacity(src, 1);
|
||||||
|
if (src_size <= 0)
|
||||||
|
return ISO_WRONG_ARG_VALUE;
|
||||||
}
|
}
|
||||||
if (offset > info.st_size) {
|
if (offset > src_size) {
|
||||||
return ISO_FILE_OFFSET_TOO_BIG;
|
return ISO_FILE_OFFSET_TOO_BIG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,7 +564,7 @@ int iso_cut_out_stream_new(IsoFileSource *src, off_t offset, off_t size,
|
||||||
iso_file_source_ref(src);
|
iso_file_source_ref(src);
|
||||||
|
|
||||||
data->offset = offset;
|
data->offset = offset;
|
||||||
data->size = MIN(info.st_size - offset, size);
|
data->size = MIN(src_size - offset, size);
|
||||||
|
|
||||||
/* get the id numbers */
|
/* get the id numbers */
|
||||||
data->dev_id = (dev_t) 0;
|
data->dev_id = (dev_t) 0;
|
||||||
|
@ -852,12 +865,24 @@ void iso_stream_get_file_name(IsoStream *stream, char *name)
|
||||||
strncpy(name, path, PATH_MAX - 1);
|
strncpy(name, path, PATH_MAX - 1);
|
||||||
name[PATH_MAX - 1] = 0;
|
name[PATH_MAX - 1] = 0;
|
||||||
free(path);
|
free(path);
|
||||||
} else if (!strncmp(type, "boot", 4)) {
|
} else if (!strncmp(type, "cout", 4)) {
|
||||||
strcpy(name, "BOOT CATALOG");
|
strcpy(name, "CUT_OUT FILE");
|
||||||
} else if (!strncmp(type, "mem ", 4)) {
|
} else if (!strncmp(type, "mem ", 4)) {
|
||||||
strcpy(name, "MEM SOURCE");
|
strcpy(name, "MEM SOURCE");
|
||||||
|
} else if (!strncmp(type, "boot", 4)) {
|
||||||
|
strcpy(name, "BOOT CATALOG");
|
||||||
} else if (!strncmp(type, "extf", 4)) {
|
} else if (!strncmp(type, "extf", 4)) {
|
||||||
strcpy(name, "EXTERNAL FILTER");
|
strcpy(name, "EXTERNAL FILTER");
|
||||||
|
} else if (!strncmp(type, "ziso", 4)) {
|
||||||
|
strcpy(name, "ZISOFS COMPRESSION FILTER");
|
||||||
|
} else if (!strncmp(type, "osiz", 4)) {
|
||||||
|
strcpy(name, "ZISOFS DECOMPRESSION FILTER");
|
||||||
|
} else if (!strncmp(type, "gzip", 4)) {
|
||||||
|
strcpy(name, "GZIP COMPRESSION FILTER");
|
||||||
|
} else if (!strncmp(type, "pizg", 4)) {
|
||||||
|
strcpy(name, "GZIP DECOMPRESSION FILTER");
|
||||||
|
} else if (!strncmp(type, "user", 4)) {
|
||||||
|
strcpy(name, "USER SUPPLIED STREAM");
|
||||||
} else {
|
} else {
|
||||||
strcpy(name, "UNKNOWN SOURCE");
|
strcpy(name, "UNKNOWN SOURCE");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Vreixo Formoso
|
* Copyright (c) 2007 Vreixo Formoso
|
||||||
* Copyright (c) 2011 - 2015 Thomas Schmitt
|
* Copyright (c) 2011 - 2022 Thomas Schmitt
|
||||||
*
|
*
|
||||||
* This file is part of the libisofs project; you can redistribute it and/or
|
* 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
|
* modify it under the terms of the GNU General Public License version 2
|
||||||
|
@ -677,6 +677,7 @@ int iso_tree_add_new_cut_out_node(IsoImage *image, IsoDir *parent,
|
||||||
IsoNode **node)
|
IsoNode **node)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
off_t src_size;
|
||||||
struct stat info;
|
struct stat info;
|
||||||
IsoFilesystem *fs;
|
IsoFilesystem *fs;
|
||||||
IsoFileSource *src;
|
IsoFileSource *src;
|
||||||
|
@ -715,17 +716,23 @@ int iso_tree_add_new_cut_out_node(IsoImage *image, IsoDir *parent,
|
||||||
iso_file_source_unref(src);
|
iso_file_source_unref(src);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (!S_ISREG(info.st_mode)) {
|
|
||||||
return ISO_WRONG_ARG_VALUE;
|
if (S_ISREG(info.st_mode)) {
|
||||||
|
src_size = info.st_size;
|
||||||
|
} else {
|
||||||
|
/* Open src, do iso_source_lseek(SEEK_END), close src */
|
||||||
|
src_size = iso_file_source_lseek_capacity(src, 1);
|
||||||
|
if (src_size <= 0)
|
||||||
|
return ISO_WRONG_ARG_VALUE;
|
||||||
}
|
}
|
||||||
if (offset >= info.st_size) {
|
if (offset >= src_size) {
|
||||||
return ISO_WRONG_ARG_VALUE;
|
return ISO_WRONG_ARG_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* force regular file */
|
/* force regular file */
|
||||||
result = image->builder->create_file(image->builder, image, src, &new);
|
result = image->builder->create_file(image->builder, image, src, &new);
|
||||||
|
|
||||||
/* free the file */
|
/* Give up the newly acquired surplus reference to src */
|
||||||
iso_file_source_unref(src);
|
iso_file_source_unref(src);
|
||||||
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
|
|
Loading…
Reference in New Issue