1
2
3
4
5
6
7
8
9#include "libbb.h"
10
11uoff_t FAST_FUNC get_volume_size_in_bytes(int fd,
12 const char *override,
13 unsigned override_units,
14 int extend)
15{
16 uoff_t result;
17
18 if (override) {
19 result = XATOOFF(override);
20 if (result >= (uoff_t)(MAXINT(off_t)) / override_units)
21 bb_error_msg_and_die("image size is too big");
22 result *= override_units;
23
24 if (lseek(fd, result - 1, SEEK_SET) != (off_t)-1) {
25 if (extend)
26 xwrite(fd, "", 1);
27 }
28
29
30
31 } else {
32
33 result = xlseek(fd, 0, SEEK_END);
34 }
35
36 xlseek(fd, 0, SEEK_SET);
37
38
39
40
41
42
43
44 if (result < 16*1024)
45 bb_error_msg_and_die("image is too small");
46
47 return result;
48}
49