VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-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/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>
19
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,
26
27         LINUX_SWAP_PARTITION = 0x82,
28         LINUX_RAID_PARTITION = 0xfd,    /* autodetect RAID partition */
29
30         SOLARIS_X86_PARTITION = LINUX_SWAP_PARTITION,
31
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 */
36
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 */
43 };
44
45 struct partition {
46         unsigned char boot_ind;         /* 0x80 - active */
47         unsigned char head;             /* starting head */
48         unsigned char sector;           /* starting sector */
49         unsigned char cyl;              /* starting cylinder */
50         unsigned char sys_ind;          /* What partition type */
51         unsigned char end_head;         /* end head */
52         unsigned char end_sector;       /* end sector */
53         unsigned char end_cyl;          /* end cylinder */
54         unsigned int start_sect;        /* starting sector counting from 0 */
55         unsigned int nr_sects;          /* nr of sectors in partition */
56 } __attribute__((packed));
57
58 #ifdef __KERNEL__
59 struct hd_struct {
60         sector_t start_sect;
61         sector_t nr_sects;
62         struct kobject kobj;
63         unsigned reads, read_sectors, writes, write_sectors;
64         int policy, partno;
65 };
66
67 #define GENHD_FL_REMOVABLE                      1
68 #define GENHD_FL_DRIVERFS                       2
69 #define GENHD_FL_CD                             8
70 #define GENHD_FL_UP                             16
71 #define GENHD_FL_SUPPRESS_PARTITION_INFO        32
72
73 struct disk_stats {
74         unsigned read_sectors, write_sectors;
75         unsigned reads, writes;
76         unsigned read_merges, write_merges;
77         unsigned read_ticks, write_ticks;
78         unsigned io_ticks;
79         unsigned time_in_queue;
80 };
81         
82 struct gendisk {
83         int major;                      /* major number of driver */
84         int first_minor;
85         int minors;                     /* maximum number of minors, =1 for
86                                          * disks that can't be partitioned. */
87         char disk_name[32];             /* name of major driver */
88         struct hd_struct **part;        /* [indexed by minor] */
89         struct block_device_operations *fops;
90         struct request_queue *queue;
91         void *private_data;
92         sector_t capacity;
93
94         int flags;
95         char devfs_name[64];            /* devfs crap */
96         int number;                     /* more of the same */
97         struct device *driverfs_dev;
98         struct kobject kobj;
99
100         struct timer_rand_state *random;
101         int policy;
102
103         unsigned sync_io;               /* RAID */
104         unsigned long stamp, stamp_idle;
105         int in_flight;
106 #ifdef  CONFIG_SMP
107         struct disk_stats *dkstats;
108 #else
109         struct disk_stats dkstats;
110 #endif
111 };
112
113 /* 
114  * Macros to operate on percpu disk statistics:
115  * Since writes to disk_stats are serialised through the queue_lock,
116  * smp_processor_id() should be enough to get to the per_cpu versions
117  * of statistics counters
118  */
119 #ifdef  CONFIG_SMP
120 #define disk_stat_add(gendiskp, field, addnd)   \
121         (per_cpu_ptr(gendiskp->dkstats, smp_processor_id())->field += addnd)
122 #define disk_stat_read(gendiskp, field)                                 \
123 ({                                                                      \
124         typeof(gendiskp->dkstats->field) res = 0;                       \
125         int i;                                                          \
126         for (i=0; i < NR_CPUS; i++) {                                   \
127                 if (!cpu_possible(i))                                   \
128                         continue;                                       \
129                 res += per_cpu_ptr(gendiskp->dkstats, i)->field;        \
130         }                                                               \
131         res;                                                            \
132 })
133
134 static inline void disk_stat_set_all(struct gendisk *gendiskp, int value)       {
135         int i;
136         for (i=0; i < NR_CPUS; i++) {
137                 if (cpu_possible(i)) {
138                         memset(per_cpu_ptr(gendiskp->dkstats, i), value,        
139                                         sizeof (struct disk_stats));
140                 }
141         }
142 }               
143                                 
144 #else
145 #define disk_stat_add(gendiskp, field, addnd) (gendiskp->dkstats.field += addnd)
146 #define disk_stat_read(gendiskp, field) (gendiskp->dkstats.field)
147
148 static inline void disk_stat_set_all(struct gendisk *gendiskp, int value)       {
149         memset(&gendiskp->dkstats, value, sizeof (struct disk_stats));
150 }
151 #endif
152
153 #define disk_stat_inc(gendiskp, field) disk_stat_add(gendiskp, field, 1)
154 #define disk_stat_dec(gendiskp, field) disk_stat_add(gendiskp, field, -1)
155 #define disk_stat_sub(gendiskp, field, subnd) \
156                 disk_stat_add(gendiskp, field, -subnd)
157
158
159 /* Inlines to alloc and free disk stats in struct gendisk */
160 #ifdef  CONFIG_SMP
161 static inline int init_disk_stats(struct gendisk *disk)
162 {
163         disk->dkstats = alloc_percpu(struct disk_stats);
164         if (!disk->dkstats)
165                 return 0;
166         return 1;
167 }
168
169 static inline void free_disk_stats(struct gendisk *disk)
170 {
171         free_percpu(disk->dkstats);
172 }
173 #else   /* CONFIG_SMP */
174 static inline int init_disk_stats(struct gendisk *disk)
175 {
176         return 1;
177 }
178
179 static inline void free_disk_stats(struct gendisk *disk)
180 {
181 }
182 #endif  /* CONFIG_SMP */
183
184 /* drivers/block/ll_rw_blk.c */
185 extern void disk_round_stats(struct gendisk *disk);
186
187 /* drivers/block/genhd.c */
188 extern void add_disk(struct gendisk *disk);
189 extern void del_gendisk(struct gendisk *gp);
190 extern void unlink_gendisk(struct gendisk *gp);
191 extern struct gendisk *get_gendisk(dev_t dev, int *part);
192
193 extern void set_device_ro(struct block_device *bdev, int flag);
194 extern void set_disk_ro(struct gendisk *disk, int flag);
195
196 /* drivers/char/random.c */
197 extern void add_disk_randomness(struct gendisk *disk);
198 extern void rand_initialize_disk(struct gendisk *disk);
199
200 static inline sector_t get_start_sect(struct block_device *bdev)
201 {
202         return bdev->bd_contains == bdev ? 0 : bdev->bd_part->start_sect;
203 }
204 static inline sector_t get_capacity(struct gendisk *disk)
205 {
206         return disk->capacity;
207 }
208 static inline void set_capacity(struct gendisk *disk, sector_t size)
209 {
210         disk->capacity = size;
211 }
212
213 #endif  /*  __KERNEL__  */
214
215 #ifdef CONFIG_SOLARIS_X86_PARTITION
216
217 #define SOLARIS_X86_NUMSLICE    8
218 #define SOLARIS_X86_VTOC_SANE   (0x600DDEEEUL)
219
220 struct solaris_x86_slice {
221         ushort  s_tag;                  /* ID tag of partition */
222         ushort  s_flag;                 /* permission flags */
223         unsigned int s_start;           /* start sector no of partition */
224         unsigned int s_size;            /* # of blocks in partition */
225 };
226
227 struct solaris_x86_vtoc {
228         unsigned int v_bootinfo[3];     /* info needed by mboot (unsupported) */
229         unsigned int v_sanity;          /* to verify vtoc sanity */
230         unsigned int v_version;         /* layout version */
231         char    v_volume[8];            /* volume name */
232         ushort  v_sectorsz;             /* sector size in bytes */
233         ushort  v_nparts;               /* number of partitions */
234         unsigned int v_reserved[10];    /* free space */
235         struct solaris_x86_slice
236                 v_slice[SOLARIS_X86_NUMSLICE]; /* slice headers */
237         unsigned int timestamp[SOLARIS_X86_NUMSLICE]; /* timestamp (unsupported) */
238         char    v_asciilabel[128];      /* for compatibility */
239 };
240
241 #endif /* CONFIG_SOLARIS_X86_PARTITION */
242
243 #ifdef CONFIG_BSD_DISKLABEL
244 /*
245  * BSD disklabel support by Yossi Gottlieb <yogo@math.tau.ac.il>
246  * updated by Marc Espie <Marc.Espie@openbsd.org>
247  */
248
249 /* check against BSD src/sys/sys/disklabel.h for consistency */
250
251 #define BSD_DISKMAGIC   (0x82564557UL)  /* The disk magic number */
252 #define BSD_MAXPARTITIONS       8
253 #define OPENBSD_MAXPARTITIONS   16
254 #define BSD_FS_UNUSED           0       /* disklabel unused partition entry ID */
255 struct bsd_disklabel {
256         __u32   d_magic;                /* the magic number */
257         __s16   d_type;                 /* drive type */
258         __s16   d_subtype;              /* controller/d_type specific */
259         char    d_typename[16];         /* type name, e.g. "eagle" */
260         char    d_packname[16];                 /* pack identifier */ 
261         __u32   d_secsize;              /* # of bytes per sector */
262         __u32   d_nsectors;             /* # of data sectors per track */
263         __u32   d_ntracks;              /* # of tracks per cylinder */
264         __u32   d_ncylinders;           /* # of data cylinders per unit */
265         __u32   d_secpercyl;            /* # of data sectors per cylinder */
266         __u32   d_secperunit;           /* # of data sectors per unit */
267         __u16   d_sparespertrack;       /* # of spare sectors per track */
268         __u16   d_sparespercyl;         /* # of spare sectors per cylinder */
269         __u32   d_acylinders;           /* # of alt. cylinders per unit */
270         __u16   d_rpm;                  /* rotational speed */
271         __u16   d_interleave;           /* hardware sector interleave */
272         __u16   d_trackskew;            /* sector 0 skew, per track */
273         __u16   d_cylskew;              /* sector 0 skew, per cylinder */
274         __u32   d_headswitch;           /* head switch time, usec */
275         __u32   d_trkseek;              /* track-to-track seek, usec */
276         __u32   d_flags;                /* generic flags */
277 #define NDDATA 5
278         __u32   d_drivedata[NDDATA];    /* drive-type specific information */
279 #define NSPARE 5
280         __u32   d_spare[NSPARE];        /* reserved for future use */
281         __u32   d_magic2;               /* the magic number (again) */
282         __u16   d_checksum;             /* xor of data incl. partitions */
283
284                         /* filesystem and partition information: */
285         __u16   d_npartitions;          /* number of partitions in following */
286         __u32   d_bbsize;               /* size of boot area at sn0, bytes */
287         __u32   d_sbsize;               /* max size of fs superblock, bytes */
288         struct  bsd_partition {         /* the partition table */
289                 __u32   p_size;         /* number of sectors in partition */
290                 __u32   p_offset;       /* starting sector */
291                 __u32   p_fsize;        /* filesystem basic fragment size */
292                 __u8    p_fstype;       /* filesystem type, see below */
293                 __u8    p_frag;         /* filesystem fragments per block */
294                 __u16   p_cpg;          /* filesystem cylinders per group */
295         } d_partitions[BSD_MAXPARTITIONS];      /* actually may be more */
296 };
297
298 #endif  /* CONFIG_BSD_DISKLABEL */
299
300 #ifdef CONFIG_UNIXWARE_DISKLABEL
301 /*
302  * Unixware slices support by Andrzej Krzysztofowicz <ankry@mif.pg.gda.pl>
303  * and Krzysztof G. Baranowski <kgb@knm.org.pl>
304  */
305
306 #define UNIXWARE_DISKMAGIC     (0xCA5E600DUL)   /* The disk magic number */
307 #define UNIXWARE_DISKMAGIC2    (0x600DDEEEUL)   /* The slice table magic nr */
308 #define UNIXWARE_NUMSLICE      16
309 #define UNIXWARE_FS_UNUSED     0                /* Unused slice entry ID */
310
311 struct unixware_slice {
312         __u16   s_label;        /* label */
313         __u16   s_flags;        /* permission flags */
314         __u32   start_sect;     /* starting sector */
315         __u32   nr_sects;       /* number of sectors in slice */
316 };
317
318 struct unixware_disklabel {
319         __u32   d_type;                 /* drive type */
320         __u32   d_magic;                /* the magic number */
321         __u32   d_version;              /* version number */
322         char    d_serial[12];           /* serial number of the device */
323         __u32   d_ncylinders;           /* # of data cylinders per device */
324         __u32   d_ntracks;              /* # of tracks per cylinder */
325         __u32   d_nsectors;             /* # of data sectors per track */
326         __u32   d_secsize;              /* # of bytes per sector */
327         __u32   d_part_start;           /* # of first sector of this partition */
328         __u32   d_unknown1[12];         /* ? */
329         __u32   d_alt_tbl;              /* byte offset of alternate table */
330         __u32   d_alt_len;              /* byte length of alternate table */
331         __u32   d_phys_cyl;             /* # of physical cylinders per device */
332         __u32   d_phys_trk;             /* # of physical tracks per cylinder */
333         __u32   d_phys_sec;             /* # of physical sectors per track */
334         __u32   d_phys_bytes;           /* # of physical bytes per sector */
335         __u32   d_unknown2;             /* ? */
336         __u32   d_unknown3;             /* ? */
337         __u32   d_pad[8];               /* pad */
338
339         struct unixware_vtoc {
340                 __u32   v_magic;                /* the magic number */
341                 __u32   v_version;              /* version number */
342                 char    v_name[8];              /* volume name */
343                 __u16   v_nslices;              /* # of slices */
344                 __u16   v_unknown1;             /* ? */
345                 __u32   v_reserved[10];         /* reserved */
346                 struct unixware_slice
347                         v_slice[UNIXWARE_NUMSLICE];     /* slice headers */
348         } vtoc;
349
350 };  /* 408 */
351
352 #endif /* CONFIG_UNIXWARE_DISKLABEL */
353
354 #ifdef CONFIG_MINIX_SUBPARTITION
355 #   define MINIX_NR_SUBPARTITIONS  4
356 #endif /* CONFIG_MINIX_SUBPARTITION */
357
358 #ifdef __KERNEL__
359
360 char *disk_name (struct gendisk *hd, int part, char *buf);
361
362 extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
363 extern void add_partition(struct gendisk *, int, sector_t, sector_t);
364 extern void delete_partition(struct gendisk *, int);
365
366 extern struct gendisk *alloc_disk(int minors);
367 extern struct kobject *get_disk(struct gendisk *disk);
368 extern void put_disk(struct gendisk *disk);
369
370 extern void blk_register_region(dev_t dev, unsigned long range,
371                         struct module *module,
372                         struct kobject *(*probe)(dev_t, int *, void *),
373                         int (*lock)(dev_t, void *),
374                         void *data);
375 extern void blk_unregister_region(dev_t dev, unsigned long range);
376
377 static inline struct block_device *bdget_disk(struct gendisk *disk, int index)
378 {
379         return bdget(MKDEV(disk->major, disk->first_minor) + index);
380 }
381
382 #endif
383
384 #endif