8dc109537a195c0476a5c02cc2eb4391157ff477
1 // SPDX-License-Identifier: GPL-2.0-or-later
7 read_uint_from_file(char *dirname
, char *filename
, unsigned int *i
)
13 snprintf(fname
, sizeof(fname
), "%s/%s", dirname
, filename
);
15 f
= fopen(fname
, "r");
19 if (fscanf(f
, "%u", i
) == 1)
27 *read_string_from_file(const char *dirname
, const char *filename
, char *buf
, size_t bufsz
)
33 snprintf(fname
, sizeof(fname
), "%s/%s", dirname
, filename
);
35 f
= fopen(fname
, "r");
39 if (fgets(buf
, bufsz
, f
) == NULL
) {
46 /* make sure the string is \0 terminated */
47 buf
[bufsz
- 1] = '\0';
49 /* remove trailing whitespace */
51 while (i
> 0 && buf
[i
] <= ' ')
57 int block_file_identify(FILE *f
, uint64_t offset
)
62 fseeko(f
, offset
, SEEK_SET
);
63 n
= fread(&magic
, sizeof(magic
), 1, f
);
64 if (magic
== cpu_to_le32(0x88b1f)) {
68 fseeko(f
, offset
+ 0x400, SEEK_SET
);
69 n
= fread(&magic
, sizeof(magic
), 1, f
);
73 if (magic
== cpu_to_le32(0xF2F52010))
77 fseeko(f
, offset
+ 0x438, SEEK_SET
);
78 n
= fread(&magic
, sizeof(magic
), 1, f
);
82 if ((le32_to_cpu(magic
) & 0xffff) == 0xef53)
88 static bool use_f2fs(struct volume
*v
, uint64_t offset
, const char *bdev
)
94 fd
= open(bdev
, O_RDONLY
);
98 if (ioctl(fd
, BLKGETSIZE64
, &size
) == 0)
99 ret
= size
- offset
> F2FS_MINSIZE
;
106 int block_volume_format(struct volume
*v
, uint64_t offset
, const char *bdev
)
111 switch (volume_identify(v
)) {
113 snprintf(str
, sizeof(str
), "gzip -cd %s > /tmp/sysupgrade.tar", v
->blk
);
117 ULOG_INFO("overlay filesystem in %s has not been formatted yet\n", v
->blk
);
118 if (use_f2fs(v
, offset
, bdev
))
119 snprintf(str
, sizeof(str
), "mkfs.f2fs -q -l rootfs_data %s", v
->blk
);
121 snprintf(str
, sizeof(str
), "mkfs.ext4 -q -L rootfs_data %s", v
->blk
);