1 1.1 haad /* $NetBSD: lvm-wrappers.c,v 1.1.1.2 2009/02/18 11:17:18 haad 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.2 haad #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.2 haad 27 1.1.1.2 haad int read_urandom(void *buf, size_t len) 28 1.1.1.2 haad { 29 1.1.1.2 haad int fd; 30 1.1.1.2 haad 31 1.1.1.2 haad /* FIXME: we should stat here, and handle other cases */ 32 1.1.1.2 haad /* FIXME: use common _io() routine's open/read/close */ 33 1.1.1.2 haad if ((fd = open("/dev/urandom", O_RDONLY)) < 0) { 34 1.1.1.2 haad log_sys_error("open", "read_urandom: /dev/urandom"); 35 1.1.1.2 haad return 0; 36 1.1.1.2 haad } 37 1.1.1.2 haad 38 1.1.1.2 haad if (read(fd, buf, len) != (ssize_t) len) { 39 1.1.1.2 haad log_sys_error("read", "read_urandom: /dev/urandom"); 40 1.1.1.2 haad if (close(fd)) 41 1.1.1.2 haad stack; 42 1.1.1.2 haad return 0; 43 1.1.1.2 haad } 44 1.1.1.2 haad 45 1.1.1.2 haad if (close(fd)) 46 1.1.1.2 haad stack; 47 1.1.1.2 haad 48 1.1.1.2 haad return 1; 49 1.1.1.2 haad } 50 1.1.1.2 haad 51