erofs-utils: introduce exclude dirs and files
PATCH 1/1 erofs-utils: introduce exclude dirs and files
From: Li Guifu <[email protected]>
Add support exlcude directory when build image with long option arg --exclude-path=dir1/dir2,dir11/dir22 or short option arg -e dir1/dir2,dir11/dir22 that seperated by ','
Signed-off-by Li Guifu <[email protected]>
--- include/erofs/exclude.h | 28 ++++++++ lib/Makefile.am | 2 +- lib/exclude.c | 149 ++++++++++++++++++++++++++++++++++++++++ lib/inode.c | 10 +++ mkfs/main.c | 13 +++- 5 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 include/erofs/exclude.h create mode 100644 lib/exclude.c
include/erofs/exclude.h new file +28 -0
@@ -0,0 +1,28 @@ +// 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 + +struct rule_entry { +struct list_head list; +struct list_head hlist; +char *name; +}; + +void erofs_init_rules (void ); +void erofs_free_rules (void ); +int erofs_parse_exclude_path (const char *args); +struct rule_entry *erofs_pattern_matched (const char *s); +struct rule_entry *erofs_entry_matched (struct rule_entry *e, +const char *s,unsigned int len); + +static inline int erofs_is_pattern_end (struct rule_entry *e) +{ +return list_empty (&e->hlist); +} +#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 +149 -0
149 lines not on this page · raw message
lib/inode.c +10 -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;
@@ -825,6 +826,7 @@ struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir)DIR *_dir;struct dirent *dp;struct erofs_dentry *d; +struct rule_entry *e; ret =erofs_prepare_xattr_ibody (dir->i_srcpath, &dir->i_xattrs);if (ret <0 )
@@ -863,6 +865,7 @@ struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir)return ERR_PTR (-errno); } + e =erofs_pattern_matched (dir->i_srcpath +strlen (cfg.c_src_path));while (1 ) {/* * set errno to 0 before calling readdir() in order to
@@ -876,7 +879,14 @@ struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir)if (is_dot_dotdot (dp->d_name) || !strncmp (dp->d_name,"lost+found" ,strlen ("lost+found" )))continue ; +if (e) { +struct rule_entry *le; + le =erofs_entry_matched (e, dp->d_name, +strlen (dp->d_name)); +if (le &&erofs_is_pattern_end (le)) +continue ; + } d =erofs_d_alloc (dir, dp->d_name);if (IS_ERR (d)) { ret =PTR_ERR (d);
mkfs/main.c +12 -1
@@ -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,7 @@static struct option long_options[] = { {"help" , no_argument,0 ,1 }, + {"exclude-path" , required_argument,NULL ,'e' }, {0 ,0 ,0 ,0 }, };
@@ -127,7 +129,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])char *endptr;int opt, i; -while ((opt =getopt_long (argc, argv,"d:x:z:E:T:" , +while ((opt =getopt_long (argc, argv,"d:x:z:E:T:e:" , long_options,NULL )) !=-1 ) {switch (opt) {case 'z' :
@@ -178,6 +180,13 @@ static int mkfs_parse_options_cfg(int argc, char *argv[]) }break ; +case 'e' : +if (erofs_parse_exclude_path (optarg)) { +usage (); +exit (0 ); + } +break ; +case 1 :usage ();exit (0 );
@@ -334,6 +343,7 @@ int main(int argc, char **argv)struct timeval t;erofs_init_configure (); +erofs_init_rules ();fprintf (stderr,"%s %s\n" ,basename (argv[0 ]), cfg.c_version); cfg.c_legacy_compress = false;
@@ -429,6 +439,7 @@ exit:z_erofs_compress_exit ();dev_close ();erofs_exit_configure (); +erofs_free_rules ();if (err) { erofs_err("\tCould not format the device : %s\n",
Signature · 1 line
2.17.1