xref: /openbsd-src/share/man/man9/disklabel.9 (revision 41ce3b17e73f6b7d2d9e1a3d961e4bab2d895cb5)
1*41ce3b17Snaddy.\"	$OpenBSD: disklabel.9,v 1.18 2022/03/31 17:27:23 naddy Exp $
2274b0fe4Smickey.\"	$NetBSD: disklabel.9,v 1.7 1999/03/06 22:09:29 mycroft Exp $
3274b0fe4Smickey.\"
4274b0fe4Smickey.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
5274b0fe4Smickey.\" All rights reserved.
6274b0fe4Smickey.\"
7274b0fe4Smickey.\" This code is derived from software contributed to The NetBSD Foundation
8274b0fe4Smickey.\" by Paul Kranenburg.
9274b0fe4Smickey.\"
10274b0fe4Smickey.\" Redistribution and use in source and binary forms, with or without
11274b0fe4Smickey.\" modification, are permitted provided that the following conditions
12274b0fe4Smickey.\" are met:
13274b0fe4Smickey.\" 1. Redistributions of source code must retain the above copyright
14274b0fe4Smickey.\"    notice, this list of conditions and the following disclaimer.
15274b0fe4Smickey.\" 2. Redistributions in binary form must reproduce the above copyright
16274b0fe4Smickey.\"    notice, this list of conditions and the following disclaimer in the
17274b0fe4Smickey.\"    documentation and/or other materials provided with the distribution.
18274b0fe4Smickey.\"
19274b0fe4Smickey.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20274b0fe4Smickey.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21274b0fe4Smickey.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22274b0fe4Smickey.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23274b0fe4Smickey.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24274b0fe4Smickey.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25274b0fe4Smickey.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26274b0fe4Smickey.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27274b0fe4Smickey.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28274b0fe4Smickey.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29274b0fe4Smickey.\" POSSIBILITY OF SUCH DAMAGE.
30274b0fe4Smickey.\"
31*41ce3b17Snaddy.Dd $Mdocdate: March 31 2022 $
32274b0fe4Smickey.Dt DISKLABEL 9
33274b0fe4Smickey.Os
34274b0fe4Smickey.Sh NAME
35274b0fe4Smickey.Nm disklabel ,
36274b0fe4Smickey.Nm readdisklabel ,
37274b0fe4Smickey.Nm writedisklabel ,
38274b0fe4Smickey.Nm setdisklabel ,
39274b0fe4Smickey.Nm bounds_check_with_label
40274b0fe4Smickey.Nd disk label management routines
41274b0fe4Smickey.Sh SYNOPSIS
42dddd2645Sschwarze.In sys/param.h
43dddd2645Sschwarze.In sys/disklabel.h
44184aa047Skrw.Ft int
45c326f117Sderaadt.Fn readdisklabel "dev_t dev" "void (*strat)(struct buf *)" "struct disklabel *lp" "int spoofonly"
46274b0fe4Smickey.Ft int
47c326f117Sderaadt.Fn writedisklabel "dev_t dev" "void (*strat)(struct buf *)" "struct disklabel *lp"
48274b0fe4Smickey.Ft int
49c326f117Sderaadt.Fn setdisklabel "struct disklabel *olp" "struct disklabel *nlp" "u_int openmask"
50274b0fe4Smickey.Ft int
51184aa047Skrw.Fn bounds_check_with_label "struct buf *bp" "struct disklabel *lp"
52274b0fe4Smickey.Sh DESCRIPTION
53274b0fe4SmickeyThis collection of routines provides a disklabel management interface to
54274b0fe4Smickeykernel device drivers.
55274b0fe4SmickeyThese routines are classified as machine- or architecture-dependent because
56274b0fe4Smickeyof restrictions imposed by the machine architecture and boot-strapping code
57274b0fe4Smickeyon the location of the label, or because cooperation with other operating
58274b0fe4Smickeysystems requires specialized conversion code.
59274b0fe4Smickey.Pp
60274b0fe4Smickey.Fn readdisklabel
61274b0fe4Smickeyattempts to read a disklabel from the device identified by
62274b0fe4Smickey.Fa dev ,
63274b0fe4Smickeyusing the device strategy routine passed in
64274b0fe4Smickey.Fa strat .
65274b0fe4SmickeyNote that a buffer structure is required to pass to the strategy routine;
66274b0fe4Smickeyit needs to be acquired and parametrized for the intended I/O operation,
67274b0fe4Smickeyand disposed of when the operation has completed.
6818280b74SjmcSome fields in the disklabel passed in
69274b0fe4Smickey.Fa lp
70274b0fe4Smickeymay be pre-initialized by the caller in order to meet device driver
71274b0fe4Smickeyrequirements for the I/O operation initiated to get to the disklabel data
72274b0fe4Smickeyon the medium.
73274b0fe4SmickeyIn particular, the field
74274b0fe4Smickey.Dq d_secsize ,
75274b0fe4Smickeyif non-zero, is used by
76274b0fe4Smickey.Fn readdisklabel
77274b0fe4Smickeyto get an appropriately sized buffer to pass to the device strategy routine.
78274b0fe4SmickeyUnspecified fields in
79274b0fe4Smickey.Fa lp
80274b0fe4Smickeyshould be set to zero.
81274b0fe4SmickeyIf the medium does not contain a native disklabel that can be read in directly
82274b0fe4Smickeyor
83274b0fe4Smickey.Fa spoofonly
84274b0fe4Smickeyargument is a true value,
85*41ce3b17SnaddyIf a disk label is found or can be constructed, a value of 0 is returned.
86184aa047SkrwOtherwise the value of the I/O errno encountered is returned.
87274b0fe4Smickey.Pp
88274b0fe4Smickey.Fn writedisklabel
89274b0fe4Smickeystores disk label information contained in the disk label structure given by
90274b0fe4Smickey.Fa lp
91274b0fe4Smickeyon the device identified by
92274b0fe4Smickey.Fa dev .
93274b0fe4SmickeyLike
94274b0fe4Smickey.Fn readdisklabel ,
95274b0fe4Smickeyit acquires and sets up an I/O buffer to pass to the strategy routine
96274b0fe4Smickey.Fa strat .
97274b0fe4Smickey.Fn writedisklabel
98274b0fe4Smickeyreturns 0 on success and
99274b0fe4Smickey.Dv EINVAL
100962020bbSavsmif the disk label specifies invalid or unconvertible values.
101274b0fe4SmickeyOtherwise, any error condition reported by the device strategy routine
102274b0fe4Smickeyin the buffer's
103274b0fe4Smickey.Dq Va b_error
104274b0fe4Smickeyfield is returned.
105274b0fe4Smickey.Pp
106274b0fe4Smickey.Fn setdisklabel
107274b0fe4Smickeychecks a proposed new disk label passed in
108274b0fe4Smickey.Fa nlp
109274b0fe4Smickeyfor some amount of basic sanity.
110274b0fe4SmickeyThis includes a check on attempts to
111274b0fe4Smickeychange the location, or reduce the size, of an existing disk partition
112274b0fe4Smickeythat is currently in use by the system.
113274b0fe4SmickeyThe current disposition of the disk partitions is made available through
114274b0fe4Smickey.Fa olp
115274b0fe4Smickeyand
116274b0fe4Smickey.Fa openmask ,
117274b0fe4Smickeywhich provide, respectively, the existing disk label and a bit mask
118274b0fe4Smickeyidentifying the partitions that are currently in use.
119274b0fe4SmickeyFailure to pass on
120274b0fe4Smickey.Dq basic sanity ,
121274b0fe4Smickeyresults in a
122274b0fe4Smickey.Dv EINVAL
123962020bbSavsmreturn value, while a vetoed update of the partition layout is signalled by a
124274b0fe4Smickey.Dv EBUSY
125274b0fe4Smickeyreturn value.
126274b0fe4SmickeyOtherwise, 0 is returned.
127274b0fe4Smickey.Pp
128274b0fe4Smickey.Fn bounds_check_with_label
129274b0fe4Smickeyis used to check whether a device transfer described by
130274b0fe4Smickey.Fa bp
131274b0fe4Smickeyto the device identified by
132274b0fe4Smickey.Fa dev ,
133274b0fe4Smickeyis properly contained within a disk partition of the disk with label
134274b0fe4Smickey.Fa lp .
135274b0fe4SmickeyIf this check fails,
136274b0fe4Smickey.Fn bounds_check_with_label
137274b0fe4Smickeysets the buffer's
138274b0fe4Smickey.Dq Va b_error
139274b0fe4Smickeyfield to
140274b0fe4Smickey.Dv EINVAL
141274b0fe4Smickeyand sets the
142274b0fe4Smickey.Dv B_ERROR
143274b0fe4Smickeyflag in
144274b0fe4Smickey.Dq Va b_flags .
14521563dd1SmatthewA value of \-1 is returned if any of the bound checks failed,
14621563dd1Smatthewa null transfer was attempted,
14721563dd1Smatthewor transfer was attempted exactly at the end of the disk partition.
14821563dd1SmatthewOtherwise the value of 0 is returned.
149274b0fe4Smickey.Sh SEE ALSO
150274b0fe4Smickey.Xr disklabel 5 ,
151274b0fe4Smickey.Xr disklabel 8 ,
152274b0fe4Smickey.Xr fdisk 8
153