diff options
Diffstat (limited to 'ubifs-utils/mkfs.ubifs/mkfs.ubifs.c')
-rw-r--r-- | ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c index 8211ada..42a47f8 100644 --- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c @@ -26,7 +26,7 @@ #include <crc32.h> #include "common.h" #include <sys/types.h> -#ifndef WITHOUT_XATTR +#ifdef WITH_XATTR #include <sys/xattr.h> #endif @@ -35,7 +35,7 @@ #include <selinux/label.h> #endif -#ifndef WITHOUT_ZSTD +#ifdef WITH_ZSTD #include <zstd.h> #endif @@ -56,7 +56,6 @@ #ifdef WITH_SELINUX #define XATTR_NAME_SELINUX "security.selinux" static struct selabel_handle *sehnd; -static char *secontext; #endif /** @@ -540,10 +539,12 @@ static void select_default_compr(void) return; } -#ifdef WITHOUT_LZO +#ifdef WITH_LZO + c->default_compr = UBIFS_COMPR_LZO; +#elif defined(WITH_ZLIB) c->default_compr = UBIFS_COMPR_ZLIB; #else - c->default_compr = UBIFS_COMPR_LZO; + c->default_compr = UBIFS_COMPR_NONE; #endif } @@ -682,26 +683,30 @@ static int get_options(int argc, char**argv) case 'x': if (strcmp(optarg, "none") == 0) c->default_compr = UBIFS_COMPR_NONE; +#ifdef WITH_ZLIB else if (strcmp(optarg, "zlib") == 0) c->default_compr = UBIFS_COMPR_ZLIB; -#ifndef WITHOUT_ZSTD +#endif +#ifdef WITH_ZSTD else if (strcmp(optarg, "zstd") == 0) c->default_compr = UBIFS_COMPR_ZSTD; #endif -#ifndef WITHOUT_LZO +#ifdef WITH_LZO + else if (strcmp(optarg, "lzo") == 0) + c->default_compr = UBIFS_COMPR_LZO; +#endif +#if defined(WITH_LZO) && defined(WITH_ZLIB) else if (strcmp(optarg, "favor_lzo") == 0) { c->default_compr = UBIFS_COMPR_LZO; c->favor_lzo = 1; - } else if (strcmp(optarg, "lzo") == 0) { - c->default_compr = UBIFS_COMPR_LZO; } #endif else return err_msg("bad compressor name"); break; case 'X': -#ifdef WITHOUT_LZO - return err_msg("built without LZO support"); +#if !defined(WITH_LZO) && !defined(WITH_ZLIB) + return err_msg("built without LZO or ZLIB support"); #else c->favor_percent = strtol(optarg, &endp, 0); if (*endp != '\0' || endp == optarg || @@ -733,6 +738,7 @@ static int get_options(int argc, char**argv) if (!context) return err_msg("xmalloc failed\n"); memcpy(context, optarg, context_len); + context[context_len] = '\0'; /* Make sure root directory exists */ if (stat(context, &context_st)) @@ -1288,7 +1294,7 @@ out: return ret; } -#ifdef WITHOUT_XATTR +#ifndef WITH_XATTR static inline int create_inum_attr(ino_t inum, const char *name) { (void)inum; @@ -1388,6 +1394,15 @@ static int inode_add_xattr(struct ubifs_ino_node *host_ino, continue; } +#ifdef WITH_SELINUX + /* + Ignore selinux attributes if we have a label file, they are + instead provided by inode_add_selinux_xattr. + */ + if (!strcmp(name, XATTR_NAME_SELINUX) && context && sehnd) + continue; +#endif + ret = add_xattr(host_ino, st, inum, name, attrbuf, attrsize); if (ret < 0) goto out_free; @@ -1412,12 +1427,10 @@ static int inode_add_selinux_xattr(struct ubifs_ino_node *host_ino, char *sepath = NULL; char *name; unsigned int con_size; + char *secontext; - if (!context || !sehnd) { - secontext = NULL; - con_size = 0; + if (!context || !sehnd) return 0; - } if (path_name[strlen(root)] == '/') sepath = strdup(&path_name[strlen(root)]); @@ -1594,11 +1607,11 @@ static int add_inode(struct stat *st, ino_t inum, void *data, len = UBIFS_INO_NODE_SZ + data_len; if (xattr_path) { -#ifdef WITH_SELINUX ret = inode_add_selinux_xattr(ino, xattr_path, st, inum); -#else + if (ret < 0) + return ret; + ret = inode_add_xattr(ino, xattr_path, st, inum); -#endif if (ret < 0) return ret; } @@ -1851,10 +1864,12 @@ static int add_file(const char *path_name, struct stat *st, ino_t inum, out_len = NODE_BUFFER_SIZE - UBIFS_DATA_NODE_SZ; if (c->default_compr == UBIFS_COMPR_NONE && !c->encrypted && (flags & FS_COMPR_FL)) -#ifdef WITHOUT_LZO +#ifdef WITH_LZO + use_compr = UBIFS_COMPR_LZO; +#elif defined(WITH_ZLIB) use_compr = UBIFS_COMPR_ZLIB; #else - use_compr = UBIFS_COMPR_LZO; + use_compr = UBIFS_COMPR_NONE; #endif else use_compr = c->default_compr; |