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