package/mtd-utils: update to 1.4.5
[openwrt/svn-archive/archive.git] / utils / mtd-utils / patches / 137-mkubifs-allow-to-overwrite-volume-data.patch
1 --- a/mkfs.ubifs/mkfs.ubifs.c
2 +++ b/mkfs.ubifs/mkfs.ubifs.c
3 @@ -110,6 +110,7 @@ static int out_fd;
4 static int out_ubi;
5 static int squash_owner;
6 static int squash_rino_perm = -1;
7 +static int overwrite_volume;
8
9 /* The 'head' (position) which nodes are written */
10 static int head_lnum;
11 @@ -132,7 +133,7 @@ static struct inum_mapping **hash_table;
12 /* Inode creation sequence number */
13 static unsigned long long creat_sqnum;
14
15 -static const char *optstring = "d:r:m:o:D:h?vVe:c:g:f:Fp:k:x:X:j:R:l:j:UQq";
16 +static const char *optstring = "d:r:m:o:OD:h?vVe:c:g:f:Fp:k:x:X:j:R:l:j:UQq";
17
18 static const struct option longopts[] = {
19 {"root", 1, NULL, 'r'},
20 @@ -140,6 +141,7 @@ static const struct option longopts[] =
21 {"leb-size", 1, NULL, 'e'},
22 {"max-leb-cnt", 1, NULL, 'c'},
23 {"output", 1, NULL, 'o'},
24 + {"overwrite", 0, NULL, 'O'},
25 {"devtable", 1, NULL, 'D'},
26 {"help", 0, NULL, 'h'},
27 {"verbose", 0, NULL, 'v'},
28 @@ -176,6 +178,7 @@ static const char *helptext =
29 "-e, --leb-size=SIZE logical erase block size\n"
30 "-c, --max-leb-cnt=COUNT maximum logical erase block count\n"
31 "-o, --output=FILE output to FILE\n"
32 +"-O, --overwrite force overwriting of the existing volume\n"
33 "-j, --jrn-size=SIZE journal size\n"
34 "-R, --reserved=SIZE how much space should be reserved for the super-user\n"
35 "-x, --compr=TYPE compression type - \"lzo\", \"favor_lzo\", \"zlib\" or\n"
36 @@ -594,6 +597,9 @@ static int get_options(int argc, char**a
37 case 'o':
38 output = strdup(optarg);
39 break;
40 + case 'O':
41 + overwrite_volume = 1;
42 + break;
43 case 'D':
44 tbl_file = optarg;
45 if (stat(tbl_file, &st) < 0)
46 @@ -2180,8 +2186,13 @@ static int open_target(void)
47 if (ubi_set_property(out_fd, UBI_PROP_DIRECT_WRITE, 1))
48 return sys_err_msg("ubi_set_property failed");
49
50 - if (check_volume_empty())
51 - return err_msg("UBI volume is not empty");
52 + if (check_volume_empty()) {
53 + if (overwrite_volume)
54 + if (verbose)
55 + printf("Warning: overwriting existing data\n");
56 + else
57 + return err_msg("UBI volume is not empty");
58 + }
59 } else {
60 out_fd = open(output, O_CREAT | O_RDWR | O_TRUNC,
61 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);