[PATCH] acpiphp: Scan slots under the nested P2P bridge
[linux-2.6/cjktty.git] / include / linux / genhd.h
blobfd647fde5ec18f0aba4124346fd4363d97fe4569
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,
31 NEW_SOLARIS_X86_PARTITION = 0xbf,
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 */
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 */
46 #ifndef __KERNEL__
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));
61 #endif
63 #ifdef __KERNEL__
64 struct partition {
65 unsigned char boot_ind; /* 0x80 - active */
66 unsigned char head; /* starting head */
67 unsigned char sector; /* starting sector */
68 unsigned char cyl; /* starting cylinder */
69 unsigned char sys_ind; /* What partition type */
70 unsigned char end_head; /* end head */
71 unsigned char end_sector; /* end sector */
72 unsigned char end_cyl; /* end cylinder */
73 __le32 start_sect; /* starting sector counting from 0 */
74 __le32 nr_sects; /* nr of sectors in partition */
75 } __attribute__((packed));
77 struct hd_struct {
78 sector_t start_sect;
79 sector_t nr_sects;
80 struct kobject kobj;
81 unsigned ios[2], sectors[2]; /* READs and WRITEs */
82 int policy, partno;
85 #define GENHD_FL_REMOVABLE 1
86 #define GENHD_FL_DRIVERFS 2
87 #define GENHD_FL_CD 8
88 #define GENHD_FL_UP 16
89 #define GENHD_FL_SUPPRESS_PARTITION_INFO 32
91 struct disk_stats {
92 unsigned sectors[2]; /* READs and WRITEs */
93 unsigned ios[2];
94 unsigned merges[2];
95 unsigned ticks[2];
96 unsigned io_ticks;
97 unsigned time_in_queue;
100 struct gendisk {
101 int major; /* major number of driver */
102 int first_minor;
103 int minors; /* maximum number of minors, =1 for
104 * disks that can't be partitioned. */
105 char disk_name[32]; /* name of major driver */
106 struct hd_struct **part; /* [indexed by minor] */
107 struct block_device_operations *fops;
108 struct request_queue *queue;
109 void *private_data;
110 sector_t capacity;
112 int flags;
113 char devfs_name[64]; /* devfs crap */
114 int number; /* more of the same */
115 struct device *driverfs_dev;
116 struct kobject kobj;
118 struct timer_rand_state *random;
119 int policy;
121 atomic_t sync_io; /* RAID */
122 unsigned long stamp;
123 int in_flight;
124 #ifdef CONFIG_SMP
125 struct disk_stats *dkstats;
126 #else
127 struct disk_stats dkstats;
128 #endif
131 /* Structure for sysfs attributes on block devices */
132 struct disk_attribute {
133 struct attribute attr;
134 ssize_t (*show)(struct gendisk *, char *);
135 ssize_t (*store)(struct gendisk *, const char *, size_t);
139 * Macros to operate on percpu disk statistics:
141 * The __ variants should only be called in critical sections. The full
142 * variants disable/enable preemption.
144 #ifdef CONFIG_SMP
145 #define __disk_stat_add(gendiskp, field, addnd) \
146 (per_cpu_ptr(gendiskp->dkstats, smp_processor_id())->field += addnd)
148 #define disk_stat_read(gendiskp, field) \
149 ({ \
150 typeof(gendiskp->dkstats->field) res = 0; \
151 int i; \
152 for_each_cpu(i) \
153 res += per_cpu_ptr(gendiskp->dkstats, i)->field; \
154 res; \
157 static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) {
158 int i;
159 for_each_cpu(i)
160 memset(per_cpu_ptr(gendiskp->dkstats, i), value,
161 sizeof (struct disk_stats));
164 #else
165 #define __disk_stat_add(gendiskp, field, addnd) \
166 (gendiskp->dkstats.field += addnd)
167 #define disk_stat_read(gendiskp, field) (gendiskp->dkstats.field)
169 static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) {
170 memset(&gendiskp->dkstats, value, sizeof (struct disk_stats));
172 #endif
174 #define disk_stat_add(gendiskp, field, addnd) \
175 do { \
176 preempt_disable(); \
177 __disk_stat_add(gendiskp, field, addnd); \
178 preempt_enable(); \
179 } while (0)
181 #define __disk_stat_dec(gendiskp, field) __disk_stat_add(gendiskp, field, -1)
182 #define disk_stat_dec(gendiskp, field) disk_stat_add(gendiskp, field, -1)
184 #define __disk_stat_inc(gendiskp, field) __disk_stat_add(gendiskp, field, 1)
185 #define disk_stat_inc(gendiskp, field) disk_stat_add(gendiskp, field, 1)
187 #define __disk_stat_sub(gendiskp, field, subnd) \
188 __disk_stat_add(gendiskp, field, -subnd)
189 #define disk_stat_sub(gendiskp, field, subnd) \
190 disk_stat_add(gendiskp, field, -subnd)
193 /* Inlines to alloc and free disk stats in struct gendisk */
194 #ifdef CONFIG_SMP
195 static inline int init_disk_stats(struct gendisk *disk)
197 disk->dkstats = alloc_percpu(struct disk_stats);
198 if (!disk->dkstats)
199 return 0;
200 return 1;
203 static inline void free_disk_stats(struct gendisk *disk)
205 free_percpu(disk->dkstats);
207 #else /* CONFIG_SMP */
208 static inline int init_disk_stats(struct gendisk *disk)
210 return 1;
213 static inline void free_disk_stats(struct gendisk *disk)
216 #endif /* CONFIG_SMP */
218 /* drivers/block/ll_rw_blk.c */
219 extern void disk_round_stats(struct gendisk *disk);
221 /* drivers/block/genhd.c */
222 extern int get_blkdev_list(char *, int);
223 extern void add_disk(struct gendisk *disk);
224 extern void del_gendisk(struct gendisk *gp);
225 extern void unlink_gendisk(struct gendisk *gp);
226 extern struct gendisk *get_gendisk(dev_t dev, int *part);
228 extern void set_device_ro(struct block_device *bdev, int flag);
229 extern void set_disk_ro(struct gendisk *disk, int flag);
231 /* drivers/char/random.c */
232 extern void add_disk_randomness(struct gendisk *disk);
233 extern void rand_initialize_disk(struct gendisk *disk);
235 static inline sector_t get_start_sect(struct block_device *bdev)
237 return bdev->bd_contains == bdev ? 0 : bdev->bd_part->start_sect;
239 static inline sector_t get_capacity(struct gendisk *disk)
241 return disk->capacity;
243 static inline void set_capacity(struct gendisk *disk, sector_t size)
245 disk->capacity = size;
248 #endif /* __KERNEL__ */
250 #ifdef CONFIG_SOLARIS_X86_PARTITION
252 #define SOLARIS_X86_NUMSLICE 8
253 #define SOLARIS_X86_VTOC_SANE (0x600DDEEEUL)
255 struct solaris_x86_slice {
256 __le16 s_tag; /* ID tag of partition */
257 __le16 s_flag; /* permission flags */
258 __le32 s_start; /* start sector no of partition */
259 __le32 s_size; /* # of blocks in partition */
262 struct solaris_x86_vtoc {
263 unsigned int v_bootinfo[3]; /* info needed by mboot (unsupported) */
264 __le32 v_sanity; /* to verify vtoc sanity */
265 __le32 v_version; /* layout version */
266 char v_volume[8]; /* volume name */
267 __le16 v_sectorsz; /* sector size in bytes */
268 __le16 v_nparts; /* number of partitions */
269 unsigned int v_reserved[10]; /* free space */
270 struct solaris_x86_slice
271 v_slice[SOLARIS_X86_NUMSLICE]; /* slice headers */
272 unsigned int timestamp[SOLARIS_X86_NUMSLICE]; /* timestamp (unsupported) */
273 char v_asciilabel[128]; /* for compatibility */
276 #endif /* CONFIG_SOLARIS_X86_PARTITION */
278 #ifdef CONFIG_BSD_DISKLABEL
280 * BSD disklabel support by Yossi Gottlieb <yogo@math.tau.ac.il>
281 * updated by Marc Espie <Marc.Espie@openbsd.org>
284 /* check against BSD src/sys/sys/disklabel.h for consistency */
286 #define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */
287 #define BSD_MAXPARTITIONS 16
288 #define OPENBSD_MAXPARTITIONS 16
289 #define BSD_FS_UNUSED 0 /* disklabel unused partition entry ID */
290 struct bsd_disklabel {
291 __le32 d_magic; /* the magic number */
292 __s16 d_type; /* drive type */
293 __s16 d_subtype; /* controller/d_type specific */
294 char d_typename[16]; /* type name, e.g. "eagle" */
295 char d_packname[16]; /* pack identifier */
296 __u32 d_secsize; /* # of bytes per sector */
297 __u32 d_nsectors; /* # of data sectors per track */
298 __u32 d_ntracks; /* # of tracks per cylinder */
299 __u32 d_ncylinders; /* # of data cylinders per unit */
300 __u32 d_secpercyl; /* # of data sectors per cylinder */
301 __u32 d_secperunit; /* # of data sectors per unit */
302 __u16 d_sparespertrack; /* # of spare sectors per track */
303 __u16 d_sparespercyl; /* # of spare sectors per cylinder */
304 __u32 d_acylinders; /* # of alt. cylinders per unit */
305 __u16 d_rpm; /* rotational speed */
306 __u16 d_interleave; /* hardware sector interleave */
307 __u16 d_trackskew; /* sector 0 skew, per track */
308 __u16 d_cylskew; /* sector 0 skew, per cylinder */
309 __u32 d_headswitch; /* head switch time, usec */
310 __u32 d_trkseek; /* track-to-track seek, usec */
311 __u32 d_flags; /* generic flags */
312 #define NDDATA 5
313 __u32 d_drivedata[NDDATA]; /* drive-type specific information */
314 #define NSPARE 5
315 __u32 d_spare[NSPARE]; /* reserved for future use */
316 __le32 d_magic2; /* the magic number (again) */
317 __le16 d_checksum; /* xor of data incl. partitions */
319 /* filesystem and partition information: */
320 __le16 d_npartitions; /* number of partitions in following */
321 __le32 d_bbsize; /* size of boot area at sn0, bytes */
322 __le32 d_sbsize; /* max size of fs superblock, bytes */
323 struct bsd_partition { /* the partition table */
324 __le32 p_size; /* number of sectors in partition */
325 __le32 p_offset; /* starting sector */
326 __le32 p_fsize; /* filesystem basic fragment size */
327 __u8 p_fstype; /* filesystem type, see below */
328 __u8 p_frag; /* filesystem fragments per block */
329 __le16 p_cpg; /* filesystem cylinders per group */
330 } d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */
333 #endif /* CONFIG_BSD_DISKLABEL */
335 #ifdef CONFIG_UNIXWARE_DISKLABEL
337 * Unixware slices support by Andrzej Krzysztofowicz <ankry@mif.pg.gda.pl>
338 * and Krzysztof G. Baranowski <kgb@knm.org.pl>
341 #define UNIXWARE_DISKMAGIC (0xCA5E600DUL) /* The disk magic number */
342 #define UNIXWARE_DISKMAGIC2 (0x600DDEEEUL) /* The slice table magic nr */
343 #define UNIXWARE_NUMSLICE 16
344 #define UNIXWARE_FS_UNUSED 0 /* Unused slice entry ID */
346 struct unixware_slice {
347 __le16 s_label; /* label */
348 __le16 s_flags; /* permission flags */
349 __le32 start_sect; /* starting sector */
350 __le32 nr_sects; /* number of sectors in slice */
353 struct unixware_disklabel {
354 __le32 d_type; /* drive type */
355 __le32 d_magic; /* the magic number */
356 __le32 d_version; /* version number */
357 char d_serial[12]; /* serial number of the device */
358 __le32 d_ncylinders; /* # of data cylinders per device */
359 __le32 d_ntracks; /* # of tracks per cylinder */
360 __le32 d_nsectors; /* # of data sectors per track */
361 __le32 d_secsize; /* # of bytes per sector */
362 __le32 d_part_start; /* # of first sector of this partition */
363 __le32 d_unknown1[12]; /* ? */
364 __le32 d_alt_tbl; /* byte offset of alternate table */
365 __le32 d_alt_len; /* byte length of alternate table */
366 __le32 d_phys_cyl; /* # of physical cylinders per device */
367 __le32 d_phys_trk; /* # of physical tracks per cylinder */
368 __le32 d_phys_sec; /* # of physical sectors per track */
369 __le32 d_phys_bytes; /* # of physical bytes per sector */
370 __le32 d_unknown2; /* ? */
371 __le32 d_unknown3; /* ? */
372 __le32 d_pad[8]; /* pad */
374 struct unixware_vtoc {
375 __le32 v_magic; /* the magic number */
376 __le32 v_version; /* version number */
377 char v_name[8]; /* volume name */
378 __le16 v_nslices; /* # of slices */
379 __le16 v_unknown1; /* ? */
380 __le32 v_reserved[10]; /* reserved */
381 struct unixware_slice
382 v_slice[UNIXWARE_NUMSLICE]; /* slice headers */
383 } vtoc;
385 }; /* 408 */
387 #endif /* CONFIG_UNIXWARE_DISKLABEL */
389 #ifdef CONFIG_MINIX_SUBPARTITION
390 # define MINIX_NR_SUBPARTITIONS 4
391 #endif /* CONFIG_MINIX_SUBPARTITION */
393 #ifdef __KERNEL__
395 char *disk_name (struct gendisk *hd, int part, char *buf);
397 extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
398 extern void add_partition(struct gendisk *, int, sector_t, sector_t);
399 extern void delete_partition(struct gendisk *, int);
401 extern struct gendisk *alloc_disk_node(int minors, int node_id);
402 extern struct gendisk *alloc_disk(int minors);
403 extern struct kobject *get_disk(struct gendisk *disk);
404 extern void put_disk(struct gendisk *disk);
406 extern void blk_register_region(dev_t dev, unsigned long range,
407 struct module *module,
408 struct kobject *(*probe)(dev_t, int *, void *),
409 int (*lock)(dev_t, void *),
410 void *data);
411 extern void blk_unregister_region(dev_t dev, unsigned long range);
413 static inline struct block_device *bdget_disk(struct gendisk *disk, int index)
415 return bdget(MKDEV(disk->major, disk->first_minor) + index);
418 #endif
420 #endif