unused_ufs.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. //kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_UFS) += ufs.o
  21. //config:### config FEATURE_VOLUMEID_UFS
  22. //config:### bool "ufs filesystem"
  23. //config:### default y
  24. //config:### depends on VOLUMEID
  25. #include "volume_id_internal.h"
  26. struct ufs_super_block {
  27. uint32_t fs_link;
  28. uint32_t fs_rlink;
  29. uint32_t fs_sblkno;
  30. uint32_t fs_cblkno;
  31. uint32_t fs_iblkno;
  32. uint32_t fs_dblkno;
  33. uint32_t fs_cgoffset;
  34. uint32_t fs_cgmask;
  35. uint32_t fs_time;
  36. uint32_t fs_size;
  37. uint32_t fs_dsize;
  38. uint32_t fs_ncg;
  39. uint32_t fs_bsize;
  40. uint32_t fs_fsize;
  41. uint32_t fs_frag;
  42. uint32_t fs_minfree;
  43. uint32_t fs_rotdelay;
  44. uint32_t fs_rps;
  45. uint32_t fs_bmask;
  46. uint32_t fs_fmask;
  47. uint32_t fs_bshift;
  48. uint32_t fs_fshift;
  49. uint32_t fs_maxcontig;
  50. uint32_t fs_maxbpg;
  51. uint32_t fs_fragshift;
  52. uint32_t fs_fsbtodb;
  53. uint32_t fs_sbsize;
  54. uint32_t fs_csmask;
  55. uint32_t fs_csshift;
  56. uint32_t fs_nindir;
  57. uint32_t fs_inopb;
  58. uint32_t fs_nspf;
  59. uint32_t fs_optim;
  60. uint32_t fs_npsect_state;
  61. uint32_t fs_interleave;
  62. uint32_t fs_trackskew;
  63. uint32_t fs_id[2];
  64. uint32_t fs_csaddr;
  65. uint32_t fs_cssize;
  66. uint32_t fs_cgsize;
  67. uint32_t fs_ntrak;
  68. uint32_t fs_nsect;
  69. uint32_t fs_spc;
  70. uint32_t fs_ncyl;
  71. uint32_t fs_cpg;
  72. uint32_t fs_ipg;
  73. uint32_t fs_fpg;
  74. struct ufs_csum {
  75. uint32_t cs_ndir;
  76. uint32_t cs_nbfree;
  77. uint32_t cs_nifree;
  78. uint32_t cs_nffree;
  79. } PACKED fs_cstotal;
  80. int8_t fs_fmod;
  81. int8_t fs_clean;
  82. int8_t fs_ronly;
  83. int8_t fs_flags;
  84. union {
  85. struct {
  86. int8_t fs_fsmnt[512];
  87. uint32_t fs_cgrotor;
  88. uint32_t fs_csp[31];
  89. uint32_t fs_maxcluster;
  90. uint32_t fs_cpc;
  91. uint16_t fs_opostbl[16][8];
  92. } PACKED fs_u1;
  93. struct {
  94. int8_t fs_fsmnt[468];
  95. uint8_t fs_volname[32];
  96. uint64_t fs_swuid;
  97. int32_t fs_pad;
  98. uint32_t fs_cgrotor;
  99. uint32_t fs_ocsp[28];
  100. uint32_t fs_contigdirs;
  101. uint32_t fs_csp;
  102. uint32_t fs_maxcluster;
  103. uint32_t fs_active;
  104. int32_t fs_old_cpc;
  105. int32_t fs_maxbsize;
  106. int64_t fs_sparecon64[17];
  107. int64_t fs_sblockloc;
  108. struct ufs2_csum_total {
  109. uint64_t cs_ndir;
  110. uint64_t cs_nbfree;
  111. uint64_t cs_nifree;
  112. uint64_t cs_nffree;
  113. uint64_t cs_numclusters;
  114. uint64_t cs_spare[3];
  115. } PACKED fs_cstotal;
  116. struct ufs_timeval {
  117. int32_t tv_sec;
  118. int32_t tv_usec;
  119. } PACKED fs_time;
  120. int64_t fs_size;
  121. int64_t fs_dsize;
  122. uint64_t fs_csaddr;
  123. int64_t fs_pendingblocks;
  124. int32_t fs_pendinginodes;
  125. } PACKED fs_u2;
  126. } fs_u11;
  127. union {
  128. struct {
  129. int32_t fs_sparecon[53];
  130. int32_t fs_reclaim;
  131. int32_t fs_sparecon2[1];
  132. int32_t fs_state;
  133. uint32_t fs_qbmask[2];
  134. uint32_t fs_qfmask[2];
  135. } PACKED fs_sun;
  136. struct {
  137. int32_t fs_sparecon[53];
  138. int32_t fs_reclaim;
  139. int32_t fs_sparecon2[1];
  140. uint32_t fs_npsect;
  141. uint32_t fs_qbmask[2];
  142. uint32_t fs_qfmask[2];
  143. } PACKED fs_sunx86;
  144. struct {
  145. int32_t fs_sparecon[50];
  146. int32_t fs_contigsumsize;
  147. int32_t fs_maxsymlinklen;
  148. int32_t fs_inodefmt;
  149. uint32_t fs_maxfilesize[2];
  150. uint32_t fs_qbmask[2];
  151. uint32_t fs_qfmask[2];
  152. int32_t fs_state;
  153. } PACKED fs_44;
  154. } fs_u2;
  155. int32_t fs_postblformat;
  156. int32_t fs_nrpos;
  157. int32_t fs_postbloff;
  158. int32_t fs_rotbloff;
  159. uint32_t fs_magic;
  160. uint8_t fs_space[1];
  161. } PACKED;
  162. #define UFS_MAGIC 0x00011954
  163. #define UFS2_MAGIC 0x19540119
  164. #define UFS_MAGIC_FEA 0x00195612
  165. #define UFS_MAGIC_LFN 0x00095014
  166. int FAST_FUNC volume_id_probe_ufs(struct volume_id *id, uint64_t off)
  167. {
  168. static const short offsets[] = { 0, 8, 64, 256 };
  169. uint32_t magic;
  170. unsigned i;
  171. struct ufs_super_block *ufs;
  172. dbg("probing at offset 0x%llx", (unsigned long long) off);
  173. for (i = 0; i < ARRAY_SIZE(offsets); i++) {
  174. ufs = volume_id_get_buffer(id, off + (offsets[i] * 0x400), 0x800);
  175. if (ufs == NULL)
  176. return -1;
  177. dbg("offset 0x%x", offsets[i] * 0x400);
  178. magic = ufs->fs_magic;
  179. if ((magic == cpu_to_be32(UFS_MAGIC))
  180. || (magic == cpu_to_be32(UFS2_MAGIC))
  181. || (magic == cpu_to_be32(UFS_MAGIC_FEA))
  182. || (magic == cpu_to_be32(UFS_MAGIC_LFN))
  183. ) {
  184. dbg("magic 0x%08x(be)", magic);
  185. goto found;
  186. }
  187. if ((magic == cpu_to_le32(UFS_MAGIC))
  188. || (magic == cpu_to_le32(UFS2_MAGIC))
  189. || (magic == cpu_to_le32(UFS_MAGIC_FEA))
  190. || (magic == cpu_to_le32(UFS_MAGIC_LFN))
  191. ) {
  192. dbg("magic 0x%08x(le)", magic);
  193. goto found;
  194. }
  195. }
  196. return -1;
  197. found:
  198. // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
  199. // id->type = "ufs";
  200. return 0;
  201. }