]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - lib/libdisk/libdisk.3
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / lib / libdisk / libdisk.3
1 .\"
2 .\" Copyright (c) 1996 Joerg Wunsch
3 .\"
4 .\" All rights reserved.
5 .\"
6 .\" This program is free software.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\"    notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\"    notice, this list of conditions and the following disclaimer in the
15 .\"    documentation and/or other materials provided with the distribution.
16 .\"
17 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
18 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 .\"
28 .\" $FreeBSD$
29 .\" "
30 .Dd January 30, 2006
31 .Dt LIBDISK 3
32 .Os
33 .Sh NAME
34 .Nm Open_Disk ,
35 .Nm Free_Disk ,
36 .Nm Debug_Disk ,
37 .Nm Set_Bios_Geom ,
38 .Nm Delete_Chunk ,
39 .Nm Collapse_Disk ,
40 .Nm Collapse_Chunk ,
41 .Nm Create_Chunk ,
42 .Nm All_FreeBSD ,
43 .Nm CheckRules ,
44 .Nm Disk_Names ,
45 .Nm Set_Boot_Mgr ,
46 .Nm Set_Boot_Blocks ,
47 .Nm Write_Disk ,
48 .Nm Cyl_Aligned ,
49 .Nm Next_Cyl_Aligned ,
50 .Nm Prev_Cyl_Aligned ,
51 .Nm Track_Aligned ,
52 .Nm Next_Track_Aligned ,
53 .Nm Prev_Track_Aligned ,
54 .Nm Create_Chunk_DWIM ,
55 .Nm MakeDev ,
56 .Nm MakeDevDisk ,
57 .Nm ShowChunkFlags ,
58 .Nm chunk_name ,
59 .Nm slice_type_name
60 .Nd library interface to slice and partition labels
61 .Sh LIBRARY
62 .Lb libdisk
63 .Sh SYNOPSIS
64 .In sys/types.h
65 .In libdisk.h
66 .Pp
67 .Ft struct disk *
68 .Fn Open_Disk "const char *devname"
69 .Ft void
70 .Fn Free_Disk "struct disk *disk"
71 .Ft void
72 .Fn Debug_Disk "struct disk *disk"
73 .Ft void
74 .Fn Set_Bios_Geom "struct disk *disk" "u_long cyl" "u_long heads" "u_long sects"
75 .Ft int
76 .Fn Delete_Chunk "struct disk *disk" "struct chunk *"
77 .Ft void
78 .Fn Collapse_Disk "struct disk *disk"
79 .Ft int
80 .Fn Collapse_Chunk "struct disk *disk" "struct chunk *chunk"
81 .Ft int
82 .Fn Create_Chunk "struct disk *disk" "daddr_t offset" "daddr_t size" "chunk_e type" "int subtype" "u_long flags" "const char *sname"
83 .Ft void
84 .Fn All_FreeBSD "struct disk *d" "int force_all"
85 .Ft char *
86 .Fn CheckRules "const struct disk *"
87 .Ft char **
88 .Fn Disk_Names "void"
89 .Ft void
90 .Fn Set_Boot_Mgr "struct disk *d" "const u_char *bootmgr" "const size_t bootmgr_size"
91 .Ft int
92 .Fn Set_Boot_Blocks "struct disk *d" "const u_char *boot1" "const u_char *boot2"
93 .Ft int
94 .Fn Write_Disk "const struct disk *d"
95 .Ft int
96 .Fn Cyl_Aligned "struct disk *d" "daddr_t offset"
97 .Ft daddr_t
98 .Fn Next_Cyl_Aligned "const struct disk *d" "daddr_t offset"
99 .Ft daddr_t
100 .Fn Prev_Cyl_Aligned "const struct disk *d" "daddr_t offset"
101 .Ft int
102 .Fn Track_Aligned "const struct disk *d" "daddr_t offset"
103 .Ft daddr_t
104 .Fn Next_Track_Aligned "const struct disk *d" "daddr_t offset"
105 .Ft daddr_t
106 .Fn Prev_Track_Aligned "const struct disk *d" "daddr_t offset"
107 .Ft struct chunk *
108 .Fn Create_Chunk_DWIM "struct disk *d" "struct chunk *parent" "daddr_t size" "chunk_e type" "int subtype" "u_long flags"
109 .Ft int
110 .Fn MakeDev "struct chunk *c" "const char *path"
111 .Ft int
112 .Fn MakeDevDisk "struct disk *d" "const char *path"
113 .Ft char *
114 .Fn ShowChunkFlags "struct chunk *c"
115 .Ft const char *
116 .Fn chunk_name "chunk_e type"
117 .Ft const char *
118 .Fn slice_type_name "int type" "int subtype"
119 .Sh DESCRIPTION
120 .Bf Sy
121 .Nm libdisk
122 is just for the use of
123 .Xr sysinstall 8 .
124 You should consider using
125 .Xr libgeom 3
126 instead.
127 .Ef
128 .Pp
129 The
130 .Nm libdisk
131 library provides an interface to the low-level disk slice and partition labels.
132 Most functions operate with arguments of the types
133 .Ql struct disk ,
134 or
135 .Ql struct chunk .
136 .Pp
137 While both types are mostly opaque to the programmer, the internal
138 structure is mentioned below for the sake of completeness.
139 .Bd -literal -offset indent
140 struct disk {
141         char            *name;
142         u_long          flags;
143         u_long          bios_cyl;
144         u_long          bios_hd;
145         u_long          bios_sect;
146         u_char          *bootmgr;
147         u_char          *boot1;
148         u_char          *boot2;
149         struct chunk    *chunks;
150         u_long          sector_size;
151 };
152 .Ed
153 The only flag value by now is
154 .Ql DISK_ON_TRACK ,
155 meaning that this disk is handled by the On-Track Disk Manager.
156 .Bd -literal -offset indent
157 struct chunk {
158         struct chunk    *next;
159         struct chunk    *part;
160         struct disk     *disk;
161         daddr_t         offset;
162         daddr_t         size;
163         daddr_t         end;
164         char            *name;
165         char            *oname;
166         chunk_e         type;
167         int             subtype;
168         u_long          flags;
169         void            (*private_free)(void*);
170         void            *(*private_clone)(void*);
171         void            *private_data;
172 };
173 .Ed
174 The
175 .Ql type
176 field can be one of the following values:
177 .Ql whole, unknown, fat, freebsd, extended, part, unused .
178 .Pp
179 These are the valid
180 .Ql flags
181 values for a
182 .Ql struct chunk .
183 .Bl -tag -offset indent -width CHUNK_AUTO_SIZEXX
184 .It CHUNK_ALIGN
185 This chunk should be aligned.
186 .It CHUNK_IS_ROOT
187 This
188 .Ql part
189 is a rootfs, allocate partition
190 .Sq a .
191 .It CHUNK_ACTIVE
192 This is the active slice in the MBR.
193 .It CHUNK_FORCE_ALL
194 Force a dedicated disk for
195 .Fx ,
196 bypassing all BIOS geometry considerations.
197 .It CHUNK_AUTO_SIZE
198 This chunk was auto-sized and can fill out any deleted following chunks.
199 .It CHUNK_NEWFS
200 newfs pending, used to enable auto-resizing on delete (along with AUTO_SIZE).
201 .El
202 .Pp
203 The
204 .Ql private_data ,
205 .Ql private_free ,
206 and
207 .Ql private_clone
208 fields are for data private to the application, and the management
209 thereof.
210 If the functions are not provided, no storage management is
211 done, cloning will just copy the pointer and freeing will just forget
212 it.
213 .Pp
214 .Fn Open_Disk
215 will open the named disk, and return populated tree.
216 .Pp
217 .Fn Free_Disk
218 frees a tree made with
219 .Fn Open_Disk
220 or
221 .Fn Clone_Disk .
222 .Pp
223 .Fn Debug_Disk
224 prints the content of the tree to
225 .Dv stdout .
226 .Pp
227 .Fn Set_Bios_Geom
228 sets the geometry the bios uses.
229 .Pp
230 .Fn Delete_Chunk
231 frees a chunk of disk_space.
232 .Pp
233 .Fn Collapse_Disk
234 and
235 .Fn Collapse_Chunk
236 are experimental, do not use.
237 .Pp
238 .Fn Create_Chunk
239 creates a chunk with the specified parameters.
240 .Pp
241 .Fn All_FreeBSD
242 makes one
243 .Fx
244 chunk covering the entire disk; if
245 .Ql force_all
246 is set, bypass all BIOS geometry considerations.
247 .Pp
248 .Fn CheckRules
249 returns
250 .Ql char*
251 to warnings about broken design rules in this disklayout.
252 .Pp
253 .Fn Disk_Names
254 returns
255 .Ql char**
256 with all disk's names (wd0, wd1 ...).
257 You must free each pointer, as
258 well as the array by hand.
259 .Pp
260 .Fn Set_Boot_Mgr
261 sets this boot-manager for use on this disk.
262 Gets written when
263 .Fn Write_Disk
264 is called.
265 .Pp
266 .Fn Set_Boot_Blocks
267 sets the boot-blocks for use on this disk.
268 Gets written when
269 .Fn Write_Disk
270 is called.
271 .Pp
272 .Fn Write_Disk
273 writes all the MBRs, disklabels, bootblocks and boot managers.
274 .Pp
275 .Fn Cyl_Aligned
276 checks if
277 .Ql offset
278 is aligned on a cylinder according to the BIOS geometry.
279 .Pp
280 .Fn Next_Cyl_Aligned
281 rounds
282 .Ql offset
283 up to next cylinder according to the BIOS geometry.
284 .Pp
285 .Fn Prev_Cyl_Aligned
286 rounds
287 .Ql offset
288 down to previous cylinder according to the BIOS geometry.
289 .Pp
290 .Fn Track_Aligned
291 checks if
292 .Ql offset
293 is aligned on a track according to the BIOS geometry.
294 .Pp
295 .Fn Next_Track_Aligned
296 rounds
297 .Ql offset
298 up to next track according to the BIOS geometry.
299 .Pp
300 .Fn Prev_Track_Aligned
301 rounds
302 .Ql offset
303 up to previous track according to the BIOS geometry.
304 .Pp
305 .Fn Create_Chunk_DWIM
306 creates a partition inside the given parent of the given size, and
307 returns a pointer to it.
308 The first unused chunk big enough is used.
309 .Pp
310 .Fn MakeDev
311 makes the device nodes for this chunk.
312 .Pp
313 .Fn MakeDevDisk
314 makes the device nodes for all chunks on this disk.
315 .Pp
316 .Fn ShowChunkFlags
317 returns a string to show flags.
318 .Pp
319 The
320 .Fn chunk_name
321 function takes the enumerated chunk type and returns its name.
322 .Fn chunk_name
323 replaces the old external array
324 .Va chunk_n .
325 .Pp
326 .Fn slice_type_name
327 returns the name strings associated with the specified
328 .Ql type .
329 .Ql subtype .
330 If
331 .Fn slice_type_name
332 returns "unknown" for slices it is not familiar with.
333 .Sh AUTHORS
334 .An -nosplit
335 The
336 .Nm libdisk
337 library was written by
338 .An Poul-Henning Kamp .
339 .Pp
340 This manual page was written by
341 .An J\(:org Wunsch .