5 * genhd.h Copyright (C) 1992 Drew Eckhardt
6 * Generic hard disk header file by
12 #include <linux/types.h>
17 /* These three have identical behaviour; use the second one if DOS FDISK gets
18 confused about extended/logical partitions starting past cylinder 1023. */
19 DOS_EXTENDED_PARTITION
= 5,
20 LINUX_EXTENDED_PARTITION
= 0x85,
21 WIN98_EXTENDED_PARTITION
= 0x0f,
23 LINUX_SWAP_PARTITION
= 0x82,
24 LINUX_RAID_PARTITION
= 0xfd, /* autodetect RAID partition */
26 SOLARIS_X86_PARTITION
= LINUX_SWAP_PARTITION
,
27 NEW_SOLARIS_X86_PARTITION
= 0xbf,
29 DM6_AUX1PARTITION
= 0x51, /* no DDO: use xlated geom */
30 DM6_AUX3PARTITION
= 0x53, /* no DDO: use xlated geom */
31 DM6_PARTITION
= 0x54, /* has DDO: use xlated geom & offset */
32 EZD_PARTITION
= 0x55, /* EZ-DRIVE */
34 FREEBSD_PARTITION
= 0xa5, /* FreeBSD Partition ID */
35 OPENBSD_PARTITION
= 0xa6, /* OpenBSD Partition ID */
36 NETBSD_PARTITION
= 0xa9, /* NetBSD Partition ID */
37 BSDI_PARTITION
= 0xb7, /* BSDI Partition ID */
38 MINIX_PARTITION
= 0x81, /* Minix Partition ID */
39 UNIXWARE_PARTITION
= 0x63, /* Same as GNU_HURD and SCO Unix */
45 unsigned char boot_ind
; /* 0x80 - active */
46 unsigned char head
; /* starting head */
47 unsigned char sector
; /* starting sector */
48 unsigned char cyl
; /* starting cylinder */
49 unsigned char sys_ind
; /* What partition type */
50 unsigned char end_head
; /* end head */
51 unsigned char end_sector
; /* end sector */
52 unsigned char end_cyl
; /* end cylinder */
53 unsigned int start_sect
; /* starting sector counting from 0 */
54 unsigned int nr_sects
; /* nr of sectors in partition */
55 } __attribute__((packed
));
60 #include <linux/major.h>
61 #include <linux/device.h>
62 #include <linux/smp.h>
63 #include <linux/string.h>
67 unsigned char boot_ind
; /* 0x80 - active */
68 unsigned char head
; /* starting head */
69 unsigned char sector
; /* starting sector */
70 unsigned char cyl
; /* starting cylinder */
71 unsigned char sys_ind
; /* What partition type */
72 unsigned char end_head
; /* end head */
73 unsigned char end_sector
; /* end sector */
74 unsigned char end_cyl
; /* end cylinder */
75 __le32 start_sect
; /* starting sector counting from 0 */
76 __le32 nr_sects
; /* nr of sectors in partition */
77 } __attribute__((packed
));
83 struct kobject
*holder_dir
;
84 unsigned ios
[2], sectors
[2]; /* READs and WRITEs */
86 #ifdef CONFIG_FAIL_MAKE_REQUEST
91 #define GENHD_FL_REMOVABLE 1
92 #define GENHD_FL_DRIVERFS 2
94 #define GENHD_FL_UP 16
95 #define GENHD_FL_SUPPRESS_PARTITION_INFO 32
96 #define GENHD_FL_FAIL 64
99 unsigned long sectors
[2]; /* READs and WRITEs */
100 unsigned long ios
[2];
101 unsigned long merges
[2];
102 unsigned long ticks
[2];
103 unsigned long io_ticks
;
104 unsigned long time_in_queue
;
108 int major
; /* major number of driver */
110 int minors
; /* maximum number of minors, =1 for
111 * disks that can't be partitioned. */
112 char disk_name
[32]; /* name of major driver */
113 struct hd_struct
**part
; /* [indexed by minor] */
114 int part_uevent_suppress
;
115 struct block_device_operations
*fops
;
116 struct request_queue
*queue
;
121 struct device
*driverfs_dev
;
123 struct kobject
*holder_dir
;
124 struct kobject
*slave_dir
;
126 struct timer_rand_state
*random
;
129 atomic_t sync_io
; /* RAID */
133 struct disk_stats
*dkstats
;
135 struct disk_stats dkstats
;
139 /* Structure for sysfs attributes on block devices */
140 struct disk_attribute
{
141 struct attribute attr
;
142 ssize_t (*show
)(struct gendisk
*, char *);
143 ssize_t (*store
)(struct gendisk
*, const char *, size_t);
147 * Macros to operate on percpu disk statistics:
149 * The __ variants should only be called in critical sections. The full
150 * variants disable/enable preemption.
153 #define __disk_stat_add(gendiskp, field, addnd) \
154 (per_cpu_ptr(gendiskp->dkstats, smp_processor_id())->field += addnd)
156 #define disk_stat_read(gendiskp, field) \
158 typeof(gendiskp->dkstats->field) res = 0; \
160 for_each_possible_cpu(i) \
161 res += per_cpu_ptr(gendiskp->dkstats, i)->field; \
165 static inline void disk_stat_set_all(struct gendisk
*gendiskp
, int value
) {
167 for_each_possible_cpu(i
)
168 memset(per_cpu_ptr(gendiskp
->dkstats
, i
), value
,
169 sizeof (struct disk_stats
));
173 #define __disk_stat_add(gendiskp, field, addnd) \
174 (gendiskp->dkstats.field += addnd)
175 #define disk_stat_read(gendiskp, field) (gendiskp->dkstats.field)
177 static inline void disk_stat_set_all(struct gendisk
*gendiskp
, int value
) {
178 memset(&gendiskp
->dkstats
, value
, sizeof (struct disk_stats
));
182 #define disk_stat_add(gendiskp, field, addnd) \
185 __disk_stat_add(gendiskp, field, addnd); \
189 #define __disk_stat_dec(gendiskp, field) __disk_stat_add(gendiskp, field, -1)
190 #define disk_stat_dec(gendiskp, field) disk_stat_add(gendiskp, field, -1)
192 #define __disk_stat_inc(gendiskp, field) __disk_stat_add(gendiskp, field, 1)
193 #define disk_stat_inc(gendiskp, field) disk_stat_add(gendiskp, field, 1)
195 #define __disk_stat_sub(gendiskp, field, subnd) \
196 __disk_stat_add(gendiskp, field, -subnd)
197 #define disk_stat_sub(gendiskp, field, subnd) \
198 disk_stat_add(gendiskp, field, -subnd)
201 /* Inlines to alloc and free disk stats in struct gendisk */
203 static inline int init_disk_stats(struct gendisk
*disk
)
205 disk
->dkstats
= alloc_percpu(struct disk_stats
);
211 static inline void free_disk_stats(struct gendisk
*disk
)
213 free_percpu(disk
->dkstats
);
215 #else /* CONFIG_SMP */
216 static inline int init_disk_stats(struct gendisk
*disk
)
221 static inline void free_disk_stats(struct gendisk
*disk
)
224 #endif /* CONFIG_SMP */
226 /* drivers/block/ll_rw_blk.c */
227 extern void disk_round_stats(struct gendisk
*disk
);
229 /* drivers/block/genhd.c */
230 extern int get_blkdev_list(char *, int);
231 extern void add_disk(struct gendisk
*disk
);
232 extern void del_gendisk(struct gendisk
*gp
);
233 extern void unlink_gendisk(struct gendisk
*gp
);
234 extern struct gendisk
*get_gendisk(dev_t dev
, int *part
);
236 extern void set_device_ro(struct block_device
*bdev
, int flag
);
237 extern void set_disk_ro(struct gendisk
*disk
, int flag
);
239 /* drivers/char/random.c */
240 extern void add_disk_randomness(struct gendisk
*disk
);
241 extern void rand_initialize_disk(struct gendisk
*disk
);
243 static inline sector_t
get_start_sect(struct block_device
*bdev
)
245 return bdev
->bd_contains
== bdev
? 0 : bdev
->bd_part
->start_sect
;
247 static inline sector_t
get_capacity(struct gendisk
*disk
)
249 return disk
->capacity
;
251 static inline void set_capacity(struct gendisk
*disk
, sector_t size
)
253 disk
->capacity
= size
;
256 #endif /* __KERNEL__ */
258 #ifdef CONFIG_SOLARIS_X86_PARTITION
260 #define SOLARIS_X86_NUMSLICE 8
261 #define SOLARIS_X86_VTOC_SANE (0x600DDEEEUL)
263 struct solaris_x86_slice
{
264 __le16 s_tag
; /* ID tag of partition */
265 __le16 s_flag
; /* permission flags */
266 __le32 s_start
; /* start sector no of partition */
267 __le32 s_size
; /* # of blocks in partition */
270 struct solaris_x86_vtoc
{
271 unsigned int v_bootinfo
[3]; /* info needed by mboot (unsupported) */
272 __le32 v_sanity
; /* to verify vtoc sanity */
273 __le32 v_version
; /* layout version */
274 char v_volume
[8]; /* volume name */
275 __le16 v_sectorsz
; /* sector size in bytes */
276 __le16 v_nparts
; /* number of partitions */
277 unsigned int v_reserved
[10]; /* free space */
278 struct solaris_x86_slice
279 v_slice
[SOLARIS_X86_NUMSLICE
]; /* slice headers */
280 unsigned int timestamp
[SOLARIS_X86_NUMSLICE
]; /* timestamp (unsupported) */
281 char v_asciilabel
[128]; /* for compatibility */
284 #endif /* CONFIG_SOLARIS_X86_PARTITION */
286 #ifdef CONFIG_BSD_DISKLABEL
288 * BSD disklabel support by Yossi Gottlieb <yogo@math.tau.ac.il>
289 * updated by Marc Espie <Marc.Espie@openbsd.org>
292 /* check against BSD src/sys/sys/disklabel.h for consistency */
294 #define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */
295 #define BSD_MAXPARTITIONS 16
296 #define OPENBSD_MAXPARTITIONS 16
297 #define BSD_FS_UNUSED 0 /* disklabel unused partition entry ID */
298 struct bsd_disklabel
{
299 __le32 d_magic
; /* the magic number */
300 __s16 d_type
; /* drive type */
301 __s16 d_subtype
; /* controller/d_type specific */
302 char d_typename
[16]; /* type name, e.g. "eagle" */
303 char d_packname
[16]; /* pack identifier */
304 __u32 d_secsize
; /* # of bytes per sector */
305 __u32 d_nsectors
; /* # of data sectors per track */
306 __u32 d_ntracks
; /* # of tracks per cylinder */
307 __u32 d_ncylinders
; /* # of data cylinders per unit */
308 __u32 d_secpercyl
; /* # of data sectors per cylinder */
309 __u32 d_secperunit
; /* # of data sectors per unit */
310 __u16 d_sparespertrack
; /* # of spare sectors per track */
311 __u16 d_sparespercyl
; /* # of spare sectors per cylinder */
312 __u32 d_acylinders
; /* # of alt. cylinders per unit */
313 __u16 d_rpm
; /* rotational speed */
314 __u16 d_interleave
; /* hardware sector interleave */
315 __u16 d_trackskew
; /* sector 0 skew, per track */
316 __u16 d_cylskew
; /* sector 0 skew, per cylinder */
317 __u32 d_headswitch
; /* head switch time, usec */
318 __u32 d_trkseek
; /* track-to-track seek, usec */
319 __u32 d_flags
; /* generic flags */
321 __u32 d_drivedata
[NDDATA
]; /* drive-type specific information */
323 __u32 d_spare
[NSPARE
]; /* reserved for future use */
324 __le32 d_magic2
; /* the magic number (again) */
325 __le16 d_checksum
; /* xor of data incl. partitions */
327 /* filesystem and partition information: */
328 __le16 d_npartitions
; /* number of partitions in following */
329 __le32 d_bbsize
; /* size of boot area at sn0, bytes */
330 __le32 d_sbsize
; /* max size of fs superblock, bytes */
331 struct bsd_partition
{ /* the partition table */
332 __le32 p_size
; /* number of sectors in partition */
333 __le32 p_offset
; /* starting sector */
334 __le32 p_fsize
; /* filesystem basic fragment size */
335 __u8 p_fstype
; /* filesystem type, see below */
336 __u8 p_frag
; /* filesystem fragments per block */
337 __le16 p_cpg
; /* filesystem cylinders per group */
338 } d_partitions
[BSD_MAXPARTITIONS
]; /* actually may be more */
341 #endif /* CONFIG_BSD_DISKLABEL */
343 #ifdef CONFIG_UNIXWARE_DISKLABEL
345 * Unixware slices support by Andrzej Krzysztofowicz <ankry@mif.pg.gda.pl>
346 * and Krzysztof G. Baranowski <kgb@knm.org.pl>
349 #define UNIXWARE_DISKMAGIC (0xCA5E600DUL) /* The disk magic number */
350 #define UNIXWARE_DISKMAGIC2 (0x600DDEEEUL) /* The slice table magic nr */
351 #define UNIXWARE_NUMSLICE 16
352 #define UNIXWARE_FS_UNUSED 0 /* Unused slice entry ID */
354 struct unixware_slice
{
355 __le16 s_label
; /* label */
356 __le16 s_flags
; /* permission flags */
357 __le32 start_sect
; /* starting sector */
358 __le32 nr_sects
; /* number of sectors in slice */
361 struct unixware_disklabel
{
362 __le32 d_type
; /* drive type */
363 __le32 d_magic
; /* the magic number */
364 __le32 d_version
; /* version number */
365 char d_serial
[12]; /* serial number of the device */
366 __le32 d_ncylinders
; /* # of data cylinders per device */
367 __le32 d_ntracks
; /* # of tracks per cylinder */
368 __le32 d_nsectors
; /* # of data sectors per track */
369 __le32 d_secsize
; /* # of bytes per sector */
370 __le32 d_part_start
; /* # of first sector of this partition */
371 __le32 d_unknown1
[12]; /* ? */
372 __le32 d_alt_tbl
; /* byte offset of alternate table */
373 __le32 d_alt_len
; /* byte length of alternate table */
374 __le32 d_phys_cyl
; /* # of physical cylinders per device */
375 __le32 d_phys_trk
; /* # of physical tracks per cylinder */
376 __le32 d_phys_sec
; /* # of physical sectors per track */
377 __le32 d_phys_bytes
; /* # of physical bytes per sector */
378 __le32 d_unknown2
; /* ? */
379 __le32 d_unknown3
; /* ? */
380 __le32 d_pad
[8]; /* pad */
382 struct unixware_vtoc
{
383 __le32 v_magic
; /* the magic number */
384 __le32 v_version
; /* version number */
385 char v_name
[8]; /* volume name */
386 __le16 v_nslices
; /* # of slices */
387 __le16 v_unknown1
; /* ? */
388 __le32 v_reserved
[10]; /* reserved */
389 struct unixware_slice
390 v_slice
[UNIXWARE_NUMSLICE
]; /* slice headers */
395 #endif /* CONFIG_UNIXWARE_DISKLABEL */
397 #ifdef CONFIG_MINIX_SUBPARTITION
398 # define MINIX_NR_SUBPARTITIONS 4
399 #endif /* CONFIG_MINIX_SUBPARTITION */
403 char *disk_name (struct gendisk
*hd
, int part
, char *buf
);
405 extern int rescan_partitions(struct gendisk
*disk
, struct block_device
*bdev
);
406 extern void add_partition(struct gendisk
*, int, sector_t
, sector_t
);
407 extern void delete_partition(struct gendisk
*, int);
409 extern struct gendisk
*alloc_disk_node(int minors
, int node_id
);
410 extern struct gendisk
*alloc_disk(int minors
);
411 extern struct kobject
*get_disk(struct gendisk
*disk
);
412 extern void put_disk(struct gendisk
*disk
);
414 extern void blk_register_region(dev_t dev
, unsigned long range
,
415 struct module
*module
,
416 struct kobject
*(*probe
)(dev_t
, int *, void *),
417 int (*lock
)(dev_t
, void *),
419 extern void blk_unregister_region(dev_t dev
, unsigned long range
);
421 static inline struct block_device
*bdget_disk(struct gendisk
*disk
, int index
)
423 return bdget(MKDEV(disk
->major
, disk
->first_minor
) + index
);