2007-12-04 21:33:40 +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.
|
|
|
|
*/
|
|
|
|
|
2009-01-16 12:24:30 +00:00
|
|
|
/* ts A90116 : libisofs.h eventually defines aaip_xinfo_func */
|
|
|
|
#include "libisofs.h"
|
|
|
|
|
2007-12-04 21:33:40 +00:00
|
|
|
#include "builder.h"
|
|
|
|
#include "node.h"
|
|
|
|
#include "fsource.h"
|
|
|
|
|
2009-01-23 08:32:32 +00:00
|
|
|
/* ts A90121 : needed for image->builder_ignore_acl */
|
|
|
|
#include "image.h"
|
|
|
|
|
2007-12-04 21:33:40 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2007-12-09 17:47:29 +00:00
|
|
|
#include <limits.h>
|
2007-12-04 21:33:40 +00:00
|
|
|
|
2009-02-07 20:00:43 +00:00
|
|
|
/* ts A90207 */
|
|
|
|
#ifdef Libisofs_with_aaiP
|
|
|
|
#include "aaip_0_2.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-12-04 21:33:40 +00:00
|
|
|
void iso_node_builder_ref(IsoNodeBuilder *builder)
|
|
|
|
{
|
|
|
|
++builder->refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void iso_node_builder_unref(IsoNodeBuilder *builder)
|
|
|
|
{
|
|
|
|
if (--builder->refcount == 0) {
|
|
|
|
/* free private data */
|
|
|
|
builder->free(builder);
|
|
|
|
free(builder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2007-12-28 21:10:17 +00:00
|
|
|
int default_create_file(IsoNodeBuilder *builder, IsoImage *image,
|
2007-12-09 17:47:29 +00:00
|
|
|
IsoFileSource *src, IsoFile **file)
|
2007-12-04 21:33:40 +00:00
|
|
|
{
|
2008-01-26 15:10:23 +00:00
|
|
|
int ret;
|
2007-12-04 21:33:40 +00:00
|
|
|
struct stat info;
|
|
|
|
IsoStream *stream;
|
|
|
|
IsoFile *node;
|
2008-01-26 15:10:23 +00:00
|
|
|
char *name;
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-04 21:33:40 +00:00
|
|
|
if (builder == NULL || src == NULL || file == NULL) {
|
|
|
|
return ISO_NULL_POINTER;
|
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2008-01-26 15:10:23 +00:00
|
|
|
ret = iso_file_source_stat(src, &info);
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
2007-12-04 21:33:40 +00:00
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-04 21:33:40 +00:00
|
|
|
/* this will fail if src is a dir, is not accessible... */
|
2008-01-26 15:10:23 +00:00
|
|
|
ret = iso_file_source_stream_new(src, &stream);
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
2007-12-04 21:33:40 +00:00
|
|
|
}
|
2008-03-08 20:45:19 +00:00
|
|
|
|
|
|
|
/* take a ref to the src, as stream has taken our ref */
|
|
|
|
iso_file_source_ref(src);
|
2008-01-26 15:10:23 +00:00
|
|
|
|
|
|
|
name = iso_file_source_get_name(src);
|
|
|
|
ret = iso_node_new_file(name, stream, &node);
|
|
|
|
if (ret < 0) {
|
2007-12-04 21:33:40 +00:00
|
|
|
iso_stream_unref(stream);
|
2008-01-26 15:10:23 +00:00
|
|
|
free(name);
|
|
|
|
return ret;
|
2007-12-04 21:33:40 +00:00
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-04 21:33:40 +00:00
|
|
|
/* fill node fields */
|
2008-01-26 15:10:23 +00:00
|
|
|
iso_node_set_permissions((IsoNode*)node, info.st_mode);
|
|
|
|
iso_node_set_uid((IsoNode*)node, info.st_uid);
|
|
|
|
iso_node_set_gid((IsoNode*)node, info.st_gid);
|
|
|
|
iso_node_set_atime((IsoNode*)node, info.st_atime);
|
|
|
|
iso_node_set_mtime((IsoNode*)node, info.st_mtime);
|
|
|
|
iso_node_set_ctime((IsoNode*)node, info.st_ctime);
|
|
|
|
iso_node_set_uid((IsoNode*)node, info.st_uid);
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-04 21:33:40 +00:00
|
|
|
*file = node;
|
|
|
|
return ISO_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-12-09 17:47:29 +00:00
|
|
|
static
|
2007-12-28 21:10:17 +00:00
|
|
|
int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
|
2007-12-09 17:47:29 +00:00
|
|
|
IsoFileSource *src, IsoNode **node)
|
|
|
|
{
|
2008-01-26 15:10:23 +00:00
|
|
|
int ret;
|
2007-12-09 17:47:29 +00:00
|
|
|
struct stat info;
|
|
|
|
IsoNode *new;
|
|
|
|
char *name;
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2009-01-16 12:24:30 +00:00
|
|
|
#ifdef Libisofs_with_aaiP
|
|
|
|
unsigned char *aa_string;
|
2009-02-07 20:00:43 +00:00
|
|
|
char *a_text = NULL, *d_text = NULL;
|
2009-01-16 12:24:30 +00:00
|
|
|
#endif /* Libisofs_with_aaiP */
|
|
|
|
|
2007-12-09 17:47:29 +00:00
|
|
|
if (builder == NULL || src == NULL || node == NULL) {
|
|
|
|
return ISO_NULL_POINTER;
|
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-09 17:47:29 +00:00
|
|
|
/* get info about source */
|
2008-01-20 15:56:41 +00:00
|
|
|
if (iso_tree_get_follow_symlinks(image)) {
|
2008-01-26 15:10:23 +00:00
|
|
|
ret = iso_file_source_stat(src, &info);
|
2007-12-11 21:47:04 +00:00
|
|
|
} else {
|
2008-01-26 15:10:23 +00:00
|
|
|
ret = iso_file_source_lstat(src, &info);
|
2007-12-11 21:47:04 +00:00
|
|
|
}
|
2008-01-26 15:10:23 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
2007-12-09 17:47:29 +00:00
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2008-01-20 15:56:41 +00:00
|
|
|
name = iso_file_source_get_name(src);
|
2007-12-09 17:47:29 +00:00
|
|
|
new = NULL;
|
2008-01-20 15:56:41 +00:00
|
|
|
|
2007-12-09 17:47:29 +00:00
|
|
|
switch (info.st_mode & S_IFMT) {
|
|
|
|
case S_IFREG:
|
|
|
|
{
|
|
|
|
/* source is a regular file */
|
|
|
|
IsoStream *stream;
|
|
|
|
IsoFile *file;
|
2008-01-26 15:10:23 +00:00
|
|
|
ret = iso_file_source_stream_new(src, &stream);
|
|
|
|
if (ret < 0) {
|
|
|
|
break;
|
2007-12-09 17:47:29 +00:00
|
|
|
}
|
2007-12-11 21:47:04 +00:00
|
|
|
/* take a ref to the src, as stream has taken our ref */
|
|
|
|
iso_file_source_ref(src);
|
2008-01-26 15:10:23 +00:00
|
|
|
|
|
|
|
/* create the file */
|
|
|
|
ret = iso_node_new_file(name, stream, &file);
|
|
|
|
if (ret < 0) {
|
2007-12-09 17:47:29 +00:00
|
|
|
iso_stream_unref(stream);
|
|
|
|
}
|
|
|
|
new = (IsoNode*) file;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case S_IFDIR:
|
|
|
|
{
|
|
|
|
/* source is a directory */
|
2008-01-26 15:10:23 +00:00
|
|
|
IsoDir *dir;
|
|
|
|
ret = iso_node_new_dir(name, &dir);
|
|
|
|
new = (IsoNode*)dir;
|
2007-12-09 17:47:29 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case S_IFLNK:
|
|
|
|
{
|
|
|
|
/* source is a symbolic link */
|
|
|
|
char dest[PATH_MAX];
|
|
|
|
IsoSymlink *link;
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2008-01-26 15:10:23 +00:00
|
|
|
ret = iso_file_source_readlink(src, dest, PATH_MAX);
|
|
|
|
if (ret < 0) {
|
|
|
|
break;
|
2007-12-09 17:47:29 +00:00
|
|
|
}
|
2008-01-26 15:10:23 +00:00
|
|
|
ret = iso_node_new_symlink(name, strdup(dest), &link);
|
2007-12-09 17:47:29 +00:00
|
|
|
new = (IsoNode*) link;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case S_IFSOCK:
|
|
|
|
case S_IFBLK:
|
|
|
|
case S_IFCHR:
|
|
|
|
case S_IFIFO:
|
|
|
|
{
|
|
|
|
/* source is an special file */
|
|
|
|
IsoSpecial *special;
|
2008-01-26 15:10:23 +00:00
|
|
|
ret = iso_node_new_special(name, info.st_mode, info.st_rdev,
|
|
|
|
&special);
|
2007-12-09 17:47:29 +00:00
|
|
|
new = (IsoNode*) special;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-01-26 15:10:23 +00:00
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
free(name);
|
|
|
|
return ret;
|
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-09 17:47:29 +00:00
|
|
|
/* fill fields */
|
2009-02-07 20:00:43 +00:00
|
|
|
iso_node_set_perms_internal(new, info.st_mode, 1);
|
2008-01-26 15:10:23 +00:00
|
|
|
iso_node_set_uid(new, info.st_uid);
|
|
|
|
iso_node_set_gid(new, info.st_gid);
|
|
|
|
iso_node_set_atime(new, info.st_atime);
|
|
|
|
iso_node_set_mtime(new, info.st_mtime);
|
|
|
|
iso_node_set_ctime(new, info.st_ctime);
|
|
|
|
iso_node_set_uid(new, info.st_uid);
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2009-01-16 12:24:30 +00:00
|
|
|
#ifdef Libisofs_with_aaiP
|
|
|
|
|
2009-02-07 20:00:43 +00:00
|
|
|
/* ts A90207 */
|
|
|
|
/* Eventually set S_IRWXG from ACL */
|
|
|
|
if (image->builder_ignore_acl) {
|
|
|
|
ret = iso_file_source_get_aa_string(src, &aa_string, 4);
|
|
|
|
if (aa_string != NULL)
|
|
|
|
iso_aa_get_acl_text(aa_string, info.st_mode, &a_text, &d_text, 16);
|
|
|
|
if (a_text != NULL) {
|
|
|
|
aaip_cleanout_st_mode(a_text, &(info.st_mode), 4 | 16);
|
|
|
|
iso_node_set_perms_internal(new, info.st_mode, 1);
|
|
|
|
}
|
|
|
|
iso_aa_get_acl_text(aa_string, info.st_mode, &a_text, &d_text,
|
|
|
|
1 << 15); /* free ACL texts */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ts A90115 */
|
2009-01-16 12:24:30 +00:00
|
|
|
/* obtain ownership of eventual AA string */
|
2009-01-23 08:32:32 +00:00
|
|
|
ret = iso_file_source_get_aa_string(src, &aa_string,
|
|
|
|
1 | (image->builder_ignore_acl << 1) |
|
|
|
|
(image->builder_ignore_ea << 2 ));
|
2009-01-16 12:24:30 +00:00
|
|
|
if (ret == 1 && aa_string != NULL) {
|
|
|
|
ret = iso_node_add_xinfo(new, aaip_xinfo_func, aa_string);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Libisofs_with_aaiP */
|
|
|
|
|
2009-02-07 20:00:43 +00:00
|
|
|
*node = new;
|
|
|
|
|
2007-12-09 17:47:29 +00:00
|
|
|
return ISO_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2007-12-04 21:33:40 +00:00
|
|
|
void default_free(IsoNodeBuilder *builder)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int iso_node_basic_builder_new(IsoNodeBuilder **builder)
|
|
|
|
{
|
|
|
|
IsoNodeBuilder *b;
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-04 21:33:40 +00:00
|
|
|
if (builder == NULL) {
|
|
|
|
return ISO_NULL_POINTER;
|
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-04 21:33:40 +00:00
|
|
|
b = malloc(sizeof(IsoNodeBuilder));
|
|
|
|
if (b == NULL) {
|
2008-01-20 21:28:27 +00:00
|
|
|
return ISO_OUT_OF_MEM;
|
2007-12-04 21:33:40 +00:00
|
|
|
}
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-04 21:33:40 +00:00
|
|
|
b->refcount = 1;
|
2007-12-09 17:47:29 +00:00
|
|
|
b->create_file_data = NULL;
|
|
|
|
b->create_node_data = NULL;
|
2007-12-04 21:33:40 +00:00
|
|
|
b->create_file = default_create_file;
|
2007-12-09 17:47:29 +00:00
|
|
|
b->create_node = default_create_node;
|
2007-12-04 21:33:40 +00:00
|
|
|
b->free = default_free;
|
2007-12-28 21:10:17 +00:00
|
|
|
|
2007-12-04 21:33:40 +00:00
|
|
|
*builder = b;
|
|
|
|
return ISO_SUCCESS;
|
|
|
|
}
|