diff options
author | Ladislav Michl <ladis@linux-mips.org> | 2015-09-30 13:06:22 +0200 |
---|---|---|
committer | Michael Olbrich <m.olbrich@pengutronix.de> | 2015-10-15 09:43:09 +0200 |
commit | 4387569c2e584ac05be5a5a6b9c8054396159b1b (patch) | |
tree | fc026e0d63409e0873fef50b678b6b49881b66bd /patches/mtd-utils-1.5.2 | |
parent | 3ecb59a522649160f04023765a17c57b667a5e34 (diff) | |
download | ptxdist-4387569c2e584ac05be5a5a6b9c8054396159b1b.tar.gz ptxdist-4387569c2e584ac05be5a5a6b9c8054396159b1b.tar.xz |
mtd-utils: version bump 1.5.1 -> 1.5.2
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Diffstat (limited to 'patches/mtd-utils-1.5.2')
8 files changed, 952 insertions, 0 deletions
diff --git a/patches/mtd-utils-1.5.2/0001-make-ubifs-optional.patch b/patches/mtd-utils-1.5.2/0001-make-ubifs-optional.patch new file mode 100644 index 000000000..7da2ef498 --- /dev/null +++ b/patches/mtd-utils-1.5.2/0001-make-ubifs-optional.patch @@ -0,0 +1,23 @@ +From: Bernhard Walle <bernhard@bwalle.de> +Date: Sun, 11 Mar 2012 20:03:50 +0100 +Subject: [PATCH] make ubifs optional + +Signed-off-by: Bernhard Walle <bernhard@bwalle.de> +--- + Makefile | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/Makefile b/Makefile +index eade23467074..8d1506df37f9 100644 +--- a/Makefile ++++ b/Makefile +@@ -31,7 +31,9 @@ UBI_BINS = \ + ubidetach ubinize ubiformat ubirename mtdinfo ubirsvol ubiblock + + BINS = $(MTD_BINS) ++ifneq ($(WITHOUT_MKUBIFS), 1) + BINS += mkfs.ubifs/mkfs.ubifs ++endif + BINS += $(addprefix ubi-utils/,$(UBI_BINS)) + SCRIPTS = flash_eraseall + diff --git a/patches/mtd-utils-1.5.2/0002-Make-liblzo-optional-for-ubifs-tools.patch b/patches/mtd-utils-1.5.2/0002-Make-liblzo-optional-for-ubifs-tools.patch new file mode 100644 index 000000000..1317c3e55 --- /dev/null +++ b/patches/mtd-utils-1.5.2/0002-Make-liblzo-optional-for-ubifs-tools.patch @@ -0,0 +1,68 @@ +From: Bernhard Walle <bernhard@bwalle.de> +Date: Sun, 11 Mar 2012 20:11:14 +0100 +Subject: [PATCH] Make liblzo optional for ubifs tools + +Based on patch from Marc Kleine-Budde <mkl@pengutronix.de>. + +Signed-off-by: Bernhard Walle <bernhard@bwalle.de> +--- + Makefile | 2 +- + mkfs.ubifs/compr.c | 17 +++++++++++++++++ + 2 files changed, 18 insertions(+), 1 deletion(-) + +diff --git a/Makefile b/Makefile +index 8d1506df37f9..228dc9cc6ea2 100644 +--- a/Makefile ++++ b/Makefile +@@ -107,7 +107,7 @@ $(call _mkdep,lib/,libmtd.a) + obj-mkfs.ubifs = crc16.o lpt.o compr.o devtable.o \ + hashtable/hashtable.o hashtable/hashtable_itr.o + LDFLAGS_mkfs.ubifs = $(ZLIBLDFLAGS) $(LZOLDFLAGS) $(UUIDLDFLAGS) +-LDLIBS_mkfs.ubifs = -lz -llzo2 -lm -luuid ++LDLIBS_mkfs.ubifs = -lz $(LZOLDLIBS) -lm -luuid + $(call mkdep,mkfs.ubifs/,mkfs.ubifs,,ubi-utils/libubi.a) + + # +diff --git a/mkfs.ubifs/compr.c b/mkfs.ubifs/compr.c +index 4152b6af8832..244d4507b5ce 100644 +--- a/mkfs.ubifs/compr.c ++++ b/mkfs.ubifs/compr.c +@@ -24,7 +24,11 @@ + #include <stdio.h> + #include <stdint.h> + #include <string.h> ++#ifndef WITHOUT_LZO + #include <lzo/lzo1x.h> ++#else ++#define LZO1X_999_MEM_COMPRESS 0 ++#endif + #include <linux/types.h> + + #define crc32 __zlib_crc32 +@@ -86,6 +90,8 @@ static int zlib_deflate(void *in_buf, size_t in_len, void *out_buf, + return 0; + } + ++ ++#ifndef WITHOUT_LZO + static int lzo_compress(void *in_buf, size_t in_len, void *out_buf, + size_t *out_len) + { +@@ -103,6 +109,17 @@ static int lzo_compress(void *in_buf, size_t in_len, void *out_buf, + + return 0; + } ++#else ++static inline int lzo_compress(void *in_buf, size_t in_len, void *out_buf, ++ size_t *out_len) ++{ ++ (void)in_buf; ++ (void)in_len; ++ (void)out_buf; ++ (void)out_len; ++ return -1; ++} ++#endif + + static int no_compress(void *in_buf, size_t in_len, void *out_buf, + size_t *out_len) diff --git a/patches/mtd-utils-1.5.2/0003-mkfs.ubifs-change-add_directory-argument-to-existing.patch b/patches/mtd-utils-1.5.2/0003-mkfs.ubifs-change-add_directory-argument-to-existing.patch new file mode 100644 index 000000000..a423ea509 --- /dev/null +++ b/patches/mtd-utils-1.5.2/0003-mkfs.ubifs-change-add_directory-argument-to-existing.patch @@ -0,0 +1,96 @@ +From: Sascha Hauer <s.hauer@pengutronix.de> +Date: Fri, 28 Nov 2014 11:04:00 +0100 +Subject: [PATCH] mkfs.ubifs: change add_directory argument to 'existing' + +A 'non_existing' argument which is only used with !non_existing +is just too confusing. Change this to positive logic. + +Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> +Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> +--- + mkfs.ubifs/mkfs.ubifs.c | 22 +++++++++++----------- + 1 file changed, 11 insertions(+), 11 deletions(-) + +diff --git a/mkfs.ubifs/mkfs.ubifs.c b/mkfs.ubifs/mkfs.ubifs.c +index 200c8a5007e4..fbcaf1ffbed6 100644 +--- a/mkfs.ubifs/mkfs.ubifs.c ++++ b/mkfs.ubifs/mkfs.ubifs.c +@@ -1396,12 +1396,12 @@ static int add_non_dir(const char *path_name, ino_t *inum, unsigned int nlink, + * @dir_name: directory path name + * @dir_inum: UBIFS inode number of directory + * @st: directory inode statistics +- * @non_existing: non-zero if this function is called for a directory which +- * does not exist on the host file-system and it is being +- * created because it is defined in the device table file. ++ * @existing: zero if this function is called for a directory which ++ * does not exist on the host file-system and it is being ++ * created because it is defined in the device table file. + */ + static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st, +- int non_existing) ++ int existing) + { + struct dirent *entry; + DIR *dir = NULL; +@@ -1417,7 +1417,7 @@ static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st, + unsigned long long dir_creat_sqnum = ++c->max_sqnum; + + dbg_msg(2, "%s", dir_name); +- if (!non_existing) { ++ if (existing) { + dir = opendir(dir_name); + if (dir == NULL) + return sys_err_msg("cannot open directory '%s'", +@@ -1435,7 +1435,7 @@ static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st, + * Before adding the directory itself, we have to iterate over all the + * entries the device table adds to this directory and create them. + */ +- for (; !non_existing;) { ++ for (; existing;) { + struct stat dent_st; + + errno = 0; +@@ -1493,7 +1493,7 @@ static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st, + inum = ++c->highest_inum; + + if (S_ISDIR(dent_st.st_mode)) { +- err = add_directory(name, inum, &dent_st, 0); ++ err = add_directory(name, inum, &dent_st, 1); + if (err) + goto out_free; + nlink += 1; +@@ -1545,7 +1545,7 @@ static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st, + inum = ++c->highest_inum; + + if (S_ISDIR(nh_elt->mode)) { +- err = add_directory(name, inum, &fake_st, 1); ++ err = add_directory(name, inum, &fake_st, 0); + if (err) + goto out_free; + nlink += 1; +@@ -1571,14 +1571,14 @@ static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st, + goto out_free; + + free(name); +- if (!non_existing && closedir(dir) == -1) ++ if (existing && closedir(dir) == -1) + return sys_err_msg("error closing directory '%s'", dir_name); + + return 0; + + out_free: + free(name); +- if (!non_existing) ++ if (existing) + closedir(dir); + return -1; + } +@@ -1625,7 +1625,7 @@ static int write_data(void) + } + + head_flags = 0; +- err = add_directory(root, UBIFS_ROOT_INO, &root_st, !root); ++ err = add_directory(root, UBIFS_ROOT_INO, &root_st, !!root); + if (err) + return err; + err = add_multi_linked_files(); diff --git a/patches/mtd-utils-1.5.2/0004-mkfs.ubifs-use-xmalloc-xzalloc-for-allocating-memory.patch b/patches/mtd-utils-1.5.2/0004-mkfs.ubifs-use-xmalloc-xzalloc-for-allocating-memory.patch new file mode 100644 index 000000000..cc9234bfc --- /dev/null +++ b/patches/mtd-utils-1.5.2/0004-mkfs.ubifs-use-xmalloc-xzalloc-for-allocating-memory.patch @@ -0,0 +1,142 @@ +From: Sascha Hauer <s.hauer@pengutronix.de> +Date: Fri, 28 Nov 2014 11:11:26 +0100 +Subject: [PATCH] mkfs.ubifs: use xmalloc/xzalloc for allocating memory + +Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> +Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> +--- + mkfs.ubifs/mkfs.ubifs.c | 64 +++++++++++-------------------------------------- + 1 file changed, 14 insertions(+), 50 deletions(-) + +diff --git a/mkfs.ubifs/mkfs.ubifs.c b/mkfs.ubifs/mkfs.ubifs.c +index fbcaf1ffbed6..cb7b643ce73c 100644 +--- a/mkfs.ubifs/mkfs.ubifs.c ++++ b/mkfs.ubifs/mkfs.ubifs.c +@@ -260,13 +260,8 @@ static int is_contained(const char *file, const char *dir) + file_base = dirname(copy); + + /* Turn the paths into the canonical form */ +- real_file = malloc(PATH_MAX); +- if (!real_file) +- goto out_free; +- +- real_dir = malloc(PATH_MAX); +- if (!real_dir) +- goto out_free; ++ real_file = xmalloc(PATH_MAX); ++ real_dir = xmalloc(PATH_MAX); + + if (!realpath(file_base, real_file)) { + perror("Could not canonicalize file path"); +@@ -501,9 +496,7 @@ static int get_options(int argc, char**argv) + case 'r': + case 'd': + root_len = strlen(optarg); +- root = malloc(root_len + 2); +- if (!root) +- return err_msg("cannot allocate memory"); ++ root = xmalloc(root_len + 2); + + /* + * The further code expects '/' at the end of the root +@@ -911,9 +904,7 @@ static int add_to_index(union ubifs_key *key, char *name, int lnum, int offs, + struct idx_entry *e; + + dbg_msg(3, "LEB %d offs %d len %d", lnum, offs, len); +- e = malloc(sizeof(struct idx_entry)); +- if (!e) +- return err_msg("out of memory"); ++ e = xmalloc(sizeof(struct idx_entry)); + e->next = NULL; + e->prev = idx_list_last; + e->key = *key; +@@ -1194,9 +1185,7 @@ static struct inum_mapping *lookup_inum_mapping(dev_t dev, ino_t inum) + return im; + im = im->next; + } +- im = malloc(sizeof(struct inum_mapping)); +- if (!im) +- return NULL; ++ im = xmalloc(sizeof(struct inum_mapping)); + im->next = hash_table[k]; + im->prev = NULL; + im->dev = dev; +@@ -1356,9 +1345,7 @@ static int add_non_dir(const char *path_name, ino_t *inum, unsigned int nlink, + /* New entry */ + im->use_inum = *inum; + im->use_nlink = 1; +- im->path_name = malloc(strlen(path_name) + 1); +- if (!im->path_name) +- return err_msg("out of memory"); ++ im->path_name = xmalloc(strlen(path_name) + 1); + strcpy(im->path_name, path_name); + } else { + /* Existing entry */ +@@ -1708,21 +1695,14 @@ static int write_index(void) + head_flags = LPROPS_INDEX; + /* Allocate index node */ + idx_sz = ubifs_idx_node_sz(c, c->fanout); +- idx = malloc(idx_sz); +- if (!idx) +- return err_msg("out of memory"); ++ idx = xmalloc(idx_sz); + /* Make an array of pointers to sort the index list */ + sz = idx_cnt * sizeof(struct idx_entry *); + if (sz / sizeof(struct idx_entry *) != idx_cnt) { + free(idx); + return err_msg("index is too big (%zu entries)", idx_cnt); + } +- idx_ptr = malloc(sz); +- if (!idx_ptr) { +- free(idx); +- return err_msg("out of memory - needed %zu bytes for index", +- sz); +- } ++ idx_ptr = xmalloc(sz); + idx_ptr[0] = idx_list_first; + for (i = 1; i < idx_cnt; i++) + idx_ptr[i] = idx_ptr[i - 1]->next; +@@ -2165,13 +2145,8 @@ static int init(void) + c->lpt_first = UBIFS_LOG_LNUM + c->log_lebs; + c->lpt_last = c->lpt_first + c->lpt_lebs - 1; + +- c->lpt = malloc(c->main_lebs * sizeof(struct ubifs_lprops)); +- if (!c->lpt) +- return err_msg("unable to allocate LPT"); +- +- c->ltab = malloc(c->lpt_lebs * sizeof(struct ubifs_lprops)); +- if (!c->ltab) +- return err_msg("unable to allocate LPT ltab"); ++ c->lpt = xmalloc(c->main_lebs * sizeof(struct ubifs_lprops)); ++ c->ltab = xmalloc(c->lpt_lebs * sizeof(struct ubifs_lprops)); + + /* Initialize LPT's own lprops */ + for (i = 0; i < c->lpt_lebs; i++) { +@@ -2183,23 +2158,12 @@ static int init(void) + c->dark_wm = ALIGN(UBIFS_MAX_NODE_SZ, c->min_io_size); + dbg_msg(1, "dead_wm %d dark_wm %d", c->dead_wm, c->dark_wm); + +- leb_buf = malloc(c->leb_size); +- if (!leb_buf) +- return err_msg("out of memory"); +- +- node_buf = malloc(NODE_BUFFER_SIZE); +- if (!node_buf) +- return err_msg("out of memory"); +- +- block_buf = malloc(UBIFS_BLOCK_SIZE); +- if (!block_buf) +- return err_msg("out of memory"); ++ leb_buf = xmalloc(c->leb_size); ++ node_buf = xmalloc(NODE_BUFFER_SIZE); ++ block_buf = xmalloc(UBIFS_BLOCK_SIZE); + + sz = sizeof(struct inum_mapping *) * HASH_TABLE_SIZE; +- hash_table = malloc(sz); +- if (!hash_table) +- return err_msg("out of memory"); +- memset(hash_table, 0, sz); ++ hash_table = xzalloc(sz); + + err = init_compression(); + if (err) diff --git a/patches/mtd-utils-1.5.2/0005-mkfs.ubifs-simplify-make_path-with-xasprintf.patch b/patches/mtd-utils-1.5.2/0005-mkfs.ubifs-simplify-make_path-with-xasprintf.patch new file mode 100644 index 000000000..8c68c84a7 --- /dev/null +++ b/patches/mtd-utils-1.5.2/0005-mkfs.ubifs-simplify-make_path-with-xasprintf.patch @@ -0,0 +1,31 @@ +From: Sascha Hauer <s.hauer@pengutronix.de> +Date: Fri, 28 Nov 2014 11:15:18 +0100 +Subject: [PATCH] mkfs.ubifs: simplify make_path with xasprintf + +Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> +Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> +--- + mkfs.ubifs/mkfs.ubifs.c | 10 +++------- + 1 file changed, 3 insertions(+), 7 deletions(-) + +diff --git a/mkfs.ubifs/mkfs.ubifs.c b/mkfs.ubifs/mkfs.ubifs.c +index cb7b643ce73c..c1e72bbddf9d 100644 +--- a/mkfs.ubifs/mkfs.ubifs.c ++++ b/mkfs.ubifs/mkfs.ubifs.c +@@ -228,13 +228,9 @@ static char *make_path(const char *dir, const char *name) + { + char *s; + +- s = malloc(strlen(dir) + strlen(name) + 2); +- if (!s) +- return NULL; +- strcpy(s, dir); +- if (dir[strlen(dir) - 1] != '/') +- strcat(s, "/"); +- strcat(s, name); ++ xasprintf(&s, "%s%s%s", ++ dir, dir[strlen(dir) - 1] == '/' ? "" : "/", name); ++ + return s; + } + diff --git a/patches/mtd-utils-1.5.2/0006-mkfs.ubifs-Add-extended-attribute-support.patch b/patches/mtd-utils-1.5.2/0006-mkfs.ubifs-Add-extended-attribute-support.patch new file mode 100644 index 000000000..9f86f4a8a --- /dev/null +++ b/patches/mtd-utils-1.5.2/0006-mkfs.ubifs-Add-extended-attribute-support.patch @@ -0,0 +1,365 @@ +From: Sascha Hauer <s.hauer@pengutronix.de> +Date: Fri, 28 Nov 2014 08:16:15 +0100 +Subject: [PATCH] mkfs.ubifs: Add extended attribute support + +This adds extended attribute support to mkfs.ubifs. When creating +an image from a directory tree the existing extended attributes are +added to the UBIFS image. + +Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> +Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> +--- + mkfs.ubifs/key.h | 18 +++++ + mkfs.ubifs/mkfs.ubifs.c | 201 +++++++++++++++++++++++++++++++++++++++++------- + mkfs.ubifs/ubifs.h | 9 +++ + 3 files changed, 201 insertions(+), 27 deletions(-) + +diff --git a/mkfs.ubifs/key.h b/mkfs.ubifs/key.h +index d3a02d4ff1a6..39379fd48178 100644 +--- a/mkfs.ubifs/key.h ++++ b/mkfs.ubifs/key.h +@@ -119,6 +119,24 @@ static inline void dent_key_init(const struct ubifs_info *c, + } + + /** ++ * xent_key_init - initialize extended attribute entry key. ++ * @c: UBIFS file-system description object ++ * @key: key to initialize ++ * @inum: host inode number ++ * @nm: extended attribute entry name and length ++ */ ++static inline void xent_key_init(const struct ubifs_info *c, ++ union ubifs_key *key, ino_t inum, ++ const struct qstr *nm) ++{ ++ uint32_t hash = c->key_hash(nm->name, nm->len); ++ ++ ubifs_assert(!(hash & ~UBIFS_S_KEY_HASH_MASK)); ++ key->u32[0] = inum; ++ key->u32[1] = hash | (UBIFS_XENT_KEY << UBIFS_S_KEY_HASH_BITS); ++} ++ ++/** + * data_key_init - initialize data key. + * @c: UBIFS file-system description object + * @key: key to initialize +diff --git a/mkfs.ubifs/mkfs.ubifs.c b/mkfs.ubifs/mkfs.ubifs.c +index c1e72bbddf9d..667dce7f2986 100644 +--- a/mkfs.ubifs/mkfs.ubifs.c ++++ b/mkfs.ubifs/mkfs.ubifs.c +@@ -26,6 +26,8 @@ + #include "mkfs.ubifs.h" + #include <crc32.h> + #include "common.h" ++#include <sys/types.h> ++#include <attr/xattr.h> + + /* Size (prime number) of hash table for link counting */ + #define HASH_TABLE_SIZE 10099 +@@ -981,20 +983,168 @@ static int add_node(union ubifs_key *key, char *name, void *node, int len) + return 0; + } + ++int add_xattr(struct stat *st, ino_t inum, const void *data, unsigned int data_len, ++ struct qstr *nm) ++{ ++ struct ubifs_ino_node *ino; ++ struct ubifs_dent_node *xent; ++ union ubifs_key xkey, nkey; ++ int len, ret; ++ ++ xent = xzalloc(sizeof(*xent) + nm->len + 1); ++ ino = xzalloc(sizeof(*ino) + data_len); ++ ++ xent_key_init(c, &xkey, inum, nm); ++ xent->ch.node_type = UBIFS_XENT_NODE; ++ key_write(&xkey, &xent->key); ++ ++ len = UBIFS_XENT_NODE_SZ + nm->len + 1; ++ ++ xent->ch.len = len; ++ xent->padding1 = 0; ++ xent->type = UBIFS_ITYPE_DIR; ++ xent->nlen = cpu_to_le16(nm->len); ++ ++ memcpy(xent->name, nm->name, nm->len + 1); ++ ++ inum = ++c->highest_inum; ++ creat_sqnum = ++c->max_sqnum; ++ ++ xent->inum = cpu_to_le64(inum); ++ ++ ret = add_node(&xkey, nm->name, xent, len); ++ if (ret) ++ goto out; ++ ++ ino->creat_sqnum = cpu_to_le64(creat_sqnum); ++ ino->nlink = cpu_to_le32(st->st_nlink); ++ /* ++ * The time fields are updated assuming the default time granularity ++ * of 1 second. To support finer granularities, utime() would be needed. ++ */ ++ ino->atime_sec = cpu_to_le64(st->st_atime); ++ ino->ctime_sec = cpu_to_le64(st->st_ctime); ++ ino->mtime_sec = cpu_to_le64(st->st_mtime); ++ ino->atime_nsec = 0; ++ ino->ctime_nsec = 0; ++ ino->mtime_nsec = 0; ++ ino->uid = cpu_to_le32(st->st_uid); ++ ino->gid = cpu_to_le32(st->st_gid); ++ ino->compr_type = cpu_to_le16(c->default_compr); ++ ino->ch.node_type = UBIFS_INO_NODE; ++ ++ ino_key_init(&nkey, inum); ++ key_write(&nkey, &ino->key); ++ ++ ino->size = cpu_to_le64(data_len); ++ ino->mode = cpu_to_le32(S_IFREG); ++ ino->data_len = cpu_to_le32(data_len); ++ ino->flags = cpu_to_le32(UBIFS_XATTR_FL); ++ ++ if (data_len) ++ memcpy(&ino->data, data, data_len); ++ ++ ret = add_node(&nkey, nm->name, ino, UBIFS_INO_NODE_SZ + data_len) ; ++ ++out: ++ free(xent); ++ free(ino); ++ ++ return ret; ++} ++ ++static int inode_add_xattr(struct ubifs_ino_node *host_ino, ++ const char *path_name, struct stat *st, ino_t inum) ++{ ++ int ret; ++ struct qstr nm; ++ void *buf = NULL; ++ ssize_t len; ++ ssize_t pos = 0; ++ void *attrval = NULL; ++ ++ len = listxattr(path_name, NULL, 0); ++ if (len < 0) { ++ if (errno == ENOENT) ++ return 0; ++ ++ sys_err_msg("flistxattr failed on %s", path_name); ++ ++ return len; ++ } ++ ++ if (len == 0) ++ goto noxattr; ++ ++ buf = xmalloc(len); ++ ++ len = listxattr(path_name, buf, len); ++ if (len < 0) { ++ sys_err_msg("flistxattr failed on %s", path_name); ++ goto out_free; ++ } ++ ++ while (pos < len) { ++ char *name; ++ ssize_t attrsize; ++ ++ name = buf + pos; ++ pos += strlen(name) + 1; ++ ++ attrsize = getxattr(path_name, name, NULL, 0); ++ if (attrsize < 0) { ++ sys_err_msg("getxattr failed on %s", path_name); ++ goto out_free; ++ } ++ ++ attrval = xmalloc(attrsize); ++ attrsize = getxattr(path_name, name, attrval, attrsize); ++ if (attrsize < 0) { ++ sys_err_msg("getxattr failed on %s", path_name); ++ goto out_free; ++ } ++ ++ nm.name = name; ++ nm.len = strlen(name); ++ ++ host_ino->xattr_cnt++; ++ host_ino->xattr_size += CALC_DENT_SIZE(nm.len); ++ host_ino->xattr_size += CALC_XATTR_BYTES(attrsize); ++ host_ino->xattr_names += nm.len; ++ ++ ret = add_xattr(st, inum, attrval, attrsize, &nm); ++ if (ret < 0) ++ goto out_free; ++ ++ free(attrval); ++ attrval = NULL; ++ } ++ ++noxattr: ++ free(buf); ++ return 0; ++ ++out_free: ++ free(buf); ++ free(attrval); ++ ++ return -1; ++} ++ + /** +- * add_inode_with_data - write an inode. ++ * add_inode - write an inode. + * @st: stat information of source inode + * @inum: target inode number + * @data: inode data (for special inodes e.g. symlink path etc) + * @data_len: inode data length + * @flags: source inode flags + */ +-static int add_inode_with_data(struct stat *st, ino_t inum, void *data, +- unsigned int data_len, int flags) ++static int add_inode(struct stat *st, ino_t inum, void *data, ++ unsigned int data_len, int flags, const char *xattr_path) + { + struct ubifs_ino_node *ino = node_buf; + union ubifs_key key; +- int len, use_flags = 0; ++ int len, use_flags = 0, ret; + + if (c->default_compr != UBIFS_COMPR_NONE) + use_flags |= UBIFS_COMPR_FL; +@@ -1038,18 +1188,13 @@ static int add_inode_with_data(struct stat *st, ino_t inum, void *data, + + len = UBIFS_INO_NODE_SZ + data_len; + +- return add_node(&key, NULL, ino, len); +-} ++ if (xattr_path) { ++ ret = inode_add_xattr(ino, xattr_path, st, inum); ++ if (ret < 0) ++ return ret; ++ } + +-/** +- * add_inode - write an inode. +- * @st: stat information of source inode +- * @inum: target inode number +- * @flags: source inode flags +- */ +-static int add_inode(struct stat *st, ino_t inum, int flags) +-{ +- return add_inode_with_data(st, inum, NULL, 0, flags); ++ return add_node(&key, NULL, ino, len); + } + + /** +@@ -1065,8 +1210,8 @@ static int add_inode(struct stat *st, ino_t inum, int flags) + * is being created does not exist at the host file system, but is defined by + * the device table. + */ +-static int add_dir_inode(DIR *dir, ino_t inum, loff_t size, unsigned int nlink, +- struct stat *st) ++static int add_dir_inode(const char *path_name, DIR *dir, ino_t inum, loff_t size, ++ unsigned int nlink, struct stat *st) + { + int fd, flags = 0; + +@@ -1081,7 +1226,7 @@ static int add_dir_inode(DIR *dir, ino_t inum, loff_t size, unsigned int nlink, + flags = 0; + } + +- return add_inode(st, inum, flags); ++ return add_inode(st, inum, NULL, 0, flags, path_name); + } + + /** +@@ -1090,12 +1235,12 @@ static int add_dir_inode(DIR *dir, ino_t inum, loff_t size, unsigned int nlink, + * @inum: target inode number + * @flags: source inode flags + */ +-static int add_dev_inode(struct stat *st, ino_t inum, int flags) ++static int add_dev_inode(const char *path_name, struct stat *st, ino_t inum, int flags) + { + union ubifs_dev_desc dev; + + dev.huge = cpu_to_le64(makedev(major(st->st_rdev), minor(st->st_rdev))); +- return add_inode_with_data(st, inum, &dev, 8, flags); ++ return add_inode(st, inum, &dev, 8, flags, path_name); + } + + /** +@@ -1118,7 +1263,7 @@ static int add_symlink_inode(const char *path_name, struct stat *st, ino_t inum, + if (len > UBIFS_MAX_INO_DATA) + return err_msg("symlink too long for %s", path_name); + +- return add_inode_with_data(st, inum, buf, len, flags); ++ return add_inode(st, inum, buf, len, flags, path_name); + } + + /** +@@ -1276,12 +1421,14 @@ static int add_file(const char *path_name, struct stat *st, ino_t inum, + return err; + } + } while (ret != 0); ++ + if (close(fd) == -1) + return sys_err_msg("failed to close file '%s'", path_name); + if (file_size != st->st_size) + return err_msg("file size changed during writing file '%s'", + path_name); +- return add_inode(st, inum, flags); ++ ++ return add_inode(st, inum, NULL, 0, flags, path_name); + } + + /** +@@ -1361,15 +1508,15 @@ static int add_non_dir(const char *path_name, ino_t *inum, unsigned int nlink, + if (S_ISREG(st->st_mode)) + return add_file(path_name, st, *inum, flags); + if (S_ISCHR(st->st_mode)) +- return add_dev_inode(st, *inum, flags); ++ return add_dev_inode(path_name, st, *inum, flags); + if (S_ISBLK(st->st_mode)) +- return add_dev_inode(st, *inum, flags); ++ return add_dev_inode(path_name, st, *inum, flags); + if (S_ISLNK(st->st_mode)) + return add_symlink_inode(path_name, st, *inum, flags); + if (S_ISSOCK(st->st_mode)) +- return add_inode(st, *inum, flags); ++ return add_inode(st, *inum, NULL, 0, flags, NULL); + if (S_ISFIFO(st->st_mode)) +- return add_inode(st, *inum, flags); ++ return add_inode(st, *inum, NULL, 0, flags, NULL); + + return err_msg("file '%s' has unknown inode type", path_name); + } +@@ -1549,7 +1696,7 @@ static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st, + + creat_sqnum = dir_creat_sqnum; + +- err = add_dir_inode(dir, dir_inum, size, nlink, st); ++ err = add_dir_inode(dir ? dir_name : NULL, dir, dir_inum, size, nlink, st); + if (err) + goto out_free; + +diff --git a/mkfs.ubifs/ubifs.h b/mkfs.ubifs/ubifs.h +index 434b651859b3..2f080a8ce708 100644 +--- a/mkfs.ubifs/ubifs.h ++++ b/mkfs.ubifs/ubifs.h +@@ -42,6 +42,15 @@ + */ + #define UBIFS_TRUN_KEY UBIFS_KEY_TYPES_CNT + ++/* ++ * How much a directory entry/extended attribute entry adds to the parent/host ++ * inode. ++ */ ++#define CALC_DENT_SIZE(name_len) ALIGN(UBIFS_DENT_NODE_SZ + (name_len) + 1, 8) ++ ++/* How much an extended attribute adds to the host inode */ ++#define CALC_XATTR_BYTES(data_len) ALIGN(UBIFS_INO_NODE_SZ + (data_len) + 1, 8) ++ + /* The below union makes it easier to deal with keys */ + union ubifs_key + { diff --git a/patches/mtd-utils-1.5.2/0007-mkfs.ubifs-Optionally-create-extended-attribute-with.patch b/patches/mtd-utils-1.5.2/0007-mkfs.ubifs-Optionally-create-extended-attribute-with.patch new file mode 100644 index 000000000..4de70724c --- /dev/null +++ b/patches/mtd-utils-1.5.2/0007-mkfs.ubifs-Optionally-create-extended-attribute-with.patch @@ -0,0 +1,217 @@ +From: Sascha Hauer <s.hauer@pengutronix.de> +Date: Tue, 25 Nov 2014 15:39:32 +0100 +Subject: [PATCH] mkfs.ubifs: Optionally create extended attribute with inode + number + +This is done to allow creating images suitable for IMA directory +appraisal. IMA creates a hash for directories and attaches this +hash to the directory itself as an extended attribute. Among other +things the inode numbers of the files are hashed. So, to create +a valid hash in the UBIFS image the evmctl tool needs to know +the inode numbers which the files in the UBIFS image will have. +evmctl will read the inode numbers from the user.image-inode-number +extended attribute. Since extended attributes are inodes themselves +the inode numbers for the generated image will change when the +extended attributes change, so to generate a correctly hashed +UBIFS image, both evmctl and mkfs.ubifs must be run twice: + +1) execute evmctl to iterate over the directory tree. This will + create the security.ima and security.evm extended attributes. + The existence of the attributes makes sure that subsequent + calls to mkfs.ubifs will use the same inode numbers. evmctl + will use the inode numbers from the host filesystem in this + step which makes the resulting image unusable +2) execute mkfs.ubifs -a. This will create the user.image-inode-number + extended attributes on files/directories added to the image. +3) execture evmctl again. This time evmctl will pick the inode + numbers from the user.image-inode-number extended attribute + instead of the ones from the host filesystem +4) execute mkfs.ubifs again. This will create the correct image. + The now existing user.image-inode-number extended attributes + are ignored and not added to the image. + +Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> +Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> +--- + mkfs.ubifs/mkfs.ubifs.c | 77 +++++++++++++++++++++++++++++++++++++++++++------ + 1 file changed, 68 insertions(+), 9 deletions(-) + +diff --git a/mkfs.ubifs/mkfs.ubifs.c b/mkfs.ubifs/mkfs.ubifs.c +index 667dce7f2986..4ab24a240087 100644 +--- a/mkfs.ubifs/mkfs.ubifs.c ++++ b/mkfs.ubifs/mkfs.ubifs.c +@@ -114,6 +114,7 @@ static char *output; + static int out_fd; + static int out_ubi; + static int squash_owner; ++static int do_create_inum_attr; + + /* The 'head' (position) which nodes are written */ + static int head_lnum; +@@ -136,7 +137,7 @@ static struct inum_mapping **hash_table; + /* Inode creation sequence number */ + static unsigned long long creat_sqnum; + +-static const char *optstring = "d:r:m:o:D:yh?vVe:c:g:f:Fp:k:x:X:j:R:l:j:UQq"; ++static const char *optstring = "d:r:m:o:D:yh?vVe:c:g:f:Fp:k:x:X:j:R:l:j:UQqa"; + + static const struct option longopts[] = { + {"root", 1, NULL, 'r'}, +@@ -160,6 +161,7 @@ static const struct option longopts[] = { + {"log-lebs", 1, NULL, 'l'}, + {"orph-lebs", 1, NULL, 'p'}, + {"squash-uids" , 0, NULL, 'U'}, ++ {"set-inode-attr", 0, NULL, 'a'}, + {NULL, 0, NULL, 0} + }; + +@@ -200,6 +202,9 @@ static const char *helptext = + "-V, --version display version information\n" + "-g, --debug=LEVEL display debug information (0 - none, 1 - statistics,\n" + " 2 - files, 3 - more details)\n" ++"-a, --set-inum-attr create user.image-inode-number extended attribute on files\n" ++" added to the image. The attribute will contain the inode\n" ++" number the file has in the generated image.\n" + "-h, --help display this help text\n\n" + "Note, SIZE is specified in bytes, but it may also be specified in Kilobytes,\n" + "Megabytes, and Gigabytes if a KiB, MiB, or GiB suffix is used.\n\n" +@@ -221,6 +226,25 @@ static const char *helptext = + "flag may make the first mount very slow, because the \"free space fixup\" procedure\n" + "takes time. This feature is supported by the Linux kernel starting from version 3.0.\n"; + ++static int create_inum_attr(ino_t inum, const char *name) ++{ ++ char *str; ++ int ret; ++ ++ if (!do_create_inum_attr) ++ return 0; ++ ++ ret = asprintf(&str, "%llu", (unsigned long long)inum); ++ if (ret < 0) ++ return -1; ++ ++ ret = lsetxattr(name, "user.image-inode-number", str, ret, 0); ++ ++ free(str); ++ ++ return ret; ++} ++ + /** + * make_path - make a path name from a directory and a name. + * @dir: directory path name +@@ -615,6 +639,10 @@ static int get_options(int argc, char**argv) + case 'U': + squash_owner = 1; + break; ++ case 'a': ++ do_create_inum_attr = 1; ++ break; ++ + } + } + +@@ -1063,12 +1091,12 @@ static int inode_add_xattr(struct ubifs_ino_node *host_ino, + ssize_t pos = 0; + void *attrval = NULL; + +- len = listxattr(path_name, NULL, 0); ++ len = llistxattr(path_name, NULL, 0); + if (len < 0) { + if (errno == ENOENT) + return 0; + +- sys_err_msg("flistxattr failed on %s", path_name); ++ sys_err_msg("llistxattr failed on %s", path_name); + + return len; + } +@@ -1078,9 +1106,9 @@ static int inode_add_xattr(struct ubifs_ino_node *host_ino, + + buf = xmalloc(len); + +- len = listxattr(path_name, buf, len); ++ len = llistxattr(path_name, buf, len); + if (len < 0) { +- sys_err_msg("flistxattr failed on %s", path_name); ++ sys_err_msg("llistxattr failed on %s", path_name); + goto out_free; + } + +@@ -1091,19 +1119,37 @@ static int inode_add_xattr(struct ubifs_ino_node *host_ino, + name = buf + pos; + pos += strlen(name) + 1; + +- attrsize = getxattr(path_name, name, NULL, 0); ++ attrsize = lgetxattr(path_name, name, NULL, 0); + if (attrsize < 0) { +- sys_err_msg("getxattr failed on %s", path_name); ++ sys_err_msg("lgetxattr failed on %s", path_name); + goto out_free; + } + + attrval = xmalloc(attrsize); +- attrsize = getxattr(path_name, name, attrval, attrsize); ++ attrsize = lgetxattr(path_name, name, attrval, attrsize); + if (attrsize < 0) { +- sys_err_msg("getxattr failed on %s", path_name); ++ sys_err_msg("lgetxattr failed on %s", path_name); + goto out_free; + } + ++ if (!strcmp(name, "user.image-inode-number")) { ++ ino_t inum_from_xattr; ++ ++ inum_from_xattr = strtoull(attrval, NULL, 10); ++ if (inum != inum_from_xattr) { ++ errno = EINVAL; ++ sys_err_msg("calculated inum (%llu) doesn't match inum from xattr (%llu) on %s", ++ (unsigned long long)inum, ++ (unsigned long long)inum_from_xattr, ++ path_name); ++ goto out_free; ++ } ++ ++ free(attrval); ++ attrval = NULL; ++ continue; ++ } ++ + nm.name = name; + nm.len = strlen(name); + +@@ -1634,6 +1680,10 @@ static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st, + goto out_free; + } + ++ err = create_inum_attr(inum, name); ++ if (err) ++ goto out_free; ++ + err = add_dent_node(dir_inum, entry->d_name, inum, type); + if (err) + goto out_free; +@@ -1686,6 +1736,10 @@ static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st, + goto out_free; + } + ++ err = create_inum_attr(inum, name); ++ if (err) ++ goto out_free; ++ + err = add_dent_node(dir_inum, nh_elt->name, inum, type); + if (err) + goto out_free; +@@ -1755,6 +1809,11 @@ static int write_data(void) + } + + head_flags = 0; ++ ++ err = create_inum_attr(UBIFS_ROOT_INO, root); ++ if (err) ++ return err; ++ + err = add_directory(root, UBIFS_ROOT_INO, &root_st, !!root); + if (err) + return err; diff --git a/patches/mtd-utils-1.5.2/series b/patches/mtd-utils-1.5.2/series new file mode 100644 index 000000000..981492260 --- /dev/null +++ b/patches/mtd-utils-1.5.2/series @@ -0,0 +1,10 @@ +# generated by git-ptx-patches +#tag:base --start-number 1 +0001-make-ubifs-optional.patch +0002-Make-liblzo-optional-for-ubifs-tools.patch +0003-mkfs.ubifs-change-add_directory-argument-to-existing.patch +0004-mkfs.ubifs-use-xmalloc-xzalloc-for-allocating-memory.patch +0005-mkfs.ubifs-simplify-make_path-with-xasprintf.patch +0006-mkfs.ubifs-Add-extended-attribute-support.patch +0007-mkfs.ubifs-Optionally-create-extended-attribute-with.patch +# 7f992a19fb7184dce60b52e08bb6e49d - git-ptx-patches magic |