2019-05-29 16:57:50 -07:00
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2008-07-14 19:08:37 +03:00
|
|
|
|
/*
|
|
|
|
|
* This file is part of UBIFS.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2006-2008 Nokia Corporation.
|
|
|
|
|
* Copyright (C) 2006, 2007 University of Szeged, Hungary
|
|
|
|
|
*
|
|
|
|
|
* Authors: Adrian Hunter
|
|
|
|
|
* Artem Bityutskiy (Битюцкий Артём)
|
|
|
|
|
* Zoltan Sogor
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This file provides a single place to access to compression and
|
|
|
|
|
* decompression.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-03-15 18:30:47 +08:00
|
|
|
|
#include <crypto/acompress.h>
|
2025-03-15 18:30:50 +08:00
|
|
|
|
#include <linux/highmem.h>
|
2008-07-14 19:08:37 +03:00
|
|
|
|
#include "ubifs.h"
|
|
|
|
|
|
2025-04-07 18:03:02 +08:00
|
|
|
|
union ubifs_in_ptr {
|
|
|
|
|
const void *buf;
|
|
|
|
|
struct folio *folio;
|
|
|
|
|
};
|
|
|
|
|
|
2008-07-14 19:08:37 +03:00
|
|
|
|
/* Fake description object for the "none" compressor */
|
|
|
|
|
static struct ubifs_compressor none_compr = {
|
|
|
|
|
.compr_type = UBIFS_COMPR_NONE,
|
2008-11-01 14:57:49 +02:00
|
|
|
|
.name = "none",
|
2008-07-14 19:08:37 +03:00
|
|
|
|
.capi_name = "",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_UBIFS_FS_LZO
|
|
|
|
|
static struct ubifs_compressor lzo_compr = {
|
|
|
|
|
.compr_type = UBIFS_COMPR_LZO,
|
2008-11-01 14:57:49 +02:00
|
|
|
|
.name = "lzo",
|
2008-07-14 19:08:37 +03:00
|
|
|
|
.capi_name = "lzo",
|
|
|
|
|
};
|
|
|
|
|
#else
|
|
|
|
|
static struct ubifs_compressor lzo_compr = {
|
|
|
|
|
.compr_type = UBIFS_COMPR_LZO,
|
2008-11-01 14:57:49 +02:00
|
|
|
|
.name = "lzo",
|
2008-07-14 19:08:37 +03:00
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_UBIFS_FS_ZLIB
|
|
|
|
|
static struct ubifs_compressor zlib_compr = {
|
|
|
|
|
.compr_type = UBIFS_COMPR_ZLIB,
|
|
|
|
|
.name = "zlib",
|
|
|
|
|
.capi_name = "deflate",
|
|
|
|
|
};
|
|
|
|
|
#else
|
|
|
|
|
static struct ubifs_compressor zlib_compr = {
|
|
|
|
|
.compr_type = UBIFS_COMPR_ZLIB,
|
|
|
|
|
.name = "zlib",
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-05-15 23:02:02 +02:00
|
|
|
|
#ifdef CONFIG_UBIFS_FS_ZSTD
|
|
|
|
|
static struct ubifs_compressor zstd_compr = {
|
|
|
|
|
.compr_type = UBIFS_COMPR_ZSTD,
|
|
|
|
|
.name = "zstd",
|
|
|
|
|
.capi_name = "zstd",
|
|
|
|
|
};
|
|
|
|
|
#else
|
|
|
|
|
static struct ubifs_compressor zstd_compr = {
|
|
|
|
|
.compr_type = UBIFS_COMPR_ZSTD,
|
|
|
|
|
.name = "zstd",
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-07-14 19:08:37 +03:00
|
|
|
|
/* All UBIFS compressors */
|
|
|
|
|
struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
|
|
|
|
|
|
2025-04-07 18:03:02 +08:00
|
|
|
|
static void ubifs_compress_common(int *compr_type, union ubifs_in_ptr in_ptr,
|
|
|
|
|
size_t in_offset, int in_len, bool in_folio,
|
|
|
|
|
void *out_buf, int *out_len)
|
2025-03-15 18:30:47 +08:00
|
|
|
|
{
|
2025-04-07 18:03:02 +08:00
|
|
|
|
struct ubifs_compressor *compr = ubifs_compressors[*compr_type];
|
2025-03-15 18:30:47 +08:00
|
|
|
|
int dlen = *out_len;
|
|
|
|
|
int err;
|
|
|
|
|
|
2025-04-07 18:03:02 +08:00
|
|
|
|
if (*compr_type == UBIFS_COMPR_NONE)
|
|
|
|
|
goto no_compr;
|
|
|
|
|
|
|
|
|
|
/* If the input data is small, do not even try to compress it */
|
|
|
|
|
if (in_len < UBIFS_MIN_COMPR_LEN)
|
|
|
|
|
goto no_compr;
|
|
|
|
|
|
2025-03-15 18:30:47 +08:00
|
|
|
|
dlen = min(dlen, in_len - UBIFS_MIN_COMPRESS_DIFF);
|
|
|
|
|
|
2025-04-07 18:03:02 +08:00
|
|
|
|
do {
|
|
|
|
|
ACOMP_REQUEST_ON_STACK(req, compr->cc);
|
|
|
|
|
DECLARE_CRYPTO_WAIT(wait);
|
|
|
|
|
|
|
|
|
|
acomp_request_set_callback(req, 0, NULL, NULL);
|
|
|
|
|
if (in_folio)
|
|
|
|
|
acomp_request_set_src_folio(req, in_ptr.folio,
|
|
|
|
|
in_offset, in_len);
|
|
|
|
|
else
|
|
|
|
|
acomp_request_set_src_dma(req, in_ptr.buf, in_len);
|
|
|
|
|
acomp_request_set_dst_dma(req, out_buf, dlen);
|
|
|
|
|
err = crypto_acomp_compress(req);
|
|
|
|
|
dlen = req->dlen;
|
|
|
|
|
if (err != -EAGAIN)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
req = ACOMP_REQUEST_CLONE(req, GFP_NOFS | __GFP_NOWARN);
|
|
|
|
|
acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
|
|
|
|
|
crypto_req_done, &wait);
|
|
|
|
|
err = crypto_acomp_compress(req);
|
|
|
|
|
err = crypto_wait_req(err, &wait);
|
|
|
|
|
dlen = req->dlen;
|
|
|
|
|
acomp_request_free(req);
|
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
|
|
*out_len = dlen;
|
|
|
|
|
if (err)
|
|
|
|
|
goto no_compr;
|
2025-03-15 18:30:47 +08:00
|
|
|
|
|
2025-04-07 18:03:02 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
no_compr:
|
|
|
|
|
if (in_folio)
|
|
|
|
|
memcpy_from_folio(out_buf, in_ptr.folio, in_offset, in_len);
|
|
|
|
|
else
|
|
|
|
|
memcpy(out_buf, in_ptr.buf, in_len);
|
|
|
|
|
*out_len = in_len;
|
|
|
|
|
*compr_type = UBIFS_COMPR_NONE;
|
2025-03-15 18:30:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 19:08:37 +03:00
|
|
|
|
/**
|
|
|
|
|
* ubifs_compress - compress data.
|
2024-05-02 13:16:55 -07:00
|
|
|
|
* @c: UBIFS file-system description object
|
2008-07-14 19:08:37 +03:00
|
|
|
|
* @in_buf: data to compress
|
|
|
|
|
* @in_len: length of the data to compress
|
|
|
|
|
* @out_buf: output buffer where compressed data should be stored
|
|
|
|
|
* @out_len: output buffer length is returned here
|
|
|
|
|
* @compr_type: type of compression to use on enter, actually used compression
|
|
|
|
|
* type on exit
|
|
|
|
|
*
|
|
|
|
|
* This function compresses input buffer @in_buf of length @in_len and stores
|
|
|
|
|
* the result in the output buffer @out_buf and the resulting length in
|
|
|
|
|
* @out_len. If the input buffer does not compress, it is just copied to the
|
|
|
|
|
* @out_buf. The same happens if @compr_type is %UBIFS_COMPR_NONE or if
|
|
|
|
|
* compression error occurred.
|
|
|
|
|
*
|
|
|
|
|
* Note, if the input buffer was not compressed, it is copied to the output
|
|
|
|
|
* buffer and %UBIFS_COMPR_NONE is returned in @compr_type.
|
|
|
|
|
*/
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
void ubifs_compress(const struct ubifs_info *c, const void *in_buf,
|
|
|
|
|
int in_len, void *out_buf, int *out_len, int *compr_type)
|
2008-07-14 19:08:37 +03:00
|
|
|
|
{
|
2025-04-07 18:03:02 +08:00
|
|
|
|
union ubifs_in_ptr in_ptr = { .buf = in_buf };
|
2008-07-14 19:08:37 +03:00
|
|
|
|
|
2025-04-07 18:03:02 +08:00
|
|
|
|
ubifs_compress_common(compr_type, in_ptr, 0, in_len, false,
|
|
|
|
|
out_buf, out_len);
|
2008-07-14 19:08:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2025-03-15 18:30:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* ubifs_compress_folio - compress folio.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
* @in_folio: data to compress
|
|
|
|
|
* @in_offset: offset into @in_folio
|
|
|
|
|
* @in_len: length of the data to compress
|
|
|
|
|
* @out_buf: output buffer where compressed data should be stored
|
|
|
|
|
* @out_len: output buffer length is returned here
|
|
|
|
|
* @compr_type: type of compression to use on enter, actually used compression
|
|
|
|
|
* type on exit
|
|
|
|
|
*
|
|
|
|
|
* This function compresses input folio @in_folio of length @in_len and
|
|
|
|
|
* stores the result in the output buffer @out_buf and the resulting length
|
|
|
|
|
* in @out_len. If the input buffer does not compress, it is just copied
|
|
|
|
|
* to the @out_buf. The same happens if @compr_type is %UBIFS_COMPR_NONE
|
|
|
|
|
* or if compression error occurred.
|
|
|
|
|
*
|
|
|
|
|
* Note, if the input buffer was not compressed, it is copied to the output
|
|
|
|
|
* buffer and %UBIFS_COMPR_NONE is returned in @compr_type.
|
|
|
|
|
*/
|
|
|
|
|
void ubifs_compress_folio(const struct ubifs_info *c, struct folio *in_folio,
|
|
|
|
|
size_t in_offset, int in_len, void *out_buf,
|
|
|
|
|
int *out_len, int *compr_type)
|
|
|
|
|
{
|
2025-04-07 18:03:02 +08:00
|
|
|
|
union ubifs_in_ptr in_ptr = { .folio = in_folio };
|
2025-03-15 18:30:50 +08:00
|
|
|
|
|
2025-04-07 18:03:02 +08:00
|
|
|
|
ubifs_compress_common(compr_type, in_ptr, in_offset, in_len, true,
|
|
|
|
|
out_buf, out_len);
|
|
|
|
|
}
|
2025-03-15 18:30:50 +08:00
|
|
|
|
|
2025-04-07 18:03:02 +08:00
|
|
|
|
static int ubifs_decompress_common(const struct ubifs_info *c,
|
|
|
|
|
const void *in_buf, int in_len,
|
|
|
|
|
void *out_ptr, size_t out_offset,
|
|
|
|
|
int *out_len, bool out_folio,
|
|
|
|
|
int compr_type)
|
|
|
|
|
{
|
|
|
|
|
struct ubifs_compressor *compr;
|
|
|
|
|
int dlen = *out_len;
|
|
|
|
|
int err;
|
2025-03-15 18:30:50 +08:00
|
|
|
|
|
2025-04-07 18:03:02 +08:00
|
|
|
|
if (unlikely(compr_type < 0 || compr_type >= UBIFS_COMPR_TYPES_CNT)) {
|
|
|
|
|
ubifs_err(c, "invalid compression type %d", compr_type);
|
|
|
|
|
return -EINVAL;
|
2025-03-15 18:30:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-04-07 18:03:02 +08:00
|
|
|
|
compr = ubifs_compressors[compr_type];
|
2025-03-15 18:30:50 +08:00
|
|
|
|
|
2025-04-07 18:03:02 +08:00
|
|
|
|
if (unlikely(!compr->capi_name)) {
|
|
|
|
|
ubifs_err(c, "%s compression is not compiled in", compr->name);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2025-03-15 18:30:50 +08:00
|
|
|
|
|
2025-04-07 18:03:02 +08:00
|
|
|
|
if (compr_type == UBIFS_COMPR_NONE) {
|
|
|
|
|
if (out_folio)
|
|
|
|
|
memcpy_to_folio(out_ptr, out_offset, in_buf, in_len);
|
|
|
|
|
else
|
|
|
|
|
memcpy(out_ptr, in_buf, in_len);
|
|
|
|
|
*out_len = in_len;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2025-03-15 18:30:47 +08:00
|
|
|
|
|
2025-04-07 18:03:02 +08:00
|
|
|
|
do {
|
|
|
|
|
ACOMP_REQUEST_ON_STACK(req, compr->cc);
|
|
|
|
|
DECLARE_CRYPTO_WAIT(wait);
|
2025-03-15 18:30:47 +08:00
|
|
|
|
|
2025-04-07 18:03:02 +08:00
|
|
|
|
acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
|
|
|
|
|
crypto_req_done, &wait);
|
|
|
|
|
acomp_request_set_src_dma(req, in_buf, in_len);
|
|
|
|
|
if (out_folio)
|
|
|
|
|
acomp_request_set_dst_folio(req, out_ptr, out_offset,
|
|
|
|
|
dlen);
|
|
|
|
|
else
|
|
|
|
|
acomp_request_set_dst_dma(req, out_ptr, dlen);
|
|
|
|
|
err = crypto_acomp_decompress(req);
|
|
|
|
|
dlen = req->dlen;
|
|
|
|
|
if (err != -EAGAIN)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
req = ACOMP_REQUEST_CLONE(req, GFP_NOFS | __GFP_NOWARN);
|
|
|
|
|
err = crypto_acomp_decompress(req);
|
|
|
|
|
err = crypto_wait_req(err, &wait);
|
|
|
|
|
dlen = req->dlen;
|
|
|
|
|
acomp_request_free(req);
|
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
|
|
*out_len = dlen;
|
2025-03-15 18:30:47 +08:00
|
|
|
|
if (err)
|
|
|
|
|
ubifs_err(c, "cannot decompress %d bytes, compressor %s, error %d",
|
2025-04-07 18:03:02 +08:00
|
|
|
|
in_len, compr->name, err);
|
2025-03-15 18:30:47 +08:00
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 19:08:37 +03:00
|
|
|
|
/**
|
|
|
|
|
* ubifs_decompress - decompress data.
|
2024-05-02 13:16:55 -07:00
|
|
|
|
* @c: UBIFS file-system description object
|
2008-07-14 19:08:37 +03:00
|
|
|
|
* @in_buf: data to decompress
|
|
|
|
|
* @in_len: length of the data to decompress
|
|
|
|
|
* @out_buf: output buffer where decompressed data should
|
|
|
|
|
* @out_len: output length is returned here
|
|
|
|
|
* @compr_type: type of compression
|
|
|
|
|
*
|
|
|
|
|
* This function decompresses data from buffer @in_buf into buffer @out_buf.
|
|
|
|
|
* The length of the uncompressed data is returned in @out_len. This functions
|
|
|
|
|
* returns %0 on success or a negative error code on failure.
|
|
|
|
|
*/
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
int ubifs_decompress(const struct ubifs_info *c, const void *in_buf,
|
|
|
|
|
int in_len, void *out_buf, int *out_len, int compr_type)
|
2008-07-14 19:08:37 +03:00
|
|
|
|
{
|
2025-04-07 18:03:02 +08:00
|
|
|
|
return ubifs_decompress_common(c, in_buf, in_len, out_buf, 0, out_len,
|
|
|
|
|
false, compr_type);
|
2025-03-15 18:30:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ubifs_decompress_folio - decompress folio.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
* @in_buf: data to decompress
|
|
|
|
|
* @in_len: length of the data to decompress
|
|
|
|
|
* @out_folio: output folio where decompressed data should
|
|
|
|
|
* @out_offset: offset into @out_folio
|
|
|
|
|
* @out_len: output length is returned here
|
|
|
|
|
* @compr_type: type of compression
|
|
|
|
|
*
|
|
|
|
|
* This function decompresses data from buffer @in_buf into folio
|
|
|
|
|
* @out_folio. The length of the uncompressed data is returned in
|
|
|
|
|
* @out_len. This functions returns %0 on success or a negative error
|
|
|
|
|
* code on failure.
|
|
|
|
|
*/
|
|
|
|
|
int ubifs_decompress_folio(const struct ubifs_info *c, const void *in_buf,
|
|
|
|
|
int in_len, struct folio *out_folio,
|
|
|
|
|
size_t out_offset, int *out_len, int compr_type)
|
|
|
|
|
{
|
2025-04-07 18:03:02 +08:00
|
|
|
|
return ubifs_decompress_common(c, in_buf, in_len, out_folio,
|
|
|
|
|
out_offset, out_len, true, compr_type);
|
2008-07-14 19:08:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* compr_init - initialize a compressor.
|
|
|
|
|
* @compr: compressor description object
|
|
|
|
|
*
|
|
|
|
|
* This function initializes the requested compressor and returns zero in case
|
|
|
|
|
* of success or a negative error code in case of failure.
|
|
|
|
|
*/
|
|
|
|
|
static int __init compr_init(struct ubifs_compressor *compr)
|
|
|
|
|
{
|
|
|
|
|
if (compr->capi_name) {
|
2025-03-15 18:30:47 +08:00
|
|
|
|
compr->cc = crypto_alloc_acomp(compr->capi_name, 0, 0);
|
2008-07-14 19:08:37 +03:00
|
|
|
|
if (IS_ERR(compr->cc)) {
|
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 10:39:42 +00:00
|
|
|
|
pr_err("UBIFS error (pid %d): cannot initialize compressor %s, error %ld",
|
|
|
|
|
current->pid, compr->name, PTR_ERR(compr->cc));
|
2008-07-14 19:08:37 +03:00
|
|
|
|
return PTR_ERR(compr->cc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ubifs_compressors[compr->compr_type] = compr;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* compr_exit - de-initialize a compressor.
|
|
|
|
|
* @compr: compressor description object
|
|
|
|
|
*/
|
|
|
|
|
static void compr_exit(struct ubifs_compressor *compr)
|
|
|
|
|
{
|
|
|
|
|
if (compr->capi_name)
|
2025-03-15 18:30:47 +08:00
|
|
|
|
crypto_free_acomp(compr->cc);
|
2008-07-14 19:08:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ubifs_compressors_init - initialize UBIFS compressors.
|
|
|
|
|
*
|
|
|
|
|
* This function initializes the compressor which were compiled in. Returns
|
|
|
|
|
* zero in case of success and a negative error code in case of failure.
|
|
|
|
|
*/
|
|
|
|
|
int __init ubifs_compressors_init(void)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
err = compr_init(&lzo_compr);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
2019-05-15 23:02:02 +02:00
|
|
|
|
err = compr_init(&zstd_compr);
|
2008-07-14 19:08:37 +03:00
|
|
|
|
if (err)
|
|
|
|
|
goto out_lzo;
|
|
|
|
|
|
2019-05-15 23:02:02 +02:00
|
|
|
|
err = compr_init(&zlib_compr);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_zstd;
|
|
|
|
|
|
2008-07-14 19:08:37 +03:00
|
|
|
|
ubifs_compressors[UBIFS_COMPR_NONE] = &none_compr;
|
|
|
|
|
return 0;
|
|
|
|
|
|
2019-05-15 23:02:02 +02:00
|
|
|
|
out_zstd:
|
|
|
|
|
compr_exit(&zstd_compr);
|
2008-07-14 19:08:37 +03:00
|
|
|
|
out_lzo:
|
|
|
|
|
compr_exit(&lzo_compr);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ubifs_compressors_exit - de-initialize UBIFS compressors.
|
|
|
|
|
*/
|
2008-12-04 17:04:18 +03:00
|
|
|
|
void ubifs_compressors_exit(void)
|
2008-07-14 19:08:37 +03:00
|
|
|
|
{
|
|
|
|
|
compr_exit(&lzo_compr);
|
|
|
|
|
compr_exit(&zlib_compr);
|
2019-05-15 23:02:02 +02:00
|
|
|
|
compr_exit(&zstd_compr);
|
2008-07-14 19:08:37 +03:00
|
|
|
|
}
|