unused_ufs.c 5.2 KB

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