diff options
author | Zhihao Cheng <chengzhihao1@huawei.com> | 2024-11-11 16:36:33 +0800 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2024-11-11 10:32:45 +0100 |
commit | 03ec75b9e6ad4cb372f86d1581c2b1b2ef987c72 (patch) | |
tree | 4d5e45faa1772cbb5b07e5dc0a78a4398de11d11 /ubifs-utils/mkfs.ubifs | |
parent | e7e19cd9d8cc0f54ca463c4aebf7c4ef5e4f84f8 (diff) |
ubifs-utils: Decouple mkfs.ubifs.h out of other modules
Header file mkfs.ubifs.h is included in other modules(eg. compr.c, lpt.c,
fscrypt.h, sign.c), decouple it out of other modules.
There are two parts in mkfs.ubifs.h:
1. common functions, for example dbg_msg, err_msg and write_leb, move
these functions into common/defs.h and common/ubifs.h.
2. devtable related definations, move them into a new header file
common/devtable.h.
Splitting common functions from mkfs.ubifs.h is also a preparation for
importing libubifs(from linux kernel) to replace current UBIFS libs.
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'ubifs-utils/mkfs.ubifs')
-rw-r--r-- | ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 21 | ||||
-rw-r--r-- | ubifs-utils/mkfs.ubifs/mkfs.ubifs.h | 158 |
2 files changed, 19 insertions, 160 deletions
diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c index f4cb512..0304ae7 100644 --- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c @@ -22,10 +22,17 @@ #define _XOPEN_SOURCE 500 /* For realpath() */ -#include "mkfs.ubifs.h" +#include <stdio.h> +#include <stdlib.h> +#include <libgen.h> +#include <getopt.h> +#include <dirent.h> #include <crc32.h> -#include "common.h" +#include <uuid.h> +#include <linux/fs.h> #include <sys/types.h> +#include <sys/stat.h> +#include <sys/ioctl.h> #ifdef WITH_XATTR #include <sys/xattr.h> #endif @@ -39,8 +46,18 @@ #include <zstd.h> #endif +/* common.h requires the PROGRAM_NAME macro */ +#define PROGRAM_NAME "mkfs.ubifs" +#include "common.h" +#include "defs.h" #include "crypto.h" #include "fscrypt.h" +#include "ubifs.h" +#include "lpt.h" +#include "compr.h" +#include "key.h" +#include "sign.h" +#include "devtable.h" /* Size (prime number) of hash table for link counting */ #define HASH_TABLE_SIZE 10099 diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.h b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.h deleted file mode 100644 index 5690984..0000000 --- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.h +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (C) 2008 Nokia Corporation. - * Copyright (C) 2008 University of Szeged, Hungary - * - * This program is free software; 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. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Artem Bityutskiy - * Adrian Hunter - * Zoltan Sogor - */ - -#ifndef __MKFS_UBIFS_H__ -#define __MKFS_UBIFS_H__ - -#include <unistd.h> -#include <stdlib.h> -#include <stdio.h> -#include <limits.h> -#include <string.h> -#include <stdint.h> -#include <endian.h> -#include <byteswap.h> -#include <linux/types.h> -#include <linux/fs.h> - -#include <getopt.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/ioctl.h> -#include <fcntl.h> -#include <dirent.h> -#include <errno.h> -#include <libgen.h> -#include <ctype.h> -#include <uuid.h> -#include <sys/file.h> - -#ifdef WITH_CRYPTO -#include <openssl/rand.h> -#endif - -#include <mtd/ubifs-media.h> - -/* common.h requires the PROGRAM_NAME macro */ -#define PROGRAM_NAME "mkfs.ubifs" -#include "common.h" - -#include "libubi.h" -#include "defs.h" -#include "crc16.h" -#include "ubifs.h" -#include "key.h" -#include "lpt.h" -#include "compr.h" -#include "sign.h" - -/* - * Compression flags are duplicated so that compr.c can compile without ubifs.h. - * Here we make sure they are the same. - */ -#if MKFS_UBIFS_COMPR_NONE != UBIFS_COMPR_NONE -#error MKFS_UBIFS_COMPR_NONE != UBIFS_COMPR_NONE -#endif -#if MKFS_UBIFS_COMPR_LZO != UBIFS_COMPR_LZO -#error MKFS_UBIFS_COMPR_LZO != UBIFS_COMPR_LZO -#endif -#if MKFS_UBIFS_COMPR_ZLIB != UBIFS_COMPR_ZLIB -#error MKFS_UBIFS_COMPR_ZLIB != UBIFS_COMPR_ZLIB -#endif -#if MKFS_UBIFS_COMPR_ZSTD != UBIFS_COMPR_ZSTD -#error MKFS_UBIFS_COMPR_ZSTD != UBIFS_COMPR_ZSTD -#endif - -extern int verbose; -extern int debug_level; - -#define dbg_msg(lvl, fmt, ...) do {if (debug_level >= lvl) \ - printf("mkfs.ubifs: %s: " fmt "\n", __FUNCTION__, ##__VA_ARGS__); \ -} while(0) - -#define err_msg(fmt, ...) ({ \ - fprintf(stderr, "Error: " fmt "\n", ##__VA_ARGS__); \ - -1; \ -}) - -#define sys_err_msg(fmt, ...) ({ \ - int err_ = errno; \ - fprintf(stderr, "Error: " fmt "\n", ##__VA_ARGS__); \ - fprintf(stderr, " %s (error %d)\n", strerror(err_), err_); \ - -1; \ -}) - -/** - * struct path_htbl_element - an element of the path hash table. - * @path: the UBIFS path the element describes (the key of the element) - * @name_htbl: one more (nested) hash table containing names of all - * files/directories/device nodes which should be created at this - * path - * - * See device table handling for more information. - */ -struct path_htbl_element { - const char *path; - struct hashtable *name_htbl; -}; - -/** - * struct name_htbl_element - an element in the name hash table - * @name: name of the file/directory/device node (the key of the element) - * @mode: accsess rights and file type - * @uid: user ID - * @gid: group ID - * @major: device node major number - * @minor: device node minor number - * - * This is an element of the name hash table. Name hash table sits in the path - * hash table elements and describes file names which should be created/changed - * at this path. - */ -struct name_htbl_element { - const char *name; - unsigned int mode; - unsigned int uid; - unsigned int gid; - dev_t dev; -}; - -extern struct ubifs_info info_; - -struct hashtable_itr; - -int write_leb(int lnum, int len, void *buf); -int parse_devtable(const char *tbl_file); -struct path_htbl_element *devtbl_find_path(const char *path); -struct name_htbl_element *devtbl_find_name(struct path_htbl_element *ph_elt, - const char *name); -int override_attributes(struct stat *st, struct path_htbl_element *ph_elt, - struct name_htbl_element *nh_elt); -struct name_htbl_element * -first_name_htbl_element(struct path_htbl_element *ph_elt, - struct hashtable_itr **itr); -struct name_htbl_element * -next_name_htbl_element(struct path_htbl_element *ph_elt, - struct hashtable_itr **itr); -void free_devtable_info(void); - -#endif |