diff --git a/demo/iso.c b/demo/iso.c index 4c30dd1..5808bcd 100644 --- a/demo/iso.c +++ b/demo/iso.c @@ -130,6 +130,7 @@ int main(int argc, char **argv) iso_image_set_msgs_severities(image, "NEVER", "ALL", ""); iso_tree_set_follow_symlinks(image, 0); iso_tree_set_ignore_hidden(image, 0); + iso_tree_set_ignore_special(image, 0); iso_tree_set_stop_on_error(image, 0); result = iso_tree_add_dir_rec(image, iso_image_get_root(image), argv[optind]); diff --git a/src/image.h b/src/image.h index c73798b..a2ebd28 100644 --- a/src/image.h +++ b/src/image.h @@ -45,6 +45,16 @@ struct Iso_Image_Rec_Opts * always cause a stop */ unsigned int stop_on_error : 1; + + /** + * Flags that determine what special files should be ignore. It is a + * bitmask: + * bit0: ignore FIFOs + * bit1: ignore Sockets + * bit2: ignore char devices + * bit3: ignore block devices + */ + int ignore_special; /** * Files to exclude diff --git a/src/libisofs.h b/src/libisofs.h index 75033cb..65c9993 100644 --- a/src/libisofs.h +++ b/src/libisofs.h @@ -1174,6 +1174,27 @@ void iso_tree_set_ignore_hidden(IsoImage *image, int skip); */ int iso_tree_get_ignore_hidden(IsoImage *image); +/** + * Set whether to skip or not special files. Default behavior is to not skip + * them. Note that, despite of this setting, special files won't never be added + * to an image unless RR extensions were enabled. + * + * @param skip + * Bitmask to determine what kind of special files will be skipped: + * bit0: ignore FIFOs + * bit1: ignore Sockets + * bit2: ignore char devices + * bit3: ignore block devices + */ +void iso_tree_set_ignore_special(IsoImage *image, int skip); + +/** + * Get current setting for ignore_special. + * + * @see iso_tree_set_ignore_special + */ +int iso_tree_get_ignore_special(IsoImage *image); + /** * Set whether to stop or not when an error happens when adding recursively a * directory to the iso tree. Default value is to skip file and continue. diff --git a/src/tree.c b/src/tree.c index 5b73a79..de16978 100644 --- a/src/tree.c +++ b/src/tree.c @@ -335,6 +335,33 @@ int iso_tree_get_ignore_hidden(IsoImage *image) return image->recOpts.ignore_hidden; } +/** + * Set whether to skip or not special files. Default behavior is to not skip + * them. Note that, despite of this setting, special files won't never be added + * to an image unless RR extensions were enabled. + * + * @param skip + * Bitmask to determine what kind of special files will be skipped: + * bit0: ignore FIFOs + * bit1: ignore Sockets + * bit2: ignore char devices + * bit3: ignore block devices + */ +void iso_tree_set_ignore_special(IsoImage *image, int skip) +{ + image->recOpts.ignore_special = skip & 0x0F; +} + +/** + * Get current setting for ignore_special. + * + * @see iso_tree_set_ignore_special + */ +int iso_tree_get_ignore_special(IsoImage *image) +{ + return image->recOpts.ignore_special; +} + /** * Set whether to stop or not when an error happens when adding recursively a * directory to the iso tree. Default value is to skip file and continue. @@ -440,6 +467,32 @@ int check_hidden(IsoImage *image, const char *name) return (image->recOpts.ignore_hidden && name[0] == '.'); } +static +int check_special(IsoImage *image, IsoFileSource *file) +{ + if (image->recOpts.ignore_special != 0) { + struct stat info; + int ret; + ret = iso_file_source_lstat(file, &info); + if (ret < 0) { + return 0; /* TODO what to do here */ + } + switch(info.st_mode & S_IFMT) { + case S_IFBLK: + return image->recOpts.ignore_special & 0x08 ? 1 : 0; + case S_IFCHR: + return image->recOpts.ignore_special & 0x04 ? 1 : 0; + case S_IFSOCK: + return image->recOpts.ignore_special & 0x02 ? 1 : 0; + case S_IFIFO: + return image->recOpts.ignore_special & 0x01 ? 1 : 0; + default: + return 0; + } + } + return 0; +} + /** * Recursively add a given directory to the image tree. * @@ -478,6 +531,9 @@ int iso_add_dir_src_rec(IsoImage *image, IsoDir *parent, IsoFileSource *dir) } else if (check_hidden(image, name)) { iso_msg_debug(image->messenger, "Skipping hidden file %s", path); action = 2; + } else if (check_special(image, file)) { + iso_msg_debug(image->messenger, "Skipping special file %s", path); + action = 2; } else { iso_msg_debug(image->messenger, "Adding file %s", path); action = 1;