Home | History | Annotate | Line # | Download | only in misc
lvm-wrappers.c revision 1.1.1.1.2.1
      1  1.1.1.1.2.1   jym /*	$NetBSD: lvm-wrappers.c,v 1.1.1.1.2.1 2009/05/13 18:52:43 jym Exp $	*/
      2          1.1  haad 
      3          1.1  haad /*
      4          1.1  haad  * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
      5          1.1  haad  *
      6          1.1  haad  * This file is part of LVM2.
      7          1.1  haad  *
      8          1.1  haad  * This copyrighted material is made available to anyone wishing to use,
      9          1.1  haad  * modify, copy, or redistribute it subject to the terms and conditions
     10          1.1  haad  * of the GNU Lesser General Public License v.2.1.
     11          1.1  haad  *
     12          1.1  haad  * You should have received a copy of the GNU Lesser General Public License
     13          1.1  haad  * along with this program; if not, write to the Free Software Foundation,
     14          1.1  haad  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     15          1.1  haad  */
     16          1.1  haad 
     17          1.1  haad #include "lib.h"
     18          1.1  haad 
     19          1.1  haad #include <unistd.h>
     20  1.1.1.1.2.1   jym #include <fcntl.h>
     21          1.1  haad 
     22          1.1  haad int lvm_getpagesize(void)
     23          1.1  haad {
     24          1.1  haad 	return getpagesize();
     25          1.1  haad }
     26  1.1.1.1.2.1   jym 
     27  1.1.1.1.2.1   jym int read_urandom(void *buf, size_t len)
     28  1.1.1.1.2.1   jym {
     29  1.1.1.1.2.1   jym 	int fd;
     30  1.1.1.1.2.1   jym 
     31  1.1.1.1.2.1   jym 	/* FIXME: we should stat here, and handle other cases */
     32  1.1.1.1.2.1   jym 	/* FIXME: use common _io() routine's open/read/close */
     33  1.1.1.1.2.1   jym 	if ((fd = open("/dev/urandom", O_RDONLY)) < 0) {
     34  1.1.1.1.2.1   jym 		log_sys_error("open", "read_urandom: /dev/urandom");
     35  1.1.1.1.2.1   jym 		return 0;
     36  1.1.1.1.2.1   jym 	}
     37  1.1.1.1.2.1   jym 
     38  1.1.1.1.2.1   jym 	if (read(fd, buf, len) != (ssize_t) len) {
     39  1.1.1.1.2.1   jym 		log_sys_error("read", "read_urandom: /dev/urandom");
     40  1.1.1.1.2.1   jym 		if (close(fd))
     41  1.1.1.1.2.1   jym 			stack;
     42  1.1.1.1.2.1   jym 		return 0;
     43  1.1.1.1.2.1   jym 	}
     44  1.1.1.1.2.1   jym 
     45  1.1.1.1.2.1   jym 	if (close(fd))
     46  1.1.1.1.2.1   jym 		stack;
     47  1.1.1.1.2.1   jym 
     48  1.1.1.1.2.1   jym 	return 1;
     49  1.1.1.1.2.1   jym }
     50  1.1.1.1.2.1   jym 
     51