xref: /openbsd/share/man/man9/disklabel.9 (revision 8932bfb7)
1.\"	$OpenBSD: disklabel.9,v 1.16 2011/07/06 04:55:00 matthew Exp $
2.\"	$NetBSD: disklabel.9,v 1.7 1999/03/06 22:09:29 mycroft Exp $
3.\"
4.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
5.\" All rights reserved.
6.\"
7.\" This code is derived from software contributed to The NetBSD Foundation
8.\" by Paul Kranenburg.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29.\" POSSIBILITY OF SUCH DAMAGE.
30.\"
31.Dd $Mdocdate: July 6 2011 $
32.Dt DISKLABEL 9
33.Os
34.Sh NAME
35.Nm disklabel ,
36.Nm readdisklabel ,
37.Nm writedisklabel ,
38.Nm setdisklabel ,
39.Nm bounds_check_with_label
40.Nd disk label management routines
41.Sh SYNOPSIS
42.Fd #include <sys/param.h>
43.Fd #include <sys/disklabel.h>
44.Ft int
45.Fn readdisklabel "dev_t dev" "void (*strat)(struct buf *)" "struct disklabel *lp" "int spoofonly"
46.Ft int
47.Fn writedisklabel "dev_t dev" "void (*strat)(struct buf *)" "struct disklabel *lp"
48.Ft int
49.Fn setdisklabel "struct disklabel *olp" "struct disklabel *nlp" "u_int openmask"
50.Ft int
51.Fn bounds_check_with_label "struct buf *bp" "struct disklabel *lp"
52.Sh DESCRIPTION
53This collection of routines provides a disklabel management interface to
54kernel device drivers.
55These routines are classified as machine- or architecture-dependent because
56of restrictions imposed by the machine architecture and boot-strapping code
57on the location of the label, or because cooperation with other operating
58systems requires specialized conversion code.
59.Pp
60.Fn readdisklabel
61attempts to read a disklabel from the device identified by
62.Fa dev ,
63using the device strategy routine passed in
64.Fa strat .
65Note that a buffer structure is required to pass to the strategy routine;
66it needs to be acquired and parametrized for the intended I/O operation,
67and disposed of when the operation has completed.
68Some fields in the disklabel passed in
69.Fa lp
70may be pre-initialized by the caller in order to meet device driver
71requirements for the I/O operation initiated to get to the disklabel data
72on the medium.
73In particular, the field
74.Dq d_secsize ,
75if non-zero, is used by
76.Fn readdisklabel
77to get an appropriately sized buffer to pass to the device strategy routine.
78Unspecified fields in
79.Fa lp
80should be set to zero.
81If the medium does not contain a native disklabel that can be read in directly
82or
83.Fa spoofonly
84argument is a true value,
85If a disk label is found or can be constructed a value of 0 is returned.
86Otherwise the value of the I/O errno encountered is returned.
87.Pp
88.Fn writedisklabel
89stores disk label information contained in the disk label structure given by
90.Fa lp
91on the device identified by
92.Fa dev .
93Like
94.Fn readdisklabel ,
95it acquires and sets up an I/O buffer to pass to the strategy routine
96.Fa strat .
97.Fn writedisklabel
98returns 0 on success and
99.Dv EINVAL
100if the disk label specifies invalid or unconvertible values.
101Otherwise, any error condition reported by the device strategy routine
102in the buffer's
103.Dq Va b_error
104field is returned.
105.Pp
106.Fn setdisklabel
107checks a proposed new disk label passed in
108.Fa nlp
109for some amount of basic sanity.
110This includes a check on attempts to
111change the location, or reduce the size, of an existing disk partition
112that is currently in use by the system.
113The current disposition of the disk partitions is made available through
114.Fa olp
115and
116.Fa openmask ,
117which provide, respectively, the existing disk label and a bit mask
118identifying the partitions that are currently in use.
119Failure to pass on
120.Dq basic sanity ,
121results in a
122.Dv EINVAL
123return value, while a vetoed update of the partition layout is signalled by a
124.Dv EBUSY
125return value.
126Otherwise, 0 is returned.
127.Pp
128.Fn bounds_check_with_label
129is used to check whether a device transfer described by
130.Fa bp
131to the device identified by
132.Fa dev ,
133is properly contained within a disk partition of the disk with label
134.Fa lp .
135If this check fails,
136.Fn bounds_check_with_label
137sets the buffer's
138.Dq Va b_error
139field to
140.Dv EINVAL
141and sets the
142.Dv B_ERROR
143flag in
144.Dq Va b_flags .
145A value of \-1 is returned if any of the bound checks failed,
146a null transfer was attempted,
147or transfer was attempted exactly at the end of the disk partition.
148Otherwise the value of 0 is returned.
149.Sh SEE ALSO
150.Xr disklabel 5 ,
151.Xr disklabel 8 ,
152.Xr fdisk 8
153