Define code style formatter for eclipse and apply it to source.

This commit is contained in:
Vreixo Formoso 2007-12-28 22:10:17 +01:00
parent 1ecb735e7c
commit 4c9d83f051
31 changed files with 1018 additions and 1019 deletions

View File

@ -313,6 +313,7 @@
</profile> </profile>
</scannerConfigBuildInfo> </scannerConfigBuildInfo>
</storageModule> </storageModule>
<storageModule moduleId="org.eclipse.cdt.core.language.mapping"/>
</cconfiguration> </cconfiguration>
<cconfiguration id="converted.config.2029700129.1058518760.974771800"> <cconfiguration id="converted.config.2029700129.1058518760.974771800">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="converted.config.2029700129.1058518760.974771800" moduleId="org.eclipse.cdt.core.settings" name="test"> <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="converted.config.2029700129.1058518760.974771800" moduleId="org.eclipse.cdt.core.settings" name="test">
@ -624,6 +625,7 @@
</profile> </profile>
</scannerConfigBuildInfo> </scannerConfigBuildInfo>
</storageModule> </storageModule>
<storageModule moduleId="org.eclipse.cdt.core.language.mapping"/>
</cconfiguration> </cconfiguration>
</storageModule> </storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> <storageModule moduleId="cdtBuildSystem" version="4.0.0">

View File

@ -1,4 +1,4 @@
#Fri Dec 28 17:36:33 CET 2007 #Fri Dec 28 21:07:56 CET 2007
eclipse.preferences.version=1 eclipse.preferences.version=1
indexer/filesToParseUpFront= indexer/filesToParseUpFront=
indexer/indexAllFiles=true indexer/indexAllFiles=true

View File

@ -22,7 +22,8 @@
* the libisofs ring buffer as intermediate memory * the libisofs ring buffer as intermediate memory
*/ */
struct th_data { struct th_data
{
IsoRingBuffer *rbuf; IsoRingBuffer *rbuf;
char *path; char *path;
}; };
@ -37,34 +38,34 @@ void *write_function(void *arg)
int res; int res;
unsigned char tmp[WRITE_CHUNK]; unsigned char tmp[WRITE_CHUNK];
struct th_data *data = (struct th_data *) arg; struct th_data *data = (struct th_data *) arg;
int fd = open(data->path, O_RDONLY); int fd = open(data->path, O_RDONLY);
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "Writer thread error: Can't open file"); fprintf(stderr, "Writer thread error: Can't open file");
iso_ring_buffer_writer_close(data->rbuf); iso_ring_buffer_writer_close(data->rbuf);
pthread_exit(NULL); pthread_exit(NULL);
} }
res = 1; res = 1;
while ( (bytes = read(fd, tmp, WRITE_CHUNK)) > 0 ) { while ( (bytes = read(fd, tmp, WRITE_CHUNK)) > 0) {
res = iso_ring_buffer_write(data->rbuf, tmp, bytes); res = iso_ring_buffer_write(data->rbuf, tmp, bytes);
if (res <= 0) { if (res <= 0) {
break; break;
} }
/* To test premature reader exit >>>>>>>>>>> /* To test premature reader exit >>>>>>>>>>>
iso_ring_buffer_writer_close(data->rbuf); iso_ring_buffer_writer_close(data->rbuf);
pthread_exit(NULL); pthread_exit(NULL);
<<<<<<<<<<<<<<<<<<<<<<<<< */ <<<<<<<<<<<<<<<<<<<<<<<<< */
// if (rand() > 2000000000) { // if (rand() > 2000000000) {
// fprintf(stderr, "Writer sleeping\n"); // fprintf(stderr, "Writer sleeping\n");
// sleep(1); // sleep(1);
// } // }
} }
fprintf(stderr, "Writer finish: %d\n", res); fprintf(stderr, "Writer finish: %d\n", res);
close(fd); close(fd);
iso_ring_buffer_writer_close(data->rbuf); iso_ring_buffer_writer_close(data->rbuf);
pthread_exit(NULL); pthread_exit(NULL);
} }
static static
@ -73,22 +74,22 @@ void *read_function(void *arg)
unsigned char tmp[READ_CHUNK]; unsigned char tmp[READ_CHUNK];
int res = 1; int res = 1;
struct th_data *data = (struct th_data *) arg; struct th_data *data = (struct th_data *) arg;
while ( (res = iso_ring_buffer_read(data->rbuf, tmp, READ_CHUNK)) > 0 ) { while ( (res = iso_ring_buffer_read(data->rbuf, tmp, READ_CHUNK)) > 0) {
write(1, tmp, READ_CHUNK); write(1, tmp, READ_CHUNK);
/* To test premature reader exit >>>>>>>>>>> /* To test premature reader exit >>>>>>>>>>>
iso_ring_buffer_reader_close(data->rbuf); iso_ring_buffer_reader_close(data->rbuf);
pthread_exit(NULL); pthread_exit(NULL);
<<<<<<<<<<<<<<<<<<<<<<<<< */ <<<<<<<<<<<<<<<<<<<<<<<<< */
// if (rand() > 2000000000) { // if (rand() > 2000000000) {
// fprintf(stderr, "Reader sleeping\n"); // fprintf(stderr, "Reader sleeping\n");
// sleep(1); // sleep(1);
// } // }
} }
fprintf(stderr, "Reader finish: %d\n", res); fprintf(stderr, "Reader finish: %d\n", res);
iso_ring_buffer_reader_close(data->rbuf); iso_ring_buffer_reader_close(data->rbuf);
pthread_exit(NULL); pthread_exit(NULL);
} }
@ -103,24 +104,24 @@ int main(int argc, char **argv)
fprintf(stderr, "Usage: catbuffer /path/to/file\n"); fprintf(stderr, "Usage: catbuffer /path/to/file\n");
return 1; return 1;
} }
res = iso_ring_buffer_new(&data.rbuf); res = iso_ring_buffer_new(&data.rbuf);
if (res < 0) { if (res < 0) {
fprintf(stderr, "Can't create buffer\n"); fprintf(stderr, "Can't create buffer\n");
return 1; return 1;
} }
data.path = argv[1]; data.path = argv[1];
res = pthread_create(&writer, NULL, write_function, (void *) &data); res = pthread_create(&writer, NULL, write_function, (void *) &data);
res = pthread_create(&reader, NULL, read_function, (void *) &data); res = pthread_create(&reader, NULL, read_function, (void *) &data);
pthread_join(writer, NULL); pthread_join(writer, NULL);
pthread_join(reader, NULL); pthread_join(reader, NULL);
fprintf(stderr, "Buffer was %d times full and %d times empty.\n", fprintf(stderr, "Buffer was %d times full and %d times empty.\n",
iso_ring_buffer_get_times_full(data.rbuf), iso_ring_buffer_get_times_full(data.rbuf),
iso_ring_buffer_get_times_empty(data.rbuf)); iso_ring_buffer_get_times_empty(data.rbuf));
free(data.rbuf); free(data.rbuf);
return 0; return 0;
} }

91
doc/devel/codestyle.xml Normal file
View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="1">
<profile kind="CodeFormatterProfile" name="nglibisofs" version="1">
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.continuation_indentation" value="2"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.lineSplit" value="80"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
<setting id="org.eclipse.cdt.core.formatter.alignment_for_conditional_expression" value="16"/>
<setting id="org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_switch" value="false"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
<setting id="org.eclipse.cdt.core.formatter.indent_access_specifier_compare_to_type_header" value="false"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_access_specifier" value="true"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
<setting id="org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_namespace_header" value="false"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.tabulation.size" value="4"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.indent_statements_compare_to_body" value="true"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.indent_statements_compare_to_block" value="true"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.indent_empty_lines" value="false"/>
<setting id="org.eclipse.cdt.core.formatter.tabulation.char" value="space"/>
<setting id="org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
<setting id="org.eclipse.cdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.brace_position_for_method_declaration" value="next_line"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.brace_position_for_block_in_case" value="next_line_shifted"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.compact_else_if" value="true"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
<setting id="org.eclipse.cdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
<setting id="org.eclipse.cdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
<setting id="org.eclipse.cdt.core.formatter.alignment_for_arguments_in_method_invocation" value="18"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.alignment_for_parameters_in_method_declaration" value="18"/>
<setting id="org.eclipse.cdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.indentation.size" value="4"/>
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.brace_position_for_namespace_declaration" value="end_of_line"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
<setting id="org.eclipse.cdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_namespace_declaration" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
<setting id="org.eclipse.cdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
<setting id="org.eclipse.cdt.core.formatter.brace_position_for_block" value="end_of_line"/>
<setting id="org.eclipse.cdt.core.formatter.brace_position_for_type_declaration" value="next_line"/>
</profile>
</profiles>

View File

