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