osf.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * fs/partitions/osf.c
  4. *
  5. * Code extracted from drivers/block/genhd.c
  6. *
  7. * Copyright (C) 1991-1998 Linus Torvalds
  8. * Re-organised Feb 1998 Russell King
  9. */
  10. #include "check.h"
  11. #define MAX_OSF_PARTITIONS 18
  12. #define DISKLABELMAGIC (0x82564557UL)
  13. int osf_partition(struct parsed_partitions *state)
  14. {
  15. int i;
  16. int slot = 1;
  17. unsigned int npartitions;
  18. Sector sect;
  19. unsigned char *data;
  20. struct disklabel {
  21. __le32 d_magic;
  22. __le16 d_type,d_subtype;
  23. u8 d_typename[16];
  24. u8 d_packname[16];
  25. __le32 d_secsize;
  26. __le32 d_nsectors;
  27. __le32 d_ntracks;
  28. __le32 d_ncylinders;
  29. __le32 d_secpercyl;
  30. __le32 d_secprtunit;
  31. __le16 d_sparespertrack;
  32. __le16 d_sparespercyl;
  33. __le32 d_acylinders;
  34. __le16 d_rpm, d_interleave, d_trackskew, d_cylskew;
  35. __le32 d_headswitch, d_trkseek, d_flags;
  36. __le32 d_drivedata[5];
  37. __le32 d_spare[5];
  38. __le32 d_magic2;
  39. __le16 d_checksum;
  40. __le16 d_npartitions;
  41. __le32 d_bbsize, d_sbsize;
  42. struct d_partition {
  43. __le32 p_size;
  44. __le32 p_offset;
  45. __le32 p_fsize;
  46. u8 p_fstype;
  47. u8 p_frag;
  48. __le16 p_cpg;
  49. } d_partitions[MAX_OSF_PARTITIONS];
  50. } * label;
  51. struct d_partition * partition;
  52. data = read_part_sector(state, 0, &sect);
  53. if (!data)
  54. return -1;
  55. label = (struct disklabel *) (data+64);
  56. partition = label->d_partitions;
  57. if (le32_to_cpu(label->d_magic) != DISKLABELMAGIC) {
  58. put_dev_sector(sect);
  59. return 0;
  60. }
  61. if (le32_to_cpu(label->d_magic2) != DISKLABELMAGIC) {
  62. put_dev_sector(sect);
  63. return 0;
  64. }
  65. npartitions = le16_to_cpu(label->d_npartitions);
  66. if (npartitions > MAX_OSF_PARTITIONS) {
  67. put_dev_sector(sect);
  68. return 0;
  69. }
  70. for (i = 0 ; i < npartitions; i++, partition++) {
  71. if (slot == state->limit)
  72. break;
  73. if (le32_to_cpu(partition->p_size))
  74. put_partition(state, slot,
  75. le32_to_cpu(partition->p_offset),
  76. le32_to_cpu(partition->p_size));
  77. slot++;
  78. }
  79. strlcat(state->pp_buf, "\n", PAGE_SIZE);
  80. put_dev_sector(sect);
  81. return 1;
  82. }