$(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
#include "pathnames.h"
#include "canonicalize.h"
#include "strutils.h"
+#include "randutils.h"
#include "fdisksunlabel.h"
#include "fdisksgilabel.h"
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.
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 */