aboutsummaryrefslogtreecommitdiff
path: root/ubifs-utils/common
diff options
context:
space:
mode:
Diffstat (limited to 'ubifs-utils/common')
-rw-r--r--ubifs-utils/common/compr.c19
-rw-r--r--ubifs-utils/common/compr.h8
-rw-r--r--ubifs-utils/common/crypto.c6
-rw-r--r--ubifs-utils/common/defs.h24
-rw-r--r--ubifs-utils/common/devtable.c9
-rw-r--r--ubifs-utils/common/devtable.h77
-rw-r--r--ubifs-utils/common/fscrypt.c4
-rw-r--r--ubifs-utils/common/fscrypt.h8
-rw-r--r--ubifs-utils/common/lpt.c10
-rw-r--r--ubifs-utils/common/lpt.h2
-rw-r--r--ubifs-utils/common/sign.c9
-rw-r--r--ubifs-utils/common/ubifs.h5
12 files changed, 153 insertions, 28 deletions
diff --git a/ubifs-utils/common/compr.c b/ubifs-utils/common/compr.c
index e4324f3..6f90151 100644
--- a/ubifs-utils/common/compr.c
+++ b/ubifs-utils/common/compr.c
@@ -39,11 +39,12 @@
#endif
#include "compr.h"
-#include "mkfs.ubifs.h"
+#include "ubifs.h"
static void *lzo_mem;
static unsigned long long errcnt = 0;
#ifdef WITH_LZO
+extern struct ubifs_info info_;
static struct ubifs_info *c = &info_;
#endif
@@ -181,12 +182,12 @@ static int favor_lzo_compress(void *in_buf, size_t in_len, void *out_buf,
select_lzo:
*out_len = lzo_len;
- *type = MKFS_UBIFS_COMPR_LZO;
+ *type = UBIFS_COMPR_LZO;
return 0;
select_zlib:
*out_len = zlib_len;
- *type = MKFS_UBIFS_COMPR_ZLIB;
+ *type = UBIFS_COMPR_ZLIB;
memcpy(out_buf, zlib_buf, zlib_len);
return 0;
}
@@ -199,7 +200,7 @@ int compress_data(void *in_buf, size_t in_len, void *out_buf, size_t *out_len,
if (in_len < UBIFS_MIN_COMPR_LEN) {
no_compress(in_buf, in_len, out_buf, out_len);
- return MKFS_UBIFS_COMPR_NONE;
+ return UBIFS_COMPR_NONE;
}
#if defined(WITH_LZO) && defined(WITH_ZLIB)
@@ -211,21 +212,21 @@ int compress_data(void *in_buf, size_t in_len, void *out_buf, size_t *out_len,
#endif
switch (type) {
#ifdef WITH_LZO
- case MKFS_UBIFS_COMPR_LZO:
+ case UBIFS_COMPR_LZO:
ret = lzo_compress(in_buf, in_len, out_buf, out_len);
break;
#endif
#ifdef WITH_ZLIB
- case MKFS_UBIFS_COMPR_ZLIB:
+ case UBIFS_COMPR_ZLIB:
ret = zlib_deflate(in_buf, in_len, out_buf, out_len);
break;
#endif
#ifdef WITH_ZSTD
- case MKFS_UBIFS_COMPR_ZSTD:
+ case UBIFS_COMPR_ZSTD:
ret = zstd_compress(in_buf, in_len, out_buf, out_len);
break;
#endif
- case MKFS_UBIFS_COMPR_NONE:
+ case UBIFS_COMPR_NONE:
ret = 1;
break;
default:
@@ -236,7 +237,7 @@ int compress_data(void *in_buf, size_t in_len, void *out_buf, size_t *out_len,
}
if (ret || *out_len >= in_len) {
no_compress(in_buf, in_len, out_buf, out_len);
- return MKFS_UBIFS_COMPR_NONE;
+ return UBIFS_COMPR_NONE;
}
return type;
}
diff --git a/ubifs-utils/common/compr.h b/ubifs-utils/common/compr.h
index d58c7c7..3e8e9b6 100644
--- a/ubifs-utils/common/compr.h
+++ b/ubifs-utils/common/compr.h
@@ -31,14 +31,6 @@
*/
#define WORST_COMPR_FACTOR 4
-enum compression_type
-{
- MKFS_UBIFS_COMPR_NONE,
- MKFS_UBIFS_COMPR_LZO,
- MKFS_UBIFS_COMPR_ZLIB,
- MKFS_UBIFS_COMPR_ZSTD,
-};
-
int compress_data(void *in_buf, size_t in_len, void *out_buf, size_t *out_len,
int type);
int init_compression(void);
diff --git a/ubifs-utils/common/crypto.c b/ubifs-utils/common/crypto.c
index 19c445e..60a67a4 100644
--- a/ubifs-utils/common/crypto.c
+++ b/ubifs-utils/common/crypto.c
@@ -17,14 +17,16 @@
* Authors: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
*/
-#define PROGRAM_NAME "mkfs.ubifs"
#include <openssl/evp.h>
#include <openssl/err.h>
+#include <openssl/rand.h>
#include <string.h>
#include <assert.h>
-#include "fscrypt.h"
+#define PROGRAM_NAME "mkfs.ubifs"
#include "common.h"
+#include "defs.h"
+#include "fscrypt.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 8db5277..e1aded0 100644
--- a/ubifs-utils/common/defs.h
+++ b/ubifs-utils/common/defs.h
@@ -6,6 +6,30 @@
#ifndef __UBIFS_DEFS_H__
#define __UBIFS_DEFS_H__
+#include <stdlib.h>
+#include <stdio.h>
+#include <limits.h>
+#include <byteswap.h>
+#include <errno.h>
+
+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; \
+})
+
#define t16(x) ({ \
uint16_t __b = (x); \
(__LITTLE_ENDIAN==__BYTE_ORDER) ? __b : bswap_16(__b); \
diff --git a/ubifs-utils/common/devtable.c b/ubifs-utils/common/devtable.c
index aa815fb..2b9c6ef 100644
--- a/ubifs-utils/common/devtable.c
+++ b/ubifs-utils/common/devtable.c
@@ -45,7 +45,14 @@
* for more information about what the device table is.
*/
-#include "mkfs.ubifs.h"
+#include <string.h>
+#include <ctype.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/sysmacros.h>
+
+#include "devtable.h"
+#include "defs.h"
#include "hashtable/hashtable.h"
#include "hashtable/hashtable_itr.h"
diff --git a/ubifs-utils/common/devtable.h b/ubifs-utils/common/devtable.h
new file mode 100644
index 0000000..97585f2
--- /dev/null
+++ b/ubifs-utils/common/devtable.h
@@ -0,0 +1,77 @@
+/*
+ * 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 __DEVTABLE_H__
+#define __DEVTABLE_H__
+
+/**
+ * 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;
+};
+
+struct hashtable_itr;
+
+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
diff --git a/ubifs-utils/common/fscrypt.c b/ubifs-utils/common/fscrypt.c
index b75bdf7..94c6c37 100644
--- a/ubifs-utils/common/fscrypt.c
+++ b/ubifs-utils/common/fscrypt.c
@@ -18,8 +18,12 @@
* David Oberhollenzer <david.oberhollenzer@sigma-star.at>
*/
+#include <endian.h>
+
#define PROGRAM_NAME "mkfs.ubifs"
+#include "common.h"
#include "fscrypt.h"
+#include "defs.h"
static __u8 fscrypt_masterkey[FS_MAX_KEY_SIZE];
diff --git a/ubifs-utils/common/fscrypt.h b/ubifs-utils/common/fscrypt.h
index ff3d326..908a504 100644
--- a/ubifs-utils/common/fscrypt.h
+++ b/ubifs-utils/common/fscrypt.h
@@ -21,9 +21,11 @@
#ifndef FSCRYPT_H
#define FSCRYPT_H
-
-#include "mkfs.ubifs.h"
-#include <sys/types.h>
+#ifdef WITH_CRYPTO
+#include <openssl/rand.h>
+#endif
+#include <assert.h>
+#include "ubifs.h"
#include "crypto.h"
#ifndef FS_KEY_DESCRIPTOR_SIZE
diff --git a/ubifs-utils/common/lpt.c b/ubifs-utils/common/lpt.c
index 7ee739a..23ffe7f 100644
--- a/ubifs-utils/common/lpt.c
+++ b/ubifs-utils/common/lpt.c
@@ -20,12 +20,18 @@
* Artem Bityutskiy
*/
-#include "mkfs.ubifs.h"
-
#ifdef WITH_CRYPTO
#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"
+
/**
* do_calc_lpt_geom - calculate sizes for the LPT area.
* @c: the UBIFS file-system description object
diff --git a/ubifs-utils/common/lpt.h b/ubifs-utils/common/lpt.h
index 4cde59d..86148a2 100644
--- a/ubifs-utils/common/lpt.h
+++ b/ubifs-utils/common/lpt.h
@@ -22,6 +22,8 @@
#ifndef __UBIFS_LPT_H__
#define __UBIFS_LPT_H__
+#include "ubifs.h"
+
int calc_dflt_lpt_geom(struct ubifs_info *c, int *main_lebs, int *big_lpt);
int create_lpt(struct ubifs_info *c);
diff --git a/ubifs-utils/common/sign.c b/ubifs-utils/common/sign.c
index 7f284f8..93399ff 100644
--- a/ubifs-utils/common/sign.c
+++ b/ubifs-utils/common/sign.c
@@ -17,9 +17,7 @@
* Author: Sascha Hauer
*/
-#include "mkfs.ubifs.h"
-#include "common.h"
-
+#include <string.h>
#include <openssl/evp.h>
#include <openssl/opensslv.h>
#include <openssl/bio.h>
@@ -30,6 +28,11 @@
#include <openssl/conf.h>
#include <err.h>
+#include "sign.h"
+#include "defs.h"
+#include "ubifs.h"
+
+extern struct ubifs_info info_;
static struct ubifs_info *c = &info_;
EVP_MD_CTX *hash_md;
diff --git a/ubifs-utils/common/ubifs.h b/ubifs-utils/common/ubifs.h
index 55937ce..0eef31a 100644
--- a/ubifs-utils/common/ubifs.h
+++ b/ubifs-utils/common/ubifs.h
@@ -25,6 +25,9 @@
#ifndef __UBIFS_H__
#define __UBIFS_H__
+#include <mtd/ubifs-media.h>
+#include "libubi.h"
+
/* Maximum logical eraseblock size in bytes */
#define UBIFS_MAX_LEB_SZ (2*1024*1024)
@@ -468,4 +471,6 @@ struct ubifs_branch *ubifs_idx_branch(const struct ubifs_info *c,
(UBIFS_BRANCH_SZ + c->key_len + c->hash_len) * bnum);
}
+int write_leb(int lnum, int len, void *buf);
+
#endif /* __UBIFS_H__ */