aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_dir2_data.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_dir2_data.c')
-rw-r--r--fs/xfs/xfs_dir2_data.c240
1 files changed, 122 insertions, 118 deletions
diff --git a/fs/xfs/xfs_dir2_data.c b/fs/xfs/xfs_dir2_data.c
index 5b7c47e2f14a..bb3d03ff002b 100644
--- a/fs/xfs/xfs_dir2_data.c
+++ b/fs/xfs/xfs_dir2_data.c
@@ -70,11 +70,11 @@ xfs_dir2_data_check(
70 70
71 mp = dp->i_mount; 71 mp = dp->i_mount;
72 d = bp->data; 72 d = bp->data;
73 ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC || 73 ASSERT(be32_to_cpu(d->hdr.magic) == XFS_DIR2_DATA_MAGIC ||
74 INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC); 74 be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC);
75 bf = d->hdr.bestfree; 75 bf = d->hdr.bestfree;
76 p = (char *)d->u; 76 p = (char *)d->u;
77 if (INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC) { 77 if (be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC) {
78 btp = XFS_DIR2_BLOCK_TAIL_P(mp, (xfs_dir2_block_t *)d); 78 btp = XFS_DIR2_BLOCK_TAIL_P(mp, (xfs_dir2_block_t *)d);
79 lep = XFS_DIR2_BLOCK_LEAF_P(btp); 79 lep = XFS_DIR2_BLOCK_LEAF_P(btp);
80 endp = (char *)lep; 80 endp = (char *)lep;
@@ -96,8 +96,8 @@ xfs_dir2_data_check(
96 ASSERT(!bf[2].offset); 96 ASSERT(!bf[2].offset);
97 freeseen |= 1 << 2; 97 freeseen |= 1 << 2;
98 } 98 }
99 ASSERT(INT_GET(bf[0].length, ARCH_CONVERT) >= INT_GET(bf[1].length, ARCH_CONVERT)); 99 ASSERT(be16_to_cpu(bf[0].length) >= be16_to_cpu(bf[1].length));
100 ASSERT(INT_GET(bf[1].length, ARCH_CONVERT) >= INT_GET(bf[2].length, ARCH_CONVERT)); 100 ASSERT(be16_to_cpu(bf[1].length) >= be16_to_cpu(bf[2].length));
101 /* 101 /*
102 * Loop over the data/unused entries. 102 * Loop over the data/unused entries.
103 */ 103 */
@@ -108,18 +108,20 @@ xfs_dir2_data_check(
108 * If we find it, account for that, else make sure it 108 * If we find it, account for that, else make sure it
109 * doesn't need to be there. 109 * doesn't need to be there.
110 */ 110 */
111 if (INT_GET(dup->freetag, ARCH_CONVERT) == XFS_DIR2_DATA_FREE_TAG) { 111 if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
112 ASSERT(lastfree == 0); 112 ASSERT(lastfree == 0);
113 ASSERT(INT_GET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT) == 113 ASSERT(be16_to_cpu(*XFS_DIR2_DATA_UNUSED_TAG_P(dup)) ==
114 (char *)dup - (char *)d); 114 (char *)dup - (char *)d);
115 dfp = xfs_dir2_data_freefind(d, dup); 115 dfp = xfs_dir2_data_freefind(d, dup);
116 if (dfp) { 116 if (dfp) {
117 i = (int)(dfp - bf); 117 i = (int)(dfp - bf);
118 ASSERT((freeseen & (1 << i)) == 0); 118 ASSERT((freeseen & (1 << i)) == 0);
119 freeseen |= 1 << i; 119 freeseen |= 1 << i;
120 } else 120 } else {
121 ASSERT(INT_GET(dup->length, ARCH_CONVERT) <= INT_GET(bf[2].length, ARCH_CONVERT)); 121 ASSERT(be16_to_cpu(dup->length) <=
122 p += INT_GET(dup->length, ARCH_CONVERT); 122 be16_to_cpu(bf[2].length));
123 }
124 p += be16_to_cpu(dup->length);
123 lastfree = 1; 125 lastfree = 1;
124 continue; 126 continue;
125 } 127 }
@@ -132,21 +134,21 @@ xfs_dir2_data_check(
132 dep = (xfs_dir2_data_entry_t *)p; 134 dep = (xfs_dir2_data_entry_t *)p;
133 ASSERT(dep->namelen != 0); 135 ASSERT(dep->namelen != 0);
134 ASSERT(xfs_dir_ino_validate(mp, INT_GET(dep->inumber, ARCH_CONVERT)) == 0); 136 ASSERT(xfs_dir_ino_validate(mp, INT_GET(dep->inumber, ARCH_CONVERT)) == 0);
135 ASSERT(INT_GET(*XFS_DIR2_DATA_ENTRY_TAG_P(dep), ARCH_CONVERT) == 137 ASSERT(be16_to_cpu(*XFS_DIR2_DATA_ENTRY_TAG_P(dep)) ==
136 (char *)dep - (char *)d); 138 (char *)dep - (char *)d);
137 count++; 139 count++;
138 lastfree = 0; 140 lastfree = 0;
139 if (INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC) { 141 if (be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC) {
140 addr = XFS_DIR2_DB_OFF_TO_DATAPTR(mp, mp->m_dirdatablk, 142 addr = XFS_DIR2_DB_OFF_TO_DATAPTR(mp, mp->m_dirdatablk,
141 (xfs_dir2_data_aoff_t) 143 (xfs_dir2_data_aoff_t)
142 ((char *)dep - (char *)d)); 144 ((char *)dep - (char *)d));
143 hash = xfs_da_hashname((char *)dep->name, dep->namelen); 145 hash = xfs_da_hashname((char *)dep->name, dep->namelen);
144 for (i = 0; i < INT_GET(btp->count, ARCH_CONVERT); i++) { 146 for (i = 0; i < be32_to_cpu(btp->count); i++) {
145 if (INT_GET(lep[i].address, ARCH_CONVERT) == addr && 147 if (be32_to_cpu(lep[i].address) == addr &&
146 INT_GET(lep[i].hashval, ARCH_CONVERT) == hash) 148 be32_to_cpu(lep[i].hashval) == hash)
147 break; 149 break;
148 } 150 }
149 ASSERT(i < INT_GET(btp->count, ARCH_CONVERT)); 151 ASSERT(i < be32_to_cpu(btp->count));
150 } 152 }
151 p += XFS_DIR2_DATA_ENTSIZE(dep->namelen); 153 p += XFS_DIR2_DATA_ENTSIZE(dep->namelen);
152 } 154 }
@@ -154,15 +156,15 @@ xfs_dir2_data_check(
154 * Need to have seen all the entries and all the bestfree slots. 156 * Need to have seen all the entries and all the bestfree slots.
155 */ 157 */
156 ASSERT(freeseen == 7); 158 ASSERT(freeseen == 7);
157 if (INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC) { 159 if (be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC) {
158 for (i = stale = 0; i < INT_GET(btp->count, ARCH_CONVERT); i++) { 160 for (i = stale = 0; i < be32_to_cpu(btp->count); i++) {
159 if (INT_GET(lep[i].address, ARCH_CONVERT) == XFS_DIR2_NULL_DATAPTR) 161 if (be32_to_cpu(lep[i].address) == XFS_DIR2_NULL_DATAPTR)
160 stale++; 162 stale++;
161 if (i > 0) 163 if (i > 0)
162 ASSERT(INT_GET(lep[i].hashval, ARCH_CONVERT) >= INT_GET(lep[i - 1].hashval, ARCH_CONVERT)); 164 ASSERT(be32_to_cpu(lep[i].hashval) >= be32_to_cpu(lep[i - 1].hashval));
163 } 165 }
164 ASSERT(count == INT_GET(btp->count, ARCH_CONVERT) - INT_GET(btp->stale, ARCH_CONVERT)); 166 ASSERT(count == be32_to_cpu(btp->count) - be32_to_cpu(btp->stale));
165 ASSERT(stale == INT_GET(btp->stale, ARCH_CONVERT)); 167 ASSERT(stale == be32_to_cpu(btp->stale));
166 } 168 }
167} 169}
168#endif 170#endif
@@ -190,8 +192,8 @@ xfs_dir2_data_freefind(
190 * Check order, non-overlapping entries, and if we find the 192 * Check order, non-overlapping entries, and if we find the
191 * one we're looking for it has to be exact. 193 * one we're looking for it has to be exact.
192 */ 194 */
193 ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC || 195 ASSERT(be32_to_cpu(d->hdr.magic) == XFS_DIR2_DATA_MAGIC ||
194 INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC); 196 be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC);
195 for (dfp = &d->hdr.bestfree[0], seenzero = matched = 0; 197 for (dfp = &d->hdr.bestfree[0], seenzero = matched = 0;
196 dfp < &d->hdr.bestfree[XFS_DIR2_DATA_FD_COUNT]; 198 dfp < &d->hdr.bestfree[XFS_DIR2_DATA_FD_COUNT];
197 dfp++) { 199 dfp++) {
@@ -201,23 +203,24 @@ xfs_dir2_data_freefind(
201 continue; 203 continue;
202 } 204 }
203 ASSERT(seenzero == 0); 205 ASSERT(seenzero == 0);
204 if (INT_GET(dfp->offset, ARCH_CONVERT) == off) { 206 if (be16_to_cpu(dfp->offset) == off) {
205 matched = 1; 207 matched = 1;
206 ASSERT(INT_GET(dfp->length, ARCH_CONVERT) == INT_GET(dup->length, ARCH_CONVERT)); 208 ASSERT(dfp->length == dup->length);
207 } else if (off < INT_GET(dfp->offset, ARCH_CONVERT)) 209 } else if (off < be16_to_cpu(dfp->offset))
208 ASSERT(off + INT_GET(dup->length, ARCH_CONVERT) <= INT_GET(dfp->offset, ARCH_CONVERT)); 210 ASSERT(off + be16_to_cpu(dup->length) <= be16_to_cpu(dfp->offset));
209 else 211 else
210 ASSERT(INT_GET(dfp->offset, ARCH_CONVERT) + INT_GET(dfp->length, ARCH_CONVERT) <= off); 212 ASSERT(be16_to_cpu(dfp->offset) + be16_to_cpu(dfp->length) <= off);
211 ASSERT(matched || INT_GET(dfp->length, ARCH_CONVERT) >= INT_GET(dup->length, ARCH_CONVERT)); 213 ASSERT(matched || be16_to_cpu(dfp->length) >= be16_to_cpu(dup->length));
212 if (dfp > &d->hdr.bestfree[0]) 214 if (dfp > &d->hdr.bestfree[0])
213 ASSERT(INT_GET(dfp[-1].length, ARCH_CONVERT) >= INT_GET(dfp[0].length, ARCH_CONVERT)); 215 ASSERT(be16_to_cpu(dfp[-1].length) >= be16_to_cpu(dfp[0].length));
214 } 216 }
215#endif 217#endif
216 /* 218 /*
217 * If this is smaller than the smallest bestfree entry, 219 * If this is smaller than the smallest bestfree entry,
218 * it can't be there since they're sorted. 220 * it can't be there since they're sorted.
219 */ 221 */
220 if (INT_GET(dup->length, ARCH_CONVERT) < INT_GET(d->hdr.bestfree[XFS_DIR2_DATA_FD_COUNT - 1].length, ARCH_CONVERT)) 222 if (be16_to_cpu(dup->length) <
223 be16_to_cpu(d->hdr.bestfree[XFS_DIR2_DATA_FD_COUNT - 1].length))
221 return NULL; 224 return NULL;
222 /* 225 /*
223 * Look at the three bestfree entries for our guy. 226 * Look at the three bestfree entries for our guy.
@@ -227,7 +230,7 @@ xfs_dir2_data_freefind(
227 dfp++) { 230 dfp++) {
228 if (!dfp->offset) 231 if (!dfp->offset)
229 return NULL; 232 return NULL;
230 if (INT_GET(dfp->offset, ARCH_CONVERT) == off) 233 if (be16_to_cpu(dfp->offset) == off)
231 return dfp; 234 return dfp;
232 } 235 }
233 /* 236 /*
@@ -249,29 +252,29 @@ xfs_dir2_data_freeinsert(
249 xfs_dir2_data_free_t new; /* new bestfree entry */ 252 xfs_dir2_data_free_t new; /* new bestfree entry */
250 253
251#ifdef __KERNEL__ 254#ifdef __KERNEL__
252 ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC || 255 ASSERT(be32_to_cpu(d->hdr.magic) == XFS_DIR2_DATA_MAGIC ||
253 INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC); 256 be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC);
254#endif 257#endif
255 dfp = d->hdr.bestfree; 258 dfp = d->hdr.bestfree;
256 INT_COPY(new.length, dup->length, ARCH_CONVERT); 259 new.length = dup->length;
257 INT_SET(new.offset, ARCH_CONVERT, (xfs_dir2_data_off_t)((char *)dup - (char *)d)); 260 new.offset = cpu_to_be16((char *)dup - (char *)d);
258 /* 261 /*
259 * Insert at position 0, 1, or 2; or not at all. 262 * Insert at position 0, 1, or 2; or not at all.
260 */ 263 */
261 if (INT_GET(new.length, ARCH_CONVERT) > INT_GET(dfp[0].length, ARCH_CONVERT)) { 264 if (be16_to_cpu(new.length) > be16_to_cpu(dfp[0].length)) {
262 dfp[2] = dfp[1]; 265 dfp[2] = dfp[1];
263 dfp[1] = dfp[0]; 266 dfp[1] = dfp[0];
264 dfp[0] = new; 267 dfp[0] = new;
265 *loghead = 1; 268 *loghead = 1;
266 return &dfp[0]; 269 return &dfp[0];
267 } 270 }
268 if (INT_GET(new.length, ARCH_CONVERT) > INT_GET(dfp[1].length, ARCH_CONVERT)) { 271 if (be16_to_cpu(new.length) > be16_to_cpu(dfp[1].length)) {
269 dfp[2] = dfp[1]; 272 dfp[2] = dfp[1];
270 dfp[1] = new; 273 dfp[1] = new;
271 *loghead = 1; 274 *loghead = 1;
272 return &dfp[1]; 275 return &dfp[1];
273 } 276 }
274 if (INT_GET(new.length, ARCH_CONVERT) > INT_GET(dfp[2].length, ARCH_CONVERT)) { 277 if (be16_to_cpu(new.length) > be16_to_cpu(dfp[2].length)) {
275 dfp[2] = new; 278 dfp[2] = new;
276 *loghead = 1; 279 *loghead = 1;
277 return &dfp[2]; 280 return &dfp[2];
@@ -289,8 +292,8 @@ xfs_dir2_data_freeremove(
289 int *loghead) /* out: log data header */ 292 int *loghead) /* out: log data header */
290{ 293{
291#ifdef __KERNEL__ 294#ifdef __KERNEL__
292 ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC || 295 ASSERT(be32_to_cpu(d->hdr.magic) == XFS_DIR2_DATA_MAGIC ||
293 INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC); 296 be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC);
294#endif 297#endif
295 /* 298 /*
296 * It's the first entry, slide the next 2 up. 299 * It's the first entry, slide the next 2 up.
@@ -334,8 +337,8 @@ xfs_dir2_data_freescan(
334 char *p; /* current entry pointer */ 337 char *p; /* current entry pointer */
335 338
336#ifdef __KERNEL__ 339#ifdef __KERNEL__
337 ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC || 340 ASSERT(be32_to_cpu(d->hdr.magic) == XFS_DIR2_DATA_MAGIC ||
338 INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC); 341 be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC);
339#endif 342#endif
340 /* 343 /*
341 * Start by clearing the table. 344 * Start by clearing the table.
@@ -348,7 +351,7 @@ xfs_dir2_data_freescan(
348 p = (char *)d->u; 351 p = (char *)d->u;
349 if (aendp) 352 if (aendp)
350 endp = aendp; 353 endp = aendp;
351 else if (INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC) { 354 else if (be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC) {
352 btp = XFS_DIR2_BLOCK_TAIL_P(mp, (xfs_dir2_block_t *)d); 355 btp = XFS_DIR2_BLOCK_TAIL_P(mp, (xfs_dir2_block_t *)d);
353 endp = (char *)XFS_DIR2_BLOCK_LEAF_P(btp); 356 endp = (char *)XFS_DIR2_BLOCK_LEAF_P(btp);
354 } else 357 } else
@@ -361,11 +364,11 @@ xfs_dir2_data_freescan(
361 /* 364 /*
362 * If it's a free entry, insert it. 365 * If it's a free entry, insert it.
363 */ 366 */
364 if (INT_GET(dup->freetag, ARCH_CONVERT) == XFS_DIR2_DATA_FREE_TAG) { 367 if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
365 ASSERT((char *)dup - (char *)d == 368 ASSERT((char *)dup - (char *)d ==
366 INT_GET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT)); 369 be16_to_cpu(*XFS_DIR2_DATA_UNUSED_TAG_P(dup)));
367 xfs_dir2_data_freeinsert(d, dup, loghead); 370 xfs_dir2_data_freeinsert(d, dup, loghead);
368 p += INT_GET(dup->length, ARCH_CONVERT); 371 p += be16_to_cpu(dup->length);
369 } 372 }
370 /* 373 /*
371 * For active entries, check their tags and skip them. 374 * For active entries, check their tags and skip them.
@@ -373,7 +376,7 @@ xfs_dir2_data_freescan(
373 else { 376 else {
374 dep = (xfs_dir2_data_entry_t *)p; 377 dep = (xfs_dir2_data_entry_t *)p;
375 ASSERT((char *)dep - (char *)d == 378 ASSERT((char *)dep - (char *)d ==
376 INT_GET(*XFS_DIR2_DATA_ENTRY_TAG_P(dep), ARCH_CONVERT)); 379 be16_to_cpu(*XFS_DIR2_DATA_ENTRY_TAG_P(dep)));
377 p += XFS_DIR2_DATA_ENTSIZE(dep->namelen); 380 p += XFS_DIR2_DATA_ENTSIZE(dep->namelen);
378 } 381 }
379 } 382 }
@@ -415,8 +418,8 @@ xfs_dir2_data_init(
415 * Initialize the header. 418 * Initialize the header.
416 */ 419 */
417 d = bp->data; 420 d = bp->data;
418 INT_SET(d->hdr.magic, ARCH_CONVERT, XFS_DIR2_DATA_MAGIC); 421 d->hdr.magic = cpu_to_be32(XFS_DIR2_DATA_MAGIC);
419 INT_SET(d->hdr.bestfree[0].offset, ARCH_CONVERT, (xfs_dir2_data_off_t)sizeof(d->hdr)); 422 d->hdr.bestfree[0].offset = cpu_to_be16(sizeof(d->hdr));
420 for (i = 1; i < XFS_DIR2_DATA_FD_COUNT; i++) { 423 for (i = 1; i < XFS_DIR2_DATA_FD_COUNT; i++) {
421 d->hdr.bestfree[i].length = 0; 424 d->hdr.bestfree[i].length = 0;
422 d->hdr.bestfree[i].offset = 0; 425 d->hdr.bestfree[i].offset = 0;
@@ -425,13 +428,12 @@ xfs_dir2_data_init(
425 * Set up an unused entry for the block's body. 428 * Set up an unused entry for the block's body.
426 */ 429 */
427 dup = &d->u[0].unused; 430 dup = &d->u[0].unused;
428 INT_SET(dup->freetag, ARCH_CONVERT, XFS_DIR2_DATA_FREE_TAG); 431 dup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG);
429 432
430 t=mp->m_dirblksize - (uint)sizeof(d->hdr); 433 t=mp->m_dirblksize - (uint)sizeof(d->hdr);
431 INT_SET(d->hdr.bestfree[0].length, ARCH_CONVERT, t); 434 d->hdr.bestfree[0].length = cpu_to_be16(t);
432 INT_SET(dup->length, ARCH_CONVERT, t); 435 dup->length = cpu_to_be16(t);
433 INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT, 436 *XFS_DIR2_DATA_UNUSED_TAG_P(dup) = cpu_to_be16((char *)dup - (char *)d);
434 (xfs_dir2_data_off_t)((char *)dup - (char *)d));
435 /* 437 /*
436 * Log it and return it. 438 * Log it and return it.
437 */ 439 */
@@ -453,8 +455,8 @@ xfs_dir2_data_log_entry(
453 xfs_dir2_data_t *d; /* data block pointer */ 455 xfs_dir2_data_t *d; /* data block pointer */
454 456
455 d = bp->data; 457 d = bp->data;
456 ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC || 458 ASSERT(be32_to_cpu(d->hdr.magic) == XFS_DIR2_DATA_MAGIC ||
457 INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC); 459 be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC);
458 xfs_da_log_buf(tp, bp, (uint)((char *)dep - (char *)d), 460 xfs_da_log_buf(tp, bp, (uint)((char *)dep - (char *)d),
459 (uint)((char *)(XFS_DIR2_DATA_ENTRY_TAG_P(dep) + 1) - 461 (uint)((char *)(XFS_DIR2_DATA_ENTRY_TAG_P(dep) + 1) -
460 (char *)d - 1)); 462 (char *)d - 1));
@@ -471,8 +473,8 @@ xfs_dir2_data_log_header(
471 xfs_dir2_data_t *d; /* data block pointer */ 473 xfs_dir2_data_t *d; /* data block pointer */
472 474
473 d = bp->data; 475 d = bp->data;
474 ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC || 476 ASSERT(be32_to_cpu(d->hdr.magic) == XFS_DIR2_DATA_MAGIC ||
475 INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC); 477 be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC);
476 xfs_da_log_buf(tp, bp, (uint)((char *)&d->hdr - (char *)d), 478 xfs_da_log_buf(tp, bp, (uint)((char *)&d->hdr - (char *)d),
477 (uint)(sizeof(d->hdr) - 1)); 479 (uint)(sizeof(d->hdr) - 1));
478} 480}
@@ -489,8 +491,8 @@ xfs_dir2_data_log_unused(
489 xfs_dir2_data_t *d; /* data block pointer */ 491 xfs_dir2_data_t *d; /* data block pointer */
490 492
491 d = bp->data; 493 d = bp->data;
492 ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC || 494 ASSERT(be32_to_cpu(d->hdr.magic) == XFS_DIR2_DATA_MAGIC ||
493 INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC); 495 be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC);
494 /* 496 /*
495 * Log the first part of the unused entry. 497 * Log the first part of the unused entry.
496 */ 498 */
@@ -533,12 +535,12 @@ xfs_dir2_data_make_free(
533 /* 535 /*
534 * Figure out where the end of the data area is. 536 * Figure out where the end of the data area is.
535 */ 537 */
536 if (INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC) 538 if (be32_to_cpu(d->hdr.magic) == XFS_DIR2_DATA_MAGIC)
537 endptr = (char *)d + mp->m_dirblksize; 539 endptr = (char *)d + mp->m_dirblksize;
538 else { 540 else {
539 xfs_dir2_block_tail_t *btp; /* block tail */ 541 xfs_dir2_block_tail_t *btp; /* block tail */
540 542
541 ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC); 543 ASSERT(be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC);
542 btp = XFS_DIR2_BLOCK_TAIL_P(mp, (xfs_dir2_block_t *)d); 544 btp = XFS_DIR2_BLOCK_TAIL_P(mp, (xfs_dir2_block_t *)d);
543 endptr = (char *)XFS_DIR2_BLOCK_LEAF_P(btp); 545 endptr = (char *)XFS_DIR2_BLOCK_LEAF_P(btp);
544 } 546 }
@@ -547,11 +549,11 @@ xfs_dir2_data_make_free(
547 * the previous entry and see if it's free. 549 * the previous entry and see if it's free.
548 */ 550 */
549 if (offset > sizeof(d->hdr)) { 551 if (offset > sizeof(d->hdr)) {
550 xfs_dir2_data_off_t *tagp; /* tag just before us */ 552 __be16 *tagp; /* tag just before us */
551 553
552 tagp = (xfs_dir2_data_off_t *)((char *)d + offset) - 1; 554 tagp = (__be16 *)((char *)d + offset) - 1;
553 prevdup = (xfs_dir2_data_unused_t *)((char *)d + INT_GET(*tagp, ARCH_CONVERT)); 555 prevdup = (xfs_dir2_data_unused_t *)((char *)d + be16_to_cpu(*tagp));
554 if (INT_GET(prevdup->freetag, ARCH_CONVERT) != XFS_DIR2_DATA_FREE_TAG) 556 if (be16_to_cpu(prevdup->freetag) != XFS_DIR2_DATA_FREE_TAG)
555 prevdup = NULL; 557 prevdup = NULL;
556 } else 558 } else
557 prevdup = NULL; 559 prevdup = NULL;
@@ -562,7 +564,7 @@ xfs_dir2_data_make_free(
562 if ((char *)d + offset + len < endptr) { 564 if ((char *)d + offset + len < endptr) {
563 postdup = 565 postdup =
564 (xfs_dir2_data_unused_t *)((char *)d + offset + len); 566 (xfs_dir2_data_unused_t *)((char *)d + offset + len);
565 if (INT_GET(postdup->freetag, ARCH_CONVERT) != XFS_DIR2_DATA_FREE_TAG) 567 if (be16_to_cpu(postdup->freetag) != XFS_DIR2_DATA_FREE_TAG)
566 postdup = NULL; 568 postdup = NULL;
567 } else 569 } else
568 postdup = NULL; 570 postdup = NULL;
@@ -586,13 +588,13 @@ xfs_dir2_data_make_free(
586 * since the third bestfree is there, there might be more 588 * since the third bestfree is there, there might be more
587 * entries. 589 * entries.
588 */ 590 */
589 needscan = d->hdr.bestfree[2].length; 591 needscan = (d->hdr.bestfree[2].length != 0);
590 /* 592 /*
591 * Fix up the new big freespace. 593 * Fix up the new big freespace.
592 */ 594 */
593 INT_MOD(prevdup->length, ARCH_CONVERT, len + INT_GET(postdup->length, ARCH_CONVERT)); 595 be16_add(&prevdup->length, len + be16_to_cpu(postdup->length));
594 INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(prevdup), ARCH_CONVERT, 596 *XFS_DIR2_DATA_UNUSED_TAG_P(prevdup) =
595 (xfs_dir2_data_off_t)((char *)prevdup - (char *)d)); 597 cpu_to_be16((char *)prevdup - (char *)d);
596 xfs_dir2_data_log_unused(tp, bp, prevdup); 598 xfs_dir2_data_log_unused(tp, bp, prevdup);
597 if (!needscan) { 599 if (!needscan) {
598 /* 600 /*
@@ -614,7 +616,7 @@ xfs_dir2_data_make_free(
614 */ 616 */
615 dfp = xfs_dir2_data_freeinsert(d, prevdup, needlogp); 617 dfp = xfs_dir2_data_freeinsert(d, prevdup, needlogp);
616 ASSERT(dfp == &d->hdr.bestfree[0]); 618 ASSERT(dfp == &d->hdr.bestfree[0]);
617 ASSERT(INT_GET(dfp->length, ARCH_CONVERT) == INT_GET(prevdup->length, ARCH_CONVERT)); 619 ASSERT(dfp->length == prevdup->length);
618 ASSERT(!dfp[1].length); 620 ASSERT(!dfp[1].length);
619 ASSERT(!dfp[2].length); 621 ASSERT(!dfp[2].length);
620 } 622 }
@@ -624,9 +626,9 @@ xfs_dir2_data_make_free(
624 */ 626 */
625 else if (prevdup) { 627 else if (prevdup) {
626 dfp = xfs_dir2_data_freefind(d, prevdup); 628 dfp = xfs_dir2_data_freefind(d, prevdup);
627 INT_MOD(prevdup->length, ARCH_CONVERT, len); 629 be16_add(&prevdup->length, len);
628 INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(prevdup), ARCH_CONVERT, 630 *XFS_DIR2_DATA_UNUSED_TAG_P(prevdup) =
629 (xfs_dir2_data_off_t)((char *)prevdup - (char *)d)); 631 cpu_to_be16((char *)prevdup - (char *)d);
630 xfs_dir2_data_log_unused(tp, bp, prevdup); 632 xfs_dir2_data_log_unused(tp, bp, prevdup);
631 /* 633 /*
632 * If the previous entry was in the table, the new entry 634 * If the previous entry was in the table, the new entry
@@ -640,8 +642,10 @@ xfs_dir2_data_make_free(
640 /* 642 /*
641 * Otherwise we need a scan if the new entry is big enough. 643 * Otherwise we need a scan if the new entry is big enough.
642 */ 644 */
643 else 645 else {
644 needscan = INT_GET(prevdup->length, ARCH_CONVERT) > INT_GET(d->hdr.bestfree[2].length, ARCH_CONVERT); 646 needscan = be16_to_cpu(prevdup->length) >
647 be16_to_cpu(d->hdr.bestfree[2].length);
648 }
645 } 649 }
646 /* 650 /*
647 * The following entry is free, merge with it. 651 * The following entry is free, merge with it.
@@ -649,10 +653,10 @@ xfs_dir2_data_make_free(
649 else if (postdup) { 653 else if (postdup) {
650 dfp = xfs_dir2_data_freefind(d, postdup); 654 dfp = xfs_dir2_data_freefind(d, postdup);
651 newdup = (xfs_dir2_data_unused_t *)((char *)d + offset); 655 newdup = (xfs_dir2_data_unused_t *)((char *)d + offset);
652 INT_SET(newdup->freetag, ARCH_CONVERT, XFS_DIR2_DATA_FREE_TAG); 656 newdup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG);
653 INT_SET(newdup->length, ARCH_CONVERT, len + INT_GET(postdup->length, ARCH_CONVERT)); 657 newdup->length = cpu_to_be16(len + be16_to_cpu(postdup->length));
654 INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup), ARCH_CONVERT, 658 *XFS_DIR2_DATA_UNUSED_TAG_P(newdup) =
655 (xfs_dir2_data_off_t)((char *)newdup - (char *)d)); 659 cpu_to_be16((char *)newdup - (char *)d);
656 xfs_dir2_data_log_unused(tp, bp, newdup); 660 xfs_dir2_data_log_unused(tp, bp, newdup);
657 /* 661 /*
658 * If the following entry was in the table, the new entry 662 * If the following entry was in the table, the new entry
@@ -666,18 +670,20 @@ xfs_dir2_data_make_free(
666 /* 670 /*
667 * Otherwise we need a scan if the new entry is big enough. 671 * Otherwise we need a scan if the new entry is big enough.
668 */ 672 */
669 else 673 else {
670 needscan = INT_GET(newdup->length, ARCH_CONVERT) > INT_GET(d->hdr.bestfree[2].length, ARCH_CONVERT); 674 needscan = be16_to_cpu(newdup->length) >
675 be16_to_cpu(d->hdr.bestfree[2].length);
676 }
671 } 677 }
672 /* 678 /*
673 * Neither neighbor is free. Make a new entry. 679 * Neither neighbor is free. Make a new entry.
674 */ 680 */
675 else { 681 else {
676 newdup = (xfs_dir2_data_unused_t *)((char *)d + offset); 682 newdup = (xfs_dir2_data_unused_t *)((char *)d + offset);
677 INT_SET(newdup->freetag, ARCH_CONVERT, XFS_DIR2_DATA_FREE_TAG); 683 newdup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG);
678 INT_SET(newdup->length, ARCH_CONVERT, len); 684 newdup->length = cpu_to_be16(len);
679 INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup), ARCH_CONVERT, 685 *XFS_DIR2_DATA_UNUSED_TAG_P(newdup) =
680 (xfs_dir2_data_off_t)((char *)newdup - (char *)d)); 686 cpu_to_be16((char *)newdup - (char *)d);
681 xfs_dir2_data_log_unused(tp, bp, newdup); 687 xfs_dir2_data_log_unused(tp, bp, newdup);
682 (void)xfs_dir2_data_freeinsert(d, newdup, needlogp); 688 (void)xfs_dir2_data_freeinsert(d, newdup, needlogp);
683 } 689 }
@@ -707,18 +713,18 @@ xfs_dir2_data_use_free(
707 int oldlen; /* old unused entry's length */ 713 int oldlen; /* old unused entry's length */
708 714
709 d = bp->data; 715 d = bp->data;
710 ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC || 716 ASSERT(be32_to_cpu(d->hdr.magic) == XFS_DIR2_DATA_MAGIC ||
711 INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC); 717 be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC);
712 ASSERT(INT_GET(dup->freetag, ARCH_CONVERT) == XFS_DIR2_DATA_FREE_TAG); 718 ASSERT(be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG);
713 ASSERT(offset >= (char *)dup - (char *)d); 719 ASSERT(offset >= (char *)dup - (char *)d);
714 ASSERT(offset + len <= (char *)dup + INT_GET(dup->length, ARCH_CONVERT) - (char *)d); 720 ASSERT(offset + len <= (char *)dup + be16_to_cpu(dup->length) - (char *)d);
715 ASSERT((char *)dup - (char *)d == INT_GET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT)); 721 ASSERT((char *)dup - (char *)d == be16_to_cpu(*XFS_DIR2_DATA_UNUSED_TAG_P(dup)));
716 /* 722 /*
717 * Look up the entry in the bestfree table. 723 * Look up the entry in the bestfree table.
718 */ 724 */
719 dfp = xfs_dir2_data_freefind(d, dup); 725 dfp = xfs_dir2_data_freefind(d, dup);
720 oldlen = INT_GET(dup->length, ARCH_CONVERT); 726 oldlen = be16_to_cpu(dup->length);
721 ASSERT(dfp || oldlen <= INT_GET(d->hdr.bestfree[2].length, ARCH_CONVERT)); 727 ASSERT(dfp || oldlen <= be16_to_cpu(d->hdr.bestfree[2].length));
722 /* 728 /*
723 * Check for alignment with front and back of the entry. 729 * Check for alignment with front and back of the entry.
724 */ 730 */
@@ -732,7 +738,7 @@ xfs_dir2_data_use_free(
732 */ 738 */
733 if (matchfront && matchback) { 739 if (matchfront && matchback) {
734 if (dfp) { 740 if (dfp) {
735 needscan = d->hdr.bestfree[2].offset; 741 needscan = (d->hdr.bestfree[2].offset != 0);
736 if (!needscan) 742 if (!needscan)
737 xfs_dir2_data_freeremove(d, dfp, needlogp); 743 xfs_dir2_data_freeremove(d, dfp, needlogp);
738 } 744 }
@@ -743,10 +749,10 @@ xfs_dir2_data_use_free(
743 */ 749 */
744 else if (matchfront) { 750 else if (matchfront) {
745 newdup = (xfs_dir2_data_unused_t *)((char *)d + offset + len); 751 newdup = (xfs_dir2_data_unused_t *)((char *)d + offset + len);
746 INT_SET(newdup->freetag, ARCH_CONVERT, XFS_DIR2_DATA_FREE_TAG); 752 newdup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG);
747 INT_SET(newdup->length, ARCH_CONVERT, oldlen - len); 753 newdup->length = cpu_to_be16(oldlen - len);
748 INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup), ARCH_CONVERT, 754 *XFS_DIR2_DATA_UNUSED_TAG_P(newdup) =
749 (xfs_dir2_data_off_t)((char *)newdup - (char *)d)); 755 cpu_to_be16((char *)newdup - (char *)d);
750 xfs_dir2_data_log_unused(tp, bp, newdup); 756 xfs_dir2_data_log_unused(tp, bp, newdup);
751 /* 757 /*
752 * If it was in the table, remove it and add the new one. 758 * If it was in the table, remove it and add the new one.
@@ -755,8 +761,8 @@ xfs_dir2_data_use_free(
755 xfs_dir2_data_freeremove(d, dfp, needlogp); 761 xfs_dir2_data_freeremove(d, dfp, needlogp);
756 dfp = xfs_dir2_data_freeinsert(d, newdup, needlogp); 762 dfp = xfs_dir2_data_freeinsert(d, newdup, needlogp);
757 ASSERT(dfp != NULL); 763 ASSERT(dfp != NULL);
758 ASSERT(INT_GET(dfp->length, ARCH_CONVERT) == INT_GET(newdup->length, ARCH_CONVERT)); 764 ASSERT(dfp->length == newdup->length);
759 ASSERT(INT_GET(dfp->offset, ARCH_CONVERT) == (char *)newdup - (char *)d); 765 ASSERT(be16_to_cpu(dfp->offset) == (char *)newdup - (char *)d);
760 /* 766 /*
761 * If we got inserted at the last slot, 767 * If we got inserted at the last slot,
762 * that means we don't know if there was a better 768 * that means we don't know if there was a better
@@ -771,10 +777,9 @@ xfs_dir2_data_use_free(
771 */ 777 */
772 else if (matchback) { 778 else if (matchback) {
773 newdup = dup; 779 newdup = dup;
774 INT_SET(newdup->length, ARCH_CONVERT, (xfs_dir2_data_off_t) 780 newdup->length = cpu_to_be16(((char *)d + offset) - (char *)newdup);
775 (((char *)d + offset) - (char *)newdup)); 781 *XFS_DIR2_DATA_UNUSED_TAG_P(newdup) =
776 INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup), ARCH_CONVERT, 782 cpu_to_be16((char *)newdup - (char *)d);
777 (xfs_dir2_data_off_t)((char *)newdup - (char *)d));
778 xfs_dir2_data_log_unused(tp, bp, newdup); 783 xfs_dir2_data_log_unused(tp, bp, newdup);
779 /* 784 /*
780 * If it was in the table, remove it and add the new one. 785 * If it was in the table, remove it and add the new one.
@@ -783,8 +788,8 @@ xfs_dir2_data_use_free(
783 xfs_dir2_data_freeremove(d, dfp, needlogp); 788 xfs_dir2_data_freeremove(d, dfp, needlogp);
784 dfp = xfs_dir2_data_freeinsert(d, newdup, needlogp); 789 dfp = xfs_dir2_data_freeinsert(d, newdup, needlogp);
785 ASSERT(dfp != NULL); 790 ASSERT(dfp != NULL);
786 ASSERT(INT_GET(dfp->length, ARCH_CONVERT) == INT_GET(newdup->length, ARCH_CONVERT)); 791 ASSERT(dfp->length == newdup->length);
787 ASSERT(INT_GET(dfp->offset, ARCH_CONVERT) == (char *)newdup - (char *)d); 792 ASSERT(be16_to_cpu(dfp->offset) == (char *)newdup - (char *)d);
788 /* 793 /*
789 * If we got inserted at the last slot, 794 * If we got inserted at the last slot,
790 * that means we don't know if there was a better 795 * that means we don't know if there was a better
@@ -799,16 +804,15 @@ xfs_dir2_data_use_free(
799 */ 804 */
800 else { 805 else {
801 newdup = dup; 806 newdup = dup;
802 INT_SET(newdup->length, ARCH_CONVERT, (xfs_dir2_data_off_t) 807 newdup->length = cpu_to_be16(((char *)d + offset) - (char *)newdup);
803 (((char *)d + offset) - (char *)newdup)); 808 *XFS_DIR2_DATA_UNUSED_TAG_P(newdup) =
804 INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup), ARCH_CONVERT, 809 cpu_to_be16((char *)newdup - (char *)d);
805 (xfs_dir2_data_off_t)((char *)newdup - (char *)d));
806 xfs_dir2_data_log_unused(tp, bp, newdup); 810 xfs_dir2_data_log_unused(tp, bp, newdup);
807 newdup2 = (xfs_dir2_data_unused_t *)((char *)d + offset + len); 811 newdup2 = (xfs_dir2_data_unused_t *)((char *)d + offset + len);
808 INT_SET(newdup2->freetag, ARCH_CONVERT, XFS_DIR2_DATA_FREE_TAG); 812 newdup2->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG);
809 INT_SET(newdup2->length, ARCH_CONVERT, oldlen - len - INT_GET(newdup->length, ARCH_CONVERT)); 813 newdup2->length = cpu_to_be16(oldlen - len - be16_to_cpu(newdup->length));
810 INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup2), ARCH_CONVERT, 814 *XFS_DIR2_DATA_UNUSED_TAG_P(newdup2) =
811 (xfs_dir2_data_off_t)((char *)newdup2 - (char *)d)); 815 cpu_to_be16((char *)newdup2 - (char *)d);
812 xfs_dir2_data_log_unused(tp, bp, newdup2); 816 xfs_dir2_data_log_unused(tp, bp, newdup2);
813 /* 817 /*
814 * If the old entry was in the table, we need to scan 818 * If the old entry was in the table, we need to scan
@@ -819,7 +823,7 @@ xfs_dir2_data_use_free(
819 * the 2 new will work. 823 * the 2 new will work.
820 */ 824 */
821 if (dfp) { 825 if (dfp) {
822 needscan = d->hdr.bestfree[2].length; 826 needscan = (d->hdr.bestfree[2].length != 0);
823 if (!needscan) { 827 if (!needscan) {
824 xfs_dir2_data_freeremove(d, dfp, needlogp); 828 xfs_dir2_data_freeremove(d, dfp, needlogp);
825 (void)xfs_dir2_data_freeinsert(d, newdup, 829 (void)xfs_dir2_data_freeinsert(d, newdup,