forked from pengutronix/genimage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image-ext2.c
129 lines (111 loc) · 3.29 KB
/
image-ext2.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright (c) 2011 Sascha Hauer <[email protected]>, Pengutronix
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include <confuse.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "genimage.h"
static int ext2_generate(struct image *image)
{
int ret;
const char *extraargs = cfg_getstr(image->imagesec, "extraargs");
const char *features = cfg_getstr(image->imagesec, "features");
const char *label = cfg_getstr(image->imagesec, "label");
const char *fs_timestamp = cfg_getstr(image->imagesec, "fs-timestamp");
ret = systemp(image, "%s -d %s --size-in-blocks=%lld -i 16384 %s %s",
get_opt("genext2fs"),
mountpath(image), image->size / 1024, imageoutfile(image),
extraargs);
if (ret)
return ret;
if (features && features[0] != '\0') {
ret = systemp(image, "%s -O \"%s\" %s", get_opt("tune2fs"),
features, imageoutfile(image));
if (ret)
return ret;
}
if (label && label[0] != '\0') {
ret = systemp(image, "%s -L \"%s\" %s", get_opt("tune2fs"),
label, imageoutfile(image));
if (ret)
return ret;
}
ret = systemp(image, "%s -pvfD %s", get_opt("e2fsck"),
imageoutfile(image));
/* e2fsck return 1 when the filesystem was successfully modified */
if (ret > 2)
return ret;
if (fs_timestamp) {
ret = systemp(image, "echo '"
"set_current_time %s\n"
"set_super_value mkfs_time %s\n"
"set_super_value lastcheck %s\n"
"set_super_value mtime 00000000' | %s -w '%s' > /dev/null",
fs_timestamp, fs_timestamp, fs_timestamp,
get_opt("debugfs"), imageoutfile(image));
if (ret)
return ret;
}
return 0;
}
static int ext2_setup(struct image *image, cfg_t *cfg)
{
if (!image->size) {
image_error(image, "no size given or must not be zero\n");
return -EINVAL;
}
return 0;
}
static cfg_opt_t ext2_opts[] = {
CFG_STR("extraargs", "", CFGF_NONE),
CFG_STR("features", 0, CFGF_NONE),
CFG_STR("label", 0, CFGF_NONE),
CFG_STR("fs-timestamp", NULL, CFGF_NONE),
CFG_END()
};
struct image_handler ext2_handler = {
.type = "ext2",
.generate = ext2_generate,
.setup = ext2_setup,
.opts = ext2_opts,
};
static cfg_opt_t ext3_opts[] = {
CFG_STR("extraargs", "", CFGF_NONE),
CFG_STR("features", "has_journal", CFGF_NONE),
CFG_STR("label", 0, CFGF_NONE),
CFG_STR("fs-timestamp", NULL, CFGF_NONE),
CFG_END()
};
struct image_handler ext3_handler = {
.type = "ext3",
.generate = ext2_generate,
.setup = ext2_setup,
.opts = ext3_opts,
};
static cfg_opt_t ext4_opts[] = {
CFG_STR("extraargs", "", CFGF_NONE),
CFG_STR("features", "extents,uninit_bg,dir_index,has_journal", CFGF_NONE),
CFG_STR("label", 0, CFGF_NONE),
CFG_STR("fs-timestamp", NULL, CFGF_NONE),
CFG_END()
};
struct image_handler ext4_handler = {
.type = "ext4",
.generate = ext2_generate,
.setup = ext2_setup,
.opts = ext4_opts,
};