aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_dir2_data.c
diff options
context:
space:
mode:
authorNathan Scott <nathans@sgi.com>2006-03-17 01:26:52 -0500
committerNathan Scott <nathans@sgi.com>2006-03-17 01:26:52 -0500
commit70e73f59755867383edf563d5a5cbea614c0fd49 (patch)
tree6850f22b47754078b1695aad1ade7bf9705dc52a /fs/xfs/xfs_dir2_data.c
parent9cea236492ebabb9545564eb039aa0f477a05c96 (diff)
[XFS] endianess annotations for xfs_dir2_data_hdr structure.
SGI-PV: 943272 SGI-Modid: xfs-linux-melb:xfs-kern:25484a Signed-off-by: Nathan Scott <nathans@sgi.com>
Diffstat (limited to 'fs/xfs/xfs_dir2_data.c')
-rw-r--r--fs/xfs/xfs_dir2_data.c123
1 files changed, 65 insertions, 58 deletions
diff --git a/fs/xfs/xfs_dir2_data.c b/fs/xfs/xfs_dir2_data.c
index 5b7c47e2f14a..fd6b7c03018a 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 */
@@ -117,8 +117,10 @@ xfs_dir2_data_check(
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(INT_GET(dup->length, ARCH_CONVERT) <=
122 be16_to_cpu(bf[2].length));
123 }
122 p += INT_GET(dup->length, ARCH_CONVERT); 124 p += INT_GET(dup->length, ARCH_CONVERT);
123 lastfree = 1; 125 lastfree = 1;
124 continue; 126 continue;
@@ -136,7 +138,7 @@ xfs_dir2_data_check(
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));
@@ -154,7 +156,7 @@ 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 < INT_GET(btp->count, ARCH_CONVERT); i++) {
159 if (INT_GET(lep[i].address, ARCH_CONVERT) == XFS_DIR2_NULL_DATAPTR) 161 if (INT_GET(lep[i].address, ARCH_CONVERT) == XFS_DIR2_NULL_DATAPTR)
160 stale++; 162 stale++;
@@ -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(be16_to_cpu(dfp->length) == INT_GET(dup->length, ARCH_CONVERT));
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 + INT_GET(dup->length, ARCH_CONVERT) <= 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) >= INT_GET(dup->length, ARCH_CONVERT));
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 (INT_GET(dup->length, ARCH_CONVERT) <
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
@@ -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;
@@ -428,7 +431,7 @@ xfs_dir2_data_init(
428 INT_SET(dup->freetag, ARCH_CONVERT, XFS_DIR2_DATA_FREE_TAG); 431 INT_SET(dup->freetag, ARCH_CONVERT, 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 INT_SET(dup->length, ARCH_CONVERT, t);
433 INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT, 436 INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT,
434 (xfs_dir2_data_off_t)((char *)dup - (char *)d)); 437 (xfs_dir2_data_off_t)((char *)dup - (char *)d));
@@ -453,8 +456,8 @@ xfs_dir2_data_log_entry(
453 xfs_dir2_data_t *d; /* data block pointer */ 456 xfs_dir2_data_t *d; /* data block pointer */
454 457
455 d = bp->data; 458 d = bp->data;
456 ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC || 459 ASSERT(be32_to_cpu(d->hdr.magic) == XFS_DIR2_DATA_MAGIC ||
457 INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC); 460 be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC);
458 xfs_da_log_buf(tp, bp, (uint)((char *)dep - (char *)d), 461 xfs_da_log_buf(tp, bp, (uint)((char *)dep - (char *)d),
459 (uint)((char *)(XFS_DIR2_DATA_ENTRY_TAG_P(dep) + 1) - 462 (uint)((char *)(XFS_DIR2_DATA_ENTRY_TAG_P(dep) + 1) -
460 (char *)d - 1)); 463 (char *)d - 1));
@@ -471,8 +474,8 @@ xfs_dir2_data_log_header(
471 xfs_dir2_data_t *d; /* data block pointer */ 474 xfs_dir2_data_t *d; /* data block pointer */
472 475
473 d = bp->data; 476 d = bp->data;
474 ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC || 477 ASSERT(be32_to_cpu(d->hdr.magic) == XFS_DIR2_DATA_MAGIC ||
475 INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC); 478 be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC);
476 xfs_da_log_buf(tp, bp, (uint)((char *)&d->hdr - (char *)d), 479 xfs_da_log_buf(tp, bp, (uint)((char *)&d->hdr - (char *)d),
477 (uint)(sizeof(d->hdr) - 1)); 480 (uint)(sizeof(d->hdr) - 1));
478} 481}
@@ -489,8 +492,8 @@ xfs_dir2_data_log_unused(
489 xfs_dir2_data_t *d; /* data block pointer */ 492 xfs_dir2_data_t *d; /* data block pointer */
490 493
491 d = bp->data; 494 d = bp->data;
492 ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC || 495 ASSERT(be32_to_cpu(d->hdr.magic) == XFS_DIR2_DATA_MAGIC ||
493 INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC); 496 be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC);
494 /* 497 /*
495 * Log the first part of the unused entry. 498 * Log the first part of the unused entry.
496 */ 499 */
@@ -533,12 +536,12 @@ xfs_dir2_data_make_free(
533 /* 536 /*
534 * Figure out where the end of the data area is. 537 * Figure out where the end of the data area is.
535 */ 538 */
536 if (INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC) 539 if (be32_to_cpu(d->hdr.magic) == XFS_DIR2_DATA_MAGIC)
537 endptr = (char *)d + mp->m_dirblksize; 540 endptr = (char *)d + mp->m_dirblksize;
538 else { 541 else {
539 xfs_dir2_block_tail_t *btp; /* block tail */ 542 xfs_dir2_block_tail_t *btp; /* block tail */
540 543
541 ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC); 544 ASSERT(be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC);
542 btp = XFS_DIR2_BLOCK_TAIL_P(mp, (xfs_dir2_block_t *)d); 545 btp = XFS_DIR2_BLOCK_TAIL_P(mp, (xfs_dir2_block_t *)d);
543 endptr = (char *)XFS_DIR2_BLOCK_LEAF_P(btp); 546 endptr = (char *)XFS_DIR2_BLOCK_LEAF_P(btp);
544 } 547 }
@@ -586,7 +589,7 @@ xfs_dir2_data_make_free(
586 * since the third bestfree is there, there might be more 589 * since the third bestfree is there, there might be more
587 * entries. 590 * entries.
588 */ 591 */
589 needscan = d->hdr.bestfree[2].length; 592 needscan = (d->hdr.bestfree[2].length != 0);
590 /* 593 /*
591 * Fix up the new big freespace. 594 * Fix up the new big freespace.
592 */ 595 */
@@ -614,7 +617,7 @@ xfs_dir2_data_make_free(
614 */ 617 */
615 dfp = xfs_dir2_data_freeinsert(d, prevdup, needlogp); 618 dfp = xfs_dir2_data_freeinsert(d, prevdup, needlogp);
616 ASSERT(dfp == &d->hdr.bestfree[0]); 619 ASSERT(dfp == &d->hdr.bestfree[0]);
617 ASSERT(INT_GET(dfp->length, ARCH_CONVERT) == INT_GET(prevdup->length, ARCH_CONVERT)); 620 ASSERT(be16_to_cpu(dfp->length) == INT_GET(prevdup->length, ARCH_CONVERT));
618 ASSERT(!dfp[1].length); 621 ASSERT(!dfp[1].length);
619 ASSERT(!dfp[2].length); 622 ASSERT(!dfp[2].length);
620 } 623 }
@@ -640,8 +643,10 @@ xfs_dir2_data_make_free(
640 /* 643 /*
641 * Otherwise we need a scan if the new entry is big enough. 644 * Otherwise we need a scan if the new entry is big enough.
642 */ 645 */
643 else 646 else {
644 needscan = INT_GET(prevdup->length, ARCH_CONVERT) > INT_GET(d->hdr.bestfree[2].length, ARCH_CONVERT); 647 needscan = INT_GET(prevdup->length, ARCH_CONVERT) >
648 be16_to_cpu(d->hdr.bestfree[2].length);
649 }
645 } 650 }
646 /* 651 /*
647 * The following entry is free, merge with it. 652 * The following entry is free, merge with it.
@@ -666,8 +671,10 @@ xfs_dir2_data_make_free(
666 /* 671 /*
667 * Otherwise we need a scan if the new entry is big enough. 672 * Otherwise we need a scan if the new entry is big enough.
668 */ 673 */
669 else 674 else {
670 needscan = INT_GET(newdup->length, ARCH_CONVERT) > INT_GET(d->hdr.bestfree[2].length, ARCH_CONVERT); 675 needscan = INT_GET(newdup->length, ARCH_CONVERT) >
676 be16_to_cpu(d->hdr.bestfree[2].length);
677 }
671 } 678 }
672 /* 679 /*
673 * Neither neighbor is free. Make a new entry. 680 * Neither neighbor is free. Make a new entry.
@@ -707,8 +714,8 @@ xfs_dir2_data_use_free(
707 int oldlen; /* old unused entry's length */ 714 int oldlen; /* old unused entry's length */
708 715
709 d = bp->data; 716 d = bp->data;
710 ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC || 717 ASSERT(be32_to_cpu(d->hdr.magic) == XFS_DIR2_DATA_MAGIC ||
711 INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC); 718 be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC);
712 ASSERT(INT_GET(dup->freetag, ARCH_CONVERT) == XFS_DIR2_DATA_FREE_TAG); 719 ASSERT(INT_GET(dup->freetag, ARCH_CONVERT) == XFS_DIR2_DATA_FREE_TAG);
713 ASSERT(offset >= (char *)dup - (char *)d); 720 ASSERT(offset >= (char *)dup - (char *)d);
714 ASSERT(offset + len <= (char *)dup + INT_GET(dup->length, ARCH_CONVERT) - (char *)d); 721 ASSERT(offset + len <= (char *)dup + INT_GET(dup->length, ARCH_CONVERT) - (char *)d);
@@ -718,7 +725,7 @@ xfs_dir2_data_use_free(
718 */ 725 */
719 dfp = xfs_dir2_data_freefind(d, dup); 726 dfp = xfs_dir2_data_freefind(d, dup);
720 oldlen = INT_GET(dup->length, ARCH_CONVERT); 727 oldlen = INT_GET(dup->length, ARCH_CONVERT);
721 ASSERT(dfp || oldlen <= INT_GET(d->hdr.bestfree[2].length, ARCH_CONVERT)); 728 ASSERT(dfp || oldlen <= be16_to_cpu(d->hdr.bestfree[2].length));
722 /* 729 /*
723 * Check for alignment with front and back of the entry. 730 * Check for alignment with front and back of the entry.
724 */ 731 */
@@ -732,7 +739,7 @@ xfs_dir2_data_use_free(
732 */ 739 */
733 if (matchfront && matchback) { 740 if (matchfront && matchback) {
734 if (dfp) { 741 if (dfp) {
735 needscan = d->hdr.bestfree[2].offset; 742 needscan = (d->hdr.bestfree[2].offset != 0);
736 if (!needscan) 743 if (!needscan)
737 xfs_dir2_data_freeremove(d, dfp, needlogp); 744 xfs_dir2_data_freeremove(d, dfp, needlogp);
738 } 745 }
@@ -755,8 +762,8 @@ xfs_dir2_data_use_free(
755 xfs_dir2_data_freeremove(d, dfp, needlogp); 762 xfs_dir2_data_freeremove(d, dfp, needlogp);
756 dfp = xfs_dir2_data_freeinsert(d, newdup, needlogp); 763 dfp = xfs_dir2_data_freeinsert(d, newdup, needlogp);
757 ASSERT(dfp != NULL); 764 ASSERT(dfp != NULL);
758 ASSERT(INT_GET(dfp->length, ARCH_CONVERT) == INT_GET(newdup->length, ARCH_CONVERT)); 765 ASSERT(be16_to_cpu(dfp->length) == INT_GET(newdup->length, ARCH_CONVERT));
759 ASSERT(INT_GET(dfp->offset, ARCH_CONVERT) == (char *)newdup - (char *)d); 766 ASSERT(be16_to_cpu(dfp->offset) == (char *)newdup - (char *)d);
760 /* 767 /*
761 * If we got inserted at the last slot, 768 * If we got inserted at the last slot,
762 * that means we don't know if there was a better 769 * that means we don't know if there was a better
@@ -783,8 +790,8 @@ xfs_dir2_data_use_free(
783 xfs_dir2_data_freeremove(d, dfp, needlogp); 790 xfs_dir2_data_freeremove(d, dfp, needlogp);
784 dfp = xfs_dir2_data_freeinsert(d, newdup, needlogp); 791 dfp = xfs_dir2_data_freeinsert(d, newdup, needlogp);
785 ASSERT(dfp != NULL); 792 ASSERT(dfp != NULL);
786 ASSERT(INT_GET(dfp->length, ARCH_CONVERT) == INT_GET(newdup->length, ARCH_CONVERT)); 793 ASSERT(be16_to_cpu(dfp->length) == INT_GET(newdup->length, ARCH_CONVERT));
787 ASSERT(INT_GET(dfp->offset, ARCH_CONVERT) == (char *)newdup - (char *)d); 794 ASSERT(be16_to_cpu(dfp->offset) == (char *)newdup - (char *)d);
788 /* 795 /*
789 * If we got inserted at the last slot, 796 * If we got inserted at the last slot,
790 * that means we don't know if there was a better 797 * that means we don't know if there was a better
@@ -819,7 +826,7 @@ xfs_dir2_data_use_free(
819 * the 2 new will work. 826 * the 2 new will work.
820 */ 827 */
821 if (dfp) { 828 if (dfp) {
822 needscan = d->hdr.bestfree[2].length; 829 needscan = (d->hdr.bestfree[2].length != 0);
823 if (!needscan) { 830 if (!needscan) {
824 xfs_dir2_data_freeremove(d, dfp, needlogp); 831 xfs_dir2_data_freeremove(d, dfp, needlogp);
825 (void)xfs_dir2_data_freeinsert(d, newdup, 832 (void)xfs_dir2_data_freeinsert(d, newdup,