From 4c9d83f051f7a5a924e75e6dafc1d09f38e11c68 Mon Sep 17 00:00:00 2001 From: Vreixo Formoso Date: Fri, 28 Dec 2007 22:10:17 +0100 Subject: [PATCH] Define code style formatter for eclipse and apply it to source. --- .cproject | 2 + .settings/org.eclipse.cdt.core.prefs | 2 +- demo/cat_buffer.c | 63 +++---- doc/devel/codestyle.xml | 91 ++++++++++ src/buffer.c | 63 +++---- src/builder.c | 42 ++--- src/builder.h | 10 +- src/ecma119.c | 248 +++++++++++++-------------- src/ecma119.h | 54 +++--- src/ecma119_tree.c | 128 +++++++------- src/ecma119_tree.h | 24 +-- src/filesrc.c | 94 +++++----- src/filesrc.h | 5 +- src/fs_local.c | 62 +++---- src/fsource.c | 20 +-- src/fsource.h | 63 ++++--- src/image.c | 27 ++- src/image.h | 44 ++--- src/libisofs.h | 122 ++++++------- src/messages.c | 141 ++++++++------- src/messages.h | 4 +- src/node.c | 48 +++--- src/node.h | 22 +-- src/rockridge.c | 215 ++++++++++++----------- src/rockridge.h | 9 +- src/stream.c | 28 +-- src/stream.h | 30 ++-- src/tree.c | 134 +++++++-------- src/util.c | 189 +++++--------------- src/util_rbtree.c | 42 +++-- src/writer.h | 11 +- 31 files changed, 1018 insertions(+), 1019 deletions(-) create mode 100644 doc/devel/codestyle.xml diff --git a/.cproject b/.cproject index 02aee84..70c48d2 100644 --- a/.cproject +++ b/.cproject @@ -313,6 +313,7 @@ + @@ -624,6 +625,7 @@ + diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs index 4c247a3..7373836 100644 --- a/.settings/org.eclipse.cdt.core.prefs +++ b/.settings/org.eclipse.cdt.core.prefs @@ -1,4 +1,4 @@ -#Fri Dec 28 17:36:33 CET 2007 +#Fri Dec 28 21:07:56 CET 2007 eclipse.preferences.version=1 indexer/filesToParseUpFront= indexer/indexAllFiles=true diff --git a/demo/cat_buffer.c b/demo/cat_buffer.c index d5745fe..91cdc3b 100644 --- a/demo/cat_buffer.c +++ b/demo/cat_buffer.c @@ -22,7 +22,8 @@ * the libisofs ring buffer as intermediate memory */ -struct th_data { +struct th_data +{ IsoRingBuffer *rbuf; char *path; }; @@ -37,34 +38,34 @@ void *write_function(void *arg) int res; unsigned char tmp[WRITE_CHUNK]; struct th_data *data = (struct th_data *) arg; - + int fd = open(data->path, O_RDONLY); if (fd < 0) { fprintf(stderr, "Writer thread error: Can't open file"); iso_ring_buffer_writer_close(data->rbuf); pthread_exit(NULL); } - + 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); if (res <= 0) { break; } /* To test premature reader exit >>>>>>>>>>> - iso_ring_buffer_writer_close(data->rbuf); - pthread_exit(NULL); - <<<<<<<<<<<<<<<<<<<<<<<<< */ -// if (rand() > 2000000000) { -// fprintf(stderr, "Writer sleeping\n"); -// sleep(1); -// } + iso_ring_buffer_writer_close(data->rbuf); + pthread_exit(NULL); + <<<<<<<<<<<<<<<<<<<<<<<<< */ + // if (rand() > 2000000000) { + // fprintf(stderr, "Writer sleeping\n"); + // sleep(1); + // } } fprintf(stderr, "Writer finish: %d\n", res); - + close(fd); iso_ring_buffer_writer_close(data->rbuf); - pthread_exit(NULL); + pthread_exit(NULL); } static @@ -73,22 +74,22 @@ void *read_function(void *arg) unsigned char tmp[READ_CHUNK]; int res = 1; 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); /* To test premature reader exit >>>>>>>>>>> - iso_ring_buffer_reader_close(data->rbuf); - pthread_exit(NULL); - <<<<<<<<<<<<<<<<<<<<<<<<< */ -// if (rand() > 2000000000) { -// fprintf(stderr, "Reader sleeping\n"); -// sleep(1); -// } + iso_ring_buffer_reader_close(data->rbuf); + pthread_exit(NULL); + <<<<<<<<<<<<<<<<<<<<<<<<< */ + // if (rand() > 2000000000) { + // fprintf(stderr, "Reader sleeping\n"); + // sleep(1); + // } } fprintf(stderr, "Reader finish: %d\n", res); - + iso_ring_buffer_reader_close(data->rbuf); - + pthread_exit(NULL); } @@ -103,24 +104,24 @@ int main(int argc, char **argv) fprintf(stderr, "Usage: catbuffer /path/to/file\n"); return 1; } - + res = iso_ring_buffer_new(&data.rbuf); if (res < 0) { fprintf(stderr, "Can't create buffer\n"); return 1; } data.path = argv[1]; - + res = pthread_create(&writer, NULL, write_function, (void *) &data); res = pthread_create(&reader, NULL, read_function, (void *) &data); - + pthread_join(writer, NULL); pthread_join(reader, NULL); - + 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_empty(data.rbuf)); - + iso_ring_buffer_get_times_full(data.rbuf), + iso_ring_buffer_get_times_empty(data.rbuf)); + free(data.rbuf); return 0; } diff --git a/doc/devel/codestyle.xml b/doc/devel/codestyle.xml new file mode 100644 index 0000000..ef96520 --- /dev/null +++ b/doc/devel/codestyle.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/buffer.c b/src/buffer.c index 8a212f5..2109165 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -14,7 +14,7 @@ * there's enought space/data at the beginning * - pre-buffer for writes < BLOCK_SIZE * - */ + */ #include "buffer.h" #include "error.h" @@ -28,26 +28,27 @@ # define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif -struct iso_ring_buffer { +struct iso_ring_buffer +{ uint8_t buf[BLOCK_SIZE * BUFFER_SIZE]; - + /* * Number of bytes available. */ size_t size; - + /* position for reading and writing, offset from buf */ size_t rpos; size_t wpos; - + /* flags to report if read or writer threads ends execution */ - unsigned int rend:1; - unsigned int wend:1; - + unsigned int rend :1; + unsigned int wend :1; + /* just for statistical purposes */ unsigned int times_full; unsigned int times_empty; - + pthread_mutex_t mutex; pthread_cond_t empty; pthread_cond_t full; @@ -64,30 +65,30 @@ struct iso_ring_buffer { int iso_ring_buffer_new(IsoRingBuffer **rbuf) { IsoRingBuffer *buffer; - + if (rbuf == NULL) { return ISO_NULL_POINTER; } - + buffer = malloc(sizeof(IsoRingBuffer)); if (buffer == NULL) { return ISO_MEM_ERROR; } - + buffer->size = 0; buffer->wpos = 0; buffer->rpos = 0; - + buffer->times_full = 0; buffer->times_empty = 0; - + buffer->rend = buffer->wend = 0; - + /* init mutex and waiting queues */ pthread_mutex_init(&buffer->mutex, NULL); pthread_cond_init(&buffer->empty, NULL); pthread_cond_init(&buffer->full, NULL); - + *rbuf = buffer; return ISO_SUCCESS; } @@ -118,15 +119,15 @@ int iso_ring_buffer_write(IsoRingBuffer *buf, uint8_t *data, size_t count) { size_t len; int bytes_write = 0; - + if (buf == NULL || data == NULL) { return ISO_NULL_POINTER; } - + while (bytes_write < count) { - + pthread_mutex_lock(&buf->mutex); - + 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 * only to propertly detect the reader has been cancelled */ - + if (buf->rend) { /* the read procces has been finished */ 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 */ pthread_cond_wait(&buf->full, &buf->mutex); } - + len = MIN(count - bytes_write, BUFFER_CAPACITY - buf->size); if (buf->wpos + len > BUFFER_CAPACITY) { 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); bytes_write += len; buf->size += len; - + /* wake up reader */ pthread_cond_signal(&buf->empty); 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; int bytes_read = 0; - + if (buf == NULL || dest == NULL) { return ISO_NULL_POINTER; } - + while (bytes_read < count) { pthread_mutex_lock(&buf->mutex); - + while (buf->size == 0) { /* * 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 * canceled while the reader was waiting */ - + if (buf->wend) { /* the writer procces has been finished */ 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 */ pthread_cond_wait(&buf->empty, &buf->mutex); } - + len = MIN(count - bytes_read, buf->size); if (buf->rpos + len > BUFFER_CAPACITY) { 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); bytes_read += len; buf->size -= len; - + /* wake up the writer */ pthread_cond_signal(&buf->full); pthread_mutex_unlock(&buf->mutex); @@ -220,7 +221,7 @@ void iso_ring_buffer_writer_close(IsoRingBuffer *buf) { pthread_mutex_lock(&buf->mutex); buf->wend = 1; - + /* ensure no reader is waiting */ pthread_cond_signal(&buf->empty); pthread_mutex_unlock(&buf->mutex); @@ -230,7 +231,7 @@ void iso_ring_buffer_reader_close(IsoRingBuffer *buf) { pthread_mutex_lock(&buf->mutex); buf->rend = 1; - + /* ensure no writer is waiting */ pthread_cond_signal(&buf->full); pthread_mutex_unlock(&buf->mutex); diff --git a/src/builder.c b/src/builder.c index 3af4adf..44b23f3 100644 --- a/src/builder.c +++ b/src/builder.c @@ -31,29 +31,29 @@ void iso_node_builder_unref(IsoNodeBuilder *builder) } static -int default_create_file(IsoNodeBuilder *builder, IsoImage *image, +int default_create_file(IsoNodeBuilder *builder, IsoImage *image, IsoFileSource *src, IsoFile **file) { int res; struct stat info; IsoStream *stream; IsoFile *node; - + if (builder == NULL || src == NULL || file == NULL) { return ISO_NULL_POINTER; } - + res = iso_file_source_stat(src, &info); if (res < 0) { return res; } - + /* this will fail if src is a dir, is not accessible... */ res = iso_file_source_stream_new(src, &stream); if (res < 0) { return res; } - + node = malloc(sizeof(IsoFile)); if (node == NULL) { /* 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); return ISO_MEM_ERROR; } - + /* fill node fields */ node->node.refcount = 1; node->node.type = LIBISO_FILE; @@ -78,26 +78,26 @@ int default_create_file(IsoNodeBuilder *builder, IsoImage *image, node->sort_weight = 0; node->stream = stream; node->msblock = 0; - + *file = node; return ISO_SUCCESS; } static -int default_create_node(IsoNodeBuilder *builder, IsoImage *image, +int default_create_node(IsoNodeBuilder *builder, IsoImage *image, IsoFileSource *src, IsoNode **node) { int result; struct stat info; IsoNode *new; char *name; - + if (builder == NULL || src == NULL || node == NULL) { return ISO_NULL_POINTER; } - + name = iso_file_source_get_name(src); - + /* get info about source */ if (image->recOpts->follow_symlinks) { result = iso_file_source_stat(src, &info); @@ -107,7 +107,7 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image, if (result < 0) { return result; } - + new = NULL; switch (info.st_mode & S_IFMT) { case S_IFREG: @@ -148,7 +148,7 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image, /* source is a symbolic link */ char dest[PATH_MAX]; IsoSymlink *link; - + result = iso_file_source_readlink(src, dest, PATH_MAX); if (result < 0) { return result; @@ -179,7 +179,7 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image, } break; } - + /* fill fields */ new->refcount = 1; new->name = strdup(name); @@ -189,12 +189,12 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image, new->atime = info.st_atime; new->mtime = info.st_mtime; new->ctime = info.st_ctime; - + new->hidden = 0; - + new->parent = NULL; new->next = NULL; - + *node = new; return ISO_SUCCESS; } @@ -208,23 +208,23 @@ void default_free(IsoNodeBuilder *builder) int iso_node_basic_builder_new(IsoNodeBuilder **builder) { IsoNodeBuilder *b; - + if (builder == NULL) { return ISO_NULL_POINTER; } - + b = malloc(sizeof(IsoNodeBuilder)); if (b == NULL) { return ISO_MEM_ERROR; } - + b->refcount = 1; b->create_file_data = NULL; b->create_node_data = NULL; b->create_file = default_create_file; b->create_node = default_create_node; b->free = default_free; - + *builder = b; return ISO_SUCCESS; } diff --git a/src/builder.h b/src/builder.h index 15d0dd4..e0d3ff1 100644 --- a/src/builder.h +++ b/src/builder.h @@ -40,9 +40,9 @@ struct Iso_Node_Builder * @return * 1 on success, < 0 on error */ - int (*create_file)(IsoNodeBuilder *builder, IsoImage *image, + int (*create_file)(IsoNodeBuilder *builder, IsoImage *image, IsoFileSource *src, IsoFile **file); - + /** * 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, @@ -53,15 +53,15 @@ struct Iso_Node_Builder * @return * 1 on success, < 0 on error */ - int (*create_node)(IsoNodeBuilder *builder, IsoImage *image, + int (*create_node)(IsoNodeBuilder *builder, IsoImage *image, IsoFileSource *src, IsoNode **node); - + /** * Free implementation specific data. Should never be called by user. * Use iso_node_builder_unref() instead. */ void (*free)(IsoNodeBuilder *builder); - + int refcount; void *create_file_data; void *create_node_data; diff --git a/src/ecma119.c b/src/ecma119.c index b03607d..2b8d4eb 100644 --- a/src/ecma119.c +++ b/src/ecma119.c @@ -30,12 +30,12 @@ static void ecma119_image_free(Ecma119Image *t) { size_t i; - + ecma119_node_free(t->root); iso_image_unref(t->image); iso_rbtree_destroy(t->files, iso_file_src_free); iso_ring_buffer_free(t->buffer); - + for (i = 0; i < t->nwriters; ++i) { IsoImageWriter *writer = t->writers[i]; writer->free_data(writer); @@ -73,7 +73,8 @@ size_t calc_dirent_len(Ecma119Image *t, Ecma119Node *n) if (need_version_number(t, n)) { ret += 2; /* take into account version numbers */ } - if (ret % 2) ret++; + if (ret % 2) + 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 * taking into account the continuation areas. */ -static +static size_t calc_dir_size(Ecma119Image *t, Ecma119Node *dir, size_t *ce) { size_t i, len; size_t ce_len = 0; - + /* size of "." and ".." entries */ len = 34 + 34; 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); *ce += ce_len; } - + for (i = 0; i < dir->info.dir.nchildren; ++i) { size_t remaining; Ecma119Node *child = dir->info.dir.children[i]; size_t dirent_len = calc_dirent_len(t, child); if (t->rockridge) { - dirent_len += rrip_calc_len(t, child, 0, 255 - dirent_len, - &ce_len); + dirent_len += rrip_calc_len(t, child, 0, 255 - dirent_len, &ce_len); *ce += ce_len; } remaining = BLOCK_SIZE - (len % BLOCK_SIZE); @@ -127,7 +127,7 @@ size_t calc_dir_size(Ecma119Image *t, Ecma119Node *dir, size_t *ce) return len; } -static +static void calc_dir_pos(Ecma119Image *t, Ecma119Node *dir) { size_t i, len; @@ -156,12 +156,12 @@ uint32_t calc_path_table_size(Ecma119Node *dir) { uint32_t size; size_t i; - + /* size of path table for this entry */ size = 8; size += dir->iso_name ? strlen(dir->iso_name) : 1; size += (size % 2); - + /* and recurse */ for (i = 0; i < dir->info.dir.nchildren; i++) { Ecma119Node *child = dir->info.dir.children[i]; @@ -177,29 +177,29 @@ int ecma119_writer_compute_data_blocks(IsoImageWriter *writer) { Ecma119Image *target; uint32_t path_table_size; - + if (writer == NULL) { return ISO_MEM_ERROR; } - + target = writer->target; - + /* compute position of directories */ iso_msg_debug(target->image, "Computing position of dir structure"); target->ndirs = 0; calc_dir_pos(target, target->root); - + /* compute length of pathlist */ iso_msg_debug(target->image, "Computing length of pathlist"); path_table_size = calc_path_table_size(target->root); - + /* compute location for path tables */ target->l_path_table_pos = target->curblock; target->curblock += div_up(path_table_size, BLOCK_SIZE); target->m_path_table_pos = target->curblock; target->curblock += div_up(path_table_size, BLOCK_SIZE); target->path_table_size = path_table_size; - + 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 * distinguish it from the "." entry in the root directory) */ -static +static 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 block; uint8_t len_dr; /*< size of dir entry without SUSP fields */ - uint8_t *name = (file_id >= 0) ? (uint8_t*)&file_id : - (uint8_t*)node->iso_name; - + uint8_t *name = (file_id >= 0) ? (uint8_t*)&file_id + : (uint8_t*)node->iso_name; + struct ecma119_dir_record *rec = (struct ecma119_dir_record*)buf; - + len_dr = 33 + len_fi + (len_fi % 2 ? 0 : 1); - + memcpy(rec->file_id, name, len_fi); - + if (need_version_number(t, node)) { len_dr += 2; rec->file_id[len_fi++] = ';'; rec->file_id[len_fi++] = '1'; } - + if (node->type == ECMA119_DIR) { /* use the cached length */ len = node->info.dir.len; @@ -253,7 +253,7 @@ void write_one_dir_record(Ecma119Image *t, Ecma119Node *node, int file_id, len = 0; block = 0; } - + /* * 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; iso_bb(rec->vol_seq_number, 1, 2); rec->len_fi[0] = len_fi; - + /* and finally write the SUSP fields */ if (info != NULL) { rrip_write_susp_fields(t, info, buf + len_dr); @@ -283,33 +283,33 @@ int ecma119_writer_write_vol_desc(IsoImageWriter *writer) IsoImage *image; Ecma119Image *t; struct ecma119_pri_vol_desc vol; - + char *vol_id, *pub_id, *data_id, *volset_id; char *system_id, *application_id, *copyright_file_id; char *abstract_file_id, *biblio_file_id; - + if (writer == NULL) { return ISO_MEM_ERROR; } - + t = writer->target; image = t->image; - + iso_msg_debug(image, "Write Primary Volume Descriptor"); - + memset(&vol, 0, sizeof(struct ecma119_pri_vol_desc)); 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->data_preparer_id, &data_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->application_id, &application_id); str2d_char(t->input_charset, image->copyright_file_id, ©right_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); - + vol.vol_desc_type[0] = 1; memcpy(vol.std_identifier, "CD001", 5); vol.vol_desc_version[0] = 1; @@ -318,7 +318,7 @@ int ecma119_writer_write_vol_desc(IsoImageWriter *writer) } else { /* put linux by default? */ memcpy(vol.system_id, "LINUX", 5); - } + } if (vol_id) { 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); if (data_id) strncpy((char*)vol.data_prep_id, data_id, 128); - + if (application_id) strncpy((char*)vol.application_id, application_id, 128); if (copyright_file_id) @@ -362,12 +362,12 @@ int ecma119_writer_write_vol_desc(IsoImageWriter *writer) free(copyright_file_id); free(abstract_file_id); free(biblio_file_id); - + /* Finally write the Volume Descriptor */ return iso_write(t, &vol, sizeof(struct ecma119_pri_vol_desc)); } -static +static int write_one_dir(Ecma119Image *t, Ecma119Node *dir) { int ret; @@ -375,13 +375,13 @@ int write_one_dir(Ecma119Image *t, Ecma119Node *dir) size_t i; size_t fi_len, len; struct susp_info info; - + /* buf will point to current write position on buffer */ uint8_t *buf = buffer; - + /* initialize buffer with 0s */ memset(buffer, 0, BLOCK_SIZE); - + /* * set susp_info to 0's, this way code for both plain ECMA-119 and * 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++) { Ecma119Node *child = dir->info.dir.children[i]; - + /* compute len of directory entry */ fi_len = strlen(child->iso_name); len = fi_len + 33 + (fi_len % 2 ? 0 : 1); if (need_version_number(t, child)) { len += 2; } - + /* get the SUSP fields if rockridge is enabled */ if (t->rockridge) { 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; } - - if ( (buf + len - buffer) > BLOCK_SIZE ) { + + if ( (buf + len - buffer) > BLOCK_SIZE) { /* dir doesn't fit in current block */ ret = iso_write(t, buffer, BLOCK_SIZE); 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); buf += len; } - + /* write the last block */ ret = iso_write(t, buffer, BLOCK_SIZE); if (ret < 0) { return ret; } - + /* write the Continuation Area if needed */ if (info.ce_len > 0) { ret = rrip_write_ce_fields(t, &info); } - + return ret; } -static +static int write_dirs(Ecma119Image *t, Ecma119Node *root) { int ret; size_t i; - + /* write all directory entries for this dir */ ret = write_one_dir(t, root); if (ret < 0) { return ret; } - + /* recurse */ for (i = 0; i < root->info.dir.nchildren; i++) { Ecma119Node *child = root->info.dir.children[i]; @@ -486,7 +486,7 @@ int write_dirs(Ecma119Image *t, Ecma119Node *root) return ISO_SUCCESS; } -static +static int write_path_table(Ecma119Image *t, Ecma119Node **pathlist, int l_type) { size_t i, len; @@ -496,8 +496,8 @@ int write_path_table(Ecma119Image *t, Ecma119Node **pathlist, int l_type) Ecma119Node *dir; uint32_t path_table_size; int parent = 0; - int ret = ISO_SUCCESS; - + int ret= ISO_SUCCESS; + path_table_size = 0; 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; } - + /* we need to fill the last block with zeros */ path_table_size %= BLOCK_SIZE; if (path_table_size) { @@ -539,15 +539,15 @@ int write_path_table(Ecma119Image *t, Ecma119Node **pathlist, int l_type) return ret; } -static +static int write_path_tables(Ecma119Image *t) { int ret; size_t i, j, cur; Ecma119Node **pathlist; - + iso_msg_debug(t->image, "Writing ISO Path tables"); - + /* allocate temporal pathlist */ pathlist = malloc(sizeof(void*) * t->ndirs); if (pathlist == NULL) { @@ -565,17 +565,17 @@ int write_path_tables(Ecma119Image *t) } } } - + /* Write L Path Table */ ret = write_path_table(t, pathlist, 1); if (ret < 0) { goto write_path_tables_exit; } - + /* Write L Path Table */ ret = write_path_table(t, pathlist, 0); - -write_path_tables_exit:; + + write_path_tables_exit: ; free(pathlist); return ret; } @@ -589,21 +589,21 @@ int ecma119_writer_write_data(IsoImageWriter *writer) { int ret; Ecma119Image *t; - + if (writer == NULL) { return ISO_MEM_ERROR; } t = writer->target; - + /* first of all, we write the directory structure */ ret = write_dirs(t, t->root); if (ret < 0) { return ret; } - + /* and write the path tables */ ret = write_path_tables(t); - + return ret; } @@ -618,28 +618,28 @@ int ecma119_writer_create(Ecma119Image *target) { int ret; IsoImageWriter *writer; - + writer = malloc(sizeof(IsoImageWriter)); if (writer == NULL) { return ISO_MEM_ERROR; } - + writer->compute_data_blocks = ecma119_writer_compute_data_blocks; writer->write_vol_desc = ecma119_writer_write_vol_desc; writer->write_data = ecma119_writer_write_data; writer->free_data = ecma119_writer_free_data; writer->data = NULL; writer->target = target; - + /* add this writer to image */ target->writers[target->nwriters++] = writer; - + iso_msg_debug(target->image, "Creating low level ECMA-119 tree..."); ret = ecma119_tree_create(target); if (ret < 0) { return ret; } - + /* we need the volume descriptor */ target->curblock++; return ISO_SUCCESS; @@ -652,10 +652,10 @@ void *write_function(void *arg) size_t i; uint8_t buf[BLOCK_SIZE]; IsoImageWriter *writer; - + Ecma119Image *target = (Ecma119Image*)arg; iso_msg_debug(target->image, "Starting image writing..."); - + /* Write System Area, 16 blocks of zeros (ECMA-119, 6.2.1) */ memset(buf, 0, BLOCK_SIZE); for (i = 0; i < 16; ++i) { @@ -664,7 +664,7 @@ void *write_function(void *arg) goto write_error; } } - + /* write volume descriptors, one per writer */ iso_msg_debug(target->image, "Write volume descriptors"); for (i = 0; i < target->nwriters; ++i) { @@ -674,22 +674,22 @@ void *write_function(void *arg) goto write_error; } } - + /* write Volume Descriptor Set Terminator (ECMA-119, 8.3) */ { struct ecma119_vol_desc_terminator *vol; vol = (struct ecma119_vol_desc_terminator *) buf; - + vol->vol_desc_type[0] = 255; memcpy(vol->std_identifier, "CD001", 5); vol->vol_desc_version[0] = 1; - + res = iso_write(target, buf, BLOCK_SIZE); if (res < 0) { goto write_error; } } - + /* write data for each writer */ for (i = 0; i < target->nwriters; ++i) { writer = target->writers[i]; @@ -698,40 +698,39 @@ void *write_function(void *arg) goto write_error; } } - + iso_ring_buffer_writer_close(target->buffer); pthread_exit(NULL); - -write_error:; - iso_msg_fatal(target->image, LIBISO_WRITE_ERROR, + + write_error: ; + iso_msg_fatal(target->image, LIBISO_WRITE_ERROR, "Image write error, code %d", res); iso_ring_buffer_writer_close(target->buffer); pthread_exit(NULL); } -static -int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts, - Ecma119Image **img) +static +int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts, Ecma119Image **img) { int ret, i; Ecma119Image *target; - + /* 1. Allocate target and copy opts there */ target = calloc(1, sizeof(Ecma119Image)); if (target == NULL) { return ISO_MEM_ERROR; } - + /* create the tree for file caching */ ret = iso_rbtree_new(iso_file_src_cmp, &(target->files)); if (ret < 0) { free(target); return ret; } - + target->image = src; iso_image_ref(src); - + target->iso_level = opts->level; target->rockridge = opts->rockridge; 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->dir_mode = opts->replace_dir_mode == 2 ? opts->dir_mode : 0555; target->file_mode = opts->replace_file_mode == 2 ? opts->file_mode : 0444; - + target->now = time(NULL); target->ms_block = 0; @@ -760,7 +759,7 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts, free(target); return ISO_MEM_ERROR; } - + if (opts->output_charset != NULL) { target->output_charset = strdup(opts->output_charset); } else { @@ -771,7 +770,7 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts, free(target); return ISO_MEM_ERROR; } - + /* * 2. Based on those options, create needed writers: iso, joliet... * Each writer inits its structures and stores needed info into @@ -780,8 +779,8 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts, * current block. * 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 */ target->writers = malloc(2 * sizeof(void*)); if (target->writers == NULL) { @@ -789,22 +788,22 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts, free(target); return ISO_MEM_ERROR; } - + /* create writer for ECMA-119 structure */ ret = ecma119_writer_create(target); if (ret < 0) { goto target_cleanup; } - + /* Volume Descriptor Set Terminator */ target->curblock++; - + /* create writer for file contents */ ret = iso_file_src_writer_create(target); if (ret < 0) { goto target_cleanup; } - + /* * 3. * Call compute_data_blocks() in each Writer. @@ -818,27 +817,27 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts, goto target_cleanup; } } - + /* * The volume space size is just the size of the last session, in * case of ms images. */ target->total_size = (target->curblock - target->ms_block) * BLOCK_SIZE; target->vol_space_size = target->curblock - target->ms_block; - + /* 4. Create and start writting thread */ - + /* create the ring buffer */ ret = iso_ring_buffer_new(&target->buffer); if (ret < 0) { goto target_cleanup; } - + /* ensure the thread is created joinable */ pthread_attr_init(&(target->th_attr)); 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); if (ret != 0) { iso_msg_fatal(target->image, LIBISO_THREAD_ERROR, @@ -846,24 +845,23 @@ int ecma119_image_new(IsoImage *src, Ecma119WriteOpts *opts, ret = ISO_THREAD_ERROR; goto target_cleanup; } - + /* * Notice that once we reach this point, target belongs to the writer * thread and should not be modified until the writer thread finished. * There're however, specific fields in target that can be accessed, or * even modified by the read thread (look inside bs_* functions) */ - + *img = target; return ISO_SUCCESS; - -target_cleanup:; + + target_cleanup: ; ecma119_image_free(target); return ret; } -static int -bs_read(struct burn_source *bs, unsigned char *buf, int size) +static int bs_read(struct burn_source *bs, unsigned char *buf, int size) { int ret; Ecma119Image *t = (Ecma119Image*)bs->data; @@ -881,29 +879,27 @@ bs_read(struct burn_source *bs, unsigned char *buf, int size) } } -static off_t -bs_get_size(struct burn_source *bs) +static off_t bs_get_size(struct burn_source *bs) { Ecma119Image *target = (Ecma119Image*)bs->data; return target->total_size; } -static void -bs_free_data(struct burn_source *bs) +static void bs_free_data(struct burn_source *bs) { Ecma119Image *target = (Ecma119Image*)bs->data; - + /* forces writer to stop if it is still running */ iso_ring_buffer_reader_close(target->buffer); - + /* wait until writer thread finishes */ pthread_join(target->wthread, NULL); - + iso_msg_debug(target->image, "Writer thread joined"); iso_msg_debug(target->image, "Ring buffer was %d times full and %d times " "empty", iso_ring_buffer_get_times_full(target->buffer), iso_ring_buffer_get_times_empty(target->buffer)); - + /* now we can safety free target */ ecma119_image_free(target); } @@ -912,7 +908,7 @@ static int bs_set_size(struct burn_source *bs, off_t size) { Ecma119Image *target = (Ecma119Image*)bs->data; - + /* * 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 @@ -927,30 +923,30 @@ int iso_image_create(IsoImage *image, Ecma119WriteOpts *opts, { int ret; struct burn_source *source; - Ecma119Image *target = NULL; - + Ecma119Image *target= NULL; + if (image == NULL || opts == NULL || burn_src == NULL) { return ISO_NULL_POINTER; } - + source = calloc(1, sizeof(struct burn_source)); if (source == NULL) { return ISO_MEM_ERROR; } - + ret = ecma119_image_new(image, opts, &target); if (ret < 0) { free(source); return ret; } - + source->refcount = 1; source->read = bs_read; source->get_size = bs_get_size; source->set_size = bs_set_size; source->free_data = bs_free_data; source->data = target; - + *burn_src = source; 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 ret; - + ret = iso_ring_buffer_write(target->buffer, buf, count); if (ret == 0) { /* reader cancelled */ diff --git a/src/ecma119.h b/src/ecma119.h index 02d025e..4de577e 100644 --- a/src/ecma119.h +++ b/src/ecma119.h @@ -23,50 +23,54 @@ typedef struct ecma119_node Ecma119Node; typedef struct Iso_File_Src IsoFileSrc; typedef struct Iso_Image_Writer IsoImageWriter; -struct ecma119_image { +struct ecma119_image +{ IsoImage *image; Ecma119Node *root; - - unsigned int iso_level:2; - + + unsigned int iso_level :2; + /* extensions */ - unsigned int rockridge:1; - + unsigned int rockridge :1; + /* relaxed constraints */ - unsigned int omit_version_numbers:1; - unsigned int allow_deep_paths:1; -// int relaxed_constraints; /**< see ecma119_relaxed_constraints_flag */ - + unsigned int omit_version_numbers :1; + unsigned int allow_deep_paths :1; + // int relaxed_constraints; /**< see ecma119_relaxed_constraints_flag */ + /* * Mode replace. If one of these flags is set, the correspodent values are * replaced with values below. */ - unsigned int replace_uid:1; - unsigned int replace_gid:1; - unsigned int replace_file_mode:1; - unsigned int replace_dir_mode:1; - + unsigned int replace_uid :1; + unsigned int replace_gid :1; + unsigned int replace_file_mode :1; + unsigned int replace_dir_mode :1; + uid_t uid; gid_t gid; mode_t file_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 * time we add a new file, this is incremented. */ ino_t ino; - + char *input_charset; char *output_charset; - + uint32_t ms_block; /**< start block for a ms image */ - time_t now; /**< Time at which writing began. */ - off_t total_size; /**< Total size of the output. This only - * includes the current volume. */ + time_t now; /**< Time at which writing began. */ + + /** Total size of the output. This only includes the current volume. */ + off_t total_size; uint32_t vol_space_size; /* @@ -83,16 +87,16 @@ struct ecma119_image { uint32_t path_table_size; uint32_t l_path_table_pos; uint32_t m_path_table_pos; - + size_t nwriters; IsoImageWriter **writers; /* tree of files sources */ IsoRBTree *files; - + /* Buffer for communication between burn_source and writer thread */ IsoRingBuffer *buffer; - + /* writer thread descriptor */ pthread_t wthread; pthread_attr_t th_attr; diff --git a/src/ecma119_tree.c b/src/ecma119_tree.c index bb6c096..6652c20 100644 --- a/src/ecma119_tree.c +++ b/src/ecma119_tree.c @@ -25,7 +25,7 @@ int get_iso_name(Ecma119Image *img, IsoNode *iso, char **name) { int ret; char *ascii_name; - char *isoname = NULL; + char *isoname= NULL; if (iso->name == NULL) { /* 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 * 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 ecma->nlink = 1; ecma->ino = ++img->ino; - + *node = ecma; return ISO_SUCCESS; } @@ -126,9 +126,9 @@ int create_file(Ecma119Image *img, IsoFile *iso, Ecma119Node **node) size = iso_stream_get_size(iso->stream); 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 " - "greater than 4GB", iso->node.name); + "greater than 4GB", iso->node.name); return 0; } @@ -147,7 +147,7 @@ int create_file(Ecma119Image *img, IsoFile *iso, Ecma119Node **node) } (*node)->type = ECMA119_FILE; (*node)->info.file = src; - + return ret; } @@ -208,13 +208,13 @@ void ecma119_node_free(Ecma119Node *node) * */ static -int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree, +int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree, int depth, int pathlen) { int ret; Ecma119Node *node; int max_path; - char *iso_name = NULL; + char *iso_name= NULL; if (image == NULL || iso == NULL || tree == NULL) { 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); if (!image->rockridge && !image->allow_deep_paths) { 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 " - "or path length over 255", iso->name); + "or path length over 255", iso->name); free(iso_name); return 0; } } - switch(iso->type) { + switch (iso->type) { case LIBISO_FILE: ret = create_file(image, (IsoFile*)iso, &node); break; @@ -249,8 +249,7 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree, } else { /* symlinks are only supported when RR is enabled */ iso_msg_note(image->image, LIBISO_FILE_IGNORED, "File \"%s\" " - "ignored. Symlinks need RockRidge extensions.", - iso->name); + "ignored. Symlinks need RockRidge extensions.", iso->name); ret = 0; } break; @@ -260,8 +259,7 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree, } else { /* symlinks are only supported when RR is enabled */ iso_msg_note(image->image, LIBISO_FILE_IGNORED, "File \"%s\" " - "ignored. Special files need RockRidge extensions.", - iso->name); + "ignored. Special files need RockRidge extensions.", iso->name); ret = 0; } break; @@ -270,7 +268,7 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree, free(iso_name); return 0; break; - case LIBISO_DIR: + case LIBISO_DIR: { IsoNode *pos; 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 */ -static +static int cmp_node_name(const void *f1, const void *f2) { 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 * by \p root, acording to the order specified in ECMA-119, section 9.3. */ -static +static void sort_tree(Ecma119Node *root) { size_t i; - qsort(root->info.dir.children, root->info.dir.nchildren, - sizeof(void*), cmp_node_name); + qsort(root->info.dir.children, root->info.dir.nchildren, sizeof(void*), + cmp_node_name); for (i = 0; i < root->info.dir.nchildren; i++) { if (root->info.dir.children[i]->type == ECMA119_DIR) sort_tree(root->info.dir.children[i]); @@ -360,33 +358,33 @@ int contains_name(Ecma119Node *dir, const char *name) * but never under 3 characters. */ static -int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len, - int max_dir_len) +int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len, + int max_dir_len) { int i, nchildren; Ecma119Node **children; int need_sort = 0; - + nchildren = dir->info.dir.nchildren; children = dir->info.dir.children; - + for (i = 0; i < nchildren; ++i) { char *name, *ext; char full_name[40]; int max; /* computed max len for name, without extension */ - int j = i; + int j = i; int digits = 1; /* characters to change per name */ - + /* first, find all child with same name */ - while (j + 1 < nchildren && - !cmp_node_name(children + i, children + j + 1)) { + while (j + 1 < nchildren && !cmp_node_name(children + i, children + j + + 1)) { ++j; } if (j == i) { /* name is unique */ continue; } - + /* * 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 @@ -397,14 +395,14 @@ int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len, int ok, k; char *dot; int change = 0; /* number to be written */ - + /* copy name to buffer */ strcpy(full_name, children[i]->iso_name); - + /* compute name and extension */ dot = strrchr(full_name, '.'); if (dot != NULL && children[i]->type != ECMA119_DIR) { - + /* * File (not dir) with extension * 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'; name = full_name; ext = dot + 1; - + /* * For iso level 1 we force ext len to be 3, as name * 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 */ ext = name + strlen(name); } - + ok = 1; /* change name of each file */ 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) { 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); free(children[k]->iso_name); 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 (need_sort) { + if (need_sort) { qsort(children, nchildren, sizeof(void*), cmp_node_name); } - + return ISO_SUCCESS; } 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 ret; size_t i; - + ret = mangle_single_dir(img, dir, max_file_len, max_dir_len); if (ret < 0) { return ret; } - + /* recurse */ for (i = 0; i < dir->info.dir.nchildren; ++i) { if (dir->info.dir.children[i]->type == ECMA119_DIR) { - ret = mangle_dir(img, dir->info.dir.children[i], - max_file_len, max_dir_len); + ret = mangle_dir(img, dir->info.dir.children[i], max_file_len, + max_dir_len); if (ret < 0) { /* error */ return ret; @@ -553,7 +551,7 @@ static int mangle_tree(Ecma119Image *img, int recurse) { int max_file, max_dir; - + // TODO take care about relaxed constraints if (img->iso_level == 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 */ -static -int create_placeholder(Ecma119Node *parent, - Ecma119Node *real, Ecma119Node **node) +static +int create_placeholder(Ecma119Node *parent, Ecma119Node *real, + Ecma119Node **node) { Ecma119Node *ret; @@ -584,7 +582,7 @@ int create_placeholder(Ecma119Node *parent, if (ret == NULL) { return ISO_MEM_ERROR; } - + /* * TODO * If real is a dir, while placeholder is a file, ISO name restricctions @@ -595,7 +593,7 @@ int create_placeholder(Ecma119Node *parent, free(ret); return ISO_MEM_ERROR; } - + /* take a ref to the IsoNode */ ret->node = real->node; iso_node_ref(real->node); @@ -604,12 +602,12 @@ int create_placeholder(Ecma119Node *parent, ret->info.real_me = real; ret->ino = real->ino; ret->nlink = real->nlink; - + *node = ret; return ISO_SUCCESS; } -static +static size_t max_child_name_len(Ecma119Node *dir) { 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 * than 255 characters, as specified in ECMA-119, section 6.8.2.1 */ -static +static int reparent(Ecma119Node *child, Ecma119Node *parent) { int ret; @@ -634,7 +632,7 @@ int reparent(Ecma119Node *child, Ecma119Node *parent) Ecma119Node *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) { ret = create_placeholder(child->parent, child, &placeholder); if (ret < 0) { @@ -644,7 +642,7 @@ int reparent(Ecma119Node *child, Ecma119Node *parent) break; } } - + /* just for debug, this should never happen... */ if (i == child->parent->info.dir.nchildren) { return ISO_ERROR; @@ -652,12 +650,12 @@ int reparent(Ecma119Node *child, Ecma119Node *parent) /* keep track of the real parent */ child->info.dir.real_parent = child->parent; - + /* add the child to its new parent */ child->parent = parent; parent->info.dir.nchildren++; - parent->info.dir.children = realloc( parent->info.dir.children, - sizeof(void*) * parent->info.dir.nchildren ); + parent->info.dir.children = realloc(parent->info.dir.children, + sizeof(void*) * parent->info.dir.nchildren); parent->info.dir.children[parent->info.dir.nchildren - 1] = child; return ISO_SUCCESS; } @@ -677,7 +675,7 @@ int reparent(Ecma119Node *child, Ecma119Node *parent) * @return * 1 success, < 0 error */ -static +static int reorder_tree(Ecma119Image *img, Ecma119Node *dir, int level, int pathlen) { int ret; @@ -690,7 +688,7 @@ int reorder_tree(Ecma119Image *img, Ecma119Node *dir, int level, int pathlen) if (ret < 0) { return ret; } - + /* * we are appended to the root's children now, so there is no * need to recurse (the root will hit us again) @@ -716,7 +714,7 @@ int ecma119_tree_create(Ecma119Image *img) { int ret; Ecma119Node *root; - + ret = create_tree(img, (IsoNode*)img->image->root, &root, 1, 0); if (ret <= 0) { if (ret == 0) { @@ -726,24 +724,24 @@ int ecma119_tree_create(Ecma119Image *img) return ret; } img->root = root; - + iso_msg_debug(img->image, "Sorting the low level tree..."); sort_tree(root); - + iso_msg_debug(img->image, "Mangling names..."); ret = mangle_tree(img, 1); if (ret < 0) { return ret; } - + if (img->rockridge && !img->allow_deep_paths) { - + /* reorder the tree, acording to RRIP, 4.1.5 */ ret = reorder_tree(img, img->root, 1, 0); if (ret < 0) { return ret; } - + /* * and we need to remangle the root directory, as the function * above could insert new directories into the root. @@ -754,6 +752,6 @@ int ecma119_tree_create(Ecma119Image *img) return ret; } } - + return ISO_SUCCESS; } diff --git a/src/ecma119_tree.h b/src/ecma119_tree.h index d1a34d4..032fe68 100644 --- a/src/ecma119_tree.h +++ b/src/ecma119_tree.h @@ -23,22 +23,23 @@ enum ecma119_node_type { /** * 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 */ size_t block; size_t nchildren; Ecma119Node **children; - + /* * Size of the dir, i.e., sum of the lengths of all directory records. * It is computed by calc_dir_size() [ecma119.c]. * 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 * than fit in the directory records System Use Field. - */ + */ size_t len; - + /** * 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 */ char *iso_name; - + Ecma119Node *parent; - + IsoNode *node; /*< reference to the iso node */ - + // TODO add true support for this ino_t ino; nlink_t nlink; - + /**< file, symlink, special, directory or placeholder */ - enum ecma119_node_type type; - union { + enum ecma119_node_type type; + union + { IsoFileSrc *file; // TODO this wastes too much memory, as dirs have much more // atts than other kind of files. Replace with a pointer. struct ecma119_dir_info dir; /** this field points to the relocated directory. */ - Ecma119Node *real_me; + Ecma119Node *real_me; } info; }; diff --git a/src/filesrc.c b/src/filesrc.c index 39b8a06..b20e48c 100644 --- a/src/filesrc.c +++ b/src/filesrc.c @@ -23,15 +23,15 @@ int iso_file_src_cmp(const void *n1, const void *n2) unsigned int fs_id1, fs_id2; dev_t dev_id1, dev_id2; ino_t ino_id1, ino_id2; - + f1 = (const IsoFileSrc *)n1; f2 = (const IsoFileSrc *)n2; - + 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); - + //TODO take care about res <= 0 - + if (fs_id1 < fs_id2) { return -1; } else if (fs_id1 > fs_id2) { @@ -44,8 +44,7 @@ int iso_file_src_cmp(const void *n1, const void *n2) return 1; } else { /* files belong to same device in same fs */ - return (ino_id1 < ino_id2) ? -1 : - (ino_id1 > ino_id2) ? 1 : 0; + return (ino_id1 < ino_id2) ? -1 : (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; dev_t dev_id; ino_t ino_id; - + if (img == NULL || file == NULL || src == NULL) { return ISO_NULL_POINTER; } - + res = iso_stream_get_id(file->stream, &fs_id, &dev_id, &ino_id); if (res < 0) { return res; @@ -73,18 +72,18 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src) return ISO_ERROR; } else { int ret; - + fsrc = malloc(sizeof(IsoFileSrc)); if (fsrc == NULL) { return ISO_MEM_ERROR; } - + /* fill key and other atts */ fsrc->prev_img = file->msblock ? 1 : 0; fsrc->block = file->msblock; fsrc->sort_weight = file->sort_weight; fsrc->stream = file->stream; - + /* insert the filesrc in the tree */ ret = iso_rbtree_insert(img->files, fsrc, (void**)src); if (ret <= 0) { @@ -105,8 +104,7 @@ off_t iso_file_src_get_size(IsoFileSrc *file) return iso_stream_get_size(file->stream); } -static int -cmp_by_weight(const void *f1, const void *f2) +static int cmp_by_weight(const void *f1, const void *f2) { IsoFileSrc *f = *((IsoFileSrc**)f1); IsoFileSrc *g = *((IsoFileSrc**)f2); @@ -120,33 +118,33 @@ int filesrc_writer_compute_data_blocks(IsoImageWriter *writer) size_t i, size; Ecma119Image *t; IsoFileSrc **filelist; - + if (writer == NULL) { return ISO_MEM_ERROR; } - + t = writer->target; - + /* store the filesrcs in a array */ filelist = (IsoFileSrc**)iso_rbtree_to_array(t->files); if (filelist == NULL) { return ISO_MEM_ERROR; } - + size = iso_rbtree_get_size(t->files); - - /* sort files by weight, if needed */ + + /* sort files by weight, if needed */ 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 */ for (i = 0; i < size; ++i) { IsoFileSrc *file = filelist[i]; file->block = t->curblock; t->curblock += div_up(iso_file_src_get_size(file), BLOCK_SIZE); } - + /* the list is only needed by this writer, store locally */ writer->data = filelist; return ISO_SUCCESS; @@ -176,25 +174,25 @@ int filesrc_close(IsoFileSrc *file) * @return * 1 ok, 0 EOF, < 0 error */ -static +static int filesrc_read(IsoFileSrc *file, char *buf, size_t count) { size_t bytes = 0; - + /* loop to ensure the full buffer is filled */ do { ssize_t result; result = iso_stream_read(file->stream, buf + bytes, count - bytes); - if (result < 0) { - /* fill buffer with 0s and return */ + if (result < 0) { + /* fill buffer with 0s and return */ memset(buf + bytes, 0, count - bytes); return result; } if (result == 0) break; - bytes += result; + bytes += result; } while (bytes < count); - + if (bytes < count) { /* eof */ memset(buf + bytes, 0, count - bytes); @@ -212,16 +210,16 @@ int filesrc_writer_write_data(IsoImageWriter *writer) Ecma119Image *t; IsoFileSrc **filelist; char buffer[BLOCK_SIZE]; - + if (writer == NULL) { return ISO_MEM_ERROR; } - + t = writer->target; filelist = writer->data; - + iso_msg_debug(t->image, "Writing Files..."); - + nfiles = iso_rbtree_get_size(t->files); for (i = 0; i < nfiles; ++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 * 0's to image */ - // TODO Stream needs a get_path function - iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE, - "File XXX can't be openned. Filling with 0s."); - memset(buffer, 0, BLOCK_SIZE); - for (b = 0; b < nblocks; ++b) { + // TODO Stream needs a get_path function + iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE, + "File XXX can't be openned. Filling with 0s."); + memset(buffer, 0, BLOCK_SIZE); + for (b = 0; b < nblocks; ++b) { res = iso_write(t, buffer, BLOCK_SIZE); if (res < 0) { /* ko, writer error, we need to go out! */ return res; } - } - continue; + } + continue; } - + /* write file contents to image */ for (b = 0; b < nblocks; ++b) { int wres; @@ -263,16 +261,16 @@ int filesrc_writer_write_data(IsoImageWriter *writer) return wres; } } - + if (b < nblocks) { /* premature end of file, due to error or eof */ if (res < 0) { /* error */ - iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE, + iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE, "Read error in file XXXXX."); } else { /* eof */ - iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE, + iso_msg_sorry(t->image, LIBISO_FILE_CANT_WRITE, "Premature end of file XXXXX."); } /* fill with 0s */ @@ -286,10 +284,10 @@ int filesrc_writer_write_data(IsoImageWriter *writer) } } } - + filesrc_close(file); } - + return ISO_SUCCESS; } @@ -304,19 +302,19 @@ int filesrc_writer_free_data(IsoImageWriter *writer) int iso_file_src_writer_create(Ecma119Image *target) { IsoImageWriter *writer; - + writer = malloc(sizeof(IsoImageWriter)); if (writer == NULL) { return ISO_MEM_ERROR; } - + writer->compute_data_blocks = filesrc_writer_compute_data_blocks; writer->write_vol_desc = filesrc_writer_write_vol_desc; writer->write_data = filesrc_writer_write_data; writer->free_data = filesrc_writer_free_data; writer->data = NULL; writer->target = target; - + /* add this writer to image */ target->writers[target->nwriters++] = writer; diff --git a/src/filesrc.h b/src/filesrc.h index 46425c6..82c69e2 100644 --- a/src/filesrc.h +++ b/src/filesrc.h @@ -14,8 +14,9 @@ #include -struct Iso_File_Src { - unsigned int prev_img:1; /**< if the file comes from a previous image */ +struct Iso_File_Src +{ + 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 */ int sort_weight; IsoStream *stream; diff --git a/src/fs_local.c b/src/fs_local.c index 9adfa9f..9bd580a 100644 --- a/src/fs_local.c +++ b/src/fs_local.c @@ -6,7 +6,6 @@ * published by the Free Software Foundation. See COPYING file for details. */ - /* * 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. */ -IsoFilesystem *lfs = NULL; +IsoFilesystem *lfs= NULL; typedef struct { /* IsoFilesystem *fs; It seems not needed */ char *path; - unsigned int openned:2; /* 0: not openned, 1: file, 2:dir */ - union { + unsigned int openned :2; /* 0: not openned, 1: file, 2:dir */ + union + { int fd; DIR *dir; } info; @@ -59,10 +59,10 @@ char* lfs_get_name(IsoFileSource *src) data = src->data; p = strdup(data->path); /* because basename() might modify its arg */ name = strdup(basename(p)); - free(p); + free(p); return name; } - + static int lfs_lstat(IsoFileSource *src, struct stat *info) { @@ -77,7 +77,7 @@ int lfs_lstat(IsoFileSource *src, struct stat *info) int err; /* error, choose an appropriate return code */ - switch(errno) { + switch (errno) { case EACCES: err = ISO_FILE_ACCESS_DENIED; break; @@ -101,7 +101,7 @@ int lfs_lstat(IsoFileSource *src, struct stat *info) } return ISO_SUCCESS; } - + static int lfs_stat(IsoFileSource *src, struct stat *info) { @@ -116,7 +116,7 @@ int lfs_stat(IsoFileSource *src, struct stat *info) int err; /* error, choose an appropriate return code */ - switch(errno) { + switch (errno) { case EACCES: err = ISO_FILE_ACCESS_DENIED; break; @@ -176,7 +176,7 @@ int lfs_open(IsoFileSource *src) * parsed in the lstat call above */ if (data->openned == 0) { - switch(errno) { + switch (errno) { case EACCES: err = ISO_FILE_ACCESS_DENIED; break; @@ -205,7 +205,7 @@ int lfs_close(IsoFileSource *src) } data = src->data; - switch(data->openned) { + switch (data->openned) { case 1: /* not dir */ ret = close(data->info.fd) == 0 ? ISO_SUCCESS : ISO_FILE_ERROR; break; @@ -232,14 +232,14 @@ int lfs_read(IsoFileSource *src, void *buf, size_t count) } data = src->data; - switch(data->openned) { + switch (data->openned) { case 1: /* not dir */ { int ret; ret = read(data->info.fd, buf, count); if (ret < 0) { /* error on read */ - switch(errno) { + switch (errno) { case EINTR: ret = ISO_INTERRUPTED; break; @@ -273,7 +273,7 @@ int lfs_readdir(IsoFileSource *src, IsoFileSource **child) } data = src->data; - switch(data->openned) { + switch (data->openned) { case 1: /* not dir */ return ISO_FILE_IS_NOT_DIR; case 2: /* directory */ @@ -292,7 +292,7 @@ int lfs_readdir(IsoFileSource *src, IsoFileSource **child) else return 0; /* EOF */ } - if (strcmp(entry->d_name,".") && strcmp(entry->d_name,"..")) { + if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) { break; } } @@ -342,7 +342,7 @@ int lfs_readlink(IsoFileSource *src, char *buf, size_t bufsiz) size = readlink(data->path, buf, bufsiz - 1); if (size < 0) { /* error */ - switch(errno) { + switch (errno) { case EACCES: return ISO_FILE_ACCESS_DENIED; case ENOTDIR: @@ -389,7 +389,7 @@ void lfs_free(IsoFileSource *src) iso_filesystem_unref(lfs); } -IsoFileSourceIface lfs_class = { +IsoFileSourceIface lfs_class = { lfs_get_path, lfs_get_name, lfs_lstat, @@ -450,7 +450,7 @@ int iso_file_source_new_lfs(const char *path, IsoFileSource **src) lfs_src->refcount = 1; lfs_src->data = data; lfs_src->class = &lfs_class; - + /* take a ref to local filesystem */ iso_filesystem_ref(lfs); @@ -462,19 +462,19 @@ int iso_file_source_new_lfs(const char *path, IsoFileSource **src) static int lfs_get_root(IsoFilesystem *fs, IsoFileSource **root) { - if (fs == NULL || root == NULL) { + if (fs == NULL || root == NULL) { return ISO_NULL_POINTER; } - return iso_file_source_new_lfs("/", root); + return iso_file_source_new_lfs("/", root); } static 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_file_source_new_lfs(path, file); + return iso_file_source_new_lfs(path, file); } static @@ -486,25 +486,25 @@ unsigned int lfs_get_id(IsoFilesystem *fs) static void lfs_fs_free(IsoFilesystem *fs) { - lfs = NULL; + lfs = NULL; } - + int iso_local_filesystem_new(IsoFilesystem **fs) { - if (fs == NULL) { + if (fs == NULL) { return ISO_NULL_POINTER; } - + if (lfs != NULL) { /* just take a new ref */ iso_filesystem_ref(lfs); } else { - - lfs = malloc(sizeof(IsoFilesystem)); + + lfs = malloc(sizeof(IsoFilesystem)); if (lfs == NULL) { return ISO_OUT_OF_MEM; } - + /* fill struct */ lfs->refcount = 1; 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->free = lfs_fs_free; } - *fs = lfs; - return ISO_SUCCESS; + *fs = lfs; + return ISO_SUCCESS; } diff --git a/src/fsource.c b/src/fsource.c index 0c62830..d12537b 100644 --- a/src/fsource.c +++ b/src/fsource.c @@ -16,26 +16,26 @@ unsigned int iso_fs_global_id = 100; void iso_file_source_ref(IsoFileSource *src) { - ++src->refcount; + ++src->refcount; } void iso_file_source_unref(IsoFileSource *src) { - if (--src->refcount == 0) { - src->class->free(src); - free(src); - } + if (--src->refcount == 0) { + src->class->free(src); + free(src); + } } void iso_filesystem_ref(IsoFilesystem *fs) { - ++fs->refcount; + ++fs->refcount; } void iso_filesystem_unref(IsoFilesystem *fs) { - if (--fs->refcount == 0) { - fs->free(fs); - free(fs); - } + if (--fs->refcount == 0) { + fs->free(fs); + free(fs); + } } diff --git a/src/fsource.h b/src/fsource.h index 119fc4d..c596551 100644 --- a/src/fsource.h +++ b/src/fsource.h @@ -14,8 +14,7 @@ */ /* - * Some functions here will be moved to libisofs.h when we expose - * Sources. + * Some functions here will be moved to libisofs.h when we expose Sources. */ #include @@ -43,9 +42,9 @@ struct Iso_Filesystem * @return * 1 success, < 0 error */ - int (*get_by_path)(IsoFilesystem *fs, const char *path, + int (*get_by_path)(IsoFilesystem *fs, const char *path, IsoFileSource **file); - + /** * Get filesystem identifier. * @@ -81,7 +80,7 @@ typedef struct IsoFileSource_Iface * freed by the user. */ const char* (*get_path)(IsoFileSource *src); - + /** * Get the name of the file, with the dir component of the path. * @@ -103,7 +102,7 @@ typedef struct IsoFileSource_Iface * ISO_NULL_POINTER */ int (*lstat)(IsoFileSource *src, struct stat *info); - + /** * Get information about the file. If the file is a symlink, the info * returned refers to the destination. @@ -211,7 +210,7 @@ typedef struct IsoFileSource_Iface * */ int (*readlink)(IsoFileSource *src, char *buf, size_t bufsiz); - + /** * Get the filesystem for this source. No extra ref is added, so you * musn't unref the IsoFilesystem. @@ -233,7 +232,8 @@ typedef struct IsoFileSource_Iface */ } IsoFileSourceIface; -struct Iso_File_Source { +struct Iso_File_Source +{ const IsoFileSourceIface *class; int refcount; void *data; @@ -245,54 +245,63 @@ void iso_file_source_unref(IsoFileSource *src); /* * this are just helpers to invoque methods in class */ -extern inline -const char* iso_file_source_get_path(IsoFileSource *src) { +extern inline +const char* iso_file_source_get_path(IsoFileSource *src) +{ return src->class->get_path(src); } -extern inline -char* iso_file_source_get_name(IsoFileSource *src) { +extern inline +char* iso_file_source_get_name(IsoFileSource *src) +{ return src->class->get_name(src); } -extern inline -int iso_file_source_lstat(IsoFileSource *src, struct stat *info) { +extern inline +int iso_file_source_lstat(IsoFileSource *src, struct stat *info) +{ return src->class->lstat(src, info); } -extern inline -int iso_file_source_stat(IsoFileSource *src, struct stat *info) { +extern inline +int iso_file_source_stat(IsoFileSource *src, struct stat *info) +{ return src->class->stat(src, info); } -extern inline -int iso_file_source_open(IsoFileSource *src) { +extern inline +int iso_file_source_open(IsoFileSource *src) +{ return src->class->open(src); } -extern inline -int iso_file_source_close(IsoFileSource *src) { +extern inline +int iso_file_source_close(IsoFileSource *src) +{ return src->class->close(src); } -extern inline -int iso_file_source_read(IsoFileSource *src, void *buf, size_t count) { +extern inline +int iso_file_source_read(IsoFileSource *src, void *buf, size_t count) +{ return src->class->read(src, buf, count); } -extern inline +extern inline int iso_file_source_readdir(IsoFileSource *src, IsoFileSource **child) { return src->class->readdir(src, child); } -extern inline -int iso_file_source_readlink(IsoFileSource *src, char *buf, size_t bufsiz) { +extern inline +int iso_file_source_readlink(IsoFileSource *src, char *buf, size_t bufsiz) +{ return src->class->readlink(src, buf, bufsiz); } -extern inline -IsoFilesystem* iso_file_source_get_filesystem(IsoFileSource *src) { +extern inline +IsoFilesystem* iso_file_source_get_filesystem(IsoFileSource *src) +{ return src->class->get_filesystem(src); } diff --git a/src/image.c b/src/image.c index 7f0bc6b..3e75cc9 100644 --- a/src/image.c +++ b/src/image.c @@ -31,23 +31,23 @@ int iso_image_new(const char *name, IsoImage **image) { int res; IsoImage *img; - + if (image == NULL) { return ISO_NULL_POINTER; } - + img = calloc(1, sizeof(IsoImage)); if (img == NULL) { return ISO_MEM_ERROR; } - + /* local filesystem will be used by default */ res = iso_local_filesystem_new(&(img->fs)); if (res < 0) { free(img); return ISO_MEM_ERROR; } - + /* use basic builder as default */ res = iso_node_basic_builder_new(&(img->builder)); if (res < 0) { @@ -55,7 +55,7 @@ int iso_image_new(const char *name, IsoImage **image) free(img); return ISO_MEM_ERROR; } - + /* create message messenger */ res = libiso_msgs_new(&img->messenger, 0); if (res <= 0) { @@ -64,9 +64,9 @@ int iso_image_new(const char *name, IsoImage **image) free(img); 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); - + /* fill image fields */ res = iso_node_new_root(&img->root); if (res < 0) { @@ -77,7 +77,7 @@ int iso_image_new(const char *name, IsoImage **image) return res; } img->refcount = 1; - img->recOpts = calloc(1,sizeof(IsoImageRecOpts)); + img->recOpts = calloc(1, sizeof(IsoImageRecOpts)); if (img->recOpts == NULL) { libiso_msgs_destroy(&img->messenger, 0); iso_node_builder_unref(img->builder); @@ -86,7 +86,7 @@ int iso_image_new(const char *name, IsoImage **image) free(img); return ISO_MEM_ERROR; } - + if (name != NULL) { img->volset_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, - const char *data_preparer_id) + const char *data_preparer_id) { free(image->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, - const char *copyright_file_id) + const char *copyright_file_id) { free(image->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, - const char *abstract_file_id) + const char *abstract_file_id) { free(image->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; } -void iso_image_set_biblio_file_id(IsoImage *image, - const char *biblio_file_id) +void iso_image_set_biblio_file_id(IsoImage *image, const char *biblio_file_id) { free(image->biblio_file_id); image->biblio_file_id = strdup(biblio_file_id); diff --git a/src/image.h b/src/image.h index 305d862..e2c36ba 100644 --- a/src/image.h +++ b/src/image.h @@ -21,39 +21,40 @@ * (Usefull, for example, in Multiple-Document-Interface GUI apps. * [The stuff we have in init belongs really to image!] */ - + typedef struct Iso_Image_Rec_Opts IsoImageRecOpts; -struct Iso_Image { - +struct Iso_Image +{ + int refcount; - + IsoDir *root; - + char *volset_id; - - char *volume_id; /**< Volume identifier. */ - char *publisher_id; /**< Volume publisher. */ + + char *volume_id; /**< Volume identifier. */ + char *publisher_id; /**< Volume publisher. */ char *data_preparer_id; /**< Volume data preparer. */ - char *system_id; /**< Volume system identifier. */ - char *application_id; /**< Volume application id */ + char *system_id; /**< Volume system identifier. */ + char *application_id; /**< Volume application id */ char *copyright_file_id; char *abstract_file_id; char *biblio_file_id; - + /* message messenger for the image */ struct libiso_msgs *messenger; - + /** * Default filesystem to use when adding files to the image tree. */ IsoFilesystem *fs; - + /* * Default builder to use when adding files to the image tree. */ IsoNodeBuilder *builder; - + /** * Options for recursive directory addition */ @@ -63,30 +64,31 @@ struct Iso_Image { /** * 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 */ unsigned int follow_symlinks; - + /** * Whether to skip hidden files */ unsigned int ignore_hidden; - + /** * Whether to stop on an error. Some errors, such as memory errors, * always cause a stop */ unsigned int stop_on_error; - + /** * Files to exclude * TODO add wildcard support */ char** excludes; - + /** * if the dir already contains a node with the same name, whether to * 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?) */ int replace; - + /** * 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. diff --git a/src/libisofs.h b/src/libisofs.h index 950c69b..f4bd69e 100644 --- a/src/libisofs.h +++ b/src/libisofs.h @@ -58,28 +58,29 @@ enum IsoHideNodeFlag { /** * Holds the options for the image generation. */ -typedef struct { - int level; /**< ISO level to write at. */ +typedef struct +{ + int level; /**< ISO level to write at. */ /** Which extensions to support. */ - unsigned int rockridge:1; - + unsigned int rockridge :1; + /* relaxed constraints */ - unsigned int omit_version_numbers:1; - unsigned int allow_deep_paths:1; + unsigned int omit_version_numbers :1; + unsigned int allow_deep_paths :1; //int relaxed_constraints; /**< see ecma119_relaxed_constraints_flag */ - + //unsigned int copy_eltorito:1; - /**< - * In multisession discs, select whether to copy el-torito catalog - * and boot image. Copy is needed for isolinux images, that need to - * be patched. However, it can lead to problems when the image is - * not present in the iso filesystem, because we can't figure out - * its size. In those cases, we only copy 1 block of data. - */ - + /**< + * In multisession discs, select whether to copy el-torito catalog + * and boot image. Copy is needed for isolinux images, that need to + * be patched. However, it can lead to problems when the image is + * not present in the iso filesystem, because we can't figure out + * its size. In those cases, we only copy 1 block of data. + */ + /**< 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 @@ -92,10 +93,10 @@ typedef struct { * below. Note that for mode attributes, only the permissions are set, the * file type remains unchanged. */ - unsigned int replace_dir_mode:2; - unsigned int replace_file_mode:2; - unsigned int replace_uid:2; - unsigned int replace_gid:2; + unsigned int replace_dir_mode :2; + unsigned int replace_file_mode :2; + unsigned int replace_uid :2; + unsigned int replace_gid :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. */ @@ -103,35 +104,35 @@ typedef struct { gid_t gid; /** gid to use when replace_gid == 2. */ char *output_charset; /**< NULL to use default charset */ -// uint32_t ms_block; - /**< - * Start block for multisession. When this is greater than 0, - * it's suppossed to be the lba of the next writable address - * on disc; all block lba on image will take this into account, - * and files from a previous session will not be written on - * image. This behavior is only suitable for images to be - * appended to a multisession disc. - * When this is 0, no multisession image will be created. If - * some files are taken from a previous image, its contents - * will be written again to the new image. Use this with new - * images or if you plan to modify an existin image. - */ -// struct data_source* src; -// /**< -// * When modifying a image, this is the source of the original -// * image, used to read file contents. -// * Otherwise it can be NULL. -// */ -// uint8_t *overwrite; -// /**< -// * When not NULL, it should point to a buffer of at least -// * 64KiB, where libisofs will write the contents that should -// * be written at the beginning of a overwriteable media, to -// * grow the image. -// * You shoudl initialize the buffer either with 0s, or with -// * the contents of the first blocks of the image you're -// * growing. In most cases, 0 is good enought. -// */ + // uint32_t ms_block; + /**< + * Start block for multisession. When this is greater than 0, + * it's suppossed to be the lba of the next writable address + * on disc; all block lba on image will take this into account, + * and files from a previous session will not be written on + * image. This behavior is only suitable for images to be + * appended to a multisession disc. + * When this is 0, no multisession image will be created. If + * some files are taken from a previous image, its contents + * will be written again to the new image. Use this with new + * images or if you plan to modify an existin image. + */ + // struct data_source* src; + // /**< + // * When modifying a image, this is the source of the original + // * image, used to read file contents. + // * Otherwise it can be NULL. + // */ + // uint8_t *overwrite; + // /**< + // * When not NULL, it should point to a buffer of at least + // * 64KiB, where libisofs will write the contents that should + // * be written at the beginning of a overwriteable media, to + // * grow the image. + // * You shoudl initialize the buffer either with 0s, or with + // * the contents of the first blocks of the image you're + // * growing. In most cases, 0 is good enought. + // */ } Ecma119WriteOpts; /** @@ -210,7 +211,7 @@ const char *iso_image_get_publisher_id(const IsoImage *image); * Fill in the data preparer for a 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. @@ -248,7 +249,7 @@ const char *iso_image_get_application_id(const IsoImage *image); * to a file on disc. Up to 37 characters. */ 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. @@ -262,7 +263,7 @@ const char *iso_image_get_copyright_file_id(const IsoImage *image); * to a file on disc. Up to 37 characters. */ 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. @@ -275,8 +276,7 @@ const char *iso_image_get_abstract_file_id(const IsoImage *image); * Fill biblio information for the image. Usually this refers * to a file on disc. Up to 37 characters. */ -void iso_image_set_biblio_file_id(IsoImage *image, - const char *biblio_file_id); +void iso_image_set_biblio_file_id(IsoImage *image, const char *biblio_file_id); /** * 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); /* -TODO #00007 expose Strem and thi function: -int iso_tree_add_new_file(IsoDir *parent, const char *name, stream, file) -*/ + TODO #00007 expose Strem and thi function: + 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, @@ -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_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); /** @@ -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_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); /** @@ -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_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); /** @@ -808,7 +808,7 @@ int iso_tree_path_to_node(IsoImage *image, const char *path, IsoNode **node); * @return >0 for success, <=0 for error */ 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 * least the given minimum_severity. This message and any older message of diff --git a/src/messages.c b/src/messages.c index 3b4886c..5c63397 100644 --- a/src/messages.c +++ b/src/messages.c @@ -20,81 +20,78 @@ void iso_msg_debug(IsoImage *img, const char *fmt, ...) { char msg[MAX_MSG_LEN]; va_list ap; - + va_start(ap, fmt); vsnprintf(msg, MAX_MSG_LEN, fmt, 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); } 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_start(ap, fmt); vsnprintf(msg, MAX_MSG_LEN, fmt, ap); va_end(ap); - + libiso_msgs_submit(img->messenger, -1, error_code, LIBISO_MSGS_SEV_NOTE, LIBISO_MSGS_PRIO_MEDIUM, msg, 0, 0); } 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_start(ap, fmt); vsnprintf(msg, MAX_MSG_LEN, fmt, ap); va_end(ap); - + libiso_msgs_submit(img->messenger, -1, error_code, LIBISO_MSGS_SEV_HINT, LIBISO_MSGS_PRIO_MEDIUM, msg, 0, 0); } 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_start(ap, fmt); vsnprintf(msg, MAX_MSG_LEN, fmt, ap); va_end(ap); - - libiso_msgs_submit(img->messenger, -1, error_code, - LIBISO_MSGS_SEV_WARNING, LIBISO_MSGS_PRIO_MEDIUM, - msg, 0, 0); + + libiso_msgs_submit(img->messenger, -1, error_code, LIBISO_MSGS_SEV_WARNING, + LIBISO_MSGS_PRIO_MEDIUM, msg, 0, 0); } 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_start(ap, fmt); vsnprintf(msg, MAX_MSG_LEN, fmt, ap); va_end(ap); - - libiso_msgs_submit(img->messenger, -1, error_code, - LIBISO_MSGS_SEV_SORRY, LIBISO_MSGS_PRIO_HIGH, - msg, 0, 0); + + libiso_msgs_submit(img->messenger, -1, error_code, LIBISO_MSGS_SEV_SORRY, + LIBISO_MSGS_PRIO_HIGH, msg, 0, 0); } 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_start(ap, fmt); vsnprintf(msg, MAX_MSG_LEN, fmt, ap); va_end(ap); - - libiso_msgs_submit(img->messenger, -1, error_code, - LIBISO_MSGS_SEV_FATAL, LIBISO_MSGS_PRIO_HIGH, - msg, 0, 0); + + libiso_msgs_submit(img->messenger, -1, error_code, LIBISO_MSGS_SEV_FATAL, + LIBISO_MSGS_PRIO_HIGH, 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, 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); - if (ret <= 0) - return 0; - ret = libiso_msgs__text_to_sev(print_severity, &print_sevno, 0); - if (ret <= 0) - return 0; - ret = libiso_msgs_set_severities(img->messenger, queue_sevno, - print_sevno, print_id, 0); - if (ret <= 0) - return 0; - return 1; + ret = libiso_msgs__text_to_sev(queue_severity, &queue_sevno, 0); + if (ret <= 0) + return 0; + ret = libiso_msgs__text_to_sev(print_severity, &print_sevno, 0); + if (ret <= 0) + return 0; + ret = libiso_msgs_set_severities(img->messenger, queue_sevno, print_sevno, + print_id, 0); + if (ret <= 0) + return 0; + return 1; } #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 */ int iso_image_obtain_msgs(IsoImage *img, char *minimum_severity, - int *error_code, char msg_text[], int *os_errno, - char severity[]) + int *error_code, char msg_text[], int *os_errno, + char severity[]) { - int ret, minimum_sevno, sevno, priority; - char *textpt, *sev_name; - struct libiso_msgs_item *item = NULL; + int ret, minimum_sevno, sevno, priority; + char *textpt, *sev_name; + struct libiso_msgs_item *item= NULL; - if (img == NULL) - return 0; + if (img == NULL) + return 0; - ret = libiso_msgs__text_to_sev(minimum_severity, &minimum_sevno, 0); - if (ret <= 0) - return 0; - ret = libiso_msgs_obtain(img->messenger, &item, minimum_sevno, - LIBISO_MSGS_PRIO_ZERO, 0); - if (ret <= 0) - goto ex; - ret = libiso_msgs_item_get_msg(item, error_code, &textpt, os_errno, 0); - if (ret <= 0) - goto ex; - strncpy(msg_text, textpt, ISO_MSGS_MESSAGE_LEN-1); - if(strlen(textpt) >= ISO_MSGS_MESSAGE_LEN) - msg_text[ISO_MSGS_MESSAGE_LEN-1] = 0; + ret = libiso_msgs__text_to_sev(minimum_severity, &minimum_sevno, 0); + if (ret <= 0) + return 0; + ret = libiso_msgs_obtain(img->messenger, &item, minimum_sevno, + LIBISO_MSGS_PRIO_ZERO, 0); + if (ret <= 0) + goto ex; + ret = libiso_msgs_item_get_msg(item, error_code, &textpt, os_errno, 0); + if (ret <= 0) + goto ex; + strncpy(msg_text, textpt, ISO_MSGS_MESSAGE_LEN-1); + if (strlen(textpt) >= ISO_MSGS_MESSAGE_LEN) + msg_text[ISO_MSGS_MESSAGE_LEN-1] = 0; - severity[0]= 0; - ret = libiso_msgs_item_get_rank(item, &sevno, &priority, 0); - if(ret <= 0) - goto ex; - ret = libiso_msgs__sev_to_text(sevno, &sev_name, 0); - if(ret <= 0) - goto ex; - strcpy(severity,sev_name); + severity[0]= 0; + ret = libiso_msgs_item_get_rank(item, &sevno, &priority, 0); + if (ret <= 0) + goto ex; + ret = libiso_msgs__sev_to_text(sevno, &sev_name, 0); + if (ret <= 0) + goto ex; + strcpy(severity, sev_name); - ret = 1; -ex: - libiso_msgs_destroy_item(img->messenger, &item, 0); - return ret; + ret = 1; + ex: ; + libiso_msgs_destroy_item(img->messenger, &item, 0); + return ret; } void *iso_image_get_messenger(IsoImage *img) { - return img->messenger; + return img->messenger; } diff --git a/src/messages.h b/src/messages.h index 150f59b..31a38e6 100644 --- a/src/messages.h +++ b/src/messages.h @@ -47,11 +47,11 @@ /** Can't read previous image file */ #define LIBISO_CANT_READ_IMG 0x00031003 -/* Unsupported SUSP entry */ +/* Unsupported SUSP entry */ #define LIBISO_SUSP_UNHANLED 0x00030101 /* Wrong SUSP entry, that cause RR to be ignored */ #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 /** Unsupported RR feature. */ #define LIBISO_RR_UNSUPPORTED 0x00030111 diff --git a/src/node.c b/src/node.c index 4a3355b..06cc999 100644 --- a/src/node.c +++ b/src/node.c @@ -31,7 +31,7 @@ void iso_node_ref(IsoNode *node) void iso_node_unref(IsoNode *node) { if (--node->refcount == 0) { - switch(node->type) { + switch (node->type) { case LIBISO_DIR: { IsoNode *child = ((IsoDir*)node)->children; @@ -56,7 +56,7 @@ void iso_node_unref(IsoNode *node) } default: /* TODO #00002 handle deletion of each kind of node */ - break; + break; } free(node->name); free(node); @@ -79,12 +79,12 @@ enum IsoNodeType iso_node_get_type(IsoNode *node) int iso_node_set_name(IsoNode *node, const char *name) { char *new; - + /* guard against the empty string or big names... */ if (name[0] == '\0' || strlen(name) > 255) { return ISO_WRONG_ARG_VALUE; } - + /* ...against "." and ".." names... */ if (!strcmp(name, ".") || !strcmp(name, "..")) { 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 */ return ISO_WRONG_ARG_VALUE; } - + new = strdup(name); if (new == NULL) { return ISO_MEM_ERROR; @@ -124,7 +124,7 @@ int iso_node_set_name(IsoNode *node, const char *name) return res; } } - return ISO_SUCCESS; + return ISO_SUCCESS; } /** @@ -168,7 +168,6 @@ mode_t iso_node_get_mode(const IsoNode *node) return node->mode; } - /** * Set the user id for the node. This attribute is only useful when * 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) { IsoNode **pos; - + if (dir == NULL || child == NULL) { return ISO_NULL_POINTER; } if ((IsoNode*)dir == child) { return ISO_WRONG_ARG_VALUE; } - + /* * check if child is already added to another dir, or if child * 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) { return ISO_NODE_ALREADY_ADDED; } - + pos = &(dir->children); while (*pos != NULL && strcmp((*pos)->name, child->name) < 0) { pos = &((*pos)->next); @@ -311,11 +310,11 @@ int iso_dir_add_node(IsoDir *dir, IsoNode *child, int replace) return ISO_WRONG_ARG_VALUE; } } - + child->next = *pos; *pos = child; child->parent = dir; - + return ++dir->nchildren; } @@ -342,19 +341,19 @@ int iso_dir_get_node(IsoDir *dir, const char *name, IsoNode **node) if (dir == NULL || name == NULL) { return ISO_NULL_POINTER; } - + pos = dir->children; while (pos != NULL && strcmp(pos->name, name) < 0) { pos = pos->next; } - + if (pos == NULL || strcmp(pos->name, name)) { if (node) { *node = NULL; } return 0; /* node not found */ } - + if (node) { *node = pos; } @@ -380,7 +379,7 @@ int iso_dir_get_nchildren(IsoDir *dir) int iso_dir_get_children(const IsoDir *dir, IsoDirIter **iter) { IsoDirIter *it; - + if (dir == NULL || iter == NULL) { return ISO_NULL_POINTER; } @@ -388,10 +387,10 @@ int iso_dir_get_children(const IsoDir *dir, IsoDirIter **iter) if (it == NULL) { return ISO_OUT_OF_MEM; } - + it->dir = dir; it->pos = dir->children; - + *iter = it; return ISO_SUCCESS; } @@ -437,14 +436,13 @@ void iso_dir_iter_free(IsoDirIter *iter) free(iter); } -static IsoNode** -iso_dir_find_node(IsoDir *dir, IsoNode *node) +static IsoNode** iso_dir_find_node(IsoDir *dir, IsoNode *node) { IsoNode **pos; pos = &(dir->children); while (*pos != NULL && *pos != node) { pos = &((*pos)->next); - } + } return pos; } @@ -461,7 +459,7 @@ int iso_node_take(IsoNode *node) { IsoNode **pos; IsoDir* dir; - + if (node == NULL) { return ISO_NULL_POINTER; } @@ -507,7 +505,7 @@ int iso_dir_iter_take(IsoDirIter *iter) if (iter == NULL) { return ISO_NULL_POINTER; } - + pos = iter->dir->children; if (iter->pos == pos) { return ISO_ERROR; @@ -599,7 +597,7 @@ int iso_file_get_sort_weight(IsoFile *file) int iso_node_new_root(IsoDir **root) { IsoDir *dir; - + dir = calloc(1, sizeof(IsoDir)); if (dir == NULL) { return ISO_MEM_ERROR; @@ -608,7 +606,7 @@ int iso_node_new_root(IsoDir **root) dir->node.type = LIBISO_DIR; dir->node.atime = dir->node.ctime = dir->node.mtime = time(NULL); dir->node.mode = S_IFDIR | 0555; - + /* set parent to itself, to prevent root to be added to another dir */ dir->node.parent = dir; *root = dir; diff --git a/src/node.h b/src/node.h index 7b423d9..c79980c 100644 --- a/src/node.h +++ b/src/node.h @@ -34,21 +34,21 @@ struct Iso_Node */ int refcount; - /**< Type of the IsoNode, do not confuse with mode */ + /** Type of the IsoNode, do not confuse with mode */ enum IsoNodeType type; char *name; /**< Real name, in default charset */ mode_t mode; /**< protection */ - uid_t uid; /**< user ID of owner */ - gid_t gid; /**< group ID of owner */ + uid_t uid; /**< user ID of owner */ + gid_t gid; /**< group ID of owner */ /* TODO #00001 : consider adding new timestamps */ time_t atime; /**< time of last access */ time_t mtime; /**< time of last modification */ 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 */ @@ -69,16 +69,16 @@ struct Iso_Dir struct Iso_File { IsoNode node; - + /** * Location of a file extent in a ms disc, 0 for newly added file */ uint32_t msblock; - /** - * 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 - */ + /** + * 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 + */ int sort_weight; IsoStream *stream; }; @@ -86,7 +86,7 @@ struct Iso_File struct Iso_Symlink { IsoNode node; - + char *dest; }; diff --git a/src/rockridge.c b/src/rockridge.c index c806684..3f2f06f 100644 --- a/src/rockridge.c +++ b/src/rockridge.c @@ -20,8 +20,8 @@ static int susp_append(Ecma119Image *t, struct susp_info *susp, uint8_t *data) { susp->n_susp_fields++; - susp->susp_fields = realloc(susp->susp_fields, - sizeof(void*) * susp->n_susp_fields); + susp->susp_fields = realloc(susp->susp_fields, sizeof(void*) + * susp->n_susp_fields); if (susp->susp_fields == NULL) { return ISO_MEM_ERROR; } @@ -34,8 +34,8 @@ static int susp_append_ce(Ecma119Image *t, struct susp_info *susp, uint8_t *data) { susp->n_ce_susp_fields++; - susp->ce_susp_fields = realloc(susp->ce_susp_fields, - sizeof(void*) * susp->n_ce_susp_fields); + susp->ce_susp_fields = realloc(susp->ce_susp_fields, sizeof(void*) + * susp->n_ce_susp_fields); if (susp->ce_susp_fields == NULL) { 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[28], px_get_gid(t, n), 4); iso_bb(&PX[36], n->ino, 4); - + return susp_append(t, susp, PX); } @@ -142,12 +142,12 @@ static int rrip_add_PL(Ecma119Image *t, Ecma119Node *n, struct susp_info *susp) { uint8_t *PL; - + if (n->type != ECMA119_DIR || n->info.dir.real_parent == NULL) { /* should never occur */ return ISO_ERROR; } - + PL = malloc(12); if (PL == NULL) { return ISO_MEM_ERROR; @@ -157,7 +157,7 @@ int rrip_add_PL(Ecma119Image *t, Ecma119Node *n, struct susp_info *susp) PL[1] = 'L'; PL[2] = 12; PL[3] = 1; - + /* write the location of the real parent, already computed */ iso_bb(&PL[4], n->info.dir.real_parent->info.dir.block, 4); return susp_append(t, susp, PL); @@ -199,13 +199,13 @@ int rrip_add_PN(Ecma119Image *t, Ecma119Node *n, struct susp_info *susp) { IsoSpecial *node; uint8_t *PN; - + node = (IsoSpecial*)n->node; if (node->node.type != LIBISO_SPECIAL) { /* should never occur */ return ISO_ERROR; } - + PN = malloc(20); if (PN == NULL) { return ISO_MEM_ERROR; @@ -252,22 +252,22 @@ char *get_rr_name(Ecma119Image *t, Ecma119Node *n) { int ret; char *name; - + if (!strcmp(t->input_charset, t->output_charset)) { /* no conversion needed */ return strdup(n->node->name); } - + ret = strconv(n->node->name, t->input_charset, t->output_charset, &name); if (ret < 0) { - iso_msg_sorry(t->image, LIBISO_CHARSET_ERROR, - "Charset conversion error. Can't convert %s from %s to %s", - n->node->name, t->input_charset, t->output_charset); - + iso_msg_sorry(t->image, LIBISO_CHARSET_ERROR, + "Charset conversion error. Can't convert %s from %s to %s", + n->node->name, t->input_charset, t->output_charset); + /* use the original name, it's the best we can do */ name = strdup(n->node->name); } - + return name; } @@ -285,8 +285,8 @@ char *get_rr_name(Ecma119Image *t, Ecma119Node *n) * Whether to add or not to CE */ static -int rrip_add_NM(Ecma119Image *t, struct susp_info *susp, - char *name, int size, int flags, int ce) +int rrip_add_NM(Ecma119Image *t, struct susp_info *susp, char *name, int size, + int flags, int ce) { uint8_t *NM = malloc(size + 5); if (NM == NULL) { @@ -324,9 +324,8 @@ int rrip_add_NM(Ecma119Image *t, struct susp_info *susp, * @return * 1 on success, < 0 on error */ -static -int rrip_SL_append_comp(size_t *n, uint8_t ***comps, - char *s, int size, char fl) +static +int rrip_SL_append_comp(size_t *n, uint8_t ***comps, char *s, int size, char fl) { uint8_t *comp = malloc(size + 2); 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. */ static -int rrip_add_SL(Ecma119Image *t, struct susp_info *susp, - uint8_t **comp, size_t n, int ce) +int rrip_add_SL(Ecma119Image *t, struct susp_info *susp, uint8_t **comp, + size_t n, int ce) { int ret, i, j; @@ -374,7 +373,7 @@ int rrip_add_SL(Ecma119Image *t, struct susp_info *susp, uint8_t *SL; for (i = 0; i < n; i++) { - + total_comp_len += comp[i][1] + 2; if (total_comp_len > 250) { /* we need a new SL entry */ @@ -383,18 +382,18 @@ int rrip_add_SL(Ecma119Image *t, struct susp_info *susp, if (SL == NULL) { return ISO_MEM_ERROR; } - + SL[0] = 'S'; SL[1] = 'L'; SL[2] = total_comp_len + 5; SL[3] = 1; - SL[4] = 1; /* CONTINUE */ + SL[4] = 1; /* CONTINUE */ pos = 5; for (j = written; j < i; j++) { memcpy(&SL[pos], comp[j], comp[j][1] + 2); pos += comp[j][1] + 2; } - + /* * In this case we are sure we're writting to CE. Check for * debug purposes @@ -410,12 +409,12 @@ int rrip_add_SL(Ecma119Image *t, struct susp_info *susp, total_comp_len = comp[i][1] + 2; } } - + SL = malloc(total_comp_len + 5); if (SL == NULL) { return ISO_MEM_ERROR; } - + SL[0] = 'S'; SL[1] = 'L'; SL[2] = total_comp_len + 5; @@ -462,10 +461,10 @@ int rrip_add_ER(Ecma119Image *t, struct susp_info *susp) ER[7] = 1; memcpy(&ER[8], "IEEE_1282", 9); 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, " - "PISCATAWAY, NJ, USA FOR THE 1282 SPECIFICATION.", 93); - + "PISCATAWAY, NJ, USA FOR THE 1282 SPECIFICATION.", 93); + /** This always goes to continuation area */ 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[12], susp->ce_len, 4); iso_bb(&CE[20], ce_len, 4); - + return susp_append(t, susp, CE); } @@ -531,11 +530,11 @@ int susp_add_SP(Ecma119Image *t, struct susp_info *susp) * @return * 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 space, size_t *ce) +size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, size_t space, + size_t *ce) { size_t su_size; - + /* space min is 255 - 33 - 37 = 185 * 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 @@ -543,10 +542,10 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, */ space--; *ce = 0; - + /* PX and TF, we are sure they always fit in SUA */ su_size = 44 + 26; - + if (n->type == ECMA119_DIR) { if (n->info.dir.real_parent != NULL) { /* 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)) { /* block or char device, we need a PN entry */ su_size += 20; - } + } } else if (n->type == ECMA119_PLACEHOLDER) { /* we need the CL entry */ su_size += 12; } - + if (type == 0) { char *name = get_rr_name(t, n); size_t namelen = strlen(name); free(name); - + /* NM entry */ if (su_size + 5 + namelen <= space) { /* 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; size_t sl_len = 5; int cew = (*ce != 0); /* are we writing to CE? */ - + prev = ((IsoSymlink*)n->node)->dest; cur = strchr(prev, '/'); while (1) { @@ -601,16 +600,16 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, /* last component */ clen = strlen(prev); } - + if (clen == 1 && prev[0] == '.') { clen = 0; } else if (clen == 2 && prev[0] == '.' && prev[1] == '.') { clen = 0; } - + /* flags and len for each component record (RRIP, 4.1.3.1) */ clen += 2; - + if (!cew) { /* we are still writing to the SUA */ if (su_size + sl_len + clen > space) { @@ -631,7 +630,7 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, } else { sl_len += clen; } - } + } if (cew) { if (sl_len + clen > 255) { /* we need an additional SL entry */ @@ -671,7 +670,7 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, sl_len += clen; } } - + if (!cur || cur[1] == '\0') { /* cur[1] can be \0 if dest ends with '/' */ break; @@ -679,7 +678,7 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, prev = cur + 1; cur = strchr(prev, '/'); } - + /* and finally write the pending SL field */ if (!cew) { /* the whole SL fits into the SUA */ @@ -687,10 +686,10 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, } else { *ce += sl_len; } - + } } else { - + /* "." or ".." entry */ su_size += 5; /* NM field */ if (type == 1 && n->parent == NULL) { @@ -703,7 +702,7 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, *ce = 182; /* ER */ } } - + /* * The System Use field inside the directory record must be padded if * it is an odd number (ECMA-119, 9.1.13) @@ -719,12 +718,12 @@ static void susp_info_free(struct susp_info* susp) { size_t i; - + for (i = 0; i < susp->n_susp_fields; ++i) { free(susp->susp_fields[i]); } free(susp->susp_fields); - + for (i = 0; i < susp->n_ce_susp_fields; ++i) { free(susp->ce_susp_fields[i]); } @@ -748,14 +747,14 @@ void susp_info_free(struct susp_info* susp) * @return * 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) { int ret; size_t i; Ecma119Node *node; - char *name = NULL; - + char *name= NULL; + if (t == NULL || n == NULL || info == NULL) { 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 */ return ISO_WRONG_ARG_VALUE; } - + if (type == 2 && n->parent != NULL) { node = n->parent; } else { node = n; } - + /* space min is 255 - 33 - 37 = 185 * 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 * (ECMA-119, 9.1.13). Thus, in fact the real space is always space - 1 */ space--; - + /* * SP must be the first entry for the "." record of the root directory * (SUSP, 5.3) @@ -787,7 +786,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type, goto add_susp_cleanup; } } - + /* PX and TF, we are sure they always fit in SUA */ ret = rrip_add_PX(t, node, info); if (ret < 0) { @@ -797,7 +796,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type, if (ret < 0) { goto add_susp_cleanup; } - + if (n->type == ECMA119_DIR) { if (n->info.dir.real_parent != NULL) { /* it is a reallocated entry */ @@ -825,7 +824,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type, if (ret < 0) { goto add_susp_cleanup; } - } + } } else if (n->type == ECMA119_PLACEHOLDER) { /* we need the CL entry */ 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; } } - + if (type == 0) { size_t sua_free; /* free space in the SUA */ int nm_type = 0; /* 0 whole entry in SUA, 1 part in CE */ size_t ce_len = 0; /* len of the CE */ size_t namelen; - + /* 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 */ - + name = get_rr_name(t, n); namelen = strlen(name); - + sua_free = space - info->suf_len; - + /* NM entry */ if (5 + namelen <= sua_free) { /* 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; size_t sl_len = 5; int cew = (nm_type == 1); /* are we writing to CE? */ - + prev = ((IsoSymlink*)n->node)->dest; cur = strchr(prev, '/'); while (1) { @@ -880,21 +879,22 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type, /* last component */ clen = strlen(prev); } - + if (clen == 0) { /* this refers to the roor directory, '/' */ cflag = 1 << 3; - } if (clen == 1 && prev[0] == '.') { + } + if (clen == 1 && prev[0] == '.') { clen = 0; cflag = 1 << 1; } else if (clen == 2 && prev[0] == '.' && prev[1] == '.') { clen = 0; cflag = 1 << 2; } - + /* flags and len for each component record (RRIP, 4.1.3.1) */ clen += 2; - + if (!cew) { /* we are still writing to the SUA */ if (sl_len + clen > sua_free) { @@ -923,7 +923,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type, } sl_len += clen; } - } + } if (cew) { if (sl_len + clen > 255) { /* 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 * and another SL entry */ - ret = rrip_SL_append_comp(&n_comp, &comps, + ret = rrip_SL_append_comp(&n_comp, &comps, prev, fit, 0x01); if (ret < 0) { 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 * other SL entry */ - ret = rrip_SL_append_comp(&n_comp, &comps, - prev + fit, - clen - fit - 2, - 0); + ret = rrip_SL_append_comp(&n_comp, &comps, prev + + fit, clen - fit - 2, 0); if (ret < 0) { 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 * anything in this SL */ - ret = rrip_SL_append_comp(&n_comp, &comps, + ret = rrip_SL_append_comp(&n_comp, &comps, prev, 248, 0x01); if (ret < 0) { goto add_susp_cleanup; } - ret = rrip_SL_append_comp(&n_comp, &comps, - prev + 248, - strlen(prev + 248), - 0x00); + ret = rrip_SL_append_comp(&n_comp, &comps, prev + + 248, strlen(prev + 248), 0x00); if (ret < 0) { goto add_susp_cleanup; } @@ -984,7 +980,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type, } } else { /* 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); if (ret < 0) { goto add_susp_cleanup; @@ -1002,7 +998,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type, sl_len += clen; } } - + if (!cur || cur[1] == '\0') { /* cur[1] can be \0 if dest ends with '/' */ break; @@ -1010,19 +1006,19 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type, prev = cur + 1; cur = strchr(prev, '/'); } - + if (cew) { ce_len += sl_len; } } - + /* * We we reach here: * - We know if NM fill in the SUA (nm_type == 0) * - If SL needs an to be written in CE (ce_len > 0) * - The components for SL entry (or entries) */ - + if (nm_type == 0) { /* the full NM fills in SUA */ 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; } } - + if (ce_len > 0) { /* Add the CE entry */ 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) { - + /* add the SL entry (or entries) */ ret = rrip_add_SL(t, info, comps, n_comp, (ce_len > 0)); - + /* free the components */ for (i = 0; i < n_comp; i++) { free(comps[i]); } free(comps); - + if (ret < 0) { goto add_susp_cleanup; } } - - + } else { - + /* "." or ".." entry */ - + /* write the NM entry */ ret = rrip_add_NM(t, info, NULL, 0, 1 << type, 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 * it is an odd number (ECMA-119, 9.1.13) */ info->suf_len += (info->suf_len % 2); - + free(name); return ISO_SUCCESS; - -add_susp_cleanup:; + + add_susp_cleanup: ; free(name); susp_info_free(info); return ret; @@ -1126,12 +1121,12 @@ add_susp_cleanup:; * After written, the info susp_fields array will be freed, and the counters * 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) { size_t i; size_t pos = 0; - + if (info->n_susp_fields == 0) { 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]); pos += info->susp_fields[i][2]; } - + /* free susp_fields */ for (i = 0; i < info->n_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; uint8_t padding[BLOCK_SIZE]; - int ret = ISO_SUCCESS; - + int ret= ISO_SUCCESS; + if (info->n_ce_susp_fields == 0) { return ret; } @@ -1173,15 +1168,15 @@ int rrip_write_ce_fields(Ecma119Image *t, struct susp_info *info) goto write_ce_field_cleanup; } } - + /* pad continuation area until block size */ i = BLOCK_SIZE - (info->ce_len % BLOCK_SIZE); if (i > 0 && i < BLOCK_SIZE) { memset(padding, 0, i); ret = iso_write(t, padding, i); } - -write_ce_field_cleanup:; + + write_ce_field_cleanup: ; /* free ce_susp_fields */ for (i = 0; i < info->n_ce_susp_fields; ++i) { free(info->ce_susp_fields[i]); diff --git a/src/rockridge.h b/src/rockridge.h index 81e2854..b6c347c 100644 --- a/src/rockridge.h +++ b/src/rockridge.h @@ -28,7 +28,6 @@ #include "ecma119.h" - /** * 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 @@ -66,8 +65,8 @@ struct susp_info * @return * 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 space, size_t *ce); +size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type, size_t space, + size_t *ce); /** * 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 * 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); /** @@ -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 * 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); /** diff --git a/src/stream.c b/src/stream.c index da976bb..1ffa400 100644 --- a/src/stream.c +++ b/src/stream.c @@ -50,11 +50,11 @@ off_t fsrc_get_size(IsoStream *stream) { FSrcStreamData *data; data = (FSrcStreamData*)stream->data; - + return data->size; } -static +static int fsrc_read(IsoStream *stream, void *buf, size_t count) { IsoFileSource *src; @@ -65,7 +65,7 @@ int fsrc_read(IsoStream *stream, void *buf, size_t count) return iso_file_source_read(src, buf, count); } -static +static int fsrc_is_repeatable(IsoStream *stream) { int ret; @@ -75,11 +75,11 @@ int fsrc_is_repeatable(IsoStream *stream) return ISO_NULL_POINTER; } data = (FSrcStreamData*)stream->data; - + /* mode is not cached, this function is only useful for filters */ ret = iso_file_source_stat(data->src, &info); if (ret < 0) { - return ret; + return ret; } if (S_ISREG(info.st_mode) || S_ISBLK(info.st_mode)) { return 1; @@ -89,24 +89,24 @@ int fsrc_is_repeatable(IsoStream *stream) } 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) { FSrcStreamData *data; IsoFilesystem *fs; - + if (stream == NULL || fs_id == NULL || dev_id == NULL || ino_id == NULL) { return ISO_NULL_POINTER; } data = (FSrcStreamData*)stream->data; - + fs = iso_file_source_get_filesystem(data->src); - + *fs_id = fs->get_id(fs); if (fs_id == 0) { return 0; } - + *dev_id = data->dev_id; *ino_id = data->ino_id; return ISO_SUCCESS; @@ -141,7 +141,7 @@ int iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream) if (src == NULL || stream == NULL) { return ISO_NULL_POINTER; } - + r = iso_file_source_stat(src, &info); if (r < 0) { return r; @@ -149,7 +149,7 @@ int iso_file_source_stream_new(IsoFileSource *src, IsoStream **stream) if (S_ISDIR(info.st_mode)) { return ISO_FILE_IS_DIR; } - + str = malloc(sizeof(IsoStream)); if (str == NULL) { 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->ino_id = info.st_ino; data->size = info.st_size; - + str->refcount = 1; str->data = data; str->class = &fsrc_stream_class; - + *stream = str; return ISO_SUCCESS; } diff --git a/src/stream.h b/src/stream.h index 5c739bf..b549ec2 100644 --- a/src/stream.h +++ b/src/stream.h @@ -55,7 +55,7 @@ typedef struct IsoStream_Iface * number of bytes read, 0 if EOF, < 0 on error */ int (*read)(IsoStream *stream, void *buf, size_t count); - + /** * 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 @@ -68,7 +68,7 @@ typedef struct IsoStream_Iface * 1 if stream is repeatable, 0 if not, < 0 on error */ int (*is_repeatable)(IsoStream *stream); - + /** * Get an unique identifier for the IsoStream. If your implementation * is unable to return a valid identifier, this function should return @@ -77,7 +77,7 @@ typedef struct IsoStream_Iface * @return * 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); /** @@ -91,43 +91,49 @@ struct Iso_Stream { IsoStreamIface *class; int refcount; - void *data; + void *data; }; void iso_stream_ref(IsoStream *stream); void iso_stream_unref(IsoStream *stream); extern inline -int iso_stream_open(IsoStream *stream) { +int iso_stream_open(IsoStream *stream) +{ return stream->class->open(stream); } extern inline -int iso_stream_close(IsoStream *stream) { +int iso_stream_close(IsoStream *stream) +{ return stream->class->close(stream); } extern inline -off_t iso_stream_get_size(IsoStream *stream) { +off_t iso_stream_get_size(IsoStream *stream) +{ return stream->class->get_size(stream); } 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); } extern inline -int iso_stream_is_repeatable(IsoStream *stream) { +int iso_stream_is_repeatable(IsoStream *stream) +{ return stream->class->is_repeatable(stream); } extern inline -int iso_stream_get_id(IsoStream *stream, unsigned int *fs_id, - dev_t *dev_id, ino_t *ino_id) { +int iso_stream_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id, + ino_t *ino_id) +{ return stream->class->get_id(stream, fs_id, dev_id, ino_id); } - + /** * Create a stream to read from a IsoFileSource. * The stream will take the ref. to the IsoFileSource, so after a successfully diff --git a/src/tree.c b/src/tree.c index 0d1d43b..6485d6c 100644 --- a/src/tree.c +++ b/src/tree.c @@ -48,14 +48,14 @@ int iso_tree_add_new_dir(IsoDir *parent, const char *name, IsoDir **dir) IsoDir *node; IsoNode **pos; time_t now; - + if (parent == NULL || name == NULL) { return ISO_NULL_POINTER; } if (dir) { *dir = NULL; } - + /* find place where to insert */ pos = &(parent->children); 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 */ return ISO_NODE_NAME_NOT_UNIQUE; } - + node = calloc(1, sizeof(IsoDir)); if (node == NULL) { return ISO_MEM_ERROR; } - + node->node.refcount = 1; node->node.type = LIBISO_DIR; node->node.name = strdup(name); @@ -78,24 +78,24 @@ int iso_tree_add_new_dir(IsoDir *parent, const char *name, IsoDir **dir) free(node); return ISO_MEM_ERROR; } - + /* permissions from parent */ node->node.mode = parent->node.mode; node->node.uid = parent->node.uid; node->node.gid = parent->node.gid; node->node.hidden = parent->node.hidden; - + /* current time */ now = time(NULL); node->node.atime = now; node->node.ctime = now; node->node.mtime = now; - + /* add to dir */ node->node.parent = parent; node->node.next = *pos; *pos = (IsoNode*)node; - + if (dir) { *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_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) { IsoSymlink *node; IsoNode **pos; time_t now; - + if (parent == NULL || name == NULL || dest == NULL) { return ISO_NULL_POINTER; } if (link) { *link = NULL; } - + /* find place where to insert */ pos = &(parent->children); 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 */ return ISO_NODE_NAME_NOT_UNIQUE; } - + node = calloc(1, sizeof(IsoSymlink)); if (node == NULL) { return ISO_MEM_ERROR; } - + node->node.refcount = 1; node->node.type = LIBISO_SYMLINK; node->node.name = strdup(name); @@ -162,31 +162,31 @@ int iso_tree_add_new_symlink(IsoDir *parent, const char *name, free(node); return ISO_MEM_ERROR; } - + node->dest = strdup(dest); if (node->dest == NULL) { free(node->node.name); free(node); return ISO_MEM_ERROR; } - + /* permissions from parent */ node->node.mode = S_IFLNK | 0777; node->node.uid = parent->node.uid; node->node.gid = parent->node.gid; node->node.hidden = parent->node.hidden; - + /* current time */ now = time(NULL); node->node.atime = now; node->node.ctime = now; node->node.mtime = now; - + /* add to dir */ node->node.parent = parent; node->node.next = *pos; *pos = (IsoNode*)node; - + if (link) { *link = node; } @@ -231,13 +231,13 @@ int iso_tree_add_new_symlink(IsoDir *parent, const char *name, * 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) { IsoSpecial *node; IsoNode **pos; time_t now; - + if (parent == NULL || name == NULL) { return ISO_NULL_POINTER; } @@ -247,7 +247,7 @@ int iso_tree_add_new_special(IsoDir *parent, const char *name, mode_t mode, if (special) { *special = NULL; } - + /* find place where to insert */ pos = &(parent->children); 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 */ return ISO_NODE_NAME_NOT_UNIQUE; } - + node = calloc(1, sizeof(IsoSpecial)); if (node == NULL) { return ISO_MEM_ERROR; } - + node->node.refcount = 1; node->node.type = LIBISO_SPECIAL; 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); return ISO_MEM_ERROR; } - + node->node.mode = mode; node->dev = dev; - + /* atts from parent */ node->node.uid = parent->node.uid; node->node.gid = parent->node.gid; node->node.hidden = parent->node.hidden; - + /* current time */ now = time(NULL); node->node.atime = now; node->node.ctime = now; node->node.mtime = now; - + /* add to dir */ node->node.parent = parent; node->node.next = *pos; *pos = (IsoNode*)node; - + if (special) { *special = node; } return ++parent->nchildren; } -static -int iso_tree_add_node_builder(IsoImage *image, IsoDir *parent, - IsoFileSource *src, IsoNodeBuilder *builder, +static +int iso_tree_add_node_builder(IsoImage *image, IsoDir *parent, + IsoFileSource *src, IsoNodeBuilder *builder, IsoNode **node) { int result; IsoNode *new; IsoNode **pos; char *name; - + if (parent == NULL || src == NULL || builder == NULL) { return ISO_NULL_POINTER; } if (node) { *node = NULL; } - + name = iso_file_source_get_name(src); - + /* find place where to insert */ pos = &(parent->children); 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 */ return ISO_NODE_NAME_NOT_UNIQUE; } - + result = builder->create_node(builder, image, src, &new); if (result < 0) { return result; } - + /* finally, add node to parent */ new->parent = parent; new->next = *pos; *pos = new; - + if (node) { *node = new; } 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) { int result; IsoFilesystem *fs; IsoFileSource *file; - + if (image == NULL || parent == NULL || path == NULL) { return ISO_NULL_POINTER; } - + fs = image->fs; result = fs->get_by_path(fs, path, &file); if (result < 0) { 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); /* free the file */ - iso_file_source_unref(file); + iso_file_source_unref(file); return result; } @@ -381,7 +381,7 @@ int check_excludes(IsoImage *image, const char *path) return 0; } -static +static int check_hidden(IsoImage *image, const char *name) { return (image->recOpts->ignore_hidden && name[0] == '.'); @@ -399,25 +399,25 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir) IsoNodeBuilder *builder; IsoFileSource *file; IsoNode **pos; - + result = iso_file_source_open(dir); if (result < 0) { iso_msg_debug(image, "Can't open dir %s", iso_file_source_get_path(dir)); return result; } - + builder = image->builder; action = 1; while ( (result = iso_file_source_readdir(dir, &file)) == 1) { int flag; char *name; IsoNode *new; - + iso_msg_debug(image, "Adding file %s", iso_file_source_get_path(file)); - + name = iso_file_source_get_name(file); - + if (check_excludes(image, iso_file_source_get_path(file))) { action = 2; } else if (check_hidden(image, name)) { @@ -425,7 +425,7 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir) } else { action = 1; } - + /* find place where to insert */ flag = 0; pos = &(parent->children); @@ -438,12 +438,12 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir) action = 2; } } - + /* ask user if callback has been set */ if (image->recOpts->report) { action = image->recOpts->report(file, action, flag); } - + if (action == 2) { /* skip 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); break; } - + /* ok, file will be added */ result = builder->create_node(builder, image, file, &new); if (result < 0) { - - iso_msg_debug(image, "Error %d when adding file %s", - result, iso_file_source_get_path(file)); - + + iso_msg_debug(image, "Error %d when adding file %s", result, + iso_file_source_get_path(file)); + if (image->recOpts->report) { action = image->recOpts->report(file, result, flag); } else { action = image->recOpts->stop_on_error ? 3 : 1; } - + /* free file */ iso_file_source_unref(file); - + if (action == 3) { result = 1; /* prevent error to be passing up */ break; @@ -478,7 +478,7 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir) continue; } } - + /* ok, node has correctly created, we need to add it */ if (flag) { /* replace node */ @@ -495,7 +495,7 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir) new->parent = parent; ++parent->nchildren; } - + /* finally, if the node is a directory we need to recurse */ if (new->type == LIBISO_DIR) { 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); } } - + if (result < 0) { // TODO printf message action = result; } - + result = iso_file_source_close(dir); if (result < 0) { return result; @@ -541,24 +541,24 @@ int iso_tree_add_dir_rec(IsoImage *image, IsoDir *parent, const char *dir) struct stat info; IsoFilesystem *fs; IsoFileSource *file; - + if (image == NULL || parent == NULL || dir == NULL) { return ISO_NULL_POINTER; } - + fs = image->fs; result = fs->get_by_path(fs, dir, &file); if (result < 0) { return result; } - + /* we also allow dir path to be a symlink to a dir */ result = iso_file_source_stat(file, &info); if (result < 0) { iso_file_source_unref(file); return result; } - + if (!S_ISDIR(info.st_mode)) { iso_file_source_unref(file); 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); result = 0; - + /* get the first component of the path */ component = strtok_r(ptr, "/", &brk_info); while (component) { diff --git a/src/util.c b/src/util.c index 89d0143..28e53d1 100644 --- a/src/util.c +++ b/src/util.c @@ -28,7 +28,6 @@ int int_pow(int base, int power) return result; } - int strconv(const char *str, const char *icharset, const char *ocharset, char **output) { @@ -74,8 +73,8 @@ int strconv(const char *str, const char *icharset, const char *ocharset, * @return * 1 success, < 0 error */ -static -int str2wchar(const char *icharset, const char *input, wchar_t **output) +static +int str2wchar(const char *icharset, const char *input, wchar_t **output) { iconv_t conv; size_t inbytes; @@ -84,7 +83,7 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output) char *src; wchar_t *wstr; size_t n; - + if (icharset == NULL || input == NULL || output == NULL) { return ISO_NULL_POINTER; } @@ -93,7 +92,7 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output) if (conv == (iconv_t)-1) { return ISO_CHARSET_CONV_ERROR; } - + inbytes = strlen(input); 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); while (n == -1) { - + if (errno == E2BIG) { /* error, should never occur */ iconv_close(conv); @@ -115,7 +114,7 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output) return ISO_CHARSET_CONV_ERROR; } else { wchar_t *wret; - + /* * Invalid input string 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); */ inbytes--; src++; - + wret = (wchar_t*) ret; *wret++ = (wchar_t) '_'; ret = (char *) wret; @@ -138,7 +137,7 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output) } } iconv_close(conv); - + *( (wchar_t *)ret )='\0'; *output = wstr; return ISO_SUCCESS; @@ -156,7 +155,7 @@ int str2ascii(const char *icharset, const char *input, char **output) size_t outbytes; size_t inbytes; size_t n; - + if (icharset == NULL || input == NULL || output == NULL) { return ISO_NULL_POINTER; } @@ -171,7 +170,7 @@ int str2ascii(const char *icharset, const char *input, char **output) } src = (char *)wsrc_; numchars = wcslen(wsrc_); - + inbytes = numchars * sizeof(wchar_t); 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); - while(n == -1) { + while (n == -1) { /* The destination buffer is too small. Stops here. */ if (errno == E2BIG) break; @@ -226,7 +225,7 @@ int str2ascii(const char *icharset, const char *input, char **output) *ret='\0'; free(wsrc_); - + *output = ret_; return ISO_SUCCESS; } @@ -238,25 +237,25 @@ static int valid_d_char(char c) static int valid_a_char(char c) { - return (c >= ' ' && c <= '"') || (c >= '%' && c <= '?') - || (c >= 'A' && c <= 'Z') || (c == '_'); + return (c >= ' ' && c <= '"') || (c >= '%' && c <= '?') || + (c >= 'A' && c <= 'Z') || (c == '_'); } -static +static char *iso_dirid(const char *src, int size) { size_t len, i; char name[32]; - + len = strlen(src); if (len > size) { len = size; } for (i = 0; i < len; i++) { - char c = toupper(src[i]); + char c= toupper(src[i]); name[i] = valid_d_char(c) ? c : '_'; } - + name[len] = '\0'; return strdup(name); } @@ -274,7 +273,7 @@ char *iso_2_dirid(const char *src) char *iso_1_fileid(const char *src) { 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; char dest[13]; /* 13 = 8 (name) + 1 (.) + 3 (ext) + 1 (\0) */ @@ -292,24 +291,24 @@ char *iso_1_fileid(const char *src) } pos = 0; - + /* Convert up to 8 characters of the filename. */ 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 : '_'; } - + /* This dot is mandatory, even if there is no extension. */ dest[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]); + char c= toupper(src[lname + 1 + i]); dest[pos++] = valid_d_char(c) ? c : '_'; } - + dest[pos] = '\0'; return strdup(dest); } @@ -339,8 +338,8 @@ char *iso_2_fileid(const char *src) } else { lext = strlen(dot + 1); lname = strlen(src) - lext - 1; - lnext = (strlen(src) > 31 && lext > 3) - ? (lname < 27 ? 30 - lname : 3) : lext; + lnext = (strlen(src) > 31 && lext > 3) ? (lname < 27 ? 30 - lname : 3) + : lext; lnname = (strlen(src) > 31) ? 30 - lnext : lname; } @@ -349,18 +348,18 @@ char *iso_2_fileid(const char *src) } pos = 0; - + /* Convert up to lnname characters of the filename. */ 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++] = '.'; - + /* Convert up to lnext characters of the extension, if any. */ 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 : '_'; } @@ -368,166 +367,70 @@ char *iso_2_fileid(const char *src) 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 ret; char *ascii; size_t len, i; - + if (output == NULL) { return ISO_MEM_ERROR; } - + /** allow NULL input */ if (input == NULL) { *output = NULL; return 0; } - + /* this checks for NULL parameters */ ret = str2ascii(icharset, input, &ascii); if (ret < 0) { *output = NULL; return ret; } - + len = strlen(ascii); - + for (i = 0; i < len; ++i) { - char c = toupper(ascii[i]); + char c= toupper(ascii[i]); ascii[i] = valid_d_char(c) ? c : '_'; } - + *output = ascii; return ISO_SUCCESS; } - + int str2a_char(const char *icharset, const char *input, char **output) { int ret; char *ascii; size_t len, i; - + if (output == NULL) { return ISO_MEM_ERROR; } - + /** allow NULL input */ if (input == NULL) { *output = NULL; return 0; } - + /* this checks for NULL parameters */ ret = str2ascii(icharset, input, &ascii); if (ret < 0) { *output = NULL; return ret; } - + len = strlen(ascii); - + for (i = 0; i < len; ++i) { - char c = toupper(ascii[i]); + char c= toupper(ascii[i]); ascii[i] = valid_a_char(c) ? c : '_'; } - + *output = ascii; return ISO_SUCCESS; } diff --git a/src/util_rbtree.c b/src/util_rbtree.c index 72e4be4..55afed0 100644 --- a/src/util_rbtree.c +++ b/src/util_rbtree.c @@ -16,13 +16,15 @@ * implementation of Julienne Walker. */ -struct iso_rbnode { +struct iso_rbnode +{ void *data; struct iso_rbnode *ch[2]; - unsigned int red:1; + unsigned int red :1; }; -struct iso_rbtree { +struct iso_rbtree +{ struct iso_rbnode *root; size_t size; int (*compare)(const void *a, const void *b); @@ -40,8 +42,7 @@ struct iso_rbtree { * @param tree * Location where the tree structure will be stored. */ -int -iso_rbtree_new(int (*compare)(const void*, const void*), IsoRBTree **tree) +int iso_rbtree_new(int (*compare)(const void*, const void*), IsoRBTree **tree) { if (compare == NULL || tree == NULL) { 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 * element of the tree, so you can use it to free any related data. */ -void -iso_rbtree_destroy(IsoRBTree *tree, void (*free_data)(void *)) +void iso_rbtree_destroy(IsoRBTree *tree, void (*free_data)(void *)) { if (tree == NULL) { return; @@ -115,14 +115,14 @@ static struct iso_rbnode *iso_rbnode_new(void *data) { struct iso_rbnode *rn = malloc(sizeof(struct iso_rbnode)); - - if ( rn != NULL ) { + + if (rn != NULL) { rn->data = data; rn->red = 1; rn->ch[0] = NULL; rn->ch[1] = NULL; } - + return rn; } @@ -154,23 +154,23 @@ int iso_rbtree_insert(IsoRBTree *tree, void *data, void **item) /* Empty tree case */ tree->root = iso_rbnode_new(data); if (tree->root == NULL) { - return ISO_MEM_ERROR; + return ISO_MEM_ERROR; } new = data; added = 1; } 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 *p, *q; /* Iterator & parent */ + struct iso_rbnode *g, *t; /* Grandparent & parent */ + struct iso_rbnode *p, *q; /* Iterator & parent */ int dir = 0, last = 0; int comp; - + /* Set up helpers */ t = &head; g = p = NULL; q = t->ch[1] = tree->root; - + /* Search down the tree */ while (1) { if (q == NULL) { @@ -186,7 +186,7 @@ int iso_rbtree_insert(IsoRBTree *tree, void *data, void **item) q->ch[0]->red = 0; q->ch[1]->red = 0; } - + /* Fix red violation */ if (is_red(q) && is_red(p)) { int dir2 = (t->ch[1] == g); @@ -208,7 +208,7 @@ int iso_rbtree_insert(IsoRBTree *tree, void *data, void **item) last = dir; dir = (comp < 0); - + /* Update helpers */ if (g != NULL) t = g; @@ -219,7 +219,7 @@ int iso_rbtree_insert(IsoRBTree *tree, void *data, void **item) /* Update root */ tree->root = head.ch[1]; } - + /* Make root black */ tree->root->red = 0; @@ -243,7 +243,6 @@ size_t iso_rbtree_get_size(IsoRBTree *tree) return tree->size; } - static 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 * has size + 1 length. */ -void ** -iso_rbtree_to_array(IsoRBTree *tree) +void ** iso_rbtree_to_array(IsoRBTree *tree) { void **array; diff --git a/src/writer.h b/src/writer.h index 0db97be..8d357f8 100644 --- a/src/writer.h +++ b/src/writer.h @@ -16,20 +16,19 @@ struct Iso_Image_Writer * */ int (*compute_data_blocks)(IsoImageWriter *writer); - + int (*write_vol_desc)(IsoImageWriter *writer); - + int (*write_data)(IsoImageWriter *writer); - + int (*free_data)(IsoImageWriter *writer); - + void *data; Ecma119Image *target; }; /** - * This is the function all Writers shoudl call to write data to - * image. + * This is the function all Writers shoudl call to write data to image. * Currently, it is just a wrapper for write(2) Unix system call. * * It is implemented in ecma119.c