Skip to content

Commit 20acb09

Browse files
authored
Add erofs-utils package (#12971)
1 parent fdaf7da commit 20acb09

12 files changed

Lines changed: 1147 additions & 1 deletion

LICENSES-AND-NOTICES/SPECS/LICENSES-MAP.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSES-AND-NOTICES/SPECS/data/licenses.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
"enchant2",
213213
"enscript",
214214
"environment-modules",
215+
"erofs-utils",
215216
"evemu",
216217
"execstack",
217218
"exempi",
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
From bc8ec19a4ed741c9b457387dcba2b647e819b16d Mon Sep 17 00:00:00 2001
2+
From: Gao Xiang <hsiangkao@linux.alibaba.com>
3+
Date: Wed, 12 Feb 2025 20:36:33 +0800
4+
Subject: [PATCH 1/7] erofs-utils: mkfs: fragment: gracefully exit if temporary
5+
storage is low
6+
7+
Currently, EROFS keeps all fragments into a temporary file for later
8+
packed inode compression. However, this could trigger an unexpected
9+
segfault if temporary storage runs low.
10+
11+
Print a proper error message and gracefully exit.
12+
13+
Closes: https://github.com/erofs/erofs-utils/issues/13
14+
Link: https://lore.kernel.org/r/20250212123633.40004-1-hsiangkao@linux.alibaba.com
15+
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
16+
---
17+
include/erofs/internal.h | 3 ++-
18+
lib/fragments.c | 4 ++++
19+
lib/inode.c | 8 +++-----
20+
3 files changed, 9 insertions(+), 6 deletions(-)
21+
22+
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
23+
index 5f5bc10..2f71557 100644
24+
--- a/include/erofs/internal.h
25+
+++ b/include/erofs/internal.h
26+
@@ -256,7 +256,6 @@ struct erofs_inode {
27+
unsigned int eof_tailrawsize;
28+
29+
union {
30+
- void *compressmeta;
31+
void *chunkindexes;
32+
struct {
33+
uint16_t z_advise;
34+
@@ -274,6 +273,8 @@ struct erofs_inode {
35+
#define z_idata_size idata_size
36+
};
37+
};
38+
+ void *compressmeta;
39+
+
40+
#ifdef WITH_ANDROID
41+
uint64_t capabilities;
42+
#endif
43+
diff --git a/lib/fragments.c b/lib/fragments.c
44+
index 32ac6f5..9633a2b 100644
45+
--- a/lib/fragments.c
46+
+++ b/lib/fragments.c
47+
@@ -266,6 +266,10 @@ int z_erofs_pack_file_from_fd(struct erofs_inode *inode, int fd, u32 tofcrc)
48+
else
49+
rc = 0;
50+
out:
51+
+ if (rc)
52+
+ erofs_err("Failed to record %llu-byte fragment data @ %llu for nid %llu: %d",
53+
+ inode->fragment_size | 0ULL,
54+
+ inode->fragmentoff | 0ULL, inode->nid | 0ULL, rc);
55+
if (memblock)
56+
munmap(memblock, inode->i_size);
57+
return rc;
58+
diff --git a/lib/inode.c b/lib/inode.c
59+
index 7f97030..743e915 100644
60+
--- a/lib/inode.c
61+
+++ b/lib/inode.c
62+
@@ -141,16 +141,14 @@ unsigned int erofs_iput(struct erofs_inode *inode)
63+
free(d);
64+
65+
free(inode->compressmeta);
66+
- if (inode->eof_tailraw)
67+
- free(inode->eof_tailraw);
68+
+ free(inode->eof_tailraw);
69+
list_del(&inode->i_hash);
70+
- if (inode->i_srcpath)
71+
- free(inode->i_srcpath);
72+
+ free(inode->i_srcpath);
73+
74+
if (inode->datasource == EROFS_INODE_DATA_SOURCE_DISKBUF) {
75+
erofs_diskbuf_close(inode->i_diskbuf);
76+
free(inode->i_diskbuf);
77+
- } else if (inode->i_link) {
78+
+ } else {
79+
free(inode->i_link);
80+
}
81+
free(inode);
82+
--
83+
2.48.1
84+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
From d180c898bd0842eaeb54ca0073e6f444bdae8c40 Mon Sep 17 00:00:00 2001
2+
From: Gao Xiang <hsiangkao@linux.alibaba.com>
3+
Date: Thu, 13 Feb 2025 03:15:45 +0800
4+
Subject: [PATCH 2/7] erofs-utils: mkfs: reduce default dict size for LZMA
5+
6+
Change the default dictionary size to 4 times the pcluster size.
7+
This will halve the LZMA internal dictionary size to a maximum of
8+
4MiB per LZMA worker (one worker per CPU in the kernel implementation
9+
unless the module parameter `lzma_streams=` is given.)
10+
11+
It has a very slight impact on the final image sizes, yet users can
12+
always use `-zlzma,dictsize=` to specify a custom value.
13+
14+
_________________________________________________________________________
15+
|______ Testset _____|_______ Vanilla _________|_________ After __________| Command Line
16+
| CoreOS | 741978112 (708 MiB) | 742293504 (708 MiB) | -zlzma,6 -Eall-fragments,fragdedupe=inode -C8192
17+
| | 687501312 (656 MiB) | 687652864 (656 MiB) | -zlzma,6 -Eall-fragments,fragdedupe=inode -C131072
18+
|____________________|__ 658485248 (628 MiB) __|__ 658698240 (629 MiB) __| -zlzma,6 -Eall-fragments,fragdedupe=inode -C1048576
19+
| Fedora KIWI | 2974957568 (2838 MiB) | 2977394688 (2840 MiB) | -zlzma,6 -Eall-fragments,fragdedupe=inode -C8192
20+
| | 2684272640 (2560 MiB) | 2686750720 (2563 MiB) | -zlzma,6 -Eall-fragments,fragdedupe=inode -C131072
21+
|____________________|_ 2550800384 (2433 MiB) _|_ 2553278464 (2435 MiB) __| -zlzma,6 -Eall-fragments,fragdedupe=inode -C1048576
22+
| AOSP system | 432562176 (413 MiB) | 432738304 (413 MiB) | -zlzma,6 -Eall-fragments,fragdedupe=inode -C8192
23+
| partition | 393277440 (376 MiB) | 393351168 (376 MiB) | -zlzma,6 -Eall-fragments,fragdedupe=inode -C131072
24+
|____________________|__ 379260928 (362 MiB) __|__ 379285504 (362 MiB) __| -zlzma,6 -Eall-fragments,fragdedupe=inode -C1048576
25+
26+
Link: https://lore.kernel.org/r/20250212191545.580768-1-hsiangkao@linux.alibaba.com
27+
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
28+
---
29+
lib/compressor_liblzma.c | 2 +-
30+
1 file changed, 1 insertion(+), 1 deletion(-)
31+
32+
diff --git a/lib/compressor_liblzma.c b/lib/compressor_liblzma.c
33+
index d609a28..c4ba585 100644
34+
--- a/lib/compressor_liblzma.c
35+
+++ b/lib/compressor_liblzma.c
36+
@@ -75,7 +75,7 @@ static int erofs_compressor_liblzma_setdictsize(struct erofs_compress *c,
37+
dict_size = erofs_compressor_lzma.default_dictsize;
38+
} else {
39+
dict_size = min_t(u32, Z_EROFS_LZMA_MAX_DICT_SIZE,
40+
- cfg.c_mkfs_pclustersize_max << 3);
41+
+ cfg.c_mkfs_pclustersize_max << 2);
42+
if (dict_size < 32768)
43+
dict_size = 32768;
44+
}
45+
--
46+
2.48.1
47+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
From 5e05ee09a3bc7331549d8e141dac0ccaf30feda5 Mon Sep 17 00:00:00 2001
2+
From: Gao Xiang <hsiangkao@linux.alibaba.com>
3+
Date: Fri, 14 Feb 2025 14:24:05 +0800
4+
Subject: [PATCH 3/7] erofs-utils: mkfs: add missing `errno = 0` before
5+
strto[u]l
6+
7+
strtoull(3) says:
8+
9+
```
10+
Since strtoul() can legitimately return 0 or ULONG_MAX (ULLONG_MAX for
11+
strtoull()) on both success and failure, the calling program should set
12+
errno to 0 before the call, and then determine if an error occurred by
13+
checking whether errno has a nonzero value after the call.
14+
```
15+
16+
Otherwise, `--workers=` could exit with `invalid worker number`.
17+
18+
Fixes: 7894301e1a80 ("erofs-utils: mkfs: add `--workers=#` parameter")
19+
Fixes: 0132cb5ea7d0 ("erofs-utils: mkfs: add `--zfeature-bits` option")
20+
Fixes: 7550a30c332c ("erofs-utils: enable incremental builds")
21+
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
22+
Link: https://lore.kernel.org/r/20250214062407.3281416-1-hsiangkao@linux.alibaba.com
23+
---
24+
mkfs/main.c | 3 +++
25+
1 file changed, 3 insertions(+)
26+
27+
diff --git a/mkfs/main.c b/mkfs/main.c
28+
index 53d330b..b2396d0 100644
29+
--- a/mkfs/main.c
30+
+++ b/mkfs/main.c
31+
@@ -814,6 +814,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
32+
case 520: {
33+
unsigned int processors;
34+
35+
+ errno = 0;
36+
cfg.c_mt_workers = strtoul(optarg, &endptr, 0);
37+
if (errno || *endptr != '\0') {
38+
erofs_err("invalid worker number %s", optarg);
39+
@@ -828,6 +829,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
40+
}
41+
#endif
42+
case 521:
43+
+ errno = 0;
44+
i = strtol(optarg, &endptr, 0);
45+
if (errno || *endptr != '\0') {
46+
erofs_err("invalid zfeature bits %s", optarg);
47+
@@ -844,6 +846,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
48+
} else if (!strcmp(optarg, "rvsp")) {
49+
dataimport_mode = EROFS_MKFS_DATA_IMPORT_RVSP;
50+
} else {
51+
+ errno = 0;
52+
dataimport_mode = strtol(optarg, &endptr, 0);
53+
if (errno || *endptr != '\0') {
54+
erofs_err("invalid --%s=%s",
55+
--
56+
2.48.1
57+

0 commit comments

Comments
 (0)