3
0

unused_ufs.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * volume_id - reads filesystem label and uuid
  3. *
  4. * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include "volume_id_internal.h"
  21. struct ufs_super_block {
  22. uint32_t fs_link;
  23. uint32_t fs_rlink;
  24. uint32_t fs_sblkno;
  25. uint32_t fs_cblkno;
  26. uint32_t fs_iblkno;
  27. uint32_t fs_dblkno;
  28. uint32_t fs_cgoffset;
  29. uint32_t fs_cgmask;
  30. uint32_t fs_time;
  31. uint32_t fs_size;
  32. uint32_t fs_dsize;
  33. uint32_t fs_ncg;
  34. uint32_t fs_bsize;
  35. uint32_t fs_fsize;
  36. uint32_t fs_frag;
  37. uint32_t fs_minfree;
  38. uint32_t fs_rotdelay;
  39. uint32_t fs_rps;
  40. uint32_t fs_bmask;
  41. uint32_t fs_fmask;
  42. uint32_t fs_bshift;
  43. uint32_t fs_fshift;
  44. uint32_t fs_maxcontig;
  45. uint32_t fs_maxbpg;
  46. uint32_t fs_fragshift;
  47. uint32_t fs_fsbtodb;
  48. uint32_t fs_sbsize;
  49. uint32_t fs_csmask;
  50. uint32_t fs_csshift;
  51. uint32_t fs_nindir;
  52. uint32_t fs_inopb;
  53. uint32_t fs_nspf;
  54. uint32_t fs_optim;
  55. uint32_t fs_npsect_state;
  56. uint32_t fs_interleave;
  57. uint32_t fs_trackskew;
  58. uint32_t fs_id[2];
  59. uint32_t fs_csaddr;
  60. uint32_t fs_cssize;
  61. uint32_t fs_cgsize;
  62. uint32_t fs_ntrak;
  63. uint32_t fs_nsect;
  64. uint32_t fs_spc;
  65. uint32_t fs_ncyl;
  66. uint32_t fs_cpg;
  67. uint32_t fs_ipg;
  68. uint32_t fs_fpg;
  69. struct ufs_csum {
  70. uint32_t cs_ndir;
  71. uint32_t cs_nbfree;
  72. uint32_t cs_nifree;
  73. uint32_t cs_nffree;
  74. } PACKED fs_cstotal;
  75. int8_t fs_fmod;
  76. int8_t fs_clean;
  77. int8_t fs_ronly;
  78. int8_t fs_flags;
  79. union {
  80. struct {
  81. int8_t fs_fsmnt[512];
  82. uint32_t fs_cgrotor;
  83. uint32_t fs_csp[31];
  84. uint32_t fs_maxcluster;
  85. uint32_t fs_cpc;
  86. uint16_t fs_opostbl[16][8];
  87. } PACKED fs_u1;
  88. struct {
  89. int8_t fs_fsmnt[468];
  90. uint8_t fs_volname[32];
  91. uint64_t fs_swuid;
  92. int32_t fs_pad;
  93. uint32_t fs_cgrotor;
  94. uint32_t fs_ocsp[28];
  95. uint32_t fs_contigdirs;
  96. uint32_t fs_csp;
  97. uint32_t fs_maxcluster;
  98. uint32_t fs_active;
  99. int32_t fs_old_cpc;
  100. int32_t fs_maxbsize;
  101. int64_t fs_sparecon64[17];
  102. int64_t fs_sblockloc;
  103. struct ufs2_csum_total {
  104. uint64_t cs_ndir;
  105. uint64_t cs_nbfree;
  106. uint64_t cs_nifree;
  107. uint64_t cs_nffree;
  108. uint64_t cs_numclusters;
  109. uint64_t cs_spare[3];
  110. } PACKED fs_cstotal;
  111. struct ufs_timeval {
  112. int32_t tv_sec;
  113. int32_t tv_usec;
  114. } PACKED fs_time;
  115. int64_t fs_size;
  116. int64_t fs_dsize;
  117. uint64_t fs_csaddr;
  118. int64_t fs_pendingblocks;
  119. int32_t fs_pendinginodes;
  120. } PACKED fs_u2;
  121. } fs_u11;
  122. union {
  123. struct {
  124. int32_t fs_sparecon[53];
  125. int32_t fs_reclaim;
  126. int32_t fs_sparecon2[1];
  127. int32_t fs_state;
  128. uint32_t fs_qbmask[2];
  129. uint32_t fs_qfmask[2];
  130. } PACKED fs_sun;
  131. struct {
  132. int32_t fs_sparecon[53];
  133. int32_t fs_reclaim;
  134. int32_t fs_sparecon2[1];
  135. uint32_t fs_npsect;
  136. uint32_t fs_qbmask[2];
  137. uint32_t fs_qfmask[2];
  138. } PACKED fs_sunx86;
  139. struct {
  140. int32_t fs_sparecon[50];
  141. int32_t fs_contigsumsize;
  142. int32_t fs_maxsymlinklen;
  143. int32_t fs_inodefmt;
  144. uint32_t fs_maxfilesize[2];
  145. uint32_t fs_qbmask[2];
  146. uint32_t fs_qfmask[2];
  147. int32_t fs_state;
  148. } PACKED fs_44;
  149. } fs_u2;
  150. int32_t fs_postblformat;
  151. int32_t fs_nrpos;
  152. int32_t fs_postbloff;
  153. int32_t fs_rotbloff;
  154. uint32_t fs_magic;
  155. uint8_t fs_space[1];
  156. } PACKED;
  157. #define UFS_MAGIC 0x00011954
  158. #define UFS2_MAGIC 0x19540119
  159. #define UFS_MAGIC_FEA 0x00195612
  160. #define UFS_MAGIC_LFN 0x00095014
  161. int FAST_FUNC volume_id_probe_ufs(struct volume_id *id, uint64_t off)
  162. {
  163. static const short offsets[] = { 0, 8, 64, 256 };
  164. uint32_t magic;
  165. unsigned i;
  166. struct ufs_super_block *ufs;
  167. dbg("probing at offset 0x%llx", (unsigned long long) off);
  168. for (i = 0; i < ARRAY_SIZE(offsets); i++) {
  169. ufs = volume_id_get_buffer(id, off + (offsets[i] * 0x400), 0x800);
  170. if (ufs == NULL)
  171. return -1;
  172. dbg("offset 0x%x", offsets[i] * 0x400);
  173. magic = ufs->fs_magic;
  174. if ((magic == cpu_to_be32(UFS_MAGIC))
  175. || (magic == cpu_to_be32(UFS2_MAGIC))
  176. || (magic == cpu_to_be32(UFS_MAGIC_FEA))
  177. || (magic == cpu_to_be32(UFS_MAGIC_LFN))
  178. ) {
  179. dbg("magic 0x%08x(be)", magic);
  180. goto found;
  181. }
  182. if ((magic == cpu_to_le32(UFS_MAGIC))
  183. || (magic == cpu_to_le32(UFS2_MAGIC))
  184. || (magic == cpu_to_le32(UFS_MAGIC_FEA))
  185. || (magic == cpu_to_le32(UFS_MAGIC_LFN))
  186. ) {
  187. dbg("magic 0x%08x(le)", magic);
  188. goto found;
  189. }
  190. }
  191. return -1;
  192. found:
  193. // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
  194. // id->type = "ufs";
  195. return 0;
  196. }