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