* [PATCH 2/3] fdisk: use randutils for mbr signature creation
@ 2012-04-05 21:52 Davidlohr Bueso
2012-04-10 11:24 ` Karel Zak
0 siblings, 1 reply; 2+ messages in thread
From: Davidlohr Bueso @ 2012-04-05 21:52 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
From: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
fdisk/Makefile.am | 1 +
fdisk/fdisk.c | 51 +++++----------------------------------------------
2 files changed, 6 insertions(+), 46 deletions(-)
diff --git a/fdisk/Makefile.am b/fdisk/Makefile.am
index 9fbfc79..f6e9a4b 100644
--- a/fdisk/Makefile.am
+++ b/fdisk/Makefile.am
@@ -10,6 +10,7 @@ fdisk_common = \
$(top_srcdir)/lib/blkdev.c \
$(top_srcdir)/lib/mbsalign.c \
$(top_srcdir)/lib/strutils.c \
+ $(top_srcdir)/lib/randutils.c \
$(top_srcdir)/lib/wholedisk.c
if LINUX
diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index 126efb3..7c14861 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -33,6 +33,7 @@
#include "pathnames.h"
#include "canonicalize.h"
#include "strutils.h"
+#include "randutils.h"
#include "fdisksunlabel.h"
#include "fdisksgilabel.h"
@@ -186,51 +187,6 @@ get_nr_sects(struct partition *p) {
return read4_little_endian(p->size4);
}
-static ssize_t
-xread(int fd, void *buf, size_t count) {
- char *p = buf;
- ssize_t out = 0;
- ssize_t rv;
-
- while (count) {
- rv = read(fd, p, count);
- if (rv == -1) {
- if (errno == EINTR || errno == EAGAIN)
- continue;
- return out ? out : -1; /* Error */
- } else if (rv == 0) {
- return out; /* EOF */
- }
-
- p += rv;
- out += rv;
- count -= rv;
- }
-
- return out;
-}
-
-static unsigned int
-get_random_id(void) {
- int fd;
- unsigned int v;
- ssize_t rv = -1;
- struct timeval tv;
-
- fd = open("/dev/urandom", O_RDONLY);
- if (fd >= 0) {
- rv = xread(fd, &v, sizeof v);
- close(fd);
- }
-
- if (rv == sizeof v)
- return v;
-
- /* Fallback: sucks, but better than nothing */
- gettimeofday(&tv, NULL);
- return (unsigned int)(tv.tv_sec + (tv.tv_usec << 12) + getpid());
-}
-
/*
* Raw disk label. For DOS-type partition tables the MBR,
* with descriptions of the primary partitions.
@@ -876,7 +832,10 @@ static void dos_init(void)
static void
create_doslabel(void) {
- unsigned int id = get_random_id();
+ unsigned int id;
+
+ /* random disk signature */
+ random_get_bytes(&id, sizeof(id));
fprintf(stderr, _("Building a new DOS disklabel with disk identifier 0x%08x.\n"), id);
sun_nolabel(); /* otherwise always recognised as sun */
--
1.7.4.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-04-10 11:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-05 21:52 [PATCH 2/3] fdisk: use randutils for mbr signature creation Davidlohr Bueso
2012-04-10 11:24 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox