2007-12-15 12:13:49 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Vreixo Formoso
|
|
|
|
*
|
|
|
|
* This file is part of the libisofs project; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation. See COPYING file for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "filesrc.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "node.h"
|
2007-12-19 23:25:25 +00:00
|
|
|
#include "util.h"
|
2007-12-15 12:13:49 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
2007-12-16 18:10:47 +00:00
|
|
|
|
2007-12-19 23:25:25 +00:00
|
|
|
int iso_file_src_cmp(const void *n1, const void *n2)
|
2007-12-15 12:13:49 +00:00
|
|
|
{
|
|
|
|
const IsoFileSrc *f1, *f2;
|
2007-12-18 19:46:28 +00:00
|
|
|
int res;
|
|
|
|
unsigned int fs_id1, fs_id2;
|
|
|
|
dev_t dev_id1, dev_id2;
|
|
|
|
ino_t ino_id1, ino_id2;
|
|
|
|
|
2007-12-15 12:13:49 +00:00
|
|
|
f1 = (const IsoFileSrc *)n1;
|
|
|
|
f2 = (const IsoFileSrc *)n2;
|
|
|
|
|
2007-12-18 19:46:28 +00:00
|
|
|
res = f1->stream->get_id(f1->stream, &fs_id1, &dev_id1, &ino_id1);
|
|
|
|
res = f2->stream->get_id(f2->stream, &fs_id2, &dev_id2, &ino_id2);
|
|
|
|
|
|
|
|
//TODO take care about res <= 0
|
|
|
|
|
|
|
|
if (fs_id1 < fs_id2) {
|
2007-12-15 12:13:49 +00:00
|
|
|
return -1;
|
2007-12-18 19:46:28 +00:00
|
|
|
} else if (fs_id1 > fs_id2) {
|
2007-12-15 12:13:49 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
/* files belong to the same fs */
|
2007-12-18 19:46:28 +00:00
|
|
|
if (dev_id1 > dev_id2) {
|
2007-12-15 12:13:49 +00:00
|
|
|
return -1;
|
2007-12-18 19:46:28 +00:00
|
|
|
} else if (dev_id1 < dev_id2) {
|
2007-12-15 12:13:49 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
/* files belong to same device in same fs */
|
2007-12-18 19:46:28 +00:00
|
|
|
return (ino_id1 < ino_id2) ? -1 :
|
|
|
|
(ino_id1 > ino_id2) ? 1 : 0;
|
2007-12-15 12:13:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
IsoStream *stream;
|
|
|
|
IsoFileSrc *fsrc;
|
|
|
|
unsigned int fs_id;
|
|
|
|
dev_t dev_id;
|
|
|
|
ino_t ino_id;
|
|
|
|
|
|
|
|
if (img == NULL || file == NULL || src == NULL) {
|
|
|
|
return ISO_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream = file->stream;
|
|
|
|
res = stream->get_id(stream, &fs_id, &dev_id, &ino_id);
|
|
|
|
if (res < 0) {
|
|
|
|
return res;
|
|
|
|
} else if (res == 0) {
|
|
|
|
// TODO this corresponds to Stream that cannot provide a valid id
|
2007-12-18 19:46:28 +00:00
|
|
|
// Not implemented for now, but that shouldn't be here, the get_id
|
|
|
|
// above is not needed at all, the comparison function should take
|
|
|
|
// care of it
|
2007-12-15 12:13:49 +00:00
|
|
|
return ISO_ERROR;
|
|
|
|
} else {
|
2007-12-19 23:25:25 +00:00
|
|
|
int ret;
|
2007-12-15 12:13:49 +00:00
|
|
|
|
|
|
|
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 */
|
2007-12-19 23:25:25 +00:00
|
|
|
ret = iso_rbtree_insert(img->files, fsrc, (void**)src);
|
|
|
|
if (ret <= 0) {
|
2007-12-15 12:13:49 +00:00
|
|
|
free(fsrc);
|
2007-12-19 23:25:25 +00:00
|
|
|
return ret;
|
2007-12-15 12:13:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ISO_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-12-19 23:25:25 +00:00
|
|
|
void iso_file_src_free(void *node)
|
2007-12-16 18:10:47 +00:00
|
|
|
{
|
2007-12-19 23:25:25 +00:00
|
|
|
free(node);
|
2007-12-16 18:10:47 +00:00
|
|
|
}
|
2007-12-18 19:46:28 +00:00
|
|
|
|
|
|
|
off_t iso_file_src_get_size(IsoFileSrc *file)
|
|
|
|
{
|
|
|
|
return file->stream->get_size(file->stream);
|
|
|
|
}
|