blob: a47b8025d39935c18a66db9cc975a58fe8f85dda [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
David Howells93614012006-09-30 20:45:40 +020014#ifdef CONFIG_BLOCK
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016enum {
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
Fabio Massimo Di Nittod18d7682007-02-10 23:50:00 -080023 SUN_WHOLE_DISK = DOS_EXTENDED_PARTITION,
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 LINUX_SWAP_PARTITION = 0x82,
Olaf Hering4419d1a2007-02-10 01:45:47 -080026 LINUX_DATA_PARTITION = 0x83,
27 LINUX_LVM_PARTITION = 0x8e,
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 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
48struct 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__
David Woodhouse34186ef2006-04-25 14:07:57 +010064#include <linux/major.h>
65#include <linux/device.h>
66#include <linux/smp.h>
67#include <linux/string.h>
68#include <linux/fs.h>
Kristen Carlson Accardi8ce7ad72007-05-23 13:57:38 -070069#include <linux/workqueue.h>
David Woodhouse34186ef2006-04-25 14:07:57 +010070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071struct partition {
72 unsigned char boot_ind; /* 0x80 - active */
73 unsigned char head; /* starting head */
74 unsigned char sector; /* starting sector */
75 unsigned char cyl; /* starting cylinder */
76 unsigned char sys_ind; /* What partition type */
77 unsigned char end_head; /* end head */
78 unsigned char end_sector; /* end sector */
79 unsigned char end_cyl; /* end cylinder */
80 __le32 start_sect; /* starting sector counting from 0 */
81 __le32 nr_sects; /* nr of sectors in partition */
82} __attribute__((packed));
83
84struct hd_struct {
85 sector_t start_sect;
86 sector_t nr_sects;
87 struct kobject kobj;
Jun'ichi Nomura6a4d44c2006-03-27 01:17:55 -080088 struct kobject *holder_dir;
Jens Axboe47a00412005-11-09 13:38:47 +010089 unsigned ios[2], sectors[2]; /* READs and WRITEs */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 int policy, partno;
Akinobu Mitac17bb492006-12-08 02:39:46 -080091#ifdef CONFIG_FAIL_MAKE_REQUEST
92 int make_it_fail;
93#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070094};
95
96#define GENHD_FL_REMOVABLE 1
97#define GENHD_FL_DRIVERFS 2
Kristen Carlson Accardi86ce18d2007-05-23 13:57:38 -070098#define GENHD_FL_MEDIA_CHANGE_NOTIFY 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#define GENHD_FL_CD 8
100#define GENHD_FL_UP 16
101#define GENHD_FL_SUPPRESS_PARTITION_INFO 32
Akinobu Mitac17bb492006-12-08 02:39:46 -0800102#define GENHD_FL_FAIL 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104struct disk_stats {
Ben Woodard837c7872006-03-22 08:09:31 +0100105 unsigned long sectors[2]; /* READs and WRITEs */
106 unsigned long ios[2];
107 unsigned long merges[2];
108 unsigned long ticks[2];
109 unsigned long io_ticks;
110 unsigned long time_in_queue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111};
112
113struct gendisk {
114 int major; /* major number of driver */
115 int first_minor;
116 int minors; /* maximum number of minors, =1 for
117 * disks that can't be partitioned. */
118 char disk_name[32]; /* name of major driver */
119 struct hd_struct **part; /* [indexed by minor] */
Kay Sieversd4d7e5d2006-03-24 20:45:35 +0100120 int part_uevent_suppress;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 struct block_device_operations *fops;
122 struct request_queue *queue;
123 void *private_data;
124 sector_t capacity;
125
126 int flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 struct device *driverfs_dev;
128 struct kobject kobj;
Jun'ichi Nomura6a4d44c2006-03-27 01:17:55 -0800129 struct kobject *holder_dir;
130 struct kobject *slave_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 struct timer_rand_state *random;
133 int policy;
134
135 atomic_t sync_io; /* RAID */
Chen, Kenneth W20e5c812005-10-13 21:48:42 +0200136 unsigned long stamp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 int in_flight;
138#ifdef CONFIG_SMP
139 struct disk_stats *dkstats;
140#else
141 struct disk_stats dkstats;
142#endif
Kristen Carlson Accardi8ce7ad72007-05-23 13:57:38 -0700143 struct work_struct async_notify;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144};
145
146/* Structure for sysfs attributes on block devices */
147struct disk_attribute {
148 struct attribute attr;
149 ssize_t (*show)(struct gendisk *, char *);
Kay Sieversa7fd6702005-10-01 14:49:43 +0200150 ssize_t (*store)(struct gendisk *, const char *, size_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151};
152
153/*
154 * Macros to operate on percpu disk statistics:
155 *
156 * The __ variants should only be called in critical sections. The full
157 * variants disable/enable preemption.
158 */
159#ifdef CONFIG_SMP
160#define __disk_stat_add(gendiskp, field, addnd) \
161 (per_cpu_ptr(gendiskp->dkstats, smp_processor_id())->field += addnd)
162
163#define disk_stat_read(gendiskp, field) \
164({ \
165 typeof(gendiskp->dkstats->field) res = 0; \
166 int i; \
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -0800167 for_each_possible_cpu(i) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 res += per_cpu_ptr(gendiskp->dkstats, i)->field; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 res; \
170})
171
172static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) {
173 int i;
KAMEZAWA Hiroyuki0a945022006-03-28 01:56:37 -0800174 for_each_possible_cpu(i)
Andrew Morton394e3902006-03-23 03:01:05 -0800175 memset(per_cpu_ptr(gendiskp->dkstats, i), value,
176 sizeof (struct disk_stats));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}
178
179#else
180#define __disk_stat_add(gendiskp, field, addnd) \
181 (gendiskp->dkstats.field += addnd)
182#define disk_stat_read(gendiskp, field) (gendiskp->dkstats.field)
183
184static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) {
185 memset(&gendiskp->dkstats, value, sizeof (struct disk_stats));
186}
187#endif
188
189#define disk_stat_add(gendiskp, field, addnd) \
190 do { \
191 preempt_disable(); \
192 __disk_stat_add(gendiskp, field, addnd); \
193 preempt_enable(); \
194 } while (0)
195
196#define __disk_stat_dec(gendiskp, field) __disk_stat_add(gendiskp, field, -1)
197#define disk_stat_dec(gendiskp, field) disk_stat_add(gendiskp, field, -1)
198
199#define __disk_stat_inc(gendiskp, field) __disk_stat_add(gendiskp, field, 1)
200#define disk_stat_inc(gendiskp, field) disk_stat_add(gendiskp, field, 1)
201
202#define __disk_stat_sub(gendiskp, field, subnd) \
203 __disk_stat_add(gendiskp, field, -subnd)
204#define disk_stat_sub(gendiskp, field, subnd) \
205 disk_stat_add(gendiskp, field, -subnd)
206
207
208/* Inlines to alloc and free disk stats in struct gendisk */
209#ifdef CONFIG_SMP
210static inline int init_disk_stats(struct gendisk *disk)
211{
212 disk->dkstats = alloc_percpu(struct disk_stats);
213 if (!disk->dkstats)
214 return 0;
215 return 1;
216}
217
218static inline void free_disk_stats(struct gendisk *disk)
219{
220 free_percpu(disk->dkstats);
221}
222#else /* CONFIG_SMP */
223static inline int init_disk_stats(struct gendisk *disk)
224{
225 return 1;
226}
227
228static inline void free_disk_stats(struct gendisk *disk)
229{
230}
231#endif /* CONFIG_SMP */
232
233/* drivers/block/ll_rw_blk.c */
234extern void disk_round_stats(struct gendisk *disk);
235
236/* drivers/block/genhd.c */
Neil Hormanac204272005-06-23 00:09:11 -0700237extern int get_blkdev_list(char *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238extern void add_disk(struct gendisk *disk);
239extern void del_gendisk(struct gendisk *gp);
240extern void unlink_gendisk(struct gendisk *gp);
241extern struct gendisk *get_gendisk(dev_t dev, int *part);
242
243extern void set_device_ro(struct block_device *bdev, int flag);
244extern void set_disk_ro(struct gendisk *disk, int flag);
245
246/* drivers/char/random.c */
247extern void add_disk_randomness(struct gendisk *disk);
248extern void rand_initialize_disk(struct gendisk *disk);
249
250static inline sector_t get_start_sect(struct block_device *bdev)
251{
252 return bdev->bd_contains == bdev ? 0 : bdev->bd_part->start_sect;
253}
254static inline sector_t get_capacity(struct gendisk *disk)
255{
256 return disk->capacity;
257}
258static inline void set_capacity(struct gendisk *disk, sector_t size)
259{
260 disk->capacity = size;
261}
262
263#endif /* __KERNEL__ */
264
265#ifdef CONFIG_SOLARIS_X86_PARTITION
266
Mark Fortescueb84d8792007-07-25 18:30:08 -0700267#define SOLARIS_X86_NUMSLICE 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268#define SOLARIS_X86_VTOC_SANE (0x600DDEEEUL)
269
270struct solaris_x86_slice {
271 __le16 s_tag; /* ID tag of partition */
272 __le16 s_flag; /* permission flags */
273 __le32 s_start; /* start sector no of partition */
274 __le32 s_size; /* # of blocks in partition */
275};
276
277struct solaris_x86_vtoc {
278 unsigned int v_bootinfo[3]; /* info needed by mboot (unsupported) */
279 __le32 v_sanity; /* to verify vtoc sanity */
280 __le32 v_version; /* layout version */
281 char v_volume[8]; /* volume name */
282 __le16 v_sectorsz; /* sector size in bytes */
283 __le16 v_nparts; /* number of partitions */
284 unsigned int v_reserved[10]; /* free space */
285 struct solaris_x86_slice
286 v_slice[SOLARIS_X86_NUMSLICE]; /* slice headers */
287 unsigned int timestamp[SOLARIS_X86_NUMSLICE]; /* timestamp (unsupported) */
288 char v_asciilabel[128]; /* for compatibility */
289};
290
291#endif /* CONFIG_SOLARIS_X86_PARTITION */
292
293#ifdef CONFIG_BSD_DISKLABEL
294/*
295 * BSD disklabel support by Yossi Gottlieb <yogo@math.tau.ac.il>
296 * updated by Marc Espie <Marc.Espie@openbsd.org>
297 */
298
299/* check against BSD src/sys/sys/disklabel.h for consistency */
300
301#define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */
302#define BSD_MAXPARTITIONS 16
303#define OPENBSD_MAXPARTITIONS 16
304#define BSD_FS_UNUSED 0 /* disklabel unused partition entry ID */
305struct bsd_disklabel {
306 __le32 d_magic; /* the magic number */
307 __s16 d_type; /* drive type */
308 __s16 d_subtype; /* controller/d_type specific */
309 char d_typename[16]; /* type name, e.g. "eagle" */
310 char d_packname[16]; /* pack identifier */
311 __u32 d_secsize; /* # of bytes per sector */
312 __u32 d_nsectors; /* # of data sectors per track */
313 __u32 d_ntracks; /* # of tracks per cylinder */
314 __u32 d_ncylinders; /* # of data cylinders per unit */
315 __u32 d_secpercyl; /* # of data sectors per cylinder */
316 __u32 d_secperunit; /* # of data sectors per unit */
317 __u16 d_sparespertrack; /* # of spare sectors per track */
318 __u16 d_sparespercyl; /* # of spare sectors per cylinder */
319 __u32 d_acylinders; /* # of alt. cylinders per unit */
320 __u16 d_rpm; /* rotational speed */
321 __u16 d_interleave; /* hardware sector interleave */
322 __u16 d_trackskew; /* sector 0 skew, per track */
323 __u16 d_cylskew; /* sector 0 skew, per cylinder */
324 __u32 d_headswitch; /* head switch time, usec */
325 __u32 d_trkseek; /* track-to-track seek, usec */
326 __u32 d_flags; /* generic flags */
327#define NDDATA 5
328 __u32 d_drivedata[NDDATA]; /* drive-type specific information */
329#define NSPARE 5
330 __u32 d_spare[NSPARE]; /* reserved for future use */
331 __le32 d_magic2; /* the magic number (again) */
332 __le16 d_checksum; /* xor of data incl. partitions */
333
334 /* filesystem and partition information: */
335 __le16 d_npartitions; /* number of partitions in following */
336 __le32 d_bbsize; /* size of boot area at sn0, bytes */
337 __le32 d_sbsize; /* max size of fs superblock, bytes */
338 struct bsd_partition { /* the partition table */
339 __le32 p_size; /* number of sectors in partition */
340 __le32 p_offset; /* starting sector */
341 __le32 p_fsize; /* filesystem basic fragment size */
342 __u8 p_fstype; /* filesystem type, see below */
343 __u8 p_frag; /* filesystem fragments per block */
344 __le16 p_cpg; /* filesystem cylinders per group */
345 } d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */
346};
347
348#endif /* CONFIG_BSD_DISKLABEL */
349
350#ifdef CONFIG_UNIXWARE_DISKLABEL
351/*
352 * Unixware slices support by Andrzej Krzysztofowicz <ankry@mif.pg.gda.pl>
353 * and Krzysztof G. Baranowski <kgb@knm.org.pl>
354 */
355
356#define UNIXWARE_DISKMAGIC (0xCA5E600DUL) /* The disk magic number */
357#define UNIXWARE_DISKMAGIC2 (0x600DDEEEUL) /* The slice table magic nr */
358#define UNIXWARE_NUMSLICE 16
359#define UNIXWARE_FS_UNUSED 0 /* Unused slice entry ID */
360
361struct unixware_slice {
362 __le16 s_label; /* label */
363 __le16 s_flags; /* permission flags */
364 __le32 start_sect; /* starting sector */
365 __le32 nr_sects; /* number of sectors in slice */
366};
367
368struct unixware_disklabel {
369 __le32 d_type; /* drive type */
370 __le32 d_magic; /* the magic number */
371 __le32 d_version; /* version number */
372 char d_serial[12]; /* serial number of the device */
373 __le32 d_ncylinders; /* # of data cylinders per device */
374 __le32 d_ntracks; /* # of tracks per cylinder */
375 __le32 d_nsectors; /* # of data sectors per track */
376 __le32 d_secsize; /* # of bytes per sector */
377 __le32 d_part_start; /* # of first sector of this partition */
378 __le32 d_unknown1[12]; /* ? */
379 __le32 d_alt_tbl; /* byte offset of alternate table */
380 __le32 d_alt_len; /* byte length of alternate table */
381 __le32 d_phys_cyl; /* # of physical cylinders per device */
382 __le32 d_phys_trk; /* # of physical tracks per cylinder */
383 __le32 d_phys_sec; /* # of physical sectors per track */
384 __le32 d_phys_bytes; /* # of physical bytes per sector */
385 __le32 d_unknown2; /* ? */
386 __le32 d_unknown3; /* ? */
387 __le32 d_pad[8]; /* pad */
388
389 struct unixware_vtoc {
390 __le32 v_magic; /* the magic number */
391 __le32 v_version; /* version number */
392 char v_name[8]; /* volume name */
393 __le16 v_nslices; /* # of slices */
394 __le16 v_unknown1; /* ? */
395 __le32 v_reserved[10]; /* reserved */
396 struct unixware_slice
397 v_slice[UNIXWARE_NUMSLICE]; /* slice headers */
398 } vtoc;
399
400}; /* 408 */
401
402#endif /* CONFIG_UNIXWARE_DISKLABEL */
403
404#ifdef CONFIG_MINIX_SUBPARTITION
405# define MINIX_NR_SUBPARTITIONS 4
406#endif /* CONFIG_MINIX_SUBPARTITION */
407
408#ifdef __KERNEL__
409
Fabio Massimo Di Nittod18d7682007-02-10 23:50:00 -0800410#define ADDPART_FLAG_NONE 0
411#define ADDPART_FLAG_RAID 1
412#define ADDPART_FLAG_WHOLEDISK 2
413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414char *disk_name (struct gendisk *hd, int part, char *buf);
415
416extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
Fabio Massimo Di Nittod18d7682007-02-10 23:50:00 -0800417extern void add_partition(struct gendisk *, int, sector_t, sector_t, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418extern void delete_partition(struct gendisk *, int);
Dave Gilbertdd2a3452007-05-09 02:33:24 -0700419extern void printk_all_partitions(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Christoph Lameter19460892005-06-23 00:08:19 -0700421extern struct gendisk *alloc_disk_node(int minors, int node_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422extern struct gendisk *alloc_disk(int minors);
423extern struct kobject *get_disk(struct gendisk *disk);
424extern void put_disk(struct gendisk *disk);
Kristen Carlson Accardi8ce7ad72007-05-23 13:57:38 -0700425extern void genhd_media_change_notify(struct gendisk *disk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426extern void blk_register_region(dev_t dev, unsigned long range,
427 struct module *module,
428 struct kobject *(*probe)(dev_t, int *, void *),
429 int (*lock)(dev_t, void *),
430 void *data);
431extern void blk_unregister_region(dev_t dev, unsigned long range);
432
433static inline struct block_device *bdget_disk(struct gendisk *disk, int index)
434{
435 return bdget(MKDEV(disk->major, disk->first_minor) + index);
436}
437
438#endif
439
Jens Axboe87c1efb2007-05-11 13:29:54 +0200440#else /* CONFIG_BLOCK */
441
442static inline void printk_all_partitions(void) { }
443
444#endif /* CONFIG_BLOCK */
David Howells93614012006-09-30 20:45:40 +0200445
446#endif