Manual Page Result
0
Command: disklabel | Section: 9 | Source: OpenBSD | File: disklabel.9
DISKLABEL(9) FreeBSD Kernel Developer's Manual DISKLABEL(9)
NAME
disklabel, readdisklabel, writedisklabel, setdisklabel,
bounds_check_with_label - disk label management routines
SYNOPSIS
#include <sys/param.h>
#include <sys/disklabel.h>
int
readdisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp, int spoofonly);
int
writedisklabel(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp);
int
setdisklabel(struct disklabel *olp, struct disklabel *nlp,
u_int openmask);
int
bounds_check_with_label(struct buf *bp, struct disklabel *lp);
DESCRIPTION
This collection of routines provides a disklabel management interface to
kernel device drivers. These routines are classified as machine- or
architecture-dependent because of restrictions imposed by the machine
architecture and boot-strapping code on the location of the label, or
because cooperation with other operating systems requires specialized
conversion code.
readdisklabel() attempts to read a disklabel from the device identified
by dev, using the device strategy routine passed in strat. Note that a
buffer structure is required to pass to the strategy routine; it needs to
be acquired and parametrized for the intended I/O operation, and disposed
of when the operation has completed. Some fields in the disklabel passed
in lp may be pre-initialized by the caller in order to meet device driver
requirements for the I/O operation initiated to get to the disklabel data
on the medium. In particular, the field "d_secsize", if non-zero, is
used by readdisklabel() to get an appropriately sized buffer to pass to
the device strategy routine. Unspecified fields in lp should be set to
zero. If the medium does not contain a native disklabel that can be read
in directly or spoofonly argument is a true value, If a disk label is
found or can be constructed, a value of 0 is returned. Otherwise the
value of the I/O errno encountered is returned.
writedisklabel() stores disk label information contained in the disk
label structure given by lp on the device identified by dev. Like
readdisklabel(), it acquires and sets up an I/O buffer to pass to the
strategy routine strat. writedisklabel() returns 0 on success and EINVAL
if the disk label specifies invalid or unconvertible values. Otherwise,
any error condition reported by the device strategy routine in the
buffer's "b_error" field is returned.
setdisklabel() checks a proposed new disk label passed in nlp for some
amount of basic sanity. This includes a check on attempts to change the
location, or reduce the size, of an existing disk partition that is
currently in use by the system. The current disposition of the disk
partitions is made available through olp and openmask, which provide,
respectively, the existing disk label and a bit mask identifying the
partitions that are currently in use. Failure to pass on "basic sanity",
results in a EINVAL return value, while a vetoed update of the partition
layout is signalled by a EBUSY return value. Otherwise, 0 is returned.
bounds_check_with_label() is used to check whether a device transfer
described by bp to the device identified by dev, is properly contained
within a disk partition of the disk with label lp. If this check fails,
bounds_check_with_label() sets the buffer's "b_error" field to EINVAL and
sets the B_ERROR flag in "b_flags". A value of -1 is returned if any of
the bound checks failed, a null transfer was attempted, or transfer was
attempted exactly at the end of the disk partition. Otherwise the value
of 0 is returned.
SEE ALSO
disklabel(5), disklabel(8), fdisk(8)
FreeBSD 14.1-RELEASE-p8 March 31, 2022 FreeBSD 14.1-RELEASE-p8