@ -14,7 +14,7 @@
* there's enought space/data at the beginning * there's enought space/data at the beginning
* - pre-buffer for writes < BLOCK_SIZE * - pre-buffer for writes < BLOCK_SIZE
* *
*/ */
#include "buffer.h" #include "buffer.h"
#include "error.h" #include "error.h"
@ -28,26 +28,27 @@
# define MIN(a, b) (((a) < (b)) ? (a) : (b)) # define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif #endif
struct iso_ring_buffer { struct iso_ring_buffer
{
uint8_t buf[BLOCK_SIZE * BUFFER_SIZE]; uint8_t buf[BLOCK_SIZE * BUFFER_SIZE];
/* /*
* Number of bytes available. * Number of bytes available.
*/ */
size_t size; size_t size;
/* position for reading and writing, offset from buf */ /* position for reading and writing, offset from buf */
size_t rpos; size_t rpos;
size_t wpos; size_t wpos;
/* flags to report if read or writer threads ends execution */ /* flags to report if read or writer threads ends execution */
unsigned int rend:1; unsigned int rend :1;
unsigned int wend:1; unsigned int wend :1;
/* just for statistical purposes */ /* just for statistical purposes */
unsigned int times_full; unsigned int times_full;
unsigned int times_empty; unsigned int times_empty;
pthread_mutex_t mutex; pthread_mutex_t mutex;
pthread_cond_t empty; pthread_cond_t empty;
pthread_cond_t full; pthread_cond_t full;
@ -64,30 +65,30 @@ struct iso_ring_buffer {
int iso_ring_buffer_new(IsoRingBuffer **rbuf) int iso_ring_buffer_new(IsoRingBuffer **rbuf)
{ {
IsoRingBuffer *buffer; IsoRingBuffer *buffer;
if (rbuf == NULL) { if (rbuf == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
buffer = malloc(sizeof(IsoRingBuffer)); buffer = malloc(sizeof(IsoRingBuffer));
if (buffer == NULL) { if (buffer == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
buffer->size = 0; buffer->size = 0;
buffer->wpos = 0; buffer->wpos = 0;
buffer->rpos = 0; buffer->rpos = 0;
buffer->times_full = 0; buffer->times_full = 0;
buffer->times_empty = 0; buffer->times_empty = 0;
buffer->rend = buffer->wend = 0; buffer->rend = buffer->wend = 0;
/* init mutex and waiting queues */ /* init mutex and waiting queues */
pthread_mutex_init(&buffer->mutex, NULL); pthread_mutex_init(&buffer->mutex, NULL);
pthread_cond_init(&buffer->empty, NULL); pthread_cond_init(&buffer->empty, NULL);
pthread_cond_init(&buffer->full, NULL); pthread_cond_init(&buffer->full, NULL);
*rbuf = buffer; *rbuf = buffer;
return ISO_SUCCESS; return ISO_SUCCESS;
} }
@ -118,15 +119,15 @@ int iso_ring_buffer_write(IsoRingBuffer *buf, uint8_t *data, size_t count)
{ {
size_t len; size_t len;
int bytes_write = 0; int bytes_write = 0;
if (buf == NULL || data == NULL) { if (buf == NULL || data == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
while (bytes_write < count) { while (bytes_write < count) {
pthread_mutex_lock(&buf->mutex); pthread_mutex_lock(&buf->mutex);
while (buf->size == BUFFER_CAPACITY) { while (buf->size == BUFFER_CAPACITY) {
/* /*
@ -134,7 +135,7 @@ int iso_ring_buffer_write(IsoRingBuffer *buf, uint8_t *data, size_t count)
* Thus, the while(buf->size == BUFFER_CAPACITY) is used here * Thus, the while(buf->size == BUFFER_CAPACITY) is used here
* only to propertly detect the reader has been cancelled * only to propertly detect the reader has been cancelled
*/ */
if (buf->rend) { if (buf->rend) {
/* the read procces has been finished */ /* the read procces has been finished */
pthread_mutex_unlock(&buf->mutex); pthread_mutex_unlock(&buf->mutex);
@ -144,7 +145,7 @@ int iso_ring_buffer_write(IsoRingBuffer *buf, uint8_t *data, size_t count)
/* wait until space available */ /* wait until space available */
pthread_cond_wait(&buf->full, &buf->mutex); pthread_cond_wait(&buf->full, &buf->mutex);
} }
len = MIN(count - bytes_write, BUFFER_CAPACITY - buf->size); len = MIN(count - bytes_write, BUFFER_CAPACITY - buf->size);
if (buf->wpos + len > BUFFER_CAPACITY) { if (buf->wpos + len > BUFFER_CAPACITY) {
len = BUFFER_CAPACITY - buf->wpos; len = BUFFER_CAPACITY - buf->wpos;
@ -153,7 +154,7 @@ int iso_ring_buffer_write(IsoRingBuffer *buf, uint8_t *data, size_t count)
buf->wpos = (buf->wpos + len) % (BUFFER_CAPACITY); buf->wpos = (buf->wpos + len) % (BUFFER_CAPACITY);
bytes_write += len; bytes_write += len;
buf->size += len; buf->size += len;
/* wake up reader */ /* wake up reader */
pthread_cond_signal(&buf->empty); pthread_cond_signal(&buf->empty);
pthread_mutex_unlock(&buf->mutex); pthread_mutex_unlock(&buf->mutex);
@ -174,14 +175,14 @@ int iso_ring_buffer_read(IsoRingBuffer *buf, uint8_t *dest, size_t count)
{ {
size_t len; size_t len;
int bytes_read = 0; int bytes_read = 0;
if (buf == NULL || dest == NULL) { if (buf == NULL || dest == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
while (bytes_read < count) { while (bytes_read < count) {
pthread_mutex_lock(&buf->mutex); pthread_mutex_lock(&buf->mutex);
while (buf->size == 0) { while (buf->size == 0) {
/* /*
* Note. There's only a reader, so we have no race conditions. * Note. There's only a reader, so we have no race conditions.
@ -189,7 +190,7 @@ int iso_ring_buffer_read(IsoRingBuffer *buf, uint8_t *dest, size_t count)
* a reader detects the EOF propertly if the writer has been * a reader detects the EOF propertly if the writer has been
* canceled while the reader was waiting * canceled while the reader was waiting
*/ */
if (buf->wend) { if (buf->wend) {
/* the writer procces has been finished */ /* the writer procces has been finished */
pthread_mutex_unlock(&buf->mutex); pthread_mutex_unlock(&buf->mutex);
@ -199,7 +200,7 @@ int iso_ring_buffer_read(IsoRingBuffer *buf, uint8_t *dest, size_t count)
/* wait until data available */ /* wait until data available */
pthread_cond_wait(&buf->empty, &buf->mutex); pthread_cond_wait(&buf->empty, &buf->mutex);
} }
len = MIN(count - bytes_read, buf->size); len = MIN(count - bytes_read, buf->size);
if (buf->rpos + len > BUFFER_CAPACITY) { if (buf->rpos + len > BUFFER_CAPACITY) {
len = BUFFER_CAPACITY - buf->rpos; len = BUFFER_CAPACITY - buf->rpos;
@ -208,7 +209,7 @@ int iso_ring_buffer_read(IsoRingBuffer *buf, uint8_t *dest, size_t count)
buf->rpos = (buf->rpos + len) % (BUFFER_CAPACITY); buf->rpos = (buf->rpos + len) % (BUFFER_CAPACITY);
bytes_read += len; bytes_read += len;
buf->size -= len; buf->size -= len;
/* wake up the writer */ /* wake up the writer */
pthread_cond_signal(&buf->full); pthread_cond_signal(&buf->full);
pthread_mutex_unlock(&buf->mutex); pthread_mutex_unlock(&buf->mutex);
@ -220,7 +221,7 @@ void iso_ring_buffer_writer_close(IsoRingBuffer *buf)
{ {
pthread_mutex_lock(&buf->mutex); pthread_mutex_lock(&buf->mutex);
buf->wend = 1; buf->wend = 1;
/* ensure no reader is waiting */ /* ensure no reader is waiting */
pthread_cond_signal(&buf->empty); pthread_cond_signal(&buf->empty);
pthread_mutex_unlock(&buf->mutex); pthread_mutex_unlock(&buf->mutex);
@ -230,7 +231,7 @@ void iso_ring_buffer_reader_close(IsoRingBuffer *buf)
{ {
pthread_mutex_lock(&buf->mutex); pthread_mutex_lock(&buf->mutex);
buf->rend = 1; buf->rend = 1;
/* ensure no writer is waiting */ /* ensure no writer is waiting */
pthread_cond_signal(&buf->full); pthread_cond_signal(&buf->full);
pthread_mutex_unlock(&buf->mutex); pthread_mutex_unlock(&buf->mutex);

View File

@ -31,29 +31,29 @@ void iso_node_builder_unref(IsoNodeBuilder *builder)
} }
static static
int default_create_file(IsoNodeBuilder *builder, IsoImage *image, int default_create_file(IsoNodeBuilder *builder, IsoImage *image,
IsoFileSource *src, IsoFile **file) IsoFileSource *src, IsoFile **file)
{ {
int res; int res;
struct stat info; struct stat info;
IsoStream *stream; IsoStream *stream;
IsoFile *node; IsoFile *node;
if (builder == NULL || src == NULL || file == NULL) { if (builder == NULL || src == NULL || file == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
res = iso_file_source_stat(src, &info); res = iso_file_source_stat(src, &info);
if (res < 0) { if (res < 0) {
return res; return res;
} }
/* this will fail if src is a dir, is not accessible... */ /* this will fail if src is a dir, is not accessible... */
res = iso_file_source_stream_new(src, &stream); res = iso_file_source_stream_new(src, &stream);
if (res < 0) { if (res < 0) {
return res; return res;
} }
node = malloc(sizeof(IsoFile)); node = malloc(sizeof(IsoFile));
if (node == NULL) { if (node == NULL) {
/* the stream has taken our ref to src, so we need to add one */ /* the stream has taken our ref to src, so we need to add one */
@ -61,7 +61,7 @@ int default_create_file(IsoNodeBuilder *builder, IsoImage *image,
iso_stream_unref(stream); iso_stream_unref(stream);
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
/* fill node fields */ /* fill node fields */
node->node.refcount = 1; node->node.refcount = 1;
node->node.type = LIBISO_FILE; node->node.type = LIBISO_FILE;
@ -78,26 +78,26 @@ int default_create_file(IsoNodeBuilder *builder, IsoImage *image,
node->sort_weight = 0; node->sort_weight = 0;
node->stream = stream; node->stream = stream;
node->msblock = 0; node->msblock = 0;
*file = node; *file = node;
return ISO_SUCCESS; return ISO_SUCCESS;
} }
static static
int default_create_node(IsoNodeBuilder *builder, IsoImage *image, int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
IsoFileSource *src, IsoNode **node) IsoFileSource *src, IsoNode **node)
{ {
int result; int result;
struct stat info; struct stat info;
IsoNode *new; IsoNode *new;
char *name; char *name;
if (builder == NULL || src == NULL || node == NULL) { if (builder == NULL || src == NULL || node == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
name = iso_file_source_get_name(src); name = iso_file_source_get_name(src);
/* get info about source */ /* get info about source */
if (image->recOpts->follow_symlinks) { if (image->recOpts->follow_symlinks) {
result = iso_file_source_stat(src, &info); result = iso_file_source_stat(src, &info);
@ -107,7 +107,7 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
if (result < 0) { if (result < 0) {
return result; return result;
} }
new = NULL; new = NULL;
switch (info.st_mode & S_IFMT) { switch (info.st_mode & S_IFMT) {
case S_IFREG: case S_IFREG:
@ -148,7 +148,7 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
/* source is a symbolic link */ /* source is a symbolic link */
char dest[PATH_MAX]; char dest[PATH_MAX];
IsoSymlink *link; IsoSymlink *link;
result = iso_file_source_readlink(src, dest, PATH_MAX); result = iso_file_source_readlink(src, dest, PATH_MAX);
if (result < 0) { if (result < 0) {
return result; return result;
@ -179,7 +179,7 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
} }
break; break;
} }
/* fill fields */ /* fill fields */
new->refcount = 1; new->refcount = 1;
new->name = strdup(name); new->name = strdup(name);
@ -189,12 +189,12 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
new->atime = info.st_atime; new->atime = info.st_atime;
new->mtime = info.st_mtime; new->mtime = info.st_mtime;
new->ctime = info.st_ctime; new->ctime = info.st_ctime;
new->hidden = 0; new->hidden = 0;
new->parent = NULL; new->parent = NULL;
new->next = NULL; new->next = NULL;
*node = new; *node = new;
return ISO_SUCCESS; return ISO_SUCCESS;
} }
@ -208,23 +208,23 @@ void default_free(IsoNodeBuilder *builder)
int iso_node_basic_builder_new(IsoNodeBuilder **builder) int iso_node_basic_builder_new(IsoNodeBuilder **builder)
{ {
IsoNodeBuilder *b; IsoNodeBuilder *b;
if (builder == NULL) { if (builder == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
b = malloc(sizeof(IsoNodeBuilder)); b = malloc(sizeof(IsoNodeBuilder));
if (b == NULL) { if (b == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
b->refcount = 1; b->refcount = 1;
b->create_file_data = NULL; b->create_file_data = NULL;
b->create_node_data = NULL; b->create_node_data = NULL;
b->create_file = default_create_file; b->create_file = default_create_file;
b->create_node = default_create_node; b->create_node = default_create_node;
b->free = default_free; b->free = default_free;
*builder = b; *builder = b;
return ISO_SUCCESS; return ISO_SUCCESS;
} }

View File

@ -40,9 +40,9 @@ struct Iso_Node_Builder
* @return * @return
* 1 on success, < 0 on error * 1 on success, < 0 on error
*/ */
int (*create_file)(IsoNodeBuilder *builder, IsoImage *image, int (*create_file)(IsoNodeBuilder *builder, IsoImage *image,
IsoFileSource *src, IsoFile **file); IsoFileSource *src, IsoFile **file);
/** /**
* Create a new IsoNode from a IsoFileSource. The type of the node to be * Create a new IsoNode from a IsoFileSource. The type of the node to be
* created is determined from the type of the file source. Name, * created is determined from the type of the file source. Name,
@ -53,15 +53,15 @@ struct Iso_Node_Builder
* @return * @return
* 1 on success, < 0 on error * 1 on success, < 0 on error
*/ */
int (*create_node)(IsoNodeBuilder *builder, IsoImage *image, int (*create_node)(IsoNodeBuilder *builder, IsoImage *image,
IsoFileSource *src, IsoNode **node); IsoFileSource *src, IsoNode **node);
/** /**
* Free implementation specific data. Should never be called by user. * Free implementation specific data. Should never be called by user.
* Use iso_node_builder_unref() instead. * Use iso_node_builder_unref() instead.
*/ */
void (*free)(IsoNodeBuilder *builder); void (*free)(IsoNodeBuilder *builder);
int refcount; int refcount;
void *create_file_data; void *create_file_data;
void *create_node_data; void *create_node_data;

View File

@ -30,12 +30,12 @@ static
void ecma119_image_free(Ecma119Image *t) void ecma119_image_free(Ecma119Image *t)
{ {
size_t i; size_t i;
ecma119_node_free(t->root); ecma119_node_free(t->root);
iso_image_unref(t->image); iso_image_unref(t->image);
iso_rbtree_destroy(t->files, iso_file_src_free); iso_rbtree_destroy(t->files, iso_file_src_free);
iso_ring_buffer_free(t->buffer); iso_ring_buffer_free(t->buffer);
for (i = 0; i < t->nwriters; ++i) { for (i = 0; i < t->nwriters; ++i) {
IsoImageWriter *writer = t->writers[i]; IsoImageWriter *writer = t->writers[i];
writer->free_data(writer); writer->free_data(writer);
@ -73,7 +73,8 @@ size_t calc_dirent_len(Ecma119Image *t, Ecma119Node *n)
if (need_version_number(t, n)) { if (need_version_number(t, n)) {
ret += 2; /* take into account version numbers */ ret += 2; /* take into account version numbers */
} }
if (ret % 2) ret++; if (ret % 2)
ret++;
return ret; return ret;
} }
@ -90,12 +91,12 @@ size_t calc_dirent_len(Ecma119Image *t, Ecma119Node *n)
* The size needed for all dir entries of the given dir, without * The size needed for all dir entries of the given dir, without
* taking into account the continuation areas. * taking into account the continuation areas.
*/ */
static static
size_t calc_dir_size(Ecma119Image *t, Ecma119Node *dir, size_t *ce) size_t calc_dir_size(Ecma119Image *t, Ecma119Node *dir, size_t *ce)
{ {
size_t i, len; size_t i, len;
size_t ce_len = 0; size_t ce_len = 0;
/* size of "." and ".." entries */ /* size of "." and ".." entries */
len = 34 + 34; len = 34 + 34;
if (t->rockridge) { if (t->rockridge) {
@ -104,14 +105,13 @@ size_t calc_dir_size(Ecma119Image *t, Ecma119Node *dir, size_t *ce)
len += rrip_calc_len(t, dir, 2, 255 - 34, &ce_len); len += rrip_calc_len(t, dir, 2, 255 - 34, &ce_len);
*ce += ce_len; *ce += ce_len;
} }
for (i = 0; i < dir->info.dir.nchildren; ++i) { for (i = 0; i < dir->info.dir.nchildren; ++i) {
size_t remaining; size_t remaining;
Ecma119Node *child = dir->info.dir.children[i]; Ecma119Node *child = dir->info.dir.children[i];
size_t dirent_len = calc_dirent_len(t, child); size_t dirent_len = calc_dirent_len(t, child);
if (t->rockridge) { if (t->rockridge) {
dirent_len += rrip_calc_len(t, child, 0, 255 - dirent_len, dirent_len += rrip_calc_len(t, child, 0, 255 - dirent_len, &ce_len);
&ce_len);
*ce += ce_len; *ce += ce_len;
} }
remaining = BLOCK_SIZE - (len % BLOCK_SIZE); remaining = BLOCK_SIZE - (len % BLOCK_SIZE);
@ -127,7 +127,7 @@ size_t calc_dir_size(Ecma119Image *t, Ecma119Node *dir, size_t *ce)
return len; return len;
} }
static static
void calc_dir_pos(Ecma119Image *t, Ecma119Node *dir) void calc_dir_pos(Ecma119Image *t, Ecma119Node *dir)
{ {
size_t i, len; size_t i, len;
@ -156,12 +156,12 @@ uint32_t calc_path_table_size(Ecma119Node *dir)
{ {
uint32_t size; uint32_t size;
size_t i; size_t i;
/* size of path table for this entry */ /* size of path table for this entry */
size = 8; size = 8;
size += dir->iso_name ? strlen(dir->iso_name) : 1; size += dir->iso_name ? strlen(dir->iso_name) : 1;
size += (size % 2); size += (size % 2);
/* and recurse */ /* and recurse */
for (i = 0; i < dir->info.dir.nchildren; i++) { for (i = 0; i < dir->info.dir.nchildren; i++) {
Ecma119Node *child = dir->info.dir.children[i]; Ecma119Node *child = dir->info.dir.children[i];
@ -177,29 +177,29 @@ int ecma119_writer_compute_data_blocks(IsoImageWriter *writer)
{ {
Ecma119Image *target; Ecma119Image *target;
uint32_t path_table_size; uint32_t path_table_size;
if (writer == NULL) { if (writer == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
target = writer->target; target = writer->target;
/* compute position of directories */ /* compute position of directories */
iso_msg_debug(target->image, "Computing position of dir structure"); iso_msg_debug(target->image, "Computing position of dir structure");
target->ndirs = 0; target->ndirs = 0;
calc_dir_pos(target, target->root); calc_dir_pos(target, target->root);
/* compute length of pathlist */ /* compute length of pathlist */
iso_msg_debug(target->image, "Computing length of pathlist"); iso_msg_debug(target->image, "Computing length of pathlist");
path_table_size = calc_path_table_size(target->root); path_table_size = calc_path_table_size(target->root);
/* compute location for path tables */ /* compute location for path tables */
target->l_path_table_pos = target->curblock; target->l_path_table_pos = target->curblock;
target->curblock += div_up(path_table_size, BLOCK_SIZE); target->curblock += div_up(path_table_size, BLOCK_SIZE);
target->m_path_table_pos = target->curblock; target->m_path_table_pos = target->curblock;
target->curblock += div_up(path_table_size, BLOCK_SIZE); target->curblock += div_up(path_table_size, BLOCK_SIZE);
target->path_table_size = path_table_size; target->path_table_size = path_table_size;
return ISO_SUCCESS; return ISO_SUCCESS;
} }
@ -216,28 +216,28 @@ int ecma119_writer_compute_data_blocks(IsoImageWriter *writer)
* root directory record in the PVD (ECMA-119, 8.4.18) (in order to * root directory record in the PVD (ECMA-119, 8.4.18) (in order to
* distinguish it from the "." entry in the root directory) * distinguish it from the "." entry in the root directory)
*/ */
static static
void write_one_dir_record(Ecma119Image *t, Ecma119Node *node, int file_id, void write_one_dir_record(Ecma119Image *t, Ecma119Node *node, int file_id,
uint8_t *buf, size_t len_fi, struct susp_info *info) uint8_t *buf, size_t len_fi, struct susp_info *info)
{ {
uint32_t len; uint32_t len;
uint32_t block; uint32_t block;
uint8_t len_dr; /*< size of dir entry without SUSP fields */ uint8_t len_dr; /*< size of dir entry without SUSP fields */
uint8_t *name = (file_id >= 0) ? (uint8_t*)&file_id : uint8_t *name = (file_id >= 0) ? (uint8_t*)&file_id
(uint8_t*)node->iso_name; : (uint8_t*)node->iso_name;
struct ecma119_dir_record *rec = (struct ecma119_dir_record*)buf; struct ecma119_dir_record *rec = (struct ecma119_dir_record*)buf;
len_dr = 33 + len_fi + (len_fi % 2 ? 0 : 1); len_dr = 33 + len_fi + (len_fi % 2 ? 0 : 1);
memcpy(rec->file_id, name, len_fi); memcpy(rec->file_id, name, len_fi);
if (need_version_number(t, node)) { if (need_version_number(t, node)) {
len_dr += 2; len_dr += 2;
rec->file_id[len_fi++] = ';'; rec->file_id[len_fi++] = ';';
rec->file_id[len_fi++] = '1'; rec->file_id[len_fi++] = '1';
} }
if (node->type == ECMA119_DIR) { if (node->type == ECMA119_DIR) {
/* use the cached length */ /* use the cached length */
len = node->info.dir.len; len = node->info.dir.len;
@ -253,7 +253,7 @@ void write_one_dir_record(Ecma119Image *t, Ecma119Node *node, int file_id,
len = 0; len = 0;
block = 0; block = 0;
} }
/* /*
* For ".." entry we need to write the parent info! * For ".." entry we need to write the parent info!
*/ */
@ -267,7 +267,7 @@ void write_one_dir_record(Ecma119Image *t, Ecma119Node *node, int file_id,
rec->flags[0] = (node->type == ECMA119_DIR) ? 2 : 0; rec->flags[0] = (node->type == ECMA119_DIR) ? 2 : 0;
iso_bb(rec->vol_seq_number, 1, 2); iso_bb(rec->vol_seq_number, 1, 2);
rec->len_fi[0] = len_fi; rec->len_fi[0] = len_fi;
/* and finally write the SUSP fields */ /* and finally write the SUSP fields */
if (info != NULL) { if (info != NULL) {
rrip_write_susp_fields(t, info, buf + len_dr); rrip_write_susp_fields(t, info, buf + len_dr);
@ -283,33 +283,33 @@ int ecma119_writer_write_vol_desc(IsoImageWriter *writer)
IsoImage *image; IsoImage *image;
Ecma119Image *t; Ecma119Image *t;
struct ecma119_pri_vol_desc vol; struct ecma119_pri_vol_desc vol;
char *vol_id, *pub_id, *data_id, *volset_id; char *vol_id, *pub_id, *data_id, *volset_id;
char *system_id, *application_id, *copyright_file_id; char *system_id, *application_id, *copyright_file_id;
char *abstract_file_id, *biblio_file_id; char *abstract_file_id, *biblio_file_id;
if (writer == NULL) { if (writer == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
t = writer->target; t = writer->target;
image = t->image; image = t->image;
iso_msg_debug(image, "Write Primary Volume Descriptor"); iso_msg_debug(image, "Write Primary Volume Descriptor");
memset(&vol, 0, sizeof(struct ecma119_pri_vol_desc)); memset(&vol, 0, sizeof(struct ecma119_pri_vol_desc));
str2d_char(t->input_charset, image->volume_id, &vol_id); str2d_char(t->input_charset, image->volume_id, &vol_id);
str2a_char(t->input_charset, image->publisher_id, &pub_id); str2a_char(t->input_charset, image->publisher_id, &pub_id);
str2a_char(t->input_charset, image->data_preparer_id, &data_id); str2a_char(t->input_charset, image->data_preparer_id, &data_id);
str2d_char(t->input_charset, image->volset_id, &volset_id); str2d_char(t->input_charset, image->volset_id, &volset_id);
str2a_char(t->input_charset, image->system_id, &system_id); str2a_char(t->input_charset, image->system_id, &system_id);
str2a_char(t->input_charset, image->application_id, &application_id); str2a_char(t->input_charset, image->application_id, &application_id);
str2d_char(t->input_charset, image->copyright_file_id, &copyright_file_id); str2d_char(t->input_charset, image->copyright_file_id, &copyright_file_id);
str2d_char(t->input_charset, image->abstract_file_id, &abstract_file_id); str2d_char(t->input_charset, image->abstract_file_id, &abstract_file_id);
str2d_char(t->input_charset, image->biblio_file_id, &biblio_file_id); str2d_char(t->input_charset, image->biblio_file_id, &biblio_file_id);
vol.vol_desc_type[0] = 1; vol.vol_desc_type[0] = 1;
memcpy(vol.std_identifier, "CD001", 5); memcpy(vol.std_identifier, "CD001", 5);
vol.vol_desc_version[0] = 1; vol.vol_desc_version[0] = 1;
@ -318,7 +318,7 @@ int ecma119_writer_write_vol_desc(IsoImageWriter *writer)
} else { } else {
/* put linux by default? */ /* put linux by default? */
memcpy(vol.system_id, "LINUX", 5); memcpy(vol.system_id, "LINUX", 5);
} }
if (vol_id) { if (vol_id) {
strncpy((char*)vol.volume_id, vol_id, 32); strncpy((char*)vol.volume_id, vol_id, 32);
} }
@ -338,7 +338,7 @@ int ecma119_writer_write_vol_desc(IsoImageWriter *writer)
strncpy((char*)vol.publisher_id, pub_id, 128); strncpy((char*)vol.publisher_id, pub_id, 128);
if (data_id) if (data_id)
strncpy((char*)vol.data_prep_id, data_id, 128); strncpy((char*)vol.data_prep_id, data_id, 128);
if (application_id) if (application_id)
strncpy((char*)vol.application_id, application_id, 128); strncpy((char*)vol.application_id, application_id, 128);
if (copyright_file_id) if (copyright_file_id)
@ -362,12 +362,12 @@ int ecma119_writer_write_vol_desc(IsoImageWriter *writer)
free(copyright_file_id); free(copyright_file_id);
free(abstract_file_id); free(abstract_file_id);
free(biblio_file_id); free(biblio_file_id);
/* Finally write the Volume Descriptor */ /* Finally write the Volume Descriptor */
return iso_write(t, &vol, sizeof(struct ecma119_pri_vol_desc)); return iso_write(t, &vol, sizeof(struct ecma119_pri_vol_desc));
} }
static static
int write_one_dir(Ecma119Image *t, Ecma119Node *dir) int write_one_dir(Ecma119Image *t, Ecma119Node *dir)
{ {
int ret; int ret;
@ -375,13 +375,13 @@ int write_one_dir(Ecma119Image *t, Ecma119Node *dir)
size_t i; size_t i;
size_t fi_len, len; size_t fi_len, len;
struct susp_info info; struct susp_info info;
/* buf will point to current write position on buffer */ /* buf will point to current write position on buffer */
uint8_t *buf = buffer; uint8_t *buf = buffer;
/* initialize buffer with 0s */ /* initialize buffer with 0s */
memset(buffer, 0, BLOCK_SIZE); memset(buffer, 0, BLOCK_SIZE);
/* /*
* set susp_info to 0's, this way code for both plain ECMA-119 and * set susp_info to 0's, this way code for both plain ECMA-119 and
* RR is very similar * RR is very similar
@ -416,14 +416,14 @@ int write_one_dir(Ecma119Image *t, Ecma119Node *dir)
for (i = 0; i < dir->info.dir.nchildren; i++) { for (i = 0; i < dir->info.dir.nchildren; i++) {
Ecma119Node *child = dir->info.dir.children[i]; Ecma119Node *child = dir->info.dir.children[i];
/* compute len of directory entry */ /* compute len of directory entry */
fi_len = strlen(child->iso_name); fi_len = strlen(child->iso_name);
len = fi_len + 33 + (fi_len % 2 ? 0 : 1); len = fi_len + 33 + (fi_len % 2 ? 0 : 1);
if (need_version_number(t, child)) { if (need_version_number(t, child)) {
len += 2; len += 2;
} }
/* get the SUSP fields if rockridge is enabled */ /* get the SUSP fields if rockridge is enabled */
if (t->rockridge) { if (t->rockridge) {
ret = rrip_get_susp_fields(t, child, 0, 255 - len, &info); ret = rrip_get_susp_fields(t, child, 0, 255 - len, &info);
@ -432,8 +432,8 @@ int write_one_dir(Ecma119Image *t, Ecma119Node *dir)
} }
len += info.suf_len; len += info.suf_len;
} }
if ( (buf + len - buffer) > BLOCK_SIZE ) { if ( (buf + len - buffer) > BLOCK_SIZE) {
/* dir doesn't fit in current block */ /* dir doesn't fit in current block */
ret = iso_write(t, buffer, BLOCK_SIZE); ret = iso_write(t, buffer, BLOCK_SIZE);
if (ret < 0) { if (ret < 0) {
@ -446,33 +446,33 @@ int write_one_dir(Ecma119Image *t, Ecma119Node *dir)
write_one_dir_record(t, child, -1, buf, fi_len, &info); write_one_dir_record(t, child, -1, buf, fi_len, &info);
buf += len; buf += len;
} }
/* write the last block */ /* write the last block */
ret = iso_write(t, buffer, BLOCK_SIZE); ret = iso_write(t, buffer, BLOCK_SIZE);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
/* write the Continuation Area if needed */ /* write the Continuation Area if needed */
if (info.ce_len > 0) { if (info.ce_len > 0) {
ret = rrip_write_ce_fields(t, &info); ret = rrip_write_ce_fields(t, &info);
} }
return ret; return ret;
} }
static static
int write_dirs(Ecma119Image *t, Ecma119Node *root) int write_dirs(Ecma119Image *t, Ecma119Node *root)
{ {
int ret; int ret;
size_t i; size_t i;
/* write all directory entries for this dir */ /* write all directory entries for this dir */
ret = write_one_dir(t, root); ret = write_one_dir(t, root);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
/* recurse */ /* recurse */
for (i = 0; i < root->info.dir.nchildren; i++) { for (i = 0; i < root->info.dir.nchildren; i++) {
Ecma119Node *child = root->info.dir.children[i]; Ecma119Node *child = root->info.dir.children[i];
@ -486,7 +486,7 @@ int write_dirs(Ecma119Image *t, Ecma119Node *root)
return ISO_SUCCESS; return ISO_SUCCESS;
} }
static static
int write_path_table(Ecma119Image *t, Ecma119Node **pathlist, int l_type) int write_path_table(Ecma119Image *t, Ecma119Node **pathlist, int l_type)
{ {
size_t i, len; size_t i, len;
@ -496,8 +496,8 @@ int write_path_table(Ecma119Image *t, Ecma119Node **pathlist, int l_type)
Ecma119Node *dir; Ecma119Node *dir;
uint32_t path_table_size; uint32_t path_table_size;
int parent = 0; int parent = 0;
int ret = ISO_SUCCESS; int ret= ISO_SUCCESS;
path_table_size = 0; path_table_size = 0;
write_int = l_type ? iso_lsb : iso_msb; write_int = l_type ? iso_lsb : iso_msb;
@ -527,7 +527,7 @@ int write_path_table(Ecma119Image *t, Ecma119Node **pathlist, int l_type)
} }
path_table_size += len; path_table_size += len;
} }
/* we need to fill the last block with zeros */ /* we need to fill the last block with zeros */
path_table_size %= BLOCK_SIZE; path_table_size %= BLOCK_SIZE;
if (path_table_size) { if (path_table_size) {
@ -539,15 +539,15 @@ int write_path_table(Ecma119Image *t, Ecma119Node **pathlist, int l_type)
return ret; return ret;
} }
static static
int write_path_tables(Ecma119Image *t) int write_path_tables(Ecma119Image *t)
{ {
int ret; int ret;
size_t i, j, cur; size_t i, j, cur;
Ecma119Node **pathlist; Ecma119Node **pathlist;
iso_msg_debug(t->image, "Writing ISO Path tables"); iso_msg_debug(t->image, "Writing ISO Path tables");
/* allocate temporal pathlist */ /* allocate temporal pathlist */
pathlist = malloc(sizeof(void*) * t->ndirs); pathlist = malloc(sizeof(void*) * t->ndirs);
if (pathlist == NULL) { if (pathlist == NULL) {
@ -565,17 +565,17 @@ int write_path_tables(Ecma119Image *t)
} }
} }
} }
/* Write L Path Table */ /* Write L Path Table */
ret = write_path_table(t, pathlist, 1); ret = write_path_table(t, pathlist, 1);
if (ret < 0) { if (ret < 0) {
goto write_path_tables_exit; goto write_path_tables_exit;
} }
/* Write L Path Table */ /* Write L Path Table */
ret = write_path_table(t, pathlist, 0); ret = write_path_table(t, pathlist, 0);
write_path_tables_exit:; write_path_tables_exit: ;
free(pathlist); free(pathlist);
return ret; return ret;
} }
@ -589,21 +589,21 @@ int ecma119_writer_write_data(IsoImageWriter *writer)
{ {
int ret; int ret;
Ecma119Image *t; Ecma119Image *t;
if (writer == NULL) { if (writer == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
t = writer->target; t = writer->target;
/* first of all, we write the directory structure */ /* first of all, we write the directory structure */
ret = write_dirs(t, t->root); ret = write_dirs(t, t->root);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
/* and write the path tables */ /* and write the path tables */
ret = write_path_tables(t); ret = write_path_tables(t);
return ret; return ret;
} }
@ -618,28 +618,28 @@ int ecma119_writer_create(Ecma119Image *target)
{ {
int ret; int ret;
IsoImageWriter *writer; IsoImageWriter *writer;
writer = malloc(sizeof(IsoImageWriter)); writer = malloc(sizeof(IsoImageWriter));
if (writer == NULL) { if (writer == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
writer->compute_data_blocks = ecma119_writer_compute_data_blocks; writer->compute_data_blocks = ecma119_writer_compute_data_blocks;
writer->write_vol_desc = ecma119_writer_write_vol_desc; writer->write_vol_desc = ecma119_writer_write_vol_desc;
writer->write_data = ecma119_writer_write_data; writer->write_data = ecma119_writer_write_data;
writer->free_data = ecma119_writer_free_data; writer->free_data = ecma119_writer_free_data;
writer->data = NULL; writer->data = NULL;
writer->target = target; writer->target = target;
/* add this writer to image */ /* add this writer to image */
target->writers[target->nwriters++] = writer; target->writers[target->nwriters++] = writer;
iso_msg_debug(target->image, "Creating low level ECMA-119 tree..."); iso_msg_debug(target->image, "Creating low level ECMA-119 tree...");
ret = ecma119_tree_create(target); ret = ecma119_tree_create(target);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
/* we need the volume descriptor */ /* we need the volume descriptor */
target->curblock++; target->curblock++;
return ISO_SUCCESS; return ISO_SUCCESS;
@ -652,10 +652,10 @@ void *write_function(void *arg)
size_t i; size_t i;
uint8_t buf[BLOCK_SIZE]; uint8_t buf[BLOCK_SIZE];
IsoImageWriter *writer; IsoImageWriter *writer;
Ecma119Image *target = (Ecma119Image*)arg; Ecma119Image *target = (Ecma119Image*)arg;
iso_msg_debug(target->image, "Starting image writing..."); iso_msg_debug(target->image, "Starting image writing...");
/* Write System Area, 16 blocks of zeros (ECMA-119, 6.2.1) */ /* Write System Area, 16 blocks of zeros (ECMA-119, 6.2.1) */
memset(buf, 0, BLOCK_SIZE); memset(buf, 0, BLOCK_SIZE);
for (i = 0; i < 16; ++i) { for (i = 0; i < 16; ++i) {
@ -664,7 +664,7 @@ void *write_function(void *arg)
goto write_error; goto write_error;
} }
} }
/* write volume descriptors, one per writer */ /* write volume descriptors, one per writer */
iso_msg_debug(target->image, "Write volume descriptors"); iso_msg_debug(target->image, "Write volume descriptors");
for (i = 0; i < target->nwriters; ++i) { for (i = 0; i < target->nwriters; ++i) {
@ -674,22 +674,22 @@ void *write_function(void *arg)
goto write_error; goto write_error;
} }
} }
/* write Volume Descriptor Set Terminator (ECMA-119, 8.3) */ /* write Volume Descriptor Set Terminator (ECMA-119, 8.3) */
{ {
struct ecma119_vol_desc_terminator *vol; struct ecma119_vol_desc_terminator *vol;
vol = (struct ecma119_vol_desc_terminator *) buf; vol = (struct ecma119_vol_desc_terminator *) buf;
vol->vol_desc_type[0] = 255; vol->vol_desc_type[0] = 255;
memcpy(vol->std_identifier, "CD001", 5); memcpy(vol->std_identifier, "CD001", 5);
vol->vol_desc_version[0] = 1; vol->vol_desc_version[0] = 1;
res = iso_write(target, buf, BLOCK_SIZE); res = iso_write(target, buf, BLOCK_SIZE);
if (res < 0) { if (res < 0) {
goto write_error; goto write_error;
} }
} }
/* write data for each writer */ /* write data for each writer */
for (i = 0; i < target->nwriters; ++i) { for (i = 0; i < target->nwriters; ++i) {
writer = target->writers[i]; writer = target->writers[i];
@ -698,40 +698,39 @@ void *write_function(void *arg)
goto write_error; goto write_error;
} }
} }
iso_ring_buffer_writer_close(target->buffer); iso_ring_buffer_writer_close(target->buffer);
pthread_exit(NULL); pthread_exit(NULL);
write_error:; write_error: ;
iso_msg_fatal(target->image, LIBISO_WRITE_ERROR, iso_msg_fatal(target->image, LIBISO_WRITE_ERROR,
"Image write error, code %d", res); "Image write error, code %d", res);
iso_ring_buffer_writer_close(target->buffer); iso_ring_buffer_writer_close(target->buffer);
pthread_exit(NULL); pthread_exit(NULL);
} }
static static
int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts, int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts, Ecma119Image **img)
Ecma119Image **img)
{ {
int ret, i; int ret, i;
Ecma119Image *target; Ecma119Image *target;
/* 1. Allocate target and copy opts there */ /* 1. Allocate target and copy opts there */
target = calloc(1, sizeof(Ecma119Image)); target = calloc(1, sizeof(Ecma119Image));
if (target == NULL) { if (target == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
/* create the tree for file caching */ /* create the tree for file caching */
ret = iso_rbtree_new(iso_file_src_cmp, &(target->files)); ret = iso_rbtree_new(iso_file_src_cmp, &(target->files));
if (ret < 0) { if (ret < 0) {
free(target); free(target);
return ret; return ret;
} }
target->image = src; target->image = src;
iso_image_ref(src); iso_image_ref(src);
target->iso_level = opts->level; target->iso_level = opts->level;
target->rockridge = opts->rockridge; target->rockridge = opts->rockridge;
target->ino = 0; target->ino = 0;
@ -748,7 +747,7 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
target->gid = opts->replace_gid == 2 ? opts->gid : 0; target->gid = opts->replace_gid == 2 ? opts->gid : 0;
target->dir_mode = opts->replace_dir_mode == 2 ? opts->dir_mode : 0555; target->dir_mode = opts->replace_dir_mode == 2 ? opts->dir_mode : 0555;
target->file_mode = opts->replace_file_mode == 2 ? opts->file_mode : 0444; target->file_mode = opts->replace_file_mode == 2 ? opts->file_mode : 0444;
target->now = time(NULL); target->now = time(NULL);
target->ms_block = 0; target->ms_block = 0;
@ -760,7 +759,7 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
free(target); free(target);
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
if (opts->output_charset != NULL) { if (opts->output_charset != NULL) {
target->output_charset = strdup(opts->output_charset); target->output_charset = strdup(opts->output_charset);
} else { } else {
@ -771,7 +770,7 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
free(target); free(target);
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
/* /*
* 2. Based on those options, create needed writers: iso, joliet... * 2. Based on those options, create needed writers: iso, joliet...
* Each writer inits its structures and stores needed info into * Each writer inits its structures and stores needed info into
@ -780,8 +779,8 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
* current block. * current block.
* Finally, create Writer for files. * Finally, create Writer for files.
*/ */
target->curblock = target->ms_block + 16; target->curblock = target->ms_block + 16;
/* the number of writers is dependent of the extensions */ /* the number of writers is dependent of the extensions */
target->writers = malloc(2 * sizeof(void*)); target->writers = malloc(2 * sizeof(void*));
if (target->writers == NULL) { if (target->writers == NULL) {
@ -789,22 +788,22 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
free(target); free(target);
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
/* create writer for ECMA-119 structure */ /* create writer for ECMA-119 structure */
ret = ecma119_writer_create(target); ret = ecma119_writer_create(target);
if (ret < 0) { if (ret < 0) {
goto target_cleanup; goto target_cleanup;
} }
/* Volume Descriptor Set Terminator */ /* Volume Descriptor Set Terminator */
target->curblock++; target->curblock++;
/* create writer for file contents */ /* create writer for file contents */
ret = iso_file_src_writer_create(target); ret = iso_file_src_writer_create(target);
if (ret < 0) { if (ret < 0) {
goto target_cleanup; goto target_cleanup;
} }
/* /*
* 3. * 3.
* Call compute_data_blocks() in each Writer. * Call compute_data_blocks() in each Writer.
@ -818,27 +817,27 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
goto target_cleanup; goto target_cleanup;
} }
} }
/* /*
* The volume space size is just the size of the last session, in * The volume space size is just the size of the last session, in
* case of ms images. * case of ms images.
*/ */
target->total_size = (target->curblock - target->ms_block) * BLOCK_SIZE; target->total_size = (target->curblock - target->ms_block) * BLOCK_SIZE;
target->vol_space_size = target->curblock - target->ms_block; target->vol_space_size = target->curblock - target->ms_block;
/* 4. Create and start writting thread */ /* 4. Create and start writting thread */
/* create the ring buffer */ /* create the ring buffer */
ret = iso_ring_buffer_new(&target->buffer); ret = iso_ring_buffer_new(&target->buffer);
if (ret < 0) { if (ret < 0) {
goto target_cleanup; goto target_cleanup;
} }
/* ensure the thread is created joinable */ /* ensure the thread is created joinable */
pthread_attr_init(&(target->th_attr)); pthread_attr_init(&(target->th_attr));
pthread_attr_setdetachstate(&(target->th_attr), PTHREAD_CREATE_JOINABLE); pthread_attr_setdetachstate(&(target->th_attr), PTHREAD_CREATE_JOINABLE);
ret = pthread_create(&(target->wthread), &(target->th_attr), ret = pthread_create(&(target->wthread), &(target->th_attr),
write_function, (void *) target); write_function, (void *) target);
if (ret != 0) { if (ret != 0) {
iso_msg_fatal(target->image, LIBISO_THREAD_ERROR, iso_msg_fatal(target->image, LIBISO_THREAD_ERROR,
@ -846,24 +845,23 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts,
ret = ISO_THREAD_ERROR; ret = ISO_THREAD_ERROR;
goto target_cleanup; goto target_cleanup;
} }
/* /*
* Notice that once we reach this point, target belongs to the writer * Notice that once we reach this point, target belongs to the writer
* thread and should not be modified until the writer thread finished. * thread and should not be modified until the writer thread finished.
* There're however, specific fields in target that can be accessed, or * There're however, specific fields in target that can be accessed, or
* even modified by the read thread (look inside bs_* functions) * even modified by the read thread (look inside bs_* functions)
*/ */
*img = target; *img = target;
return ISO_SUCCESS; return ISO_SUCCESS;
target_cleanup:; target_cleanup: ;
ecma119_image_free(target); ecma119_image_free(target);
return ret; return ret;
} }
static int static int bs_read(struct burn_source *bs, unsigned char *buf, int size)
bs_read(struct burn_source *bs, unsigned char *buf, int size)
{ {
int ret; int ret;
Ecma119Image *t = (Ecma119Image*)bs->data; Ecma119Image *t = (Ecma119Image*)bs->data;
@ -881,29 +879,27 @@ bs_read(struct burn_source *bs, unsigned char *buf, int size)
} }
} }
static off_t static off_t bs_get_size(struct burn_source *bs)
bs_get_size(struct burn_source *bs)
{ {
Ecma119Image *target = (Ecma119Image*)bs->data; Ecma119Image *target = (Ecma119Image*)bs->data;
return target->total_size; return target->total_size;
} }
static void static void bs_free_data(struct burn_source *bs)
bs_free_data(struct burn_source *bs)
{ {
Ecma119Image *target = (Ecma119Image*)bs->data; Ecma119Image *target = (Ecma119Image*)bs->data;
/* forces writer to stop if it is still running */ /* forces writer to stop if it is still running */
iso_ring_buffer_reader_close(target->buffer); iso_ring_buffer_reader_close(target->buffer);
/* wait until writer thread finishes */ /* wait until writer thread finishes */
pthread_join(target->wthread, NULL); pthread_join(target->wthread, NULL);
iso_msg_debug(target->image, "Writer thread joined"); iso_msg_debug(target->image, "Writer thread joined");
iso_msg_debug(target->image, "Ring buffer was %d times full and %d times " iso_msg_debug(target->image, "Ring buffer was %d times full and %d times "
"empty", iso_ring_buffer_get_times_full(target->buffer), "empty", iso_ring_buffer_get_times_full(target->buffer),
iso_ring_buffer_get_times_empty(target->buffer)); iso_ring_buffer_get_times_empty(target->buffer));
/* now we can safety free target */ /* now we can safety free target */
ecma119_image_free(target); ecma119_image_free(target);
} }
@ -912,7 +908,7 @@ static
int bs_set_size(struct burn_source *bs, off_t size) int bs_set_size(struct burn_source *bs, off_t size)
{ {
Ecma119Image *target = (Ecma119Image*)bs->data; Ecma119Image *target = (Ecma119Image*)bs->data;
/* /*
* just set the value to be returned by get_size. This is not used at * just set the value to be returned by get_size. This is not used at
* all by libisofs, it is here just for helping libburn to correctly pad * all by libisofs, it is here just for helping libburn to correctly pad
@ -927,30 +923,30 @@ int iso_image_create(IsoImage *image, Ecma119WriteOpts *opts,
{ {
int ret; int ret;
struct burn_source *source; struct burn_source *source;
Ecma119Image *target = NULL; Ecma119Image *target= NULL;
if (image == NULL || opts == NULL || burn_src == NULL) { if (image == NULL || opts == NULL || burn_src == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
source = calloc(1, sizeof(struct burn_source)); source = calloc(1, sizeof(struct burn_source));
if (source == NULL) { if (source == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
ret = ecma119_image_new(image, opts, &target); ret = ecma119_image_new(image, opts, &target);
if (ret < 0) { if (ret < 0) {
free(source); free(source);
return ret; return ret;
} }
source->refcount = 1; source->refcount = 1;
source->read = bs_read; source->read = bs_read;
source->get_size = bs_get_size; source->get_size = bs_get_size;
source->set_size = bs_set_size; source->set_size = bs_set_size;
source->free_data = bs_free_data; source->free_data = bs_free_data;
source->data = target; source->data = target;
*burn_src = source; *burn_src = source;
return ISO_SUCCESS; return ISO_SUCCESS;
} }
@ -958,7 +954,7 @@ int iso_image_create(IsoImage *image, Ecma119WriteOpts *opts,
int iso_write(Ecma119Image *target, void *buf, size_t count) int iso_write(Ecma119Image *target, void *buf, size_t count)
{ {
int ret; int ret;
ret = iso_ring_buffer_write(target->buffer, buf, count); ret = iso_ring_buffer_write(target->buffer, buf, count);
if (ret == 0) { if (ret == 0) {
/* reader cancelled */ /* reader cancelled */

View File

@ -23,50 +23,54 @@ typedef struct ecma119_node Ecma119Node;
typedef struct Iso_File_Src IsoFileSrc; typedef struct Iso_File_Src IsoFileSrc;
typedef struct Iso_Image_Writer IsoImageWriter; typedef struct Iso_Image_Writer IsoImageWriter;
struct ecma119_image { struct ecma119_image
{
IsoImage *image; IsoImage *image;
Ecma119Node *root; Ecma119Node *root;
unsigned int iso_level:2; unsigned int iso_level :2;
/* extensions */ /* extensions */
unsigned int rockridge:1; unsigned int rockridge :1;
/* relaxed constraints */ /* relaxed constraints */
unsigned int omit_version_numbers:1; unsigned int omit_version_numbers :1;
unsigned int allow_deep_paths:1; unsigned int allow_deep_paths :1;
// int relaxed_constraints; /**< see ecma119_relaxed_constraints_flag */ // int relaxed_constraints; /**< see ecma119_relaxed_constraints_flag */
/* /*
* Mode replace. If one of these flags is set, the correspodent values are * Mode replace. If one of these flags is set, the correspodent values are
* replaced with values below. * replaced with values below.
*/ */
unsigned int replace_uid:1; unsigned int replace_uid :1;
unsigned int replace_gid:1; unsigned int replace_gid :1;
unsigned int replace_file_mode:1; unsigned int replace_file_mode :1;
unsigned int replace_dir_mode:1; unsigned int replace_dir_mode :1;
uid_t uid; uid_t uid;
gid_t gid; gid_t gid;
mode_t file_mode; mode_t file_mode;
mode_t dir_mode; mode_t dir_mode;
int sort_files; /**< if sort files or not. Sorting is based of /**
* the weight of each file */ * if sort files or not. Sorting is based of the weight of each file
*/
int sort_files;
/** /**
* In the CD, each file must have an unique inode number. So each * In the CD, each file must have an unique inode number. So each
* time we add a new file, this is incremented. * time we add a new file, this is incremented.
*/ */
ino_t ino; ino_t ino;
char *input_charset; char *input_charset;
char *output_charset; char *output_charset;
uint32_t ms_block; /**< start block for a ms image */ uint32_t ms_block; /**< start block for a ms image */
time_t now; /**< Time at which writing began. */ time_t now; /**< Time at which writing began. */
off_t total_size; /**< Total size of the output. This only
* includes the current volume. */ /** Total size of the output. This only includes the current volume. */
off_t total_size;
uint32_t vol_space_size; uint32_t vol_space_size;
/* /*
@ -83,16 +87,16 @@ struct ecma119_image {
uint32_t path_table_size; uint32_t path_table_size;
uint32_t l_path_table_pos; uint32_t l_path_table_pos;
uint32_t m_path_table_pos; uint32_t m_path_table_pos;
size_t nwriters; size_t nwriters;
IsoImageWriter **writers; IsoImageWriter **writers;
/* tree of files sources */ /* tree of files sources */
IsoRBTree *files; IsoRBTree *files;
/* Buffer for communication between burn_source and writer thread */ /* Buffer for communication between burn_source and writer thread */
IsoRingBuffer *buffer; IsoRingBuffer *buffer;
/* writer thread descriptor */ /* writer thread descriptor */
pthread_t wthread; pthread_t wthread;
pthread_attr_t th_attr; pthread_attr_t th_attr;

View File

@ -25,7 +25,7 @@ int get_iso_name(Ecma119Image *img, IsoNode *iso, char **name)
{ {
int ret; int ret;
char *ascii_name; char *ascii_name;
char *isoname = NULL; char *isoname= NULL;
if (iso->name == NULL) { if (iso->name == NULL) {
/* it is not necessarily an error, it can be the root */ /* it is not necessarily an error, it can be the root */
@ -61,7 +61,7 @@ int get_iso_name(Ecma119Image *img, IsoNode *iso, char **name)
* only possible if mem error, as check for empty names is done * only possible if mem error, as check for empty names is done
* in public tree * in public tree
*/ */
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
} }
@ -82,7 +82,7 @@ int create_ecma119_node(Ecma119Image *img, IsoNode *iso, Ecma119Node **node)
// TODO better handling of this, add support for harlinks // TODO better handling of this, add support for harlinks
ecma->nlink = 1; ecma->nlink = 1;
ecma->ino = ++img->ino; ecma->ino = ++img->ino;
*node = ecma; *node = ecma;
return ISO_SUCCESS; return ISO_SUCCESS;
} }
@ -126,9 +126,9 @@ int create_file(Ecma119Image *img, IsoFile *iso, Ecma119Node **node)
size = iso_stream_get_size(iso->stream); size = iso_stream_get_size(iso->stream);
if (size > (off_t)0xffffffff) { if (size > (off_t)0xffffffff) {
iso_msg_note(img->image, LIBISO_FILE_IGNORED, iso_msg_note(img->image, LIBISO_FILE_IGNORED,
"File \"%s\" can't be added to image because is " "File \"%s\" can't be added to image because is "
"greater than 4GB", iso->node.name); "greater than 4GB", iso->node.name);
return 0; return 0;
} }
@ -147,7 +147,7 @@ int create_file(Ecma119Image *img, IsoFile *iso, Ecma119Node **node)
} }
(*node)->type = ECMA119_FILE; (*node)->type = ECMA119_FILE;
(*node)->info.file = src; (*node)->info.file = src;
return ret; return ret;
} }
@ -208,13 +208,13 @@ void ecma119_node_free(Ecma119Node *node)
* *
*/ */
static static
int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree, int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree,
int depth, int pathlen) int depth, int pathlen)
{ {
int ret; int ret;
Ecma119Node *node; Ecma119Node *node;
int max_path; int max_path;
char *iso_name = NULL; char *iso_name= NULL;
if (image == NULL || iso == NULL || tree == NULL) { if (image == NULL || iso == NULL || tree == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
@ -231,15 +231,15 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree,
max_path = pathlen + 1 + (iso_name ? strlen(iso_name) : 0); max_path = pathlen + 1 + (iso_name ? strlen(iso_name) : 0);
if (!image->rockridge && !image->allow_deep_paths) { if (!image->rockridge && !image->allow_deep_paths) {
if ((iso->type == LIBISO_DIR && depth > 8) || max_path > 255) { if ((iso->type == LIBISO_DIR && depth > 8) || max_path > 255) {
iso_msg_note(image->image, LIBISO_FILE_IGNORED, iso_msg_note(image->image, LIBISO_FILE_IGNORED,
"File \"%s\" can't be added, because depth > 8 " "File \"%s\" can't be added, because depth > 8 "
"or path length over 255", iso->name); "or path length over 255", iso->name);
free(iso_name); free(iso_name);
return 0; return 0;
} }
} }
switch(iso->type) { switch (iso->type) {
case LIBISO_FILE: case LIBISO_FILE:
ret = create_file(image, (IsoFile*)iso, &node); ret = create_file(image, (IsoFile*)iso, &node);
break; break;
@ -249,8 +249,7 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree,
} else { } else {
/* symlinks are only supported when RR is enabled */ /* symlinks are only supported when RR is enabled */
iso_msg_note(image->image, LIBISO_FILE_IGNORED, "File \"%s\" " iso_msg_note(image->image, LIBISO_FILE_IGNORED, "File \"%s\" "
"ignored. Symlinks need RockRidge extensions.", "ignored. Symlinks need RockRidge extensions.", iso->name);
iso->name);
ret = 0; ret = 0;
} }
break; break;
@ -260,8 +259,7 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree,
} else { } else {
/* symlinks are only supported when RR is enabled */ /* symlinks are only supported when RR is enabled */
iso_msg_note(image->image, LIBISO_FILE_IGNORED, "File \"%s\" " iso_msg_note(image->image, LIBISO_FILE_IGNORED, "File \"%s\" "
"ignored. Special files need RockRidge extensions.", "ignored. Special files need RockRidge extensions.", iso->name);
iso->name);
ret = 0; ret = 0;
} }
break; break;
@ -270,7 +268,7 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree,
free(iso_name); free(iso_name);
return 0; return 0;
break; break;
case LIBISO_DIR: case LIBISO_DIR:
{ {
IsoNode *pos; IsoNode *pos;
IsoDir *dir = (IsoDir*)iso; IsoDir *dir = (IsoDir*)iso;
@ -314,7 +312,7 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree,
/** /**
* Compare the iso name of two ECMA-119 nodes * Compare the iso name of two ECMA-119 nodes
*/ */
static static
int cmp_node_name(const void *f1, const void *f2) int cmp_node_name(const void *f1, const void *f2)
{ {
Ecma119Node *f = *((Ecma119Node**)f1); Ecma119Node *f = *((Ecma119Node**)f1);
@ -326,13 +324,13 @@ int cmp_node_name(const void *f1, const void *f2)
* Sorts a the children of each directory in the ECMA-119 tree represented * Sorts a the children of each directory in the ECMA-119 tree represented
* by \p root, acording to the order specified in ECMA-119, section 9.3. * by \p root, acording to the order specified in ECMA-119, section 9.3.
*/ */
static static
void sort_tree(Ecma119Node *root) void sort_tree(Ecma119Node *root)
{ {
size_t i; size_t i;
qsort(root->info.dir.children, root->info.dir.nchildren, qsort(root->info.dir.children, root->info.dir.nchildren, sizeof(void*),
sizeof(void*), cmp_node_name); cmp_node_name);
for (i = 0; i < root->info.dir.nchildren; i++) { for (i = 0; i < root->info.dir.nchildren; i++) {
if (root->info.dir.children[i]->type == ECMA119_DIR) if (root->info.dir.children[i]->type == ECMA119_DIR)
sort_tree(root->info.dir.children[i]); sort_tree(root->info.dir.children[i]);
@ -360,33 +358,33 @@ int contains_name(Ecma119Node *dir, const char *name)
* but never under 3 characters. * but never under 3 characters.
*/ */
static static
int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len, int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len,
int max_dir_len) int max_dir_len)
{ {
int i, nchildren; int i, nchildren;
Ecma119Node **children; Ecma119Node **children;
int need_sort = 0; int need_sort = 0;
nchildren = dir->info.dir.nchildren; nchildren = dir->info.dir.nchildren;
children = dir->info.dir.children; children = dir->info.dir.children;
for (i = 0; i < nchildren; ++i) { for (i = 0; i < nchildren; ++i) {
char *name, *ext; char *name, *ext;
char full_name[40]; char full_name[40];
int max; /* computed max len for name, without extension */ int max; /* computed max len for name, without extension */
int j = i; int j = i;
int digits = 1; /* characters to change per name */ int digits = 1; /* characters to change per name */
/* first, find all child with same name */ /* first, find all child with same name */
while (j + 1 < nchildren && while (j + 1 < nchildren && !cmp_node_name(children + i, children + j
!cmp_node_name(children + i, children + j + 1)) { + 1)) {
++j; ++j;
} }
if (j == i) { if (j == i) {
/* name is unique */ /* name is unique */
continue; continue;
} }
/* /*
* A max of 7 characters is good enought, it allows handling up to * A max of 7 characters is good enought, it allows handling up to
* 9,999,999 files with same name. We can increment this to * 9,999,999 files with same name. We can increment this to
@ -397,14 +395,14 @@ int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len,
int ok, k; int ok, k;
char *dot; char *dot;
int change = 0; /* number to be written */ int change = 0; /* number to be written */
/* copy name to buffer */ /* copy name to buffer */
strcpy(full_name, children[i]->iso_name); strcpy(full_name, children[i]->iso_name);
/* compute name and extension */ /* compute name and extension */
dot = strrchr(full_name, '.'); dot = strrchr(full_name, '.');
if (dot != NULL && children[i]->type != ECMA119_DIR) { if (dot != NULL && children[i]->type != ECMA119_DIR) {
/* /*
* File (not dir) with extension * File (not dir) with extension
* Note that we don't need to check for placeholders, as * Note that we don't need to check for placeholders, as
@ -415,7 +413,7 @@ int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len,
full_name[dot - full_name] = '\0'; full_name[dot - full_name] = '\0';
name = full_name; name = full_name;
ext = dot + 1; ext = dot + 1;
/* /*
* For iso level 1 we force ext len to be 3, as name * For iso level 1 we force ext len to be 3, as name
* can't grow on the extension space * can't grow on the extension space
@ -459,7 +457,7 @@ int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len,
/* let ext be an empty string */ /* let ext be an empty string */
ext = name + strlen(name); ext = name + strlen(name);
} }
ok = 1; ok = 1;
/* change name of each file */ /* change name of each file */
for (k = i; k <= j; ++k) { for (k = i; k <= j; ++k) {
@ -487,7 +485,7 @@ int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len,
if (new == NULL) { if (new == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
iso_msg_debug(img->image, "\"%s\" renamed to \"%s\"", iso_msg_debug(img->image, "\"%s\" renamed to \"%s\"",
children[k]->iso_name, new); children[k]->iso_name, new);
free(children[k]->iso_name); free(children[k]->iso_name);
children[k]->iso_name = new; children[k]->iso_name = new;
@ -516,30 +514,30 @@ int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len,
/* /*
* If needed, sort again the files inside dir * If needed, sort again the files inside dir
*/ */
if (need_sort) { if (need_sort) {
qsort(children, nchildren, sizeof(void*), cmp_node_name); qsort(children, nchildren, sizeof(void*), cmp_node_name);
} }
return ISO_SUCCESS; return ISO_SUCCESS;
} }
static static
int mangle_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len, int mangle_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len,
int max_dir_len) int max_dir_len)
{ {
int ret; int ret;
size_t i; size_t i;
ret = mangle_single_dir(img, dir, max_file_len, max_dir_len); ret = mangle_single_dir(img, dir, max_file_len, max_dir_len);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
/* recurse */ /* recurse */
for (i = 0; i < dir->info.dir.nchildren; ++i) { for (i = 0; i < dir->info.dir.nchildren; ++i) {
if (dir->info.dir.children[i]->type == ECMA119_DIR) { if (dir->info.dir.children[i]->type == ECMA119_DIR) {
ret = mangle_dir(img, dir->info.dir.children[i], ret = mangle_dir(img, dir->info.dir.children[i], max_file_len,
max_file_len, max_dir_len); max_dir_len);
if (ret < 0) { if (ret < 0) {
/* error */ /* error */
return ret; return ret;
@ -553,7 +551,7 @@ static
int mangle_tree(Ecma119Image *img, int recurse) int mangle_tree(Ecma119Image *img, int recurse)
{ {
int max_file, max_dir; int max_file, max_dir;
// TODO take care about relaxed constraints // TODO take care about relaxed constraints
if (img->iso_level == 1) { if (img->iso_level == 1) {
max_file = 12; /* 8 + 3 + 1 */ max_file = 12; /* 8 + 3 + 1 */
@ -574,9 +572,9 @@ int mangle_tree(Ecma119Image *img, int recurse)
* *
* See IEEE P1282, section 4.1.5 for details * See IEEE P1282, section 4.1.5 for details
*/ */
static static
int create_placeholder(Ecma119Node *parent, int create_placeholder(Ecma119Node *parent, Ecma119Node *real,
Ecma119Node *real, Ecma119Node **node) Ecma119Node **node)
{ {
Ecma119Node *ret; Ecma119Node *ret;
@ -584,7 +582,7 @@ int create_placeholder(Ecma119Node *parent,
if (ret == NULL) { if (ret == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
/* /*
* TODO * TODO
* If real is a dir, while placeholder is a file, ISO name restricctions * If real is a dir, while placeholder is a file, ISO name restricctions
@ -595,7 +593,7 @@ int create_placeholder(Ecma119Node *parent,
free(ret); free(ret);
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
/* take a ref to the IsoNode */ /* take a ref to the IsoNode */
ret->node = real->node; ret->node = real->node;
iso_node_ref(real->node); iso_node_ref(real->node);
@ -604,12 +602,12 @@ int create_placeholder(Ecma119Node *parent,
ret->info.real_me = real; ret->info.real_me = real;
ret->ino = real->ino; ret->ino = real->ino;
ret->nlink = real->nlink; ret->nlink = real->nlink;
*node = ret; *node = ret;
return ISO_SUCCESS; return ISO_SUCCESS;
} }
static static
size_t max_child_name_len(Ecma119Node *dir) size_t max_child_name_len(Ecma119Node *dir)
{ {
size_t ret = 0, i; size_t ret = 0, i;
@ -626,7 +624,7 @@ size_t max_child_name_len(Ecma119Node *dir)
* on a directory hierarchy exceeds 8, or the length of a path is higher * on a directory hierarchy exceeds 8, or the length of a path is higher
* than 255 characters, as specified in ECMA-119, section 6.8.2.1 * than 255 characters, as specified in ECMA-119, section 6.8.2.1
*/ */
static static
int reparent(Ecma119Node *child, Ecma119Node *parent) int reparent(Ecma119Node *child, Ecma119Node *parent)
{ {
int ret; int ret;
@ -634,7 +632,7 @@ int reparent(Ecma119Node *child, Ecma119Node *parent)
Ecma119Node *placeholder; Ecma119Node *placeholder;
/* replace the child in the original parent with a placeholder */ /* replace the child in the original parent with a placeholder */
for ( i = 0; i < child->parent->info.dir.nchildren; i++) { for (i = 0; i < child->parent->info.dir.nchildren; i++) {
if (child->parent->info.dir.children[i] == child) { if (child->parent->info.dir.children[i] == child) {
ret = create_placeholder(child->parent, child, &placeholder); ret = create_placeholder(child->parent, child, &placeholder);
if (ret < 0) { if (ret < 0) {
@ -644,7 +642,7 @@ int reparent(Ecma119Node *child, Ecma119Node *parent)
break; break;
} }
} }
/* just for debug, this should never happen... */ /* just for debug, this should never happen... */
if (i == child->parent->info.dir.nchildren) { if (i == child->parent->info.dir.nchildren) {
return ISO_ERROR; return ISO_ERROR;
@ -652,12 +650,12 @@ int reparent(Ecma119Node *child, Ecma119Node *parent)
/* keep track of the real parent */ /* keep track of the real parent */
child->info.dir.real_parent = child->parent; child->info.dir.real_parent = child->parent;
/* add the child to its new parent */ /* add the child to its new parent */
child->parent = parent; child->parent = parent;
parent->info.dir.nchildren++; parent->info.dir.nchildren++;
parent->info.dir.children = realloc( parent->info.dir.children, parent->info.dir.children = realloc(parent->info.dir.children,
sizeof(void*) * parent->info.dir.nchildren ); sizeof(void*) * parent->info.dir.nchildren);
parent->info.dir.children[parent->info.dir.nchildren - 1] = child; parent->info.dir.children[parent->info.dir.nchildren - 1] = child;
return ISO_SUCCESS; return ISO_SUCCESS;
} }
@ -677,7 +675,7 @@ int reparent(Ecma119Node *child, Ecma119Node *parent)
* @return * @return
* 1 success, < 0 error * 1 success, < 0 error
*/ */
static static
int reorder_tree(Ecma119Image *img, Ecma119Node *dir, int level, int pathlen) int reorder_tree(Ecma119Image *img, Ecma119Node *dir, int level, int pathlen)
{ {
int ret; int ret;
@ -690,7 +688,7 @@ int reorder_tree(Ecma119Image *img, Ecma119Node *dir, int level, int pathlen)
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
/* /*
* we are appended to the root's children now, so there is no * we are appended to the root's children now, so there is no
* need to recurse (the root will hit us again) * need to recurse (the root will hit us again)
@ -716,7 +714,7 @@ int ecma119_tree_create(Ecma119Image *img)
{ {
int ret; int ret;
Ecma119Node *root; Ecma119Node *root;
ret = create_tree(img, (IsoNode*)img->image->root, &root, 1, 0); ret = create_tree(img, (IsoNode*)img->image->root, &root, 1, 0);
if (ret <= 0) { if (ret <= 0) {
if (ret == 0) { if (ret == 0) {
@ -726,24 +724,24 @@ int ecma119_tree_create(Ecma119Image *img)
return ret; return ret;
} }
img->root = root; img->root = root;
iso_msg_debug(img->image, "Sorting the low level tree..."); iso_msg_debug(img->image, "Sorting the low level tree...");
sort_tree(root); sort_tree(root);
iso_msg_debug(img->image, "Mangling names..."); iso_msg_debug(img->image, "Mangling names...");
ret = mangle_tree(img, 1); ret = mangle_tree(img, 1);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
if (img->rockridge && !img->allow_deep_paths) { if (img->rockridge && !img->allow_deep_paths) {
/* reorder the tree, acording to RRIP, 4.1.5 */ /* reorder the tree, acording to RRIP, 4.1.5 */
ret = reorder_tree(img, img->root, 1, 0); ret = reorder_tree(img, img->root, 1, 0);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
/* /*
* and we need to remangle the root directory, as the function * and we need to remangle the root directory, as the function
* above could insert new directories into the root. * above could insert new directories into the root.
@ -754,6 +752,6 @@ int ecma119_tree_create(Ecma119Image *img)
return ret; return ret;
} }
} }
return ISO_SUCCESS; return ISO_SUCCESS;
} }

View File

@ -23,22 +23,23 @@ enum ecma119_node_type {
/** /**
* Struct with info about a node representing a tree * Struct with info about a node representing a tree
*/ */
struct ecma119_dir_info { struct ecma119_dir_info
{
/* Block where the directory entries will be written on image */ /* Block where the directory entries will be written on image */
size_t block; size_t block;
size_t nchildren; size_t nchildren;
Ecma119Node **children; Ecma119Node **children;
/* /*
* Size of the dir, i.e., sum of the lengths of all directory records. * Size of the dir, i.e., sum of the lengths of all directory records.
* It is computed by calc_dir_size() [ecma119.c]. * It is computed by calc_dir_size() [ecma119.c].
* Note that this don't include the length of any SUSP Continuation * Note that this don't include the length of any SUSP Continuation
* Area needed by the dir, but it includes the size of the SUSP entries * Area needed by the dir, but it includes the size of the SUSP entries
* than fit in the directory records System Use Field. * than fit in the directory records System Use Field.
*/ */
size_t len; size_t len;
/** /**
* Real parent if the dir has been reallocated. NULL otherwise. * Real parent if the dir has been reallocated. NULL otherwise.
*/ */
@ -56,24 +57,25 @@ struct ecma119_node
* Version number is not include, it is added on the fly * Version number is not include, it is added on the fly
*/ */
char *iso_name; char *iso_name;
Ecma119Node *parent; Ecma119Node *parent;
IsoNode *node; /*< reference to the iso node */ IsoNode *node; /*< reference to the iso node */
// TODO add true support for this // TODO add true support for this
ino_t ino; ino_t ino;
nlink_t nlink; nlink_t nlink;
/**< file, symlink, special, directory or placeholder */ /**< file, symlink, special, directory or placeholder */
enum ecma119_node_type type; enum ecma119_node_type type;
union { union
{
IsoFileSrc *file; IsoFileSrc *file;
// TODO this wastes too much memory, as dirs have much more // TODO this wastes too much memory, as dirs have much more
// atts than other kind of files. Replace with a pointer. // atts than other kind of files. Replace with a pointer.
struct ecma119_dir_info dir; struct ecma119_dir_info dir;
/** this field points to the relocated directory. */ /** this field points to the relocated directory. */
Ecma119Node *real_me; Ecma119Node *real_me;
} info; } info;
}; };

View File

@ -23,15 +23,15 @@ int iso_file_src_cmp(const void *n1, const void *n2)
unsigned int fs_id1, fs_id2; unsigned int fs_id1, fs_id2;
dev_t dev_id1, dev_id2; dev_t dev_id1, dev_id2;
ino_t ino_id1, ino_id2; ino_t ino_id1, ino_id2;
f1 = (const IsoFileSrc *)n1; f1 = (const IsoFileSrc *)n1;
f2 = (const IsoFileSrc *)n2; f2 = (const IsoFileSrc *)n2;
res = iso_stream_get_id(f1->stream, &fs_id1, &dev_id1, &ino_id1); res = iso_stream_get_id(f1->stream, &fs_id1, &dev_id1, &ino_id1);
res = iso_stream_get_id(f2->stream, &fs_id2, &dev_id2, &ino_id2); res = iso_stream_get_id(f2->stream, &fs_id2, &dev_id2, &ino_id2);
//TODO take care about res <= 0 //TODO take care about res <= 0
if (fs_id1 < fs_id2) { if (fs_id1 < fs_id2) {
return -1; return -1;
} else if (fs_id1 > fs_id2) { } else if (fs_id1 > fs_id2) {
@ -44,8 +44,7 @@ int iso_file_src_cmp(const void *n1, const void *n2)
return 1; return 1;
} else { } else {
/* files belong to same device in same fs */ /* files belong to same device in same fs */
return (ino_id1 < ino_id2) ? -1 : return (ino_id1 < ino_id2) ? -1 : (ino_id1 > ino_id2) ? 1 : 0;
(ino_id1 > ino_id2) ? 1 : 0;
} }
} }
} }
@ -57,11 +56,11 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src)
unsigned int fs_id; unsigned int fs_id;
dev_t dev_id; dev_t dev_id;
ino_t ino_id; ino_t ino_id;
if (img == NULL || file == NULL || src == NULL) { if (img == NULL || file == NULL || src == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
res = iso_stream_get_id(file->stream, &fs_id, &dev_id, &ino_id); res = iso_stream_get_id(file->stream, &fs_id, &dev_id, &ino_id);
if (res < 0) { if (res < 0) {
return res; return res;
@ -73,18 +72,18 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src)
return ISO_ERROR; return ISO_ERROR;
} else { } else {
int ret; int ret;
fsrc = malloc(sizeof(IsoFileSrc)); fsrc = malloc(sizeof(IsoFileSrc));
if (fsrc == NULL) { if (fsrc == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
/* fill key and other atts */ /* fill key and other atts */
fsrc->prev_img = file->msblock ? 1 : 0; fsrc->prev_img = file->msblock ? 1 : 0;
fsrc->block = file->msblock; fsrc->block = file->msblock;
fsrc->sort_weight = file->sort_weight; fsrc->sort_weight = file->sort_weight;
fsrc->stream = file->stream; fsrc->stream = file->stream;
/* insert the filesrc in the tree */ /* insert the filesrc in the tree */
ret = iso_rbtree_insert(img->files, fsrc, (void**)src); ret = iso_rbtree_insert(img->files, fsrc, (void**)src);
if (ret <= 0) { if (ret <= 0) {
@ -105,8 +104,7 @@ off_t iso_file_src_get_size(IsoFileSrc *file)
return iso_stream_get_size(file->stream); return iso_stream_get_size(file->stream);
} }
static int static int cmp_by_weight(const void *f1, const void *f2)
cmp_by_weight(const void *f1, const void *f2)
{ {
IsoFileSrc *f = *((IsoFileSrc**)f1); IsoFileSrc *f = *((IsoFileSrc**)f1);
IsoFileSrc *g = *((IsoFileSrc**)f2); IsoFileSrc *g = *((IsoFileSrc**)f2);
@ -120,33 +118,33 @@ int filesrc_writer_compute_data_blocks(IsoImageWriter *writer)
size_t i, size; size_t i, size;
Ecma119Image *t; Ecma119Image *t;
IsoFileSrc **filelist; IsoFileSrc **filelist;
if (writer == NULL) { if (writer == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
t = writer->target; t = writer->target;
/* store the filesrcs in a array */ /* store the filesrcs in a array */
filelist = (IsoFileSrc**)iso_rbtree_to_array(t->files); filelist = (IsoFileSrc**)iso_rbtree_to_array(t->files);
if (filelist == NULL) { if (filelist == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
size = iso_rbtree_get_size(t->files); size = iso_rbtree_get_size(t->files);
/* sort files by weight, if needed */ /* sort files by weight, if needed */
if (t->sort_files) { if (t->sort_files) {
qsort(t->files, size, sizeof(void*), cmp_by_weight); qsort(t->files, size, sizeof(void*), cmp_by_weight);
} }
/* fill block value */ /* fill block value */
for (i = 0; i < size; ++i) { for (i = 0; i < size; ++i) {
IsoFileSrc *file = filelist[i]; IsoFileSrc *file = filelist[i];
file->block = t->curblock; file->block = t->curblock;
t->curblock += div_up(iso_file_src_get_size(file), BLOCK_SIZE); t->curblock += div_up(iso_file_src_get_size(file), BLOCK_SIZE);
} }
/* the list is only needed by this writer, store locally */ /* the list is only needed by this writer, store locally */
writer->data = filelist; writer->data = filelist;
return ISO_SUCCESS; return ISO_SUCCESS;
@ -176,25 +174,25 @@ int filesrc_close(IsoFileSrc *file)
* @return * @return
* 1 ok, 0 EOF, < 0 error * 1 ok, 0 EOF, < 0 error
*/ */
static static
int filesrc_read(IsoFileSrc *file, char *buf, size_t count) int filesrc_read(IsoFileSrc *file, char *buf, size_t count)
{ {
size_t bytes = 0; size_t bytes = 0;
/* loop to ensure the full buffer is filled */ /* loop to ensure the full buffer is filled */
do { do {
ssize_t result; ssize_t result;
result = iso_stream_read(file->stream, buf + bytes, count - bytes); result = iso_stream_read(file->stream, buf + bytes, count - bytes);
if (result < 0) { if (result < 0) {
/* fill buffer with 0s and return */ /* fill buffer with 0s and return */
memset(buf + bytes, 0, count - bytes); memset(buf + bytes, 0, count - bytes);
return result; return result;
} }
if (result == 0) if (result == 0)
break; break;
bytes += result; bytes += result;
} while (bytes < count); } while (bytes < count);
if (bytes < count) { if (bytes < count) {
/* eof */ /* eof */
memset(buf + bytes, 0, count - bytes); memset(buf + bytes, 0, count - bytes);
@ -212,16 +210,16 @@ int filesrc_writer_write_data(IsoImageWriter *writer)
Ecma119Image *t; Ecma119Image *t;
IsoFileSrc **filelist; IsoFileSrc **filelist;
char buffer[BLOCK_SIZE]; char buffer[BLOCK_SIZE];
if (writer == NULL) { if (writer == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
t = writer->target; t = writer->target;
filelist = writer->data; filelist = writer->data;
iso_msg_debug(t->image, "Writing Files..."); iso_msg_debug(t->image, "Writing Files...");
nfiles = iso_rbtree_get_size(t->files); nfiles = iso_rbtree_get_size(t->files);
for (i = 0; i < nfiles; ++i) { for (i = 0; i < nfiles; ++i) {
IsoFileSrc *file = filelist[i]; IsoFileSrc *file = filelist[i];
@ -239,20 +237,20 @@ int filesrc_writer_write_data(IsoImageWriter *writer)
* UPS, very ugly error, the best we can do is just to write * UPS, very ugly error, the best we can do is just to write
* 0's to image * 0's to image
*/ */
// TODO Stream needs a get_path function // TODO Stream needs a get_path function
iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE, iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE,
"File XXX can't be openned. Filling with 0s."); "File XXX can't be openned. Filling with 0s.");
memset(buffer, 0, BLOCK_SIZE); memset(buffer, 0, BLOCK_SIZE);
for (b = 0; b < nblocks; ++b) { for (b = 0; b < nblocks; ++b) {
res = iso_write(t, buffer, BLOCK_SIZE); res = iso_write(t, buffer, BLOCK_SIZE);
if (res < 0) { if (res < 0) {
/* ko, writer error, we need to go out! */ /* ko, writer error, we need to go out! */
return res; return res;
} }
} }
continue; continue;
} }
/* write file contents to image */ /* write file contents to image */
for (b = 0; b < nblocks; ++b) { for (b = 0; b < nblocks; ++b) {
int wres; int wres;
@ -263,16 +261,16 @@ int filesrc_writer_write_data(IsoImageWriter *writer)
return wres; return wres;
} }
} }
if (b < nblocks) { if (b < nblocks) {
/* premature end of file, due to error or eof */ /* premature end of file, due to error or eof */
if (res < 0) { if (res < 0) {
/* error */ /* error */
iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE, iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE,
"Read error in file XXXXX."); "Read error in file XXXXX.");
} else { } else {
/* eof */ /* eof */
iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE, iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE,
"Premature end of file XXXXX."); "Premature end of file XXXXX.");
} }
/* fill with 0s */ /* fill with 0s */
@ -286,10 +284,10 @@ int filesrc_writer_write_data(IsoImageWriter *writer)
} }
} }
} }
filesrc_close(file); filesrc_close(file);
} }
return ISO_SUCCESS; return ISO_SUCCESS;
} }
@ -304,19 +302,19 @@ int filesrc_writer_free_data(IsoImageWriter *writer)
int iso_file_src_writer_create(Ecma119Image *target) int iso_file_src_writer_create(Ecma119Image *target)
{ {
IsoImageWriter *writer; IsoImageWriter *writer;
writer = malloc(sizeof(IsoImageWriter)); writer = malloc(sizeof(IsoImageWriter));
if (writer == NULL) { if (writer == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
writer->compute_data_blocks = filesrc_writer_compute_data_blocks; writer->compute_data_blocks = filesrc_writer_compute_data_blocks;
writer->write_vol_desc = filesrc_writer_write_vol_desc; writer->write_vol_desc = filesrc_writer_write_vol_desc;
writer->write_data = filesrc_writer_write_data; writer->write_data = filesrc_writer_write_data;
writer->free_data = filesrc_writer_free_data; writer->free_data = filesrc_writer_free_data;
writer->data = NULL; writer->data = NULL;
writer->target = target; writer->target = target;
/* add this writer to image */ /* add this writer to image */
target->writers[target->nwriters++] = writer; target->writers[target->nwriters++] = writer;

View File

@ -14,8 +14,9 @@
#include <stdint.h> #include <stdint.h>
struct Iso_File_Src { struct Iso_File_Src
unsigned int prev_img:1; /**< if the file comes from a previous image */ {
unsigned int prev_img :1; /**< if the file comes from a previous image */
uint32_t block; /**< Block where this file will be written on image */ uint32_t block; /**< Block where this file will be written on image */
int sort_weight; int sort_weight;
IsoStream *stream; IsoStream *stream;

View File

@ -6,7 +6,6 @@
* published by the Free Software Foundation. See COPYING file for details. * published by the Free Software Foundation. See COPYING file for details.
*/ */
/* /*
* Filesystem/FileSource implementation to access the local filesystem. * Filesystem/FileSource implementation to access the local filesystem.
*/ */
@ -29,15 +28,16 @@
/* /*
* We can share a local filesystem object, as it has no private atts. * We can share a local filesystem object, as it has no private atts.
*/ */
IsoFilesystem *lfs = NULL; IsoFilesystem *lfs= NULL;
typedef struct typedef struct
{ {
/* IsoFilesystem *fs; It seems not needed */ /* IsoFilesystem *fs; It seems not needed */
char *path; char *path;
unsigned int openned:2; /* 0: not openned, 1: file, 2:dir */ unsigned int openned :2; /* 0: not openned, 1: file, 2:dir */
union { union
{
int fd; int fd;
DIR *dir; DIR *dir;
} info; } info;
@ -59,10 +59,10 @@ char* lfs_get_name(IsoFileSource *src)
data = src->data; data = src->data;
p = strdup(data->path); /* because basename() might modify its arg */ p = strdup(data->path); /* because basename() might modify its arg */
name = strdup(basename(p)); name = strdup(basename(p));
free(p); free(p);
return name; return name;
} }
static static
int lfs_lstat(IsoFileSource *src, struct stat *info) int lfs_lstat(IsoFileSource *src, struct stat *info)
{ {
@ -77,7 +77,7 @@ int lfs_lstat(IsoFileSource *src, struct stat *info)
int err; int err;
/* error, choose an appropriate return code */ /* error, choose an appropriate return code */
switch(errno) { switch (errno) {
case EACCES: case EACCES:
err = ISO_FILE_ACCESS_DENIED; err = ISO_FILE_ACCESS_DENIED;
break; break;
@ -101,7 +101,7 @@ int lfs_lstat(IsoFileSource *src, struct stat *info)
} }
return ISO_SUCCESS; return ISO_SUCCESS;
} }
static static
int lfs_stat(IsoFileSource *src, struct stat *info) int lfs_stat(IsoFileSource *src, struct stat *info)
{ {
@ -116,7 +116,7 @@ int lfs_stat(IsoFileSource *src, struct stat *info)
int err; int err;
/* error, choose an appropriate return code */ /* error, choose an appropriate return code */
switch(errno) { switch (errno) {
case EACCES: case EACCES:
err = ISO_FILE_ACCESS_DENIED; err = ISO_FILE_ACCESS_DENIED;
break; break;
@ -176,7 +176,7 @@ int lfs_open(IsoFileSource *src)
* parsed in the lstat call above * parsed in the lstat call above
*/ */
if (data->openned == 0) { if (data->openned == 0) {
switch(errno) { switch (errno) {
case EACCES: case EACCES:
err = ISO_FILE_ACCESS_DENIED; err = ISO_FILE_ACCESS_DENIED;
break; break;
@ -205,7 +205,7 @@ int lfs_close(IsoFileSource *src)
} }
data = src->data; data = src->data;
switch(data->openned) { switch (data->openned) {
case 1: /* not dir */ case 1: /* not dir */
ret = close(data->info.fd) == 0 ? ISO_SUCCESS : ISO_FILE_ERROR; ret = close(data->info.fd) == 0 ? ISO_SUCCESS : ISO_FILE_ERROR;
break; break;
@ -232,14 +232,14 @@ int lfs_read(IsoFileSource *src, void *buf, size_t count)
} }
data = src->data; data = src->data;
switch(data->openned) { switch (data->openned) {
case 1: /* not dir */ case 1: /* not dir */
{ {
int ret; int ret;
ret = read(data->info.fd, buf, count); ret = read(data->info.fd, buf, count);
if (ret < 0) { if (ret < 0) {
/* error on read */ /* error on read */
switch(errno) { switch (errno) {
case EINTR: case EINTR:
ret = ISO_INTERRUPTED; ret = ISO_INTERRUPTED;
break; break;
@ -273,7 +273,7 @@ int lfs_readdir(IsoFileSource *src, IsoFileSource **child)
} }
data = src->data; data = src->data;
switch(data->openned) { switch (data->openned) {
case 1: /* not dir */ case 1: /* not dir */
return ISO_FILE_IS_NOT_DIR; return ISO_FILE_IS_NOT_DIR;
case 2: /* directory */ case 2: /* directory */
@ -292,7 +292,7 @@ int lfs_readdir(IsoFileSource *src, IsoFileSource **child)
else else
return 0; /* EOF */ return 0; /* EOF */
} }
if (strcmp(entry->d_name,".") && strcmp(entry->d_name,"..")) { if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) {
break; break;
} }
} }
@ -342,7 +342,7 @@ int lfs_readlink(IsoFileSource *src, char *buf, size_t bufsiz)
size = readlink(data->path, buf, bufsiz - 1); size = readlink(data->path, buf, bufsiz - 1);
if (size < 0) { if (size < 0) {
/* error */ /* error */
switch(errno) { switch (errno) {
case EACCES: case EACCES:
return ISO_FILE_ACCESS_DENIED; return ISO_FILE_ACCESS_DENIED;
case ENOTDIR: case ENOTDIR:
@ -389,7 +389,7 @@ void lfs_free(IsoFileSource *src)
iso_filesystem_unref(lfs); iso_filesystem_unref(lfs);
} }
IsoFileSourceIface lfs_class = { IsoFileSourceIface lfs_class = {
lfs_get_path, lfs_get_path,
lfs_get_name, lfs_get_name,
lfs_lstat, lfs_lstat,
@ -450,7 +450,7 @@ int iso_file_source_new_lfs(const char *path, IsoFileSource **src)
lfs_src->refcount = 1; lfs_src->refcount = 1;
lfs_src->data = data; lfs_src->data = data;
lfs_src->class = &lfs_class; lfs_src->class = &lfs_class;
/* take a ref to local filesystem */ /* take a ref to local filesystem */
iso_filesystem_ref(lfs); iso_filesystem_ref(lfs);
@ -462,19 +462,19 @@ int iso_file_source_new_lfs(const char *path, IsoFileSource **src)
static static
int lfs_get_root(IsoFilesystem *fs, IsoFileSource **root) int lfs_get_root(IsoFilesystem *fs, IsoFileSource **root)
{ {
if (fs == NULL || root == NULL) { if (fs == NULL || root == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
return iso_file_source_new_lfs("/", root); return iso_file_source_new_lfs("/", root);
} }
static static
int lfs_get_by_path(IsoFilesystem *fs, const char *path, IsoFileSource **file) int lfs_get_by_path(IsoFilesystem *fs, const char *path, IsoFileSource **file)
{ {
if (fs == NULL || path == NULL || file == NULL) { if (fs == NULL || path == NULL || file == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
return iso_file_source_new_lfs(path, file); return iso_file_source_new_lfs(path, file);
} }
static static
@ -486,25 +486,25 @@ unsigned int lfs_get_id(IsoFilesystem *fs)
static static
void lfs_fs_free(IsoFilesystem *fs) void lfs_fs_free(IsoFilesystem *fs)
{ {
lfs = NULL; lfs = NULL;
} }
int iso_local_filesystem_new(IsoFilesystem **fs) int iso_local_filesystem_new(IsoFilesystem **fs)
{ {
if (fs == NULL) { if (fs == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
if (lfs != NULL) { if (lfs != NULL) {
/* just take a new ref */ /* just take a new ref */
iso_filesystem_ref(lfs); iso_filesystem_ref(lfs);
} else { } else {
lfs = malloc(sizeof(IsoFilesystem)); lfs = malloc(sizeof(IsoFilesystem));
if (lfs == NULL) { if (lfs == NULL) {
return ISO_OUT_OF_MEM; return ISO_OUT_OF_MEM;
} }
/* fill struct */ /* fill struct */
lfs->refcount = 1; lfs->refcount = 1;
lfs->data = NULL; /* we don't need private data */ lfs->data = NULL; /* we don't need private data */
@ -513,6 +513,6 @@ int iso_local_filesystem_new(IsoFilesystem **fs)
lfs->get_id = lfs_get_id; lfs->get_id = lfs_get_id;
lfs->free = lfs_fs_free; lfs->free = lfs_fs_free;
} }
*fs = lfs; *fs = lfs;
return ISO_SUCCESS; return ISO_SUCCESS;
} }

View File

@ -16,26 +16,26 @@ unsigned int iso_fs_global_id = 100;
void iso_file_source_ref(IsoFileSource *src) void iso_file_source_ref(IsoFileSource *src)
{ {
++src->refcount; ++src->refcount;
} }
void iso_file_source_unref(IsoFileSource *src) void iso_file_source_unref(IsoFileSource *src)
{ {
if (--src->refcount == 0) { if (--src->refcount == 0) {
src->class->free(src); src->class->free(src);
free(src); free(src);
} }
} }
void iso_filesystem_ref(IsoFilesystem *fs) void iso_filesystem_ref(IsoFilesystem *fs)
{ {
++fs->refcount; ++fs->refcount;
} }
void iso_filesystem_unref(IsoFilesystem *fs) void iso_filesystem_unref(IsoFilesystem *fs)
{ {
if (--fs->refcount == 0) { if (--fs->refcount == 0) {
fs->free(fs); fs->free(fs);
free(fs); free(fs);
} }
} }

View File

@ -14,8 +14,7 @@
*/ */
/* /*
* Some functions here will be moved to libisofs.h when we expose * Some functions here will be moved to libisofs.h when we expose Sources.
* Sources.
*/ */
#include <sys/stat.h> #include <sys/stat.h>
@ -43,9 +42,9 @@ struct Iso_Filesystem
* @return * @return
* 1 success, < 0 error * 1 success, < 0 error
*/ */
int (*get_by_path)(IsoFilesystem *fs, const char *path, int (*get_by_path)(IsoFilesystem *fs, const char *path,
IsoFileSource **file); IsoFileSource **file);
/** /**
* Get filesystem identifier. * Get filesystem identifier.
* *
@ -81,7 +80,7 @@ typedef struct IsoFileSource_Iface
* freed by the user. * freed by the user.
*/ */
const char* (*get_path)(IsoFileSource *src); const char* (*get_path)(IsoFileSource *src);
/** /**
* Get the name of the file, with the dir component of the path. * Get the name of the file, with the dir component of the path.
* *
@ -103,7 +102,7 @@ typedef struct IsoFileSource_Iface
* ISO_NULL_POINTER * ISO_NULL_POINTER
*/ */
int (*lstat)(IsoFileSource *src, struct stat *info); int (*lstat)(IsoFileSource *src, struct stat *info);
/** /**
* Get information about the file. If the file is a symlink, the info * Get information about the file. If the file is a symlink, the info
* returned refers to the destination. * returned refers to the destination.
@ -211,7 +210,7 @@ typedef struct IsoFileSource_Iface
* *
*/ */
int (*readlink)(IsoFileSource *src, char *buf, size_t bufsiz); int (*readlink)(IsoFileSource *src, char *buf, size_t bufsiz);
/** /**
* Get the filesystem for this source. No extra ref is added, so you * Get the filesystem for this source. No extra ref is added, so you
* musn't unref the IsoFilesystem. * musn't unref the IsoFilesystem.
@ -233,7 +232,8 @@ typedef struct IsoFileSource_Iface
*/ */
} IsoFileSourceIface; } IsoFileSourceIface;
struct Iso_File_Source { struct Iso_File_Source
{
const IsoFileSourceIface *class; const IsoFileSourceIface *class;
int refcount; int refcount;
void *data; void *data;
@ -245,54 +245,63 @@ void iso_file_source_unref(IsoFileSource *src);
/* /*
* this are just helpers to invoque methods in class * this are just helpers to invoque methods in class
*/ */
extern inline extern inline
const char* iso_file_source_get_path(IsoFileSource *src) { const char* iso_file_source_get_path(IsoFileSource *src)
{
return src->class->get_path(src); return src->class->get_path(src);
} }
extern inline extern inline
char* iso_file_source_get_name(IsoFileSource *src) { char* iso_file_source_get_name(IsoFileSource *src)
{
return src->class->get_name(src); return src->class->get_name(src);
} }
extern inline extern inline
int iso_file_source_lstat(IsoFileSource *src, struct stat *info) { int iso_file_source_lstat(IsoFileSource *src, struct stat *info)
{
return src->class->lstat(src, info); return src->class->lstat(src, info);
} }
extern inline extern inline
int iso_file_source_stat(IsoFileSource *src, struct stat *info) { int iso_file_source_stat(IsoFileSource *src, struct stat *info)
{
return src->class->stat(src, info); return src->class->stat(src, info);
} }
extern inline extern inline
int iso_file_source_open(IsoFileSource *src) { int iso_file_source_open(IsoFileSource *src)
{
return src->class->open(src); return src->class->open(src);
} }
extern inline extern inline
int iso_file_source_close(IsoFileSource *src) { int iso_file_source_close(IsoFileSource *src)
{
return src->class->close(src); return src->class->close(src);
} }
extern inline extern inline
int iso_file_source_read(IsoFileSource *src, void *buf, size_t count) { int iso_file_source_read(IsoFileSource *src, void *buf, size_t count)
{
return src->class->read(src, buf, count); return src->class->read(src, buf, count);
} }
extern inline extern inline
int iso_file_source_readdir(IsoFileSource *src, IsoFileSource **child) int iso_file_source_readdir(IsoFileSource *src, IsoFileSource **child)
{ {
return src->class->readdir(src, child); return src->class->readdir(src, child);
} }
extern inline extern inline
int iso_file_source_readlink(IsoFileSource *src, char *buf, size_t bufsiz) { int iso_file_source_readlink(IsoFileSource *src, char *buf, size_t bufsiz)
{
return src->class->readlink(src, buf, bufsiz); return src->class->readlink(src, buf, bufsiz);
} }
extern inline extern inline
IsoFilesystem* iso_file_source_get_filesystem(IsoFileSource *src) { IsoFilesystem* iso_file_source_get_filesystem(IsoFileSource *src)
{
return src->class->get_filesystem(src); return src->class->get_filesystem(src);
} }

View File

@ -31,23 +31,23 @@ int iso_image_new(const char *name, IsoImage **image)
{ {
int res; int res;
IsoImage *img; IsoImage *img;
if (image == NULL) { if (image == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
img = calloc(1, sizeof(IsoImage)); img = calloc(1, sizeof(IsoImage));
if (img == NULL) { if (img == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
/* local filesystem will be used by default */ /* local filesystem will be used by default */
res = iso_local_filesystem_new(&(img->fs)); res = iso_local_filesystem_new(&(img->fs));
if (res < 0) { if (res < 0) {
free(img); free(img);
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
/* use basic builder as default */ /* use basic builder as default */
res = iso_node_basic_builder_new(&(img->builder)); res = iso_node_basic_builder_new(&(img->builder));
if (res < 0) { if (res < 0) {
@ -55,7 +55,7 @@ int iso_image_new(const char *name, IsoImage **image)
free(img); free(img);
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
/* create message messenger */ /* create message messenger */
res = libiso_msgs_new(&img->messenger, 0); res = libiso_msgs_new(&img->messenger, 0);
if (res <= 0) { if (res <= 0) {
@ -64,9 +64,9 @@ int iso_image_new(const char *name, IsoImage **image)
free(img); free(img);
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
libiso_msgs_set_severities(img->messenger, LIBISO_MSGS_SEV_NEVER, libiso_msgs_set_severities(img->messenger, LIBISO_MSGS_SEV_NEVER,
LIBISO_MSGS_SEV_FATAL, name, 0); LIBISO_MSGS_SEV_FATAL, name, 0);
/* fill image fields */ /* fill image fields */
res = iso_node_new_root(&img->root); res = iso_node_new_root(&img->root);
if (res < 0) { if (res < 0) {
@ -77,7 +77,7 @@ int iso_image_new(const char *name, IsoImage **image)
return res; return res;
} }
img->refcount = 1; img->refcount = 1;
img->recOpts = calloc(1,sizeof(IsoImageRecOpts)); img->recOpts = calloc(1, sizeof(IsoImageRecOpts));
if (img->recOpts == NULL) { if (img->recOpts == NULL) {
libiso_msgs_destroy(&img->messenger, 0); libiso_msgs_destroy(&img->messenger, 0);
iso_node_builder_unref(img->builder); iso_node_builder_unref(img->builder);
@ -86,7 +86,7 @@ int iso_image_new(const char *name, IsoImage **image)
free(img); free(img);
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
if (name != NULL) { if (name != NULL) {
img->volset_id = strdup(name); img->volset_id = strdup(name);
img->volume_id = strdup(name); img->volume_id = strdup(name);
@ -167,7 +167,7 @@ const char *iso_image_get_publisher_id(const IsoImage *image)
} }
void iso_image_set_data_preparer_id(IsoImage *image, void iso_image_set_data_preparer_id(IsoImage *image,
const char *data_preparer_id) const char *data_preparer_id)
{ {
free(image->data_preparer_id); free(image->data_preparer_id);
image->data_preparer_id = strdup(data_preparer_id); image->data_preparer_id = strdup(data_preparer_id);
@ -201,7 +201,7 @@ const char *iso_image_get_application_id(const IsoImage *image)
} }
void iso_image_set_copyright_file_id(IsoImage *image, void iso_image_set_copyright_file_id(IsoImage *image,
const char *copyright_file_id) const char *copyright_file_id)
{ {
free(image->copyright_file_id); free(image->copyright_file_id);
image->copyright_file_id = strdup(copyright_file_id); image->copyright_file_id = strdup(copyright_file_id);
@ -213,7 +213,7 @@ const char *iso_image_get_copyright_file_id(const IsoImage *image)
} }
void iso_image_set_abstract_file_id(IsoImage *image, void iso_image_set_abstract_file_id(IsoImage *image,
const char *abstract_file_id) const char *abstract_file_id)
{ {
free(image->abstract_file_id); free(image->abstract_file_id);
image->abstract_file_id = strdup(abstract_file_id); image->abstract_file_id = strdup(abstract_file_id);
@ -224,8 +224,7 @@ const char *iso_image_get_abstract_file_id(const IsoImage *image)
return image->abstract_file_id; return image->abstract_file_id;
} }
void iso_image_set_biblio_file_id(IsoImage *image, void iso_image_set_biblio_file_id(IsoImage *image, const char *biblio_file_id)
const char *biblio_file_id)
{ {
free(image->biblio_file_id); free(image->biblio_file_id);
image->biblio_file_id = strdup(biblio_file_id); image->biblio_file_id = strdup(biblio_file_id);

View File

@ -21,39 +21,40 @@
* (Usefull, for example, in Multiple-Document-Interface GUI apps. * (Usefull, for example, in Multiple-Document-Interface GUI apps.
* [The stuff we have in init belongs really to image!] * [The stuff we have in init belongs really to image!]
*/ */
typedef struct Iso_Image_Rec_Opts IsoImageRecOpts; typedef struct Iso_Image_Rec_Opts IsoImageRecOpts;
struct Iso_Image { struct Iso_Image
{
int refcount; int refcount;
IsoDir *root; IsoDir *root;
char *volset_id; char *volset_id;
char *volume_id; /**< Volume identifier. */ char *volume_id; /**< Volume identifier. */
char *publisher_id; /**< Volume publisher. */ char *publisher_id; /**< Volume publisher. */
char *data_preparer_id; /**< Volume data preparer. */ char *data_preparer_id; /**< Volume data preparer. */
char *system_id; /**< Volume system identifier. */ char *system_id; /**< Volume system identifier. */
char *application_id; /**< Volume application id */ char *application_id; /**< Volume application id */
char *copyright_file_id; char *copyright_file_id;
char *abstract_file_id; char *abstract_file_id;
char *biblio_file_id; char *biblio_file_id;
/* message messenger for the image */ /* message messenger for the image */
struct libiso_msgs *messenger; struct libiso_msgs *messenger;
/** /**
* Default filesystem to use when adding files to the image tree. * Default filesystem to use when adding files to the image tree.
*/ */
IsoFilesystem *fs; IsoFilesystem *fs;
/* /*
* Default builder to use when adding files to the image tree. * Default builder to use when adding files to the image tree.
*/ */
IsoNodeBuilder *builder; IsoNodeBuilder *builder;
/** /**
* Options for recursive directory addition * Options for recursive directory addition
*/ */
@ -63,30 +64,31 @@ struct Iso_Image {
/** /**
* Options for recursive directory addition * Options for recursive directory addition
*/ */
struct Iso_Image_Rec_Opts { struct Iso_Image_Rec_Opts
{
/** /**
* Whether to follow symlinks or just add them as symlinks * Whether to follow symlinks or just add them as symlinks
*/ */
unsigned int follow_symlinks; unsigned int follow_symlinks;
/** /**
* Whether to skip hidden files * Whether to skip hidden files
*/ */
unsigned int ignore_hidden; unsigned int ignore_hidden;
/** /**
* Whether to stop on an error. Some errors, such as memory errors, * Whether to stop on an error. Some errors, such as memory errors,
* always cause a stop * always cause a stop
*/ */
unsigned int stop_on_error; unsigned int stop_on_error;
/** /**
* Files to exclude * Files to exclude
* TODO add wildcard support * TODO add wildcard support
*/ */
char** excludes; char** excludes;
/** /**
* if the dir already contains a node with the same name, whether to * if the dir already contains a node with the same name, whether to
* replace or not the old node with the new. * replace or not the old node with the new.
@ -97,7 +99,7 @@ struct Iso_Image_Rec_Opts {
* if both are dirs, add contents (and what to do with conflicts?) * if both are dirs, add contents (and what to do with conflicts?)
*/ */
int replace; int replace;
/** /**
* When this is not NULL, it is a pointer to a function that will * When this is not NULL, it is a pointer to a function that will
* be called just before a file will be added, or when an error occurs. * be called just before a file will be added, or when an error occurs.

View File

@ -58,28 +58,29 @@ enum IsoHideNodeFlag {
/** /**
* Holds the options for the image generation. * Holds the options for the image generation.
*/ */
typedef struct { typedef struct
int level; /**< ISO level to write at. */ {
int level; /**< ISO level to write at. */
/** Which extensions to support. */ /** Which extensions to support. */
unsigned int rockridge:1; unsigned int rockridge :1;
/* relaxed constraints */ /* relaxed constraints */
unsigned int omit_version_numbers:1; unsigned int omit_version_numbers :1;
unsigned int allow_deep_paths:1; unsigned int allow_deep_paths :1;
//int relaxed_constraints; /**< see ecma119_relaxed_constraints_flag */ //int relaxed_constraints; /**< see ecma119_relaxed_constraints_flag */
//unsigned int copy_eltorito:1; //unsigned int copy_eltorito:1;
/**< /**<
* In multisession discs, select whether to copy el-torito catalog * In multisession discs, select whether to copy el-torito catalog
* and boot image. Copy is needed for isolinux images, that need to * and boot image. Copy is needed for isolinux images, that need to
* be patched. However, it can lead to problems when the image is * be patched. However, it can lead to problems when the image is
* not present in the iso filesystem, because we can't figure out * not present in the iso filesystem, because we can't figure out
* its size. In those cases, we only copy 1 block of data. * its size. In those cases, we only copy 1 block of data.
*/ */
/**< If files should be sorted based on their weight. */ /**< If files should be sorted based on their weight. */
unsigned int sort_files:1; unsigned int sort_files :1;
/** /**
* The following options set the default values for files and directory * The following options set the default values for files and directory
@ -92,10 +93,10 @@ typedef struct {
* below. Note that for mode attributes, only the permissions are set, the * below. Note that for mode attributes, only the permissions are set, the
* file type remains unchanged. * file type remains unchanged.
*/ */
unsigned int replace_dir_mode:2; unsigned int replace_dir_mode :2;
unsigned int replace_file_mode:2; unsigned int replace_file_mode :2;
unsigned int replace_uid:2; unsigned int replace_uid :2;
unsigned int replace_gid:2; unsigned int replace_gid :2;
mode_t dir_mode; /** Mode to use on dirs when replace_dir_mode == 2. */ mode_t dir_mode; /** Mode to use on dirs when replace_dir_mode == 2. */
mode_t file_mode; /** Mode to use on files when replace_file_mode == 2. */ mode_t file_mode; /** Mode to use on files when replace_file_mode == 2. */
@ -103,35 +104,35 @@ typedef struct {
gid_t gid; /** gid to use when replace_gid == 2. */ gid_t gid; /** gid to use when replace_gid == 2. */
char *output_charset; /**< NULL to use default charset */ char *output_charset; /**< NULL to use default charset */
// uint32_t ms_block; // uint32_t ms_block;
/**< /**<
* Start block for multisession. When this is greater than 0, * Start block for multisession. When this is greater than 0,
* it's suppossed to be the lba of the next writable address * it's suppossed to be the lba of the next writable address
* on disc; all block lba on image will take this into account, * on disc; all block lba on image will take this into account,
* and files from a previous session will not be written on * and files from a previous session will not be written on
* image. This behavior is only suitable for images to be * image. This behavior is only suitable for images to be
* appended to a multisession disc. * appended to a multisession disc.
* When this is 0, no multisession image will be created. If * When this is 0, no multisession image will be created. If
* some files are taken from a previous image, its contents * some files are taken from a previous image, its contents
* will be written again to the new image. Use this with new * will be written again to the new image. Use this with new
* images or if you plan to modify an existin image. * images or if you plan to modify an existin image.
*/ */
// struct data_source* src; // struct data_source* src;
// /**< // /**<
// * When modifying a image, this is the source of the original // * When modifying a image, this is the source of the original
// * image, used to read file contents. // * image, used to read file contents.
// * Otherwise it can be NULL. // * Otherwise it can be NULL.
// */ // */
// uint8_t *overwrite; // uint8_t *overwrite;
// /**< // /**<
// * When not NULL, it should point to a buffer of at least // * When not NULL, it should point to a buffer of at least
// * 64KiB, where libisofs will write the contents that should // * 64KiB, where libisofs will write the contents that should
// * be written at the beginning of a overwriteable media, to // * be written at the beginning of a overwriteable media, to
// * grow the image. // * grow the image.
// * You shoudl initialize the buffer either with 0s, or with // * You shoudl initialize the buffer either with 0s, or with
// * the contents of the first blocks of the image you're // * the contents of the first blocks of the image you're
// * growing. In most cases, 0 is good enought. // * growing. In most cases, 0 is good enought.
// */ // */
} Ecma119WriteOpts; } Ecma119WriteOpts;
/** /**
@ -210,7 +211,7 @@ const char *iso_image_get_publisher_id(const IsoImage *image);
* Fill in the data preparer for a image. * Fill in the data preparer for a image.
*/ */
void iso_image_set_data_preparer_id(IsoImage *image, void iso_image_set_data_preparer_id(IsoImage *image,
const char *data_preparer_id); const char *data_preparer_id);
/** /**
* Get the data preparer of a image. * Get the data preparer of a image.
@ -248,7 +249,7 @@ const char *iso_image_get_application_id(const IsoImage *image);
* to a file on disc. Up to 37 characters. * to a file on disc. Up to 37 characters.
*/ */
void iso_image_set_copyright_file_id(IsoImage *image, void iso_image_set_copyright_file_id(IsoImage *image,
const char *copyright_file_id); const char *copyright_file_id);
/** /**
* Get the copyright information of a image. * Get the copyright information of a image.
@ -262,7 +263,7 @@ const char *iso_image_get_copyright_file_id(const IsoImage *image);
* to a file on disc. Up to 37 characters. * to a file on disc. Up to 37 characters.
*/ */
void iso_image_set_abstract_file_id(IsoImage *image, void iso_image_set_abstract_file_id(IsoImage *image,
const char *abstract_file_id); const char *abstract_file_id);
/** /**
* Get the abstract information of a image. * Get the abstract information of a image.
@ -275,8 +276,7 @@ const char *iso_image_get_abstract_file_id(const IsoImage *image);
* Fill biblio information for the image. Usually this refers * Fill biblio information for the image. Usually this refers
* to a file on disc. Up to 37 characters. * to a file on disc. Up to 37 characters.
*/ */
void iso_image_set_biblio_file_id(IsoImage *image, void iso_image_set_biblio_file_id(IsoImage *image, const char *biblio_file_id);
const char *biblio_file_id);
/** /**
* Get the biblio information of a image. * Get the biblio information of a image.
@ -659,9 +659,9 @@ int iso_file_get_sort_weight(IsoFile *file);
int iso_tree_add_new_dir(IsoDir *parent, const char *name, IsoDir **dir); int iso_tree_add_new_dir(IsoDir *parent, const char *name, IsoDir **dir);
/* /*
TODO #00007 expose Strem and thi function: TODO #00007 expose Strem and thi function:
int iso_tree_add_new_file(IsoDir *parent, const char *name, stream, file) int iso_tree_add_new_file(IsoDir *parent, const char *name, stream, file)
*/ */
/** /**
* Add a new symlink to the directory tree. Permissions are set to 0777, * Add a new symlink to the directory tree. Permissions are set to 0777,
@ -687,7 +687,7 @@ int iso_tree_add_new_file(IsoDir *parent, const char *name, stream, file)
* 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_MEM_ERROR * ISO_MEM_ERROR
*/ */
int iso_tree_add_new_symlink(IsoDir *parent, const char *name, int iso_tree_add_new_symlink(IsoDir *parent, const char *name,
const char *dest, IsoSymlink **link); const char *dest, IsoSymlink **link);
/** /**
@ -728,7 +728,7 @@ int iso_tree_add_new_symlink(IsoDir *parent, const char *name,
* ISO_WRONG_ARG_VALUE if you select a incorrect mode * ISO_WRONG_ARG_VALUE if you select a incorrect mode
* ISO_MEM_ERROR * ISO_MEM_ERROR
*/ */
int iso_tree_add_new_special(IsoDir *parent, const char *name, mode_t mode, int iso_tree_add_new_special(IsoDir *parent, const char *name, mode_t mode,
dev_t dev, IsoSpecial **special); dev_t dev, IsoSpecial **special);
/** /**
@ -757,7 +757,7 @@ int iso_tree_add_new_special(IsoDir *parent, const char *name, mode_t mode,
* 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_MEM_ERROR * ISO_MEM_ERROR
*/ */
int iso_tree_add_node(IsoImage *image, IsoDir *parent, const char *path, int iso_tree_add_node(IsoImage *image, IsoDir *parent, const char *path,
IsoNode **node); IsoNode **node);
/** /**
@ -808,7 +808,7 @@ int iso_tree_path_to_node(IsoImage *image, const char *path, IsoNode **node);
* @return >0 for success, <=0 for error * @return >0 for success, <=0 for error
*/ */
int iso_image_set_msgs_severities(IsoImage *img, char *queue_severity, int iso_image_set_msgs_severities(IsoImage *img, char *queue_severity,
char *print_severity, char *print_id); char *print_severity, char *print_id);
/** /**
* Obtain the oldest pending message from a IsoImage message queue which has at * Obtain the oldest pending message from a IsoImage message queue which has at
* least the given minimum_severity. This message and any older message of * least the given minimum_severity. This message and any older message of

View File

@ -20,81 +20,78 @@ void iso_msg_debug(IsoImage *img, const char *fmt, ...)
{ {
char msg[MAX_MSG_LEN]; char msg[MAX_MSG_LEN];
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(msg, MAX_MSG_LEN, fmt, ap); vsnprintf(msg, MAX_MSG_LEN, fmt, ap);
va_end(ap); va_end(ap);
libiso_msgs_submit(img->messenger, -1, 0x00000002, LIBISO_MSGS_SEV_DEBUG, libiso_msgs_submit(img->messenger, -1, 0x00000002, LIBISO_MSGS_SEV_DEBUG,
LIBISO_MSGS_PRIO_ZERO, msg, 0, 0); LIBISO_MSGS_PRIO_ZERO, msg, 0, 0);
} }
void iso_msg_note(IsoImage *img, int error_code, const char *fmt, ...) void iso_msg_note(IsoImage *img, int error_code, const char *fmt, ...)
{ {
char msg[MAX_MSG_LEN]; char msg[MAX_MSG_LEN];
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(msg, MAX_MSG_LEN, fmt, ap); vsnprintf(msg, MAX_MSG_LEN, fmt, ap);
va_end(ap); va_end(ap);
libiso_msgs_submit(img->messenger, -1, error_code, LIBISO_MSGS_SEV_NOTE, libiso_msgs_submit(img->messenger, -1, error_code, LIBISO_MSGS_SEV_NOTE,
LIBISO_MSGS_PRIO_MEDIUM, msg, 0, 0); LIBISO_MSGS_PRIO_MEDIUM, msg, 0, 0);
} }
void iso_msg_hint(IsoImage *img, int error_code, const char *fmt, ...) void iso_msg_hint(IsoImage *img, int error_code, const char *fmt, ...)
{ {
char msg[MAX_MSG_LEN]; char msg[MAX_MSG_LEN];
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(msg, MAX_MSG_LEN, fmt, ap); vsnprintf(msg, MAX_MSG_LEN, fmt, ap);
va_end(ap); va_end(ap);
libiso_msgs_submit(img->messenger, -1, error_code, LIBISO_MSGS_SEV_HINT, libiso_msgs_submit(img->messenger, -1, error_code, LIBISO_MSGS_SEV_HINT,
LIBISO_MSGS_PRIO_MEDIUM, msg, 0, 0); LIBISO_MSGS_PRIO_MEDIUM, msg, 0, 0);
} }
void iso_msg_warn(IsoImage *img, int error_code, const char *fmt, ...) void iso_msg_warn(IsoImage *img, int error_code, const char *fmt, ...)
{ {
char msg[MAX_MSG_LEN]; char msg[MAX_MSG_LEN];
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(msg, MAX_MSG_LEN, fmt, ap); vsnprintf(msg, MAX_MSG_LEN, fmt, ap);
va_end(ap); va_end(ap);
libiso_msgs_submit(img->messenger, -1, error_code, libiso_msgs_submit(img->messenger, -1, error_code, LIBISO_MSGS_SEV_WARNING,
LIBISO_MSGS_SEV_WARNING, LIBISO_MSGS_PRIO_MEDIUM, LIBISO_MSGS_PRIO_MEDIUM, msg, 0, 0);
msg, 0, 0);
} }
void iso_msg_sorry(IsoImage *img, int error_code, const char *fmt, ...) void iso_msg_sorry(IsoImage *img, int error_code, const char *fmt, ...)
{ {
char msg[MAX_MSG_LEN]; char msg[MAX_MSG_LEN];
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(msg, MAX_MSG_LEN, fmt, ap); vsnprintf(msg, MAX_MSG_LEN, fmt, ap);
va_end(ap); va_end(ap);
libiso_msgs_submit(img->messenger, -1, error_code, libiso_msgs_submit(img->messenger, -1, error_code, LIBISO_MSGS_SEV_SORRY,
LIBISO_MSGS_SEV_SORRY, LIBISO_MSGS_PRIO_HIGH, LIBISO_MSGS_PRIO_HIGH, msg, 0, 0);
msg, 0, 0);
} }
void iso_msg_fatal(IsoImage *img, int error_code, const char *fmt, ...) void iso_msg_fatal(IsoImage *img, int error_code, const char *fmt, ...)
{ {
char msg[MAX_MSG_LEN]; char msg[MAX_MSG_LEN];
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(msg, MAX_MSG_LEN, fmt, ap); vsnprintf(msg, MAX_MSG_LEN, fmt, ap);
va_end(ap); va_end(ap);
libiso_msgs_submit(img->messenger, -1, error_code, libiso_msgs_submit(img->messenger, -1, error_code, LIBISO_MSGS_SEV_FATAL,
LIBISO_MSGS_SEV_FATAL, LIBISO_MSGS_PRIO_HIGH, LIBISO_MSGS_PRIO_HIGH, msg, 0, 0);
msg, 0, 0);
} }
/** /**
@ -113,19 +110,19 @@ void iso_msg_fatal(IsoImage *img, int error_code, const char *fmt, ...)
int iso_image_set_msgs_severities(IsoImage *img, char *queue_severity, int iso_image_set_msgs_severities(IsoImage *img, char *queue_severity,
char *print_severity, char *print_id) char *print_severity, char *print_id)
{ {
int ret, queue_sevno, print_sevno; int ret, queue_sevno, print_sevno;
ret = libiso_msgs__text_to_sev(queue_severity, &queue_sevno, 0); ret = libiso_msgs__text_to_sev(queue_severity, &queue_sevno, 0);
if (ret <= 0) if (ret <= 0)
return 0; return 0;
ret = libiso_msgs__text_to_sev(print_severity, &print_sevno, 0); ret = libiso_msgs__text_to_sev(print_severity, &print_sevno, 0);
if (ret <= 0) if (ret <= 0)
return 0; return 0;
ret = libiso_msgs_set_severities(img->messenger, queue_sevno, ret = libiso_msgs_set_severities(img->messenger, queue_sevno, print_sevno,
print_sevno, print_id, 0); print_id, 0);
if (ret <= 0) if (ret <= 0)
return 0; return 0;
return 1; return 1;
} }
#define ISO_MSGS_MESSAGE_LEN 4096 #define ISO_MSGS_MESSAGE_LEN 4096
@ -147,47 +144,47 @@ int iso_image_set_msgs_severities(IsoImage *img, char *queue_severity,
* @return 1 if a matching item was found, 0 if not, <0 for severe errors * @return 1 if a matching item was found, 0 if not, <0 for severe errors
*/ */
int iso_image_obtain_msgs(IsoImage *img, char *minimum_severity, int iso_image_obtain_msgs(IsoImage *img, char *minimum_severity,
int *error_code, char msg_text[], int *os_errno, int *error_code, char msg_text[], int *os_errno,
char severity[]) char severity[])
{ {
int ret, minimum_sevno, sevno, priority; int ret, minimum_sevno, sevno, priority;
char *textpt, *sev_name; char *textpt, *sev_name;
struct libiso_msgs_item *item = NULL; struct libiso_msgs_item *item= NULL;
if (img == NULL) if (img == NULL)
return 0; return 0;
ret = libiso_msgs__text_to_sev(minimum_severity, &minimum_sevno, 0); ret = libiso_msgs__text_to_sev(minimum_severity, &minimum_sevno, 0);
if (ret <= 0) if (ret <= 0)
return 0; return 0;
ret = libiso_msgs_obtain(img->messenger, &item, minimum_sevno, ret = libiso_msgs_obtain(img->messenger, &item, minimum_sevno,
LIBISO_MSGS_PRIO_ZERO, 0); LIBISO_MSGS_PRIO_ZERO, 0);
if (ret <= 0) if (ret <= 0)
goto ex; goto ex;
ret = libiso_msgs_item_get_msg(item, error_code, &textpt, os_errno, 0); ret = libiso_msgs_item_get_msg(item, error_code, &textpt, os_errno, 0);
if (ret <= 0) if (ret <= 0)
goto ex; goto ex;
strncpy(msg_text, textpt, ISO_MSGS_MESSAGE_LEN-1); strncpy(msg_text, textpt, ISO_MSGS_MESSAGE_LEN-1);
if(strlen(textpt) >= ISO_MSGS_MESSAGE_LEN) if (strlen(textpt) >= ISO_MSGS_MESSAGE_LEN)
msg_text[ISO_MSGS_MESSAGE_LEN-1] = 0; msg_text[ISO_MSGS_MESSAGE_LEN-1] = 0;
severity[0]= 0; severity[0]= 0;
ret = libiso_msgs_item_get_rank(item, &sevno, &priority, 0); ret = libiso_msgs_item_get_rank(item, &sevno, &priority, 0);
if(ret <= 0) if (ret <= 0)
goto ex; goto ex;
ret = libiso_msgs__sev_to_text(sevno, &sev_name, 0); ret = libiso_msgs__sev_to_text(sevno, &sev_name, 0);
if(ret <= 0) if (ret <= 0)
goto ex; goto ex;
strcpy(severity,sev_name); strcpy(severity, sev_name);
ret = 1; ret = 1;
ex: ex: ;
libiso_msgs_destroy_item(img->messenger, &item, 0); libiso_msgs_destroy_item(img->messenger, &item, 0);
return ret; return ret;
} }
void *iso_image_get_messenger(IsoImage *img) void *iso_image_get_messenger(IsoImage *img)
{ {
return img->messenger; return img->messenger;
} }

View File

@ -47,11 +47,11 @@
/** Can't read previous image file */ /** Can't read previous image file */
#define LIBISO_CANT_READ_IMG 0x00031003 #define LIBISO_CANT_READ_IMG 0x00031003
/* Unsupported SUSP entry */ /* Unsupported SUSP entry */
#define LIBISO_SUSP_UNHANLED 0x00030101 #define LIBISO_SUSP_UNHANLED 0x00030101
/* Wrong SUSP entry, that cause RR to be ignored */ /* Wrong SUSP entry, that cause RR to be ignored */
#define LIBISO_SUSP_WRONG 0x00030102 #define LIBISO_SUSP_WRONG 0x00030102
/* Unsupported multiple SUSP ER entries where found */ /* Unsupported multiple SUSP ER entries where found */
#define LIBISO_SUSP_MULTIPLE_ER 0x00030103 #define LIBISO_SUSP_MULTIPLE_ER 0x00030103
/** Unsupported RR feature. */ /** Unsupported RR feature. */
#define LIBISO_RR_UNSUPPORTED 0x00030111 #define LIBISO_RR_UNSUPPORTED 0x00030111

View File

@ -31,7 +31,7 @@ void iso_node_ref(IsoNode *node)
void iso_node_unref(IsoNode *node) void iso_node_unref(IsoNode *node)
{ {
if (--node->refcount == 0) { if (--node->refcount == 0) {
switch(node->type) { switch (node->type) {
case LIBISO_DIR: case LIBISO_DIR:
{ {
IsoNode *child = ((IsoDir*)node)->children; IsoNode *child = ((IsoDir*)node)->children;
@ -56,7 +56,7 @@ void iso_node_unref(IsoNode *node)
} }
default: default:
/* TODO #00002 handle deletion of each kind of node */ /* TODO #00002 handle deletion of each kind of node */
break; break;
} }
free(node->name); free(node->name);
free(node); free(node);
@ -79,12 +79,12 @@ enum IsoNodeType iso_node_get_type(IsoNode *node)
int iso_node_set_name(IsoNode *node, const char *name) int iso_node_set_name(IsoNode *node, const char *name)
{ {
char *new; char *new;
/* guard against the empty string or big names... */ /* guard against the empty string or big names... */
if (name[0] == '\0' || strlen(name) > 255) { if (name[0] == '\0' || strlen(name) > 255) {
return ISO_WRONG_ARG_VALUE; return ISO_WRONG_ARG_VALUE;
} }
/* ...against "." and ".." names... */ /* ...against "." and ".." names... */
if (!strcmp(name, ".") || !strcmp(name, "..")) { if (!strcmp(name, ".") || !strcmp(name, "..")) {
return ISO_WRONG_ARG_VALUE; return ISO_WRONG_ARG_VALUE;
@ -99,7 +99,7 @@ int iso_node_set_name(IsoNode *node, const char *name)
/* you can't change name of the root node */ /* you can't change name of the root node */
return ISO_WRONG_ARG_VALUE; return ISO_WRONG_ARG_VALUE;
} }
new = strdup(name); new = strdup(name);
if (new == NULL) { if (new == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
@ -124,7 +124,7 @@ int iso_node_set_name(IsoNode *node, const char *name)
return res; return res;
} }
} }
return ISO_SUCCESS; return ISO_SUCCESS;
} }
/** /**
@ -168,7 +168,6 @@ mode_t iso_node_get_mode(const IsoNode *node)
return node->mode; return node->mode;
} }
/** /**
* Set the user id for the node. This attribute is only useful when * Set the user id for the node. This attribute is only useful when
* Rock Ridge extensions are enabled. * Rock Ridge extensions are enabled.
@ -275,14 +274,14 @@ void iso_node_set_hidden(IsoNode *node, int hide_attrs)
int iso_dir_add_node(IsoDir *dir, IsoNode *child, int replace) int iso_dir_add_node(IsoDir *dir, IsoNode *child, int replace)
{ {
IsoNode **pos; IsoNode **pos;
if (dir == NULL || child == NULL) { if (dir == NULL || child == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
if ((IsoNode*)dir == child) { if ((IsoNode*)dir == child) {
return ISO_WRONG_ARG_VALUE; return ISO_WRONG_ARG_VALUE;
} }
/* /*
* check if child is already added to another dir, or if child * check if child is already added to another dir, or if child
* is the root node, where parent == itself * is the root node, where parent == itself
@ -290,7 +289,7 @@ int iso_dir_add_node(IsoDir *dir, IsoNode *child, int replace)
if (child->parent != NULL || child->parent == (IsoDir*)child) { if (child->parent != NULL || child->parent == (IsoDir*)child) {
return ISO_NODE_ALREADY_ADDED; return ISO_NODE_ALREADY_ADDED;
} }
pos = &(dir->children); pos = &(dir->children);
while (*pos != NULL && strcmp((*pos)->name, child->name) < 0) { while (*pos != NULL && strcmp((*pos)->name, child->name) < 0) {
pos = &((*pos)->next); pos = &((*pos)->next);
@ -311,11 +310,11 @@ int iso_dir_add_node(IsoDir *dir, IsoNode *child, int replace)
return ISO_WRONG_ARG_VALUE; return ISO_WRONG_ARG_VALUE;
} }
} }
child->next = *pos; child->next = *pos;
*pos = child; *pos = child;
child->parent = dir; child->parent = dir;
return ++dir->nchildren; return ++dir->nchildren;
} }
@ -342,19 +341,19 @@ int iso_dir_get_node(IsoDir *dir, const char *name, IsoNode **node)
if (dir == NULL || name == NULL) { if (dir == NULL || name == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
pos = dir->children; pos = dir->children;
while (pos != NULL && strcmp(pos->name, name) < 0) { while (pos != NULL && strcmp(pos->name, name) < 0) {
pos = pos->next; pos = pos->next;
} }
if (pos == NULL || strcmp(pos->name, name)) { if (pos == NULL || strcmp(pos->name, name)) {
if (node) { if (node) {
*node = NULL; *node = NULL;
} }
return 0; /* node not found */ return 0; /* node not found */
} }
if (node) { if (node) {
*node = pos; *node = pos;
} }
@ -380,7 +379,7 @@ int iso_dir_get_nchildren(IsoDir *dir)
int iso_dir_get_children(const IsoDir *dir, IsoDirIter **iter) int iso_dir_get_children(const IsoDir *dir, IsoDirIter **iter)
{ {
IsoDirIter *it; IsoDirIter *it;
if (dir == NULL || iter == NULL) { if (dir == NULL || iter == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
@ -388,10 +387,10 @@ int iso_dir_get_children(const IsoDir *dir, IsoDirIter **iter)
if (it == NULL) { if (it == NULL) {
return ISO_OUT_OF_MEM; return ISO_OUT_OF_MEM;
} }
it->dir = dir; it->dir = dir;
it->pos = dir->children; it->pos = dir->children;
*iter = it; *iter = it;
return ISO_SUCCESS; return ISO_SUCCESS;
} }
@ -437,14 +436,13 @@ void iso_dir_iter_free(IsoDirIter *iter)
free(iter); free(iter);
} }
static IsoNode** static IsoNode** iso_dir_find_node(IsoDir *dir, IsoNode *node)
iso_dir_find_node(IsoDir *dir, IsoNode *node)
{ {
IsoNode **pos; IsoNode **pos;
pos = &(dir->children); pos = &(dir->children);
while (*pos != NULL && *pos != node) { while (*pos != NULL && *pos != node) {
pos = &((*pos)->next); pos = &((*pos)->next);
} }
return pos; return pos;
} }
@ -461,7 +459,7 @@ int iso_node_take(IsoNode *node)
{ {
IsoNode **pos; IsoNode **pos;
IsoDir* dir; IsoDir* dir;
if (node == NULL) { if (node == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
@ -507,7 +505,7 @@ int iso_dir_iter_take(IsoDirIter *iter)
if (iter == NULL) { if (iter == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
pos = iter->dir->children; pos = iter->dir->children;
if (iter->pos == pos) { if (iter->pos == pos) {
return ISO_ERROR; return ISO_ERROR;
@ -599,7 +597,7 @@ int iso_file_get_sort_weight(IsoFile *file)
int iso_node_new_root(IsoDir **root) int iso_node_new_root(IsoDir **root)
{ {
IsoDir *dir; IsoDir *dir;
dir = calloc(1, sizeof(IsoDir)); dir = calloc(1, sizeof(IsoDir));
if (dir == NULL) { if (dir == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
@ -608,7 +606,7 @@ int iso_node_new_root(IsoDir **root)
dir->node.type = LIBISO_DIR; dir->node.type = LIBISO_DIR;
dir->node.atime = dir->node.ctime = dir->node.mtime = time(NULL); dir->node.atime = dir->node.ctime = dir->node.mtime = time(NULL);
dir->node.mode = S_IFDIR | 0555; dir->node.mode = S_IFDIR | 0555;
/* set parent to itself, to prevent root to be added to another dir */ /* set parent to itself, to prevent root to be added to another dir */
dir->node.parent = dir; dir->node.parent = dir;
*root = dir; *root = dir;

View File

@ -34,21 +34,21 @@ struct Iso_Node
*/ */
int refcount; int refcount;
/**< Type of the IsoNode, do not confuse with mode */ /** Type of the IsoNode, do not confuse with mode */
enum IsoNodeType type; enum IsoNodeType type;
char *name; /**< Real name, in default charset */ char *name; /**< Real name, in default charset */
mode_t mode; /**< protection */ mode_t mode; /**< protection */
uid_t uid; /**< user ID of owner */ uid_t uid; /**< user ID of owner */
gid_t gid; /**< group ID of owner */ gid_t gid; /**< group ID of owner */
/* TODO #00001 : consider adding new timestamps */ /* TODO #00001 : consider adding new timestamps */
time_t atime; /**< time of last access */ time_t atime; /**< time of last access */
time_t mtime; /**< time of last modification */ time_t mtime; /**< time of last modification */
time_t ctime; /**< time of last status change */ time_t ctime; /**< time of last status change */
int hidden; /**< whether the node will be hidden, see IsoHideNodeFlag */ int hidden; /**< whether the node will be hidden, see IsoHideNodeFlag */
IsoDir *parent; /**< parent node, NULL for root */ IsoDir *parent; /**< parent node, NULL for root */
@ -69,16 +69,16 @@ struct Iso_Dir
struct Iso_File struct Iso_File
{ {
IsoNode node; IsoNode node;
/** /**
* Location of a file extent in a ms disc, 0 for newly added file * Location of a file extent in a ms disc, 0 for newly added file
*/ */
uint32_t msblock; uint32_t msblock;
/** /**
* It sorts the order in which the file data is written to the CD image. * It sorts the order in which the file data is written to the CD image.
* Higher weighting files are written at the beginning of image * Higher weighting files are written at the beginning of image
*/ */
int sort_weight; int sort_weight;
IsoStream *stream; IsoStream *stream;
}; };
@ -86,7 +86,7 @@ struct Iso_File
struct Iso_Symlink struct Iso_Symlink
{ {
IsoNode node; IsoNode node;
char *dest; char *dest;
}; };

View File

@ -20,8 +20,8 @@ static
int susp_append(Ecma119Image *t, struct susp_info *susp, uint8_t *data) int susp_append(Ecma119Image *t, struct susp_info *susp, uint8_t *data)
{ {
susp->n_susp_fields++; susp->n_susp_fields++;
susp->susp_fields = realloc(susp->susp_fields, susp->susp_fields = realloc(susp->susp_fields, sizeof(void*)
sizeof(void*) * susp->n_susp_fields); * susp->n_susp_fields);
if (susp->susp_fields == NULL) { if (susp->susp_fields == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
@ -34,8 +34,8 @@ static
int susp_append_ce(Ecma119Image *t, struct susp_info *susp, uint8_t *data) int susp_append_ce(Ecma119Image *t, struct susp_info *susp, uint8_t *data)
{ {
susp->n_ce_susp_fields++; susp->n_ce_susp_fields++;
susp->ce_susp_fields = realloc(susp->ce_susp_fields, susp->ce_susp_fields = realloc(susp->ce_susp_fields, sizeof(void*)
sizeof(void*) * susp->n_ce_susp_fields); * susp->n_ce_susp_fields);
if (susp->ce_susp_fields == NULL) { if (susp->ce_susp_fields == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
@ -101,7 +101,7 @@ int rrip_add_PX(Ecma119Image *t, Ecma119Node *n, struct susp_info *susp)
iso_bb(&PX[20], px_get_uid(t, n), 4); iso_bb(&PX[20], px_get_uid(t, n), 4);
iso_bb(&PX[28], px_get_gid(t, n), 4); iso_bb(&PX[28], px_get_gid(t, n), 4);
iso_bb(&PX[36], n->ino, 4); iso_bb(&PX[36], n->ino, 4);
return susp_append(t, susp, PX); return susp_append(t, susp, PX);
} }
@ -142,12 +142,12 @@ static
int rrip_add_PL(Ecma119Image *t, Ecma119Node *n, struct susp_info *susp) int rrip_add_PL(Ecma119Image *t, Ecma119Node *n, struct susp_info *susp)
{ {
uint8_t *PL; uint8_t *PL;
if (n->type != ECMA119_DIR || n->info.dir.real_parent == NULL) { if (n->type != ECMA119_DIR || n->info.dir.real_parent == NULL) {
/* should never occur */ /* should never occur */
return ISO_ERROR; return ISO_ERROR;
} }
PL = malloc(12); PL = malloc(12);
if (PL == NULL) { if (PL == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
@ -157,7 +157,7 @@ int rrip_add_PL(Ecma119Image *t, Ecma119Node *n, struct susp_info *susp)
PL[1] = 'L'; PL[1] = 'L';
PL[2] = 12; PL[2] = 12;
PL[3] = 1; PL[3] = 1;
/* write the location of the real parent, already computed */ /* write the location of the real parent, already computed */
iso_bb(&PL[4], n->info.dir.real_parent->info.dir.block, 4); iso_bb(&PL[4], n->info.dir.real_parent->info.dir.block, 4);
return susp_append(t, susp, PL); return susp_append(t, susp, PL);
@ -199,13 +199,13 @@ int rrip_add_PN(Ecma119Image *t, Ecma119Node *n, struct susp_info *susp)
{ {
IsoSpecial *node; IsoSpecial *node;
uint8_t *PN; uint8_t *PN;
node = (IsoSpecial*)n->node; node = (IsoSpecial*)n->node;
if (node->node.type != LIBISO_SPECIAL) { if (node->node.type != LIBISO_SPECIAL) {
/* should never occur */ /* should never occur */
return ISO_ERROR; return ISO_ERROR;
} }
PN = malloc(20); PN = malloc(20);
if (PN == NULL) { if (PN == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
@ -252,22 +252,22 @@ char *get_rr_name(Ecma119Image *t, Ecma119Node *n)
{ {
int ret; int ret;
char *name; char *name;
if (!strcmp(t->input_charset, t->output_charset)) { if (!strcmp(t->input_charset, t->output_charset)) {
/* no conversion needed */ /* no conversion needed */
return strdup(n->node->name); return strdup(n->node->name);
} }
ret = strconv(n->node->name, t->input_charset, t->output_charset, &name); ret = strconv(n->node->name, t->input_charset, t->output_charset, &name);
if (ret < 0) { if (ret < 0) {
iso_msg_sorry(t->image, LIBISO_CHARSET_ERROR, iso_msg_sorry(t->image, LIBISO_CHARSET_ERROR,
"Charset conversion error. Can't convert %s from %s to %s", "Charset conversion error. Can't convert %s from %s to %s",
n->node->name, t->input_charset, t->output_charset); n->node->name, t->input_charset, t->output_charset);
/* use the original name, it's the best we can do */ /* use the original name, it's the best we can do */
name = strdup(n->node->name); name = strdup(n->node->name);
} }
return name; return name;
} }
@ -285,8 +285,8 @@ char *get_rr_name(Ecma119Image *t, Ecma119Node *n)
* Whether to add or not to CE * Whether to add or not to CE
*/ */
static static
int rrip_add_NM(Ecma119Image *t, struct susp_info *susp, int rrip_add_NM(Ecma119Image *t, struct susp_info *susp, char *name, int size,
char *name, int size, int flags, int ce) int flags, int ce)
{ {
uint8_t *NM = malloc(size + 5); uint8_t *NM = malloc(size + 5);
if (NM == NULL) { if (NM == NULL) {
@ -324,9 +324,8 @@ int rrip_add_NM(Ecma119Image *t, struct susp_info *susp,
* @return * @return
* 1 on success, < 0 on error * 1 on success, < 0 on error
*/ */
static static
int rrip_SL_append_comp(size_t *n, uint8_t ***comps, int rrip_SL_append_comp(size_t *n, uint8_t ***comps, char *s, int size, char fl)
char *s, int size, char fl)
{ {
uint8_t *comp = malloc(size + 2); uint8_t *comp = malloc(size + 2);
if (comp == NULL) { if (comp == NULL) {
@ -363,8 +362,8 @@ int rrip_SL_append_comp(size_t *n, uint8_t ***comps,
* Whether to add to a continuation area or system use field. * Whether to add to a continuation area or system use field.
*/ */
static static
int rrip_add_SL(Ecma119Image *t, struct susp_info *susp, int rrip_add_SL(Ecma119Image *t, struct susp_info *susp, uint8_t **comp,
uint8_t **comp, size_t n, int ce) size_t n, int ce)
{ {
int ret, i, j; int ret, i, j;
@ -374,7 +373,7 @@ int rrip_add_SL(Ecma119Image *t, struct susp_info *susp,
uint8_t *SL; uint8_t *SL;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
total_comp_len += comp[i][1] + 2; total_comp_len += comp[i][1] + 2;
if (total_comp_len > 250) { if (total_comp_len > 250) {
/* we need a new SL entry */ /* we need a new SL entry */
@ -383,18 +382,18 @@ int rrip_add_SL(Ecma119Image *t, struct susp_info *susp,
if (SL == NULL) { if (SL == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
SL[0] = 'S'; SL[0] = 'S';
SL[1] = 'L'; SL[1] = 'L';
SL[2] = total_comp_len + 5; SL[2] = total_comp_len + 5;
SL[3] = 1; SL[3] = 1;
SL[4] = 1; /* CONTINUE */ SL[4] = 1; /* CONTINUE */
pos = 5; pos = 5;
for (j = written; j < i; j++) { for (j = written; j < i; j++) {
memcpy(&SL[pos], comp[j], comp[j][1] + 2); memcpy(&SL[pos], comp[j], comp[j][1] + 2);
pos += comp[j][1] + 2; pos += comp[j][1] + 2;
} }
/* /*
* In this case we are sure we're writting to CE. Check for * In this case we are sure we're writting to CE. Check for
* debug purposes * debug purposes
@ -410,12 +409,12 @@ int rrip_add_SL(Ecma119Image *t, struct susp_info *susp,
total_comp_len = comp[i][1] + 2; total_comp_len = comp[i][1] + 2;
} }
} }
SL = malloc(total_comp_len + 5); SL = malloc(total_comp_len + 5);
if (SL == NULL) { if (SL == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
SL[0] = 'S'; SL[0] = 'S';
SL[1] = 'L'; SL[1] = 'L';
SL[2] = total_comp_len + 5; SL[2] = total_comp_len + 5;
@ -462,10 +461,10 @@ int rrip_add_ER(Ecma119Image *t, struct susp_info *susp)
ER[7] = 1; ER[7] = 1;
memcpy(&ER[8], "IEEE_1282", 9); memcpy(&ER[8], "IEEE_1282", 9);
memcpy(&ER[17], "THE IEEE 1282 PROTOCOL PROVIDES SUPPORT FOR POSIX " memcpy(&ER[17], "THE IEEE 1282 PROTOCOL PROVIDES SUPPORT FOR POSIX "
"FILE SYSTEM SEMANTICS.", 72); "FILE SYSTEM SEMANTICS.", 72);
memcpy(&ER[89], "PLEASE CONTACT THE IEEE STANDARDS DEPARTMENT, " memcpy(&ER[89], "PLEASE CONTACT THE IEEE STANDARDS DEPARTMENT, "
"PISCATAWAY, NJ, USA FOR THE 1282 SPECIFICATION.", 93); "PISCATAWAY, NJ, USA FOR THE 1282 SPECIFICATION.", 93);
/** This always goes to continuation area */ /** This always goes to continuation area */
return susp_append_ce(t, susp, ER); return susp_append_ce(t, susp, ER);
} }
@ -490,7 +489,7 @@ int susp_add_CE(Ecma119Image *t, size_t ce_len, struct susp_info *susp)
iso_bb(&CE[4], susp->ce_block, 4); iso_bb(&CE[4], susp->ce_block, 4);
iso_bb(&CE[12], susp->ce_len, 4); iso_bb(&CE[12], susp->ce_len, 4);
iso_bb(&CE[20], ce_len, 4); iso_bb(&CE[20], ce_len, 4);
return susp_append(t, susp, CE); return susp_append(t, susp, CE);
} }
@ -531,11 +530,11 @@ int susp_add_SP(Ecma119Image *t, struct susp_info *susp)
* @return * @return
* The size needed for the RR entries in the System Use Area * The size needed for the RR entries in the System Use Area
*/ */
size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, size_t space,
size_t space, size_t *ce) size_t *ce)
{ {
size_t su_size; size_t su_size;
/* space min is 255 - 33 - 37 = 185 /* space min is 255 - 33 - 37 = 185
* At the same time, it is always an odd number, but we need to pad it * At the same time, it is always an odd number, but we need to pad it
* propertly to ensure the length of a directory record is a even number * propertly to ensure the length of a directory record is a even number
@ -543,10 +542,10 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type,
*/ */
space--; space--;
*ce = 0; *ce = 0;
/* PX and TF, we are sure they always fit in SUA */ /* PX and TF, we are sure they always fit in SUA */
su_size = 44 + 26; su_size = 44 + 26;
if (n->type == ECMA119_DIR) { if (n->type == ECMA119_DIR) {
if (n->info.dir.real_parent != NULL) { if (n->info.dir.real_parent != NULL) {
/* it is a reallocated entry */ /* it is a reallocated entry */
@ -562,17 +561,17 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type,
if (S_ISBLK(n->node->mode) || S_ISCHR(n->node->mode)) { if (S_ISBLK(n->node->mode) || S_ISCHR(n->node->mode)) {
/* block or char device, we need a PN entry */ /* block or char device, we need a PN entry */
su_size += 20; su_size += 20;
} }
} else if (n->type == ECMA119_PLACEHOLDER) { } else if (n->type == ECMA119_PLACEHOLDER) {
/* we need the CL entry */ /* we need the CL entry */
su_size += 12; su_size += 12;
} }
if (type == 0) { if (type == 0) {
char *name = get_rr_name(t, n); char *name = get_rr_name(t, n);
size_t namelen = strlen(name); size_t namelen = strlen(name);
free(name); free(name);
/* NM entry */ /* NM entry */
if (su_size + 5 + namelen <= space) { if (su_size + 5 + namelen <= space) {
/* ok, it fits in System Use Area */ /* ok, it fits in System Use Area */
@ -590,7 +589,7 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type,
char *cur, *prev; char *cur, *prev;
size_t sl_len = 5; size_t sl_len = 5;
int cew = (*ce != 0); /* are we writing to CE? */ int cew = (*ce != 0); /* are we writing to CE? */
prev = ((IsoSymlink*)n->node)->dest; prev = ((IsoSymlink*)n->node)->dest;
cur = strchr(prev, '/'); cur = strchr(prev, '/');
while (1) { while (1) {
@ -601,16 +600,16 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type,
/* last component */ /* last component */
clen = strlen(prev); clen = strlen(prev);
} }
if (clen == 1 && prev[0] == '.') { if (clen == 1 && prev[0] == '.') {
clen = 0; clen = 0;
} else if (clen == 2 && prev[0] == '.' && prev[1] == '.') { } else if (clen == 2 && prev[0] == '.' && prev[1] == '.') {
clen = 0; clen = 0;
} }
/* flags and len for each component record (RRIP, 4.1.3.1) */ /* flags and len for each component record (RRIP, 4.1.3.1) */
clen += 2; clen += 2;
if (!cew) { if (!cew) {
/* we are still writing to the SUA */ /* we are still writing to the SUA */
if (su_size + sl_len + clen > space) { if (su_size + sl_len + clen > space) {
@ -631,7 +630,7 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type,
} else { } else {
sl_len += clen; sl_len += clen;
} }
} }
if (cew) { if (cew) {
if (sl_len + clen > 255) { if (sl_len + clen > 255) {
/* we need an additional SL entry */ /* we need an additional SL entry */
@ -671,7 +670,7 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type,
sl_len += clen; sl_len += clen;
} }
} }
if (!cur || cur[1] == '\0') { if (!cur || cur[1] == '\0') {
/* cur[1] can be \0 if dest ends with '/' */ /* cur[1] can be \0 if dest ends with '/' */
break; break;
@ -679,7 +678,7 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type,
prev = cur + 1; prev = cur + 1;
cur = strchr(prev, '/'); cur = strchr(prev, '/');
} }
/* and finally write the pending SL field */ /* and finally write the pending SL field */
if (!cew) { if (!cew) {
/* the whole SL fits into the SUA */ /* the whole SL fits into the SUA */
@ -687,10 +686,10 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type,
} else { } else {
*ce += sl_len; *ce += sl_len;
} }
} }
} else { } else {
/* "." or ".." entry */ /* "." or ".." entry */
su_size += 5; /* NM field */ su_size += 5; /* NM field */
if (type == 1 && n->parent == NULL) { if (type == 1 && n->parent == NULL) {
@ -703,7 +702,7 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type,
*ce = 182; /* ER */ *ce = 182; /* ER */
} }
} }
/* /*
* The System Use field inside the directory record must be padded if * The System Use field inside the directory record must be padded if
* it is an odd number (ECMA-119, 9.1.13) * it is an odd number (ECMA-119, 9.1.13)
@ -719,12 +718,12 @@ static
void susp_info_free(struct susp_info* susp) void susp_info_free(struct susp_info* susp)
{ {
size_t i; size_t i;
for (i = 0; i < susp->n_susp_fields; ++i) { for (i = 0; i < susp->n_susp_fields; ++i) {
free(susp->susp_fields[i]); free(susp->susp_fields[i]);
} }
free(susp->susp_fields); free(susp->susp_fields);
for (i = 0; i < susp->n_ce_susp_fields; ++i) { for (i = 0; i < susp->n_ce_susp_fields; ++i) {
free(susp->ce_susp_fields[i]); free(susp->ce_susp_fields[i]);
} }
@ -748,14 +747,14 @@ void susp_info_free(struct susp_info* susp)
* @return * @return
* 1 success, < 0 error * 1 success, < 0 error
*/ */
int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type, int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
size_t space, struct susp_info *info) size_t space, struct susp_info *info)
{ {
int ret; int ret;
size_t i; size_t i;
Ecma119Node *node; Ecma119Node *node;
char *name = NULL; char *name= NULL;
if (t == NULL || n == NULL || info == NULL) { if (t == NULL || n == NULL || info == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
@ -763,20 +762,20 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
/* space min is 255 - 33 - 37 = 185 */ /* space min is 255 - 33 - 37 = 185 */
return ISO_WRONG_ARG_VALUE; return ISO_WRONG_ARG_VALUE;
} }
if (type == 2 && n->parent != NULL) { if (type == 2 && n->parent != NULL) {
node = n->parent; node = n->parent;
} else { } else {
node = n; node = n;
} }
/* space min is 255 - 33 - 37 = 185 /* space min is 255 - 33 - 37 = 185
* At the same time, it is always an odd number, but we need to pad it * At the same time, it is always an odd number, but we need to pad it
* propertly to ensure the length of a directory record is a even number * propertly to ensure the length of a directory record is a even number
* (ECMA-119, 9.1.13). Thus, in fact the real space is always space - 1 * (ECMA-119, 9.1.13). Thus, in fact the real space is always space - 1
*/ */
space--; space--;
/* /*
* SP must be the first entry for the "." record of the root directory * SP must be the first entry for the "." record of the root directory
* (SUSP, 5.3) * (SUSP, 5.3)
@ -787,7 +786,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
goto add_susp_cleanup; goto add_susp_cleanup;
} }
} }
/* PX and TF, we are sure they always fit in SUA */ /* PX and TF, we are sure they always fit in SUA */
ret = rrip_add_PX(t, node, info); ret = rrip_add_PX(t, node, info);
if (ret < 0) { if (ret < 0) {
@ -797,7 +796,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
if (ret < 0) { if (ret < 0) {
goto add_susp_cleanup; goto add_susp_cleanup;
} }
if (n->type == ECMA119_DIR) { if (n->type == ECMA119_DIR) {
if (n->info.dir.real_parent != NULL) { if (n->info.dir.real_parent != NULL) {
/* it is a reallocated entry */ /* it is a reallocated entry */
@ -825,7 +824,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
if (ret < 0) { if (ret < 0) {
goto add_susp_cleanup; goto add_susp_cleanup;
} }
} }
} else if (n->type == ECMA119_PLACEHOLDER) { } else if (n->type == ECMA119_PLACEHOLDER) {
/* we need the CL entry */ /* we need the CL entry */
ret = rrip_add_CL(t, node, info); ret = rrip_add_CL(t, node, info);
@ -833,22 +832,22 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
goto add_susp_cleanup; goto add_susp_cleanup;
} }
} }
if (type == 0) { if (type == 0) {
size_t sua_free; /* free space in the SUA */ size_t sua_free; /* free space in the SUA */
int nm_type = 0; /* 0 whole entry in SUA, 1 part in CE */ int nm_type = 0; /* 0 whole entry in SUA, 1 part in CE */
size_t ce_len = 0; /* len of the CE */ size_t ce_len = 0; /* len of the CE */
size_t namelen; size_t namelen;
/* this two are only defined for symlinks */ /* this two are only defined for symlinks */
uint8_t **comps = NULL; /* components of the SL field */ uint8_t **comps= NULL; /* components of the SL field */
size_t n_comp = 0; /* number of components */ size_t n_comp = 0; /* number of components */
name = get_rr_name(t, n); name = get_rr_name(t, n);
namelen = strlen(name); namelen = strlen(name);
sua_free = space - info->suf_len; sua_free = space - info->suf_len;
/* NM entry */ /* NM entry */
if (5 + namelen <= sua_free) { if (5 + namelen <= sua_free) {
/* ok, it fits in System Use Area */ /* ok, it fits in System Use Area */
@ -868,7 +867,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
char *cur, *prev; char *cur, *prev;
size_t sl_len = 5; size_t sl_len = 5;
int cew = (nm_type == 1); /* are we writing to CE? */ int cew = (nm_type == 1); /* are we writing to CE? */
prev = ((IsoSymlink*)n->node)->dest; prev = ((IsoSymlink*)n->node)->dest;
cur = strchr(prev, '/'); cur = strchr(prev, '/');
while (1) { while (1) {
@ -880,21 +879,22 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
/* last component */ /* last component */
clen = strlen(prev); clen = strlen(prev);
} }
if (clen == 0) { if (clen == 0) {
/* this refers to the roor directory, '/' */ /* this refers to the roor directory, '/' */
cflag = 1 << 3; cflag = 1 << 3;
} if (clen == 1 && prev[0] == '.') { }
if (clen == 1 && prev[0] == '.') {
clen = 0; clen = 0;
cflag = 1 << 1; cflag = 1 << 1;
} else if (clen == 2 && prev[0] == '.' && prev[1] == '.') { } else if (clen == 2 && prev[0] == '.' && prev[1] == '.') {
clen = 0; clen = 0;
cflag = 1 << 2; cflag = 1 << 2;
} }
/* flags and len for each component record (RRIP, 4.1.3.1) */ /* flags and len for each component record (RRIP, 4.1.3.1) */
clen += 2; clen += 2;
if (!cew) { if (!cew) {
/* we are still writing to the SUA */ /* we are still writing to the SUA */
if (sl_len + clen > sua_free) { if (sl_len + clen > sua_free) {
@ -923,7 +923,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
} }
sl_len += clen; sl_len += clen;
} }
} }
if (cew) { if (cew) {
if (sl_len + clen > 255) { if (sl_len + clen > 255) {
/* we need an addition SL entry */ /* we need an addition SL entry */
@ -943,7 +943,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
* the component can be divided between this * the component can be divided between this
* and another SL entry * and another SL entry
*/ */
ret = rrip_SL_append_comp(&n_comp, &comps, ret = rrip_SL_append_comp(&n_comp, &comps,
prev, fit, 0x01); prev, fit, 0x01);
if (ret < 0) { if (ret < 0) {
goto add_susp_cleanup; goto add_susp_cleanup;
@ -952,10 +952,8 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
* and another component, that will go in * and another component, that will go in
* other SL entry * other SL entry
*/ */
ret = rrip_SL_append_comp(&n_comp, &comps, ret = rrip_SL_append_comp(&n_comp, &comps, prev
prev + fit, + fit, clen - fit - 2, 0);
clen - fit - 2,
0);
if (ret < 0) { if (ret < 0) {
goto add_susp_cleanup; goto add_susp_cleanup;
} }
@ -967,15 +965,13 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
* any case, so we prefer to don't write * any case, so we prefer to don't write
* anything in this SL * anything in this SL
*/ */
ret = rrip_SL_append_comp(&n_comp, &comps, ret = rrip_SL_append_comp(&n_comp, &comps,
prev, 248, 0x01); prev, 248, 0x01);
if (ret < 0) { if (ret < 0) {
goto add_susp_cleanup; goto add_susp_cleanup;
} }
ret = rrip_SL_append_comp(&n_comp, &comps, ret = rrip_SL_append_comp(&n_comp, &comps, prev
prev + 248, + 248, strlen(prev + 248), 0x00);
strlen(prev + 248),
0x00);
if (ret < 0) { if (ret < 0) {
goto add_susp_cleanup; goto add_susp_cleanup;
} }
@ -984,7 +980,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
} }
} else { } else {
/* case 2, create a new SL entry */ /* case 2, create a new SL entry */
ret = rrip_SL_append_comp(&n_comp, &comps, prev, ret = rrip_SL_append_comp(&n_comp, &comps, prev,
clen - 2, cflag); clen - 2, cflag);
if (ret < 0) { if (ret < 0) {
goto add_susp_cleanup; goto add_susp_cleanup;
@ -1002,7 +998,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
sl_len += clen; sl_len += clen;
} }
} }
if (!cur || cur[1] == '\0') { if (!cur || cur[1] == '\0') {
/* cur[1] can be \0 if dest ends with '/' */ /* cur[1] can be \0 if dest ends with '/' */
break; break;
@ -1010,19 +1006,19 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
prev = cur + 1; prev = cur + 1;
cur = strchr(prev, '/'); cur = strchr(prev, '/');
} }
if (cew) { if (cew) {
ce_len += sl_len; ce_len += sl_len;
} }
} }
/* /*
* We we reach here: * We we reach here:
* - We know if NM fill in the SUA (nm_type == 0) * - We know if NM fill in the SUA (nm_type == 0)
* - If SL needs an to be written in CE (ce_len > 0) * - If SL needs an to be written in CE (ce_len > 0)
* - The components for SL entry (or entries) * - The components for SL entry (or entries)
*/ */
if (nm_type == 0) { if (nm_type == 0) {
/* the full NM fills in SUA */ /* the full NM fills in SUA */
ret = rrip_add_NM(t, info, name, strlen(name), 0, 0); ret = rrip_add_NM(t, info, name, strlen(name), 0, 0);
@ -1040,7 +1036,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
goto add_susp_cleanup; goto add_susp_cleanup;
} }
} }
if (ce_len > 0) { if (ce_len > 0) {
/* Add the CE entry */ /* Add the CE entry */
ret = susp_add_CE(t, ce_len, info); ret = susp_add_CE(t, ce_len, info);
@ -1061,26 +1057,25 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
} }
if (n->type == ECMA119_SYMLINK) { if (n->type == ECMA119_SYMLINK) {
/* add the SL entry (or entries) */ /* add the SL entry (or entries) */
ret = rrip_add_SL(t, info, comps, n_comp, (ce_len > 0)); ret = rrip_add_SL(t, info, comps, n_comp, (ce_len > 0));
/* free the components */ /* free the components */
for (i = 0; i < n_comp; i++) { for (i = 0; i < n_comp; i++) {
free(comps[i]); free(comps[i]);
} }
free(comps); free(comps);
if (ret < 0) { if (ret < 0) {
goto add_susp_cleanup; goto add_susp_cleanup;
} }
} }
} else { } else {
/* "." or ".." entry */ /* "." or ".." entry */
/* write the NM entry */ /* write the NM entry */
ret = rrip_add_NM(t, info, NULL, 0, 1 << type, 0); ret = rrip_add_NM(t, info, NULL, 0, 1 << type, 0);
if (ret < 0) { if (ret < 0) {
@ -1103,17 +1098,17 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
} }
} }
} }
/* /*
* The System Use field inside the directory record must be padded if * The System Use field inside the directory record must be padded if
* it is an odd number (ECMA-119, 9.1.13) * it is an odd number (ECMA-119, 9.1.13)
*/ */
info->suf_len += (info->suf_len % 2); info->suf_len += (info->suf_len % 2);
free(name); free(name);
return ISO_SUCCESS; return ISO_SUCCESS;
add_susp_cleanup:; add_susp_cleanup: ;
free(name); free(name);
susp_info_free(info); susp_info_free(info);
return ret; return ret;
@ -1126,12 +1121,12 @@ add_susp_cleanup:;
* After written, the info susp_fields array will be freed, and the counters * After written, the info susp_fields array will be freed, and the counters
* updated propertly. * updated propertly.
*/ */
void rrip_write_susp_fields(Ecma119Image *t, struct susp_info *info, void rrip_write_susp_fields(Ecma119Image *t, struct susp_info *info,
uint8_t *buf) uint8_t *buf)
{ {
size_t i; size_t i;
size_t pos = 0; size_t pos = 0;
if (info->n_susp_fields == 0) { if (info->n_susp_fields == 0) {
return; return;
} }
@ -1140,7 +1135,7 @@ void rrip_write_susp_fields(Ecma119Image *t, struct susp_info *info,
memcpy(buf + pos, info->susp_fields[i], info->susp_fields[i][2]); memcpy(buf + pos, info->susp_fields[i], info->susp_fields[i][2]);
pos += info->susp_fields[i][2]; pos += info->susp_fields[i][2];
} }
/* free susp_fields */ /* free susp_fields */
for (i = 0; i < info->n_susp_fields; ++i) { for (i = 0; i < info->n_susp_fields; ++i) {
free(info->susp_fields[i]); free(info->susp_fields[i]);
@ -1160,8 +1155,8 @@ int rrip_write_ce_fields(Ecma119Image *t, struct susp_info *info)
{ {
size_t i; size_t i;
uint8_t padding[BLOCK_SIZE]; uint8_t padding[BLOCK_SIZE];
int ret = ISO_SUCCESS; int ret= ISO_SUCCESS;
if (info->n_ce_susp_fields == 0) { if (info->n_ce_susp_fields == 0) {
return ret; return ret;
} }
@ -1173,15 +1168,15 @@ int rrip_write_ce_fields(Ecma119Image *t, struct susp_info *info)
goto write_ce_field_cleanup; goto write_ce_field_cleanup;
} }
} }
/* pad continuation area until block size */ /* pad continuation area until block size */
i = BLOCK_SIZE - (info->ce_len % BLOCK_SIZE); i = BLOCK_SIZE - (info->ce_len % BLOCK_SIZE);
if (i > 0 && i < BLOCK_SIZE) { if (i > 0 && i < BLOCK_SIZE) {
memset(padding, 0, i); memset(padding, 0, i);
ret = iso_write(t, padding, i); ret = iso_write(t, padding, i);
} }
write_ce_field_cleanup:; write_ce_field_cleanup: ;
/* free ce_susp_fields */ /* free ce_susp_fields */
for (i = 0; i < info->n_ce_susp_fields; ++i) { for (i = 0; i < info->n_ce_susp_fields; ++i) {
free(info->ce_susp_fields[i]); free(info->ce_susp_fields[i]);

View File

@ -28,7 +28,6 @@
#include "ecma119.h" #include "ecma119.h"
/** /**
* This contains the information about the System Use Fields (SUSP, 4.1), * This contains the information about the System Use Fields (SUSP, 4.1),
* that will be written in the System Use Areas, both in the ISO directory * that will be written in the System Use Areas, both in the ISO directory
@ -66,8 +65,8 @@ struct susp_info
* @return * @return
* The size needed for the RR entries in the System Use Area * The size needed for the RR entries in the System Use Area
*/ */
size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, size_t space,
size_t space, size_t *ce); size_t *ce);
/** /**
* Fill a struct susp_info with the RR/SUSP entries needed for a given * Fill a struct susp_info with the RR/SUSP entries needed for a given
@ -86,7 +85,7 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type,
* @return * @return
* 1 success, < 0 error * 1 success, < 0 error
*/ */
int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type, int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
size_t space, struct susp_info *info); size_t space, struct susp_info *info);
/** /**
@ -96,7 +95,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
* After written, the info susp_fields array will be freed, and the counters * After written, the info susp_fields array will be freed, and the counters
* updated propertly. * updated propertly.
*/ */
void rrip_write_susp_fields(Ecma119Image *t, struct susp_info *info, void rrip_write_susp_fields(Ecma119Image *t, struct susp_info *info,
uint8_t *buf); uint8_t *buf);
/** /**

View File

@ -50,11 +50,11 @@ off_t fsrc_get_size(IsoStream *stream)
{ {
FSrcStreamData *data; FSrcStreamData *data;
data = (FSrcStreamData*)stream->data; data = (FSrcStreamData*)stream->data;
return data->size; return data->size;
} }
static static
int fsrc_read(IsoStream *stream, void *buf, size_t count) int fsrc_read(IsoStream *stream, void *buf, size_t count)
{ {
IsoFileSource *src; IsoFileSource *src;
@ -65,7 +65,7 @@ int fsrc_read(IsoStream *stream, void *buf, size_t count)
return iso_file_source_read(src, buf, count); return iso_file_source_read(src, buf, count);
} }
static static
int fsrc_is_repeatable(IsoStream *stream) int fsrc_is_repeatable(IsoStream *stream)
{ {
int ret; int ret;
@ -75,11 +75,11 @@ int fsrc_is_repeatable(IsoStream *stream)
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
data = (FSrcStreamData*)stream->data; data = (FSrcStreamData*)stream->data;
/* mode is not cached, this function is only useful for filters */ /* mode is not cached, this function is only useful for filters */
ret = iso_file_source_stat(data->src, &info); ret = iso_file_source_stat(data->src, &info);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
if (S_ISREG(info.st_mode) || S_ISBLK(info.st_mode)) { if (S_ISREG(info.st_mode) || S_ISBLK(info.st_mode)) {
return 1; return 1;
@ -89,24 +89,24 @@ int fsrc_is_repeatable(IsoStream *stream)
} }
static static
int fsrc_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id, int fsrc_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
ino_t *ino_id) ino_t *ino_id)
{ {
FSrcStreamData *data; FSrcStreamData *data;
IsoFilesystem *fs; IsoFilesystem *fs;
if (stream == NULL || fs_id == NULL || dev_id == NULL || ino_id == NULL) { if (stream == NULL || fs_id == NULL || dev_id == NULL || ino_id == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
data = (FSrcStreamData*)stream->data; data = (FSrcStreamData*)stream->data;
fs = iso_file_source_get_filesystem(data->src); fs = iso_file_source_get_filesystem(data->src);
*fs_id = fs->get_id(fs); *fs_id = fs->get_id(fs);
if (fs_id == 0) { if (fs_id == 0) {
return 0; return 0;
} }
*dev_id = data->dev_id; *dev_id = data->dev_id;
*ino_id = data->ino_id; *ino_id = data->ino_id;
return ISO_SUCCESS; return ISO_SUCCESS;
@ -141,7 +141,7 @@ int iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream)
if (src == NULL || stream == NULL) { if (src == NULL || stream == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
r = iso_file_source_stat(src, &info); r = iso_file_source_stat(src, &info);
if (r < 0) { if (r < 0) {
return r; return r;
@ -149,7 +149,7 @@ int iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream)
if (S_ISDIR(info.st_mode)) { if (S_ISDIR(info.st_mode)) {
return ISO_FILE_IS_DIR; return ISO_FILE_IS_DIR;
} }
str = malloc(sizeof(IsoStream)); str = malloc(sizeof(IsoStream));
if (str == NULL) { if (str == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
@ -165,11 +165,11 @@ int iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream)
data->dev_id = info.st_dev; data->dev_id = info.st_dev;
data->ino_id = info.st_ino; data->ino_id = info.st_ino;
data->size = info.st_size; data->size = info.st_size;
str->refcount = 1; str->refcount = 1;
str->data = data; str->data = data;
str->class = &fsrc_stream_class; str->class = &fsrc_stream_class;
*stream = str; *stream = str;
return ISO_SUCCESS; return ISO_SUCCESS;
} }

View File

@ -55,7 +55,7 @@ typedef struct IsoStream_Iface
* number of bytes read, 0 if EOF, < 0 on error * number of bytes read, 0 if EOF, < 0 on error
*/ */
int (*read)(IsoStream *stream, void *buf, size_t count); int (*read)(IsoStream *stream, void *buf, size_t count);
/** /**
* Whether this Stram can be read several times, with the same results. * Whether this Stram can be read several times, with the same results.
* For example, a regular file is repeatable, you can read it as many * For example, a regular file is repeatable, you can read it as many
@ -68,7 +68,7 @@ typedef struct IsoStream_Iface
* 1 if stream is repeatable, 0 if not, < 0 on error * 1 if stream is repeatable, 0 if not, < 0 on error
*/ */
int (*is_repeatable)(IsoStream *stream); int (*is_repeatable)(IsoStream *stream);
/** /**
* Get an unique identifier for the IsoStream. If your implementation * Get an unique identifier for the IsoStream. If your implementation
* is unable to return a valid identifier, this function should return * is unable to return a valid identifier, this function should return
@ -77,7 +77,7 @@ typedef struct IsoStream_Iface
* @return * @return
* 1 on success, 0 if idenfier is not valid, < 0 error * 1 on success, 0 if idenfier is not valid, < 0 error
*/ */
int (*get_id)(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id, int (*get_id)(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
ino_t *ino_id); ino_t *ino_id);
/** /**
@ -91,43 +91,49 @@ struct Iso_Stream
{ {
IsoStreamIface *class; IsoStreamIface *class;
int refcount; int refcount;
void *data; void *data;
}; };
void iso_stream_ref(IsoStream *stream); void iso_stream_ref(IsoStream *stream);
void iso_stream_unref(IsoStream *stream); void iso_stream_unref(IsoStream *stream);
extern inline extern inline
int iso_stream_open(IsoStream *stream) { int iso_stream_open(IsoStream *stream)
{
return stream->class->open(stream); return stream->class->open(stream);
} }
extern inline extern inline
int iso_stream_close(IsoStream *stream) { int iso_stream_close(IsoStream *stream)
{
return stream->class->close(stream); return stream->class->close(stream);
} }
extern inline extern inline
off_t iso_stream_get_size(IsoStream *stream) { off_t iso_stream_get_size(IsoStream *stream)
{
return stream->class->get_size(stream); return stream->class->get_size(stream);
} }
extern inline extern inline
int iso_stream_read(IsoStream *stream, void *buf, size_t count) { int iso_stream_read(IsoStream *stream, void *buf, size_t count)
{
return stream->class->read(stream, buf, count); return stream->class->read(stream, buf, count);
} }
extern inline extern inline
int iso_stream_is_repeatable(IsoStream *stream) { int iso_stream_is_repeatable(IsoStream *stream)
{
return stream->class->is_repeatable(stream); return stream->class->is_repeatable(stream);
} }
extern inline extern inline
int iso_stream_get_id(IsoStream *stream, unsigned int *fs_id, int iso_stream_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id,
dev_t *dev_id, ino_t *ino_id) { ino_t *ino_id)
{
return stream->class->get_id(stream, fs_id, dev_id, ino_id); return stream->class->get_id(stream, fs_id, dev_id, ino_id);
} }
/** /**
* Create a stream to read from a IsoFileSource. * Create a stream to read from a IsoFileSource.
* The stream will take the ref. to the IsoFileSource, so after a successfully * The stream will take the ref. to the IsoFileSource, so after a successfully

View File

@ -48,14 +48,14 @@ int iso_tree_add_new_dir(IsoDir *parent, const char *name, IsoDir **dir)
IsoDir *node; IsoDir *node;
IsoNode **pos; IsoNode **pos;
time_t now; time_t now;
if (parent == NULL || name == NULL) { if (parent == NULL || name == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
if (dir) { if (dir) {
*dir = NULL; *dir = NULL;
} }
/* find place where to insert */ /* find place where to insert */
pos = &(parent->children); pos = &(parent->children);
while (*pos != NULL && strcmp((*pos)->name, name) < 0) { while (*pos != NULL && strcmp((*pos)->name, name) < 0) {
@ -65,12 +65,12 @@ int iso_tree_add_new_dir(IsoDir *parent, const char *name, IsoDir **dir)
/* a node with same name already exists */ /* a node with same name already exists */
return ISO_NODE_NAME_NOT_UNIQUE; return ISO_NODE_NAME_NOT_UNIQUE;
} }
node = calloc(1, sizeof(IsoDir)); node = calloc(1, sizeof(IsoDir));
if (node == NULL) { if (node == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
node->node.refcount = 1; node->node.refcount = 1;
node->node.type = LIBISO_DIR; node->node.type = LIBISO_DIR;
node->node.name = strdup(name); node->node.name = strdup(name);
@ -78,24 +78,24 @@ int iso_tree_add_new_dir(IsoDir *parent, const char *name, IsoDir **dir)
free(node); free(node);
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
/* permissions from parent */ /* permissions from parent */
node->node.mode = parent->node.mode; node->node.mode = parent->node.mode;
node->node.uid = parent->node.uid; node->node.uid = parent->node.uid;
node->node.gid = parent->node.gid; node->node.gid = parent->node.gid;
node->node.hidden = parent->node.hidden; node->node.hidden = parent->node.hidden;
/* current time */ /* current time */
now = time(NULL); now = time(NULL);
node->node.atime = now; node->node.atime = now;
node->node.ctime = now; node->node.ctime = now;
node->node.mtime = now; node->node.mtime = now;
/* add to dir */ /* add to dir */
node->node.parent = parent; node->node.parent = parent;
node->node.next = *pos; node->node.next = *pos;
*pos = (IsoNode*)node; *pos = (IsoNode*)node;
if (dir) { if (dir) {
*dir = node; *dir = node;
} }
@ -126,20 +126,20 @@ int iso_tree_add_new_dir(IsoDir *parent, const char *name, IsoDir **dir)
* 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_MEM_ERROR * ISO_MEM_ERROR
*/ */
int iso_tree_add_new_symlink(IsoDir *parent, const char *name, int iso_tree_add_new_symlink(IsoDir *parent, const char *name,
const char *dest, IsoSymlink **link) const char *dest, IsoSymlink **link)
{ {
IsoSymlink *node; IsoSymlink *node;
IsoNode **pos; IsoNode **pos;
time_t now; time_t now;
if (parent == NULL || name == NULL || dest == NULL) { if (parent == NULL || name == NULL || dest == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
if (link) { if (link) {
*link = NULL; *link = NULL;
} }
/* find place where to insert */ /* find place where to insert */
pos = &(parent->children); pos = &(parent->children);
while (*pos != NULL && strcmp((*pos)->name, name) < 0) { while (*pos != NULL && strcmp((*pos)->name, name) < 0) {
@ -149,12 +149,12 @@ int iso_tree_add_new_symlink(IsoDir *parent, const char *name,
/* a node with same name already exists */ /* a node with same name already exists */
return ISO_NODE_NAME_NOT_UNIQUE; return ISO_NODE_NAME_NOT_UNIQUE;
} }
node = calloc(1, sizeof(IsoSymlink)); node = calloc(1, sizeof(IsoSymlink));
if (node == NULL) { if (node == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
node->node.refcount = 1; node->node.refcount = 1;
node->node.type = LIBISO_SYMLINK; node->node.type = LIBISO_SYMLINK;
node->node.name = strdup(name); node->node.name = strdup(name);
@ -162,31 +162,31 @@ int iso_tree_add_new_symlink(IsoDir *parent, const char *name,
free(node); free(node);
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
node->dest = strdup(dest); node->dest = strdup(dest);
if (node->dest == NULL) { if (node->dest == NULL) {
free(node->node.name); free(node->node.name);
free(node); free(node);
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
/* permissions from parent */ /* permissions from parent */
node->node.mode = S_IFLNK | 0777; node->node.mode = S_IFLNK | 0777;
node->node.uid = parent->node.uid; node->node.uid = parent->node.uid;
node->node.gid = parent->node.gid; node->node.gid = parent->node.gid;
node->node.hidden = parent->node.hidden; node->node.hidden = parent->node.hidden;
/* current time */ /* current time */
now = time(NULL); now = time(NULL);
node->node.atime = now; node->node.atime = now;
node->node.ctime = now; node->node.ctime = now;
node->node.mtime = now; node->node.mtime = now;
/* add to dir */ /* add to dir */
node->node.parent = parent; node->node.parent = parent;
node->node.next = *pos; node->node.next = *pos;
*pos = (IsoNode*)node; *pos = (IsoNode*)node;
if (link) { if (link) {
*link = node; *link = node;
} }
@ -231,13 +231,13 @@ int iso_tree_add_new_symlink(IsoDir *parent, const char *name,
* ISO_MEM_ERROR * ISO_MEM_ERROR
* *
*/ */
int iso_tree_add_new_special(IsoDir *parent, const char *name, mode_t mode, int iso_tree_add_new_special(IsoDir *parent, const char *name, mode_t mode,
dev_t dev, IsoSpecial **special) dev_t dev, IsoSpecial **special)
{ {
IsoSpecial *node; IsoSpecial *node;
IsoNode **pos; IsoNode **pos;
time_t now; time_t now;
if (parent == NULL || name == NULL) { if (parent == NULL || name == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
@ -247,7 +247,7 @@ int iso_tree_add_new_special(IsoDir *parent, const char *name, mode_t mode,
if (special) { if (special) {
*special = NULL; *special = NULL;
} }
/* find place where to insert */ /* find place where to insert */
pos = &(parent->children); pos = &(parent->children);
while (*pos != NULL && strcmp((*pos)->name, name) < 0) { while (*pos != NULL && strcmp((*pos)->name, name) < 0) {
@ -257,12 +257,12 @@ int iso_tree_add_new_special(IsoDir *parent, const char *name, mode_t mode,
/* a node with same name already exists */ /* a node with same name already exists */
return ISO_NODE_NAME_NOT_UNIQUE; return ISO_NODE_NAME_NOT_UNIQUE;
} }
node = calloc(1, sizeof(IsoSpecial)); node = calloc(1, sizeof(IsoSpecial));
if (node == NULL) { if (node == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
node->node.refcount = 1; node->node.refcount = 1;
node->node.type = LIBISO_SPECIAL; node->node.type = LIBISO_SPECIAL;
node->node.name = strdup(name); node->node.name = strdup(name);
@ -270,51 +270,51 @@ int iso_tree_add_new_special(IsoDir *parent, const char *name, mode_t mode,
free(node); free(node);
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
node->node.mode = mode; node->node.mode = mode;
node->dev = dev; node->dev = dev;
/* atts from parent */ /* atts from parent */
node->node.uid = parent->node.uid; node->node.uid = parent->node.uid;
node->node.gid = parent->node.gid; node->node.gid = parent->node.gid;
node->node.hidden = parent->node.hidden; node->node.hidden = parent->node.hidden;
/* current time */ /* current time */
now = time(NULL); now = time(NULL);
node->node.atime = now; node->node.atime = now;
node->node.ctime = now; node->node.ctime = now;
node->node.mtime = now; node->node.mtime = now;
/* add to dir */ /* add to dir */
node->node.parent = parent; node->node.parent = parent;
node->node.next = *pos; node->node.next = *pos;
*pos = (IsoNode*)node; *pos = (IsoNode*)node;
if (special) { if (special) {
*special = node; *special = node;
} }
return ++parent->nchildren; return ++parent->nchildren;
} }
static static
int iso_tree_add_node_builder(IsoImage *image, IsoDir *parent, int iso_tree_add_node_builder(IsoImage *image, IsoDir *parent,
IsoFileSource *src, IsoNodeBuilder *builder, IsoFileSource *src, IsoNodeBuilder *builder,
IsoNode **node) IsoNode **node)
{ {
int result; int result;
IsoNode *new; IsoNode *new;
IsoNode **pos; IsoNode **pos;
char *name; char *name;
if (parent == NULL || src == NULL || builder == NULL) { if (parent == NULL || src == NULL || builder == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
if (node) { if (node) {
*node = NULL; *node = NULL;
} }
name = iso_file_source_get_name(src); name = iso_file_source_get_name(src);
/* find place where to insert */ /* find place where to insert */
pos = &(parent->children); pos = &(parent->children);
while (*pos != NULL && strcmp((*pos)->name, name) < 0) { while (*pos != NULL && strcmp((*pos)->name, name) < 0) {
@ -324,43 +324,43 @@ int iso_tree_add_node_builder(IsoImage *image, IsoDir *parent,
/* a node with same name already exists */ /* a node with same name already exists */
return ISO_NODE_NAME_NOT_UNIQUE; return ISO_NODE_NAME_NOT_UNIQUE;
} }
result = builder->create_node(builder, image, src, &new); result = builder->create_node(builder, image, src, &new);
if (result < 0) { if (result < 0) {
return result; return result;
} }
/* finally, add node to parent */ /* finally, add node to parent */
new->parent = parent; new->parent = parent;
new->next = *pos; new->next = *pos;
*pos = new; *pos = new;
if (node) { if (node) {
*node = new; *node = new;
} }
return ++parent->nchildren; return ++parent->nchildren;
} }
int iso_tree_add_node(IsoImage *image, IsoDir *parent, const char *path, int iso_tree_add_node(IsoImage *image, IsoDir *parent, const char *path,
IsoNode **node) IsoNode **node)
{ {
int result; int result;
IsoFilesystem *fs; IsoFilesystem *fs;
IsoFileSource *file; IsoFileSource *file;
if (image == NULL || parent == NULL || path == NULL) { if (image == NULL || parent == NULL || path == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
fs = image->fs; fs = image->fs;
result = fs->get_by_path(fs, path, &file); result = fs->get_by_path(fs, path, &file);
if (result < 0) { if (result < 0) {
return result; return result;
} }
result = iso_tree_add_node_builder(image, parent, file, image->builder, result = iso_tree_add_node_builder(image, parent, file, image->builder,
node); node);
/* free the file */ /* free the file */
iso_file_source_unref(file); iso_file_source_unref(file);
return result; return result;
} }
@ -381,7 +381,7 @@ int check_excludes(IsoImage *image, const char *path)
return 0; return 0;
} }
static static
int check_hidden(IsoImage *image, const char *name) int check_hidden(IsoImage *image, const char *name)
{ {
return (image->recOpts->ignore_hidden && name[0] == '.'); return (image->recOpts->ignore_hidden && name[0] == '.');
@ -399,25 +399,25 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir)
IsoNodeBuilder *builder; IsoNodeBuilder *builder;
IsoFileSource *file; IsoFileSource *file;
IsoNode **pos; IsoNode **pos;
result = iso_file_source_open(dir); result = iso_file_source_open(dir);
if (result < 0) { if (result < 0) {
iso_msg_debug(image, "Can't open dir %s", iso_msg_debug(image, "Can't open dir %s",
iso_file_source_get_path(dir)); iso_file_source_get_path(dir));
return result; return result;
} }
builder = image->builder; builder = image->builder;
action = 1; action = 1;
while ( (result = iso_file_source_readdir(dir, &file)) == 1) { while ( (result = iso_file_source_readdir(dir, &file)) == 1) {
int flag; int flag;
char *name; char *name;
IsoNode *new; IsoNode *new;
iso_msg_debug(image, "Adding file %s", iso_file_source_get_path(file)); iso_msg_debug(image, "Adding file %s", iso_file_source_get_path(file));
name = iso_file_source_get_name(file); name = iso_file_source_get_name(file);
if (check_excludes(image, iso_file_source_get_path(file))) { if (check_excludes(image, iso_file_source_get_path(file))) {
action = 2; action = 2;
} else if (check_hidden(image, name)) { } else if (check_hidden(image, name)) {
@ -425,7 +425,7 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir)
} else { } else {
action = 1; action = 1;
} }
/* find place where to insert */ /* find place where to insert */
flag = 0; flag = 0;
pos = &(parent->children); pos = &(parent->children);
@ -438,12 +438,12 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir)
action = 2; action = 2;
} }
} }
/* ask user if callback has been set */ /* ask user if callback has been set */
if (image->recOpts->report) { if (image->recOpts->report) {
action = image->recOpts->report(file, action, flag); action = image->recOpts->report(file, action, flag);
} }
if (action == 2) { if (action == 2) {
/* skip file */ /* skip file */
iso_file_source_unref(file); iso_file_source_unref(file);
@ -453,23 +453,23 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir)
iso_file_source_unref(file); iso_file_source_unref(file);
break; break;
} }
/* ok, file will be added */ /* ok, file will be added */
result = builder->create_node(builder, image, file, &new); result = builder->create_node(builder, image, file, &new);
if (result < 0) { if (result < 0) {
iso_msg_debug(image, "Error %d when adding file %s", iso_msg_debug(image, "Error %d when adding file %s", result,
result, iso_file_source_get_path(file)); iso_file_source_get_path(file));
if (image->recOpts->report) { if (image->recOpts->report) {
action = image->recOpts->report(file, result, flag); action = image->recOpts->report(file, result, flag);
} else { } else {
action = image->recOpts->stop_on_error ? 3 : 1; action = image->recOpts->stop_on_error ? 3 : 1;
} }
/* free file */ /* free file */
iso_file_source_unref(file); iso_file_source_unref(file);
if (action == 3) { if (action == 3) {
result = 1; /* prevent error to be passing up */ result = 1; /* prevent error to be passing up */
break; break;
@ -478,7 +478,7 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir)
continue; continue;
} }
} }
/* ok, node has correctly created, we need to add it */ /* ok, node has correctly created, we need to add it */
if (flag) { if (flag) {
/* replace node */ /* replace node */
@ -495,7 +495,7 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir)
new->parent = parent; new->parent = parent;
++parent->nchildren; ++parent->nchildren;
} }
/* finally, if the node is a directory we need to recurse */ /* finally, if the node is a directory we need to recurse */
if (new->type == LIBISO_DIR) { if (new->type == LIBISO_DIR) {
result = iso_add_dir_aux(image, (IsoDir*)new, file); result = iso_add_dir_aux(image, (IsoDir*)new, file);
@ -516,12 +516,12 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir)
iso_file_source_unref(file); iso_file_source_unref(file);
} }
} }
if (result < 0) { if (result < 0) {
// TODO printf message // TODO printf message
action = result; action = result;
} }
result = iso_file_source_close(dir); result = iso_file_source_close(dir);
if (result < 0) { if (result < 0) {
return result; return result;
@ -541,24 +541,24 @@ int iso_tree_add_dir_rec(IsoImage *image, IsoDir *parent, const char *dir)
struct stat info; struct stat info;
IsoFilesystem *fs; IsoFilesystem *fs;
IsoFileSource *file; IsoFileSource *file;
if (image == NULL || parent == NULL || dir == NULL) { if (image == NULL || parent == NULL || dir == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
fs = image->fs; fs = image->fs;
result = fs->get_by_path(fs, dir, &file); result = fs->get_by_path(fs, dir, &file);
if (result < 0) { if (result < 0) {
return result; return result;
} }
/* we also allow dir path to be a symlink to a dir */ /* we also allow dir path to be a symlink to a dir */
result = iso_file_source_stat(file, &info); result = iso_file_source_stat(file, &info);
if (result < 0) { if (result < 0) {
iso_file_source_unref(file); iso_file_source_unref(file);
return result; return result;
} }
if (!S_ISDIR(info.st_mode)) { if (!S_ISDIR(info.st_mode)) {
iso_file_source_unref(file); iso_file_source_unref(file);
return ISO_FILE_IS_NOT_DIR; return ISO_FILE_IS_NOT_DIR;
@ -591,7 +591,7 @@ int iso_tree_path_to_node(IsoImage *image, const char *path, IsoNode **node)
ptr = strdup(path); ptr = strdup(path);
result = 0; result = 0;
/* get the first component of the path */ /* get the first component of the path */
component = strtok_r(ptr, "/", &brk_info); component = strtok_r(ptr, "/", &brk_info);
while (component) { while (component) {

View File

@ -28,7 +28,6 @@ int int_pow(int base, int power)
return result; return result;
} }
int strconv(const char *str, const char *icharset, const char *ocharset, int strconv(const char *str, const char *icharset, const char *ocharset,
char **output) char **output)
{ {
@ -74,8 +73,8 @@ int strconv(const char *str, const char *icharset, const char *ocharset,
* @return * @return
* 1 success, < 0 error * 1 success, < 0 error
*/ */
static static
int str2wchar(const char *icharset, const char *input, wchar_t **output) int str2wchar(const char *icharset, const char *input, wchar_t **output)
{ {
iconv_t conv; iconv_t conv;
size_t inbytes; size_t inbytes;
@ -84,7 +83,7 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output)
char *src; char *src;
wchar_t *wstr; wchar_t *wstr;
size_t n; size_t n;
if (icharset == NULL || input == NULL || output == NULL) { if (icharset == NULL || input == NULL || output == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
@ -93,7 +92,7 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output)
if (conv == (iconv_t)-1) { if (conv == (iconv_t)-1) {
return ISO_CHARSET_CONV_ERROR; return ISO_CHARSET_CONV_ERROR;
} }
inbytes = strlen(input); inbytes = strlen(input);
outbytes = (inbytes + 1) * sizeof(wchar_t); outbytes = (inbytes + 1) * sizeof(wchar_t);
@ -107,7 +106,7 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output)
n = iconv(conv, &src, &inbytes, &ret, &outbytes); n = iconv(conv, &src, &inbytes, &ret, &outbytes);
while (n == -1) { while (n == -1) {
if (errno == E2BIG) { if (errno == E2BIG) {
/* error, should never occur */ /* error, should never occur */
iconv_close(conv); iconv_close(conv);
@ -115,7 +114,7 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output)
return ISO_CHARSET_CONV_ERROR; return ISO_CHARSET_CONV_ERROR;
} else { } else {
wchar_t *wret; wchar_t *wret;
/* /*
* Invalid input string charset. * Invalid input string charset.
* This can happen if input is in fact encoded in a charset * This can happen if input is in fact encoded in a charset
@ -126,7 +125,7 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output)
/* printf("String %s is not encoded in %s\n", str, codeset); */ /* printf("String %s is not encoded in %s\n", str, codeset); */
inbytes--; inbytes--;
src++; src++;
wret = (wchar_t*) ret; wret = (wchar_t*) ret;
*wret++ = (wchar_t) '_'; *wret++ = (wchar_t) '_';
ret = (char *) wret; ret = (char *) wret;
@ -138,7 +137,7 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output)
} }
} }
iconv_close(conv); iconv_close(conv);
*( (wchar_t *)ret )='\0'; *( (wchar_t *)ret )='\0';
*output = wstr; *output = wstr;
return ISO_SUCCESS; return ISO_SUCCESS;
@ -156,7 +155,7 @@ int str2ascii(const char *icharset, const char *input, char **output)
size_t outbytes; size_t outbytes;
size_t inbytes; size_t inbytes;
size_t n; size_t n;
if (icharset == NULL || input == NULL || output == NULL) { if (icharset == NULL || input == NULL || output == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
} }
@ -171,7 +170,7 @@ int str2ascii(const char *icharset, const char *input, char **output)
} }
src = (char *)wsrc_; src = (char *)wsrc_;
numchars = wcslen(wsrc_); numchars = wcslen(wsrc_);
inbytes = numchars * sizeof(wchar_t); inbytes = numchars * sizeof(wchar_t);
ret_ = malloc(numchars + 1); ret_ = malloc(numchars + 1);
@ -190,7 +189,7 @@ int str2ascii(const char *icharset, const char *input, char **output)
} }
n = iconv(conv, &src, &inbytes, &ret, &outbytes); n = iconv(conv, &src, &inbytes, &ret, &outbytes);
while(n == -1) { while (n == -1) {
/* The destination buffer is too small. Stops here. */ /* The destination buffer is too small. Stops here. */
if (errno == E2BIG) if (errno == E2BIG)
break; break;
@ -226,7 +225,7 @@ int str2ascii(const char *icharset, const char *input, char **output)
*ret='\0'; *ret='\0';
free(wsrc_); free(wsrc_);
*output = ret_; *output = ret_;
return ISO_SUCCESS; return ISO_SUCCESS;
} }
@ -238,25 +237,25 @@ static int valid_d_char(char c)
static int valid_a_char(char c) static int valid_a_char(char c)
{ {
return (c >= ' ' && c <= '"') || (c >= '%' && c <= '?') return (c >= ' ' && c <= '"') || (c >= '%' && c <= '?') ||
|| (c >= 'A' && c <= 'Z') || (c == '_'); (c >= 'A' && c <= 'Z') || (c == '_');
} }
static static
char *iso_dirid(const char *src, int size) char *iso_dirid(const char *src, int size)
{ {
size_t len, i; size_t len, i;
char name[32]; char name[32];
len = strlen(src); len = strlen(src);
if (len > size) { if (len > size) {
len = size; len = size;
} }
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
char c = toupper(src[i]); char c= toupper(src[i]);
name[i] = valid_d_char(c) ? c : '_'; name[i] = valid_d_char(c) ? c : '_';
} }
name[len] = '\0'; name[len] = '\0';
return strdup(name); return strdup(name);
} }
@ -274,7 +273,7 @@ char *iso_2_dirid(const char *src)
char *iso_1_fileid(const char *src) char *iso_1_fileid(const char *src)
{ {
char *dot; /* Position of the last dot in the filename, will be used char *dot; /* Position of the last dot in the filename, will be used
to calculate lname and lext. */ * to calculate lname and lext. */
int lname, lext, pos, i; int lname, lext, pos, i;
char dest[13]; /* 13 = 8 (name) + 1 (.) + 3 (ext) + 1 (\0) */ char dest[13]; /* 13 = 8 (name) + 1 (.) + 3 (ext) + 1 (\0) */
@ -292,24 +291,24 @@ char *iso_1_fileid(const char *src)
} }
pos = 0; pos = 0;
/* Convert up to 8 characters of the filename. */ /* Convert up to 8 characters of the filename. */
for (i = 0; i < lname && i < 8; i++) { for (i = 0; i < lname && i < 8; i++) {
char c = toupper(src[i]); char c= toupper(src[i]);
dest[pos++] = valid_d_char(c) ? c : '_'; dest[pos++] = valid_d_char(c) ? c : '_';
} }
/* This dot is mandatory, even if there is no extension. */ /* This dot is mandatory, even if there is no extension. */
dest[pos++] = '.'; dest[pos++] = '.';
/* Convert up to 3 characters of the extension, if any. */ /* Convert up to 3 characters of the extension, if any. */
for (i = 0; i < lext && i < 3; i++) { for (i = 0; i < lext && i < 3; i++) {
char c = toupper(src[lname + 1 + i]); char c= toupper(src[lname + 1 + i]);
dest[pos++] = valid_d_char(c) ? c : '_'; dest[pos++] = valid_d_char(c) ? c : '_';
} }
dest[pos] = '\0'; dest[pos] = '\0';
return strdup(dest); return strdup(dest);
} }
@ -339,8 +338,8 @@ char *iso_2_fileid(const char *src)
} else { } else {
lext = strlen(dot + 1); lext = strlen(dot + 1);
lname = strlen(src) - lext - 1; lname = strlen(src) - lext - 1;
lnext = (strlen(src) > 31 && lext > 3) lnext = (strlen(src) > 31 && lext > 3) ? (lname < 27 ? 30 - lname : 3)
? (lname < 27 ? 30 - lname : 3) : lext; : lext;
lnname = (strlen(src) > 31) ? 30 - lnext : lname; lnname = (strlen(src) > 31) ? 30 - lnext : lname;
} }
@ -349,18 +348,18 @@ char *iso_2_fileid(const char *src)
} }
pos = 0; pos = 0;
/* Convert up to lnname characters of the filename. */ /* Convert up to lnname characters of the filename. */
for (i = 0; i < lnname; i++) { for (i = 0; i < lnname; i++) {
char c = toupper(src[i]); char c= toupper(src[i]);
dest[pos++] = valid_d_char(c) ? c : '_'; dest[pos++] = valid_d_char(c) ? c : '_';
} }
dest[pos++] = '.'; dest[pos++] = '.';
/* Convert up to lnext characters of the extension, if any. */ /* Convert up to lnext characters of the extension, if any. */
for (i = 0; i < lnext; i++) { for (i = 0; i < lnext; i++) {
char c = toupper(src[lname + 1 + i]); char c= toupper(src[lname + 1 + i]);
dest[pos++] = valid_d_char(c) ? c : '_'; dest[pos++] = valid_d_char(c) ? c : '_';
} }
@ -368,166 +367,70 @@ char *iso_2_fileid(const char *src)
return strdup(dest); return strdup(dest);
} }
//void iso_dirid(char *src, int maxlen)
//{
// size_t len, i;
//
// len = strlen(src);
// if (len > maxlen) {
// src[maxlen] = '\0';
// len = maxlen;
// }
// for (i = 0; i < len; i++) {
// char c = toupper(src[i]);
// src[i] = valid_d_char(c) ? c : '_';
// }
//}
//void iso_1_fileid(char *src)
//{
// char *dot; /* Position of the last dot in the filename, will be used to
// calculate lname and lext. */
// int lname, lext, pos, i;
//
// dot = strrchr(src, '.');
//
// lext = dot ? strlen(dot + 1) : 0;
// lname = strlen(src) - lext - (dot ? 1 : 0);
//
// /* If we can't build a filename, return. */
// if (lname == 0 && lext == 0) {
// return;
// }
//
// pos = 0;
// /* Convert up to 8 characters of the filename. */
// for (i = 0; i < lname && i < 8; i++) {
// char c = toupper(src[i]);
// src[pos++] = valid_d_char(c) ? c : '_';
// }
//
// /* This dot is mandatory, even if there is no extension. */
// src[pos++] = '.';
//
// /* Convert up to 3 characters of the extension, if any. */
// for (i = 0; i < lext && i < 3; i++) {
// char c = toupper(src[lname + 1 + i]);
// src[pos++] = valid_d_char(c) ? c : '_';
// }
// src[pos] = '\0';
//}
//
//void iso_2_fileid(char *src)
//{
// char *dot;
// int lname, lext, lnname, lnext, pos, i;
//
// if (!src)
// return;
//
// dot = strrchr(src, '.');
//
// /*
// * Since the maximum length can be divided freely over the name and
// * extension, we need to calculate their new lengths (lnname and
// * lnext). If the original filename is too long, we start by trimming
// * the extension, but keep a minimum extension length of 3.
// */
// if (dot == NULL || *(dot + 1) == '\0') {
// lname = strlen(src);
// lnname = (lname > 30) ? 30 : lname;
// lext = lnext = 0;
// } else {
// lext = strlen(dot + 1);
// lname = strlen(src) - lext - 1;
// lnext = (strlen(src) > 31 && lext > 3)
// ? (lname < 27 ? 30 - lname : 3) : lext;
// lnname = (strlen(src) > 31) ? 30 - lnext : lname;
// }
//
// if (lnname == 0 && lnext == 0) {
// return;
// }
//
// pos = 0;
// /* Convert up to lnname characters of the filename. */
// for (i = 0; i < lnname; i++) {
// char c = toupper(src[i]);
// src[pos++] = valid_d_char(c) ? c : '_';
// }
// src[pos++] = '.';
// /* Convert up to lnext characters of the extension, if any. */
// for (i = 0; i < lnext; i++) {
// char c = toupper(src[lname + 1 + i]);
// src[pos++] = valid_d_char(c) ? c : '_';
// }
// src[pos] = '\0';
//}
int str2d_char(const char *icharset, const char *input, char **output) int str2d_char(const char *icharset, const char *input, char **output)
{ {
int ret; int ret;
char *ascii; char *ascii;
size_t len, i; size_t len, i;
if (output == NULL) { if (output == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
/** allow NULL input */ /** allow NULL input */
if (input == NULL) { if (input == NULL) {
*output = NULL; *output = NULL;
return 0; return 0;
} }
/* this checks for NULL parameters */ /* this checks for NULL parameters */
ret = str2ascii(icharset, input, &ascii); ret = str2ascii(icharset, input, &ascii);
if (ret < 0) { if (ret < 0) {
*output = NULL; *output = NULL;
return ret; return ret;
} }
len = strlen(ascii); len = strlen(ascii);
for (i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
char c = toupper(ascii[i]); char c= toupper(ascii[i]);
ascii[i] = valid_d_char(c) ? c : '_'; ascii[i] = valid_d_char(c) ? c : '_';
} }
*output = ascii; *output = ascii;
return ISO_SUCCESS; return ISO_SUCCESS;
} }
int str2a_char(const char *icharset, const char *input, char **output) int str2a_char(const char *icharset, const char *input, char **output)
{ {
int ret; int ret;
char *ascii; char *ascii;
size_t len, i; size_t len, i;
if (output == NULL) { if (output == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
/** allow NULL input */ /** allow NULL input */
if (input == NULL) { if (input == NULL) {
*output = NULL; *output = NULL;
return 0; return 0;
} }
/* this checks for NULL parameters */ /* this checks for NULL parameters */
ret = str2ascii(icharset, input, &ascii); ret = str2ascii(icharset, input, &ascii);
if (ret < 0) { if (ret < 0) {
*output = NULL; *output = NULL;
return ret; return ret;
} }
len = strlen(ascii); len = strlen(ascii);
for (i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
char c = toupper(ascii[i]); char c= toupper(ascii[i]);
ascii[i] = valid_a_char(c) ? c : '_'; ascii[i] = valid_a_char(c) ? c : '_';
} }
*output = ascii; *output = ascii;
return ISO_SUCCESS; return ISO_SUCCESS;
} }

View File

@ -16,13 +16,15 @@
* implementation of Julienne Walker. * implementation of Julienne Walker.
*/ */
struct iso_rbnode { struct iso_rbnode
{
void *data; void *data;
struct iso_rbnode *ch[2]; struct iso_rbnode *ch[2];
unsigned int red:1; unsigned int red :1;
}; };
struct iso_rbtree { struct iso_rbtree
{
struct iso_rbnode *root; struct iso_rbnode *root;
size_t size; size_t size;
int (*compare)(const void *a, const void *b); int (*compare)(const void *a, const void *b);
@ -40,8 +42,7 @@ struct iso_rbtree {
* @param tree * @param tree
* Location where the tree structure will be stored. * Location where the tree structure will be stored.
*/ */
int int iso_rbtree_new(int (*compare)(const void*, const void*), IsoRBTree **tree)
iso_rbtree_new(int (*compare)(const void*, const void*), IsoRBTree **tree)
{ {
if (compare == NULL || tree == NULL) { if (compare == NULL || tree == NULL) {
return ISO_NULL_POINTER; return ISO_NULL_POINTER;
@ -75,8 +76,7 @@ void rbtree_destroy_aux(struct iso_rbnode *root, void (*free_data)(void *))
* should provide a valid free_data function. It will be called for each * should provide a valid free_data function. It will be called for each
* element of the tree, so you can use it to free any related data. * element of the tree, so you can use it to free any related data.
*/ */
void void iso_rbtree_destroy(IsoRBTree *tree, void (*free_data)(void *))
iso_rbtree_destroy(IsoRBTree *tree, void (*free_data)(void *))
{ {
if (tree == NULL) { if (tree == NULL) {
return; return;
@ -115,14 +115,14 @@ static
struct iso_rbnode *iso_rbnode_new(void *data) struct iso_rbnode *iso_rbnode_new(void *data)
{ {
struct iso_rbnode *rn = malloc(sizeof(struct iso_rbnode)); struct iso_rbnode *rn = malloc(sizeof(struct iso_rbnode));
if ( rn != NULL ) { if (rn != NULL) {
rn->data = data; rn->data = data;
rn->red = 1; rn->red = 1;
rn->ch[0] = NULL; rn->ch[0] = NULL;
rn->ch[1] = NULL; rn->ch[1] = NULL;
} }
return rn; return rn;
} }
@ -154,23 +154,23 @@ int iso_rbtree_insert(IsoRBTree *tree, void *data, void **item)
/* Empty tree case */ /* Empty tree case */
tree->root = iso_rbnode_new(data); tree->root = iso_rbnode_new(data);
if (tree->root == NULL) { if (tree->root == NULL) {
return ISO_MEM_ERROR; return ISO_MEM_ERROR;
} }
new = data; new = data;
added = 1; added = 1;
} else { } else {
struct iso_rbnode head = {0}; /* False tree root */ struct iso_rbnode head = { 0 }; /* False tree root */
struct iso_rbnode *g, *t; /* Grandparent & parent */ struct iso_rbnode *g, *t; /* Grandparent & parent */
struct iso_rbnode *p, *q; /* Iterator & parent */ struct iso_rbnode *p, *q; /* Iterator & parent */
int dir = 0, last = 0; int dir = 0, last = 0;
int comp; int comp;
/* Set up helpers */ /* Set up helpers */
t = &head; t = &head;
g = p = NULL; g = p = NULL;
q = t->ch[1] = tree->root; q = t->ch[1] = tree->root;
/* Search down the tree */ /* Search down the tree */
while (1) { while (1) {
if (q == NULL) { if (q == NULL) {
@ -186,7 +186,7 @@ int iso_rbtree_insert(IsoRBTree *tree, void *data, void **item)
q->ch[0]->red = 0; q->ch[0]->red = 0;
q->ch[1]->red = 0; q->ch[1]->red = 0;
} }
/* Fix red violation */ /* Fix red violation */
if (is_red(q) && is_red(p)) { if (is_red(q) && is_red(p)) {
int dir2 = (t->ch[1] == g); int dir2 = (t->ch[1] == g);
@ -208,7 +208,7 @@ int iso_rbtree_insert(IsoRBTree *tree, void *data, void **item)
last = dir; last = dir;
dir = (comp < 0); dir = (comp < 0);
/* Update helpers */ /* Update helpers */
if (g != NULL) if (g != NULL)
t = g; t = g;
@ -219,7 +219,7 @@ int iso_rbtree_insert(IsoRBTree *tree, void *data, void **item)
/* Update root */ /* Update root */
tree->root = head.ch[1]; tree->root = head.ch[1];
} }
/* Make root black */ /* Make root black */
tree->root->red = 0; tree->root->red = 0;
@ -243,7 +243,6 @@ size_t iso_rbtree_get_size(IsoRBTree *tree)
return tree->size; return tree->size;
} }
static static
int rbtree_to_array_aux(struct iso_rbnode *root, void **array, size_t pos) int rbtree_to_array_aux(struct iso_rbnode *root, void **array, size_t pos)
{ {
@ -265,8 +264,7 @@ int rbtree_to_array_aux(struct iso_rbnode *root, void **array, size_t pos)
* no more needed. Note that the array is NULL-terminated, and thus it * no more needed. Note that the array is NULL-terminated, and thus it
* has size + 1 length. * has size + 1 length.
*/ */
void ** void ** iso_rbtree_to_array(IsoRBTree *tree)
iso_rbtree_to_array(IsoRBTree *tree)
{ {
void **array; void **array;

View File

@ -16,20 +16,19 @@ struct Iso_Image_Writer
* *
*/ */
int (*compute_data_blocks)(IsoImageWriter *writer); int (*compute_data_blocks)(IsoImageWriter *writer);
int (*write_vol_desc)(IsoImageWriter *writer); int (*write_vol_desc)(IsoImageWriter *writer);
int (*write_data)(IsoImageWriter *writer); int (*write_data)(IsoImageWriter *writer);
int (*free_data)(IsoImageWriter *writer); int (*free_data)(IsoImageWriter *writer);
void *data; void *data;
Ecma119Image *target; Ecma119Image *target;
}; };
/** /**
* This is the function all Writers shoudl call to write data to * This is the function all Writers shoudl call to write data to image.
* image.
* Currently, it is just a wrapper for write(2) Unix system call. * Currently, it is just a wrapper for write(2) Unix system call.
* *
* It is implemented in ecma119.c * It is implemented in ecma119.c