initial commit with v2.6.9
[linux-2.6.9-moxart.git] / include / linux / genhd.h
blob749992dc71b7863b51fa4dba54f616fb25eef2c0
1 #ifndef _LINUX_GENHD_H
2 #define _LINUX_GENHD_H
4 /*
5 * genhd.h Copyright (C) 1992 Drew Eckhardt
6 * Generic hard disk header file by
7 * Drew Eckhardt
9 * <drew@colorado.edu>
12 #include <linux/config.h>
13 #include <linux/types.h>
14 #include <linux/major.h>
15 #include <linux/device.h>
16 #include <linux/smp.h>
17 #include <linux/string.h>
18 #include <linux/fs.h>
20 enum {
21 /* These three have identical behaviour; use the second one if DOS FDISK gets
22 confused about extended/logical partitions starting past cylinder 1023. */
23 DOS_EXTENDED_PARTITION = 5,
24 LINUX_EXTENDED_PARTITION = 0x85,
25 WIN98_EXTENDED_PARTITION = 0x0f,
27 LINUX_SWAP_PARTITION = 0x82,
28 LINUX_RAID_PARTITION = 0xfd, /* autodetect RAID partition */
30 SOLARIS_X86_PARTITION = LINUX_SWAP_PARTITION,
32 DM6_AUX1PARTITION = 0x51, /* no DDO: use xlated geom */
33 DM6_AUX3PARTITION = 0x53, /* no DDO: use xlated geom */
34 DM6_PARTITION = 0x54, /* has DDO: use xlated geom & offset */
35 EZD_PARTITION = 0x55, /* EZ-DRIVE */
37 FREEBSD_PARTITION = 0xa5, /* FreeBSD Partition ID */
38 OPENBSD_PARTITION = 0xa6, /* OpenBSD Partition ID */
39 NETBSD_PARTITION = 0xa9, /* NetBSD Partition ID */
40 BSDI_PARTITION = 0xb7, /* BSDI Partition ID */
41 MINIX_PARTITION = 0x81, /* Minix Partition ID */
42 UNIXWARE_PARTITION = 0x63, /* Same as GNU_HURD and SCO Unix */
45 #ifndef __KERNEL__
47 struct partition {
48 unsigned char boot_ind; /* 0x80 - active */
49 unsigned char head; /* starting head */
50 unsigned char sector; /* starting sector */
51 unsigned char cyl; /* starting cylinder */
52 unsigned char sys_ind; /* What partition type */
53 unsigned char end_head; /* end head */
54 unsigned char end_sector; /* end sector */
55 unsigned char end_cyl; /* end cylinder */
56 unsigned int start_sect; /* starting sector counting from 0 */
57 unsigned int nr_sects; /* nr of sectors in partition */
58 } __attribute__((packed));
60 #endif
62 #ifdef __KERNEL__
63 struct partition {
64 unsigned char boot_ind; /* 0x80 - active */
65 unsigned char head; /* starting head */
66 unsigned char sector; /* starting sector */
67 unsigned char cyl; /* starting cylinder */
68 unsigned char sys_ind; /* What partition type */
69 unsigned char end_head; /* end head */
70 unsigned char end_sector; /* end sector */
71 unsigned char end_cyl; /* end cylinder */
72 __le32 start_sect; /* starting sector counting from 0 */
73 __le32 nr_sects; /* nr of sectors in partition */
74 } __attribute__((packed));
76 struct hd_struct {
77 sector_t start_sect;
78 sector_t nr_sects;
79 struct kobject kobj;
80 unsigned reads, read_sectors, writes, write_sectors;
81 int policy, partno;
84 #define GENHD_FL_REMOVABLE 1
85 #define GENHD_FL_DRIVERFS 2
86 #define GENHD_FL_CD 8
87 #define GENHD_FL_UP 16
88 #define GENHD_FL_SUPPRESS_PARTITION_INFO 32
90 struct disk_stats {
91 unsigned read_sectors, write_sectors;
92 unsigned reads, writes;
93 unsigned read_merges, write_merges;
94 unsigned read_ticks, write_ticks;
95 unsigned io_ticks;
96 unsigned time_in_queue;
99 struct gendisk {
100 int major; /* major number of driver */
101 int first_minor;
102 int minors; /* maximum number of minors, =1 for
103 * disks that can't be partitioned. */
104 char disk_name[32]; /* name of major driver */
105 struct hd_struct **part; /* [indexed by minor] */
106 struct block_device_operations *fops;
107 struct request_queue *queue;
108 void *private_data;
109 sector_t capacity;
111 int flags;
112 char devfs_name[64]; /* devfs crap */
113 int number; /* more of the same */
114 struct device *driverfs_dev;
115 struct kobject kobj;
117 struct timer_rand_state *random;
118 int policy;
120 atomic_t sync_io; /* RAID */
121 unsigned long stamp, stamp_idle;
122 int in_flight;
123 #ifdef CONFIG_SMP
124 struct disk_stats *dkstats;
125 #else
126 struct disk_stats dkstats;
127 #endif
131 * Macros to operate on percpu disk statistics:
132 * Since writes to disk_stats are serialised through the queue_lock,
133 * smp_processor_id() should be enough to get to the per_cpu versions
134 * of statistics counters
136 #ifdef CONFIG_SMP
137 #define disk_stat_add(gendiskp, field, addnd) \
138 (per_cpu_ptr(gendiskp->dkstats, smp_processor_id())->field += addnd)
139 #define disk_stat_read(gendiskp, field) \
140 ({ \
141 typeof(gendiskp->dkstats->field) res = 0; \
142 int i; \
143 for (i=0; i < NR_CPUS; i++) { \
144 if (!cpu_possible(i)) \
145 continue; \
146 res += per_cpu_ptr(gendiskp->dkstats, i)->field; \
148 res; \
151 static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) {
152 int i;
153 for (i=0; i < NR_CPUS; i++) {
154 if (cpu_possible(i)) {
155 memset(per_cpu_ptr(gendiskp->dkstats, i), value,
156 sizeof (struct disk_stats));
161 #else
162 #define disk_stat_add(gendiskp, field, addnd) (gendiskp->dkstats.field += addnd)
163 #define disk_stat_read(gendiskp, field) (gendiskp->dkstats.field)
165 static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) {
166 memset(&gendiskp->dkstats, value, sizeof (struct disk_stats));
168 #endif
170 #define disk_stat_inc(gendiskp, field) disk_stat_add(gendiskp, field, 1)
171 #define disk_stat_dec(gendiskp, field) disk_stat_add(gendiskp, field, -1)
172 #define disk_stat_sub(gendiskp, field, subnd) \
173 disk_stat_add(gendiskp, field, -subnd)
176 /* Inlines to alloc and free disk stats in struct gendisk */
177 #ifdef CONFIG_SMP
178 static inline int init_disk_stats(struct gendisk *disk)
180 disk->dkstats = alloc_percpu(struct disk_stats);
181 if (!disk->dkstats)
182 return 0;
183 return 1;
186 static inline void free_disk_stats(struct gendisk *disk)
188 free_percpu(disk->dkstats);
190 #else /* CONFIG_SMP */
191 static inline int init_disk_stats(struct gendisk *disk)
193 return 1;
196 static inline void free_disk_stats(struct gendisk *disk)
199 #endif /* CONFIG_SMP */
201 /* drivers/block/ll_rw_blk.c */
202 extern void disk_round_stats(struct gendisk *disk);
204 /* drivers/block/genhd.c */
205 extern void add_disk(struct gendisk *disk);
206 extern void del_gendisk(struct gendisk *gp);
207 extern void unlink_gendisk(struct gendisk *gp);
208 extern struct gendisk *get_gendisk(dev_t dev, int *part);
210 extern void set_device_ro(struct block_device *bdev, int flag);
211 extern void set_disk_ro(struct gendisk *disk, int flag);
213 /* drivers/char/random.c */
214 extern void add_disk_randomness(struct gendisk *disk);
215 extern void rand_initialize_disk(struct gendisk *disk);
217 static inline sector_t get_start_sect(struct block_device *bdev)
219 return bdev->bd_contains == bdev ? 0 : bdev->bd_part->start_sect;
221 static inline sector_t get_capacity(struct gendisk *disk)
223 return disk->capacity;
225 static inline void set_capacity(struct gendisk *disk, sector_t size)
227 disk->capacity = size;
230 #endif /* __KERNEL__ */
232 #ifdef CONFIG_SOLARIS_X86_PARTITION
234 #define SOLARIS_X86_NUMSLICE 8
235 #define SOLARIS_X86_VTOC_SANE (0x600DDEEEUL)
237 struct solaris_x86_slice {
238 __le16 s_tag; /* ID tag of partition */
239 __le16 s_flag; /* permission flags */
240 __le32 s_start; /* start sector no of partition */
241 __le32 s_size; /* # of blocks in partition */
244 struct solaris_x86_vtoc {
245 unsigned int v_bootinfo[3]; /* info needed by mboot (unsupported) */
246 __le32 v_sanity; /* to verify vtoc sanity */
247 __le32 v_version; /* layout version */
248 char v_volume[8]; /* volume name */
249 __le16 v_sectorsz; /* sector size in bytes */
250 __le16 v_nparts; /* number of partitions */
251 unsigned int v_reserved[10]; /* free space */
252 struct solaris_x86_slice
253 v_slice[SOLARIS_X86_NUMSLICE]; /* slice headers */
254 unsigned int timestamp[SOLARIS_X86_NUMSLICE]; /* timestamp (unsupported) */
255 char v_asciilabel[128]; /* for compatibility */
258 #endif /* CONFIG_SOLARIS_X86_PARTITION */
260 #ifdef CONFIG_BSD_DISKLABEL
262 * BSD disklabel support by Yossi Gottlieb <yogo@math.tau.ac.il>
263 * updated by Marc Espie <Marc.Espie@openbsd.org>
266 /* check against BSD src/sys/sys/disklabel.h for consistency */
268 #define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */
269 #define BSD_MAXPARTITIONS 16
270 #define OPENBSD_MAXPARTITIONS 16
271 #define BSD_FS_UNUSED 0 /* disklabel unused partition entry ID */
272 struct bsd_disklabel {
273 __le32 d_magic; /* the magic number */
274 __s16 d_type; /* drive type */
275 __s16 d_subtype; /* controller/d_type specific */
276 char d_typename[16]; /* type name, e.g. "eagle" */
277 char d_packname[16]; /* pack identifier */
278 __u32 d_secsize; /* # of bytes per sector */
279 __u32 d_nsectors; /* # of data sectors per track */
280 __u32 d_ntracks; /* # of tracks per cylinder */
281 __u32 d_ncylinders; /* # of data cylinders per unit */
282 __u32 d_secpercyl; /* # of data sectors per cylinder */
283 __u32 d_secperunit; /* # of data sectors per unit */
284 __u16 d_sparespertrack; /* # of spare sectors per track */
285 __u16 d_sparespercyl; /* # of spare sectors per cylinder */
286 __u32 d_acylinders; /* # of alt. cylinders per unit */
287 __u16 d_rpm; /* rotational speed */
288 __u16 d_interleave; /* hardware sector interleave */
289 __u16 d_trackskew; /* sector 0 skew, per track */
290 __u16 d_cylskew; /* sector 0 skew, per cylinder */
291 __u32 d_headswitch; /* head switch time, usec */
292 __u32 d_trkseek; /* track-to-track seek, usec */
293 __u32 d_flags; /* generic flags */
294 #define NDDATA 5
295 __u32 d_drivedata[NDDATA]; /* drive-type specific information */
296 #define NSPARE 5
297 __u32 d_spare[NSPARE]; /* reserved for future use */
298 __le32 d_magic2; /* the magic number (again) */
299 __le16 d_checksum; /* xor of data incl. partitions */
301 /* filesystem and partition information: */
302 __le16 d_npartitions; /* number of partitions in following */
303 __le32 d_bbsize; /* size of boot area at sn0, bytes */
304 __le32 d_sbsize; /* max size of fs superblock, bytes */
305 struct bsd_partition { /* the partition table */
306 __le32 p_size; /* number of sectors in partition */
307 __le32 p_offset; /* starting sector */
308 __le32 p_fsize; /* filesystem basic fragment size */
309 __u8 p_fstype; /* filesystem type, see below */
310 __u8 p_frag; /* filesystem fragments per block */
311 __le16 p_cpg; /* filesystem cylinders per group */
312 } d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */
315 #endif /* CONFIG_BSD_DISKLABEL */
317 #ifdef CONFIG_UNIXWARE_DISKLABEL
319 * Unixware slices support by Andrzej Krzysztofowicz <ankry@mif.pg.gda.pl>
320 * and Krzysztof G. Baranowski <kgb@knm.org.pl>
323 #define UNIXWARE_DISKMAGIC (0xCA5E600DUL) /* The disk magic number */
324 #define UNIXWARE_DISKMAGIC2 (0x600DDEEEUL) /* The slice table magic nr */
325 #define UNIXWARE_NUMSLICE 16
326 #define UNIXWARE_FS_UNUSED 0 /* Unused slice entry ID */
328 struct unixware_slice {
329 __le16 s_label; /* label */
330 __le16 s_flags; /* permission flags */
331 __le32 start_sect; /* starting sector */
332 __le32 nr_sects; /* number of sectors in slice */
335 struct unixware_disklabel {
336 __le32 d_type; /* drive type */
337 __le32 d_magic; /* the magic number */
338 __le32 d_version; /* version number */
339 char d_serial[12]; /* serial number of the device */
340 __le32 d_ncylinders; /* # of data cylinders per device */
341 __le32 d_ntracks; /* # of tracks per cylinder */
342 __le32 d_nsectors; /* # of data sectors per track */
343 __le32 d_secsize; /* # of bytes per sector */
344 __le32 d_part_start; /* # of first sector of this partition */
345 __le32 d_unknown1[12]; /* ? */
346 __le32 d_alt_tbl; /* byte offset of alternate table */
347 __le32 d_alt_len; /* byte length of alternate table */
348 __le32 d_phys_cyl; /* # of physical cylinders per device */
349 __le32 d_phys_trk; /* # of physical tracks per cylinder */
350 __le32 d_phys_sec; /* # of physical sectors per track */
351 __le32 d_phys_bytes; /* # of physical bytes per sector */
352 __le32 d_unknown2; /* ? */
353 __le32 d_unknown3; /* ? */
354 __le32 d_pad[8]; /* pad */
356 struct unixware_vtoc {
357 __le32 v_magic; /* the magic number */
358 __le32 v_version; /* version number */
359 char v_name[8]; /* volume name */
360 __le16 v_nslices; /* # of slices */
361 __le16 v_unknown1; /* ? */
362 __le32 v_reserved[10]; /* reserved */
363 struct unixware_slice
364 v_slice[UNIXWARE_NUMSLICE]; /* slice headers */
365 } vtoc;
367 }; /* 408 */
369 #endif /* CONFIG_UNIXWARE_DISKLABEL */
371 #ifdef CONFIG_MINIX_SUBPARTITION
372 # define MINIX_NR_SUBPARTITIONS 4
373 #endif /* CONFIG_MINIX_SUBPARTITION */
375 #ifdef __KERNEL__
377 char *disk_name (struct gendisk *hd, int part, char *buf);
379 extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
380 extern void add_partition(struct gendisk *, int, sector_t, sector_t);
381 extern void delete_partition(struct gendisk *, int);
383 extern struct gendisk *alloc_disk(int minors);
384 extern struct kobject *get_disk(struct gendisk *disk);
385 extern void put_disk(struct gendisk *disk);
387 extern void blk_register_region(dev_t dev, unsigned long range,
388 struct module *module,
389 struct kobject *(*probe)(dev_t, int *, void *),
390 int (*lock)(dev_t, void *),
391 void *data);
392 extern void blk_unregister_region(dev_t dev, unsigned long range);
394 static inline struct block_device *bdget_disk(struct gendisk *disk, int index)
396 return bdget(MKDEV(disk->major, disk->first_minor) + index);
399 #endif
401 #endif