genhd: expose AN to user space
[deliverable/linux.git] / include / linux / genhd.h
1 #ifndef _LINUX_GENHD_H
2 #define _LINUX_GENHD_H
3
4 /*
5 * genhd.h Copyright (C) 1992 Drew Eckhardt
6 * Generic hard disk header file by
7 * Drew Eckhardt
8 *
9 * <drew@colorado.edu>
10 */
11
12 #include <linux/types.h>
13
14 #ifdef CONFIG_BLOCK
15
16 enum {
17 /* These three have identical behaviour; use the second one if DOS FDISK gets
18 confused about extended/logical partitions starting past cylinder 1023. */
19 DOS_EXTENDED_PARTITION = 5,
20 LINUX_EXTENDED_PARTITION = 0x85,
21 WIN98_EXTENDED_PARTITION = 0x0f,
22
23 SUN_WHOLE_DISK = DOS_EXTENDED_PARTITION,
24
25 LINUX_SWAP_PARTITION = 0x82,
26 LINUX_DATA_PARTITION = 0x83,
27 LINUX_LVM_PARTITION = 0x8e,
28 LINUX_RAID_PARTITION = 0xfd, /* autodetect RAID partition */
29
30 SOLARIS_X86_PARTITION = LINUX_SWAP_PARTITION,
31 NEW_SOLARIS_X86_PARTITION = 0xbf,
32
33 DM6_AUX1PARTITION = 0x51, /* no DDO: use xlated geom */
34 DM6_AUX3PARTITION = 0x53, /* no DDO: use xlated geom */
35 DM6_PARTITION = 0x54, /* has DDO: use xlated geom & offset */
36 EZD_PARTITION = 0x55, /* EZ-DRIVE */
37
38 FREEBSD_PARTITION = 0xa5, /* FreeBSD Partition ID */
39 OPENBSD_PARTITION = 0xa6, /* OpenBSD Partition ID */
40 NETBSD_PARTITION = 0xa9, /* NetBSD Partition ID */
41 BSDI_PARTITION = 0xb7, /* BSDI Partition ID */
42 MINIX_PARTITION = 0x81, /* Minix Partition ID */
43 UNIXWARE_PARTITION = 0x63, /* Same as GNU_HURD and SCO Unix */
44 };
45
46 #ifndef __KERNEL__
47
48 struct partition {
49 unsigned char boot_ind; /* 0x80 - active */
50 unsigned char head; /* starting head */
51 unsigned char sector; /* starting sector */
52 unsigned char cyl; /* starting cylinder */
53 unsigned char sys_ind; /* What partition type */
54 unsigned char end_head; /* end head */
55 unsigned char end_sector; /* end sector */
56 unsigned char end_cyl; /* end cylinder */
57 unsigned int start_sect; /* starting sector counting from 0 */
58 unsigned int nr_sects; /* nr of sectors in partition */
59 } __attribute__((packed));
60
61 #endif
62
63 #ifdef __KERNEL__
64 #include <linux/major.h>
65 #include <linux/device.h>
66 #include <linux/smp.h>
67 #include <linux/string.h>
68 #include <linux/fs.h>
69
70 struct partition {
71 unsigned char boot_ind; /* 0x80 - active */
72 unsigned char head; /* starting head */
73 unsigned char sector; /* starting sector */
74 unsigned char cyl; /* starting cylinder */
75 unsigned char sys_ind; /* What partition type */
76 unsigned char end_head; /* end head */
77 unsigned char end_sector; /* end sector */
78 unsigned char end_cyl; /* end cylinder */
79 __le32 start_sect; /* starting sector counting from 0 */
80 __le32 nr_sects; /* nr of sectors in partition */
81 } __attribute__((packed));
82
83 struct hd_struct {
84 sector_t start_sect;
85 sector_t nr_sects;
86 struct kobject kobj;
87 struct kobject *holder_dir;
88 unsigned ios[2], sectors[2]; /* READs and WRITEs */
89 int policy, partno;
90 #ifdef CONFIG_FAIL_MAKE_REQUEST
91 int make_it_fail;
92 #endif
93 };
94
95 #define GENHD_FL_REMOVABLE 1
96 #define GENHD_FL_DRIVERFS 2
97 #define GENHD_FL_MEDIA_CHANGE_NOTIFY 4
98 #define GENHD_FL_CD 8
99 #define GENHD_FL_UP 16
100 #define GENHD_FL_SUPPRESS_PARTITION_INFO 32
101 #define GENHD_FL_FAIL 64
102
103 struct disk_stats {
104 unsigned long sectors[2]; /* READs and WRITEs */
105 unsigned long ios[2];
106 unsigned long merges[2];
107 unsigned long ticks[2];
108 unsigned long io_ticks;
109 unsigned long time_in_queue;
110 };
111
112 struct gendisk {
113 int major; /* major number of driver */
114 int first_minor;
115 int minors; /* maximum number of minors, =1 for
116 * disks that can't be partitioned. */
117 char disk_name[32]; /* name of major driver */
118 struct hd_struct **part; /* [indexed by minor] */
119 int part_uevent_suppress;
120 struct block_device_operations *fops;
121 struct request_queue *queue;
122 void *private_data;
123 sector_t capacity;
124
125 int flags;
126 struct device *driverfs_dev;
127 struct kobject kobj;
128 struct kobject *holder_dir;
129 struct kobject *slave_dir;
130
131 struct timer_rand_state *random;
132 int policy;
133
134 atomic_t sync_io; /* RAID */
135 unsigned long stamp;
136 int in_flight;
137 #ifdef CONFIG_SMP
138 struct disk_stats *dkstats;
139 #else
140 struct disk_stats dkstats;
141 #endif
142 };
143
144 /* Structure for sysfs attributes on block devices */
145 struct disk_attribute {
146 struct attribute attr;
147 ssize_t (*show)(struct gendisk *, char *);
148 ssize_t (*store)(struct gendisk *, const char *, size_t);
149 };
150
151 /*
152 * Macros to operate on percpu disk statistics:
153 *
154 * The __ variants should only be called in critical sections. The full
155 * variants disable/enable preemption.
156 */
157 #ifdef CONFIG_SMP
158 #define __disk_stat_add(gendiskp, field, addnd) \
159 (per_cpu_ptr(gendiskp->dkstats, smp_processor_id())->field += addnd)
160
161 #define disk_stat_read(gendiskp, field) \
162 ({ \
163 typeof(gendiskp->dkstats->field) res = 0; \
164 int i; \
165 for_each_possible_cpu(i) \
166 res += per_cpu_ptr(gendiskp->dkstats, i)->field; \
167 res; \
168 })
169
170 static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) {
171 int i;
172 for_each_possible_cpu(i)
173 memset(per_cpu_ptr(gendiskp->dkstats, i), value,
174 sizeof (struct disk_stats));
175 }
176
177 #else
178 #define __disk_stat_add(gendiskp, field, addnd) \
179 (gendiskp->dkstats.field += addnd)
180 #define disk_stat_read(gendiskp, field) (gendiskp->dkstats.field)
181
182 static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) {
183 memset(&gendiskp->dkstats, value, sizeof (struct disk_stats));
184 }
185 #endif
186
187 #define disk_stat_add(gendiskp, field, addnd) \
188 do { \
189 preempt_disable(); \
190 __disk_stat_add(gendiskp, field, addnd); \
191 preempt_enable(); \
192 } while (0)
193
194 #define __disk_stat_dec(gendiskp, field) __disk_stat_add(gendiskp, field, -1)
195 #define disk_stat_dec(gendiskp, field) disk_stat_add(gendiskp, field, -1)
196
197 #define __disk_stat_inc(gendiskp, field) __disk_stat_add(gendiskp, field, 1)
198 #define disk_stat_inc(gendiskp, field) disk_stat_add(gendiskp, field, 1)
199
200 #define __disk_stat_sub(gendiskp, field, subnd) \
201 __disk_stat_add(gendiskp, field, -subnd)
202 #define disk_stat_sub(gendiskp, field, subnd) \
203 disk_stat_add(gendiskp, field, -subnd)
204
205
206 /* Inlines to alloc and free disk stats in struct gendisk */
207 #ifdef CONFIG_SMP
208 static inline int init_disk_stats(struct gendisk *disk)
209 {
210 disk->dkstats = alloc_percpu(struct disk_stats);
211 if (!disk->dkstats)
212 return 0;
213 return 1;
214 }
215
216 static inline void free_disk_stats(struct gendisk *disk)
217 {
218 free_percpu(disk->dkstats);
219 }
220 #else /* CONFIG_SMP */
221 static inline int init_disk_stats(struct gendisk *disk)
222 {
223 return 1;
224 }
225
226 static inline void free_disk_stats(struct gendisk *disk)
227 {
228 }
229 #endif /* CONFIG_SMP */
230
231 /* drivers/block/ll_rw_blk.c */
232 extern void disk_round_stats(struct gendisk *disk);
233
234 /* drivers/block/genhd.c */
235 extern int get_blkdev_list(char *, int);
236 extern void add_disk(struct gendisk *disk);
237 extern void del_gendisk(struct gendisk *gp);
238 extern void unlink_gendisk(struct gendisk *gp);
239 extern struct gendisk *get_gendisk(dev_t dev, int *part);
240
241 extern void set_device_ro(struct block_device *bdev, int flag);
242 extern void set_disk_ro(struct gendisk *disk, int flag);
243
244 /* drivers/char/random.c */
245 extern void add_disk_randomness(struct gendisk *disk);
246 extern void rand_initialize_disk(struct gendisk *disk);
247
248 static inline sector_t get_start_sect(struct block_device *bdev)
249 {
250 return bdev->bd_contains == bdev ? 0 : bdev->bd_part->start_sect;
251 }
252 static inline sector_t get_capacity(struct gendisk *disk)
253 {
254 return disk->capacity;
255 }
256 static inline void set_capacity(struct gendisk *disk, sector_t size)
257 {
258 disk->capacity = size;
259 }
260
261 #endif /* __KERNEL__ */
262
263 #ifdef CONFIG_SOLARIS_X86_PARTITION
264
265 #define SOLARIS_X86_NUMSLICE 8
266 #define SOLARIS_X86_VTOC_SANE (0x600DDEEEUL)
267
268 struct solaris_x86_slice {
269 __le16 s_tag; /* ID tag of partition */
270 __le16 s_flag; /* permission flags */
271 __le32 s_start; /* start sector no of partition */
272 __le32 s_size; /* # of blocks in partition */
273 };
274
275 struct solaris_x86_vtoc {
276 unsigned int v_bootinfo[3]; /* info needed by mboot (unsupported) */
277 __le32 v_sanity; /* to verify vtoc sanity */
278 __le32 v_version; /* layout version */
279 char v_volume[8]; /* volume name */
280 __le16 v_sectorsz; /* sector size in bytes */
281 __le16 v_nparts; /* number of partitions */
282 unsigned int v_reserved[10]; /* free space */
283 struct solaris_x86_slice
284 v_slice[SOLARIS_X86_NUMSLICE]; /* slice headers */
285 unsigned int timestamp[SOLARIS_X86_NUMSLICE]; /* timestamp (unsupported) */
286 char v_asciilabel[128]; /* for compatibility */
287 };
288
289 #endif /* CONFIG_SOLARIS_X86_PARTITION */
290
291 #ifdef CONFIG_BSD_DISKLABEL
292 /*
293 * BSD disklabel support by Yossi Gottlieb <yogo@math.tau.ac.il>
294 * updated by Marc Espie <Marc.Espie@openbsd.org>
295 */
296
297 /* check against BSD src/sys/sys/disklabel.h for consistency */
298
299 #define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */
300 #define BSD_MAXPARTITIONS 16
301 #define OPENBSD_MAXPARTITIONS 16
302 #define BSD_FS_UNUSED 0 /* disklabel unused partition entry ID */
303 struct bsd_disklabel {
304 __le32 d_magic; /* the magic number */
305 __s16 d_type; /* drive type */
306 __s16 d_subtype; /* controller/d_type specific */
307 char d_typename[16]; /* type name, e.g. "eagle" */
308 char d_packname[16]; /* pack identifier */
309 __u32 d_secsize; /* # of bytes per sector */
310 __u32 d_nsectors; /* # of data sectors per track */
311 __u32 d_ntracks; /* # of tracks per cylinder */
312 __u32 d_ncylinders; /* # of data cylinders per unit */
313 __u32 d_secpercyl; /* # of data sectors per cylinder */
314 __u32 d_secperunit; /* # of data sectors per unit */
315 __u16 d_sparespertrack; /* # of spare sectors per track */
316 __u16 d_sparespercyl; /* # of spare sectors per cylinder */
317 __u32 d_acylinders; /* # of alt. cylinders per unit */
318 __u16 d_rpm; /* rotational speed */
319 __u16 d_interleave; /* hardware sector interleave */
320 __u16 d_trackskew; /* sector 0 skew, per track */
321 __u16 d_cylskew; /* sector 0 skew, per cylinder */
322 __u32 d_headswitch; /* head switch time, usec */
323 __u32 d_trkseek; /* track-to-track seek, usec */
324 __u32 d_flags; /* generic flags */
325 #define NDDATA 5
326 __u32 d_drivedata[NDDATA]; /* drive-type specific information */
327 #define NSPARE 5
328 __u32 d_spare[NSPARE]; /* reserved for future use */
329 __le32 d_magic2; /* the magic number (again) */
330 __le16 d_checksum; /* xor of data incl. partitions */
331
332 /* filesystem and partition information: */
333 __le16 d_npartitions; /* number of partitions in following */
334 __le32 d_bbsize; /* size of boot area at sn0, bytes */
335 __le32 d_sbsize; /* max size of fs superblock, bytes */
336 struct bsd_partition { /* the partition table */
337 __le32 p_size; /* number of sectors in partition */
338 __le32 p_offset; /* starting sector */
339 __le32 p_fsize; /* filesystem basic fragment size */
340 __u8 p_fstype; /* filesystem type, see below */
341 __u8 p_frag; /* filesystem fragments per block */
342 __le16 p_cpg; /* filesystem cylinders per group */
343 } d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */
344 };
345
346 #endif /* CONFIG_BSD_DISKLABEL */
347
348 #ifdef CONFIG_UNIXWARE_DISKLABEL
349 /*
350 * Unixware slices support by Andrzej Krzysztofowicz <ankry@mif.pg.gda.pl>
351 * and Krzysztof G. Baranowski <kgb@knm.org.pl>
352 */
353
354 #define UNIXWARE_DISKMAGIC (0xCA5E600DUL) /* The disk magic number */
355 #define UNIXWARE_DISKMAGIC2 (0x600DDEEEUL) /* The slice table magic nr */
356 #define UNIXWARE_NUMSLICE 16
357 #define UNIXWARE_FS_UNUSED 0 /* Unused slice entry ID */
358
359 struct unixware_slice {
360 __le16 s_label; /* label */
361 __le16 s_flags; /* permission flags */
362 __le32 start_sect; /* starting sector */
363 __le32 nr_sects; /* number of sectors in slice */
364 };
365
366 struct unixware_disklabel {
367 __le32 d_type; /* drive type */
368 __le32 d_magic; /* the magic number */
369 __le32 d_version; /* version number */
370 char d_serial[12]; /* serial number of the device */
371 __le32 d_ncylinders; /* # of data cylinders per device */
372 __le32 d_ntracks; /* # of tracks per cylinder */
373 __le32 d_nsectors; /* # of data sectors per track */
374 __le32 d_secsize; /* # of bytes per sector */
375 __le32 d_part_start; /* # of first sector of this partition */
376 __le32 d_unknown1[12]; /* ? */
377 __le32 d_alt_tbl; /* byte offset of alternate table */
378 __le32 d_alt_len; /* byte length of alternate table */
379 __le32 d_phys_cyl; /* # of physical cylinders per device */
380 __le32 d_phys_trk; /* # of physical tracks per cylinder */
381 __le32 d_phys_sec; /* # of physical sectors per track */
382 __le32 d_phys_bytes; /* # of physical bytes per sector */
383 __le32 d_unknown2; /* ? */
384 __le32 d_unknown3; /* ? */
385 __le32 d_pad[8]; /* pad */
386
387 struct unixware_vtoc {
388 __le32 v_magic; /* the magic number */
389 __le32 v_version; /* version number */
390 char v_name[8]; /* volume name */
391 __le16 v_nslices; /* # of slices */
392 __le16 v_unknown1; /* ? */
393 __le32 v_reserved[10]; /* reserved */
394 struct unixware_slice
395 v_slice[UNIXWARE_NUMSLICE]; /* slice headers */
396 } vtoc;
397
398 }; /* 408 */
399
400 #endif /* CONFIG_UNIXWARE_DISKLABEL */
401
402 #ifdef CONFIG_MINIX_SUBPARTITION
403 # define MINIX_NR_SUBPARTITIONS 4
404 #endif /* CONFIG_MINIX_SUBPARTITION */
405
406 #ifdef __KERNEL__
407
408 #define ADDPART_FLAG_NONE 0
409 #define ADDPART_FLAG_RAID 1
410 #define ADDPART_FLAG_WHOLEDISK 2
411
412 char *disk_name (struct gendisk *hd, int part, char *buf);
413
414 extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
415 extern void add_partition(struct gendisk *, int, sector_t, sector_t, int);
416 extern void delete_partition(struct gendisk *, int);
417 extern void printk_all_partitions(void);
418
419 extern struct gendisk *alloc_disk_node(int minors, int node_id);
420 extern struct gendisk *alloc_disk(int minors);
421 extern struct kobject *get_disk(struct gendisk *disk);
422 extern void put_disk(struct gendisk *disk);
423
424 extern void blk_register_region(dev_t dev, unsigned long range,
425 struct module *module,
426 struct kobject *(*probe)(dev_t, int *, void *),
427 int (*lock)(dev_t, void *),
428 void *data);
429 extern void blk_unregister_region(dev_t dev, unsigned long range);
430
431 static inline struct block_device *bdget_disk(struct gendisk *disk, int index)
432 {
433 return bdget(MKDEV(disk->major, disk->first_minor) + index);
434 }
435
436 #endif
437
438 #else /* CONFIG_BLOCK */
439
440 static inline void printk_all_partitions(void) { }
441
442 #endif /* CONFIG_BLOCK */
443
444 #endif
This page took 0.039336 seconds and 6 git commands to generate.