aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorSven Eisenberg <sven.eisenberg@novero.com>2016-04-03 21:53:12 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-04-03 22:01:43 +0200
commitb068cf2a7e036da8d0b3533b41886c5605c8139d (patch)
tree0c29bccfabd054c5cafc5dd68e9d161d70bf1286 /libbb
parentcb9264099822505dc2930cfea0b1f9027a02dc06 (diff)
downloadbusybox-w32-b068cf2a7e036da8d0b3533b41886c5605c8139d.tar.gz
busybox-w32-b068cf2a7e036da8d0b3533b41886c5605c8139d.tar.bz2
busybox-w32-b068cf2a7e036da8d0b3533b41886c5605c8139d.zip
ubirmvol: Implement -N switch for ubirmvol
function old new delta get_volid_by_name - 125 +125 ubi_devnum_from_devname - 43 +43 ubi_tools_main 1215 1220 +5 packed_usage 30674 30655 -19 ubirename_main 394 221 -173 ------------------------------------------------------------------------------ (add/remove: 3/0 grow/shrink: 1/2 up/down: 173/-192) Total: -19 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/ubi.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/libbb/ubi.c b/libbb/ubi.c
new file mode 100644
index 000000000..7d3b2952d
--- /dev/null
+++ b/libbb/ubi.c
@@ -0,0 +1,43 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
5 * Copyright (C) 2016 Denys Vlasenko
6 *
7 * Licensed under GPLv2, see file LICENSE in this source tree.
8 */
9//kbuild:lib-y += ubi.o
10
11#include "libbb.h"
12
13// from ubi-media.h
14#define UBI_MAX_VOLUME_NAME 127
15#define UBI_MAX_VOLUMES 128
16
17unsigned FAST_FUNC ubi_devnum_from_devname(const char *str)
18{
19 unsigned ubi_devnum;
20
21 if (sscanf(str, "/dev/ubi%u", &ubi_devnum) != 1)
22 bb_error_msg_and_die("not an UBI device: '%s'", str);
23 return ubi_devnum;
24}
25
26int FAST_FUNC get_volid_by_name(unsigned ubi_devnum, const char *vol_name)
27{
28 unsigned i;
29
30 for (i = 0; i < UBI_MAX_VOLUMES; i++) {
31 char buf[UBI_MAX_VOLUME_NAME + 1];
32 char fname[sizeof("/sys/class/ubi/ubi%u_%u/name") + 2 * sizeof(int)*3];
33
34 sprintf(fname, "/sys/class/ubi/ubi%u_%u/name", ubi_devnum, i);
35 if (open_read_close(fname, buf, sizeof(buf)) <= 0)
36 continue;
37
38 strchrnul(buf, '\n')[0] = '\0';
39 if (strcmp(vol_name, buf) == 0)
40 return i;
41 }
42 bb_error_msg_and_die("volume '%s' not found", vol_name);
43}