blob: 7aab8ec117ad65f9b558889e5434f929cb6dad63 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110019#include "xfs_fs.h"
Dave Chinnera4fbe6a2013-10-23 10:51:50 +110020#include "xfs_format.h"
Dave Chinner239880e2013-10-23 10:50:10 +110021#include "xfs_log_format.h"
22#include "xfs_trans_resv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "xfs_sb.h"
David Chinnerda353b02007-08-28 14:00:13 +100024#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include "xfs_mount.h"
Dave Chinner57062782013-10-15 09:17:51 +110026#include "xfs_da_format.h"
Nathan Scotta844f452005-11-02 14:38:42 +110027#include "xfs_da_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include "xfs_inode.h"
Dave Chinner239880e2013-10-23 10:50:10 +110029#include "xfs_trans.h"
Nathan Scotta844f452005-11-02 14:38:42 +110030#include "xfs_inode_item.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "xfs_error.h"
Dave Chinner2b9ab5a2013-08-12 20:49:37 +100032#include "xfs_dir2.h"
Christoph Hellwig57926642011-07-13 13:43:48 +020033#include "xfs_dir2_priv.h"
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000034#include "xfs_trace.h"
Dave Chinnera4fbe6a2013-10-23 10:51:50 +110035#include "xfs_dinode.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37/*
38 * Prototypes for internal functions.
39 */
40static void xfs_dir2_sf_addname_easy(xfs_da_args_t *args,
41 xfs_dir2_sf_entry_t *sfep,
42 xfs_dir2_data_aoff_t offset,
43 int new_isize);
44static void xfs_dir2_sf_addname_hard(xfs_da_args_t *args, int objchange,
45 int new_isize);
46static int xfs_dir2_sf_addname_pick(xfs_da_args_t *args, int objchange,
47 xfs_dir2_sf_entry_t **sfepp,
48 xfs_dir2_data_aoff_t *offsetp);
49#ifdef DEBUG
50static void xfs_dir2_sf_check(xfs_da_args_t *args);
51#else
52#define xfs_dir2_sf_check(args)
53#endif /* DEBUG */
54#if XFS_BIG_INUMS
55static void xfs_dir2_sf_toino4(xfs_da_args_t *args);
56static void xfs_dir2_sf_toino8(xfs_da_args_t *args);
57#endif /* XFS_BIG_INUMS */
58
Christoph Hellwig8bc38782011-07-08 14:35:03 +020059/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 * Given a block directory (dp/block), calculate its size as a shortform (sf)
61 * directory and a header for the sf directory, if it will fit it the
62 * space currently present in the inode. If it won't fit, the output
63 * size is too big (but not accurate).
64 */
65int /* size for sf form */
66xfs_dir2_block_sfsize(
67 xfs_inode_t *dp, /* incore inode pointer */
Christoph Hellwig4f6ae1a2011-07-08 14:35:27 +020068 xfs_dir2_data_hdr_t *hdr, /* block directory data */
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 xfs_dir2_sf_hdr_t *sfhp) /* output: header for sf form */
70{
71 xfs_dir2_dataptr_t addr; /* data entry address */
72 xfs_dir2_leaf_entry_t *blp; /* leaf area of the block */
73 xfs_dir2_block_tail_t *btp; /* tail area of the block */
74 int count; /* shortform entry count */
75 xfs_dir2_data_entry_t *dep; /* data entry in the block */
76 int i; /* block entry index */
77 int i8count; /* count of big-inode entries */
78 int isdot; /* entry is "." */
79 int isdotdot; /* entry is ".." */
80 xfs_mount_t *mp; /* mount structure pointer */
81 int namelen; /* total name bytes */
Christoph Hellwig5bde1ba92005-11-02 15:06:18 +110082 xfs_ino_t parent = 0; /* parent inode number */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 int size=0; /* total computed size */
Dave Chinner0cb97762013-08-12 20:50:09 +100084 int has_ftype;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86 mp = dp->i_mount;
87
Dave Chinner0cb97762013-08-12 20:50:09 +100088 /*
89 * if there is a filetype field, add the extra byte to the namelen
90 * for each entry that we see.
91 */
92 has_ftype = xfs_sb_version_hasftype(&mp->m_sb) ? 1 : 0;
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 count = i8count = namelen = 0;
Christoph Hellwig4f6ae1a2011-07-08 14:35:27 +020095 btp = xfs_dir2_block_tail_p(mp, hdr);
Christoph Hellwigbbaaf532007-06-28 16:43:50 +100096 blp = xfs_dir2_block_leaf_p(btp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98 /*
99 * Iterate over the block's data entries by using the leaf pointers.
100 */
Nathan Scotte922fff2006-03-17 17:27:56 +1100101 for (i = 0; i < be32_to_cpu(btp->count); i++) {
Nathan Scott3c1f9c12006-03-17 17:28:18 +1100102 if ((addr = be32_to_cpu(blp[i].address)) == XFS_DIR2_NULL_DATAPTR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 continue;
104 /*
105 * Calculate the pointer to the entry at hand.
106 */
107 dep = (xfs_dir2_data_entry_t *)
Christoph Hellwig4f6ae1a2011-07-08 14:35:27 +0200108 ((char *)hdr + xfs_dir2_dataptr_to_off(mp, addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 /*
110 * Detect . and .., so we can special-case them.
111 * . is not included in sf directories.
112 * .. is included by just the parent inode number.
113 */
114 isdot = dep->namelen == 1 && dep->name[0] == '.';
115 isdotdot =
116 dep->namelen == 2 &&
117 dep->name[0] == '.' && dep->name[1] == '.';
118#if XFS_BIG_INUMS
119 if (!isdot)
Christoph Hellwigff9901c2006-06-09 14:48:37 +1000120 i8count += be64_to_cpu(dep->inumber) > XFS_DIR2_MAX_SHORT_INUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121#endif
Dave Chinner0cb97762013-08-12 20:50:09 +1000122 /* take into account the file type field */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 if (!isdot && !isdotdot) {
124 count++;
Dave Chinner0cb97762013-08-12 20:50:09 +1000125 namelen += dep->namelen + has_ftype;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 } else if (isdotdot)
Christoph Hellwigff9901c2006-06-09 14:48:37 +1000127 parent = be64_to_cpu(dep->inumber);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 /*
129 * Calculate the new size, see if we should give up yet.
130 */
Christoph Hellwigbbaaf532007-06-28 16:43:50 +1000131 size = xfs_dir2_sf_hdr_size(i8count) + /* header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 count + /* namelen */
133 count * (uint)sizeof(xfs_dir2_sf_off_t) + /* offset */
134 namelen + /* name */
135 (i8count ? /* inumber */
136 (uint)sizeof(xfs_dir2_ino8_t) * count :
137 (uint)sizeof(xfs_dir2_ino4_t) * count);
138 if (size > XFS_IFORK_DSIZE(dp))
139 return size; /* size value is a failure */
140 }
141 /*
142 * Create the output header, if it worked.
143 */
144 sfhp->count = count;
145 sfhp->i8count = i8count;
Dave Chinner47401752013-10-29 22:11:47 +1100146 dp->d_ops->sf_put_parent_ino(sfhp, parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 return size;
148}
149
150/*
151 * Convert a block format directory to shortform.
152 * Caller has already checked that it will fit, and built us a header.
153 */
154int /* error */
155xfs_dir2_block_to_sf(
156 xfs_da_args_t *args, /* operation arguments */
Dave Chinner1d9025e2012-06-22 18:50:14 +1000157 struct xfs_buf *bp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 int size, /* shortform directory size */
159 xfs_dir2_sf_hdr_t *sfhp) /* shortform directory hdr */
160{
Christoph Hellwiga64b0412011-07-08 14:35:32 +0200161 xfs_dir2_data_hdr_t *hdr; /* block header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 xfs_dir2_block_tail_t *btp; /* block tail pointer */
163 xfs_dir2_data_entry_t *dep; /* data entry pointer */
164 xfs_inode_t *dp; /* incore directory inode */
165 xfs_dir2_data_unused_t *dup; /* unused data pointer */
166 char *endptr; /* end of data entries */
167 int error; /* error return value */
168 int logflags; /* inode logging flags */
169 xfs_mount_t *mp; /* filesystem mount point */
170 char *ptr; /* current data pointer */
171 xfs_dir2_sf_entry_t *sfep; /* shortform entry */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200172 xfs_dir2_sf_hdr_t *sfp; /* shortform directory header */
Dave Chinnerb3f03ba2013-12-03 23:50:57 +1100173 xfs_dir2_sf_hdr_t *dst; /* temporary data buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000175 trace_xfs_dir2_block_to_sf(args);
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 dp = args->dp;
178 mp = dp->i_mount;
179
180 /*
Dave Chinnerb3f03ba2013-12-03 23:50:57 +1100181 * allocate a temporary destination buffer the size of the inode
182 * to format the data into. Once we have formatted the data, we
183 * can free the block and copy the formatted data into the inode literal
184 * area.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 */
Dave Chinnerb3f03ba2013-12-03 23:50:57 +1100186 dst = kmem_alloc(mp->m_sb.sb_inodesize, KM_SLEEP);
187 hdr = bp->b_addr;
Christoph Hellwig4f6ae1a2011-07-08 14:35:27 +0200188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 * Copy the header into the newly allocate local space.
191 */
Dave Chinnerb3f03ba2013-12-03 23:50:57 +1100192 sfp = (xfs_dir2_sf_hdr_t *)dst;
Christoph Hellwigbbaaf532007-06-28 16:43:50 +1000193 memcpy(sfp, sfhp, xfs_dir2_sf_hdr_size(sfhp->i8count));
Dave Chinnerb3f03ba2013-12-03 23:50:57 +1100194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 /*
196 * Set up to loop over the block's entries.
197 */
Christoph Hellwiga64b0412011-07-08 14:35:32 +0200198 btp = xfs_dir2_block_tail_p(mp, hdr);
Dave Chinner2ca98772013-10-29 22:11:49 +1100199 ptr = (char *)dp->d_ops->data_entry_p(hdr);
Christoph Hellwigbbaaf532007-06-28 16:43:50 +1000200 endptr = (char *)xfs_dir2_block_leaf_p(btp);
201 sfep = xfs_dir2_sf_firstentry(sfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 /*
203 * Loop over the active and unused entries.
204 * Stop when we reach the leaf/tail portion of the block.
205 */
206 while (ptr < endptr) {
207 /*
208 * If it's unused, just skip over it.
209 */
210 dup = (xfs_dir2_data_unused_t *)ptr;
Nathan Scottad354eb2006-03-17 17:27:37 +1100211 if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
212 ptr += be16_to_cpu(dup->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 continue;
214 }
215 dep = (xfs_dir2_data_entry_t *)ptr;
216 /*
217 * Skip .
218 */
219 if (dep->namelen == 1 && dep->name[0] == '.')
Christoph Hellwigff9901c2006-06-09 14:48:37 +1000220 ASSERT(be64_to_cpu(dep->inumber) == dp->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 /*
222 * Skip .., but make sure the inode number is right.
223 */
224 else if (dep->namelen == 2 &&
225 dep->name[0] == '.' && dep->name[1] == '.')
Christoph Hellwigff9901c2006-06-09 14:48:37 +1000226 ASSERT(be64_to_cpu(dep->inumber) ==
Dave Chinner47401752013-10-29 22:11:47 +1100227 dp->d_ops->sf_get_parent_ino(sfp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 /*
229 * Normal entry, copy it into shortform.
230 */
231 else {
232 sfep->namelen = dep->namelen;
Christoph Hellwigbbaaf532007-06-28 16:43:50 +1000233 xfs_dir2_sf_put_offset(sfep,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 (xfs_dir2_data_aoff_t)
Christoph Hellwiga64b0412011-07-08 14:35:32 +0200235 ((char *)dep - (char *)hdr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 memcpy(sfep->name, dep->name, dep->namelen);
Dave Chinner47401752013-10-29 22:11:47 +1100237 dp->d_ops->sf_put_ino(sfp, sfep,
238 be64_to_cpu(dep->inumber));
239 dp->d_ops->sf_put_ftype(sfep,
Dave Chinner9d23fc82013-10-29 22:11:48 +1100240 dp->d_ops->data_get_ftype(dep));
Christoph Hellwig8bc38782011-07-08 14:35:03 +0200241
Dave Chinner32c54832013-10-29 22:11:46 +1100242 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 }
Dave Chinner9d23fc82013-10-29 22:11:48 +1100244 ptr += dp->d_ops->data_entsize(dep->namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 }
246 ASSERT((char *)sfep - (char *)sfp == size);
Dave Chinnerb3f03ba2013-12-03 23:50:57 +1100247
248 /* now we are done with the block, we can shrink the inode */
249 logflags = XFS_ILOG_CORE;
250 error = xfs_dir2_shrink_inode(args, mp->m_dirdatablk, bp);
251 if (error) {
252 ASSERT(error != ENOSPC);
253 goto out;
254 }
255
256 /*
257 * The buffer is now unconditionally gone, whether
258 * xfs_dir2_shrink_inode worked or not.
259 *
260 * Convert the inode to local format and copy the data in.
261 */
262 dp->i_df.if_flags &= ~XFS_IFEXTENTS;
263 dp->i_df.if_flags |= XFS_IFINLINE;
264 dp->i_d.di_format = XFS_DINODE_FMT_LOCAL;
265 ASSERT(dp->i_df.if_bytes == 0);
266 xfs_idata_realloc(dp, size, XFS_DATA_FORK);
267
268 logflags |= XFS_ILOG_DDATA;
269 memcpy(dp->i_df.if_u1.if_data, dst, size);
270 dp->i_d.di_size = size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 xfs_dir2_sf_check(args);
272out:
273 xfs_trans_log_inode(args->trans, dp, logflags);
Dave Chinnerb3f03ba2013-12-03 23:50:57 +1100274 kmem_free(dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 return error;
276}
277
278/*
279 * Add a name to a shortform directory.
280 * There are two algorithms, "easy" and "hard" which we decide on
281 * before changing anything.
282 * Convert to block form if necessary, if the new entry won't fit.
283 */
284int /* error */
285xfs_dir2_sf_addname(
286 xfs_da_args_t *args) /* operation arguments */
287{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 xfs_inode_t *dp; /* incore directory inode */
289 int error; /* error return value */
290 int incr_isize; /* total change in size */
291 int new_isize; /* di_size after adding name */
292 int objchange; /* changing to 8-byte inodes */
Christoph Hellwig5bde1ba92005-11-02 15:06:18 +1100293 xfs_dir2_data_aoff_t offset = 0; /* offset for new entry */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 int pick; /* which algorithm to use */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200295 xfs_dir2_sf_hdr_t *sfp; /* shortform structure */
Christoph Hellwig5bde1ba92005-11-02 15:06:18 +1100296 xfs_dir2_sf_entry_t *sfep = NULL; /* shortform entry */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000298 trace_xfs_dir2_sf_addname(args);
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 ASSERT(xfs_dir2_sf_lookup(args) == ENOENT);
301 dp = args->dp;
302 ASSERT(dp->i_df.if_flags & XFS_IFINLINE);
303 /*
304 * Make sure the shortform value has some of its header.
305 */
306 if (dp->i_d.di_size < offsetof(xfs_dir2_sf_hdr_t, parent)) {
307 ASSERT(XFS_FORCED_SHUTDOWN(dp->i_mount));
308 return XFS_ERROR(EIO);
309 }
310 ASSERT(dp->i_df.if_bytes == dp->i_d.di_size);
311 ASSERT(dp->i_df.if_u1.if_data != NULL);
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200312 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
313 ASSERT(dp->i_d.di_size >= xfs_dir2_sf_hdr_size(sfp->i8count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 /*
315 * Compute entry (and change in) size.
316 */
Eric Sandeen5e06d142014-04-14 19:07:23 +1000317 incr_isize = dp->d_ops->sf_entsize(sfp, args->namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 objchange = 0;
319#if XFS_BIG_INUMS
320 /*
321 * Do we have to change to 8 byte inodes?
322 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200323 if (args->inumber > XFS_DIR2_MAX_SHORT_INUM && sfp->i8count == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 /*
Eric Sandeen5e06d142014-04-14 19:07:23 +1000325 * Yes, adjust the inode size. old count + (parent + new)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 incr_isize +=
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200328 (sfp->count + 2) *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 ((uint)sizeof(xfs_dir2_ino8_t) -
330 (uint)sizeof(xfs_dir2_ino4_t));
331 objchange = 1;
332 }
333#endif
Eric Sandeen5e06d142014-04-14 19:07:23 +1000334 new_isize = (int)dp->i_d.di_size + incr_isize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 /*
336 * Won't fit as shortform any more (due to size),
337 * or the pick routine says it won't (due to offset values).
338 */
339 if (new_isize > XFS_IFORK_DSIZE(dp) ||
340 (pick =
341 xfs_dir2_sf_addname_pick(args, objchange, &sfep, &offset)) == 0) {
342 /*
343 * Just checking or no space reservation, it doesn't fit.
344 */
Barry Naujok6a178102008-05-21 16:42:05 +1000345 if ((args->op_flags & XFS_DA_OP_JUSTCHECK) || args->total == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 return XFS_ERROR(ENOSPC);
347 /*
348 * Convert to block form then add the name.
349 */
350 error = xfs_dir2_sf_to_block(args);
351 if (error)
352 return error;
353 return xfs_dir2_block_addname(args);
354 }
355 /*
356 * Just checking, it fits.
357 */
Barry Naujok6a178102008-05-21 16:42:05 +1000358 if (args->op_flags & XFS_DA_OP_JUSTCHECK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 return 0;
360 /*
361 * Do it the easy way - just add it at the end.
362 */
363 if (pick == 1)
364 xfs_dir2_sf_addname_easy(args, sfep, offset, new_isize);
365 /*
366 * Do it the hard way - look for a place to insert the new entry.
367 * Convert to 8 byte inode numbers first if necessary.
368 */
369 else {
370 ASSERT(pick == 2);
371#if XFS_BIG_INUMS
372 if (objchange)
373 xfs_dir2_sf_toino8(args);
374#endif
375 xfs_dir2_sf_addname_hard(args, objchange, new_isize);
376 }
377 xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA);
378 return 0;
379}
380
381/*
382 * Add the new entry the "easy" way.
383 * This is copying the old directory and adding the new entry at the end.
384 * Since it's sorted by "offset" we need room after the last offset
385 * that's already there, and then room to convert to a block directory.
386 * This is already checked by the pick routine.
387 */
388static void
389xfs_dir2_sf_addname_easy(
390 xfs_da_args_t *args, /* operation arguments */
391 xfs_dir2_sf_entry_t *sfep, /* pointer to new entry */
392 xfs_dir2_data_aoff_t offset, /* offset to use for new ent */
393 int new_isize) /* new directory size */
394{
395 int byteoff; /* byte offset in sf dir */
396 xfs_inode_t *dp; /* incore directory inode */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200397 xfs_dir2_sf_hdr_t *sfp; /* shortform structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399 dp = args->dp;
400
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200401 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 byteoff = (int)((char *)sfep - (char *)sfp);
403 /*
404 * Grow the in-inode space.
405 */
Dave Chinner32c54832013-10-29 22:11:46 +1100406 xfs_idata_realloc(dp, dp->d_ops->sf_entsize(sfp, args->namelen),
Dave Chinner0cb97762013-08-12 20:50:09 +1000407 XFS_DATA_FORK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 /*
409 * Need to set up again due to realloc of the inode data.
410 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200411 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 sfep = (xfs_dir2_sf_entry_t *)((char *)sfp + byteoff);
413 /*
414 * Fill in the new entry.
415 */
416 sfep->namelen = args->namelen;
Christoph Hellwigbbaaf532007-06-28 16:43:50 +1000417 xfs_dir2_sf_put_offset(sfep, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 memcpy(sfep->name, args->name, sfep->namelen);
Dave Chinner47401752013-10-29 22:11:47 +1100419 dp->d_ops->sf_put_ino(sfp, sfep, args->inumber);
420 dp->d_ops->sf_put_ftype(sfep, args->filetype);
Dave Chinner1c55cec2013-08-12 20:50:10 +1000421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 /*
423 * Update the header and inode.
424 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200425 sfp->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#if XFS_BIG_INUMS
427 if (args->inumber > XFS_DIR2_MAX_SHORT_INUM)
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200428 sfp->i8count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#endif
430 dp->i_d.di_size = new_isize;
431 xfs_dir2_sf_check(args);
432}
433
434/*
435 * Add the new entry the "hard" way.
436 * The caller has already converted to 8 byte inode numbers if necessary,
437 * in which case we need to leave the i8count at 1.
438 * Find a hole that the new entry will fit into, and copy
439 * the first part of the entries, the new entry, and the last part of
440 * the entries.
441 */
442/* ARGSUSED */
443static void
444xfs_dir2_sf_addname_hard(
445 xfs_da_args_t *args, /* operation arguments */
446 int objchange, /* changing inode number size */
447 int new_isize) /* new directory size */
448{
449 int add_datasize; /* data size need for new ent */
450 char *buf; /* buffer for old */
451 xfs_inode_t *dp; /* incore directory inode */
452 int eof; /* reached end of old dir */
453 int nbytes; /* temp for byte copies */
454 xfs_dir2_data_aoff_t new_offset; /* next offset value */
455 xfs_dir2_data_aoff_t offset; /* current offset value */
456 int old_isize; /* previous di_size */
457 xfs_dir2_sf_entry_t *oldsfep; /* entry in original dir */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200458 xfs_dir2_sf_hdr_t *oldsfp; /* original shortform dir */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 xfs_dir2_sf_entry_t *sfep; /* entry in new dir */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200460 xfs_dir2_sf_hdr_t *sfp; /* new shortform dir */
Dave Chinner0cb97762013-08-12 20:50:09 +1000461 struct xfs_mount *mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 /*
464 * Copy the old directory to the stack buffer.
465 */
466 dp = args->dp;
Dave Chinner0cb97762013-08-12 20:50:09 +1000467 mp = dp->i_mount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200469 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 old_isize = (int)dp->i_d.di_size;
471 buf = kmem_alloc(old_isize, KM_SLEEP);
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200472 oldsfp = (xfs_dir2_sf_hdr_t *)buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 memcpy(oldsfp, sfp, old_isize);
474 /*
475 * Loop over the old directory finding the place we're going
476 * to insert the new entry.
477 * If it's going to end up at the end then oldsfep will point there.
478 */
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100479 for (offset = dp->d_ops->data_first_offset,
Christoph Hellwigbbaaf532007-06-28 16:43:50 +1000480 oldsfep = xfs_dir2_sf_firstentry(oldsfp),
Dave Chinner9d23fc82013-10-29 22:11:48 +1100481 add_datasize = dp->d_ops->data_entsize(args->namelen),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 eof = (char *)oldsfep == &buf[old_isize];
483 !eof;
Dave Chinner9d23fc82013-10-29 22:11:48 +1100484 offset = new_offset + dp->d_ops->data_entsize(oldsfep->namelen),
Dave Chinner32c54832013-10-29 22:11:46 +1100485 oldsfep = dp->d_ops->sf_nextentry(oldsfp, oldsfep),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 eof = (char *)oldsfep == &buf[old_isize]) {
Christoph Hellwigbbaaf532007-06-28 16:43:50 +1000487 new_offset = xfs_dir2_sf_get_offset(oldsfep);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 if (offset + add_datasize <= new_offset)
489 break;
490 }
491 /*
492 * Get rid of the old directory, then allocate space for
493 * the new one. We do this so xfs_idata_realloc won't copy
494 * the data.
495 */
496 xfs_idata_realloc(dp, -old_isize, XFS_DATA_FORK);
497 xfs_idata_realloc(dp, new_isize, XFS_DATA_FORK);
498 /*
499 * Reset the pointer since the buffer was reallocated.
500 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200501 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 /*
503 * Copy the first part of the directory, including the header.
504 */
505 nbytes = (int)((char *)oldsfep - (char *)oldsfp);
506 memcpy(sfp, oldsfp, nbytes);
507 sfep = (xfs_dir2_sf_entry_t *)((char *)sfp + nbytes);
508 /*
509 * Fill in the new entry, and update the header counts.
510 */
511 sfep->namelen = args->namelen;
Christoph Hellwigbbaaf532007-06-28 16:43:50 +1000512 xfs_dir2_sf_put_offset(sfep, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 memcpy(sfep->name, args->name, sfep->namelen);
Dave Chinner47401752013-10-29 22:11:47 +1100514 dp->d_ops->sf_put_ino(sfp, sfep, args->inumber);
515 dp->d_ops->sf_put_ftype(sfep, args->filetype);
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200516 sfp->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517#if XFS_BIG_INUMS
518 if (args->inumber > XFS_DIR2_MAX_SHORT_INUM && !objchange)
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200519 sfp->i8count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520#endif
521 /*
522 * If there's more left to copy, do that.
523 */
524 if (!eof) {
Dave Chinner32c54832013-10-29 22:11:46 +1100525 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 memcpy(sfep, oldsfep, old_isize - nbytes);
527 }
Denys Vlasenkof0e2d932008-05-19 16:31:57 +1000528 kmem_free(buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 dp->i_d.di_size = new_isize;
530 xfs_dir2_sf_check(args);
531}
532
533/*
534 * Decide if the new entry will fit at all.
535 * If it will fit, pick between adding the new entry to the end (easy)
536 * or somewhere else (hard).
537 * Return 0 (won't fit), 1 (easy), 2 (hard).
538 */
539/*ARGSUSED*/
540static int /* pick result */
541xfs_dir2_sf_addname_pick(
542 xfs_da_args_t *args, /* operation arguments */
543 int objchange, /* inode # size changes */
544 xfs_dir2_sf_entry_t **sfepp, /* out(1): new entry ptr */
545 xfs_dir2_data_aoff_t *offsetp) /* out(1): new offset */
546{
547 xfs_inode_t *dp; /* incore directory inode */
548 int holefit; /* found hole it will fit in */
549 int i; /* entry number */
550 xfs_mount_t *mp; /* filesystem mount point */
551 xfs_dir2_data_aoff_t offset; /* data block offset */
552 xfs_dir2_sf_entry_t *sfep; /* shortform entry */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200553 xfs_dir2_sf_hdr_t *sfp; /* shortform structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 int size; /* entry's data size */
555 int used; /* data bytes used */
556
557 dp = args->dp;
558 mp = dp->i_mount;
559
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200560 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
Dave Chinner9d23fc82013-10-29 22:11:48 +1100561 size = dp->d_ops->data_entsize(args->namelen);
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100562 offset = dp->d_ops->data_first_offset;
Christoph Hellwigbbaaf532007-06-28 16:43:50 +1000563 sfep = xfs_dir2_sf_firstentry(sfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 holefit = 0;
565 /*
566 * Loop over sf entries.
567 * Keep track of data offset and whether we've seen a place
568 * to insert the new entry.
569 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200570 for (i = 0; i < sfp->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 if (!holefit)
Christoph Hellwigbbaaf532007-06-28 16:43:50 +1000572 holefit = offset + size <= xfs_dir2_sf_get_offset(sfep);
573 offset = xfs_dir2_sf_get_offset(sfep) +
Dave Chinner9d23fc82013-10-29 22:11:48 +1100574 dp->d_ops->data_entsize(sfep->namelen);
Dave Chinner32c54832013-10-29 22:11:46 +1100575 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 }
577 /*
578 * Calculate data bytes used excluding the new entry, if this
579 * was a data block (block form directory).
580 */
581 used = offset +
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200582 (sfp->count + 3) * (uint)sizeof(xfs_dir2_leaf_entry_t) +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 (uint)sizeof(xfs_dir2_block_tail_t);
584 /*
585 * If it won't fit in a block form then we can't insert it,
586 * we'll go back, convert to block, then try the insert and convert
587 * to leaf.
588 */
589 if (used + (holefit ? 0 : size) > mp->m_dirblksize)
590 return 0;
591 /*
592 * If changing the inode number size, do it the hard way.
593 */
594#if XFS_BIG_INUMS
595 if (objchange) {
596 return 2;
597 }
598#else
599 ASSERT(objchange == 0);
600#endif
601 /*
602 * If it won't fit at the end then do it the hard way (use the hole).
603 */
604 if (used + size > mp->m_dirblksize)
605 return 2;
606 /*
607 * Do it the easy way.
608 */
609 *sfepp = sfep;
610 *offsetp = offset;
611 return 1;
612}
613
614#ifdef DEBUG
615/*
616 * Check consistency of shortform directory, assert if bad.
617 */
618static void
619xfs_dir2_sf_check(
620 xfs_da_args_t *args) /* operation arguments */
621{
622 xfs_inode_t *dp; /* incore directory inode */
623 int i; /* entry number */
624 int i8count; /* number of big inode#s */
625 xfs_ino_t ino; /* entry inode number */
626 int offset; /* data offset */
627 xfs_dir2_sf_entry_t *sfep; /* shortform dir entry */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200628 xfs_dir2_sf_hdr_t *sfp; /* shortform structure */
Dave Chinner0cb97762013-08-12 20:50:09 +1000629 struct xfs_mount *mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
631 dp = args->dp;
Dave Chinner0cb97762013-08-12 20:50:09 +1000632 mp = dp->i_mount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200634 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100635 offset = dp->d_ops->data_first_offset;
Dave Chinner47401752013-10-29 22:11:47 +1100636 ino = dp->d_ops->sf_get_parent_ino(sfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 i8count = ino > XFS_DIR2_MAX_SHORT_INUM;
638
Christoph Hellwigbbaaf532007-06-28 16:43:50 +1000639 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp);
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200640 i < sfp->count;
Dave Chinner32c54832013-10-29 22:11:46 +1100641 i++, sfep = dp->d_ops->sf_nextentry(sfp, sfep)) {
Christoph Hellwigbbaaf532007-06-28 16:43:50 +1000642 ASSERT(xfs_dir2_sf_get_offset(sfep) >= offset);
Dave Chinner47401752013-10-29 22:11:47 +1100643 ino = dp->d_ops->sf_get_ino(sfp, sfep);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 i8count += ino > XFS_DIR2_MAX_SHORT_INUM;
645 offset =
Christoph Hellwigbbaaf532007-06-28 16:43:50 +1000646 xfs_dir2_sf_get_offset(sfep) +
Dave Chinner9d23fc82013-10-29 22:11:48 +1100647 dp->d_ops->data_entsize(sfep->namelen);
Dave Chinner47401752013-10-29 22:11:47 +1100648 ASSERT(dp->d_ops->sf_get_ftype(sfep) < XFS_DIR3_FT_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200650 ASSERT(i8count == sfp->i8count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 ASSERT(XFS_BIG_INUMS || i8count == 0);
652 ASSERT((char *)sfep - (char *)sfp == dp->i_d.di_size);
653 ASSERT(offset +
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200654 (sfp->count + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t) +
Dave Chinner0cb97762013-08-12 20:50:09 +1000655 (uint)sizeof(xfs_dir2_block_tail_t) <= mp->m_dirblksize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656}
657#endif /* DEBUG */
658
659/*
660 * Create a new (shortform) directory.
661 */
662int /* error, always 0 */
663xfs_dir2_sf_create(
664 xfs_da_args_t *args, /* operation arguments */
665 xfs_ino_t pino) /* parent inode number */
666{
667 xfs_inode_t *dp; /* incore directory inode */
668 int i8count; /* parent inode is an 8-byte number */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200669 xfs_dir2_sf_hdr_t *sfp; /* shortform structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 int size; /* directory size */
671
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000672 trace_xfs_dir2_sf_create(args);
673
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 dp = args->dp;
675
676 ASSERT(dp != NULL);
677 ASSERT(dp->i_d.di_size == 0);
678 /*
679 * If it's currently a zero-length extent file,
680 * convert it to local format.
681 */
682 if (dp->i_d.di_format == XFS_DINODE_FMT_EXTENTS) {
683 dp->i_df.if_flags &= ~XFS_IFEXTENTS; /* just in case */
684 dp->i_d.di_format = XFS_DINODE_FMT_LOCAL;
685 xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE);
686 dp->i_df.if_flags |= XFS_IFINLINE;
687 }
688 ASSERT(dp->i_df.if_flags & XFS_IFINLINE);
689 ASSERT(dp->i_df.if_bytes == 0);
690 i8count = pino > XFS_DIR2_MAX_SHORT_INUM;
Christoph Hellwigbbaaf532007-06-28 16:43:50 +1000691 size = xfs_dir2_sf_hdr_size(i8count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 /*
693 * Make a buffer for the data.
694 */
695 xfs_idata_realloc(dp, size, XFS_DATA_FORK);
696 /*
697 * Fill in the header,
698 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200699 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
700 sfp->i8count = i8count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 /*
702 * Now can put in the inode number, since i8count is set.
703 */
Dave Chinner47401752013-10-29 22:11:47 +1100704 dp->d_ops->sf_put_parent_ino(sfp, pino);
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200705 sfp->count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 dp->i_d.di_size = size;
707 xfs_dir2_sf_check(args);
708 xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA);
709 return 0;
710}
711
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712/*
713 * Lookup an entry in a shortform directory.
714 * Returns EEXIST if found, ENOENT if not found.
715 */
716int /* error */
717xfs_dir2_sf_lookup(
718 xfs_da_args_t *args) /* operation arguments */
719{
720 xfs_inode_t *dp; /* incore directory inode */
721 int i; /* entry index */
Barry Naujok384f3ce2008-05-21 16:58:22 +1000722 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 xfs_dir2_sf_entry_t *sfep; /* shortform directory entry */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200724 xfs_dir2_sf_hdr_t *sfp; /* shortform structure */
Barry Naujok5163f952008-05-21 16:41:01 +1000725 enum xfs_dacmp cmp; /* comparison result */
Barry Naujok384f3ce2008-05-21 16:58:22 +1000726 xfs_dir2_sf_entry_t *ci_sfep; /* case-insens. entry */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000728 trace_xfs_dir2_sf_lookup(args);
729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 xfs_dir2_sf_check(args);
731 dp = args->dp;
732
733 ASSERT(dp->i_df.if_flags & XFS_IFINLINE);
734 /*
735 * Bail out if the directory is way too short.
736 */
737 if (dp->i_d.di_size < offsetof(xfs_dir2_sf_hdr_t, parent)) {
738 ASSERT(XFS_FORCED_SHUTDOWN(dp->i_mount));
739 return XFS_ERROR(EIO);
740 }
741 ASSERT(dp->i_df.if_bytes == dp->i_d.di_size);
742 ASSERT(dp->i_df.if_u1.if_data != NULL);
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200743 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
744 ASSERT(dp->i_d.di_size >= xfs_dir2_sf_hdr_size(sfp->i8count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 /*
746 * Special case for .
747 */
748 if (args->namelen == 1 && args->name[0] == '.') {
749 args->inumber = dp->i_ino;
Barry Naujok5163f952008-05-21 16:41:01 +1000750 args->cmpresult = XFS_CMP_EXACT;
Dave Chinner1c55cec2013-08-12 20:50:10 +1000751 args->filetype = XFS_DIR3_FT_DIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 return XFS_ERROR(EEXIST);
753 }
754 /*
755 * Special case for ..
756 */
757 if (args->namelen == 2 &&
758 args->name[0] == '.' && args->name[1] == '.') {
Dave Chinner47401752013-10-29 22:11:47 +1100759 args->inumber = dp->d_ops->sf_get_parent_ino(sfp);
Barry Naujok5163f952008-05-21 16:41:01 +1000760 args->cmpresult = XFS_CMP_EXACT;
Dave Chinner1c55cec2013-08-12 20:50:10 +1000761 args->filetype = XFS_DIR3_FT_DIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 return XFS_ERROR(EEXIST);
763 }
764 /*
765 * Loop over all the entries trying to match ours.
766 */
Barry Naujok384f3ce2008-05-21 16:58:22 +1000767 ci_sfep = NULL;
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200768 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp); i < sfp->count;
Dave Chinner32c54832013-10-29 22:11:46 +1100769 i++, sfep = dp->d_ops->sf_nextentry(sfp, sfep)) {
Barry Naujok5163f952008-05-21 16:41:01 +1000770 /*
771 * Compare name and if it's an exact match, return the inode
772 * number. If it's the first case-insensitive match, store the
773 * inode number and continue looking for an exact match.
774 */
775 cmp = dp->i_mount->m_dirnameops->compname(args, sfep->name,
776 sfep->namelen);
777 if (cmp != XFS_CMP_DIFFERENT && cmp != args->cmpresult) {
778 args->cmpresult = cmp;
Dave Chinner47401752013-10-29 22:11:47 +1100779 args->inumber = dp->d_ops->sf_get_ino(sfp, sfep);
780 args->filetype = dp->d_ops->sf_get_ftype(sfep);
Barry Naujok5163f952008-05-21 16:41:01 +1000781 if (cmp == XFS_CMP_EXACT)
782 return XFS_ERROR(EEXIST);
Barry Naujok384f3ce2008-05-21 16:58:22 +1000783 ci_sfep = sfep;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 }
785 }
Barry Naujok6a178102008-05-21 16:42:05 +1000786 ASSERT(args->op_flags & XFS_DA_OP_OKNOENT);
Barry Naujok5163f952008-05-21 16:41:01 +1000787 /*
788 * Here, we can only be doing a lookup (not a rename or replace).
Barry Naujok384f3ce2008-05-21 16:58:22 +1000789 * If a case-insensitive match was not found, return ENOENT.
Barry Naujok5163f952008-05-21 16:41:01 +1000790 */
Barry Naujok384f3ce2008-05-21 16:58:22 +1000791 if (!ci_sfep)
792 return XFS_ERROR(ENOENT);
793 /* otherwise process the CI match as required by the caller */
794 error = xfs_dir_cilookup_result(args, ci_sfep->name, ci_sfep->namelen);
795 return XFS_ERROR(error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796}
797
798/*
799 * Remove an entry from a shortform directory.
800 */
801int /* error */
802xfs_dir2_sf_removename(
803 xfs_da_args_t *args)
804{
805 int byteoff; /* offset of removed entry */
806 xfs_inode_t *dp; /* incore directory inode */
807 int entsize; /* this entry's size */
808 int i; /* shortform entry index */
809 int newsize; /* new inode size */
810 int oldsize; /* old inode size */
811 xfs_dir2_sf_entry_t *sfep; /* shortform directory entry */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200812 xfs_dir2_sf_hdr_t *sfp; /* shortform structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000814 trace_xfs_dir2_sf_removename(args);
815
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 dp = args->dp;
817
818 ASSERT(dp->i_df.if_flags & XFS_IFINLINE);
819 oldsize = (int)dp->i_d.di_size;
820 /*
821 * Bail out if the directory is way too short.
822 */
823 if (oldsize < offsetof(xfs_dir2_sf_hdr_t, parent)) {
824 ASSERT(XFS_FORCED_SHUTDOWN(dp->i_mount));
825 return XFS_ERROR(EIO);
826 }
827 ASSERT(dp->i_df.if_bytes == oldsize);
828 ASSERT(dp->i_df.if_u1.if_data != NULL);
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200829 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
830 ASSERT(oldsize >= xfs_dir2_sf_hdr_size(sfp->i8count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 /*
832 * Loop over the old directory entries.
833 * Find the one we're deleting.
834 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200835 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp); i < sfp->count;
Dave Chinner32c54832013-10-29 22:11:46 +1100836 i++, sfep = dp->d_ops->sf_nextentry(sfp, sfep)) {
Barry Naujok5163f952008-05-21 16:41:01 +1000837 if (xfs_da_compname(args, sfep->name, sfep->namelen) ==
838 XFS_CMP_EXACT) {
Dave Chinner47401752013-10-29 22:11:47 +1100839 ASSERT(dp->d_ops->sf_get_ino(sfp, sfep) ==
Christoph Hellwig8bc38782011-07-08 14:35:03 +0200840 args->inumber);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 break;
842 }
843 }
844 /*
845 * Didn't find it.
846 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200847 if (i == sfp->count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 return XFS_ERROR(ENOENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 /*
850 * Calculate sizes.
851 */
852 byteoff = (int)((char *)sfep - (char *)sfp);
Dave Chinner32c54832013-10-29 22:11:46 +1100853 entsize = dp->d_ops->sf_entsize(sfp, args->namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 newsize = oldsize - entsize;
855 /*
856 * Copy the part if any after the removed entry, sliding it down.
857 */
858 if (byteoff + entsize < oldsize)
859 memmove((char *)sfp + byteoff, (char *)sfp + byteoff + entsize,
860 oldsize - (byteoff + entsize));
861 /*
862 * Fix up the header and file size.
863 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200864 sfp->count--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 dp->i_d.di_size = newsize;
866 /*
867 * Reallocate, making it smaller.
868 */
869 xfs_idata_realloc(dp, newsize - oldsize, XFS_DATA_FORK);
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200870 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871#if XFS_BIG_INUMS
872 /*
873 * Are we changing inode number size?
874 */
875 if (args->inumber > XFS_DIR2_MAX_SHORT_INUM) {
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200876 if (sfp->i8count == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 xfs_dir2_sf_toino4(args);
878 else
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200879 sfp->i8count--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 }
881#endif
882 xfs_dir2_sf_check(args);
883 xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA);
884 return 0;
885}
886
887/*
888 * Replace the inode number of an entry in a shortform directory.
889 */
890int /* error */
891xfs_dir2_sf_replace(
892 xfs_da_args_t *args) /* operation arguments */
893{
894 xfs_inode_t *dp; /* incore directory inode */
895 int i; /* entry index */
896#if XFS_BIG_INUMS || defined(DEBUG)
897 xfs_ino_t ino=0; /* entry old inode number */
898#endif
899#if XFS_BIG_INUMS
900 int i8elevated; /* sf_toino8 set i8count=1 */
901#endif
902 xfs_dir2_sf_entry_t *sfep; /* shortform directory entry */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200903 xfs_dir2_sf_hdr_t *sfp; /* shortform structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000905 trace_xfs_dir2_sf_replace(args);
906
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 dp = args->dp;
908
909 ASSERT(dp->i_df.if_flags & XFS_IFINLINE);
910 /*
911 * Bail out if the shortform directory is way too small.
912 */
913 if (dp->i_d.di_size < offsetof(xfs_dir2_sf_hdr_t, parent)) {
914 ASSERT(XFS_FORCED_SHUTDOWN(dp->i_mount));
915 return XFS_ERROR(EIO);
916 }
917 ASSERT(dp->i_df.if_bytes == dp->i_d.di_size);
918 ASSERT(dp->i_df.if_u1.if_data != NULL);
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200919 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
920 ASSERT(dp->i_d.di_size >= xfs_dir2_sf_hdr_size(sfp->i8count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921#if XFS_BIG_INUMS
922 /*
923 * New inode number is large, and need to convert to 8-byte inodes.
924 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200925 if (args->inumber > XFS_DIR2_MAX_SHORT_INUM && sfp->i8count == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 int error; /* error return value */
927 int newsize; /* new inode size */
928
929 newsize =
930 dp->i_df.if_bytes +
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200931 (sfp->count + 1) *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 ((uint)sizeof(xfs_dir2_ino8_t) -
933 (uint)sizeof(xfs_dir2_ino4_t));
934 /*
935 * Won't fit as shortform, convert to block then do replace.
936 */
937 if (newsize > XFS_IFORK_DSIZE(dp)) {
938 error = xfs_dir2_sf_to_block(args);
939 if (error) {
940 return error;
941 }
942 return xfs_dir2_block_replace(args);
943 }
944 /*
945 * Still fits, convert to 8-byte now.
946 */
947 xfs_dir2_sf_toino8(args);
948 i8elevated = 1;
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200949 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 } else
951 i8elevated = 0;
952#endif
953 ASSERT(args->namelen != 1 || args->name[0] != '.');
954 /*
955 * Replace ..'s entry.
956 */
957 if (args->namelen == 2 &&
958 args->name[0] == '.' && args->name[1] == '.') {
959#if XFS_BIG_INUMS || defined(DEBUG)
Dave Chinner47401752013-10-29 22:11:47 +1100960 ino = dp->d_ops->sf_get_parent_ino(sfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 ASSERT(args->inumber != ino);
962#endif
Dave Chinner47401752013-10-29 22:11:47 +1100963 dp->d_ops->sf_put_parent_ino(sfp, args->inumber);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 }
965 /*
966 * Normal entry, look for the name.
967 */
968 else {
Dave Chinner0cb97762013-08-12 20:50:09 +1000969 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp); i < sfp->count;
Dave Chinner32c54832013-10-29 22:11:46 +1100970 i++, sfep = dp->d_ops->sf_nextentry(sfp, sfep)) {
Barry Naujok5163f952008-05-21 16:41:01 +1000971 if (xfs_da_compname(args, sfep->name, sfep->namelen) ==
972 XFS_CMP_EXACT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973#if XFS_BIG_INUMS || defined(DEBUG)
Dave Chinner47401752013-10-29 22:11:47 +1100974 ino = dp->d_ops->sf_get_ino(sfp, sfep);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 ASSERT(args->inumber != ino);
976#endif
Dave Chinner47401752013-10-29 22:11:47 +1100977 dp->d_ops->sf_put_ino(sfp, sfep, args->inumber);
978 dp->d_ops->sf_put_ftype(sfep, args->filetype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 break;
980 }
981 }
982 /*
983 * Didn't find it.
984 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +0200985 if (i == sfp->count) {
Barry Naujok6a178102008-05-21 16:42:05 +1000986 ASSERT(args->op_flags & XFS_DA_OP_OKNOENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987#if XFS_BIG_INUMS
988 if (i8elevated)
989 xfs_dir2_sf_toino4(args);
990#endif
991 return XFS_ERROR(ENOENT);
992 }
993 }
994#if XFS_BIG_INUMS
995 /*
996 * See if the old number was large, the new number is small.
997 */
998 if (ino > XFS_DIR2_MAX_SHORT_INUM &&
999 args->inumber <= XFS_DIR2_MAX_SHORT_INUM) {
1000 /*
1001 * And the old count was one, so need to convert to small.
1002 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001003 if (sfp->i8count == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 xfs_dir2_sf_toino4(args);
1005 else
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001006 sfp->i8count--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 }
1008 /*
1009 * See if the old number was small, the new number is large.
1010 */
1011 if (ino <= XFS_DIR2_MAX_SHORT_INUM &&
1012 args->inumber > XFS_DIR2_MAX_SHORT_INUM) {
1013 /*
1014 * add to the i8count unless we just converted to 8-byte
1015 * inodes (which does an implied i8count = 1)
1016 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001017 ASSERT(sfp->i8count != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 if (!i8elevated)
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001019 sfp->i8count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 }
1021#endif
1022 xfs_dir2_sf_check(args);
1023 xfs_trans_log_inode(args->trans, dp, XFS_ILOG_DDATA);
1024 return 0;
1025}
1026
1027#if XFS_BIG_INUMS
1028/*
1029 * Convert from 8-byte inode numbers to 4-byte inode numbers.
1030 * The last 8-byte inode number is gone, but the count is still 1.
1031 */
1032static void
1033xfs_dir2_sf_toino4(
1034 xfs_da_args_t *args) /* operation arguments */
1035{
1036 char *buf; /* old dir's buffer */
1037 xfs_inode_t *dp; /* incore directory inode */
1038 int i; /* entry index */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 int newsize; /* new inode size */
1040 xfs_dir2_sf_entry_t *oldsfep; /* old sf entry */
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001041 xfs_dir2_sf_hdr_t *oldsfp; /* old sf directory */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 int oldsize; /* old inode size */
1043 xfs_dir2_sf_entry_t *sfep; /* new sf entry */
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001044 xfs_dir2_sf_hdr_t *sfp; /* new sf directory */
Dave Chinner1c55cec2013-08-12 20:50:10 +10001045 struct xfs_mount *mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
Christoph Hellwig0b1b2132009-12-14 23:14:59 +00001047 trace_xfs_dir2_sf_toino4(args);
1048
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 dp = args->dp;
Dave Chinner1c55cec2013-08-12 20:50:10 +10001050 mp = dp->i_mount;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
1052 /*
1053 * Copy the old directory to the buffer.
1054 * Then nuke it from the inode, and add the new buffer to the inode.
1055 * Don't want xfs_idata_realloc copying the data here.
1056 */
1057 oldsize = dp->i_df.if_bytes;
1058 buf = kmem_alloc(oldsize, KM_SLEEP);
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001059 oldsfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
1060 ASSERT(oldsfp->i8count == 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 memcpy(buf, oldsfp, oldsize);
1062 /*
1063 * Compute the new inode size.
1064 */
1065 newsize =
1066 oldsize -
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001067 (oldsfp->count + 1) *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t));
1069 xfs_idata_realloc(dp, -oldsize, XFS_DATA_FORK);
1070 xfs_idata_realloc(dp, newsize, XFS_DATA_FORK);
1071 /*
1072 * Reset our pointers, the data has moved.
1073 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001074 oldsfp = (xfs_dir2_sf_hdr_t *)buf;
1075 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 /*
1077 * Fill in the new header.
1078 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001079 sfp->count = oldsfp->count;
1080 sfp->i8count = 0;
Dave Chinner47401752013-10-29 22:11:47 +11001081 dp->d_ops->sf_put_parent_ino(sfp, dp->d_ops->sf_get_parent_ino(oldsfp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 /*
1083 * Copy the entries field by field.
1084 */
Christoph Hellwigbbaaf532007-06-28 16:43:50 +10001085 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp),
1086 oldsfep = xfs_dir2_sf_firstentry(oldsfp);
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001087 i < sfp->count;
Dave Chinner32c54832013-10-29 22:11:46 +11001088 i++, sfep = dp->d_ops->sf_nextentry(sfp, sfep),
1089 oldsfep = dp->d_ops->sf_nextentry(oldsfp, oldsfep)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 sfep->namelen = oldsfep->namelen;
1091 sfep->offset = oldsfep->offset;
1092 memcpy(sfep->name, oldsfep->name, sfep->namelen);
Dave Chinner47401752013-10-29 22:11:47 +11001093 dp->d_ops->sf_put_ino(sfp, sfep,
1094 dp->d_ops->sf_get_ino(oldsfp, oldsfep));
1095 dp->d_ops->sf_put_ftype(sfep, dp->d_ops->sf_get_ftype(oldsfep));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 }
1097 /*
1098 * Clean up the inode.
1099 */
Denys Vlasenkof0e2d932008-05-19 16:31:57 +10001100 kmem_free(buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 dp->i_d.di_size = newsize;
1102 xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA);
1103}
1104
1105/*
Eric Sandeen5e06d142014-04-14 19:07:23 +10001106 * Convert existing entries from 4-byte inode numbers to 8-byte inode numbers.
1107 * The new entry w/ an 8-byte inode number is not there yet; we leave with
1108 * i8count set to 1, but no corresponding 8-byte entry.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 */
1110static void
1111xfs_dir2_sf_toino8(
1112 xfs_da_args_t *args) /* operation arguments */
1113{
1114 char *buf; /* old dir's buffer */
1115 xfs_inode_t *dp; /* incore directory inode */
1116 int i; /* entry index */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 int newsize; /* new inode size */
1118 xfs_dir2_sf_entry_t *oldsfep; /* old sf entry */
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001119 xfs_dir2_sf_hdr_t *oldsfp; /* old sf directory */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 int oldsize; /* old inode size */
1121 xfs_dir2_sf_entry_t *sfep; /* new sf entry */
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001122 xfs_dir2_sf_hdr_t *sfp; /* new sf directory */
Dave Chinner1c55cec2013-08-12 20:50:10 +10001123 struct xfs_mount *mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Christoph Hellwig0b1b2132009-12-14 23:14:59 +00001125 trace_xfs_dir2_sf_toino8(args);
1126
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 dp = args->dp;
Dave Chinner1c55cec2013-08-12 20:50:10 +10001128 mp = dp->i_mount;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
1130 /*
1131 * Copy the old directory to the buffer.
1132 * Then nuke it from the inode, and add the new buffer to the inode.
1133 * Don't want xfs_idata_realloc copying the data here.
1134 */
1135 oldsize = dp->i_df.if_bytes;
1136 buf = kmem_alloc(oldsize, KM_SLEEP);
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001137 oldsfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
1138 ASSERT(oldsfp->i8count == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 memcpy(buf, oldsfp, oldsize);
1140 /*
Eric Sandeen5e06d142014-04-14 19:07:23 +10001141 * Compute the new inode size (nb: entry count + 1 for parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 */
1143 newsize =
1144 oldsize +
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001145 (oldsfp->count + 1) *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t));
1147 xfs_idata_realloc(dp, -oldsize, XFS_DATA_FORK);
1148 xfs_idata_realloc(dp, newsize, XFS_DATA_FORK);
1149 /*
1150 * Reset our pointers, the data has moved.
1151 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001152 oldsfp = (xfs_dir2_sf_hdr_t *)buf;
1153 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 /*
1155 * Fill in the new header.
1156 */
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001157 sfp->count = oldsfp->count;
1158 sfp->i8count = 1;
Dave Chinner47401752013-10-29 22:11:47 +11001159 dp->d_ops->sf_put_parent_ino(sfp, dp->d_ops->sf_get_parent_ino(oldsfp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 /*
1161 * Copy the entries field by field.
1162 */
Christoph Hellwigbbaaf532007-06-28 16:43:50 +10001163 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp),
1164 oldsfep = xfs_dir2_sf_firstentry(oldsfp);
Christoph Hellwigac8ba502011-07-08 14:35:13 +02001165 i < sfp->count;
Dave Chinner32c54832013-10-29 22:11:46 +11001166 i++, sfep = dp->d_ops->sf_nextentry(sfp, sfep),
1167 oldsfep = dp->d_ops->sf_nextentry(oldsfp, oldsfep)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 sfep->namelen = oldsfep->namelen;
1169 sfep->offset = oldsfep->offset;
1170 memcpy(sfep->name, oldsfep->name, sfep->namelen);
Dave Chinner47401752013-10-29 22:11:47 +11001171 dp->d_ops->sf_put_ino(sfp, sfep,
1172 dp->d_ops->sf_get_ino(oldsfp, oldsfep));
1173 dp->d_ops->sf_put_ftype(sfep, dp->d_ops->sf_get_ftype(oldsfep));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 }
1175 /*
1176 * Clean up the inode.
1177 */
Denys Vlasenkof0e2d932008-05-19 16:31:57 +10001178 kmem_free(buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 dp->i_d.di_size = newsize;
1180 xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA);
1181}
1182#endif /* XFS_BIG_INUMS */