2007-12-15 15:55:44 +00:00
|
|
|
/*
|
|
|
|
* Little program that imports a directory to iso image, generates the
|
|
|
|
* ecma119 low level tree and prints it.
|
|
|
|
* Note that this is not an API example, but a little program for test
|
|
|
|
* purposes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libisofs.h"
|
|
|
|
#include "ecma119.h"
|
|
|
|
#include "ecma119_tree.h"
|
2007-12-19 23:25:25 +00:00
|
|
|
#include "util.h"
|
|
|
|
#include "filesrc.h"
|
2007-12-23 15:16:26 +00:00
|
|
|
#include "node.h"
|
2007-12-15 15:55:44 +00:00
|
|
|
#include <stdio.h>
|
2008-01-14 23:21:07 +00:00
|
|
|
#include <stdlib.h>
|
2007-12-15 15:55:44 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_permissions(mode_t mode)
|
|
|
|
{
|
2007-12-23 15:16:26 +00:00
|
|
|
char perm[10];
|
|
|
|
|
|
|
|
//TODO suid, sticky...
|
|
|
|
|
|
|
|
perm[9] = '\0';
|
|
|
|
perm[8] = mode & S_IXOTH ? 'x' : '-';
|
|
|
|
perm[7] = mode & S_IWOTH ? 'w' : '-';
|
|
|
|
perm[6] = mode & S_IROTH ? 'r' : '-';
|
|
|
|
perm[5] = mode & S_IXGRP ? 'x' : '-';
|
|
|
|
perm[4] = mode & S_IWGRP ? 'w' : '-';
|
|
|
|
perm[3] = mode & S_IRGRP ? 'r' : '-';
|
|
|
|
perm[2] = mode & S_IXUSR ? 'x' : '-';
|
|
|
|
perm[1] = mode & S_IWUSR ? 'w' : '-';
|
|
|
|
perm[0] = mode & S_IRUSR ? 'r' : '-';
|
|
|
|
printf("[%s]",perm);
|
2007-12-15 15:55:44 +00:00
|
|
|
}
|
|
|
|
|
2007-12-23 15:16:26 +00:00
|
|
|
static void
|
|
|
|
print_dir(Ecma119Node *dir, int level)
|
2007-12-15 15:55:44 +00:00
|
|
|
{
|
2007-12-23 15:16:26 +00:00
|
|
|
int i;
|
2008-01-14 23:21:07 +00:00
|
|
|
char *sp = alloca(level * 2 + 1);
|
2007-12-23 15:16:26 +00:00
|
|
|
|
|
|
|
for (i = 0; i < level * 2; i += 2) {
|
|
|
|
sp[i] = '|';
|
|
|
|
sp[i+1] = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
sp[level * 2-1] = '-';
|
|
|
|
sp[level * 2] = '\0';
|
|
|
|
|
2007-12-29 17:30:59 +00:00
|
|
|
for (i = 0; i < dir->info.dir->nchildren; i++) {
|
|
|
|
Ecma119Node *child = dir->info.dir->children[i];
|
2007-12-23 15:16:26 +00:00
|
|
|
|
|
|
|
if (child->type == ECMA119_DIR) {
|
|
|
|
printf("%s+[D] ", sp);
|
|
|
|
print_permissions(iso_node_get_permissions(child->node));
|
|
|
|
printf(" %s\n", child->iso_name);
|
|
|
|
print_dir(child, level+1);
|
|
|
|
} else if (child->type == ECMA119_FILE) {
|
|
|
|
printf("%s-[F] ", sp);
|
2007-12-15 15:55:44 +00:00
|
|
|
print_permissions(iso_node_get_permissions(child->node));
|
|
|
|
printf(" %s {%p}\n", child->iso_name, (void*)child->info.file);
|
2007-12-23 15:16:26 +00:00
|
|
|
} else if (child->type == ECMA119_SYMLINK) {
|
|
|
|
printf("%s-[L] ", sp);
|
|
|
|
print_permissions(iso_node_get_permissions(child->node));
|
|
|
|
printf(" %s -> %s\n", child->iso_name,
|
|
|
|
((IsoSymlink*)child->node)->dest);
|
|
|
|
} else if (child->type == ECMA119_SPECIAL) {
|
|
|
|
printf("%s-[S] ", sp);
|
|
|
|
print_permissions(iso_node_get_permissions(child->node));
|
|
|
|
printf(" %s\n", child->iso_name);
|
2007-12-23 16:11:32 +00:00
|
|
|
} else if (child->type == ECMA119_PLACEHOLDER) {
|
|
|
|
printf("%s-[RD] ", sp);
|
|
|
|
print_permissions(iso_node_get_permissions(child->node));
|
|
|
|
printf(" %s\n", child->iso_name);
|
2007-12-23 15:16:26 +00:00
|
|
|
} else {
|
|
|
|
printf("%s-[????] ", sp);
|
|
|
|
}
|
|
|
|
}
|
2007-12-15 15:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2007-12-23 15:16:26 +00:00
|
|
|
int result;
|
2007-12-15 15:55:44 +00:00
|
|
|
IsoImage *image;
|
|
|
|
Ecma119Image *ecma119;
|
2007-12-23 15:16:26 +00:00
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
printf ("You need to specify a valid path\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-01-19 01:48:12 +00:00
|
|
|
iso_init();
|
|
|
|
iso_set_msgs_severities("NEVER", "ALL", "");
|
2007-12-15 15:55:44 +00:00
|
|
|
result = iso_image_new("volume_id", &image);
|
|
|
|
if (result < 0) {
|
|
|
|
printf ("Error creating image\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2007-12-23 15:16:26 +00:00
|
|
|
|
2007-12-15 15:55:44 +00:00
|
|
|
result = iso_tree_add_dir_rec(image, iso_image_get_root(image), argv[1]);
|
|
|
|
if (result < 0) {
|
|
|
|
printf ("Error adding directory %d\n", result);
|
|
|
|
return 1;
|
|
|
|
}
|
2007-12-23 15:16:26 +00:00
|
|
|
|
2007-12-15 15:55:44 +00:00
|
|
|
ecma119 = calloc(1, sizeof(Ecma119Image));
|
2007-12-19 23:25:25 +00:00
|
|
|
iso_rbtree_new(iso_file_src_cmp, &(ecma119->files));
|
2007-12-15 15:55:44 +00:00
|
|
|
ecma119->iso_level = 1;
|
2007-12-23 15:16:26 +00:00
|
|
|
ecma119->rockridge = 1;
|
2007-12-17 20:12:51 +00:00
|
|
|
ecma119->image = image;
|
2007-12-23 15:16:26 +00:00
|
|
|
ecma119->input_charset = strdup("UTF-8");
|
|
|
|
|
2007-12-15 15:55:44 +00:00
|
|
|
/* create low level tree */
|
2007-12-17 22:22:19 +00:00
|
|
|
result = ecma119_tree_create(ecma119);
|
2007-12-15 15:55:44 +00:00
|
|
|
if (result < 0) {
|
|
|
|
printf ("Error creating ecma-119 tree: %d\n", result);
|
|
|
|
return 1;
|
|
|
|
}
|
2007-12-23 15:16:26 +00:00
|
|
|
|
2007-12-15 15:55:44 +00:00
|
|
|
printf("================= ECMA-119 TREE =================\n");
|
2007-12-23 15:16:26 +00:00
|
|
|
print_dir(ecma119->root, 0);
|
|
|
|
printf("\n\n");
|
|
|
|
|
2007-12-15 17:40:33 +00:00
|
|
|
ecma119_node_free(ecma119->root);
|
2008-01-12 01:43:07 +00:00
|
|
|
iso_rbtree_destroy(ecma119->files, iso_file_src_free);
|
|
|
|
free(ecma119->input_charset);
|
|
|
|
free(ecma119);
|
2007-12-15 15:55:44 +00:00
|
|
|
iso_image_unref(image);
|
2008-01-19 01:48:12 +00:00
|
|
|
iso_finish();
|
2007-12-23 15:16:26 +00:00
|
|
|
return 0;
|
2007-12-15 15:55:44 +00:00
|
|
|
}
|