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