genhd.h 14 KB

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