]> www.infradead.org Git - mtd-utils.git/commitdiff
ubifs-utils: Define PROGRAM_NAME as variable
authorZhihao Cheng <chengzhihao1@huawei.com>
Mon, 11 Nov 2024 08:36:34 +0000 (16:36 +0800)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Mon, 11 Nov 2024 09:32:45 +0000 (10:32 +0100)
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 <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
ubifs-utils/common/crypto.c
ubifs-utils/common/defs.h
ubifs-utils/common/fscrypt.c
ubifs-utils/common/hashtable/hashtable.c
ubifs-utils/common/lpt.c
ubifs-utils/common/ubifs.h
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c

index 60a67a4eaef629d04f234214964a1e77dbcac8ad..614a16def666a2bd46b8ef0bd5d721ec8a0ceab0 100644 (file)
 #include <string.h>
 #include <assert.h>
 
-#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)
 {
index e1aded0326f95c7d36dbf64c3f6955236d43e8b9..143f6c65a6f57e06414cf320d3bead06ca9cf800 100644 (file)
 #include <byteswap.h>
 #include <errno.h>
 
+#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)                \
index 94c6c37757200c67289ae72607550d432163562b..cc9896386f29322d965019b6424ace0e0c6b025a 100644 (file)
 
 #include <endian.h>
 
-#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;
index c1f99edd1c38b9cec1b978ac322785a89e217ad7..071afd22f70dd6fb1dd8a1dafdef1e720b09573f 100644 (file)
@@ -1,15 +1,19 @@
 /* Copyright (C) 2004 Christopher Clark <firstname.lastname@cl.cam.ac.uk> */
 
-#define PROGRAM_NAME "hashtable"
-
-#include "common.h"
-#include "hashtable.h"
-#include "hashtable_private.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <math.h>
 
+#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/
index 23ffe7f700776d4d5c1eb82b5815ed7bf13df0e9..746fc7db91d1dc42f355a1cc019423ce0386e1c1 100644 (file)
 #include <openssl/evp.h>
 #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
index 0eef31acf8d479806226f6c9f56269d78d2063e5..2b0ffe565fbc8e8352646ad9b7167167d939741f 100644 (file)
@@ -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;
 
index 0304ae70b69a3436cbe76e3112a6d928b70d0a45..8f292a2128050e7c71f18959c2864eccc84e93b8 100644 (file)
@@ -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;