aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_dir2_block.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_dir2_block.c')
-rw-r--r--fs/xfs/xfs_dir2_block.c195
1 files changed, 99 insertions, 96 deletions
diff --git a/fs/xfs/xfs_dir2_block.c b/fs/xfs/xfs_dir2_block.c
index 31bc99faa704..972ded595476 100644
--- a/fs/xfs/xfs_dir2_block.c
+++ b/fs/xfs/xfs_dir2_block.c
@@ -81,7 +81,7 @@ xfs_dir2_block_addname(
81 xfs_mount_t *mp; /* filesystem mount point */ 81 xfs_mount_t *mp; /* filesystem mount point */
82 int needlog; /* need to log header */ 82 int needlog; /* need to log header */
83 int needscan; /* need to rescan freespace */ 83 int needscan; /* need to rescan freespace */
84 xfs_dir2_data_off_t *tagp; /* pointer to tag value */ 84 __be16 *tagp; /* pointer to tag value */
85 xfs_trans_t *tp; /* transaction structure */ 85 xfs_trans_t *tp; /* transaction structure */
86 86
87 xfs_dir2_trace_args("block_addname", args); 87 xfs_dir2_trace_args("block_addname", args);
@@ -100,8 +100,7 @@ xfs_dir2_block_addname(
100 /* 100 /*
101 * Check the magic number, corrupted if wrong. 101 * Check the magic number, corrupted if wrong.
102 */ 102 */
103 if (unlikely(INT_GET(block->hdr.magic, ARCH_CONVERT) 103 if (unlikely(be32_to_cpu(block->hdr.magic) != XFS_DIR2_BLOCK_MAGIC)) {
104 != XFS_DIR2_BLOCK_MAGIC)) {
105 XFS_CORRUPTION_ERROR("xfs_dir2_block_addname", 104 XFS_CORRUPTION_ERROR("xfs_dir2_block_addname",
106 XFS_ERRLEVEL_LOW, mp, block); 105 XFS_ERRLEVEL_LOW, mp, block);
107 xfs_da_brelse(tp, bp); 106 xfs_da_brelse(tp, bp);
@@ -121,38 +120,38 @@ xfs_dir2_block_addname(
121 /* 120 /*
122 * Tag just before the first leaf entry. 121 * Tag just before the first leaf entry.
123 */ 122 */
124 tagp = (xfs_dir2_data_off_t *)blp - 1; 123 tagp = (__be16 *)blp - 1;
125 /* 124 /*
126 * Data object just before the first leaf entry. 125 * Data object just before the first leaf entry.
127 */ 126 */
128 enddup = (xfs_dir2_data_unused_t *)((char *)block + INT_GET(*tagp, ARCH_CONVERT)); 127 enddup = (xfs_dir2_data_unused_t *)((char *)block + be16_to_cpu(*tagp));
129 /* 128 /*
130 * If it's not free then can't do this add without cleaning up: 129 * If it's not free then can't do this add without cleaning up:
131 * the space before the first leaf entry needs to be free so it 130 * the space before the first leaf entry needs to be free so it
132 * can be expanded to hold the pointer to the new entry. 131 * can be expanded to hold the pointer to the new entry.
133 */ 132 */
134 if (INT_GET(enddup->freetag, ARCH_CONVERT) != XFS_DIR2_DATA_FREE_TAG) 133 if (be16_to_cpu(enddup->freetag) != XFS_DIR2_DATA_FREE_TAG)
135 dup = enddup = NULL; 134 dup = enddup = NULL;
136 /* 135 /*
137 * Check out the biggest freespace and see if it's the same one. 136 * Check out the biggest freespace and see if it's the same one.
138 */ 137 */
139 else { 138 else {
140 dup = (xfs_dir2_data_unused_t *) 139 dup = (xfs_dir2_data_unused_t *)
141 ((char *)block + INT_GET(bf[0].offset, ARCH_CONVERT)); 140 ((char *)block + be16_to_cpu(bf[0].offset));
142 if (dup == enddup) { 141 if (dup == enddup) {
143 /* 142 /*
144 * It is the biggest freespace, is it too small 143 * It is the biggest freespace, is it too small
145 * to hold the new leaf too? 144 * to hold the new leaf too?
146 */ 145 */
147 if (INT_GET(dup->length, ARCH_CONVERT) < len + (uint)sizeof(*blp)) { 146 if (be16_to_cpu(dup->length) < len + (uint)sizeof(*blp)) {
148 /* 147 /*
149 * Yes, we use the second-largest 148 * Yes, we use the second-largest
150 * entry instead if it works. 149 * entry instead if it works.
151 */ 150 */
152 if (INT_GET(bf[1].length, ARCH_CONVERT) >= len) 151 if (be16_to_cpu(bf[1].length) >= len)
153 dup = (xfs_dir2_data_unused_t *) 152 dup = (xfs_dir2_data_unused_t *)
154 ((char *)block + 153 ((char *)block +
155 INT_GET(bf[1].offset, ARCH_CONVERT)); 154 be16_to_cpu(bf[1].offset));
156 else 155 else
157 dup = NULL; 156 dup = NULL;
158 } 157 }
@@ -161,7 +160,7 @@ xfs_dir2_block_addname(
161 * Not the same free entry, 160 * Not the same free entry,
162 * just check its length. 161 * just check its length.
163 */ 162 */
164 if (INT_GET(dup->length, ARCH_CONVERT) < len) { 163 if (be16_to_cpu(dup->length) < len) {
165 dup = NULL; 164 dup = NULL;
166 } 165 }
167 } 166 }
@@ -172,9 +171,9 @@ xfs_dir2_block_addname(
172 * If there are stale entries we'll use one for the leaf. 171 * If there are stale entries we'll use one for the leaf.
173 * Is the biggest entry enough to avoid compaction? 172 * Is the biggest entry enough to avoid compaction?
174 */ 173 */
175 else if (INT_GET(bf[0].length, ARCH_CONVERT) >= len) { 174 else if (be16_to_cpu(bf[0].length) >= len) {
176 dup = (xfs_dir2_data_unused_t *) 175 dup = (xfs_dir2_data_unused_t *)
177 ((char *)block + INT_GET(bf[0].offset, ARCH_CONVERT)); 176 ((char *)block + be16_to_cpu(bf[0].offset));
178 compact = 0; 177 compact = 0;
179 } 178 }
180 /* 179 /*
@@ -184,20 +183,20 @@ xfs_dir2_block_addname(
184 /* 183 /*
185 * Tag just before the first leaf entry. 184 * Tag just before the first leaf entry.
186 */ 185 */
187 tagp = (xfs_dir2_data_off_t *)blp - 1; 186 tagp = (__be16 *)blp - 1;
188 /* 187 /*
189 * Data object just before the first leaf entry. 188 * Data object just before the first leaf entry.
190 */ 189 */
191 dup = (xfs_dir2_data_unused_t *)((char *)block + INT_GET(*tagp, ARCH_CONVERT)); 190 dup = (xfs_dir2_data_unused_t *)((char *)block + be16_to_cpu(*tagp));
192 /* 191 /*
193 * If it's not free then the data will go where the 192 * If it's not free then the data will go where the
194 * leaf data starts now, if it works at all. 193 * leaf data starts now, if it works at all.
195 */ 194 */
196 if (INT_GET(dup->freetag, ARCH_CONVERT) == XFS_DIR2_DATA_FREE_TAG) { 195 if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
197 if (INT_GET(dup->length, ARCH_CONVERT) + (INT_GET(btp->stale, ARCH_CONVERT) - 1) * 196 if (be16_to_cpu(dup->length) + (be32_to_cpu(btp->stale) - 1) *
198 (uint)sizeof(*blp) < len) 197 (uint)sizeof(*blp) < len)
199 dup = NULL; 198 dup = NULL;
200 } else if ((INT_GET(btp->stale, ARCH_CONVERT) - 1) * (uint)sizeof(*blp) < len) 199 } else if ((be32_to_cpu(btp->stale) - 1) * (uint)sizeof(*blp) < len)
201 dup = NULL; 200 dup = NULL;
202 else 201 else
203 dup = (xfs_dir2_data_unused_t *)blp; 202 dup = (xfs_dir2_data_unused_t *)blp;
@@ -243,11 +242,11 @@ xfs_dir2_block_addname(
243 int fromidx; /* source leaf index */ 242 int fromidx; /* source leaf index */
244 int toidx; /* target leaf index */ 243 int toidx; /* target leaf index */
245 244
246 for (fromidx = toidx = INT_GET(btp->count, ARCH_CONVERT) - 1, 245 for (fromidx = toidx = be32_to_cpu(btp->count) - 1,
247 highstale = lfloghigh = -1; 246 highstale = lfloghigh = -1;
248 fromidx >= 0; 247 fromidx >= 0;
249 fromidx--) { 248 fromidx--) {
250 if (INT_GET(blp[fromidx].address, ARCH_CONVERT) == XFS_DIR2_NULL_DATAPTR) { 249 if (be32_to_cpu(blp[fromidx].address) == XFS_DIR2_NULL_DATAPTR) {
251 if (highstale == -1) 250 if (highstale == -1)
252 highstale = toidx; 251 highstale = toidx;
253 else { 252 else {
@@ -260,15 +259,15 @@ xfs_dir2_block_addname(
260 blp[toidx] = blp[fromidx]; 259 blp[toidx] = blp[fromidx];
261 toidx--; 260 toidx--;
262 } 261 }
263 lfloglow = toidx + 1 - (INT_GET(btp->stale, ARCH_CONVERT) - 1); 262 lfloglow = toidx + 1 - (be32_to_cpu(btp->stale) - 1);
264 lfloghigh -= INT_GET(btp->stale, ARCH_CONVERT) - 1; 263 lfloghigh -= be32_to_cpu(btp->stale) - 1;
265 INT_MOD(btp->count, ARCH_CONVERT, -(INT_GET(btp->stale, ARCH_CONVERT) - 1)); 264 be32_add(&btp->count, -(be32_to_cpu(btp->stale) - 1));
266 xfs_dir2_data_make_free(tp, bp, 265 xfs_dir2_data_make_free(tp, bp,
267 (xfs_dir2_data_aoff_t)((char *)blp - (char *)block), 266 (xfs_dir2_data_aoff_t)((char *)blp - (char *)block),
268 (xfs_dir2_data_aoff_t)((INT_GET(btp->stale, ARCH_CONVERT) - 1) * sizeof(*blp)), 267 (xfs_dir2_data_aoff_t)((be32_to_cpu(btp->stale) - 1) * sizeof(*blp)),
269 &needlog, &needscan); 268 &needlog, &needscan);
270 blp += INT_GET(btp->stale, ARCH_CONVERT) - 1; 269 blp += be32_to_cpu(btp->stale) - 1;
271 INT_SET(btp->stale, ARCH_CONVERT, 1); 270 btp->stale = cpu_to_be32(1);
272 /* 271 /*
273 * If we now need to rebuild the bestfree map, do so. 272 * If we now need to rebuild the bestfree map, do so.
274 * This needs to happen before the next call to use_free. 273 * This needs to happen before the next call to use_free.
@@ -283,23 +282,23 @@ xfs_dir2_block_addname(
283 * Set leaf logging boundaries to impossible state. 282 * Set leaf logging boundaries to impossible state.
284 * For the no-stale case they're set explicitly. 283 * For the no-stale case they're set explicitly.
285 */ 284 */
286 else if (INT_GET(btp->stale, ARCH_CONVERT)) { 285 else if (btp->stale) {
287 lfloglow = INT_GET(btp->count, ARCH_CONVERT); 286 lfloglow = be32_to_cpu(btp->count);
288 lfloghigh = -1; 287 lfloghigh = -1;
289 } 288 }
290 /* 289 /*
291 * Find the slot that's first lower than our hash value, -1 if none. 290 * Find the slot that's first lower than our hash value, -1 if none.
292 */ 291 */
293 for (low = 0, high = INT_GET(btp->count, ARCH_CONVERT) - 1; low <= high; ) { 292 for (low = 0, high = be32_to_cpu(btp->count) - 1; low <= high; ) {
294 mid = (low + high) >> 1; 293 mid = (low + high) >> 1;
295 if ((hash = INT_GET(blp[mid].hashval, ARCH_CONVERT)) == args->hashval) 294 if ((hash = be32_to_cpu(blp[mid].hashval)) == args->hashval)
296 break; 295 break;
297 if (hash < args->hashval) 296 if (hash < args->hashval)
298 low = mid + 1; 297 low = mid + 1;
299 else 298 else
300 high = mid - 1; 299 high = mid - 1;
301 } 300 }
302 while (mid >= 0 && INT_GET(blp[mid].hashval, ARCH_CONVERT) >= args->hashval) { 301 while (mid >= 0 && be32_to_cpu(blp[mid].hashval) >= args->hashval) {
303 mid--; 302 mid--;
304 } 303 }
305 /* 304 /*
@@ -311,14 +310,14 @@ xfs_dir2_block_addname(
311 */ 310 */
312 xfs_dir2_data_use_free(tp, bp, enddup, 311 xfs_dir2_data_use_free(tp, bp, enddup,
313 (xfs_dir2_data_aoff_t) 312 (xfs_dir2_data_aoff_t)
314 ((char *)enddup - (char *)block + INT_GET(enddup->length, ARCH_CONVERT) - 313 ((char *)enddup - (char *)block + be16_to_cpu(enddup->length) -
315 sizeof(*blp)), 314 sizeof(*blp)),
316 (xfs_dir2_data_aoff_t)sizeof(*blp), 315 (xfs_dir2_data_aoff_t)sizeof(*blp),
317 &needlog, &needscan); 316 &needlog, &needscan);
318 /* 317 /*
319 * Update the tail (entry count). 318 * Update the tail (entry count).
320 */ 319 */
321 INT_MOD(btp->count, ARCH_CONVERT, +1); 320 be32_add(&btp->count, 1);
322 /* 321 /*
323 * If we now need to rebuild the bestfree map, do so. 322 * If we now need to rebuild the bestfree map, do so.
324 * This needs to happen before the next call to use_free. 323 * This needs to happen before the next call to use_free.
@@ -346,12 +345,12 @@ xfs_dir2_block_addname(
346 else { 345 else {
347 for (lowstale = mid; 346 for (lowstale = mid;
348 lowstale >= 0 && 347 lowstale >= 0 &&
349 INT_GET(blp[lowstale].address, ARCH_CONVERT) != XFS_DIR2_NULL_DATAPTR; 348 be32_to_cpu(blp[lowstale].address) != XFS_DIR2_NULL_DATAPTR;
350 lowstale--) 349 lowstale--)
351 continue; 350 continue;
352 for (highstale = mid + 1; 351 for (highstale = mid + 1;
353 highstale < INT_GET(btp->count, ARCH_CONVERT) && 352 highstale < be32_to_cpu(btp->count) &&
354 INT_GET(blp[highstale].address, ARCH_CONVERT) != XFS_DIR2_NULL_DATAPTR && 353 be32_to_cpu(blp[highstale].address) != XFS_DIR2_NULL_DATAPTR &&
355 (lowstale < 0 || mid - lowstale > highstale - mid); 354 (lowstale < 0 || mid - lowstale > highstale - mid);
356 highstale++) 355 highstale++)
357 continue; 356 continue;
@@ -359,7 +358,7 @@ xfs_dir2_block_addname(
359 * Move entries toward the low-numbered stale entry. 358 * Move entries toward the low-numbered stale entry.
360 */ 359 */
361 if (lowstale >= 0 && 360 if (lowstale >= 0 &&
362 (highstale == INT_GET(btp->count, ARCH_CONVERT) || 361 (highstale == be32_to_cpu(btp->count) ||
363 mid - lowstale <= highstale - mid)) { 362 mid - lowstale <= highstale - mid)) {
364 if (mid - lowstale) 363 if (mid - lowstale)
365 memmove(&blp[lowstale], &blp[lowstale + 1], 364 memmove(&blp[lowstale], &blp[lowstale + 1],
@@ -371,7 +370,7 @@ xfs_dir2_block_addname(
371 * Move entries toward the high-numbered stale entry. 370 * Move entries toward the high-numbered stale entry.
372 */ 371 */
373 else { 372 else {
374 ASSERT(highstale < INT_GET(btp->count, ARCH_CONVERT)); 373 ASSERT(highstale < be32_to_cpu(btp->count));
375 mid++; 374 mid++;
376 if (highstale - mid) 375 if (highstale - mid)
377 memmove(&blp[mid + 1], &blp[mid], 376 memmove(&blp[mid + 1], &blp[mid],
@@ -379,7 +378,7 @@ xfs_dir2_block_addname(
379 lfloglow = MIN(mid, lfloglow); 378 lfloglow = MIN(mid, lfloglow);
380 lfloghigh = MAX(highstale, lfloghigh); 379 lfloghigh = MAX(highstale, lfloghigh);
381 } 380 }
382 INT_MOD(btp->stale, ARCH_CONVERT, -1); 381 be32_add(&btp->stale, -1);
383 } 382 }
384 /* 383 /*
385 * Point to the new data entry. 384 * Point to the new data entry.
@@ -388,8 +387,9 @@ xfs_dir2_block_addname(
388 /* 387 /*
389 * Fill in the leaf entry. 388 * Fill in the leaf entry.
390 */ 389 */
391 INT_SET(blp[mid].hashval, ARCH_CONVERT, args->hashval); 390 blp[mid].hashval = cpu_to_be32(args->hashval);
392 INT_SET(blp[mid].address, ARCH_CONVERT, XFS_DIR2_BYTE_TO_DATAPTR(mp, (char *)dep - (char *)block)); 391 blp[mid].address = cpu_to_be32(XFS_DIR2_BYTE_TO_DATAPTR(mp,
392 (char *)dep - (char *)block));
393 xfs_dir2_block_log_leaf(tp, bp, lfloglow, lfloghigh); 393 xfs_dir2_block_log_leaf(tp, bp, lfloglow, lfloghigh);
394 /* 394 /*
395 * Mark space for the data entry used. 395 * Mark space for the data entry used.
@@ -404,7 +404,7 @@ xfs_dir2_block_addname(
404 dep->namelen = args->namelen; 404 dep->namelen = args->namelen;
405 memcpy(dep->name, args->name, args->namelen); 405 memcpy(dep->name, args->name, args->namelen);
406 tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep); 406 tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep);
407 INT_SET(*tagp, ARCH_CONVERT, (xfs_dir2_data_off_t)((char *)dep - (char *)block)); 407 *tagp = cpu_to_be16((char *)dep - (char *)block);
408 /* 408 /*
409 * Clean up the bestfree array and log the header, tail, and entry. 409 * Clean up the bestfree array and log the header, tail, and entry.
410 */ 410 */
@@ -485,8 +485,8 @@ xfs_dir2_block_getdents(
485 /* 485 /*
486 * Unused, skip it. 486 * Unused, skip it.
487 */ 487 */
488 if (INT_GET(dup->freetag, ARCH_CONVERT) == XFS_DIR2_DATA_FREE_TAG) { 488 if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
489 ptr += INT_GET(dup->length, ARCH_CONVERT); 489 ptr += be16_to_cpu(dup->length);
490 continue; 490 continue;
491 } 491 }
492 492
@@ -533,7 +533,7 @@ xfs_dir2_block_getdents(
533 533
534 /* 534 /*
535 * Reached the end of the block. 535 * Reached the end of the block.
536 * Set the offset to a nonexistent block 1 and return. 536 * Set the offset to a non-existent block 1 and return.
537 */ 537 */
538 *eofp = 1; 538 *eofp = 1;
539 539
@@ -622,7 +622,7 @@ xfs_dir2_block_lookup(
622 * Get the offset from the leaf entry, to point to the data. 622 * Get the offset from the leaf entry, to point to the data.
623 */ 623 */
624 dep = (xfs_dir2_data_entry_t *) 624 dep = (xfs_dir2_data_entry_t *)
625 ((char *)block + XFS_DIR2_DATAPTR_TO_OFF(mp, INT_GET(blp[ent].address, ARCH_CONVERT))); 625 ((char *)block + XFS_DIR2_DATAPTR_TO_OFF(mp, be32_to_cpu(blp[ent].address)));
626 /* 626 /*
627 * Fill in inode number, release the block. 627 * Fill in inode number, release the block.
628 */ 628 */
@@ -674,10 +674,10 @@ xfs_dir2_block_lookup_int(
674 * Loop doing a binary search for our hash value. 674 * Loop doing a binary search for our hash value.
675 * Find our entry, ENOENT if it's not there. 675 * Find our entry, ENOENT if it's not there.
676 */ 676 */
677 for (low = 0, high = INT_GET(btp->count, ARCH_CONVERT) - 1; ; ) { 677 for (low = 0, high = be32_to_cpu(btp->count) - 1; ; ) {
678 ASSERT(low <= high); 678 ASSERT(low <= high);
679 mid = (low + high) >> 1; 679 mid = (low + high) >> 1;
680 if ((hash = INT_GET(blp[mid].hashval, ARCH_CONVERT)) == args->hashval) 680 if ((hash = be32_to_cpu(blp[mid].hashval)) == args->hashval)
681 break; 681 break;
682 if (hash < args->hashval) 682 if (hash < args->hashval)
683 low = mid + 1; 683 low = mid + 1;
@@ -692,7 +692,7 @@ xfs_dir2_block_lookup_int(
692 /* 692 /*
693 * Back up to the first one with the right hash value. 693 * Back up to the first one with the right hash value.
694 */ 694 */
695 while (mid > 0 && INT_GET(blp[mid - 1].hashval, ARCH_CONVERT) == args->hashval) { 695 while (mid > 0 && be32_to_cpu(blp[mid - 1].hashval) == args->hashval) {
696 mid--; 696 mid--;
697 } 697 }
698 /* 698 /*
@@ -700,7 +700,7 @@ xfs_dir2_block_lookup_int(
700 * right hash value looking for our name. 700 * right hash value looking for our name.
701 */ 701 */
702 do { 702 do {
703 if ((addr = INT_GET(blp[mid].address, ARCH_CONVERT)) == XFS_DIR2_NULL_DATAPTR) 703 if ((addr = be32_to_cpu(blp[mid].address)) == XFS_DIR2_NULL_DATAPTR)
704 continue; 704 continue;
705 /* 705 /*
706 * Get pointer to the entry from the leaf. 706 * Get pointer to the entry from the leaf.
@@ -717,7 +717,7 @@ xfs_dir2_block_lookup_int(
717 *entno = mid; 717 *entno = mid;
718 return 0; 718 return 0;
719 } 719 }
720 } while (++mid < INT_GET(btp->count, ARCH_CONVERT) && INT_GET(blp[mid].hashval, ARCH_CONVERT) == hash); 720 } while (++mid < be32_to_cpu(btp->count) && be32_to_cpu(blp[mid].hashval) == hash);
721 /* 721 /*
722 * No match, release the buffer and return ENOENT. 722 * No match, release the buffer and return ENOENT.
723 */ 723 */
@@ -767,7 +767,7 @@ xfs_dir2_block_removename(
767 * Point to the data entry using the leaf entry. 767 * Point to the data entry using the leaf entry.
768 */ 768 */
769 dep = (xfs_dir2_data_entry_t *) 769 dep = (xfs_dir2_data_entry_t *)
770 ((char *)block + XFS_DIR2_DATAPTR_TO_OFF(mp, INT_GET(blp[ent].address, ARCH_CONVERT))); 770 ((char *)block + XFS_DIR2_DATAPTR_TO_OFF(mp, be32_to_cpu(blp[ent].address)));
771 /* 771 /*
772 * Mark the data entry's space free. 772 * Mark the data entry's space free.
773 */ 773 */
@@ -778,12 +778,12 @@ xfs_dir2_block_removename(
778 /* 778 /*
779 * Fix up the block tail. 779 * Fix up the block tail.
780 */ 780 */
781 INT_MOD(btp->stale, ARCH_CONVERT, +1); 781 be32_add(&btp->stale, 1);
782 xfs_dir2_block_log_tail(tp, bp); 782 xfs_dir2_block_log_tail(tp, bp);
783 /* 783 /*
784 * Remove the leaf entry by marking it stale. 784 * Remove the leaf entry by marking it stale.
785 */ 785 */
786 INT_SET(blp[ent].address, ARCH_CONVERT, XFS_DIR2_NULL_DATAPTR); 786 blp[ent].address = cpu_to_be32(XFS_DIR2_NULL_DATAPTR);
787 xfs_dir2_block_log_leaf(tp, bp, ent, ent); 787 xfs_dir2_block_log_leaf(tp, bp, ent, ent);
788 /* 788 /*
789 * Fix up bestfree, log the header if necessary. 789 * Fix up bestfree, log the header if necessary.
@@ -843,7 +843,7 @@ xfs_dir2_block_replace(
843 * Point to the data entry we need to change. 843 * Point to the data entry we need to change.
844 */ 844 */
845 dep = (xfs_dir2_data_entry_t *) 845 dep = (xfs_dir2_data_entry_t *)
846 ((char *)block + XFS_DIR2_DATAPTR_TO_OFF(mp, INT_GET(blp[ent].address, ARCH_CONVERT))); 846 ((char *)block + XFS_DIR2_DATAPTR_TO_OFF(mp, be32_to_cpu(blp[ent].address)));
847 ASSERT(INT_GET(dep->inumber, ARCH_CONVERT) != args->inumber); 847 ASSERT(INT_GET(dep->inumber, ARCH_CONVERT) != args->inumber);
848 /* 848 /*
849 * Change the inode number to the new value. 849 * Change the inode number to the new value.
@@ -868,8 +868,8 @@ xfs_dir2_block_sort(
868 868
869 la = a; 869 la = a;
870 lb = b; 870 lb = b;
871 return INT_GET(la->hashval, ARCH_CONVERT) < INT_GET(lb->hashval, ARCH_CONVERT) ? -1 : 871 return be32_to_cpu(la->hashval) < be32_to_cpu(lb->hashval) ? -1 :
872 (INT_GET(la->hashval, ARCH_CONVERT) > INT_GET(lb->hashval, ARCH_CONVERT) ? 1 : 0); 872 (be32_to_cpu(la->hashval) > be32_to_cpu(lb->hashval) ? 1 : 0);
873} 873}
874 874
875/* 875/*
@@ -881,7 +881,7 @@ xfs_dir2_leaf_to_block(
881 xfs_dabuf_t *lbp, /* leaf buffer */ 881 xfs_dabuf_t *lbp, /* leaf buffer */
882 xfs_dabuf_t *dbp) /* data buffer */ 882 xfs_dabuf_t *dbp) /* data buffer */
883{ 883{
884 xfs_dir2_data_off_t *bestsp; /* leaf bests table */ 884 __be16 *bestsp; /* leaf bests table */
885 xfs_dir2_block_t *block; /* block structure */ 885 xfs_dir2_block_t *block; /* block structure */
886 xfs_dir2_block_tail_t *btp; /* block tail */ 886 xfs_dir2_block_tail_t *btp; /* block tail */
887 xfs_inode_t *dp; /* incore directory inode */ 887 xfs_inode_t *dp; /* incore directory inode */
@@ -896,7 +896,7 @@ xfs_dir2_leaf_to_block(
896 int needscan; /* need to scan for bestfree */ 896 int needscan; /* need to scan for bestfree */
897 xfs_dir2_sf_hdr_t sfh; /* shortform header */ 897 xfs_dir2_sf_hdr_t sfh; /* shortform header */
898 int size; /* bytes used */ 898 int size; /* bytes used */
899 xfs_dir2_data_off_t *tagp; /* end of entry (tag) */ 899 __be16 *tagp; /* end of entry (tag) */
900 int to; /* block/leaf to index */ 900 int to; /* block/leaf to index */
901 xfs_trans_t *tp; /* transaction pointer */ 901 xfs_trans_t *tp; /* transaction pointer */
902 902
@@ -905,7 +905,7 @@ xfs_dir2_leaf_to_block(
905 tp = args->trans; 905 tp = args->trans;
906 mp = dp->i_mount; 906 mp = dp->i_mount;
907 leaf = lbp->data; 907 leaf = lbp->data;
908 ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT) == XFS_DIR2_LEAF1_MAGIC); 908 ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR2_LEAF1_MAGIC);
909 ltp = XFS_DIR2_LEAF_TAIL_P(mp, leaf); 909 ltp = XFS_DIR2_LEAF_TAIL_P(mp, leaf);
910 /* 910 /*
911 * If there are data blocks other than the first one, take this 911 * If there are data blocks other than the first one, take this
@@ -915,11 +915,11 @@ xfs_dir2_leaf_to_block(
915 */ 915 */
916 while (dp->i_d.di_size > mp->m_dirblksize) { 916 while (dp->i_d.di_size > mp->m_dirblksize) {
917 bestsp = XFS_DIR2_LEAF_BESTS_P(ltp); 917 bestsp = XFS_DIR2_LEAF_BESTS_P(ltp);
918 if (INT_GET(bestsp[INT_GET(ltp->bestcount, ARCH_CONVERT) - 1], ARCH_CONVERT) == 918 if (be16_to_cpu(bestsp[be32_to_cpu(ltp->bestcount) - 1]) ==
919 mp->m_dirblksize - (uint)sizeof(block->hdr)) { 919 mp->m_dirblksize - (uint)sizeof(block->hdr)) {
920 if ((error = 920 if ((error =
921 xfs_dir2_leaf_trim_data(args, lbp, 921 xfs_dir2_leaf_trim_data(args, lbp,
922 (xfs_dir2_db_t)(INT_GET(ltp->bestcount, ARCH_CONVERT) - 1)))) 922 (xfs_dir2_db_t)(be32_to_cpu(ltp->bestcount) - 1))))
923 goto out; 923 goto out;
924 } else { 924 } else {
925 error = 0; 925 error = 0;
@@ -935,28 +935,29 @@ xfs_dir2_leaf_to_block(
935 goto out; 935 goto out;
936 } 936 }
937 block = dbp->data; 937 block = dbp->data;
938 ASSERT(INT_GET(block->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC); 938 ASSERT(be32_to_cpu(block->hdr.magic) == XFS_DIR2_DATA_MAGIC);
939 /* 939 /*
940 * Size of the "leaf" area in the block. 940 * Size of the "leaf" area in the block.
941 */ 941 */
942 size = (uint)sizeof(block->tail) + 942 size = (uint)sizeof(block->tail) +
943 (uint)sizeof(*lep) * (INT_GET(leaf->hdr.count, ARCH_CONVERT) - INT_GET(leaf->hdr.stale, ARCH_CONVERT)); 943 (uint)sizeof(*lep) * (be16_to_cpu(leaf->hdr.count) - be16_to_cpu(leaf->hdr.stale));
944 /* 944 /*
945 * Look at the last data entry. 945 * Look at the last data entry.
946 */ 946 */
947 tagp = (xfs_dir2_data_off_t *)((char *)block + mp->m_dirblksize) - 1; 947 tagp = (__be16 *)((char *)block + mp->m_dirblksize) - 1;
948 dup = (xfs_dir2_data_unused_t *)((char *)block + INT_GET(*tagp, ARCH_CONVERT)); 948 dup = (xfs_dir2_data_unused_t *)((char *)block + be16_to_cpu(*tagp));
949 /* 949 /*
950 * If it's not free or is too short we can't do it. 950 * If it's not free or is too short we can't do it.
951 */ 951 */
952 if (INT_GET(dup->freetag, ARCH_CONVERT) != XFS_DIR2_DATA_FREE_TAG || INT_GET(dup->length, ARCH_CONVERT) < size) { 952 if (be16_to_cpu(dup->freetag) != XFS_DIR2_DATA_FREE_TAG ||
953 be16_to_cpu(dup->length) < size) {
953 error = 0; 954 error = 0;
954 goto out; 955 goto out;
955 } 956 }
956 /* 957 /*
957 * Start converting it to block form. 958 * Start converting it to block form.
958 */ 959 */
959 INT_SET(block->hdr.magic, ARCH_CONVERT, XFS_DIR2_BLOCK_MAGIC); 960 block->hdr.magic = cpu_to_be32(XFS_DIR2_BLOCK_MAGIC);
960 needlog = 1; 961 needlog = 1;
961 needscan = 0; 962 needscan = 0;
962 /* 963 /*
@@ -968,20 +969,20 @@ xfs_dir2_leaf_to_block(
968 * Initialize the block tail. 969 * Initialize the block tail.
969 */ 970 */
970 btp = XFS_DIR2_BLOCK_TAIL_P(mp, block); 971 btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
971 INT_SET(btp->count, ARCH_CONVERT, INT_GET(leaf->hdr.count, ARCH_CONVERT) - INT_GET(leaf->hdr.stale, ARCH_CONVERT)); 972 btp->count = cpu_to_be32(be16_to_cpu(leaf->hdr.count) - be16_to_cpu(leaf->hdr.stale));
972 btp->stale = 0; 973 btp->stale = 0;
973 xfs_dir2_block_log_tail(tp, dbp); 974 xfs_dir2_block_log_tail(tp, dbp);
974 /* 975 /*
975 * Initialize the block leaf area. We compact out stale entries. 976 * Initialize the block leaf area. We compact out stale entries.
976 */ 977 */
977 lep = XFS_DIR2_BLOCK_LEAF_P(btp); 978 lep = XFS_DIR2_BLOCK_LEAF_P(btp);
978 for (from = to = 0; from < INT_GET(leaf->hdr.count, ARCH_CONVERT); from++) { 979 for (from = to = 0; from < be16_to_cpu(leaf->hdr.count); from++) {
979 if (INT_GET(leaf->ents[from].address, ARCH_CONVERT) == XFS_DIR2_NULL_DATAPTR) 980 if (be32_to_cpu(leaf->ents[from].address) == XFS_DIR2_NULL_DATAPTR)
980 continue; 981 continue;
981 lep[to++] = leaf->ents[from]; 982 lep[to++] = leaf->ents[from];
982 } 983 }
983 ASSERT(to == INT_GET(btp->count, ARCH_CONVERT)); 984 ASSERT(to == be32_to_cpu(btp->count));
984 xfs_dir2_block_log_leaf(tp, dbp, 0, INT_GET(btp->count, ARCH_CONVERT) - 1); 985 xfs_dir2_block_log_leaf(tp, dbp, 0, be32_to_cpu(btp->count) - 1);
985 /* 986 /*
986 * Scan the bestfree if we need it and log the data block header. 987 * Scan the bestfree if we need it and log the data block header.
987 */ 988 */
@@ -1043,7 +1044,7 @@ xfs_dir2_sf_to_block(
1043 int offset; /* target block offset */ 1044 int offset; /* target block offset */
1044 xfs_dir2_sf_entry_t *sfep; /* sf entry pointer */ 1045 xfs_dir2_sf_entry_t *sfep; /* sf entry pointer */
1045 xfs_dir2_sf_t *sfp; /* shortform structure */ 1046 xfs_dir2_sf_t *sfp; /* shortform structure */
1046 xfs_dir2_data_off_t *tagp; /* end of data entry */ 1047 __be16 *tagp; /* end of data entry */
1047 xfs_trans_t *tp; /* transaction pointer */ 1048 xfs_trans_t *tp; /* transaction pointer */
1048 1049
1049 xfs_dir2_trace_args("sf_to_block", args); 1050 xfs_dir2_trace_args("sf_to_block", args);
@@ -1095,12 +1096,12 @@ xfs_dir2_sf_to_block(
1095 return error; 1096 return error;
1096 } 1097 }
1097 block = bp->data; 1098 block = bp->data;
1098 INT_SET(block->hdr.magic, ARCH_CONVERT, XFS_DIR2_BLOCK_MAGIC); 1099 block->hdr.magic = cpu_to_be32(XFS_DIR2_BLOCK_MAGIC);
1099 /* 1100 /*
1100 * Compute size of block "tail" area. 1101 * Compute size of block "tail" area.
1101 */ 1102 */
1102 i = (uint)sizeof(*btp) + 1103 i = (uint)sizeof(*btp) +
1103 (INT_GET(sfp->hdr.count, ARCH_CONVERT) + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t); 1104 (sfp->hdr.count + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t);
1104 /* 1105 /*
1105 * The whole thing is initialized to free by the init routine. 1106 * The whole thing is initialized to free by the init routine.
1106 * Say we're using the leaf and tail area. 1107 * Say we're using the leaf and tail area.
@@ -1114,7 +1115,7 @@ xfs_dir2_sf_to_block(
1114 * Fill in the tail. 1115 * Fill in the tail.
1115 */ 1116 */
1116 btp = XFS_DIR2_BLOCK_TAIL_P(mp, block); 1117 btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
1117 INT_SET(btp->count, ARCH_CONVERT, INT_GET(sfp->hdr.count, ARCH_CONVERT) + 2); /* ., .. */ 1118 btp->count = cpu_to_be32(sfp->hdr.count + 2); /* ., .. */
1118 btp->stale = 0; 1119 btp->stale = 0;
1119 blp = XFS_DIR2_BLOCK_LEAF_P(btp); 1120 blp = XFS_DIR2_BLOCK_LEAF_P(btp);
1120 endoffset = (uint)((char *)blp - (char *)block); 1121 endoffset = (uint)((char *)blp - (char *)block);
@@ -1123,7 +1124,7 @@ xfs_dir2_sf_to_block(
1123 */ 1124 */
1124 xfs_dir2_data_use_free(tp, bp, dup, 1125 xfs_dir2_data_use_free(tp, bp, dup,
1125 (xfs_dir2_data_aoff_t)((char *)dup - (char *)block), 1126 (xfs_dir2_data_aoff_t)((char *)dup - (char *)block),
1126 INT_GET(dup->length, ARCH_CONVERT), &needlog, &needscan); 1127 be16_to_cpu(dup->length), &needlog, &needscan);
1127 /* 1128 /*
1128 * Create entry for . 1129 * Create entry for .
1129 */ 1130 */
@@ -1133,10 +1134,11 @@ xfs_dir2_sf_to_block(
1133 dep->namelen = 1; 1134 dep->namelen = 1;
1134 dep->name[0] = '.'; 1135 dep->name[0] = '.';
1135 tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep); 1136 tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep);
1136 INT_SET(*tagp, ARCH_CONVERT, (xfs_dir2_data_off_t)((char *)dep - (char *)block)); 1137 *tagp = cpu_to_be16((char *)dep - (char *)block);
1137 xfs_dir2_data_log_entry(tp, bp, dep); 1138 xfs_dir2_data_log_entry(tp, bp, dep);
1138 INT_SET(blp[0].hashval, ARCH_CONVERT, xfs_dir_hash_dot); 1139 blp[0].hashval = cpu_to_be32(xfs_dir_hash_dot);
1139 INT_SET(blp[0].address, ARCH_CONVERT, XFS_DIR2_BYTE_TO_DATAPTR(mp, (char *)dep - (char *)block)); 1140 blp[0].address = cpu_to_be32(XFS_DIR2_BYTE_TO_DATAPTR(mp,
1141 (char *)dep - (char *)block));
1140 /* 1142 /*
1141 * Create entry for .. 1143 * Create entry for ..
1142 */ 1144 */
@@ -1146,15 +1148,16 @@ xfs_dir2_sf_to_block(
1146 dep->namelen = 2; 1148 dep->namelen = 2;
1147 dep->name[0] = dep->name[1] = '.'; 1149 dep->name[0] = dep->name[1] = '.';
1148 tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep); 1150 tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep);
1149 INT_SET(*tagp, ARCH_CONVERT, (xfs_dir2_data_off_t)((char *)dep - (char *)block)); 1151 *tagp = cpu_to_be16((char *)dep - (char *)block);
1150 xfs_dir2_data_log_entry(tp, bp, dep); 1152 xfs_dir2_data_log_entry(tp, bp, dep);
1151 INT_SET(blp[1].hashval, ARCH_CONVERT, xfs_dir_hash_dotdot); 1153 blp[1].hashval = cpu_to_be32(xfs_dir_hash_dotdot);
1152 INT_SET(blp[1].address, ARCH_CONVERT, XFS_DIR2_BYTE_TO_DATAPTR(mp, (char *)dep - (char *)block)); 1154 blp[1].address = cpu_to_be32(XFS_DIR2_BYTE_TO_DATAPTR(mp,
1155 (char *)dep - (char *)block));
1153 offset = XFS_DIR2_DATA_FIRST_OFFSET; 1156 offset = XFS_DIR2_DATA_FIRST_OFFSET;
1154 /* 1157 /*
1155 * Loop over existing entries, stuff them in. 1158 * Loop over existing entries, stuff them in.
1156 */ 1159 */
1157 if ((i = 0) == INT_GET(sfp->hdr.count, ARCH_CONVERT)) 1160 if ((i = 0) == sfp->hdr.count)
1158 sfep = NULL; 1161 sfep = NULL;
1159 else 1162 else
1160 sfep = XFS_DIR2_SF_FIRSTENTRY(sfp); 1163 sfep = XFS_DIR2_SF_FIRSTENTRY(sfp);
@@ -1176,15 +1179,14 @@ xfs_dir2_sf_to_block(
1176 if (offset < newoffset) { 1179 if (offset < newoffset) {
1177 dup = (xfs_dir2_data_unused_t *) 1180 dup = (xfs_dir2_data_unused_t *)
1178 ((char *)block + offset); 1181 ((char *)block + offset);
1179 INT_SET(dup->freetag, ARCH_CONVERT, XFS_DIR2_DATA_FREE_TAG); 1182 dup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG);
1180 INT_SET(dup->length, ARCH_CONVERT, newoffset - offset); 1183 dup->length = cpu_to_be16(newoffset - offset);
1181 INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT, 1184 *XFS_DIR2_DATA_UNUSED_TAG_P(dup) = cpu_to_be16(
1182 (xfs_dir2_data_off_t)
1183 ((char *)dup - (char *)block)); 1185 ((char *)dup - (char *)block));
1184 xfs_dir2_data_log_unused(tp, bp, dup); 1186 xfs_dir2_data_log_unused(tp, bp, dup);
1185 (void)xfs_dir2_data_freeinsert((xfs_dir2_data_t *)block, 1187 (void)xfs_dir2_data_freeinsert((xfs_dir2_data_t *)block,
1186 dup, &dummy); 1188 dup, &dummy);
1187 offset += INT_GET(dup->length, ARCH_CONVERT); 1189 offset += be16_to_cpu(dup->length);
1188 continue; 1190 continue;
1189 } 1191 }
1190 /* 1192 /*
@@ -1196,13 +1198,14 @@ xfs_dir2_sf_to_block(
1196 dep->namelen = sfep->namelen; 1198 dep->namelen = sfep->namelen;
1197 memcpy(dep->name, sfep->name, dep->namelen); 1199 memcpy(dep->name, sfep->name, dep->namelen);
1198 tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep); 1200 tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep);
1199 INT_SET(*tagp, ARCH_CONVERT, (xfs_dir2_data_off_t)((char *)dep - (char *)block)); 1201 *tagp = cpu_to_be16((char *)dep - (char *)block);
1200 xfs_dir2_data_log_entry(tp, bp, dep); 1202 xfs_dir2_data_log_entry(tp, bp, dep);
1201 INT_SET(blp[2 + i].hashval, ARCH_CONVERT, xfs_da_hashname((char *)sfep->name, sfep->namelen)); 1203 blp[2 + i].hashval = cpu_to_be32(xfs_da_hashname(
1202 INT_SET(blp[2 + i].address, ARCH_CONVERT, XFS_DIR2_BYTE_TO_DATAPTR(mp, 1204 (char *)sfep->name, sfep->namelen));
1205 blp[2 + i].address = cpu_to_be32(XFS_DIR2_BYTE_TO_DATAPTR(mp,
1203 (char *)dep - (char *)block)); 1206 (char *)dep - (char *)block));
1204 offset = (int)((char *)(tagp + 1) - (char *)block); 1207 offset = (int)((char *)(tagp + 1) - (char *)block);
1205 if (++i == INT_GET(sfp->hdr.count, ARCH_CONVERT)) 1208 if (++i == sfp->hdr.count)
1206 sfep = NULL; 1209 sfep = NULL;
1207 else 1210 else
1208 sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep); 1211 sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep);
@@ -1212,13 +1215,13 @@ xfs_dir2_sf_to_block(
1212 /* 1215 /*
1213 * Sort the leaf entries by hash value. 1216 * Sort the leaf entries by hash value.
1214 */ 1217 */
1215 xfs_sort(blp, INT_GET(btp->count, ARCH_CONVERT), sizeof(*blp), xfs_dir2_block_sort); 1218 xfs_sort(blp, be32_to_cpu(btp->count), sizeof(*blp), xfs_dir2_block_sort);
1216 /* 1219 /*
1217 * Log the leaf entry area and tail. 1220 * Log the leaf entry area and tail.
1218 * Already logged the header in data_init, ignore needlog. 1221 * Already logged the header in data_init, ignore needlog.
1219 */ 1222 */
1220 ASSERT(needscan == 0); 1223 ASSERT(needscan == 0);
1221 xfs_dir2_block_log_leaf(tp, bp, 0, INT_GET(btp->count, ARCH_CONVERT) - 1); 1224 xfs_dir2_block_log_leaf(tp, bp, 0, be32_to_cpu(btp->count) - 1);
1222 xfs_dir2_block_log_tail(tp, bp); 1225 xfs_dir2_block_log_tail(tp, bp);
1223 xfs_dir2_data_check(dp, bp); 1226 xfs_dir2_data_check(dp, bp);
1224 xfs_da_buf_done(bp); 1227 xfs_da_buf_done(bp);