erofs-utils: introduce exclude dirs and files
PATCH v7 1/1 erofs-utils: introduce exclude dirs and files
From: Li GuiFu <[email protected]>
Add excluded file feature "--exclude-path=" and '--exclude-regex=', which can be used to build EROFS image without some user specific files or dirs. Note that you may give multiple '--exclude-path' or '--exclude-regex' options.
---
change since v7:
- fux as comment by Gao Xiang
- fix missing regex free
- update comment of option
include/erofs/exclude.h | 26 ++++++++ lib/Makefile.am | 2 +- lib/exclude.c | 141 ++++++++++++++++++++++++++++++++++++++++ lib/inode.c | 5 ++ man/mkfs.erofs.1 | 8 +++ mkfs/main.c | 36 ++++++++-- 6 files changed, 211 insertions(+), 7 deletions(-) create mode 100644 include/erofs/exclude.h create mode 100644 lib/exclude.c
include/erofs/exclude.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* erofs-utils/include/erofs/exclude.h +* +* Created by Li Guifu <[email protected]> +*/ +#ifndef __EROFS_EXCLUDE_H +#define __EROFS_EXCLUDE_H +#include <sys/types.h> +#include <regex.h> + +struct erofs_exclude_rule { +struct list_head list; + +char *pattern;/* save original pattern for exact or regex match */ +regex_t reg; +}; + +void erofs_exclude_set_root (const char *rootdir); +void erofs_cleanup_exclude_rules (void ); + +int erofs_parse_exclude_path (const char *args,bool is_regex); +struct erofs_exclude_rule *erofs_is_exclude_path (const char *dir, +const char *name); +#endif +
lib/Makefile.am +1 -1
@@ -3,7 +3,7 @@ noinst_LTLIBRARIES = liberofs.la liberofs_la_SOURCES = config.c io.c cache.c inode.c xattr.c \ - compress.c compressor.c + compress.c compressor.c exclude.c liberofs_la_CFLAGS = -Wall -Werror -I$(top_srcdir)/include if ENABLE_LZ4 liberofs_la_CFLAGS += ${LZ4_CFLAGS}
lib/exclude.c new file +141 -0
141 lines not on this page · raw message
lib/inode.c +5 -0
@@ -20,6 +20,7 @@#include "erofs/io.h" #include "erofs/compress.h" #include "erofs/xattr.h" +#include "erofs/exclude.h" struct erofs_sb_info sbi;
@@ -877,6 +878,10 @@ struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir) !strncmp(dp->d_name, "lost+found", strlen("lost+found"))) continue; +/* skip if it's a exclude file */ +if (erofs_is_exclude_path (dir->i_srcpath, dp->d_name)) +continue ; + d =erofs_d_alloc (dir, dp->d_name);if (IS_ERR (d)) { ret =PTR_ERR (d);
man/mkfs.erofs.1 +8 -0
@@ -52,6 +52,14 @@ Forcely generate extended inodes (64-byte inodes) to output. Set all files to the given UNIX timestamp. Reproducible builds requires setting all to a specific one. .TP +.BI "\-\-exclude-path=" path +Ignore file that matches the exact literal path. +You may give multiple `--exclude-path' options. +.TP +.BI "\-\-exclude-regex=" path +Ignore file that matches the exact path included in the regex expression +You may give multiple `--exclude-regex` options +.TP .B \-\-help Display this help and exit. .SH AUTHOR
mkfs/main.c +30 -6
@@ -21,6 +21,7 @@#include "erofs/io.h" #include "erofs/compress.h" #include "erofs/xattr.h" +#include "erofs/exclude.h" #ifdef HAVE_LIBUUID #include <uuid/uuid.h>
@@ -30,6 +31,8 @@static struct option long_options[] = { {"help" , no_argument,0 ,1 }, + {"exclude-path" , required_argument,NULL ,2 }, + {"exclude-regex" , required_argument,NULL ,3 }, {0 ,0 ,0 ,0 }, };
@@ -50,12 +53,14 @@ static void usage(void) {fputs ("usage: [options] FILE DIRECTORY\n\n" "Generate erofs image from DIRECTORY to FILE, and [options] are:\n" -" -zX[,Y] X=compressor (Y=compression level, optional)\n" -" -d# set output message level to # (maximum 9)\n" -" -x# set xattr tolerance to # (< 0, disable xattrs; default 2)\n" -" -EX[,...] X=extended options\n" -" -T# set a fixed UNIX timestamp # to all files\n" -" --help display this help and exit\n" +" -zX[,Y] X=compressor (Y=compression level, optional)\n" +" -d# set output message level to # (maximum 9)\n" +" -x# set xattr tolerance to # (< 0, disable xattrs; default 2)\n" +" -EX[,...] X=extended options\n" +" -T# set a fixed UNIX timestamp # to all files\n" +" --exclude-path=X avoid including file X (X = exact literal path)\n" +" --exclude-regex=X avoid including file X (X = exact regex path)\n" +" --help display this help and exit\n" "\nAvailable compressors are: " , stderr);print_available_compressors (stderr,", " ); }
@@ -178,6 +183,23 @@ static int mkfs_parse_options_cfg(int argc, char *argv[]) }break ; +case 2 : + opt =erofs_parse_exclude_path (optarg, false); +if (opt) { +erofs_err ("failed to parse exclude path: %s" , +erofs_strerror (opt)); +return opt; + } +break ; +case 3 : + opt =erofs_parse_exclude_path (optarg, true); +if (opt) { +erofs_err ("failed to parse exclude path: %s" , +erofs_strerror (opt)); +return opt; + } +break ; +case 1 :usage ();exit (0 );
@@ -372,6 +394,7 @@ int main(int argc, char **argv) }erofs_show_config (); +erofs_exclude_set_root (cfg.c_src_path); sb_bh =erofs_buffer_init ();if (IS_ERR (sb_bh)) {
@@ -428,6 +451,7 @@ int main(int argc, char **argv) exit:z_erofs_compress_exit ();dev_close (); +erofs_cleanup_exclude_rules ();erofs_exit_configure ();if (err) {
Signature · 1 line
2.17.1
Gao Xiang
AppliedHi Guifu,
Quoted 9 lines · Li Guifu
From: Li GuiFu <[email protected]>
Add excluded file feature "--exclude-path=" and '--exclude-regex=', which can be used to build EROFS image without some user specific files or dirs. Note that you may give multiple '--exclude-path' or '--exclude-regex' options.
Signed-off-by Gao Xiang <[email protected]>Signed-off-by Li Guifu <[email protected]>
Applied to experimental branch with the following minor updates.
If you have more suggestions, please kindly point out. Or I will push it out to dev branch later.
Thanks,
Gao Xiang
From 8cdf49bc529d05e741d540b4e5018e2b4215c90a Mon Sep 17 00:00:00 2001
From: Li Guifu <[email protected]>
Date: Tue, 18 Feb 2020 22:30:47 +0800
Subject: [PATCH v8] erofs-utils: introduce exclude dirs and files
Add excluded file feature "--exclude-path=" and '--exclude-regex=', which can be used to build EROFS image without some user specific files or dirs.
The implementation is kept as simple as possible for now.
Note that you may give multiple '--exclude-path' and '--exclude-regex' options.
--- include/erofs/exclude.h | 26 ++++++++ lib/Makefile.am | 2 +- lib/exclude.c | 142 ++++++++++++++++++++++++++++++++++++++++ lib/inode.c | 5 ++ man/mkfs.erofs.1 | 8 +++ mkfs/main.c | 36 ++++++++-- 6 files changed, 211 insertions(+), 8 deletions(-) create mode 100644 include/erofs/exclude.h create mode 100644 lib/exclude.c
include/erofs/exclude.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* erofs-utils/include/erofs/exclude.h +* +* Created by Li Guifu <[email protected]> +*/ +#ifndef __EROFS_EXCLUDE_H +#define __EROFS_EXCLUDE_H +#include <sys/types.h> +#include <regex.h> + +struct erofs_exclude_rule { +struct list_head list; + +char *pattern; +regex_t reg; +}; + +void erofs_exclude_set_root (const char *rootdir); +void erofs_cleanup_exclude_rules (void ); + +int erofs_parse_exclude_path (const char *args,bool is_regex); +struct erofs_exclude_rule *erofs_is_exclude_path (const char *dir, +const char *name); +#endif +
lib/Makefile.am +1 -1
@@ -3,7 +3,7 @@ noinst_LTLIBRARIES = liberofs.la liberofs_la_SOURCES = config.c io.c cache.c inode.c xattr.c \ - compress.c compressor.c + compress.c compressor.c exclude.c liberofs_la_CFLAGS = -Wall -Werror -I$(top_srcdir)/include if ENABLE_LZ4 liberofs_la_CFLAGS += ${LZ4_CFLAGS}
lib/exclude.c new file +142 -0
142 lines not on this page · raw message
lib/inode.c +5 -0
@@ -20,6 +20,7 @@#include "erofs/io.h" #include "erofs/compress.h" #include "erofs/xattr.h" +#include "erofs/exclude.h" struct erofs_sb_info sbi;
@@ -877,6 +878,10 @@ struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir) !strncmp(dp->d_name, "lost+found", strlen("lost+found"))) continue; +/* skip if it's a exclude file */ +if (erofs_is_exclude_path (dir->i_srcpath, dp->d_name)) +continue ; + d =erofs_d_alloc (dir, dp->d_name);if (IS_ERR (d)) { ret =PTR_ERR (d);
man/mkfs.erofs.1 +8 -0
@@ -52,6 +52,14 @@ Forcely generate extended inodes (64-byte inodes) to output. Set all files to the given UNIX timestamp. Reproducible builds requires setting all to a specific one. .TP +.BI "\-\-exclude-path=" path +Ignore file that matches the exact literal path. +You may give multiple `--exclude-path' options. +.TP +.BI "\-\-exclude-regex=" regex +Ignore files that match the given regular expression. +You may give multiple `--exclude-regex` options. +.TP .B \-\-help Display this help and exit. .SH AUTHOR
mkfs/main.c +29 -7
@@ -21,6 +21,7 @@#include "erofs/io.h" #include "erofs/compress.h" #include "erofs/xattr.h" +#include "erofs/exclude.h" #ifdef HAVE_LIBUUID #include <uuid/uuid.h>
@@ -30,6 +31,8 @@static struct option long_options[] = { {"help" , no_argument,0 ,1 }, + {"exclude-path" , required_argument,NULL ,2 }, + {"exclude-regex" , required_argument,NULL ,3 }, {0 ,0 ,0 ,0 }, };
@@ -50,12 +53,14 @@ static void usage(void) {fputs ("usage: [options] FILE DIRECTORY\n\n" "Generate erofs image from DIRECTORY to FILE, and [options] are:\n" -" -zX[,Y] X=compressor (Y=compression level, optional)\n" -" -d# set output message level to # (maximum 9)\n" -" -x# set xattr tolerance to # (< 0, disable xattrs; default 2)\n" -" -EX[,...] X=extended options\n" -" -T# set a fixed UNIX timestamp # to all files\n" -" --help display this help and exit\n" +" -zX[,Y] X=compressor (Y=compression level, optional)\n" +" -d# set output message level to # (maximum 9)\n" +" -x# set xattr tolerance to # (< 0, disable xattrs; default 2)\n" +" -EX[,...] X=extended options\n" +" -T# set a fixed UNIX timestamp # to all files\n" +" --exclude-path=X avoid including file X (X = exact literal path)\n" +" --exclude-regex=X avoid including files that match X (X = regular expression)\n" +" --help display this help and exit\n" "\nAvailable compressors are: " , stderr);print_available_compressors (stderr,", " ); }
@@ -177,7 +182,22 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])return -EINVAL ; }break ; - +case 2 : + opt =erofs_parse_exclude_path (optarg, false); +if (opt) { +erofs_err ("failed to parse exclude path: %s" , +erofs_strerror (opt)); +return opt; + } +break ; +case 3 : + opt =erofs_parse_exclude_path (optarg, true); +if (opt) { +erofs_err ("failed to parse exclude regex: %s" , +erofs_strerror (opt)); +return opt; + } +break ;case 1 :usage ();exit (0 );
@@ -372,6 +392,7 @@ int main(int argc, char **argv) }erofs_show_config (); +erofs_exclude_set_root (cfg.c_src_path); sb_bh =erofs_buffer_init ();if (IS_ERR (sb_bh)) {
@@ -428,6 +449,7 @@ int main(int argc, char **argv) exit:z_erofs_compress_exit ();dev_close (); +erofs_cleanup_exclude_rules ();erofs_exit_configure ();if (err) {
Signature · 1 line
2.17.1
Quoted 13 lines · Gao Xiang
Hi Guifu,
Quoted 9 lines · Li Guifu
From: Li GuiFu <[email protected]>
Add excluded file feature "--exclude-path=" and '--exclude-regex=', which can be used to build EROFS image without some user specific files or dirs. Note that you may give multiple '--exclude-path' or '--exclude-regex' options.
Signed-off-by Gao Xiang <[email protected]>Signed-off-by Li Guifu <[email protected]>
Quoted 8 lines
Applied to experimental branch with the following minor updates.
If you have more suggestions, please kindly point out. Or I will push it out to dev branch later.
Thanks,
Gao Xiang
It looks good