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