Continue untangling the disklabel. Use the generic disk_info structure
[dragonfly.git] / sys / sys / disk.h
1 /*
2  * Copyright (c) 2003,2004 The DragonFly Project.  All rights reserved.
3  * 
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  * 
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 
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
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  * 
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  * 
34  * ----------------------------------------------------------------------------
35  * "THE BEER-WARE LICENSE" (Revision 42):
36  * <phk@FreeBSD.ORG> wrote this file.  As long as you retain this notice you
37  * can do whatever you want with this stuff. If we meet some day, and you think
38  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
39  * ----------------------------------------------------------------------------
40  *
41  * $FreeBSD: src/sys/sys/disk.h,v 1.16.2.3 2001/06/20 16:11:01 scottl Exp $
42  * $DragonFly: src/sys/sys/disk.h,v 1.12 2007/05/15 05:37:39 dillon Exp $
43  */
44
45 #ifndef _SYS_DISK_H_
46 #define _SYS_DISK_H_
47
48 #if !defined(_KERNEL) && !defined(_KERNEL_STRUCTURES)
49 #error "This file should not be included by userland programs."
50 #endif
51
52 #ifndef _SYS_DISKSLICE_H_
53 #include <sys/diskslice.h>
54 #endif
55
56 #ifndef _SYS_DISKLABEL_H_
57 #include <sys/disklabel.h>
58 #endif
59
60 /*
61  * Media information structure - filled in by the media driver.
62  */
63 struct disk_info {
64         /*
65          * These fields are required.  Most drivers will load a disk_info
66          * structure in the device open function with the media parameters
67          * and call disk_setdiskinfo().
68          *
69          * Note that only one of d_media_size or d_media_blocks should be
70          * filled in.
71          *
72          * d_media_size         media size in bytes
73          * d_media_blocks       media size in blocks (e.g. total sectors)
74          * d_media_blksize      media block size / sector size
75          * d_dsflags            disklabel management flags
76          */
77         u_int64_t               d_media_size;
78         u_int64_t               d_media_blocks;
79         int                     d_media_blksize;
80         u_int                   d_dsflags;
81
82         /*
83          * Optional fields, leave 0 if not known
84          */
85         u_int                   d_type;         /* DTYPE_xxx */
86         u_int                   d_nheads;
87         u_int                   d_ncylinders;
88         u_int                   d_secpertrack;
89         u_int                   d_secpercyl;
90 };
91
92 /*
93  * d_dsflags, also used for dsopen() - control disklabel processing
94  */
95 #define DSO_NOLABELS            0x0001
96 #define DSO_ONESLICE            0x0002
97 #define DSO_COMPATLABEL         0x0004
98 #define DSO_COMPATPARTA         0x0008
99
100 /*
101  * Disk management structure - automated disklabel support.
102  */
103 struct disk {
104         struct dev_ops          *d_dev_ops;     /* our device switch */
105         struct dev_ops          *d_raw_ops;     /* the raw device switch */
106         u_int                   d_flags;
107         cdev_t                  d_rawdev;       /* backing raw device */
108         cdev_t                  d_cdev;         /* special whole-disk part */
109         struct diskslices       *d_slice;
110         struct disk_info        d_info;         /* info structure for media */
111         LIST_ENTRY(disk)        d_list;
112 };
113
114 /*
115  * d_flags
116  */
117 #define DISKFLAG_LOCK           0x1
118 #define DISKFLAG_WANTED         0x2
119
120 #ifdef _KERNEL
121 cdev_t disk_create (int unit, struct disk *disk, struct dev_ops *raw_ops);
122 void disk_destroy (struct disk *disk);
123 void disk_setdiskinfo (struct disk *disk, struct disk_info *info);
124 int disk_dumpcheck (cdev_t dev, u_int *count, u_int *blkno, u_int *secsize);
125 struct disk *disk_enumerate (struct disk *disk);
126 void disk_invalidate (struct disk *disk);
127 #endif /* _KERNEL */
128
129 #endif /* _SYS_DISK_H_ */