ibm.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 inline int
  22. cchh2blk (struct vtoc_cchh *ptr, struct hd_geometry *geo) {
  23. return ptr->cc * geo->heads * geo->sectors +
  24. ptr->hh * geo->sectors;
  25. }
  26. /*
  27. * compute the block number from a
  28. * cyl-cyl-head-head-block structure
  29. */
  30. static inline int
  31. cchhb2blk (struct vtoc_cchhb *ptr, struct hd_geometry *geo) {
  32. return ptr->cc * geo->heads * geo->sectors +
  33. ptr->hh * geo->sectors +
  34. ptr->b;
  35. }
  36. /*
  37. */
  38. int
  39. ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
  40. {
  41. int blocksize, offset, size;
  42. loff_t i_size;
  43. dasd_information_t *info;
  44. struct hd_geometry *geo;
  45. char type[5] = {0,};
  46. char name[7] = {0,};
  47. union label_t {
  48. struct vtoc_volume_label vol;
  49. struct vtoc_cms_label cms;
  50. } *label;
  51. unsigned char *data;
  52. Sector sect;
  53. blocksize = bdev_hardsect_size(bdev);
  54. if (blocksize <= 0)
  55. return 0;
  56. i_size = i_size_read(bdev->bd_inode);
  57. if (i_size == 0)
  58. return 0;
  59. if ((info = kmalloc(sizeof(dasd_information_t), GFP_KERNEL)) == NULL)
  60. goto out_noinfo;
  61. if ((geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL)) == NULL)
  62. goto out_nogeo;
  63. if ((label = kmalloc(sizeof(union label_t), GFP_KERNEL)) == NULL)
  64. goto out_nolab;
  65. if (ioctl_by_bdev(bdev, BIODASDINFO, (unsigned long)info) != 0 ||
  66. ioctl_by_bdev(bdev, HDIO_GETGEO, (unsigned long)geo) != 0)
  67. goto out_noioctl;
  68. /*
  69. * Get volume label, extract name and type.
  70. */
  71. data = read_dev_sector(bdev, info->label_block*(blocksize/512), &sect);
  72. if (data == NULL)
  73. goto out_readerr;
  74. strncpy (type, data, 4);
  75. if ((!info->FBA_layout) && (!strcmp(info->type, "ECKD")))
  76. strncpy(name, data + 8, 6);
  77. else
  78. strncpy(name, data + 4, 6);
  79. memcpy(label, data, sizeof(union label_t));
  80. put_dev_sector(sect);
  81. EBCASC(type, 4);
  82. EBCASC(name, 6);
  83. /*
  84. * Three different types: CMS1, VOL1 and LNX1/unlabeled
  85. */
  86. if (strncmp(type, "CMS1", 4) == 0) {
  87. /*
  88. * VM style CMS1 labeled disk
  89. */
  90. if (label->cms.disk_offset != 0) {
  91. printk("CMS1/%8s(MDSK):", name);
  92. /* disk is reserved minidisk */
  93. blocksize = label->cms.block_size;
  94. offset = label->cms.disk_offset;
  95. size = (label->cms.block_count - 1) * (blocksize >> 9);
  96. } else {
  97. printk("CMS1/%8s:", name);
  98. offset = (info->label_block + 1);
  99. size = i_size >> 9;
  100. }
  101. put_partition(state, 1, offset*(blocksize >> 9),
  102. size-offset*(blocksize >> 9));
  103. } else if ((strncmp(type, "VOL1", 4) == 0) &&
  104. (!info->FBA_layout) && (!strcmp(info->type, "ECKD"))) {
  105. /*
  106. * New style VOL1 labeled disk
  107. */
  108. unsigned int blk;
  109. int counter;
  110. printk("VOL1/%8s:", name);
  111. /* get block number and read then go through format1 labels */
  112. blk = cchhb2blk(&label->vol.vtoc, geo) + 1;
  113. counter = 0;
  114. while ((data = read_dev_sector(bdev, blk*(blocksize/512),
  115. &sect)) != NULL) {
  116. struct vtoc_format1_label f1;
  117. memcpy(&f1, data, sizeof(struct vtoc_format1_label));
  118. put_dev_sector(sect);
  119. /* skip FMT4 / FMT5 / FMT7 labels */
  120. if (f1.DS1FMTID == _ascebc['4']
  121. || f1.DS1FMTID == _ascebc['5']
  122. || f1.DS1FMTID == _ascebc['7']) {
  123. blk++;
  124. continue;
  125. }
  126. /* only FMT1 valid at this point */
  127. if (f1.DS1FMTID != _ascebc['1'])
  128. break;
  129. /* OK, we got valid partition data */
  130. offset = cchh2blk(&f1.DS1EXT1.llimit, geo);
  131. size = cchh2blk(&f1.DS1EXT1.ulimit, geo) -
  132. offset + geo->sectors;
  133. if (counter >= state->limit)
  134. break;
  135. put_partition(state, counter + 1,
  136. offset * (blocksize >> 9),
  137. size * (blocksize >> 9));
  138. counter++;
  139. blk++;
  140. }
  141. } else {
  142. /*
  143. * Old style LNX1 or unlabeled disk
  144. */
  145. if (strncmp(type, "LNX1", 4) == 0)
  146. printk ("LNX1/%8s:", name);
  147. else
  148. printk("(nonl)/%8s:", name);
  149. offset = (info->label_block + 1);
  150. size = i_size >> 9;
  151. put_partition(state, 1, offset*(blocksize >> 9),
  152. size-offset*(blocksize >> 9));
  153. }
  154. printk("\n");
  155. kfree(label);
  156. kfree(geo);
  157. kfree(info);
  158. return 1;
  159. out_readerr:
  160. out_noioctl:
  161. kfree(label);
  162. out_nolab:
  163. kfree(geo);
  164. out_nogeo:
  165. kfree(info);
  166. out_noinfo:
  167. return 0;
  168. }