diff options
author | Ron Yorston <rmy@pobox.com> | 2016-02-22 10:00:45 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2016-02-22 10:00:45 +0000 |
commit | 371c20c008254a36e7157df6c13dc2e4cf87d6fd (patch) | |
tree | a214c03f6617dffa60df2192b312a46c93b7c19f /util-linux | |
parent | ab879a41ab674129ef1593cda181cc8b64d0dadf (diff) | |
parent | 3a5cc989025eefe03fda0552b253a4a8f015a761 (diff) | |
download | busybox-w32-371c20c008254a36e7157df6c13dc2e4cf87d6fd.tar.gz busybox-w32-371c20c008254a36e7157df6c13dc2e4cf87d6fd.tar.bz2 busybox-w32-371c20c008254a36e7157df6c13dc2e4cf87d6fd.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/blkdiscard.c | 83 | ||||
-rw-r--r-- | util-linux/mount.c | 10 | ||||
-rw-r--r-- | util-linux/swaponoff.c | 13 | ||||
-rw-r--r-- | util-linux/volume_id/bcache.c | 110 | ||||
-rw-r--r-- | util-linux/volume_id/volume_id.c | 3 | ||||
-rw-r--r-- | util-linux/volume_id/volume_id_internal.h | 2 |
6 files changed, 213 insertions, 8 deletions
diff --git a/util-linux/blkdiscard.c b/util-linux/blkdiscard.c new file mode 100644 index 000000000..ace88a1f0 --- /dev/null +++ b/util-linux/blkdiscard.c | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | * Mini blkdiscard implementation for busybox | ||
3 | * | ||
4 | * Copyright (C) 2015 by Ari Sundholm <ari@tuxera.com> and Tuxera Inc. | ||
5 | * | ||
6 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | ||
7 | */ | ||
8 | |||
9 | //config:config BLKDISCARD | ||
10 | //config: bool "blkdiscard" | ||
11 | //config: default y | ||
12 | //config: help | ||
13 | //config: blkdiscard discards sectors on a given device. | ||
14 | |||
15 | //kbuild:lib-$(CONFIG_BLKDISCARD) += blkdiscard.o | ||
16 | //applet:IF_BLKDISCARD(APPLET(blkdiscard, BB_DIR_USR_BIN, BB_SUID_DROP)) | ||
17 | |||
18 | //usage:#define blkdiscard_trivial_usage | ||
19 | //usage: "[-o OFS] [-l LEN] [-s] DEVICE" | ||
20 | //usage:#define blkdiscard_full_usage "\n\n" | ||
21 | //usage: "Discard sectors on DEVICE\n" | ||
22 | //usage: "\n -o OFS Byte offset into device" | ||
23 | //usage: "\n -l LEN Number of bytes to discard" | ||
24 | //usage: "\n -s Perform a secure discard" | ||
25 | //usage: | ||
26 | //usage:#define blkdiscard_example_usage | ||
27 | //usage: "$ blkdiscard -o 0 -l 1G /dev/sdb" | ||
28 | |||
29 | #include "libbb.h" | ||
30 | #include <linux/fs.h> | ||
31 | |||
32 | int blkdiscard_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
33 | int blkdiscard_main(int argc UNUSED_PARAM, char **argv) | ||
34 | { | ||
35 | unsigned opts; | ||
36 | const char *offset_str = "0"; | ||
37 | const char *length_str; | ||
38 | uint64_t offset; /* Leaving these two variables out does not */ | ||
39 | uint64_t length; /* shrink code size and hampers readability. */ | ||
40 | uint64_t range[2]; | ||
41 | // struct stat st; | ||
42 | int fd; | ||
43 | |||
44 | enum { | ||
45 | OPT_OFFSET = (1 << 0), | ||
46 | OPT_LENGTH = (1 << 1), | ||
47 | OPT_SECURE = (1 << 2), | ||
48 | }; | ||
49 | |||
50 | opt_complementary = "=1"; | ||
51 | opts = getopt32(argv, "o:l:s", &offset_str, &length_str); | ||
52 | argv += optind; | ||
53 | |||
54 | fd = xopen(argv[0], O_RDWR|O_EXCL); | ||
55 | //Why bother, BLK[SEC]DISCARD will fail on non-blockdevs anyway? | ||
56 | // xfstat(fd, &st); | ||
57 | // if (!S_ISBLK(st.st_mode)) | ||
58 | // bb_error_msg_and_die("%s: not a block device", argv[0]); | ||
59 | |||
60 | offset = xatoull_sfx(offset_str, kMG_suffixes); | ||
61 | |||
62 | if (opts & OPT_LENGTH) | ||
63 | length = xatoull_sfx(length_str, kMG_suffixes); | ||
64 | else { | ||
65 | xioctl(fd, BLKGETSIZE64, &length); | ||
66 | length -= offset; | ||
67 | } | ||
68 | |||
69 | range[0] = offset; | ||
70 | range[1] = length; | ||
71 | ioctl_or_perror_and_die(fd, | ||
72 | (opts & OPT_SECURE) ? BLKSECDISCARD : BLKDISCARD, | ||
73 | &range, | ||
74 | "%s: %s failed", | ||
75 | argv[0], | ||
76 | (opts & OPT_SECURE) ? "BLKSECDISCARD" : "BLKDISCARD" | ||
77 | ); | ||
78 | |||
79 | if (ENABLE_FEATURE_CLEAN_UP) | ||
80 | close(fd); | ||
81 | |||
82 | return EXIT_SUCCESS; | ||
83 | } | ||
diff --git a/util-linux/mount.c b/util-linux/mount.c index cb40c802d..c428f5827 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -259,9 +259,11 @@ static struct mntent *getmntent_r(FILE* stream, struct mntent* result, | |||
259 | 259 | ||
260 | // Not real flags, but we want to be able to check for this. | 260 | // Not real flags, but we want to be able to check for this. |
261 | enum { | 261 | enum { |
262 | MOUNT_USERS = (1 << 28) * ENABLE_DESKTOP, | 262 | MOUNT_USERS = (1 << 27) * ENABLE_DESKTOP, |
263 | MOUNT_NOFAIL = (1 << 28) * ENABLE_DESKTOP, | ||
263 | MOUNT_NOAUTO = (1 << 29), | 264 | MOUNT_NOAUTO = (1 << 29), |
264 | MOUNT_SWAP = (1 << 30), | 265 | MOUNT_SWAP = (1 << 30), |
266 | MOUNT_FAKEFLAGS = MOUNT_USERS | MOUNT_NOFAIL | MOUNT_NOAUTO | MOUNT_SWAP | ||
265 | }; | 267 | }; |
266 | 268 | ||
267 | 269 | ||
@@ -326,6 +328,7 @@ static const int32_t mount_options[] = { | |||
326 | /* "swap" */ MOUNT_SWAP, | 328 | /* "swap" */ MOUNT_SWAP, |
327 | IF_DESKTOP(/* "user" */ MOUNT_USERS,) | 329 | IF_DESKTOP(/* "user" */ MOUNT_USERS,) |
328 | IF_DESKTOP(/* "users" */ MOUNT_USERS,) | 330 | IF_DESKTOP(/* "users" */ MOUNT_USERS,) |
331 | IF_DESKTOP(/* "nofail" */ MOUNT_NOFAIL,) | ||
329 | /* "_netdev" */ 0, | 332 | /* "_netdev" */ 0, |
330 | IF_DESKTOP(/* "comment=" */ 0,) /* systemd uses this in fstab */ | 333 | IF_DESKTOP(/* "comment=" */ 0,) /* systemd uses this in fstab */ |
331 | ) | 334 | ) |
@@ -385,6 +388,7 @@ static const char mount_option_str[] = | |||
385 | "swap\0" | 388 | "swap\0" |
386 | IF_DESKTOP("user\0") | 389 | IF_DESKTOP("user\0") |
387 | IF_DESKTOP("users\0") | 390 | IF_DESKTOP("users\0") |
391 | IF_DESKTOP("nofail\0") | ||
388 | "_netdev\0" | 392 | "_netdev\0" |
389 | IF_DESKTOP("comment=\0") /* systemd uses this in fstab */ | 393 | IF_DESKTOP("comment=\0") /* systemd uses this in fstab */ |
390 | ) | 394 | ) |
@@ -672,6 +676,8 @@ static int mount_it_now(struct mntent *mp, unsigned long vfsflags, char *filtero | |||
672 | { | 676 | { |
673 | int rc = 0; | 677 | int rc = 0; |
674 | 678 | ||
679 | vfsflags &= ~(unsigned long)MOUNT_FAKEFLAGS; | ||
680 | |||
675 | if (FAKE_IT) { | 681 | if (FAKE_IT) { |
676 | if (verbose >= 2) | 682 | if (verbose >= 2) |
677 | bb_error_msg("would do mount('%s','%s','%s',0x%08lx,'%s')", | 683 | bb_error_msg("would do mount('%s','%s','%s',0x%08lx,'%s')", |
@@ -2061,6 +2067,8 @@ static int singlemount(struct mntent *mp, int ignore_busy) | |||
2061 | 2067 | ||
2062 | if (errno == EBUSY && ignore_busy) | 2068 | if (errno == EBUSY && ignore_busy) |
2063 | return 0; | 2069 | return 0; |
2070 | if (errno == ENOENT && (vfsflags & MOUNT_NOFAIL)) | ||
2071 | return 0; | ||
2064 | if (rc != 0) | 2072 | if (rc != 0) |
2065 | bb_perror_msg("mounting %s on %s failed", mp->mnt_fsname, mp->mnt_dir); | 2073 | bb_perror_msg("mounting %s on %s failed", mp->mnt_fsname, mp->mnt_dir); |
2066 | return rc; | 2074 | return rc; |
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c index 5cd1fbe70..c29dd3071 100644 --- a/util-linux/swaponoff.c +++ b/util-linux/swaponoff.c | |||
@@ -22,11 +22,10 @@ | |||
22 | //usage: ) | 22 | //usage: ) |
23 | //usage: | 23 | //usage: |
24 | //usage:#define swapoff_trivial_usage | 24 | //usage:#define swapoff_trivial_usage |
25 | //usage: "[-a] [-e] [DEVICE]" | 25 | //usage: "[-a] [DEVICE]" |
26 | //usage:#define swapoff_full_usage "\n\n" | 26 | //usage:#define swapoff_full_usage "\n\n" |
27 | //usage: "Stop swapping on DEVICE\n" | 27 | //usage: "Stop swapping on DEVICE\n" |
28 | //usage: "\n -a Stop swapping on all swap devices" | 28 | //usage: "\n -a Stop swapping on all swap devices" |
29 | //usage: "\n -e Silently skip devices that do not exist" | ||
30 | 29 | ||
31 | #include "libbb.h" | 30 | #include "libbb.h" |
32 | #include <mntent.h> | 31 | #include <mntent.h> |
@@ -97,11 +96,8 @@ static int swap_enable_disable(char *device) | |||
97 | { | 96 | { |
98 | int err = 0; | 97 | int err = 0; |
99 | int quiet = 0; | 98 | int quiet = 0; |
100 | struct stat st; | ||
101 | 99 | ||
102 | resolve_mount_spec(&device); | 100 | resolve_mount_spec(&device); |
103 | if (!OPT_IFEXISTS) | ||
104 | xstat(device, &st); | ||
105 | 101 | ||
106 | if (do_swapoff) { | 102 | if (do_swapoff) { |
107 | err = swapoff(device); | 103 | err = swapoff(device); |
@@ -109,6 +105,7 @@ static int swap_enable_disable(char *device) | |||
109 | quiet = (OPT_ALL && (errno == EINVAL || errno == ENOENT)); | 105 | quiet = (OPT_ALL && (errno == EINVAL || errno == ENOENT)); |
110 | } else { | 106 | } else { |
111 | /* swapon */ | 107 | /* swapon */ |
108 | struct stat st; | ||
112 | err = stat(device, &st); | 109 | err = stat(device, &st); |
113 | if (!err) { | 110 | if (!err) { |
114 | if (ENABLE_DESKTOP && S_ISREG(st.st_mode)) { | 111 | if (ENABLE_DESKTOP && S_ISREG(st.st_mode)) { |
@@ -119,9 +116,11 @@ static int swap_enable_disable(char *device) | |||
119 | } | 116 | } |
120 | err = swapon(device, g_flags); | 117 | err = swapon(device, g_flags); |
121 | /* Don't complain on swapon -a if device is already in use */ | 118 | /* Don't complain on swapon -a if device is already in use */ |
122 | /* Don't complain if file does not exist with -e option */ | 119 | quiet = (OPT_ALL && errno == EBUSY); |
123 | quiet = (OPT_ALL && errno == EBUSY) || (OPT_IFEXISTS && errno == ENOENT); | ||
124 | } | 120 | } |
121 | /* Don't complain if file does not exist with -e option */ | ||
122 | if (err && OPT_IFEXISTS && errno == ENOENT) | ||
123 | err = 0; | ||
125 | } | 124 | } |
126 | 125 | ||
127 | if (err && !quiet) { | 126 | if (err && !quiet) { |
diff --git a/util-linux/volume_id/bcache.c b/util-linux/volume_id/bcache.c new file mode 100644 index 000000000..648e44de5 --- /dev/null +++ b/util-linux/volume_id/bcache.c | |||
@@ -0,0 +1,110 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2013 Rolf Fokkens <rolf@fokkens.nl> | ||
3 | * | ||
4 | * This file may be redistributed under the terms of the | ||
5 | * GNU Lesser General Public License. | ||
6 | * | ||
7 | * Based on code fragments from bcache-tools by Kent Overstreet: | ||
8 | * http://evilpiepirate.org/git/bcache-tools.git | ||
9 | */ | ||
10 | |||
11 | //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_BCACHE) += bcache.o | ||
12 | |||
13 | //config: | ||
14 | //config:config FEATURE_VOLUMEID_BCACHE | ||
15 | //config: bool "bcache filesystem" | ||
16 | //config: default y | ||
17 | //config: depends on VOLUMEID | ||
18 | //config: help | ||
19 | //config: TODO | ||
20 | //config: | ||
21 | |||
22 | #include "volume_id_internal.h" | ||
23 | |||
24 | #define SB_LABEL_SIZE 32 | ||
25 | #define SB_JOURNAL_BUCKETS 256U | ||
26 | |||
27 | static const char bcache_magic[] = { | ||
28 | 0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca, | ||
29 | 0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81 | ||
30 | }; | ||
31 | |||
32 | struct bcache_super_block { | ||
33 | uint64_t csum; | ||
34 | uint64_t offset; /* sector where this sb was written */ | ||
35 | uint64_t version; | ||
36 | |||
37 | uint8_t magic[16]; | ||
38 | |||
39 | uint8_t uuid[16]; | ||
40 | union { | ||
41 | uint8_t set_uuid[16]; | ||
42 | uint64_t set_magic; | ||
43 | }; | ||
44 | uint8_t label[SB_LABEL_SIZE]; | ||
45 | |||
46 | uint64_t flags; | ||
47 | uint64_t seq; | ||
48 | uint64_t pad[8]; | ||
49 | |||
50 | union { | ||
51 | struct { | ||
52 | /* Cache devices */ | ||
53 | uint64_t nbuckets; /* device size */ | ||
54 | |||
55 | uint16_t block_size; /* sectors */ | ||
56 | uint16_t bucket_size; /* sectors */ | ||
57 | |||
58 | uint16_t nr_in_set; | ||
59 | uint16_t nr_this_dev; | ||
60 | }; | ||
61 | struct { | ||
62 | /* Backing devices */ | ||
63 | uint64_t data_offset; | ||
64 | |||
65 | /* | ||
66 | * block_size from the cache device section is still used by | ||
67 | * backing devices, so don't add anything here until we fix | ||
68 | * things to not need it for backing devices anymore | ||
69 | */ | ||
70 | }; | ||
71 | }; | ||
72 | |||
73 | uint32_t last_mount; /* time_t */ | ||
74 | |||
75 | uint16_t first_bucket; | ||
76 | union { | ||
77 | uint16_t njournal_buckets; | ||
78 | uint16_t keys; | ||
79 | }; | ||
80 | uint64_t d[SB_JOURNAL_BUCKETS]; /* journal buckets */ | ||
81 | }; | ||
82 | |||
83 | /* magic string */ | ||
84 | #define BCACHE_SB_MAGIC bcache_magic | ||
85 | /* magic string len */ | ||
86 | #define BCACHE_SB_MAGIC_LEN sizeof (bcache_magic) | ||
87 | /* super block offset */ | ||
88 | #define BCACHE_SB_OFF 0x1000 | ||
89 | /* supper block offset in kB */ | ||
90 | #define BCACHE_SB_KBOFF (BCACHE_SB_OFF >> 10) | ||
91 | /* magic string offset within super block */ | ||
92 | #define BCACHE_SB_MAGIC_OFF offsetof (struct bcache_super_block, magic) | ||
93 | |||
94 | int FAST_FUNC volume_id_probe_bcache(struct volume_id *id /*,uint64_t off*/) | ||
95 | { | ||
96 | struct bcache_super_block *sb; | ||
97 | |||
98 | sb = volume_id_get_buffer(id, BCACHE_SB_OFF, sizeof(*sb)); | ||
99 | if (sb == NULL) | ||
100 | return -1; | ||
101 | |||
102 | if (memcmp(sb->magic, BCACHE_SB_MAGIC, BCACHE_SB_MAGIC_LEN) != 0) | ||
103 | return -1; | ||
104 | |||
105 | volume_id_set_label_string(id, sb->label, SB_LABEL_SIZE); | ||
106 | volume_id_set_uuid(id, sb->uuid, UUID_DCE); | ||
107 | IF_FEATURE_BLKID_TYPE(id->type = "bcache";) | ||
108 | |||
109 | return 0; | ||
110 | } | ||
diff --git a/util-linux/volume_id/volume_id.c b/util-linux/volume_id/volume_id.c index 5c459a0e2..3f71e0084 100644 --- a/util-linux/volume_id/volume_id.c +++ b/util-linux/volume_id/volume_id.c | |||
@@ -107,6 +107,9 @@ static const probe_fptr fs1[] = { | |||
107 | #if ENABLE_FEATURE_VOLUMEID_XFS | 107 | #if ENABLE_FEATURE_VOLUMEID_XFS |
108 | volume_id_probe_xfs, | 108 | volume_id_probe_xfs, |
109 | #endif | 109 | #endif |
110 | #if ENABLE_FEATURE_VOLUMEID_BCACHE | ||
111 | volume_id_probe_bcache, | ||
112 | #endif | ||
110 | }; | 113 | }; |
111 | 114 | ||
112 | /* fill buffer with maximum */ | 115 | /* fill buffer with maximum */ |
diff --git a/util-linux/volume_id/volume_id_internal.h b/util-linux/volume_id/volume_id_internal.h index 6e2dbd7bb..3061ac4d5 100644 --- a/util-linux/volume_id/volume_id_internal.h +++ b/util-linux/volume_id/volume_id_internal.h | |||
@@ -169,6 +169,8 @@ int FAST_FUNC volume_id_probe_linux_raid(struct volume_id *id /*,uint64_t off*/, | |||
169 | 169 | ||
170 | /* FS */ | 170 | /* FS */ |
171 | 171 | ||
172 | int FAST_FUNC volume_id_probe_bcache(struct volume_id *id /*,uint64_t off*/); | ||
173 | |||
172 | int FAST_FUNC volume_id_probe_btrfs(struct volume_id *id /*,uint64_t off*/); | 174 | int FAST_FUNC volume_id_probe_btrfs(struct volume_id *id /*,uint64_t off*/); |
173 | 175 | ||
174 | int FAST_FUNC volume_id_probe_cramfs(struct volume_id *id /*,uint64_t off*/); | 176 | int FAST_FUNC volume_id_probe_cramfs(struct volume_id *id /*,uint64_t off*/); |