diff options
author | Christoph Hellwig <hch@lst.de> | 2016-07-19 21:48:31 -0400 |
---|---|---|
committer | Dave Chinner <david@fromorbit.com> | 2016-07-19 21:48:31 -0400 |
commit | 266b6969c3dfd3c81d8601754c8b0e25bb52615b (patch) | |
tree | 364f50458253497ff5c06d0411cb077b89700daf | |
parent | 8353a649f577a5d775f4666a31b286b8a5156dfb (diff) |
xfs: kill xfs_dir2_inou_t
And use an array of unsigned char values directly to avoid problems
with architectures that pad the size of structures. This also gets
rid of the xfs_dir2_ino4_t and xfs_dir2_ino8_t types, and introduces
new constants for the size of 4 and 8 bytes as well as the size
difference between the two.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
-rw-r--r-- | fs/xfs/libxfs/xfs_da_format.c | 31 | ||||
-rw-r--r-- | fs/xfs/libxfs/xfs_da_format.h | 27 | ||||
-rw-r--r-- | fs/xfs/libxfs/xfs_dir2_sf.c | 25 | ||||
-rw-r--r-- | fs/xfs/xfs_ondisk.h | 3 |
4 files changed, 26 insertions, 60 deletions
diff --git a/fs/xfs/libxfs/xfs_da_format.c b/fs/xfs/libxfs/xfs_da_format.c index 9d624a622946..f1e8d4dbb600 100644 --- a/fs/xfs/libxfs/xfs_da_format.c +++ b/fs/xfs/libxfs/xfs_da_format.c | |||
@@ -40,8 +40,7 @@ xfs_dir2_sf_entsize( | |||
40 | int count = sizeof(struct xfs_dir2_sf_entry); /* namelen + offset */ | 40 | int count = sizeof(struct xfs_dir2_sf_entry); /* namelen + offset */ |
41 | 41 | ||
42 | count += len; /* name */ | 42 | count += len; /* name */ |
43 | count += hdr->i8count ? sizeof(xfs_dir2_ino8_t) : | 43 | count += hdr->i8count ? XFS_INO64_SIZE : XFS_INO32_SIZE; /* ino # */ |
44 | sizeof(xfs_dir2_ino4_t); /* ino # */ | ||
45 | return count; | 44 | return count; |
46 | } | 45 | } |
47 | 46 | ||
@@ -125,33 +124,33 @@ xfs_dir3_sfe_put_ftype( | |||
125 | static xfs_ino_t | 124 | static xfs_ino_t |
126 | xfs_dir2_sf_get_ino( | 125 | xfs_dir2_sf_get_ino( |
127 | struct xfs_dir2_sf_hdr *hdr, | 126 | struct xfs_dir2_sf_hdr *hdr, |
128 | xfs_dir2_inou_t *from) | 127 | __uint8_t *from) |
129 | { | 128 | { |
130 | if (hdr->i8count) | 129 | if (hdr->i8count) |
131 | return get_unaligned_be64(&from->i8.i) & 0x00ffffffffffffffULL; | 130 | return get_unaligned_be64(from) & 0x00ffffffffffffffULL; |
132 | else | 131 | else |
133 | return get_unaligned_be32(&from->i4.i); | 132 | return get_unaligned_be32(from); |
134 | } | 133 | } |
135 | 134 | ||
136 | static void | 135 | static void |
137 | xfs_dir2_sf_put_ino( | 136 | xfs_dir2_sf_put_ino( |
138 | struct xfs_dir2_sf_hdr *hdr, | 137 | struct xfs_dir2_sf_hdr *hdr, |
139 | xfs_dir2_inou_t *to, | 138 | __uint8_t *to, |
140 | xfs_ino_t ino) | 139 | xfs_ino_t ino) |
141 | { | 140 | { |
142 | ASSERT((ino & 0xff00000000000000ULL) == 0); | 141 | ASSERT((ino & 0xff00000000000000ULL) == 0); |
143 | 142 | ||
144 | if (hdr->i8count) | 143 | if (hdr->i8count) |
145 | put_unaligned_be64(ino, &to->i8.i); | 144 | put_unaligned_be64(ino, to); |
146 | else | 145 | else |
147 | put_unaligned_be32(ino, &to->i4.i); | 146 | put_unaligned_be32(ino, to); |
148 | } | 147 | } |
149 | 148 | ||
150 | static xfs_ino_t | 149 | static xfs_ino_t |
151 | xfs_dir2_sf_get_parent_ino( | 150 | xfs_dir2_sf_get_parent_ino( |
152 | struct xfs_dir2_sf_hdr *hdr) | 151 | struct xfs_dir2_sf_hdr *hdr) |
153 | { | 152 | { |
154 | return xfs_dir2_sf_get_ino(hdr, &hdr->parent); | 153 | return xfs_dir2_sf_get_ino(hdr, hdr->parent); |
155 | } | 154 | } |
156 | 155 | ||
157 | static void | 156 | static void |
@@ -159,7 +158,7 @@ xfs_dir2_sf_put_parent_ino( | |||
159 | struct xfs_dir2_sf_hdr *hdr, | 158 | struct xfs_dir2_sf_hdr *hdr, |
160 | xfs_ino_t ino) | 159 | xfs_ino_t ino) |
161 | { | 160 | { |
162 | xfs_dir2_sf_put_ino(hdr, &hdr->parent, ino); | 161 | xfs_dir2_sf_put_ino(hdr, hdr->parent, ino); |
163 | } | 162 | } |
164 | 163 | ||
165 | /* | 164 | /* |
@@ -173,8 +172,7 @@ xfs_dir2_sfe_get_ino( | |||
173 | struct xfs_dir2_sf_hdr *hdr, | 172 | struct xfs_dir2_sf_hdr *hdr, |
174 | struct xfs_dir2_sf_entry *sfep) | 173 | struct xfs_dir2_sf_entry *sfep) |
175 | { | 174 | { |
176 | return xfs_dir2_sf_get_ino(hdr, | 175 | return xfs_dir2_sf_get_ino(hdr, &sfep->name[sfep->namelen]); |
177 | (xfs_dir2_inou_t *)&sfep->name[sfep->namelen]); | ||
178 | } | 176 | } |
179 | 177 | ||
180 | static void | 178 | static void |
@@ -183,8 +181,7 @@ xfs_dir2_sfe_put_ino( | |||
183 | struct xfs_dir2_sf_entry *sfep, | 181 | struct xfs_dir2_sf_entry *sfep, |
184 | xfs_ino_t ino) | 182 | xfs_ino_t ino) |
185 | { | 183 | { |
186 | xfs_dir2_sf_put_ino(hdr, | 184 | xfs_dir2_sf_put_ino(hdr, &sfep->name[sfep->namelen], ino); |
187 | (xfs_dir2_inou_t *)&sfep->name[sfep->namelen], ino); | ||
188 | } | 185 | } |
189 | 186 | ||
190 | static xfs_ino_t | 187 | static xfs_ino_t |
@@ -192,8 +189,7 @@ xfs_dir3_sfe_get_ino( | |||
192 | struct xfs_dir2_sf_hdr *hdr, | 189 | struct xfs_dir2_sf_hdr *hdr, |
193 | struct xfs_dir2_sf_entry *sfep) | 190 | struct xfs_dir2_sf_entry *sfep) |
194 | { | 191 | { |
195 | return xfs_dir2_sf_get_ino(hdr, | 192 | return xfs_dir2_sf_get_ino(hdr, &sfep->name[sfep->namelen + 1]); |
196 | (xfs_dir2_inou_t *)&sfep->name[sfep->namelen + 1]); | ||
197 | } | 193 | } |
198 | 194 | ||
199 | static void | 195 | static void |
@@ -202,8 +198,7 @@ xfs_dir3_sfe_put_ino( | |||
202 | struct xfs_dir2_sf_entry *sfep, | 198 | struct xfs_dir2_sf_entry *sfep, |
203 | xfs_ino_t ino) | 199 | xfs_ino_t ino) |
204 | { | 200 | { |
205 | xfs_dir2_sf_put_ino(hdr, | 201 | xfs_dir2_sf_put_ino(hdr, &sfep->name[sfep->namelen + 1], ino); |
206 | (xfs_dir2_inou_t *)&sfep->name[sfep->namelen + 1], ino); | ||
207 | } | 202 | } |
208 | 203 | ||
209 | 204 | ||
diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h index a5f4d6ee2bb3..f877bb17c6c3 100644 --- a/fs/xfs/libxfs/xfs_da_format.h +++ b/fs/xfs/libxfs/xfs_da_format.h | |||
@@ -208,22 +208,10 @@ typedef xfs_off_t xfs_dir2_off_t; | |||
208 | */ | 208 | */ |
209 | typedef __uint32_t xfs_dir2_db_t; | 209 | typedef __uint32_t xfs_dir2_db_t; |
210 | 210 | ||
211 | /* | 211 | #define XFS_INO32_SIZE 4 |
212 | * Inode number stored as 8 8-bit values. | 212 | #define XFS_INO64_SIZE 8 |
213 | */ | 213 | #define XFS_INO64_DIFF (XFS_INO64_SIZE - XFS_INO32_SIZE) |
214 | typedef struct { __uint8_t i[8]; } xfs_dir2_ino8_t; | ||
215 | |||
216 | /* | ||
217 | * Inode number stored as 4 8-bit values. | ||
218 | * Works a lot of the time, when all the inode numbers in a directory | ||
219 | * fit in 32 bits. | ||
220 | */ | ||
221 | typedef struct { __uint8_t i[4]; } xfs_dir2_ino4_t; | ||
222 | 214 | ||
223 | typedef union { | ||
224 | xfs_dir2_ino8_t i8; | ||
225 | xfs_dir2_ino4_t i4; | ||
226 | } xfs_dir2_inou_t; | ||
227 | #define XFS_DIR2_MAX_SHORT_INUM ((xfs_ino_t)0xffffffffULL) | 215 | #define XFS_DIR2_MAX_SHORT_INUM ((xfs_ino_t)0xffffffffULL) |
228 | 216 | ||
229 | /* | 217 | /* |
@@ -240,7 +228,7 @@ typedef union { | |||
240 | typedef struct xfs_dir2_sf_hdr { | 228 | typedef struct xfs_dir2_sf_hdr { |
241 | __uint8_t count; /* count of entries */ | 229 | __uint8_t count; /* count of entries */ |
242 | __uint8_t i8count; /* count of 8-byte inode #s */ | 230 | __uint8_t i8count; /* count of 8-byte inode #s */ |
243 | xfs_dir2_inou_t parent; /* parent dir inode number */ | 231 | __uint8_t parent[8]; /* parent dir inode number */ |
244 | } __arch_pack xfs_dir2_sf_hdr_t; | 232 | } __arch_pack xfs_dir2_sf_hdr_t; |
245 | 233 | ||
246 | typedef struct xfs_dir2_sf_entry { | 234 | typedef struct xfs_dir2_sf_entry { |
@@ -251,16 +239,15 @@ typedef struct xfs_dir2_sf_entry { | |||
251 | * A single byte containing the file type field follows the inode | 239 | * A single byte containing the file type field follows the inode |
252 | * number for version 3 directory entries. | 240 | * number for version 3 directory entries. |
253 | * | 241 | * |
254 | * A xfs_dir2_ino8_t or xfs_dir2_ino4_t follows here, at a | 242 | * A 64-bit or 32-bit inode number follows here, at a variable offset |
255 | * variable offset after the name. | 243 | * after the name. |
256 | */ | 244 | */ |
257 | } xfs_dir2_sf_entry_t; | 245 | } xfs_dir2_sf_entry_t; |
258 | 246 | ||
259 | static inline int xfs_dir2_sf_hdr_size(int i8count) | 247 | static inline int xfs_dir2_sf_hdr_size(int i8count) |
260 | { | 248 | { |
261 | return sizeof(struct xfs_dir2_sf_hdr) - | 249 | return sizeof(struct xfs_dir2_sf_hdr) - |
262 | (i8count == 0) * | 250 | (i8count == 0) * XFS_INO64_DIFF; |
263 | (sizeof(xfs_dir2_ino8_t) - sizeof(xfs_dir2_ino4_t)); | ||
264 | } | 251 | } |
265 | 252 | ||
266 | static inline xfs_dir2_data_aoff_t | 253 | static inline xfs_dir2_data_aoff_t |
diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index f8ccfd5a0477..c6809ff41197 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c | |||
@@ -130,8 +130,8 @@ xfs_dir2_block_sfsize( | |||
130 | count * 3 * sizeof(u8) + /* namelen + offset */ | 130 | count * 3 * sizeof(u8) + /* namelen + offset */ |
131 | namelen + /* name */ | 131 | namelen + /* name */ |
132 | (i8count ? /* inumber */ | 132 | (i8count ? /* inumber */ |
133 | (uint)sizeof(xfs_dir2_ino8_t) * count : | 133 | count * XFS_INO64_SIZE : |
134 | (uint)sizeof(xfs_dir2_ino4_t) * count); | 134 | count * XFS_INO32_SIZE); |
135 | if (size > XFS_IFORK_DSIZE(dp)) | 135 | if (size > XFS_IFORK_DSIZE(dp)) |
136 | return size; /* size value is a failure */ | 136 | return size; /* size value is a failure */ |
137 | } | 137 | } |
@@ -318,10 +318,7 @@ xfs_dir2_sf_addname( | |||
318 | /* | 318 | /* |
319 | * Yes, adjust the inode size. old count + (parent + new) | 319 | * Yes, adjust the inode size. old count + (parent + new) |
320 | */ | 320 | */ |
321 | incr_isize += | 321 | incr_isize += (sfp->count + 2) * XFS_INO64_DIFF; |
322 | (sfp->count + 2) * | ||
323 | ((uint)sizeof(xfs_dir2_ino8_t) - | ||
324 | (uint)sizeof(xfs_dir2_ino4_t)); | ||
325 | objchange = 1; | 322 | objchange = 1; |
326 | } | 323 | } |
327 | 324 | ||
@@ -896,11 +893,7 @@ xfs_dir2_sf_replace( | |||
896 | int error; /* error return value */ | 893 | int error; /* error return value */ |
897 | int newsize; /* new inode size */ | 894 | int newsize; /* new inode size */ |
898 | 895 | ||
899 | newsize = | 896 | newsize = dp->i_df.if_bytes + (sfp->count + 1) * XFS_INO64_DIFF; |
900 | dp->i_df.if_bytes + | ||
901 | (sfp->count + 1) * | ||
902 | ((uint)sizeof(xfs_dir2_ino8_t) - | ||
903 | (uint)sizeof(xfs_dir2_ino4_t)); | ||
904 | /* | 897 | /* |
905 | * Won't fit as shortform, convert to block then do replace. | 898 | * Won't fit as shortform, convert to block then do replace. |
906 | */ | 899 | */ |
@@ -1021,10 +1014,7 @@ xfs_dir2_sf_toino4( | |||
1021 | /* | 1014 | /* |
1022 | * Compute the new inode size. | 1015 | * Compute the new inode size. |
1023 | */ | 1016 | */ |
1024 | newsize = | 1017 | newsize = oldsize - (oldsfp->count + 1) * XFS_INO64_DIFF; |
1025 | oldsize - | ||
1026 | (oldsfp->count + 1) * | ||
1027 | ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t)); | ||
1028 | xfs_idata_realloc(dp, -oldsize, XFS_DATA_FORK); | 1018 | xfs_idata_realloc(dp, -oldsize, XFS_DATA_FORK); |
1029 | xfs_idata_realloc(dp, newsize, XFS_DATA_FORK); | 1019 | xfs_idata_realloc(dp, newsize, XFS_DATA_FORK); |
1030 | /* | 1020 | /* |
@@ -1097,10 +1087,7 @@ xfs_dir2_sf_toino8( | |||
1097 | /* | 1087 | /* |
1098 | * Compute the new inode size (nb: entry count + 1 for parent) | 1088 | * Compute the new inode size (nb: entry count + 1 for parent) |
1099 | */ | 1089 | */ |
1100 | newsize = | 1090 | newsize = oldsize + (oldsfp->count + 1) * XFS_INO64_DIFF; |
1101 | oldsize + | ||
1102 | (oldsfp->count + 1) * | ||
1103 | ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t)); | ||
1104 | xfs_idata_realloc(dp, -oldsize, XFS_DATA_FORK); | 1091 | xfs_idata_realloc(dp, -oldsize, XFS_DATA_FORK); |
1105 | xfs_idata_realloc(dp, newsize, XFS_DATA_FORK); | 1092 | xfs_idata_realloc(dp, newsize, XFS_DATA_FORK); |
1106 | /* | 1093 | /* |
diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/xfs_ondisk.h index 918f13c5dd58..19cc8b872db1 100644 --- a/fs/xfs/xfs_ondisk.h +++ b/fs/xfs/xfs_ondisk.h | |||
@@ -86,9 +86,6 @@ xfs_check_ondisk_structs(void) | |||
86 | XFS_CHECK_STRUCT_SIZE(xfs_dir2_data_unused_t, 6); | 86 | XFS_CHECK_STRUCT_SIZE(xfs_dir2_data_unused_t, 6); |
87 | XFS_CHECK_STRUCT_SIZE(xfs_dir2_free_hdr_t, 16); | 87 | XFS_CHECK_STRUCT_SIZE(xfs_dir2_free_hdr_t, 16); |
88 | XFS_CHECK_STRUCT_SIZE(xfs_dir2_free_t, 16); | 88 | XFS_CHECK_STRUCT_SIZE(xfs_dir2_free_t, 16); |
89 | XFS_CHECK_STRUCT_SIZE(xfs_dir2_ino4_t, 4); | ||
90 | XFS_CHECK_STRUCT_SIZE(xfs_dir2_ino8_t, 8); | ||
91 | XFS_CHECK_STRUCT_SIZE(xfs_dir2_inou_t, 8); | ||
92 | XFS_CHECK_STRUCT_SIZE(xfs_dir2_leaf_entry_t, 8); | 89 | XFS_CHECK_STRUCT_SIZE(xfs_dir2_leaf_entry_t, 8); |
93 | XFS_CHECK_STRUCT_SIZE(xfs_dir2_leaf_hdr_t, 16); | 90 | XFS_CHECK_STRUCT_SIZE(xfs_dir2_leaf_hdr_t, 16); |
94 | XFS_CHECK_STRUCT_SIZE(xfs_dir2_leaf_t, 16); | 91 | XFS_CHECK_STRUCT_SIZE(xfs_dir2_leaf_t, 16); |