nrelease - fix/improve livecd
[dragonfly.git] / sys / sys / disk.h
CommitLineData
984263bc 1/*
8c10bfcf
MD
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 *
e4c9c0c8
MD
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
8c10bfcf 10 *
e4c9c0c8
MD
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
8c10bfcf
MD
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
e4c9c0c8 32 * SUCH DAMAGE.
8c10bfcf 33 *
984263bc
MD
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 $
984263bc
MD
42 */
43
44#ifndef _SYS_DISK_H_
45#define _SYS_DISK_H_
46
d9f3f6fa
CP
47#if !defined(_KERNEL) && !defined(_KERNEL_STRUCTURES)
48#error "This file should not be included by userland programs."
49#endif
50
984263bc
MD
51#ifndef _SYS_DISKSLICE_H_
52#include <sys/diskslice.h>
335dda38 53#endif
5350e1e9
MD
54#ifndef _SYS_QUEUE_H_
55#include <sys/queue.h>
56#endif
cd29885a
MD
57#ifndef _SYS_MSGPORT_H_
58#include <sys/msgport.h>
59#endif
185ace93
MD
60#ifndef _SYS_DMSG_H_
61#include <sys/dmsg.h>
62#endif
335dda38 63
a688b15c
MD
64/*
65 * Media information structure - filled in by the media driver.
55230951
MD
66 *
67 * NOTE: d_serialno is copied on the call to setdiskinfo and need
68 * not be valid after that.
a688b15c
MD
69 */
70struct disk_info {
71 /*
72 * These fields are required. Most drivers will load a disk_info
73 * structure in the device open function with the media parameters
74 * and call disk_setdiskinfo().
75 *
76 * Note that only one of d_media_size or d_media_blocks should be
77 * filled in.
78 *
79 * d_media_size media size in bytes
80 * d_media_blocks media size in blocks (e.g. total sectors)
81 * d_media_blksize media block size / sector size
82 * d_dsflags disklabel management flags
83 */
84 u_int64_t d_media_size;
85 u_int64_t d_media_blocks;
86 int d_media_blksize;
87 u_int d_dsflags;
88
89 /*
90 * Optional fields, leave 0 if not known
91 */
92 u_int d_type; /* DTYPE_xxx */
93 u_int d_nheads;
94 u_int d_ncylinders;
95 u_int d_secpertrack;
96 u_int d_secpercyl;
e0fb398b 97 u_int d_trimflag;
55230951 98 char *d_serialno;
a688b15c
MD
99};
100
101/*
102 * d_dsflags, also used for dsopen() - control disklabel processing
7dc62e37
MD
103 *
104 * COMPATPARTA - used by scsi devices to allow CDs to boot from cd0a.
105 * cd's don't have disklabels and the default compat label
106 * does not implement an 'a' partition.
107 *
3af01d56 108 * COMPATMBR - used by the vn device to request that one sector be
7dc62e37 109 * reserved as if an MBR were present even when one isn't.
aec8eea4
MD
110 *
111 * MBRQUIET - silently ignore MBR probe if unable to read sector 0.
112 * used by VN.
3af01d56
AH
113 *
114 * DEVICEMAPPER - used by the device mapper (dm). Adds a '.' between the
115 * device name and the slice/part stuff (i.e. foo.s0).
c6bbf777
AH
116 *
117 * RAWPSIZE - use the dev_psize of the underlying raw device if the top
118 * psize fails.
a688b15c
MD
119 */
120#define DSO_NOLABELS 0x0001
121#define DSO_ONESLICE 0x0002
122#define DSO_COMPATLABEL 0x0004
123#define DSO_COMPATPARTA 0x0008
7dc62e37 124#define DSO_COMPATMBR 0x0010
8a88e0d0 125#define DSO_RAWEXTENSIONS 0x0020
aec8eea4 126#define DSO_MBRQUIET 0x0040
3af01d56 127#define DSO_DEVICEMAPPER 0x0080
c6bbf777 128#define DSO_RAWPSIZE 0x0100
a688b15c 129
0fe3034c
MD
130#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
131
a688b15c
MD
132/*
133 * Disk management structure - automated disklabel support.
134 */
984263bc 135struct disk {
fef8985e
MD
136 struct dev_ops *d_dev_ops; /* our device switch */
137 struct dev_ops *d_raw_ops; /* the raw device switch */
984263bc 138 u_int d_flags;
8d51c2a2 139 int d_opencount; /* The current open count */
b13267a5
MD
140 cdev_t d_rawdev; /* backing raw device */
141 cdev_t d_cdev; /* special whole-disk part */
984263bc 142 struct diskslices *d_slice;
a688b15c 143 struct disk_info d_info; /* info structure for media */
3573cf7b
MD
144 void *d_unused01;
145 void *d_unused02;
146 void *d_unused03;
f5d8307c 147 const char *d_disktype; /* Disk type information */
984263bc 148 LIST_ENTRY(disk) d_list;
185ace93 149 kdmsg_iocom_t d_iocom; /* cluster import/export */
5374d04f 150 int d_refs; /* interlock destruction */
984263bc
MD
151};
152
0fe3034c
MD
153#endif
154
a688b15c
MD
155/*
156 * d_flags
157 */
5374d04f
MD
158#define DISKFLAG_LOCK 0x0001
159#define DISKFLAG_WANTED 0x0002
160#define DISKFLAG_MARKER 0x0004
984263bc 161
d9f3f6fa 162#ifdef _KERNEL
a688b15c 163cdev_t disk_create (int unit, struct disk *disk, struct dev_ops *raw_ops);
4064300e 164cdev_t disk_create_clone (int unit, struct disk *disk, struct dev_ops *raw_ops);
c6ef65ea 165cdev_t disk_create_named(const char *name, int unit, struct disk *dp, struct dev_ops *raw_ops);
4064300e 166cdev_t disk_create_named_clone(const char *name, int unit, struct disk *dp, struct dev_ops *raw_ops);
a8873631 167cdev_t disk_locate (const char *devname);
b153f746 168void disk_destroy (struct disk *disk);
a688b15c 169void disk_setdiskinfo (struct disk *disk, struct disk_info *info);
f5d8307c 170int disk_setdisktype(struct disk *disk, const char *type);
8d51c2a2 171int disk_getopencount(struct disk *disk);
aec8eea4 172void disk_setdiskinfo_sync(struct disk *disk, struct disk_info *info);
e0fc5693 173int disk_dumpcheck (cdev_t dev, u_int64_t *count, u_int64_t *blkno, u_int *secsize);
b24cd69c 174int disk_dumpconf(cdev_t dev, u_int onoff);
5374d04f
MD
175struct disk *disk_enumerate (struct disk *marker, struct disk *dp);
176void disk_enumerate_stop (struct disk *marker, struct disk *dp);
b153f746 177void disk_invalidate (struct disk *disk);
aec8eea4 178void disk_unprobe(struct disk *disk);
cd29885a
MD
179
180void disk_msg_send(uint32_t cmd, void *load, void *load2);
aec8eea4 181void disk_msg_send_sync(uint32_t cmd, void *load, void *load2);
cd29885a
MD
182void disk_config(void *);
183
c6ef65ea
AH
184int bounds_check_with_mediasize(struct bio *bio, int secsize, uint64_t mediasize);
185
185ace93
MD
186void disk_iocom_init(struct disk *dp);
187void disk_iocom_update(struct disk *dp);
188void disk_iocom_uninit(struct disk *dp);
f4668135 189int disk_iocom_ioctl(struct disk *dp, u_long cmd, void *data);
185ace93 190void disk_clusterctl_wakeup(kdmsg_iocom_t *iocom);
185ace93 191
cd29885a
MD
192typedef struct disk_msg {
193 struct lwkt_msg hdr;
cd29885a
MD
194 void *load;
195 void *load2;
196} *disk_msg_t;
197
198#define DISK_DISK_PROBE 0x01
199#define DISK_DISK_DESTROY 0x02
200#define DISK_SLICE_REPROBE 0x03
201#define DISK_DISK_REPROBE 0x04
aec8eea4 202#define DISK_UNPROBE 0x05
185ace93 203#define DISK_SYNC 0x99
cd29885a
MD
204
205
d9f3f6fa 206#endif /* _KERNEL */
984263bc
MD
207
208#endif /* _SYS_DISK_H_ */