ibm.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * File...........: linux/fs/partitions/ibm.c
  3. * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
  4. * Volker Sameske <sameske@de.ibm.com>
  5. * Bugreports.to..: <Linux390@de.ibm.com>
  6. * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
  7. */
  8. #include <linux/buffer_head.h>
  9. #include <linux/hdreg.h>
  10. #include <linux/slab.h>
  11. #include <asm/dasd.h>
  12. #include <asm/ebcdic.h>
  13. #include <asm/uaccess.h>
  14. #include <asm/vtoc.h>
  15. #include "check.h"
  16. #include "ibm.h"
  17. /*
  18. * compute the block number from a
  19. * cyl-cyl-head-head structure
  20. */
  21. static sector_t
  22. cchh2blk (struct vtoc_cchh *ptr, struct hd_geometry *geo) {
  23. sector_t cyl;
  24. __u16 head;
  25. /*decode cylinder and heads for large volumes */
  26. cyl = ptr->hh & 0xFFF0;
  27. cyl <<= 12;
  28. cyl |= ptr->cc;
  29. head = ptr->hh & 0x000F;
  30. return cyl * geo->heads * geo->sectors +
  31. head * geo->sectors;
  32. }
  33. /*
  34. * compute the block number from a
  35. * cyl-cyl-head-head-block structure
  36. */
  37. static sector_t
  38. cchhb2blk (struct vtoc_cchhb *ptr, struct hd_geometry *geo) {
  39. sector_t cyl;
  40. __u16 head;
  41. /*decode cylinder and heads for large volumes */
  42. cyl = ptr->hh & 0xFFF0;
  43. cyl <<= 12;
  44. cyl |= ptr->cc;
  45. head = ptr->hh & 0x000F;
  46. return cyl * geo->heads * geo->sectors +
  47. head * geo->sectors +
  48. ptr->b;
  49. }
  50. /*
  51. */
  52. int
  53. ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
  54. {
  55. int blocksize, res;
  56. loff_t i_size, offset, size, fmt_size;
  57. dasd_information2_t *info;
  58. struct hd_geometry *geo;
  59. char type[5] = {0,};
  60. char name[7] = {0,};
  61. union label_t {
  62. struct vtoc_volume_label_cdl vol;
  63. struct vtoc_volume_label_ldl lnx;
  64. struct vtoc_cms_label cms;
  65. } *label;
  66. unsigned char *data;
  67. Sector sect;
  68. res = 0;
  69. blocksize = bdev_logical_block_size(bdev);
  70. if (blocksize <= 0)
  71. goto out_exit;
  72. i_size = i_size_read(bdev->bd_inode);
  73. if (i_size == 0)
  74. goto out_exit;
  75. info = kmalloc(sizeof(dasd_information2_t), GFP_KERNEL);
  76. if (info == NULL)
  77. goto out_exit;
  78. geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL);
  79. if (geo == NULL)
  80. goto out_nogeo;
  81. label = kmalloc(sizeof(union label_t), GFP_KERNEL);
  82. if (label == NULL)
  83. goto out_nolab;
  84. if (ioctl_by_bdev(bdev, BIODASDINFO2, (unsigned long)info) != 0 ||
  85. ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0)
  86. goto out_freeall;
  87. /*
  88. * Get volume label, extract name and type.
  89. */
  90. data = read_dev_sector(bdev, info->label_block*(blocksize/512), &sect);
  91. if (data == NULL)
  92. goto out_readerr;
  93. memcpy(label, data, sizeof(union label_t));
  94. put_dev_sector(sect);
  95. if ((!info->FBA_layout) && (!strcmp(info->type, "ECKD"))) {
  96. strncpy(type, label->vol.vollbl, 4);
  97. strncpy(name, label->vol.volid, 6);
  98. } else {
  99. strncpy(type, label->lnx.vollbl, 4);
  100. strncpy(name, label->lnx.volid, 6);
  101. }
  102. EBCASC(type, 4);
  103. EBCASC(name, 6);
  104. res = 1;
  105. /*
  106. * Three different formats: LDL, CDL and unformated disk
  107. *
  108. * identified by info->format
  109. *
  110. * unformated disks we do not have to care about
  111. */
  112. if (info->format == DASD_FORMAT_LDL) {
  113. if (strncmp(type, "CMS1", 4) == 0) {
  114. /*
  115. * VM style CMS1 labeled disk
  116. */
  117. blocksize = label->cms.block_size;
  118. if (label->cms.disk_offset != 0) {
  119. printk("CMS1/%8s(MDSK):", name);
  120. /* disk is reserved minidisk */
  121. offset = label->cms.disk_offset;
  122. size = (label->cms.block_count - 1)
  123. * (blocksize >> 9);
  124. } else {
  125. printk("CMS1/%8s:", name);
  126. offset = (info->label_block + 1);
  127. size = label->cms.block_count
  128. * (blocksize >> 9);
  129. }
  130. put_partition(state, 1, offset*(blocksize >> 9),
  131. size-offset*(blocksize >> 9));
  132. } else {
  133. if (strncmp(type, "LNX1", 4) == 0) {
  134. printk("LNX1/%8s:", name);
  135. if (label->lnx.ldl_version == 0xf2) {
  136. fmt_size = label->lnx.formatted_blocks
  137. * (blocksize >> 9);
  138. } else if (!strcmp(info->type, "ECKD")) {
  139. /* formated w/o large volume support */
  140. fmt_size = geo->cylinders * geo->heads
  141. * geo->sectors * (blocksize >> 9);
  142. } else {
  143. /* old label and no usable disk geometry
  144. * (e.g. DIAG) */
  145. fmt_size = i_size >> 9;
  146. }
  147. size = i_size >> 9;
  148. if (fmt_size < size)
  149. size = fmt_size;
  150. offset = (info->label_block + 1);
  151. } else {
  152. /* unlabeled disk */
  153. printk("(nonl)");
  154. size = i_size >> 9;
  155. offset = (info->label_block + 1);
  156. }
  157. put_partition(state, 1, offset*(blocksize >> 9),
  158. size-offset*(blocksize >> 9));
  159. }
  160. } else if (info->format == DASD_FORMAT_CDL) {
  161. /*
  162. * New style CDL formatted disk
  163. */
  164. sector_t blk;
  165. int counter;
  166. /*
  167. * check if VOL1 label is available
  168. * if not, something is wrong, skipping partition detection
  169. */
  170. if (strncmp(type, "VOL1", 4) == 0) {
  171. printk("VOL1/%8s:", name);
  172. /*
  173. * get block number and read then go through format1
  174. * labels
  175. */
  176. blk = cchhb2blk(&label->vol.vtoc, geo) + 1;
  177. counter = 0;
  178. data = read_dev_sector(bdev, blk * (blocksize/512),
  179. &sect);
  180. while (data != NULL) {
  181. struct vtoc_format1_label f1;
  182. memcpy(&f1, data,
  183. sizeof(struct vtoc_format1_label));
  184. put_dev_sector(sect);
  185. /* skip FMT4 / FMT5 / FMT7 labels */
  186. if (f1.DS1FMTID == _ascebc['4']
  187. || f1.DS1FMTID == _ascebc['5']
  188. || f1.DS1FMTID == _ascebc['7']
  189. || f1.DS1FMTID == _ascebc['9']) {
  190. blk++;
  191. data = read_dev_sector(bdev, blk *
  192. (blocksize/512),
  193. &sect);
  194. continue;
  195. }
  196. /* only FMT1 and 8 labels valid at this point */
  197. if (f1.DS1FMTID != _ascebc['1'] &&
  198. f1.DS1FMTID != _ascebc['8'])
  199. break;
  200. /* OK, we got valid partition data */
  201. offset = cchh2blk(&f1.DS1EXT1.llimit, geo);
  202. size = cchh2blk(&f1.DS1EXT1.ulimit, geo) -
  203. offset + geo->sectors;
  204. if (counter >= state->limit)
  205. break;
  206. put_partition(state, counter + 1,
  207. offset * (blocksize >> 9),
  208. size * (blocksize >> 9));
  209. counter++;
  210. blk++;
  211. data = read_dev_sector(bdev,
  212. blk * (blocksize/512),
  213. &sect);
  214. }
  215. if (!data)
  216. /* Are we not supposed to report this ? */
  217. goto out_readerr;
  218. } else
  219. printk(KERN_WARNING "Warning, expected Label VOL1 not "
  220. "found, treating as CDL formated Disk");
  221. }
  222. printk("\n");
  223. goto out_freeall;
  224. out_readerr:
  225. res = -1;
  226. out_freeall:
  227. kfree(label);
  228. out_nolab:
  229. kfree(geo);
  230. out_nogeo:
  231. kfree(info);
  232. out_exit:
  233. return res;
  234. }