]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - libxfs/xfs_dir2_sf.c
%p has an implied 0x prefix - qa is sensitive to this, so revert.
[thirdparty/xfsprogs-dev.git] / libxfs / xfs_dir2_sf.c
CommitLineData
2bd0ea18
NS
1/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33/*
34 * xfs_dir2_sf.c
35 * Shortform directory implementation for v2 directories.
36 */
37
38#include <xfs.h>
39
40
41/*
42 * Given a block directory (dp/block), calculate its size as a shortform (sf)
43 * directory and a header for the sf directory, if it will fit it the
44 * space currently present in the inode. If it won't fit, the output
45 * size is too big (but not accurate).
46 */
47int /* size for sf form */
48xfs_dir2_block_sfsize(
49 xfs_inode_t *dp, /* incore inode pointer */
50 xfs_dir2_block_t *block, /* block directory data */
51 xfs_dir2_sf_hdr_t *sfhp) /* output: header for sf form */
52{
53 xfs_dir2_dataptr_t addr; /* data entry address */
54 xfs_dir2_leaf_entry_t *blp; /* leaf area of the block */
55 xfs_dir2_block_tail_t *btp; /* tail area of the block */
56 int count; /* shortform entry count */
57 xfs_dir2_data_entry_t *dep; /* data entry in the block */
58 int i; /* block entry index */
59 int i8count; /* count of big-inode entries */
60 int isdot; /* entry is "." */
61 int isdotdot; /* entry is ".." */
62 xfs_mount_t *mp; /* mount structure pointer */
63 int namelen; /* total name bytes */
64 xfs_ino_t parent; /* parent inode number */
65 int size; /* total computed size */
66
67 mp = dp->i_mount;
68
69 count = i8count = namelen = 0;
70 btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
71 blp = XFS_DIR2_BLOCK_LEAF_P_ARCH(btp, ARCH_CONVERT);
72
73 /*
74 * Iterate over the block's data entries by using the leaf pointers.
75 */
76 for (i = 0; i < INT_GET(btp->count, ARCH_CONVERT); i++) {
77 if ((addr = INT_GET(blp[i].address, ARCH_CONVERT)) == XFS_DIR2_NULL_DATAPTR)
78 continue;
79 /*
80 * Calculate the pointer to the entry at hand.
81 */
82 dep = (xfs_dir2_data_entry_t *)
83 ((char *)block + XFS_DIR2_DATAPTR_TO_OFF(mp, addr));
84 /*
85 * Detect . and .., so we can special-case them.
86 * . is not included in sf directories.
87 * .. is included by just the parent inode number.
88 */
89 isdot = dep->namelen == 1 && dep->name[0] == '.';
90 isdotdot =
91 dep->namelen == 2 &&
92 dep->name[0] == '.' && dep->name[1] == '.';
93#if XFS_BIG_FILESYSTEMS
94 if (!isdot)
95 i8count += INT_GET(dep->inumber, ARCH_CONVERT) > XFS_DIR2_MAX_SHORT_INUM;
96#endif
97 if (!isdot && !isdotdot) {
98 count++;
99 namelen += dep->namelen;
100 } else if (isdotdot)
101 parent = INT_GET(dep->inumber, ARCH_CONVERT);
102 /*
103 * Calculate the new size, see if we should give up yet.
104 */
105 size = XFS_DIR2_SF_HDR_SIZE(i8count) + /* header */
106 count + /* namelen */
107 count * (uint)sizeof(xfs_dir2_sf_off_t) + /* offset */
108 namelen + /* name */
109 (i8count ? /* inumber */
110 (uint)sizeof(xfs_dir2_ino8_t) * count :
111 (uint)sizeof(xfs_dir2_ino4_t) * count);
112 if (size > XFS_IFORK_DSIZE(dp))
113 return size; /* size value is a failure */
114 }
115 /*
116 * Create the output header, if it worked.
117 */
118 sfhp->count = count;
119 sfhp->i8count = i8count;
120 XFS_DIR2_SF_PUT_INUMBER_ARCH((xfs_dir2_sf_t *)sfhp, &parent, &sfhp->parent, ARCH_CONVERT);
121 return size;
122}
123
124/*
125 * Convert a block format directory to shortform.
126 * Caller has already checked that it will fit, and built us a header.
127 */
128int /* error */
129xfs_dir2_block_to_sf(
130 xfs_da_args_t *args, /* operation arguments */
131 xfs_dabuf_t *bp, /* block buffer */
132 int size, /* shortform directory size */
133 xfs_dir2_sf_hdr_t *sfhp) /* shortform directory hdr */
134{
135 xfs_dir2_block_t *block; /* block structure */
136 xfs_dir2_block_tail_t *btp; /* block tail pointer */
137 xfs_dir2_data_entry_t *dep; /* data entry pointer */
138 xfs_inode_t *dp; /* incore directory inode */
139 xfs_dir2_data_unused_t *dup; /* unused data pointer */
140 char *endptr; /* end of data entries */
141 int error; /* error return value */
142 int logflags; /* inode logging flags */
143 xfs_mount_t *mp; /* filesystem mount point */
144 char *ptr; /* current data pointer */
145 xfs_dir2_sf_entry_t *sfep; /* shortform entry */
146 xfs_dir2_sf_t *sfp; /* shortform structure */
147 xfs_ino_t temp;
148
149 xfs_dir2_trace_args_sb("block_to_sf", args, size, bp);
150 dp = args->dp;
151 mp = dp->i_mount;
152
153 /*
154 * Make a copy of the block data, so we can shrink the inode
155 * and add local data.
156 */
157 block = kmem_alloc(mp->m_dirblksize, KM_SLEEP);
158 bcopy(bp->data, block, mp->m_dirblksize);
159 logflags = XFS_ILOG_CORE;
160 if (error = xfs_dir2_shrink_inode(args, mp->m_dirdatablk, bp)) {
161#pragma mips_frequency_hint NEVER
162 ASSERT(error != ENOSPC);
163 goto out;
164 }
165 /*
166 * The buffer is now unconditionally gone, whether
167 * xfs_dir2_shrink_inode worked or not.
168 *
169 * Convert the inode to local format.
170 */
171 dp->i_df.if_flags &= ~XFS_IFEXTENTS;
172 dp->i_df.if_flags |= XFS_IFINLINE;
173 dp->i_d.di_format = XFS_DINODE_FMT_LOCAL;
174 ASSERT(dp->i_df.if_bytes == 0);
175 xfs_idata_realloc(dp, size, XFS_DATA_FORK);
176 logflags |= XFS_ILOG_DDATA;
177 /*
178 * Copy the header into the newly allocate local space.
179 */
180 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
181 bcopy(sfhp, sfp, XFS_DIR2_SF_HDR_SIZE(sfhp->i8count));
182 dp->i_d.di_size = size;
183 /*
184 * Set up to loop over the block's entries.
185 */
186 btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
187 ptr = (char *)block->u;
188 endptr = (char *)XFS_DIR2_BLOCK_LEAF_P_ARCH(btp, ARCH_CONVERT);
189 sfep = XFS_DIR2_SF_FIRSTENTRY(sfp);
190 /*
191 * Loop over the active and unused entries.
192 * Stop when we reach the leaf/tail portion of the block.
193 */
194 while (ptr < endptr) {
195 /*
196 * If it's unused, just skip over it.
197 */
198 dup = (xfs_dir2_data_unused_t *)ptr;
199 if (INT_GET(dup->freetag, ARCH_CONVERT) == XFS_DIR2_DATA_FREE_TAG) {
200 ptr += INT_GET(dup->length, ARCH_CONVERT);
201 continue;
202 }
203 dep = (xfs_dir2_data_entry_t *)ptr;
204 /*
205 * Skip .
206 */
207 if (dep->namelen == 1 && dep->name[0] == '.')
208 ASSERT(INT_GET(dep->inumber, ARCH_CONVERT) == dp->i_ino);
209 /*
210 * Skip .., but make sure the inode number is right.
211 */
212 else if (dep->namelen == 2 &&
213 dep->name[0] == '.' && dep->name[1] == '.')
214 ASSERT(INT_GET(dep->inumber, ARCH_CONVERT) ==
215 XFS_DIR2_SF_GET_INUMBER_ARCH(sfp, &sfp->hdr.parent, ARCH_CONVERT));
216 /*
217 * Normal entry, copy it into shortform.
218 */
219 else {
220 sfep->namelen = dep->namelen;
221 XFS_DIR2_SF_PUT_OFFSET_ARCH(sfep,
222 (xfs_dir2_data_aoff_t)
223 ((char *)dep - (char *)block), ARCH_CONVERT);
224 bcopy(dep->name, sfep->name, dep->namelen);
225 temp=INT_GET(dep->inumber, ARCH_CONVERT);
226 XFS_DIR2_SF_PUT_INUMBER_ARCH(sfp, &temp,
227 XFS_DIR2_SF_INUMBERP(sfep), ARCH_CONVERT);
228 sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep);
229 }
230 ptr += XFS_DIR2_DATA_ENTSIZE(dep->namelen);
231 }
232 ASSERT((char *)sfep - (char *)sfp == size);
233 xfs_dir2_sf_check(args);
234out:
235 xfs_trans_log_inode(args->trans, dp, logflags);
236 kmem_free(block, mp->m_dirblksize);
237 return error;
238}
239
240/*
241 * Add a name to a shortform directory.
242 * There are two algorithms, "easy" and "hard" which we decide on
243 * before changing anything.
244 * Convert to block form if necessary, if the new entry won't fit.
245 */
246int /* error */
247xfs_dir2_sf_addname(
248 xfs_da_args_t *args) /* operation arguments */
249{
250 int add_entsize; /* size of the new entry */
251 xfs_inode_t *dp; /* incore directory inode */
252 int error; /* error return value */
253 int incr_isize; /* total change in size */
254 int new_isize; /* di_size after adding name */
255 int objchange; /* changing to 8-byte inodes */
256 xfs_dir2_data_aoff_t offset; /* offset for new entry */
257 int old_isize; /* di_size before adding name */
258 int pick; /* which algorithm to use */
259 xfs_dir2_sf_t *sfp; /* shortform structure */
260 xfs_dir2_sf_entry_t *sfep; /* shortform entry */
261
262 xfs_dir2_trace_args("sf_addname", args);
263 ASSERT(xfs_dir2_sf_lookup(args) == ENOENT);
264 dp = args->dp;
265 ASSERT(dp->i_df.if_flags & XFS_IFINLINE);
266 /*
267 * Make sure the shortform value has some of its header.
268 */
269 if (dp->i_d.di_size < offsetof(xfs_dir2_sf_hdr_t, parent)) {
270#pragma mips_frequency_hint NEVER
271 ASSERT(XFS_FORCED_SHUTDOWN(dp->i_mount));
272 return XFS_ERROR(EIO);
273 }
274 ASSERT(dp->i_df.if_bytes == dp->i_d.di_size);
275 ASSERT(dp->i_df.if_u1.if_data != NULL);
276 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
277 ASSERT(dp->i_d.di_size >= XFS_DIR2_SF_HDR_SIZE(sfp->hdr.i8count));
278 /*
279 * Compute entry (and change in) size.
280 */
281 add_entsize = XFS_DIR2_SF_ENTSIZE_BYNAME(sfp, args->namelen);
282 incr_isize = add_entsize;
283#if XFS_BIG_FILESYSTEMS
284 /*
285 * Do we have to change to 8 byte inodes?
286 */
287 if (args->inumber > XFS_DIR2_MAX_SHORT_INUM && sfp->hdr.i8count == 0) {
288#pragma mips_frequency_hint NEVER
289 /*
290 * Yes, adjust the entry size and the total size.
291 */
292 add_entsize +=
293 (uint)sizeof(xfs_dir2_ino8_t) -
294 (uint)sizeof(xfs_dir2_ino4_t);
295 incr_isize +=
296 (sfp->hdr.count + 2) *
297 ((uint)sizeof(xfs_dir2_ino8_t) -
298 (uint)sizeof(xfs_dir2_ino4_t));
299 objchange = 1;
300 } else
301 objchange = 0;
302#else
303 objchange = 0;
304#endif
305 old_isize = (int)dp->i_d.di_size;
306 new_isize = old_isize + incr_isize;
307 /*
308 * Won't fit as shortform any more (due to size),
309 * or the pick routine says it won't (due to offset values).
310 */
311 if (new_isize > XFS_IFORK_DSIZE(dp) ||
312 (pick =
313 xfs_dir2_sf_addname_pick(args, objchange, &sfep, &offset)) == 0) {
314#pragma mips_frequency_hint NEVER
315 /*
316 * Just checking or no space reservation, it doesn't fit.
317 */
318 if (args->justcheck || args->total == 0)
319 return XFS_ERROR(ENOSPC);
320 /*
321 * Convert to block form then add the name.
322 */
323 error = xfs_dir2_sf_to_block(args);
324 if (error)
325 return error;
326 return xfs_dir2_block_addname(args);
327 }
328 /*
329 * Just checking, it fits.
330 */
331 if (args->justcheck)
332 return 0;
333 /*
334 * Do it the easy way - just add it at the end.
335 */
336 if (pick == 1)
337 xfs_dir2_sf_addname_easy(args, sfep, offset, new_isize);
338 /*
339 * Do it the hard way - look for a place to insert the new entry.
340 * Convert to 8 byte inode numbers first if necessary.
341 */
342 else {
343 ASSERT(pick == 2);
344#if XFS_BIG_FILESYSTEMS
345 if (objchange)
346 xfs_dir2_sf_toino8(args);
347#endif
348 xfs_dir2_sf_addname_hard(args, objchange, new_isize);
349 }
350 xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA);
351 return 0;
352}
353
354/*
355 * Add the new entry the "easy" way.
356 * This is copying the old directory and adding the new entry at the end.
357 * Since it's sorted by "offset" we need room after the last offset
358 * that's already there, and then room to convert to a block directory.
359 * This is already checked by the pick routine.
360 */
361STATIC void
362xfs_dir2_sf_addname_easy(
363 xfs_da_args_t *args, /* operation arguments */
364 xfs_dir2_sf_entry_t *sfep, /* pointer to new entry */
365 xfs_dir2_data_aoff_t offset, /* offset to use for new ent */
366 int new_isize) /* new directory size */
367{
368 int byteoff; /* byte offset in sf dir */
369 xfs_inode_t *dp; /* incore directory inode */
370 xfs_dir2_sf_t *sfp; /* shortform structure */
371
372 dp = args->dp;
373
374 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
375 byteoff = (int)((char *)sfep - (char *)sfp);
376 /*
377 * Grow the in-inode space.
378 */
379 xfs_idata_realloc(dp, XFS_DIR2_SF_ENTSIZE_BYNAME(sfp, args->namelen),
380 XFS_DATA_FORK);
381 /*
382 * Need to set up again due to realloc of the inode data.
383 */
384 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
385 sfep = (xfs_dir2_sf_entry_t *)((char *)sfp + byteoff);
386 /*
387 * Fill in the new entry.
388 */
389 sfep->namelen = args->namelen;
390 XFS_DIR2_SF_PUT_OFFSET_ARCH(sfep, offset, ARCH_CONVERT);
391 bcopy(args->name, sfep->name, sfep->namelen);
392 XFS_DIR2_SF_PUT_INUMBER_ARCH(sfp, &args->inumber,
393 XFS_DIR2_SF_INUMBERP(sfep), ARCH_CONVERT);
394 /*
395 * Update the header and inode.
396 */
397 sfp->hdr.count++;
398#if XFS_BIG_FILESYSTEMS
399 if (args->inumber > XFS_DIR2_MAX_SHORT_INUM)
400 sfp->hdr.i8count++;
401#endif
402 dp->i_d.di_size = new_isize;
403 xfs_dir2_sf_check(args);
404}
405
406/*
407 * Add the new entry the "hard" way.
408 * The caller has already converted to 8 byte inode numbers if necessary,
409 * in which case we need to leave the i8count at 1.
410 * Find a hole that the new entry will fit into, and copy
411 * the first part of the entries, the new entry, and the last part of
412 * the entries.
413 */
414/* ARGSUSED */
415STATIC void
416xfs_dir2_sf_addname_hard(
417 xfs_da_args_t *args, /* operation arguments */
418 int objchange, /* changing inode number size */
419 int new_isize) /* new directory size */
420{
421 int add_datasize; /* data size need for new ent */
422 char buf[XFS_DIR2_SF_MAX_SIZE]; /* buffer for old */
423 xfs_inode_t *dp; /* incore directory inode */
424 int eof; /* reached end of old dir */
425 int nbytes; /* temp for byte copies */
426 xfs_dir2_data_aoff_t new_offset; /* next offset value */
427 xfs_dir2_data_aoff_t offset; /* current offset value */
428 int old_isize; /* previous di_size */
429 xfs_dir2_sf_entry_t *oldsfep; /* entry in original dir */
430 xfs_dir2_sf_t *oldsfp; /* original shortform dir */
431 xfs_dir2_sf_entry_t *sfep; /* entry in new dir */
432 xfs_dir2_sf_t *sfp; /* new shortform dir */
433
434 /*
435 * Copy the old directory to the stack buffer.
436 */
437 dp = args->dp;
438
439 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
440 old_isize = (int)dp->i_d.di_size;
441 oldsfp = (xfs_dir2_sf_t *)buf;
442 bcopy(sfp, oldsfp, old_isize);
443 /*
444 * Loop over the old directory finding the place we're going
445 * to insert the new entry.
446 * If it's going to end up at the end then oldsfep will point there.
447 */
448 for (offset = XFS_DIR2_DATA_FIRST_OFFSET,
449 oldsfep = XFS_DIR2_SF_FIRSTENTRY(oldsfp),
450 add_datasize = XFS_DIR2_DATA_ENTSIZE(args->namelen),
451 eof = (char *)oldsfep == &buf[old_isize];
452 !eof;
453 offset = new_offset + XFS_DIR2_DATA_ENTSIZE(oldsfep->namelen),
454 oldsfep = XFS_DIR2_SF_NEXTENTRY(oldsfp, oldsfep),
455 eof = (char *)oldsfep == &buf[old_isize]) {
456 new_offset = XFS_DIR2_SF_GET_OFFSET_ARCH(oldsfep, ARCH_CONVERT);
457 if (offset + add_datasize <= new_offset)
458 break;
459 }
460 /*
461 * Get rid of the old directory, then allocate space for
462 * the new one. We do this so xfs_idata_realloc won't copy
463 * the data.
464 */
465 xfs_idata_realloc(dp, -old_isize, XFS_DATA_FORK);
466 xfs_idata_realloc(dp, new_isize, XFS_DATA_FORK);
467 /*
468 * Reset the pointer since the buffer was reallocated.
469 */
470 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
471 /*
472 * Copy the first part of the directory, including the header.
473 */
474 nbytes = (int)((char *)oldsfep - (char *)oldsfp);
475 bcopy(oldsfp, sfp, nbytes);
476 sfep = (xfs_dir2_sf_entry_t *)((char *)sfp + nbytes);
477 /*
478 * Fill in the new entry, and update the header counts.
479 */
480 sfep->namelen = args->namelen;
481 XFS_DIR2_SF_PUT_OFFSET_ARCH(sfep, offset, ARCH_CONVERT);
482 bcopy(args->name, sfep->name, sfep->namelen);
483 XFS_DIR2_SF_PUT_INUMBER_ARCH(sfp, &args->inumber,
484 XFS_DIR2_SF_INUMBERP(sfep), ARCH_CONVERT);
485 sfp->hdr.count++;
486#if XFS_BIG_FILESYSTEMS
487 if (args->inumber > XFS_DIR2_MAX_SHORT_INUM && !objchange)
488 sfp->hdr.i8count++;
489#endif
490 /*
491 * If there's more left to copy, do that.
492 */
493 if (!eof) {
494 sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep);
495 bcopy(oldsfep, sfep, old_isize - nbytes);
496 }
497 dp->i_d.di_size = new_isize;
498 xfs_dir2_sf_check(args);
499}
500
501/*
502 * Decide if the new entry will fit at all.
503 * If it will fit, pick between adding the new entry to the end (easy)
504 * or somewhere else (hard).
505 * Return 0 (won't fit), 1 (easy), 2 (hard).
506 */
507/*ARGSUSED*/
508STATIC int /* pick result */
509xfs_dir2_sf_addname_pick(
510 xfs_da_args_t *args, /* operation arguments */
511 int objchange, /* inode # size changes */
512 xfs_dir2_sf_entry_t **sfepp, /* out(1): new entry ptr */
513 xfs_dir2_data_aoff_t *offsetp) /* out(1): new offset */
514{
515 xfs_inode_t *dp; /* incore directory inode */
516 int holefit; /* found hole it will fit in */
517 int i; /* entry number */
518 xfs_mount_t *mp; /* filesystem mount point */
519 xfs_dir2_data_aoff_t offset; /* data block offset */
520 xfs_dir2_sf_entry_t *sfep; /* shortform entry */
521 xfs_dir2_sf_t *sfp; /* shortform structure */
522 int size; /* entry's data size */
523 int used; /* data bytes used */
524
525 dp = args->dp;
526 mp = dp->i_mount;
527
528 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
529 size = XFS_DIR2_DATA_ENTSIZE(args->namelen);
530 offset = XFS_DIR2_DATA_FIRST_OFFSET;
531 sfep = XFS_DIR2_SF_FIRSTENTRY(sfp);
532 holefit = 0;
533 /*
534 * Loop over sf entries.
535 * Keep track of data offset and whether we've seen a place
536 * to insert the new entry.
537 */
538 for (i = 0; i < sfp->hdr.count; i++) {
539 if (!holefit)
540 holefit = offset + size <= XFS_DIR2_SF_GET_OFFSET_ARCH(sfep, ARCH_CONVERT);
541 offset = XFS_DIR2_SF_GET_OFFSET_ARCH(sfep, ARCH_CONVERT) +
542 XFS_DIR2_DATA_ENTSIZE(sfep->namelen);
543 sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep);
544 }
545 /*
546 * Calculate data bytes used excluding the new entry, if this
547 * was a data block (block form directory).
548 */
549 used = offset +
550 (sfp->hdr.count + 3) * (uint)sizeof(xfs_dir2_leaf_entry_t) +
551 (uint)sizeof(xfs_dir2_block_tail_t);
552 /*
553 * If it won't fit in a block form then we can't insert it,
554 * we'll go back, convert to block, then try the insert and convert
555 * to leaf.
556 */
557 if (used + (holefit ? 0 : size) > mp->m_dirblksize)
558 return 0;
559 /*
560 * If changing the inode number size, do it the hard way.
561 */
562#if XFS_BIG_FILESYSTEMS
563 if (objchange) {
564#pragma mips_frequency_hint NEVER
565 return 2;
566 }
567#else
568 ASSERT(objchange == 0);
569#endif
570 /*
571 * If it won't fit at the end then do it the hard way (use the hole).
572 */
573 if (used + size > mp->m_dirblksize)
574 return 2;
575 /*
576 * Do it the easy way.
577 */
578 *sfepp = sfep;
579 *offsetp = offset;
580 return 1;
581}
582
583#ifdef DEBUG
584/*
585 * Check consistency of shortform directory, assert if bad.
586 */
587STATIC void
588xfs_dir2_sf_check(
589 xfs_da_args_t *args) /* operation arguments */
590{
591 xfs_inode_t *dp; /* incore directory inode */
592 int i; /* entry number */
593 int i8count; /* number of big inode#s */
594 xfs_ino_t ino; /* entry inode number */
595 int offset; /* data offset */
596 xfs_dir2_sf_entry_t *sfep; /* shortform dir entry */
597 xfs_dir2_sf_t *sfp; /* shortform structure */
598
599 dp = args->dp;
600
601 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
602 offset = XFS_DIR2_DATA_FIRST_OFFSET;
603 ino = XFS_DIR2_SF_GET_INUMBER_ARCH(sfp, &sfp->hdr.parent, ARCH_CONVERT);
604 i8count = ino > XFS_DIR2_MAX_SHORT_INUM;
605
606 for (i = 0, sfep = XFS_DIR2_SF_FIRSTENTRY(sfp);
607 i < sfp->hdr.count;
608 i++, sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep)) {
609 ASSERT(XFS_DIR2_SF_GET_OFFSET_ARCH(sfep, ARCH_CONVERT) >= offset);
610 ino = XFS_DIR2_SF_GET_INUMBER_ARCH(sfp, XFS_DIR2_SF_INUMBERP(sfep), ARCH_CONVERT);
611 i8count += ino > XFS_DIR2_MAX_SHORT_INUM;
612 offset =
613 XFS_DIR2_SF_GET_OFFSET_ARCH(sfep, ARCH_CONVERT) +
614 XFS_DIR2_DATA_ENTSIZE(sfep->namelen);
615 }
616 ASSERT(i8count == sfp->hdr.i8count);
617#if !XFS_BIG_FILESYSTEMS
618 ASSERT(i8count == 0);
619#endif
620 ASSERT((char *)sfep - (char *)sfp == dp->i_d.di_size);
621 ASSERT(offset +
622 (sfp->hdr.count + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t) +
623 (uint)sizeof(xfs_dir2_block_tail_t) <=
624 dp->i_mount->m_dirblksize);
625}
626#endif /* DEBUG */
627
628/*
629 * Create a new (shortform) directory.
630 */
631int /* error, always 0 */
632xfs_dir2_sf_create(
633 xfs_da_args_t *args, /* operation arguments */
634 xfs_ino_t pino) /* parent inode number */
635{
636 xfs_inode_t *dp; /* incore directory inode */
637 int i8count; /* parent inode is an 8-byte number */
638 xfs_dir2_sf_t *sfp; /* shortform structure */
639 int size; /* directory size */
640
641 xfs_dir2_trace_args_i("sf_create", args, pino);
642 dp = args->dp;
643
644 ASSERT(dp != NULL);
645 ASSERT(dp->i_d.di_size == 0);
646 /*
647 * If it's currently a zero-length extent file,
648 * convert it to local format.
649 */
650 if (dp->i_d.di_format == XFS_DINODE_FMT_EXTENTS) {
651 dp->i_df.if_flags &= ~XFS_IFEXTENTS; /* just in case */
652 dp->i_d.di_format = XFS_DINODE_FMT_LOCAL;
653 xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE);
654 dp->i_df.if_flags |= XFS_IFINLINE;
655 }
656 ASSERT(dp->i_df.if_flags & XFS_IFINLINE);
657 ASSERT(dp->i_df.if_bytes == 0);
658 i8count = pino > XFS_DIR2_MAX_SHORT_INUM;
659 size = XFS_DIR2_SF_HDR_SIZE(i8count);
660 /*
661 * Make a buffer for the data.
662 */
663 xfs_idata_realloc(dp, size, XFS_DATA_FORK);
664 /*
665 * Fill in the header,
666 */
667 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
668 sfp->hdr.i8count = i8count;
669 /*
670 * Now can put in the inode number, since i8count is set.
671 */
672 XFS_DIR2_SF_PUT_INUMBER_ARCH(sfp, &pino, &sfp->hdr.parent, ARCH_CONVERT);
673 sfp->hdr.count = 0;
674 dp->i_d.di_size = size;
675 xfs_dir2_sf_check(args);
676 xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA);
677 return 0;
678}
679
680/*
681 * Lookup an entry in a shortform directory.
682 * Returns EEXIST if found, ENOENT if not found.
683 */
684int /* error */
685xfs_dir2_sf_lookup(
686 xfs_da_args_t *args) /* operation arguments */
687{
688 xfs_inode_t *dp; /* incore directory inode */
689 int i; /* entry index */
690 xfs_dir2_sf_entry_t *sfep; /* shortform directory entry */
691 xfs_dir2_sf_t *sfp; /* shortform structure */
692
693 xfs_dir2_trace_args("sf_lookup", args);
694 xfs_dir2_sf_check(args);
695 dp = args->dp;
696
697 ASSERT(dp->i_df.if_flags & XFS_IFINLINE);
698 /*
699 * Bail out if the directory is way too short.
700 */
701 if (dp->i_d.di_size < offsetof(xfs_dir2_sf_hdr_t, parent)) {
702#pragma mips_frequency_hint NEVER
703 ASSERT(XFS_FORCED_SHUTDOWN(dp->i_mount));
704 return XFS_ERROR(EIO);
705 }
706 ASSERT(dp->i_df.if_bytes == dp->i_d.di_size);
707 ASSERT(dp->i_df.if_u1.if_data != NULL);
708 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
709 ASSERT(dp->i_d.di_size >= XFS_DIR2_SF_HDR_SIZE(sfp->hdr.i8count));
710 /*
711 * Special case for .
712 */
713 if (args->namelen == 1 && args->name[0] == '.') {
714 args->inumber = dp->i_ino;
715 return XFS_ERROR(EEXIST);
716 }
717 /*
718 * Special case for ..
719 */
720 if (args->namelen == 2 &&
721 args->name[0] == '.' && args->name[1] == '.') {
722 args->inumber = XFS_DIR2_SF_GET_INUMBER_ARCH(sfp, &sfp->hdr.parent, ARCH_CONVERT);
723 return XFS_ERROR(EEXIST);
724 }
725 /*
726 * Loop over all the entries trying to match ours.
727 */
728 for (i = 0, sfep = XFS_DIR2_SF_FIRSTENTRY(sfp);
729 i < sfp->hdr.count;
730 i++, sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep)) {
731 if (sfep->namelen == args->namelen &&
732 sfep->name[0] == args->name[0] &&
733 bcmp(args->name, sfep->name, args->namelen) == 0) {
734 args->inumber =
735 XFS_DIR2_SF_GET_INUMBER_ARCH(sfp,
736 XFS_DIR2_SF_INUMBERP(sfep), ARCH_CONVERT);
737 return XFS_ERROR(EEXIST);
738 }
739 }
740 /*
741 * Didn't find it.
742 */
743 ASSERT(args->oknoent);
744 return XFS_ERROR(ENOENT);
745}
746
747/*
748 * Remove an entry from a shortform directory.
749 */
750int /* error */
751xfs_dir2_sf_removename(
752 xfs_da_args_t *args)
753{
754 int byteoff; /* offset of removed entry */
755 xfs_inode_t *dp; /* incore directory inode */
756 int entsize; /* this entry's size */
757 int i; /* shortform entry index */
758 int newsize; /* new inode size */
759 int oldsize; /* old inode size */
760 xfs_dir2_sf_entry_t *sfep; /* shortform directory entry */
761 xfs_dir2_sf_t *sfp; /* shortform structure */
762
763 xfs_dir2_trace_args("sf_removename", args);
764 dp = args->dp;
765
766 ASSERT(dp->i_df.if_flags & XFS_IFINLINE);
767 oldsize = (int)dp->i_d.di_size;
768 /*
769 * Bail out if the directory is way too short.
770 */
771 if (oldsize < offsetof(xfs_dir2_sf_hdr_t, parent)) {
772#pragma mips_frequency_hint NEVER
773 ASSERT(XFS_FORCED_SHUTDOWN(dp->i_mount));
774 return XFS_ERROR(EIO);
775 }
776 ASSERT(dp->i_df.if_bytes == oldsize);
777 ASSERT(dp->i_df.if_u1.if_data != NULL);
778 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
779 ASSERT(oldsize >= XFS_DIR2_SF_HDR_SIZE(sfp->hdr.i8count));
780 /*
781 * Loop over the old directory entries.
782 * Find the one we're deleting.
783 */
784 for (i = 0, sfep = XFS_DIR2_SF_FIRSTENTRY(sfp);
785 i < sfp->hdr.count;
786 i++, sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep)) {
787 if (sfep->namelen == args->namelen &&
788 sfep->name[0] == args->name[0] &&
789 bcmp(sfep->name, args->name, args->namelen) == 0) {
790 ASSERT(XFS_DIR2_SF_GET_INUMBER_ARCH(sfp,
791 XFS_DIR2_SF_INUMBERP(sfep), ARCH_CONVERT) ==
792 args->inumber);
793 break;
794 }
795 }
796 /*
797 * Didn't find it.
798 */
799 if (i == sfp->hdr.count) {
800#pragma mips_frequency_hint NEVER
801 return XFS_ERROR(ENOENT);
802 }
803 /*
804 * Calculate sizes.
805 */
806 byteoff = (int)((char *)sfep - (char *)sfp);
807 entsize = XFS_DIR2_SF_ENTSIZE_BYNAME(sfp, args->namelen);
808 newsize = oldsize - entsize;
809 /*
810 * Copy the part if any after the removed entry, sliding it down.
811 */
812 if (byteoff + entsize < oldsize)
813 ovbcopy((char *)sfp + byteoff + entsize, (char *)sfp + byteoff,
814 oldsize - (byteoff + entsize));
815 /*
816 * Fix up the header and file size.
817 */
818 sfp->hdr.count--;
819 dp->i_d.di_size = newsize;
820 /*
821 * Reallocate, making it smaller.
822 */
823 xfs_idata_realloc(dp, newsize - oldsize, XFS_DATA_FORK);
824 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
825#if XFS_BIG_FILESYSTEMS
826 /*
827 * Are we changing inode number size?
828 */
829 if (args->inumber > XFS_DIR2_MAX_SHORT_INUM) {
830#pragma mips_frequency_hint NEVER
831 if (sfp->hdr.i8count == 1)
832 xfs_dir2_sf_toino4(args);
833 else
834 sfp->hdr.i8count--;
835 }
836#endif
837 xfs_dir2_sf_check(args);
838 xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA);
839 return 0;
840}
841
842/*
843 * Replace the inode number of an entry in a shortform directory.
844 */
845int /* error */
846xfs_dir2_sf_replace(
847 xfs_da_args_t *args) /* operation arguments */
848{
849 xfs_inode_t *dp; /* incore directory inode */
850 int i; /* entry index */
851#if XFS_BIG_FILESYSTEMS || defined(DEBUG)
852 xfs_ino_t ino; /* entry old inode number */
853#endif
854 xfs_dir2_sf_entry_t *sfep; /* shortform directory entry */
855 xfs_dir2_sf_t *sfp; /* shortform structure */
856
857 xfs_dir2_trace_args("sf_replace", args);
858 dp = args->dp;
859
860 ASSERT(dp->i_df.if_flags & XFS_IFINLINE);
861 /*
862 * Bail out if the shortform directory is way too small.
863 */
864 if (dp->i_d.di_size < offsetof(xfs_dir2_sf_hdr_t, parent)) {
865#pragma mips_frequency_hint NEVER
866 ASSERT(XFS_FORCED_SHUTDOWN(dp->i_mount));
867 return XFS_ERROR(EIO);
868 }
869 ASSERT(dp->i_df.if_bytes == dp->i_d.di_size);
870 ASSERT(dp->i_df.if_u1.if_data != NULL);
871 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
872 ASSERT(dp->i_d.di_size >= XFS_DIR2_SF_HDR_SIZE(sfp->hdr.i8count));
873#if XFS_BIG_FILESYSTEMS
874 /*
875 * New inode number is large, and need to convert to 8-byte inodes.
876 */
877 if (args->inumber > XFS_DIR2_MAX_SHORT_INUM && sfp->hdr.i8count == 0) {
878#pragma mips_frequency_hint NEVER
879 int error; /* error return value */
880 int newsize; /* new inode size */
881
882 newsize =
883 dp->i_df.if_bytes +
884 (sfp->hdr.count + 1) *
885 ((uint)sizeof(xfs_dir2_ino8_t) -
886 (uint)sizeof(xfs_dir2_ino4_t));
887 /*
888 * Won't fit as shortform, convert to block then do replace.
889 */
890 if (newsize > XFS_IFORK_DSIZE(dp)) {
891 error = xfs_dir2_sf_to_block(args);
892 if (error) {
893 return error;
894 }
895 return xfs_dir2_block_replace(args);
896 }
897 /*
898 * Still fits, convert to 8-byte now.
899 */
900 xfs_dir2_sf_toino8(args);
901 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
902 }
903#endif
904 ASSERT(args->namelen != 1 || args->name[0] != '.');
905 /*
906 * Replace ..'s entry.
907 */
908 if (args->namelen == 2 &&
909 args->name[0] == '.' && args->name[1] == '.') {
910#if XFS_BIG_FILESYSTEMS || defined(DEBUG)
911 ino = XFS_DIR2_SF_GET_INUMBER_ARCH(sfp, &sfp->hdr.parent, ARCH_CONVERT);
912 ASSERT(args->inumber != ino);
913#endif
914 XFS_DIR2_SF_PUT_INUMBER_ARCH(sfp, &args->inumber, &sfp->hdr.parent, ARCH_CONVERT);
915 }
916 /*
917 * Normal entry, look for the name.
918 */
919 else {
920 for (i = 0, sfep = XFS_DIR2_SF_FIRSTENTRY(sfp);
921 i < sfp->hdr.count;
922 i++, sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep)) {
923 if (sfep->namelen == args->namelen &&
924 sfep->name[0] == args->name[0] &&
925 bcmp(args->name, sfep->name, args->namelen) == 0) {
926#if XFS_BIG_FILESYSTEMS || defined(DEBUG)
927 ino = XFS_DIR2_SF_GET_INUMBER_ARCH(sfp,
928 XFS_DIR2_SF_INUMBERP(sfep), ARCH_CONVERT);
929 ASSERT(args->inumber != ino);
930#endif
931 XFS_DIR2_SF_PUT_INUMBER_ARCH(sfp, &args->inumber,
932 XFS_DIR2_SF_INUMBERP(sfep), ARCH_CONVERT);
933 break;
934 }
935 }
936 /*
937 * Didn't find it.
938 */
939 if (i == sfp->hdr.count) {
940#pragma mips_frequency_hint NEVER
941 ASSERT(args->oknoent);
942 return XFS_ERROR(ENOENT);
943 }
944 }
945#if XFS_BIG_FILESYSTEMS
946 /*
947 * See if the old number was large, the new number is small.
948 */
949 if (ino > XFS_DIR2_MAX_SHORT_INUM &&
950 args->inumber <= XFS_DIR2_MAX_SHORT_INUM) {
951#pragma mips_frequency_hint NEVER
952 /*
953 * And the old count was one, so need to convert to small.
954 */
955 if (sfp->hdr.i8count == 1)
956 xfs_dir2_sf_toino4(args);
957 else
958 sfp->hdr.i8count--;
959 }
960#endif
961 xfs_dir2_sf_check(args);
962 xfs_trans_log_inode(args->trans, dp, XFS_ILOG_DDATA);
963 return 0;
964}
965
966#if XFS_BIG_FILESYSTEMS
967/*
968 * Convert from 8-byte inode numbers to 4-byte inode numbers.
969 * The last 8-byte inode number is gone, but the count is still 1.
970 */
971STATIC void
972xfs_dir2_sf_toino4(
973 xfs_da_args_t *args) /* operation arguments */
974{
975 char *buf; /* old dir's buffer */
976 xfs_inode_t *dp; /* incore directory inode */
977 int i; /* entry index */
978 xfs_ino_t ino; /* entry inode number */
979 int newsize; /* new inode size */
980 xfs_dir2_sf_entry_t *oldsfep; /* old sf entry */
981 xfs_dir2_sf_t *oldsfp; /* old sf directory */
982 int oldsize; /* old inode size */
983 xfs_dir2_sf_entry_t *sfep; /* new sf entry */
984 xfs_dir2_sf_t *sfp; /* new sf directory */
985
986 xfs_dir2_trace_args("sf_toino4", args);
987 dp = args->dp;
988
989 /*
990 * Copy the old directory to the buffer.
991 * Then nuke it from the inode, and add the new buffer to the inode.
992 * Don't want xfs_idata_realloc copying the data here.
993 */
994 oldsize = dp->i_df.if_bytes;
995 buf = kmem_alloc(oldsize, KM_SLEEP);
996 oldsfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
997 ASSERT(oldsfp->hdr.i8count == 1);
998 bcopy(oldsfp, buf, oldsize);
999 /*
1000 * Compute the new inode size.
1001 */
1002 newsize =
1003 oldsize -
1004 (oldsfp->hdr.count + 1) *
1005 ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t));
1006 xfs_idata_realloc(dp, -oldsize, XFS_DATA_FORK);
1007 xfs_idata_realloc(dp, newsize, XFS_DATA_FORK);
1008 /*
1009 * Reset our pointers, the data has moved.
1010 */
1011 oldsfp = (xfs_dir2_sf_t *)buf;
1012 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
1013 /*
1014 * Fill in the new header.
1015 */
1016 sfp->hdr.count = oldsfp->hdr.count;
1017 sfp->hdr.i8count = 0;
1018 ino = XFS_DIR2_SF_GET_INUMBER_ARCH(oldsfp, &oldsfp->hdr.parent, ARCH_CONVERT);
1019 XFS_DIR2_SF_PUT_INUMBER_ARCH(sfp, &ino, &sfp->hdr.parent, ARCH_CONVERT);
1020 /*
1021 * Copy the entries field by field.
1022 */
1023 for (i = 0, sfep = XFS_DIR2_SF_FIRSTENTRY(sfp),
1024 oldsfep = XFS_DIR2_SF_FIRSTENTRY(oldsfp);
1025 i < sfp->hdr.count;
1026 i++, sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep),
1027 oldsfep = XFS_DIR2_SF_NEXTENTRY(oldsfp, oldsfep)) {
1028 sfep->namelen = oldsfep->namelen;
1029 sfep->offset = oldsfep->offset;
1030 bcopy(oldsfep->name, sfep->name, sfep->namelen);
1031 ino = XFS_DIR2_SF_GET_INUMBER_ARCH(oldsfp,
1032 XFS_DIR2_SF_INUMBERP(oldsfep), ARCH_CONVERT);
1033 XFS_DIR2_SF_PUT_INUMBER_ARCH(sfp, &ino, XFS_DIR2_SF_INUMBERP(sfep), ARCH_CONVERT);
1034 }
1035 /*
1036 * Clean up the inode.
1037 */
1038 kmem_free(buf, oldsize);
1039 dp->i_d.di_size = newsize;
1040 xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA);
1041}
1042
1043/*
1044 * Convert from 4-byte inode numbers to 8-byte inode numbers.
1045 * The new 8-byte inode number is not there yet, we leave with the
1046 * count 1 but no corresponding entry.
1047 */
1048STATIC void
1049xfs_dir2_sf_toino8(
1050 xfs_da_args_t *args) /* operation arguments */
1051{
1052 char *buf; /* old dir's buffer */
1053 xfs_inode_t *dp; /* incore directory inode */
1054 int i; /* entry index */
1055 xfs_ino_t ino; /* entry inode number */
1056 int newsize; /* new inode size */
1057 xfs_dir2_sf_entry_t *oldsfep; /* old sf entry */
1058 xfs_dir2_sf_t *oldsfp; /* old sf directory */
1059 int oldsize; /* old inode size */
1060 xfs_dir2_sf_entry_t *sfep; /* new sf entry */
1061 xfs_dir2_sf_t *sfp; /* new sf directory */
1062
1063 xfs_dir2_trace_args("sf_toino8", args);
1064 dp = args->dp;
1065
1066 /*
1067 * Copy the old directory to the buffer.
1068 * Then nuke it from the inode, and add the new buffer to the inode.
1069 * Don't want xfs_idata_realloc copying the data here.
1070 */
1071 oldsize = dp->i_df.if_bytes;
1072 buf = kmem_alloc(oldsize, KM_SLEEP);
1073 oldsfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
1074 ASSERT(oldsfp->hdr.i8count == 0);
1075 bcopy(oldsfp, buf, oldsize);
1076 /*
1077 * Compute the new inode size.
1078 */
1079 newsize =
1080 oldsize +
1081 (oldsfp->hdr.count + 1) *
1082 ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t));
1083 xfs_idata_realloc(dp, -oldsize, XFS_DATA_FORK);
1084 xfs_idata_realloc(dp, newsize, XFS_DATA_FORK);
1085 /*
1086 * Reset our pointers, the data has moved.
1087 */
1088 oldsfp = (xfs_dir2_sf_t *)buf;
1089 sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
1090 /*
1091 * Fill in the new header.
1092 */
1093 sfp->hdr.count = oldsfp->hdr.count;
1094 sfp->hdr.i8count = 1;
1095 ino = XFS_DIR2_SF_GET_INUMBER_ARCH(oldsfp, &oldsfp->hdr.parent, ARCH_CONVERT);
1096 XFS_DIR2_SF_PUT_INUMBER_ARCH(sfp, &ino, &sfp->hdr.parent, ARCH_CONVERT);
1097 /*
1098 * Copy the entries field by field.
1099 */
1100 for (i = 0, sfep = XFS_DIR2_SF_FIRSTENTRY(sfp),
1101 oldsfep = XFS_DIR2_SF_FIRSTENTRY(oldsfp);
1102 i < sfp->hdr.count;
1103 i++, sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep),
1104 oldsfep = XFS_DIR2_SF_NEXTENTRY(oldsfp, oldsfep)) {
1105 sfep->namelen = oldsfep->namelen;
1106 sfep->offset = oldsfep->offset;
1107 bcopy(oldsfep->name, sfep->name, sfep->namelen);
1108 ino = XFS_DIR2_SF_GET_INUMBER_ARCH(oldsfp,
1109 XFS_DIR2_SF_INUMBERP(oldsfep), ARCH_CONVERT);
1110 XFS_DIR2_SF_PUT_INUMBER_ARCH(sfp, &ino, XFS_DIR2_SF_INUMBERP(sfep), ARCH_CONVERT);
1111 }
1112 /*
1113 * Clean up the inode.
1114 */
1115 kmem_free(buf, oldsize);
1116 dp->i_d.di_size = newsize;
1117 xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA);
1118}
1119#endif /* XFS_BIG_FILESYSTEMS */