-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmicrofs_decompressor.c
82 lines (69 loc) · 2.28 KB
/
microfs_decompressor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* microfs - Minimally Improved Compressed Read Only File System
* Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, ..., +%Y
* Erik Edlund <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "microfs.h"
#include <linux/cpumask.h>
#include <linux/sched.h>
#include <linux/wait.h>
static const struct microfs_decompressor decompressor_null = {
.dc_info = NULL
};
static const struct microfs_decompressor* decompressors[] = {
&decompressor_zlib,
&decompressor_lz4,
&decompressor_lzo,
&decompressor_xz,
&decompressor_zstd,
&decompressor_null
};
int microfs_decompressor_init(struct microfs_sb_info* sbi, char* dd,
microfs_decompressor_data_acquirer acquirer,
microfs_decompressor_data_creator creator)
{
int i;
int err = 0;
__u32 decompressor = sbi->si_flags & MICROFS_FLAG_MASK_DECOMPRESSOR;
for (i = 0; decompressors[i]->dc_info; i++) {
if (decompressors[i]->dc_info->li_id == decompressor)
break;
}
if (!decompressors[i]->dc_info) {
pr_err("failed to find a decompressor with id 0x%x\n",
decompressor);
err = -EINVAL;
goto err;
}
if (!decompressors[i]->dc_compiled) {
pr_err("%s: decompressor not compiled\n",
decompressors[i]->dc_info->li_name);
err = -ENOSYS;
goto err;
}
if (decompressors[i]->dc_info->li_min_blksz == 0 &&
sbi->si_blksz < PAGE_SIZE) {
pr_err("%s: block size must be greater than or equal to PAGE_SIZE",
decompressors[i]->dc_info->li_name);
err = -ENOSYS;
goto err;
}
sbi->si_decompressor = decompressors[i];
sbi->si_decompressor_data = NULL;
return acquirer(sbi, dd, &sbi->si_decompressor_data, creator);
err:
return err;
}