Home | History | Annotate | Line # | Download | only in sysinst
geom.c revision 1.1
      1  1.1  dholland /*	$NetBSD: geom.c,v 1.1 2014/07/26 19:30:44 dholland Exp $	*/
      2  1.1  dholland 
      3  1.1  dholland /*
      4  1.1  dholland  * Copyright (c) 1995, 1997 Jason R. Thorpe.
      5  1.1  dholland  * All rights reserved.
      6  1.1  dholland  *
      7  1.1  dholland  * Redistribution and use in source and binary forms, with or without
      8  1.1  dholland  * modification, are permitted provided that the following conditions
      9  1.1  dholland  * are met:
     10  1.1  dholland  * 1. Redistributions of source code must retain the above copyright
     11  1.1  dholland  *    notice, this list of conditions and the following disclaimer.
     12  1.1  dholland  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  dholland  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  dholland  *    documentation and/or other materials provided with the distribution.
     15  1.1  dholland  * 3. All advertising materials mentioning features or use of this software
     16  1.1  dholland  *    must display the following acknowledgement:
     17  1.1  dholland  *	This product includes software developed for the NetBSD Project
     18  1.1  dholland  *	by Jason R. Thorpe.
     19  1.1  dholland  * 4. The name of the author may not be used to endorse or promote products
     20  1.1  dholland  *    derived from this software without specific prior written permission.
     21  1.1  dholland  *
     22  1.1  dholland  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1  dholland  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1  dholland  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1  dholland  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1  dholland  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     27  1.1  dholland  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     28  1.1  dholland  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     29  1.1  dholland  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     30  1.1  dholland  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1  dholland  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1  dholland  * SUCH DAMAGE.
     33  1.1  dholland  */
     34  1.1  dholland 
     35  1.1  dholland /* Modified by Philip A. Nelson for use in sysinst. */
     36  1.1  dholland 
     37  1.1  dholland #include <sys/param.h>
     38  1.1  dholland #include <sys/disklabel.h>
     39  1.1  dholland #include <sys/ioctl.h>
     40  1.1  dholland #include <fcntl.h>
     41  1.1  dholland #include <unistd.h>
     42  1.1  dholland #include <util.h>
     43  1.1  dholland #include <errno.h>
     44  1.1  dholland 
     45  1.1  dholland #include "defs.h"
     46  1.1  dholland 
     47  1.1  dholland static int
     48  1.1  dholland get_label(const char *disk, struct disklabel *l, unsigned long cmd)
     49  1.1  dholland {
     50  1.1  dholland 	char diskpath[MAXPATHLEN];
     51  1.1  dholland 	int fd;
     52  1.1  dholland 	int sv_errno;
     53  1.1  dholland 
     54  1.1  dholland 	/* Open the disk. */
     55  1.1  dholland 	fd = opendisk(disk, O_RDONLY, diskpath, sizeof(diskpath), 0);
     56  1.1  dholland 	if (fd < 0)
     57  1.1  dholland 		return 0;
     58  1.1  dholland 
     59  1.1  dholland 	if (ioctl(fd, cmd, l) < 0) {
     60  1.1  dholland 		sv_errno = errno;
     61  1.1  dholland 		(void)close(fd);
     62  1.1  dholland 		errno = sv_errno;
     63  1.1  dholland 		return 0;
     64  1.1  dholland 	}
     65  1.1  dholland 	(void)close(fd);
     66  1.1  dholland 	return 1;
     67  1.1  dholland }
     68  1.1  dholland 
     69  1.1  dholland int
     70  1.1  dholland get_geom(const char *disk, struct disklabel *l)
     71  1.1  dholland {
     72  1.1  dholland 
     73  1.1  dholland 	return get_label(disk, l, DIOCGDEFLABEL);
     74  1.1  dholland }
     75  1.1  dholland 
     76  1.1  dholland int
     77  1.1  dholland get_real_geom(const char *disk, struct disklabel *l)
     78  1.1  dholland {
     79  1.1  dholland 
     80  1.1  dholland 	return get_label(disk, l, DIOCGDINFO);
     81  1.1  dholland }
     82