From bc85302b02f8a1af351d05050f9de8a54c68ba09 Mon Sep 17 00:00:00 2001 From: Zhihao Cheng Date: Mon, 11 Nov 2024 16:36:34 +0800 Subject: ubifs-utils: Define PROGRAM_NAME as variable PROGRAM_NAME is defined as a const string "mkfs.ubifs", which won't be suitable for fsck.ubifs. Add 'program_name' member in ubifs_info structure, define PROGRAM_NAME as ubifs_info.program_name. Then, error messages will display right program name if fsck.ubifs is supported. Besides, add 'program_type' member in ubifs_info structure to identify which current program type is, without comparing program name. Signed-off-by: Zhihao Cheng Signed-off-by: David Oberhollenzer --- ubifs-utils/common/crypto.c | 10 +++++++--- ubifs-utils/common/defs.h | 4 ++++ ubifs-utils/common/fscrypt.c | 7 +++++-- ubifs-utils/common/hashtable/hashtable.c | 14 +++++++++----- ubifs-utils/common/lpt.c | 7 +++++-- ubifs-utils/common/ubifs.h | 6 ++++++ ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 3 +++ 7 files changed, 39 insertions(+), 12 deletions(-) diff --git a/ubifs-utils/common/crypto.c b/ubifs-utils/common/crypto.c index 60a67a4..614a16d 100644 --- a/ubifs-utils/common/crypto.c +++ b/ubifs-utils/common/crypto.c @@ -23,10 +23,14 @@ #include #include -#define PROGRAM_NAME "mkfs.ubifs" -#include "common.h" -#include "defs.h" #include "fscrypt.h" +#include "defs.h" +#include "ubifs.h" + +/* common.h requires the PROGRAM_NAME macro */ +extern struct ubifs_info info_; +#define PROGRAM_NAME (info_.program_name) +#include "common.h" static int do_hash(const EVP_MD *md, const unsigned char *in, size_t len, unsigned char *out) { diff --git a/ubifs-utils/common/defs.h b/ubifs-utils/common/defs.h index e1aded0..143f6c6 100644 --- a/ubifs-utils/common/defs.h +++ b/ubifs-utils/common/defs.h @@ -12,6 +12,10 @@ #include #include +#define MKFS_PROGRAM_NAME "mkfs.ubifs" + +enum { MKFS_PROGRAM_TYPE = 0 }; + extern int debug_level; #define dbg_msg(lvl, fmt, ...) do {if (debug_level >= lvl) \ diff --git a/ubifs-utils/common/fscrypt.c b/ubifs-utils/common/fscrypt.c index 94c6c37..cc98963 100644 --- a/ubifs-utils/common/fscrypt.c +++ b/ubifs-utils/common/fscrypt.c @@ -20,11 +20,14 @@ #include -#define PROGRAM_NAME "mkfs.ubifs" -#include "common.h" #include "fscrypt.h" #include "defs.h" +#include "ubifs.h" +/* common.h requires the PROGRAM_NAME macro */ +extern struct ubifs_info info_; +#define PROGRAM_NAME (info_.program_name) +#include "common.h" static __u8 fscrypt_masterkey[FS_MAX_KEY_SIZE]; static struct cipher *fscrypt_cipher; diff --git a/ubifs-utils/common/hashtable/hashtable.c b/ubifs-utils/common/hashtable/hashtable.c index c1f99ed..071afd2 100644 --- a/ubifs-utils/common/hashtable/hashtable.c +++ b/ubifs-utils/common/hashtable/hashtable.c @@ -1,15 +1,19 @@ /* Copyright (C) 2004 Christopher Clark */ -#define PROGRAM_NAME "hashtable" - -#include "common.h" -#include "hashtable.h" -#include "hashtable_private.h" #include #include #include #include +#include "ubifs.h" +#include "hashtable.h" +#include "hashtable_private.h" + +/* common.h requires the PROGRAM_NAME macro */ +extern struct ubifs_info info_; +#define PROGRAM_NAME (info_.program_name) +#include "common.h" + /* Credit for primes table: Aaron Krowne http://br.endernet.org/~akrowne/ diff --git a/ubifs-utils/common/lpt.c b/ubifs-utils/common/lpt.c index 23ffe7f..746fc7d 100644 --- a/ubifs-utils/common/lpt.c +++ b/ubifs-utils/common/lpt.c @@ -24,14 +24,17 @@ #include #endif -#define PROGRAM_NAME "mkfs.ubifs" -#include "common.h" #include "lpt.h" #include "defs.h" #include "ubifs.h" #include "crc16.h" #include "sign.h" +/* common.h requires the PROGRAM_NAME macro */ +extern struct ubifs_info info_; +#define PROGRAM_NAME (info_.program_name) +#include "common.h" + /** * do_calc_lpt_geom - calculate sizes for the LPT area. * @c: the UBIFS file-system description object diff --git a/ubifs-utils/common/ubifs.h b/ubifs-utils/common/ubifs.h index 0eef31a..2b0ffe5 100644 --- a/ubifs-utils/common/ubifs.h +++ b/ubifs-utils/common/ubifs.h @@ -273,6 +273,9 @@ struct ubifs_znode * @highest_inum: highest used inode number * @max_sqnum: current global sequence number * + * @program_type: used to identify the type of current program + * @program_name: program name + * * @jhead_cnt: count of journal heads * @max_bud_bytes: maximum number of bytes allowed in buds * @@ -360,6 +363,9 @@ struct ubifs_info ino_t highest_inum; unsigned long long max_sqnum; + int program_type; + const char *program_name; + int jhead_cnt; long long max_bud_bytes; diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c index 0304ae7..8f292a2 100644 --- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c @@ -3073,6 +3073,9 @@ int main(int argc, char *argv[]) { int err; + info_.program_name = MKFS_PROGRAM_NAME; + info_.program_type = MKFS_PROGRAM_TYPE; + if (crypto_init()) return -1; -- cgit v1.2.3