On Fri, Jun 19, 2009 at 09:30:37AM +0200, Denys Vlasenko wrote:
> On Friday 19 June 2009 04:10, Colin Watson wrote:
> > Please bear in mind that I was replying specifically to Denys' patch,
> > not to an abstract concept of a patch that used proper random numbers.
> > The reason I'm concerned about it is that I *do* understand the scale of
> > these things and that patch (which is in master now) isn't in the right
> > ballpark at all. I spent several days and nights of my life last year on
> > very little sleep dealing with cleanup and mitigation of the notorious
> > Debian openssl bug, in which an accidental mispatch caused a shortage of
> > randomness such that only 2^15 distinct keys were possible for each key
> > type/length combination. I know what powers of two do, and the kinds of
> > thing that happen if you don't have enough of them.
>
> How about this?
>
> i = open("/dev/urandom", O_RDONLY);
> if (i >= 0) {
> read(i, buf, 16);
I'd recommend using full_read.
> close(i);
> }
> /* Paranoia. /dev/urandom may be missing.
> * rand() is guaranteed to generate at least [0, 2^15) range,
> * but lowest bits in some libc are not so "random". */
> srand(monotonic_us());
> pid = getpid();
> while (1) {
> for (i = 0; i < 16; i++)
> buf[i] ^= rand() >> 5;
> if (pid == 0)
> break;
> srand(pid);
> pid = 0;
> }
I haven't checked this in detail, but it looks superficially OK.
> buf[4 + 2 ] = (buf[4 + 2 ] & 0x0f) | 0x40; /*
> time_hi_and_version */
> buf[4 + 2 + 2] = (buf[4 + 2 + 2] & 0x3f) | 0x80; /*
> clk_seq_and_variant */
You should probably also borrow Rob's recommendation of setting the
multicast bit in the node ID so that your random UUIDs can't be confused
with those generated from network cards.
buf[4 + 4 + 2] |= 1;
> > Now, granted, it doesn't matter so much if swap UUIDs are really
> > universally unique when you compare them to something like SSH keys. But
> > let's consider the example of a large organisation deploying Linux
> > automatically on lots of machines. We can probably expect those machines
> > to be of roughly the same specification such that they'll reach similar
> > stages of the installer at about the same time, plus or minus a few
> > seconds, and we can certainly expect their deployment to be such that
> > the installer takes an identical or nearly identical code path each
> > time. I'd be surprised at this point if you had much more than 2^24
> > random bits to play with. The probability of real collisions within the
> > organisation is no longer negligible.
>
> Wow, they would mix their swap partitions! Run for your lives.
I attempted to stave off sarcasm later in my post by pointing out that
the same UUID generation function ought to be used for things like
mke2fs too (assuming it's ever turned back on in busybox), in which case
mounting the wrong filesystem can cause data loss. I guess my attempt
didn't work.
(And actually, if you get a swap partition of a different size mounted,
or one on a disk you were planning to phase out, it could well cause
enough confusion to lead to some support costs. Probably not hugely
important but still.)
> > The generation function you (Rob) sent in
> > http://lists.busybox.net/pipermail/busybox/2009-June/069690.html seems
> > much better to me and largely fine, except for two mistakes:
> >
> > * RFC2518 appears to be in error when it says that you should set the
> > most significant bit of the first octet of the node ID to 1. RFC4122
> > instead says you should set the *least* significant bit, which
> > matches the description of IEEE 802 MAC addresses in
> > http://en.wikipedia.org/wiki/MAC_address.
> >
> > * Your code uses uuid[11] as if it were the first octet of the node ID.
> > I think this should in fact be uuid[10].
> >
> > If I were writing it I think I'd follow libuuid's lead
>
> That code is a good example of code explosion for no discernible reason
> which is so prevalent nowadays. No wonder just about anything today
> takes megabytes of code.
>
> Getting a list of present network cards because I am about to mkswap?!
> No thanks.
libuuid supports various methods of generating UUIDs, which are
appropriate in different situations. As I said, in busybox's case it
would make complete sense to strip it down and only support random
UUIDs.
> > Can I recommend at least looking at libuuid and seeing what can be used,
> > though? It could be made a lot smaller simply by stripping out all the
> > time-based UUID stuff and assuming the existence of /dev/urandom, and as
> > I said above this should all be configured off by default.
>
> The code above does something like that. Is it ok with you?
ENABLE_DESKTOP seems likely to be too heavyweight for me. I use this in
an environment that isn't as stripped-down as a real embedded
environment, but nevertheless I'd rather not turn on an option that's a
dumping ground for all kinds of stuff.
Why not take the opportunity to strip out lots of junk from
old_e2fsprogs after adding UUID handling to libbb? I'm assuming that
ultimately you guys want the old_e2fsprogs bit of the source tree to get
smaller as well as the executable size.
I've attached two alternative patches to this mail:
1) Add support for CONFIG_FEATURE_MKSWAP_UUID which can be used
instead of the bloaty CONFIG_DESKTOP.
2) Add libbb/uuid.c with a heavily stripped-down version of libuuid;
convert everything to use it, whether currently built or not;
remove a couple of features from tune2fs (yes, I know it isn't
currently built) that required more bits from the UUID library and
didn't seem to be too important to support; strip out all the old
libuuid source.
master (with CONFIG_DESKTOP) vs. patch 2 (with
CONFIG_FEATURE_MKSWAP_UUID) says -11687 bytes. A fairer comparison is
patch 1 vs. patch 2, both with CONFIG_FEATURE_MKSWAP_UUID; patch 2
produces an executable 126 bytes bigger. Given that this is a feature
that I doubt embedded people are going to enable, this seems like a
fairly worthwhile tradeoff for removing nearly 1000 lines of source
code. What do you think?
Incidentally, all of this probably works out bigger for me than just
linking against libuuid and being done with it, since I need libuuid in
my images *anyway* for other binaries that I need that aren't in
busybox! But hey, I can cope with that.
Thanks,
--
Colin Watson [[email protected]]
>From b997bbc9ae736d5c7a138623252da984121123cb Mon Sep 17 00:00:00 2001
From: Colin Watson <[email protected]>
Date: Fri, 19 Jun 2009 11:05:04 +0100
Subject: [PATCH] mkswap: separate UUID feature
Signed-off-by: Colin Watson <[email protected]>
---
util-linux/Config.in | 7 +++++++
util-linux/mkswap.c | 2 +-
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/util-linux/Config.in b/util-linux/Config.in
index 0245501..be2437c 100644
--- a/util-linux/Config.in
+++ b/util-linux/Config.in
@@ -409,6 +409,13 @@ config FEATURE_MKSWAP_V0
If your kernel is older than 2.1.117, then v0 support is the
only option.
+config FEATURE_MKSWAP_UUID
+ bool "UUID support"
+ default n
+ depends on MKSWAP
+ help
+ Generate swap spaces with universally unique identifiers.
+
config MORE
bool "more"
default n
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c
index c4e30fd..99ed1be 100644
--- a/util-linux/mkswap.c
+++ b/util-linux/mkswap.c
@@ -50,7 +50,7 @@ static void mkswap_selinux_setcontext(int fd, const char *path)
# define mkswap_selinux_setcontext(fd, path) ((void)0)
#endif
-#if ENABLE_DESKTOP
+#if ENABLE_FEATURE_MKSWAP_UUID
static void mkswap_generate_uuid(uint8_t *buf)
{
pid_t pid;
--
1.6.3.1
>From 61caf538f1cdf0e313992d03ed0c88e2349d93d2 Mon Sep 17 00:00:00 2001
From: Colin Watson <[email protected]>
Date: Fri, 19 Jun 2009 11:18:21 +0100
Subject: [PATCH] Remove libuuid from old_e2fsprogs; replace with libbb version
Signed-off-by: Colin Watson <[email protected]>
---
e2fsprogs/Config.in | 3 +
e2fsprogs/old_e2fsprogs/blkid/probe.c | 2 +-
e2fsprogs/old_e2fsprogs/blkid/read.c | 2 +-
e2fsprogs/old_e2fsprogs/e2fsck.h | 1 -
e2fsprogs/old_e2fsprogs/mke2fs.c | 1 -
e2fsprogs/old_e2fsprogs/tune2fs.c | 5 -
e2fsprogs/old_e2fsprogs/uuid/Kbuild | 14 --
e2fsprogs/old_e2fsprogs/uuid/compare.c | 55 ------
e2fsprogs/old_e2fsprogs/uuid/gen_uuid.c | 304 ------------------------------
e2fsprogs/old_e2fsprogs/uuid/pack.c | 69 -------
e2fsprogs/old_e2fsprogs/uuid/parse.c | 80 --------
e2fsprogs/old_e2fsprogs/uuid/unpack.c | 63 ------
e2fsprogs/old_e2fsprogs/uuid/unparse.c | 77 --------
e2fsprogs/old_e2fsprogs/uuid/uuid.h | 103 ----------
e2fsprogs/old_e2fsprogs/uuid/uuidP.h | 60 ------
e2fsprogs/old_e2fsprogs/uuid/uuid_time.c | 161 ----------------
include/libbb.h | 8 +
libbb/Config.in | 5 +
libbb/Kbuild | 1 +
libbb/uuid.c | 115 +++++++++++
scripts/Makefile.IMA | 3 -
util-linux/Config.in | 8 +
util-linux/mkswap.c | 86 +--------
23 files changed, 150 insertions(+), 1076 deletions(-)
delete mode 100644 e2fsprogs/old_e2fsprogs/uuid/Kbuild
delete mode 100644 e2fsprogs/old_e2fsprogs/uuid/compare.c
delete mode 100644 e2fsprogs/old_e2fsprogs/uuid/gen_uuid.c
delete mode 100644 e2fsprogs/old_e2fsprogs/uuid/pack.c
delete mode 100644 e2fsprogs/old_e2fsprogs/uuid/parse.c
delete mode 100644 e2fsprogs/old_e2fsprogs/uuid/unpack.c
delete mode 100644 e2fsprogs/old_e2fsprogs/uuid/unparse.c
delete mode 100644 e2fsprogs/old_e2fsprogs/uuid/uuid.h
delete mode 100644 e2fsprogs/old_e2fsprogs/uuid/uuidP.h
delete mode 100644 e2fsprogs/old_e2fsprogs/uuid/uuid_time.c
create mode 100644 libbb/uuid.c
diff --git a/e2fsprogs/Config.in b/e2fsprogs/Config.in
index 9a0088a..45755bc 100644
--- a/e2fsprogs/Config.in
+++ b/e2fsprogs/Config.in
@@ -14,6 +14,7 @@ config CHATTR
### config E2FSCK
### bool "e2fsck"
### default n
+### select FEATURE_UUID
### help
### e2fsck is used to check Linux second extended file systems (ext2fs).
### e2fsck also supports ext2 filesystems countaining a journal (ext3).
@@ -37,6 +38,7 @@ config LSATTR
### config MKE2FS
### bool "mke2fs"
### default n
+### select FEATURE_UUID
### help
### mke2fs is used to create an ext2/ext3 filesystem. The normal compat
### symlinks 'mkfs.ext2' and 'mkfs.ext3' are also provided.
@@ -44,6 +46,7 @@ config LSATTR
### config TUNE2FS
### bool "tune2fs"
### default n
+### select FEATURE_UUID
### help
### tune2fs allows the system administrator to adjust various tunable
### filesystem parameters on Linux ext2/ext3 filesystems.
diff --git a/e2fsprogs/old_e2fsprogs/blkid/probe.c b/e2fsprogs/old_e2fsprogs/blkid/probe.c
index 1f7188e..a948a7f 100644
--- a/e2fsprogs/old_e2fsprogs/blkid/probe.c
+++ b/e2fsprogs/old_e2fsprogs/blkid/probe.c
@@ -29,7 +29,7 @@
#include <errno.h>
#endif
#include "blkidP.h"
-#include "../uuid/uuid.h"
+#include "libbb.h"
#include "probe.h"
/*
diff --git a/e2fsprogs/old_e2fsprogs/blkid/read.c b/e2fsprogs/old_e2fsprogs/blkid/read.c
index 67bc8ee..0e70a20 100644
--- a/e2fsprogs/old_e2fsprogs/blkid/read.c
+++ b/e2fsprogs/old_e2fsprogs/blkid/read.c
@@ -22,7 +22,7 @@
#include <errno.h>
#include "blkidP.h"
-#include "../uuid/uuid.h"
+#include "libbb.h"
#ifdef HAVE_STRTOULL
#define __USE_ISOC9X
diff --git a/e2fsprogs/old_e2fsprogs/e2fsck.h b/e2fsprogs/old_e2fsprogs/e2fsck.h
index 73d398f..552c122 100644
--- a/e2fsprogs/old_e2fsprogs/e2fsck.h
+++ b/e2fsprogs/old_e2fsprogs/e2fsck.h
@@ -38,7 +38,6 @@
#include "ext2fs/ext2_fs.h"
#include "blkid/blkid.h"
#include "ext2fs/ext2_ext_attr.h"
-#include "uuid/uuid.h"
#include "libbb.h"
#ifdef HAVE_CONIO_H
diff --git a/e2fsprogs/old_e2fsprogs/mke2fs.c b/e2fsprogs/old_e2fsprogs/mke2fs.c
index a132743..13c9633 100644
--- a/e2fsprogs/old_e2fsprogs/mke2fs.c
+++ b/e2fsprogs/old_e2fsprogs/mke2fs.c
@@ -29,7 +29,6 @@
#include "e2fsbb.h"
#include "ext2fs/ext2_fs.h"
-#include "uuid/uuid.h"
#include "e2p/e2p.h"
#include "ext2fs/ext2fs.h"
#include "util.h"
diff --git a/e2fsprogs/old_e2fsprogs/tune2fs.c b/e2fsprogs/old_e2fsprogs/tune2fs.c
index 1d39ed1..4813ed5 100644
--- a/e2fsprogs/old_e2fsprogs/tune2fs.c
+++ b/e2fsprogs/old_e2fsprogs/tune2fs.c
@@ -35,7 +35,6 @@
#include "e2fsbb.h"
#include "ext2fs/ext2_fs.h"
#include "ext2fs/ext2fs.h"
-#include "uuid/uuid.h"
#include "e2p/e2p.h"
#include "ext2fs/kernel-jbd.h"
#include "util.h"
@@ -694,12 +693,8 @@ int tune2fs_main(int argc, char **argv)
if ((strcasecmp(new_UUID, "null") == 0) ||
(strcasecmp(new_UUID, "clear") == 0)) {
uuid_clear(sb->s_uuid);
- } else if (strcasecmp(new_UUID, "time") == 0) {
- uuid_generate_time(sb->s_uuid);
} else if (strcasecmp(new_UUID, "random") == 0) {
uuid_generate(sb->s_uuid);
- } else if (uuid_parse(new_UUID, sb->s_uuid)) {
- bb_error_msg_and_die("Invalid UUID format");
}
ext2fs_mark_super_dirty(fs);
}
diff --git a/e2fsprogs/old_e2fsprogs/uuid/Kbuild b/e2fsprogs/old_e2fsprogs/uuid/Kbuild
deleted file mode 100644
index dde9818..0000000
--- a/e2fsprogs/old_e2fsprogs/uuid/Kbuild
+++ /dev/null
@@ -1,14 +0,0 @@
-# Makefile for busybox
-#
-# Copyright (C) 1999-2005 by Erik Andersen <[email protected]>
-#
-# Licensed under the GPL v2, see the file LICENSE in this tarball.
-
-NEEDED-$(CONFIG_E2FSCK) = y
-NEEDED-$(CONFIG_FSCK) = y
-NEEDED-$(CONFIG_MKE2FS) = y
-NEEDED-$(CONFIG_TUNE2FS) = y
-
-lib-y:=
-lib-$(NEEDED-y) += compare.o gen_uuid.o pack.o parse.o unpack.o unparse.o \
- uuid_time.o
diff --git a/e2fsprogs/old_e2fsprogs/uuid/compare.c b/e2fsprogs/old_e2fsprogs/uuid/compare.c
deleted file mode 100644
index 348ea7c..0000000
--- a/e2fsprogs/old_e2fsprogs/uuid/compare.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * compare.c --- compare whether or not two UUID's are the same
- *
- * Returns 0 if the two UUID's are different, and 1 if they are the same.
- *
- * Copyright (C) 1996, 1997 Theodore Ts'o.
- *
- * %Begin-Header%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, and the entire permission notice in its entirety,
- * including the disclaimer of warranties.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
- * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- * %End-Header%
- */
-
-#include "uuidP.h"
-#include <string.h>
-
-#define UUCMP(u1,u2) if (u1 != u2) return (u1 < u2) ? -1 : 1;
-
-int uuid_compare(const uuid_t uu1, const uuid_t uu2)
-{
- struct uuid uuid1, uuid2;
-
- uuid_unpack(uu1, &uuid1);
- uuid_unpack(uu2, &uuid2);
-
- UUCMP(uuid1.time_low, uuid2.time_low);
- UUCMP(uuid1.time_mid, uuid2.time_mid);
- UUCMP(uuid1.time_hi_and_version, uuid2.time_hi_and_version);
- UUCMP(uuid1.clock_seq, uuid2.clock_seq);
- return memcmp(uuid1.node, uuid2.node, 6);
-}
diff --git a/e2fsprogs/old_e2fsprogs/uuid/gen_uuid.c b/e2fsprogs/old_e2fsprogs/uuid/gen_uuid.c
deleted file mode 100644
index 4310c17..0000000
--- a/e2fsprogs/old_e2fsprogs/uuid/gen_uuid.c
+++ /dev/null
@@ -1,304 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * gen_uuid.c --- generate a DCE-compatible uuid
- *
- * Copyright (C) 1996, 1997, 1998, 1999 Theodore Ts'o.
- *
- * %Begin-Header%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, and the entire permission notice in its entirety,
- * including the disclaimer of warranties.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
- * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- * %End-Header%
- */
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/file.h>
-#include <sys/time.h>
-#ifdef HAVE_SYS_IOCTL_H
-#include <sys/ioctl.h>
-#endif
-#include <sys/socket.h>
-#ifdef HAVE_SYS_SOCKIO_H
-#include <sys/sockio.h>
-#endif
-#ifdef HAVE_NET_IF_H
-#include <net/if.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#ifdef HAVE_NET_IF_DL_H
-#include <net/if_dl.h>
-#endif
-
-#include "uuidP.h"
-
-#ifdef HAVE_SRANDOM
-#define srand(x) srandom(x)
-#define rand() random()
-#endif
-
-static int get_random_fd(void)
-{
- struct timeval tv;
- static int fd = -2;
- int i;
-
- if (fd == -2) {
- gettimeofday(&tv, 0);
- fd = open("/dev/urandom", O_RDONLY);
- if (fd == -1)
- fd = open("/dev/random", O_RDONLY | O_NONBLOCK);
- srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
- }
- /* Crank the random number generator a few times */
- gettimeofday(&tv, 0);
- for (i = (tv.tv_sec ^ tv.tv_usec) & 0x1F; i > 0; i--)
- rand();
- return fd;
-}
-
-
-/*
- * Generate a series of random bytes. Use /dev/urandom if possible,
- * and if not, use srandom/random.
- */
-static void get_random_bytes(void *buf, int nbytes)
-{
- int i, n = nbytes, fd = get_random_fd();
- int lose_counter = 0;
- unsigned char *cp = (unsigned char *) buf;
-
- if (fd >= 0) {
- while (n > 0) {
- i = read(fd, cp, n);
- if (i <= 0) {
- if (lose_counter++ > 16)
- break;
- continue;
- }
- n -= i;
- cp += i;
- lose_counter = 0;
- }
- }
-
- /*
- * We do this all the time, but this is the only source of
- * randomness if /dev/random/urandom is out to lunch.
- */
- for (cp = buf, i = 0; i < nbytes; i++)
- *cp++ ^= (rand() >> 7) & 0xFF;
-}
-
-/*
- * Get the ethernet hardware address, if we can find it...
- */
-static int get_node_id(unsigned char *node_id)
-{
-#ifdef HAVE_NET_IF_H
- int sd;
- struct ifreq ifr, *ifrp;
- struct ifconf ifc;
- char buf[1024];
- int n, i;
- unsigned char *a;
-#ifdef HAVE_NET_IF_DL_H
- struct sockaddr_dl *sdlp;
-#endif
-
-/*
- * BSD 4.4 defines the size of an ifreq to be
- * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len
- * However, under earlier systems, sa_len isn't present, so the size is
- * just sizeof(struct ifreq)
- */
-#ifdef HAVE_SA_LEN
-#ifndef max
-#define max(a,b) ((a) > (b) ? (a) : (b))
-#endif
-#define ifreq_size(i) max(sizeof(struct ifreq),\
- sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
-#else
-#define ifreq_size(i) sizeof(struct ifreq)
-#endif /* HAVE_SA_LEN*/
-
- sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
- if (sd < 0) {
- return -1;
- }
- memset(buf, 0, sizeof(buf));
- ifc.ifc_len = sizeof(buf);
- ifc.ifc_buf = buf;
- if (ioctl (sd, SIOCGIFCONF, (char *)&ifc) < 0) {
- close(sd);
- return -1;
- }
- n = ifc.ifc_len;
- for (i = 0; i < n; i+= ifreq_size(*ifrp) ) {
- ifrp = (struct ifreq *)((char *) ifc.ifc_buf+i);
- strncpy_IFNAMSIZ(ifr.ifr_name, ifrp->ifr_name);
-#ifdef SIOCGIFHWADDR
- if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0)
- continue;
- a = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
-#else
-#ifdef SIOCGENADDR
- if (ioctl(sd, SIOCGENADDR, &ifr) < 0)
- continue;
- a = (unsigned char *) ifr.ifr_enaddr;
-#else
-#ifdef HAVE_NET_IF_DL_H
- sdlp = (struct sockaddr_dl *) &ifrp->ifr_addr;
- if ((sdlp->sdl_family != AF_LINK) || (sdlp->sdl_alen != 6))
- continue;
- a = (unsigned char *) &sdlp->sdl_data[sdlp->sdl_nlen];
-#else
- /*
- * XXX we don't have a way of getting the hardware
- * address
- */
- close(sd);
- return 0;
-#endif /* HAVE_NET_IF_DL_H */
-#endif /* SIOCGENADDR */
-#endif /* SIOCGIFHWADDR */
- if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
- continue;
- if (node_id) {
- memcpy(node_id, a, 6);
- close(sd);
- return 1;
- }
- }
- close(sd);
-#endif
- return 0;
-}
-
-/* Assume that the gettimeofday() has microsecond granularity */
-#define MAX_ADJUSTMENT 10
-
-static int get_clock(uint32_t *clock_high, uint32_t *clock_low, uint16_t *ret_clock_seq)
-{
- static int adjustment = 0;
- static struct timeval last = {0, 0};
- static uint16_t clock_seq;
- struct timeval tv;
- unsigned long long clock_reg;
-
-try_again:
- gettimeofday(&tv, 0);
- if ((last.tv_sec == 0) && (last.tv_usec == 0)) {
- get_random_bytes(&clock_seq, sizeof(clock_seq));
- clock_seq &= 0x3FFF;
- last = tv;
- last.tv_sec--;
- }
- if ((tv.tv_sec < last.tv_sec) ||
- ((tv.tv_sec == last.tv_sec) &&
- (tv.tv_usec < last.tv_usec))) {
- clock_seq = (clock_seq+1) & 0x3FFF;
- adjustment = 0;
- last = tv;
- } else if ((tv.tv_sec == last.tv_sec) &&
- (tv.tv_usec == last.tv_usec)) {
- if (adjustment >= MAX_ADJUSTMENT)
- goto try_again;
- adjustment++;
- } else {
- adjustment = 0;
- last = tv;
- }
-
- clock_reg = tv.tv_usec*10 + adjustment;
- clock_reg += ((unsigned long long) tv.tv_sec)*10000000;
- clock_reg += (((unsigned long long) 0x01B21DD2) << 32) + 0x13814000;
-
- *clock_high = clock_reg >> 32;
- *clock_low = clock_reg;
- *ret_clock_seq = clock_seq;
- return 0;
-}
-
-void uuid_generate_time(uuid_t out)
-{
- static unsigned char node_id[6];
- static int has_init = 0;
- struct uuid uu;
- uint32_t clock_mid;
-
- if (!has_init) {
- if (get_node_id(node_id) <= 0) {
- get_random_bytes(node_id, 6);
- /*
- * Set multicast bit, to prevent conflicts
- * with IEEE 802 addresses obtained from
- * network cards
- */
- node_id[0] |= 0x01;
- }
- has_init = 1;
- }
- get_clock(&clock_mid, &uu.time_low, &uu.clock_seq);
- uu.clock_seq |= 0x8000;
- uu.time_mid = (uint16_t) clock_mid;
- uu.time_hi_and_version = ((clock_mid >> 16) & 0x0FFF) | 0x1000;
- memcpy(uu.node, node_id, 6);
- uuid_pack(&uu, out);
-}
-
-void uuid_generate_random(uuid_t out)
-{
- uuid_t buf;
- struct uuid uu;
-
- get_random_bytes(buf, sizeof(buf));
- uuid_unpack(buf, &uu);
-
- uu.clock_seq = (uu.clock_seq & 0x3FFF) | 0x8000;
- uu.time_hi_and_version = (uu.time_hi_and_version & 0x0FFF) | 0x4000;
- uuid_pack(&uu, out);
-}
-
-/*
- * This is the generic front-end to uuid_generate_random and
- * uuid_generate_time. It uses uuid_generate_random only if
- * /dev/urandom is available, since otherwise we won't have
- * high-quality randomness.
- */
-void uuid_generate(uuid_t out)
-{
- if (get_random_fd() >= 0)
- uuid_generate_random(out);
- else
- uuid_generate_time(out);
-}
diff --git a/e2fsprogs/old_e2fsprogs/uuid/pack.c b/e2fsprogs/old_e2fsprogs/uuid/pack.c
deleted file mode 100644
index 217cfce..0000000
--- a/e2fsprogs/old_e2fsprogs/uuid/pack.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Internal routine for packing UUID's
- *
- * Copyright (C) 1996, 1997 Theodore Ts'o.
- *
- * %Begin-Header%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, and the entire permission notice in its entirety,
- * including the disclaimer of warranties.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
- * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- * %End-Header%
- */
-
-#include <string.h>
-#include "uuidP.h"
-
-void uuid_pack(const struct uuid *uu, uuid_t ptr)
-{
- uint32_t tmp;
- unsigned char *out = ptr;
-
- tmp = uu->time_low;
- out[3] = (unsigned char) tmp;
- tmp >>= 8;
- out[2] = (unsigned char) tmp;
- tmp >>= 8;
- out[1] = (unsigned char) tmp;
- tmp >>= 8;
- out[0] = (unsigned char) tmp;
-
- tmp = uu->time_mid;
- out[5] = (unsigned char) tmp;
- tmp >>= 8;
- out[4] = (unsigned char) tmp;
-
- tmp = uu->time_hi_and_version;
- out[7] = (unsigned char) tmp;
- tmp >>= 8;
- out[6] = (unsigned char) tmp;
-
- tmp = uu->clock_seq;
- out[9] = (unsigned char) tmp;
- tmp >>= 8;
- out[8] = (unsigned char) tmp;
-
- memcpy(out+10, uu->node, 6);
-}
diff --git a/e2fsprogs/old_e2fsprogs/uuid/parse.c b/e2fsprogs/old_e2fsprogs/uuid/parse.c
deleted file mode 100644
index 9a3f9cb..0000000
--- a/e2fsprogs/old_e2fsprogs/uuid/parse.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * parse.c --- UUID parsing
- *
- * Copyright (C) 1996, 1997 Theodore Ts'o.
- *
- * %Begin-Header%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, and the entire permission notice in its entirety,
- * including the disclaimer of warranties.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
- * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- * %End-Header%
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-
-#include "uuidP.h"
-
-int uuid_parse(const char *in, uuid_t uu)
-{
- struct uuid uuid;
- int i;
- const char *cp;
- char buf[3];
-
- if (strlen(in) != 36)
- return -1;
- for (i=0, cp = in; i <= 36; i++,cp++) {
- if ((i == 8) || (i == 13) || (i == 18) ||
- (i == 23)) {
- if (*cp == '-')
- continue;
- else
- return -1;
- }
- if (i== 36)
- if (*cp == 0)
- continue;
- if (!isxdigit(*cp))
- return -1;
- }
- uuid.time_low = strtoul(in, NULL, 16);
- uuid.time_mid = strtoul(in+9, NULL, 16);
- uuid.time_hi_and_version = strtoul(in+14, NULL, 16);
- uuid.clock_seq = strtoul(in+19, NULL, 16);
- cp = in+24;
- buf[2] = 0;
- for (i=0; i < 6; i++) {
- buf[0] = *cp++;
- buf[1] = *cp++;
- uuid.node[i] = strtoul(buf, NULL, 16);
- }
-
- uuid_pack(&uuid, uu);
- return 0;
-}
diff --git a/e2fsprogs/old_e2fsprogs/uuid/unpack.c b/e2fsprogs/old_e2fsprogs/uuid/unpack.c
deleted file mode 100644
index 95d3aab..0000000
--- a/e2fsprogs/old_e2fsprogs/uuid/unpack.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Internal routine for unpacking UUID
- *
- * Copyright (C) 1996, 1997 Theodore Ts'o.
- *
- * %Begin-Header%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, and the entire permission notice in its entirety,
- * including the disclaimer of warranties.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
- * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- * %End-Header%
- */
-
-#include <string.h>
-#include "uuidP.h"
-
-void uuid_unpack(const uuid_t in, struct uuid *uu)
-{
- const uint8_t *ptr = in;
- uint32_t tmp;
-
- tmp = *ptr++;
- tmp = (tmp << 8) | *ptr++;
- tmp = (tmp << 8) | *ptr++;
- tmp = (tmp << 8) | *ptr++;
- uu->time_low = tmp;
-
- tmp = *ptr++;
- tmp = (tmp << 8) | *ptr++;
- uu->time_mid = tmp;
-
- tmp = *ptr++;
- tmp = (tmp << 8) | *ptr++;
- uu->time_hi_and_version = tmp;
-
- tmp = *ptr++;
- tmp = (tmp << 8) | *ptr++;
- uu->clock_seq = tmp;
-
- memcpy(uu->node, ptr, 6);
-}
diff --git a/e2fsprogs/old_e2fsprogs/uuid/unparse.c b/e2fsprogs/old_e2fsprogs/uuid/unparse.c
deleted file mode 100644
index d2948fe..0000000
--- a/e2fsprogs/old_e2fsprogs/uuid/unparse.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * unparse.c -- convert a UUID to string
- *
- * Copyright (C) 1996, 1997 Theodore Ts'o.
- *
- * %Begin-Header%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, and the entire permission notice in its entirety,
- * including the disclaimer of warranties.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
- * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- * %End-Header%
- */
-
-#include <stdio.h>
-
-#include "uuidP.h"
-
-static const char *fmt_lower =
- "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
-
-static const char *fmt_upper =
- "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X";
-
-#ifdef UUID_UNPARSE_DEFAULT_UPPER
-#define FMT_DEFAULT fmt_upper
-#else
-#define FMT_DEFAULT fmt_lower
-#endif
-
-static void uuid_unparse_x(const uuid_t uu, char *out, const char *fmt)
-{
- struct uuid uuid;
-
- uuid_unpack(uu, &uuid);
- sprintf(out, fmt,
- uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
- uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
- uuid.node[0], uuid.node[1], uuid.node[2],
- uuid.node[3], uuid.node[4], uuid.node[5]);
-}
-
-void uuid_unparse_lower(const uuid_t uu, char *out)
-{
- uuid_unparse_x(uu, out, fmt_lower);
-}
-
-void uuid_unparse_upper(const uuid_t uu, char *out)
-{
- uuid_unparse_x(uu, out, fmt_upper);
-}
-
-void uuid_unparse(const uuid_t uu, char *out)
-{
- uuid_unparse_x(uu, out, FMT_DEFAULT);
-}
diff --git a/e2fsprogs/old_e2fsprogs/uuid/uuid.h b/e2fsprogs/old_e2fsprogs/uuid/uuid.h
deleted file mode 100644
index 7a97064..0000000
--- a/e2fsprogs/old_e2fsprogs/uuid/uuid.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Public include file for the UUID library
- *
- * Copyright (C) 1996, 1997, 1998 Theodore Ts'o.
- *
- * %Begin-Header%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, and the entire permission notice in its entirety,
- * including the disclaimer of warranties.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
- * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- * %End-Header%
- */
-#ifndef UUID_UUID_H
-#define UUID_UUID_H 1
-
-#include <sys/types.h>
-#include <time.h>
-
-typedef unsigned char uuid_t[16];
-
-/* UUID Variant definitions */
-#define UUID_VARIANT_NCS 0
-#define UUID_VARIANT_DCE 1
-#define UUID_VARIANT_MICROSOFT 2
-#define UUID_VARIANT_OTHER 3
-
-/* UUID Type definitions */
-#define UUID_TYPE_DCE_TIME 1
-#define UUID_TYPE_DCE_RANDOM 4
-
-/* Allow UUID constants to be defined */
-#ifdef __GNUC__
-#define UUID_DEFINE(name,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15) \
- static const uuid_t name UNUSED_PARAM = {u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15}
-#else
-#define UUID_DEFINE(name,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15) \
- static const uuid_t name = {u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15}
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* clear.c */
-/*void uuid_clear(uuid_t uu);*/
-#define uuid_clear(uu) memset(uu, 0, sizeof(uu))
-
-/* compare.c */
-int uuid_compare(const uuid_t uu1, const uuid_t uu2);
-
-/* copy.c */
-/*void uuid_copy(uuid_t dst, const uuid_t src);*/
-#define uuid_copy(dst,src) memcpy(dst, src, sizeof(dst))
-
-/* gen_uuid.c */
-void uuid_generate(uuid_t out);
-void uuid_generate_random(uuid_t out);
-void uuid_generate_time(uuid_t out);
-
-/* isnull.c */
-/*int uuid_is_null(const uuid_t uu);*/
-#define uuid_is_null(uu) (!memcmp(uu, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", sizeof(uu)))
-
-/* parse.c */
-int uuid_parse(const char *in, uuid_t uu);
-
-/* unparse.c */
-void uuid_unparse(const uuid_t uu, char *out);
-void uuid_unparse_lower(const uuid_t uu, char *out);
-void uuid_unparse_upper(const uuid_t uu, char *out);
-
-/* uuid_time.c */
-time_t uuid_time(const uuid_t uu, struct timeval *ret_tv);
-int uuid_type(const uuid_t uu);
-int uuid_variant(const uuid_t uu);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _UUID_UUID_H */
diff --git a/e2fsprogs/old_e2fsprogs/uuid/uuidP.h b/e2fsprogs/old_e2fsprogs/uuid/uuidP.h
deleted file mode 100644
index 87041ef..0000000
--- a/e2fsprogs/old_e2fsprogs/uuid/uuidP.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * uuid.h -- private header file for uuids
- *
- * Copyright (C) 1996, 1997 Theodore Ts'o.
- *
- * %Begin-Header%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, and the entire permission notice in its entirety,
- * including the disclaimer of warranties.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
- * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- * %End-Header%
- */
-
-#include <inttypes.h>
-#include <sys/types.h>
-
-#include "uuid.h"
-
-/*
- * Offset between 15-Oct-1582 and 1-Jan-70
- */
-#define TIME_OFFSET_HIGH 0x01B21DD2
-#define TIME_OFFSET_LOW 0x13814000
-
-struct uuid {
- uint32_t time_low;
- uint16_t time_mid;
- uint16_t time_hi_and_version;
- uint16_t clock_seq;
- uint8_t node[6];
-};
-
-
-/*
- * prototypes
- */
-void uuid_pack(const struct uuid *uu, uuid_t ptr);
-void uuid_unpack(const uuid_t in, struct uuid *uu);
diff --git a/e2fsprogs/old_e2fsprogs/uuid/uuid_time.c b/e2fsprogs/old_e2fsprogs/uuid/uuid_time.c
deleted file mode 100644
index b6f73e6..0000000
--- a/e2fsprogs/old_e2fsprogs/uuid/uuid_time.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * uuid_time.c --- Interpret the time field from a uuid. This program
- * violates the UUID abstraction barrier by reaching into the guts
- * of a UUID and interpreting it.
- *
- * Copyright (C) 1998, 1999 Theodore Ts'o.
- *
- * %Begin-Header%
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, and the entire permission notice in its entirety,
- * including the disclaimer of warranties.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
- * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- * %End-Header%
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <time.h>
-
-#include "uuidP.h"
-
-time_t uuid_time(const uuid_t uu, struct timeval *ret_tv)
-{
- struct uuid uuid;
- uint32_t high;
- struct timeval tv;
- unsigned long long clock_reg;
-
- uuid_unpack(uu, &uuid);
-
- high = uuid.time_mid | ((uuid.time_hi_and_version & 0xFFF) << 16);
- clock_reg = uuid.time_low | ((unsigned long long) high << 32);
-
- clock_reg -= (((unsigned long long) 0x01B21DD2) << 32) + 0x13814000;
- tv.tv_sec = clock_reg / 10000000;
- tv.tv_usec = (clock_reg % 10000000) / 10;
-
- if (ret_tv)
- *ret_tv = tv;
-
- return tv.tv_sec;
-}
-
-int uuid_type(const uuid_t uu)
-{
- struct uuid uuid;
-
- uuid_unpack(uu, &uuid);
- return ((uuid.time_hi_and_version >> 12) & 0xF);
-}
-
-int uuid_variant(const uuid_t uu)
-{
- struct uuid uuid;
- int var;
-
- uuid_unpack(uu, &uuid);
- var = uuid.clock_seq;
-
- if ((var & 0x8000) == 0)
- return UUID_VARIANT_NCS;
- if ((var & 0x4000) == 0)
- return UUID_VARIANT_DCE;
- if ((var & 0x2000) == 0)
- return UUID_VARIANT_MICROSOFT;
- return UUID_VARIANT_OTHER;
-}
-
-#ifdef DEBUG
-static const char *variant_string(int variant)
-{
- switch (variant) {
- case UUID_VARIANT_NCS:
- return "NCS";
- case UUID_VARIANT_DCE:
- return "DCE";
- case UUID_VARIANT_MICROSOFT:
- return "Microsoft";
- default:
- return "Other";
- }
-}
-
-
-int
-main(int argc, char **argv)
-{
- uuid_t buf;
- time_t time_reg;
- struct timeval tv;
- int type, variant;
-
- if (argc != 2) {
- fprintf(stderr, "Usage: %s uuid\n", argv[0]);
- exit(1);
- }
- if (uuid_parse(argv[1], buf)) {
- fprintf(stderr, "Invalid UUID: %s\n", argv[1]);
- exit(1);
- }
- variant = uuid_variant(buf);
- type = uuid_type(buf);
- time_reg = uuid_time(buf, &tv);
-
- printf("UUID variant is %d (%s)\n", variant, variant_string(variant));
- if (variant != UUID_VARIANT_DCE) {
- printf("Warning: This program only knows how to interpret "
- "DCE UUIDs.\n\tThe rest of the output is likely "
- "to be incorrect!!\n");
- }
- printf("UUID type is %d", type);
- switch (type) {
- case 1:
- printf(" (time based)\n");
- break;
- case 2:
- printf(" (DCE)\n");
- break;
- case 3:
- printf(" (name-based)\n");
- break;
- case 4:
- printf(" (random)\n");
- break;
- default:
- bb_putchar('\n');
- }
- if (type != 1) {
- printf("Warning: not a time-based UUID, so UUID time "
- "decoding will likely not work!\n");
- }
- printf("UUID time is: (%ld, %ld): %s\n", tv.tv_sec, tv.tv_usec,
- ctime(&time_reg));
-
- return 0;
-}
-#endif
diff --git a/include/libbb.h b/include/libbb.h
index 62a60f9..81d3116 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1548,6 +1548,14 @@ extern const char bb_default_login_shell[];
#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
+#if ENABLE_FEATURE_UUID
+typedef unsigned char uuid_t[16];
+#define uuid_clear(uu) memset(uu, 0, sizeof(uu))
+void uuid_generate(uuid_t out);
+#define uuid_is_null(uu) (!memcmp(uu, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", sizeof(uu)))
+void uuid_unparse(const uuid_t uu, char *out);
+#endif
+
POP_SAVED_FUNCTION_VISIBILITY
diff --git a/libbb/Config.in b/libbb/Config.in
index a572775..dc4a300 100644
--- a/libbb/Config.in
+++ b/libbb/Config.in
@@ -164,4 +164,9 @@ config FEATURE_HWIB
Support for printing infiniband addresses in
network applets.
+config FEATURE_UUID
+ bool #No description makes it a hidden option
+ default n
+ #help
+
endmenu
diff --git a/libbb/Kbuild b/libbb/Kbuild
index 70dc48d..ce57dcb 100644
--- a/libbb/Kbuild
+++ b/libbb/Kbuild
@@ -138,6 +138,7 @@ lib-$(CONFIG_SELINUX) += selinux_common.o
lib-$(CONFIG_HWCLOCK) += rtc.o
lib-$(CONFIG_RTCWAKE) += rtc.o
lib-$(CONFIG_FEATURE_CHECK_NAMES) += die_if_bad_username.o
+lib-$(CONFIG_FEATURE_UUID) += uuid.o
# We shouldn't build xregcomp.c if we don't need it - this ensures we don't
# require regex.h to be in the include dir even if we don't need it thereby
diff --git a/libbb/uuid.c b/libbb/uuid.c
new file mode 100644
index 0000000..a1e6439
--- /dev/null
+++ b/libbb/uuid.c
@@ -0,0 +1,115 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * uuid.c --- generate a DCE-compatible uuid
+ *
+ * Copyright (C) 1996, 1997, 1998, 1999 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ *
+ * Stripped down for use in busybox by Colin Watson; supports only random
+ * UUIDs.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+
+#include "libbb.h"
+
+static int get_random_fd(void)
+{
+ struct timeval tv;
+ int fd;
+ int i;
+
+ gettimeofday(&tv, 0);
+ fd = open("/dev/urandom", O_RDONLY);
+ srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
+
+ /* Crank the random number generator a few times */
+ gettimeofday(&tv, 0);
+ for (i = (tv.tv_sec ^ tv.tv_usec) & 0x1F; i > 0; i--)
+ rand();
+ return fd;
+}
+
+
+/*
+ * Generate a series of random bytes. Use /dev/urandom if possible,
+ * and if not, use srandom/random.
+ */
+static void get_random_bytes(void *buf, int nbytes)
+{
+ int i, fd = get_random_fd();
+ unsigned char *cp;
+
+ if (fd >= 0) {
+ i = full_read(fd, buf, nbytes);
+ close(fd);
+ }
+
+ /*
+ * We do this all the time, but this is the only source of
+ * randomness if /dev/random/urandom is out to lunch.
+ */
+ for (cp = buf, i = 0; i < nbytes; i++)
+ *cp++ ^= (rand() >> 7) & 0xFF;
+}
+
+void uuid_generate(uuid_t out)
+{
+ get_random_bytes(out, sizeof(uuid_t));
+
+ out[6] = (out[6] & 0x0F) | 0x40; /* time_hi_and_version */
+ out[8] = (out[8] & 0x3F) | 0x80; /* clock_seq */
+ /*
+ * Set multicast bit, to prevent conflicts
+ * with IEEE 802 addresses obtained from
+ * network cards
+ */
+ out[10] |= 0x01;
+}
+
+void uuid_unparse(const uuid_t uu, char *out)
+{
+ char uuid_string[32];
+
+ bin2hex(uuid_string, (const char*) uu, 16);
+ /* f.e. dfd9c173-be52-4d27-99a5-c34c6c2ff55f */
+ sprintf(out, "%.8s" "-%.4s-%.4s-%.4s-%.12s",
+ uuid_string,
+ uuid_string+8,
+ uuid_string+8+4,
+ uuid_string+8+4+4,
+ uuid_string+8+4+4+4
+ );
+}
diff --git a/scripts/Makefile.IMA b/scripts/Makefile.IMA
index a34db50..5aadb72 100644
--- a/scripts/Makefile.IMA
+++ b/scripts/Makefile.IMA
@@ -103,9 +103,6 @@ lib-y:=
#include e2fsprogs/old_e2fsprogs/blkid/Kbuild
#lib-all-y += $(patsubst %,e2fsprogs/old_e2fsprogs/blkid/%,$(sort $(lib-y)))
#lib-y:=
-#include e2fsprogs/old_e2fsprogs/uuid/Kbuild
-#lib-all-y += $(patsubst %,e2fsprogs/old_e2fsprogs/uuid/%,$(sort $(lib-y)))
-#lib-y:=
#include e2fsprogs/old_e2fsprogs/e2p/Kbuild
#lib-all-y += $(patsubst %,e2fsprogs/old_e2fsprogs/e2p/%,$(sort $(lib-y)))
#lib-y:=
diff --git a/util-linux/Config.in b/util-linux/Config.in
index 0245501..17ad85b 100644
--- a/util-linux/Config.in
+++ b/util-linux/Config.in
@@ -409,6 +409,14 @@ config FEATURE_MKSWAP_V0
If your kernel is older than 2.1.117, then v0 support is the
only option.
+config FEATURE_MKSWAP_UUID
+ bool "UUID support"
+ default n
+ depends on MKSWAP
+ select FEATURE_UUID
+ help
+ Generate swap spaces with universally unique identifiers.
+
config MORE
bool "more"
default n
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c
index c4e30fd..1a1e2bd 100644
--- a/util-linux/mkswap.c
+++ b/util-linux/mkswap.c
@@ -50,83 +50,6 @@ static void mkswap_selinux_setcontext(int fd, const char *path)
# define mkswap_selinux_setcontext(fd, path) ((void)0)
#endif
-#if ENABLE_DESKTOP
-static void mkswap_generate_uuid(uint8_t *buf)
-{
- pid_t pid;
- unsigned i;
- char uuid_string[32];
-
- /* http://www.ietf.org/rfc/rfc4122.txt
- * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * | time_low |
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * | time_mid | time_hi_and_version |
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * |clk_seq__and_variant | node (0-1) |
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * | node (2-5) |
- * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- * IOW, uuid has this layout:
- * uint32_t time_low (big endian)
- * uint16_t time_mid (big endian)
- * uint16_t time_hi_and_version (big endian)
- * version is a 4-bit field:
- * 1 Time-based version
- * 2 DCE Security version, with embedded POSIX UIDs
- * 3 Name-based version (MD5)
- * 4 Randomly generated version
- * 5 Name-based version (SHA-1)
- * uint16_t clk_seq_and_variant (big endian)
- * variant is a 3-bit field:
- * 0xx Reserved, NCS backward compatibility
- * 10x The variant specified in rfc4122
- * 110 Reserved, Microsoft backward compatibility
- * 111 Reserved for future definition
- * uint8_t node[6]
- *
- * For version 4, these bits are set/cleared:
- * time_hi_and_version & 0x0fff | 0x4000
- * clk_seq_and_variant & 0x3fff | 0x8000
- */
-
- i = open("/dev/urandom", O_RDONLY);
- if (i >= 0) {
- read(i, buf, 16);
- close(i);
- }
- /* Paranoia. /dev/urandom may be missing.
- * rand() is guaranteed to generate at least [0, 2^15) range,
- * but lowest bits in some libc are not so "random". */
- srand(monotonic_us());
- pid = getpid();
- while (1) {
- for (i = 0; i < 16; i++)
- buf[i] ^= rand() >> 5;
- if (pid == 0)
- break;
- srand(pid);
- pid = 0;
- }
-
- buf[4 + 2 ] = (buf[4 + 2 ] & 0x0f) | 0x40; /* time_hi_and_version */
- buf[4 + 2 + 2] = (buf[4 + 2 + 2] & 0x3f) | 0x80; /* clk_seq_and_variant */
-
- bin2hex(uuid_string, (void*) buf, 16);
- /* f.e. UUID=dfd9c173-be52-4d27-99a5-c34c6c2ff55f */
- printf("UUID=%.8s" "-%.4s-%.4s-%.4s-%.12s\n",
- uuid_string,
- uuid_string+8,
- uuid_string+8+4,
- uuid_string+8+4+4,
- uuid_string+8+4+4+4
- );
-}
-#else
-# define mkswap_generate_uuid(buf) ((void)0)
-#endif
-
#if 0 /* from Linux 2.6.23 */
/*
* Magic header for a swap area. The first part of the union is
@@ -168,6 +91,9 @@ int mkswap_main(int argc, char **argv)
{
int fd, pagesize;
off_t len;
+#if ENABLE_FEATURE_MKSWAP_UUID
+ char uuid_string[37];
+#endif
// No options supported.
@@ -189,7 +115,11 @@ int mkswap_main(int argc, char **argv)
// Make a header. hdr is zero-filled so far...
hdr[0] = 1;
hdr[1] = (len / pagesize) - 1;
- mkswap_generate_uuid((void*) &hdr[3]);
+#if ENABLE_FEATURE_MKSWAP_UUID
+ uuid_generate((void*) &hdr[3]);
+ uuid_unparse((const void*) &hdr[3], uuid_string);
+ printf("UUID=%s\n", uuid_string);
+#endif
// Write the header. Sync to disk because some kernel versions check
// signature on disk (not in cache) during swapon.
--
1.6.3.1
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox