5 * genhd.h Copyright (C) 1992 Drew Eckhardt
6 * Generic hard disk header file by
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>
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 */
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));
63 unsigned reads, read_sectors, writes, write_sectors;
67 #define GENHD_FL_REMOVABLE 1
68 #define GENHD_FL_DRIVERFS 2
70 #define GENHD_FL_UP 16
71 #define GENHD_FL_SUPPRESS_PARTITION_INFO 32
74 unsigned read_sectors, write_sectors;
75 unsigned reads, writes;
76 unsigned read_merges, write_merges;
77 unsigned read_ticks, write_ticks;
79 unsigned time_in_queue;
83 int major; /* major number of driver */
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;
95 char devfs_name[64]; /* devfs crap */
96 int number; /* more of the same */
97 struct device *driverfs_dev;
100 struct timer_rand_state *random;
103 unsigned sync_io; /* RAID */
104 unsigned long stamp, stamp_idle;
107 struct disk_stats *dkstats;
109 struct disk_stats dkstats;
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
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) \
124 typeof(gendiskp->dkstats->field) res = 0; \
126 for (i=0; i < NR_CPUS; i++) { \
127 if (!cpu_possible(i)) \
129 res += per_cpu_ptr(gendiskp->dkstats, i)->field; \
134 static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) {
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));
145 #define disk_stat_add(gendiskp, field, addnd) (gendiskp->dkstats.field += addnd)
146 #define disk_stat_read(gendiskp, field) (gendiskp->dkstats.field)
148 static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) {
149 memset(&gendiskp->dkstats, value, sizeof (struct disk_stats));
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)
159 /* Inlines to alloc and free disk stats in struct gendisk */
161 static inline int init_disk_stats(struct gendisk *disk)
163 disk->dkstats = alloc_percpu(struct disk_stats);
169 static inline void free_disk_stats(struct gendisk *disk)
171 free_percpu(disk->dkstats);
173 #else /* CONFIG_SMP */
174 static inline int init_disk_stats(struct gendisk *disk)
179 static inline void free_disk_stats(struct gendisk *disk)
182 #endif /* CONFIG_SMP */
184 /* drivers/block/ll_rw_blk.c */
185 extern void disk_round_stats(struct gendisk *disk);
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);
193 extern void set_device_ro(struct block_device *bdev, int flag);
194 extern void set_disk_ro(struct gendisk *disk, int flag);
196 /* drivers/char/random.c */
197 extern void add_disk_randomness(struct gendisk *disk);
198 extern void rand_initialize_disk(struct gendisk *disk);
200 static inline sector_t get_start_sect(struct block_device *bdev)
202 return bdev->bd_contains == bdev ? 0 : bdev->bd_part->start_sect;
204 static inline sector_t get_capacity(struct gendisk *disk)
206 return disk->capacity;
208 static inline void set_capacity(struct gendisk *disk, sector_t size)
210 disk->capacity = size;
213 #endif /* __KERNEL__ */
215 #ifdef CONFIG_SOLARIS_X86_PARTITION
217 #define SOLARIS_X86_NUMSLICE 8
218 #define SOLARIS_X86_VTOC_SANE (0x600DDEEEUL)
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 */
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 */
241 #endif /* CONFIG_SOLARIS_X86_PARTITION */
243 #ifdef CONFIG_BSD_DISKLABEL
245 * BSD disklabel support by Yossi Gottlieb <yogo@math.tau.ac.il>
246 * updated by Marc Espie <Marc.Espie@openbsd.org>
249 /* check against BSD src/sys/sys/disklabel.h for consistency */
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 */
278 __u32 d_drivedata[NDDATA]; /* drive-type specific information */
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 */
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 */
298 #endif /* CONFIG_BSD_DISKLABEL */
300 #ifdef CONFIG_UNIXWARE_DISKLABEL
302 * Unixware slices support by Andrzej Krzysztofowicz <ankry@mif.pg.gda.pl>
303 * and Krzysztof G. Baranowski <kgb@knm.org.pl>
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 */
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 */
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 */
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 */
352 #endif /* CONFIG_UNIXWARE_DISKLABEL */
354 #ifdef CONFIG_MINIX_SUBPARTITION
355 # define MINIX_NR_SUBPARTITIONS 4
356 #endif /* CONFIG_MINIX_SUBPARTITION */
360 char *disk_name (struct gendisk *hd, int part, char *buf);
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);
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);
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 *),
375 extern void blk_unregister_region(dev_t dev, unsigned long range);
377 static inline struct block_device *bdget_disk(struct gendisk *disk, int index)
379 return bdget(MKDEV(disk->major, disk->first_minor) + index);