blob: 4e59c8219ddec1398b595f3d7f03b0095521ed30 [file] [log] [blame]
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +09001/*
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +09002 * fs/f2fs/dir.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/fs.h>
12#include <linux/f2fs_fs.h>
13#include "f2fs.h"
Jaegeuk Kim398b1ac2012-12-19 15:28:39 +090014#include "node.h"
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +090015#include "acl.h"
Jaegeuk Kim8ae8f162013-06-03 19:46:19 +090016#include "xattr.h"
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +090017
18static unsigned long dir_blocks(struct inode *inode)
19{
20 return ((unsigned long long) (i_size_read(inode) + PAGE_CACHE_SIZE - 1))
21 >> PAGE_CACHE_SHIFT;
22}
23
Jaegeuk Kim38431542014-02-27 18:20:00 +090024static unsigned int dir_buckets(unsigned int level, int dir_level)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +090025{
Chao Yubfec07d2014-05-28 08:56:09 +080026 if (level + dir_level < MAX_DIR_HASH_DEPTH / 2)
Jaegeuk Kim38431542014-02-27 18:20:00 +090027 return 1 << (level + dir_level);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +090028 else
Chao Yubfec07d2014-05-28 08:56:09 +080029 return MAX_DIR_BUCKETS;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +090030}
31
32static unsigned int bucket_blocks(unsigned int level)
33{
34 if (level < MAX_DIR_HASH_DEPTH / 2)
35 return 2;
36 else
37 return 4;
38}
39
Chao Yudbeacf02014-09-24 18:17:04 +080040unsigned char f2fs_filetype_table[F2FS_FT_MAX] = {
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +090041 [F2FS_FT_UNKNOWN] = DT_UNKNOWN,
42 [F2FS_FT_REG_FILE] = DT_REG,
43 [F2FS_FT_DIR] = DT_DIR,
44 [F2FS_FT_CHRDEV] = DT_CHR,
45 [F2FS_FT_BLKDEV] = DT_BLK,
46 [F2FS_FT_FIFO] = DT_FIFO,
47 [F2FS_FT_SOCK] = DT_SOCK,
48 [F2FS_FT_SYMLINK] = DT_LNK,
49};
50
51#define S_SHIFT 12
52static unsigned char f2fs_type_by_mode[S_IFMT >> S_SHIFT] = {
53 [S_IFREG >> S_SHIFT] = F2FS_FT_REG_FILE,
54 [S_IFDIR >> S_SHIFT] = F2FS_FT_DIR,
55 [S_IFCHR >> S_SHIFT] = F2FS_FT_CHRDEV,
56 [S_IFBLK >> S_SHIFT] = F2FS_FT_BLKDEV,
57 [S_IFIFO >> S_SHIFT] = F2FS_FT_FIFO,
58 [S_IFSOCK >> S_SHIFT] = F2FS_FT_SOCK,
59 [S_IFLNK >> S_SHIFT] = F2FS_FT_SYMLINK,
60};
61
Chao Yudbeacf02014-09-24 18:17:04 +080062void set_de_type(struct f2fs_dir_entry *de, struct inode *inode)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +090063{
Al Viro0ecc8332013-03-29 12:23:28 -040064 umode_t mode = inode->i_mode;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +090065 de->file_type = f2fs_type_by_mode[(mode & S_IFMT) >> S_SHIFT];
66}
67
Jaegeuk Kim38431542014-02-27 18:20:00 +090068static unsigned long dir_block_index(unsigned int level,
69 int dir_level, unsigned int idx)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +090070{
71 unsigned long i;
72 unsigned long bidx = 0;
73
74 for (i = 0; i < level; i++)
Jaegeuk Kim38431542014-02-27 18:20:00 +090075 bidx += dir_buckets(i, dir_level) * bucket_blocks(i);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +090076 bidx += idx * bucket_blocks(level);
77 return bidx;
78}
79
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -070080static bool early_match_name(size_t namelen, f2fs_hash_t namehash,
Gu Zhengeee61602014-06-24 18:21:23 +080081 struct f2fs_dir_entry *de)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +090082{
83 if (le16_to_cpu(de->name_len) != namelen)
84 return false;
85
Jaegeuk Kim25ca9232012-11-28 16:12:41 +090086 if (de->hash_code != namehash)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +090087 return false;
88
89 return true;
90}
91
92static struct f2fs_dir_entry *find_in_block(struct page *dentry_page,
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -070093 struct qstr *name, int *max_slots,
94 struct page **res_page)
95{
96 struct f2fs_dentry_block *dentry_blk;
97 struct f2fs_dir_entry *de;
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -070098 struct f2fs_dentry_ptr d;
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -070099
100 dentry_blk = (struct f2fs_dentry_block *)kmap(dentry_page);
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700101
102 make_dentry_ptr(&d, (void *)dentry_blk, 1);
103 de = find_target_dentry(name, max_slots, &d);
104
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -0700105 if (de)
106 *res_page = dentry_page;
107 else
108 kunmap(dentry_page);
109
110 /*
111 * For the most part, it should be a bug when name_len is zero.
112 * We stop here for figuring out where the bugs has occurred.
113 */
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700114 f2fs_bug_on(F2FS_P_SB(dentry_page), d.max < 0);
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -0700115 return de;
116}
117
118struct f2fs_dir_entry *find_target_dentry(struct qstr *name, int *max_slots,
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700119 struct f2fs_dentry_ptr *d)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900120{
121 struct f2fs_dir_entry *de;
Jaegeuk Kim5d0c66712014-02-27 13:57:53 +0900122 unsigned long bit_pos = 0;
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -0700123 f2fs_hash_t namehash = f2fs_dentry_hash(name);
Jaegeuk Kim5d0c66712014-02-27 13:57:53 +0900124 int max_len = 0;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900125
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700126 if (max_slots)
127 *max_slots = 0;
128 while (bit_pos < d->max) {
129 if (!test_bit_le(bit_pos, d->bitmap)) {
Jaegeuk Kim5d0c66712014-02-27 13:57:53 +0900130 bit_pos++;
Chao Yubda19072015-03-09 17:33:16 +0800131 max_len++;
Jaegeuk Kim5d0c66712014-02-27 13:57:53 +0900132 continue;
133 }
Chao Yubda19072015-03-09 17:33:16 +0800134
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700135 de = &d->dentry[bit_pos];
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -0700136 if (early_match_name(name->len, namehash, de) &&
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700137 !memcmp(d->filename[bit_pos], name->name, name->len))
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -0700138 goto found;
139
Chao Yubda19072015-03-09 17:33:16 +0800140 if (max_slots && max_len > *max_slots)
Jaegeuk Kim5d0c66712014-02-27 13:57:53 +0900141 *max_slots = max_len;
Chao Yubda19072015-03-09 17:33:16 +0800142 max_len = 0;
Chao Yu81e366f2014-07-10 12:37:46 +0800143
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -0700144 /* remain bug on condition */
145 if (unlikely(!de->name_len))
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700146 d->max = -1;
Chao Yu81e366f2014-07-10 12:37:46 +0800147
Jaegeuk Kim5d0c66712014-02-27 13:57:53 +0900148 bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900149 }
150
151 de = NULL;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900152found:
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700153 if (max_slots && max_len > *max_slots)
Jaegeuk Kim5d0c66712014-02-27 13:57:53 +0900154 *max_slots = max_len;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900155 return de;
156}
157
158static struct f2fs_dir_entry *find_in_level(struct inode *dir,
Gu Zhengeee61602014-06-24 18:21:23 +0800159 unsigned int level, struct qstr *name,
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900160 f2fs_hash_t namehash, struct page **res_page)
161{
Gu Zhengeee61602014-06-24 18:21:23 +0800162 int s = GET_DENTRY_SLOTS(name->len);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900163 unsigned int nbucket, nblock;
164 unsigned int bidx, end_block;
165 struct page *dentry_page;
166 struct f2fs_dir_entry *de = NULL;
167 bool room = false;
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -0700168 int max_slots;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900169
Jaegeuk Kim9850cf42014-09-02 15:52:58 -0700170 f2fs_bug_on(F2FS_I_SB(dir), level > MAX_DIR_HASH_DEPTH);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900171
Jaegeuk Kim38431542014-02-27 18:20:00 +0900172 nbucket = dir_buckets(level, F2FS_I(dir)->i_dir_level);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900173 nblock = bucket_blocks(level);
174
Jaegeuk Kim38431542014-02-27 18:20:00 +0900175 bidx = dir_block_index(level, F2FS_I(dir)->i_dir_level,
176 le32_to_cpu(namehash) % nbucket);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900177 end_block = bidx + nblock;
178
179 for (; bidx < end_block; bidx++) {
180 /* no need to allocate new dentry pages to all the indices */
Jaegeuk Kimc718379b2013-04-24 13:19:56 +0900181 dentry_page = find_data_page(dir, bidx, true);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900182 if (IS_ERR(dentry_page)) {
183 room = true;
184 continue;
185 }
186
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -0700187 de = find_in_block(dentry_page, name, &max_slots, res_page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900188 if (de)
189 break;
190
191 if (max_slots >= s)
192 room = true;
193 f2fs_put_page(dentry_page, 0);
194 }
195
196 if (!de && room && F2FS_I(dir)->chash != namehash) {
197 F2FS_I(dir)->chash = namehash;
198 F2FS_I(dir)->clevel = level;
199 }
200
201 return de;
202}
203
204/*
205 * Find an entry in the specified directory with the wanted name.
206 * It returns the page where the entry was found (as a parameter - res_page),
207 * and the entry itself. Page is returned mapped and unlocked.
208 * Entry is guaranteed to be valid.
209 */
210struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,
211 struct qstr *child, struct page **res_page)
212{
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900213 unsigned long npages = dir_blocks(dir);
214 struct f2fs_dir_entry *de = NULL;
215 f2fs_hash_t name_hash;
216 unsigned int max_depth;
217 unsigned int level;
218
Yuan Zhongb1f73b72015-03-07 10:07:42 +0000219 *res_page = NULL;
220
Chao Yu622f28a2014-09-24 18:19:10 +0800221 if (f2fs_has_inline_dentry(dir))
222 return find_in_inline_dir(dir, child, res_page);
223
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900224 if (npages == 0)
225 return NULL;
226
Gu Zhengeee61602014-06-24 18:21:23 +0800227 name_hash = f2fs_dentry_hash(child);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900228 max_depth = F2FS_I(dir)->i_current_depth;
229
230 for (level = 0; level < max_depth; level++) {
Gu Zhengeee61602014-06-24 18:21:23 +0800231 de = find_in_level(dir, level, child, name_hash, res_page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900232 if (de)
233 break;
234 }
235 if (!de && F2FS_I(dir)->chash != name_hash) {
236 F2FS_I(dir)->chash = name_hash;
237 F2FS_I(dir)->clevel = level - 1;
238 }
239 return de;
240}
241
242struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p)
243{
Namjae Jeon4777f862013-05-23 22:58:07 +0900244 struct page *page;
245 struct f2fs_dir_entry *de;
246 struct f2fs_dentry_block *dentry_blk;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900247
Chao Yu622f28a2014-09-24 18:19:10 +0800248 if (f2fs_has_inline_dentry(dir))
249 return f2fs_parent_inline_dir(dir, p);
250
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900251 page = get_lock_data_page(dir, 0);
252 if (IS_ERR(page))
253 return NULL;
254
255 dentry_blk = kmap(page);
256 de = &dentry_blk->dentry[1];
257 *p = page;
258 unlock_page(page);
259 return de;
260}
261
262ino_t f2fs_inode_by_name(struct inode *dir, struct qstr *qstr)
263{
264 ino_t res = 0;
265 struct f2fs_dir_entry *de;
266 struct page *page;
267
268 de = f2fs_find_entry(dir, qstr, &page);
269 if (de) {
270 res = le32_to_cpu(de->ino);
Jaegeuk Kim9486ba42014-11-21 16:36:28 -0800271 f2fs_dentry_kunmap(dir, page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900272 f2fs_put_page(page, 0);
273 }
274
275 return res;
276}
277
278void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
279 struct page *page, struct inode *inode)
280{
Jaegeuk Kim59a06152014-10-13 19:34:26 -0700281 enum page_type type = f2fs_has_inline_dentry(dir) ? NODE : DATA;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900282 lock_page(page);
Jaegeuk Kim59a06152014-10-13 19:34:26 -0700283 f2fs_wait_on_page_writeback(page, type);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900284 de->ino = cpu_to_le32(inode->i_ino);
285 set_de_type(de, inode);
Jaegeuk Kim5df1f1d2014-12-13 13:13:11 -0800286 f2fs_dentry_kunmap(dir, page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900287 set_page_dirty(page);
288 dir->i_mtime = dir->i_ctime = CURRENT_TIME;
289 mark_inode_dirty(dir);
Jaegeuk Kim6666e6a2012-12-10 17:52:48 +0900290
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900291 f2fs_put_page(page, 1);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900292}
293
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900294static void init_dent_inode(const struct qstr *name, struct page *ipage)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900295{
Jaegeuk Kim58bfaf42013-12-26 16:30:41 +0900296 struct f2fs_inode *ri;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900297
Jaegeuk Kim54b591d2014-04-29 17:28:32 +0900298 f2fs_wait_on_page_writeback(ipage, NODE);
299
Al Viro53dc9a62013-01-25 16:01:21 -0500300 /* copy name info. to this inode page */
Jaegeuk Kim58bfaf42013-12-26 16:30:41 +0900301 ri = F2FS_INODE(ipage);
302 ri->i_namelen = cpu_to_le32(name->len);
303 memcpy(ri->i_name, name->name, name->len);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900304 set_page_dirty(ipage);
305}
306
Jaegeuk Kim1cd14ca2013-07-18 18:02:31 +0900307int update_dent_inode(struct inode *inode, const struct qstr *name)
308{
Jaegeuk Kim1cd14ca2013-07-18 18:02:31 +0900309 struct page *page;
310
Jaegeuk Kim40813632014-09-02 15:31:18 -0700311 page = get_node_page(F2FS_I_SB(inode), inode->i_ino);
Jaegeuk Kim1cd14ca2013-07-18 18:02:31 +0900312 if (IS_ERR(page))
313 return PTR_ERR(page);
314
315 init_dent_inode(name, page);
316 f2fs_put_page(page, 1);
317
318 return 0;
319}
320
Jaegeuk Kim062a3e72014-10-18 23:06:41 -0700321void do_make_empty_dir(struct inode *inode, struct inode *parent,
322 struct f2fs_dentry_ptr *d)
323{
324 struct f2fs_dir_entry *de;
325
326 de = &d->dentry[0];
327 de->name_len = cpu_to_le16(1);
328 de->hash_code = 0;
329 de->ino = cpu_to_le32(inode->i_ino);
330 memcpy(d->filename[0], ".", 1);
331 set_de_type(de, inode);
332
333 de = &d->dentry[1];
334 de->hash_code = 0;
335 de->name_len = cpu_to_le16(2);
336 de->ino = cpu_to_le32(parent->i_ino);
337 memcpy(d->filename[1], "..", 2);
338 set_de_type(de, inode);
339
340 test_and_set_bit_le(0, (void *)d->bitmap);
341 test_and_set_bit_le(1, (void *)d->bitmap);
342}
343
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900344static int make_empty_dir(struct inode *inode,
345 struct inode *parent, struct page *page)
Jaegeuk Kim39936832012-11-22 16:21:29 +0900346{
347 struct page *dentry_page;
348 struct f2fs_dentry_block *dentry_blk;
Jaegeuk Kim062a3e72014-10-18 23:06:41 -0700349 struct f2fs_dentry_ptr d;
Jaegeuk Kim39936832012-11-22 16:21:29 +0900350
Chao Yu622f28a2014-09-24 18:19:10 +0800351 if (f2fs_has_inline_dentry(inode))
352 return make_empty_inline_dir(inode, parent, page);
353
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900354 dentry_page = get_new_data_page(inode, page, 0, true);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900355 if (IS_ERR(dentry_page))
356 return PTR_ERR(dentry_page);
357
Gu Zheng1c3bb972014-06-27 17:57:04 +0800358 dentry_blk = kmap_atomic(dentry_page);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900359
Jaegeuk Kim062a3e72014-10-18 23:06:41 -0700360 make_dentry_ptr(&d, (void *)dentry_blk, 1);
361 do_make_empty_dir(inode, parent, &d);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900362
Gu Zheng1c3bb972014-06-27 17:57:04 +0800363 kunmap_atomic(dentry_blk);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900364
365 set_page_dirty(dentry_page);
366 f2fs_put_page(dentry_page, 1);
367 return 0;
368}
369
Jaegeuk Kimbce8d112014-10-13 19:42:53 -0700370struct page *init_inode_metadata(struct inode *inode, struct inode *dir,
371 const struct qstr *name, struct page *dpage)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900372{
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900373 struct page *page;
374 int err;
375
Jaegeuk Kimb97a9b52014-06-20 21:37:02 -0700376 if (is_inode_flag_set(F2FS_I(inode), FI_NEW_INODE)) {
Jaegeuk Kima014e032014-06-20 21:44:02 -0700377 page = new_inode_page(inode);
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900378 if (IS_ERR(page))
379 return page;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900380
381 if (S_ISDIR(inode->i_mode)) {
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900382 err = make_empty_dir(inode, dir, page);
383 if (err)
384 goto error;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900385 }
386
Jaegeuk Kimbce8d112014-10-13 19:42:53 -0700387 err = f2fs_init_acl(inode, dir, page, dpage);
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900388 if (err)
Jaegeuk Kima8865372013-12-27 17:04:17 +0900389 goto put_error;
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900390
Jaegeuk Kim8ae8f162013-06-03 19:46:19 +0900391 err = f2fs_init_security(inode, dir, name, page);
392 if (err)
Jaegeuk Kima8865372013-12-27 17:04:17 +0900393 goto put_error;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900394 } else {
Jaegeuk Kim40813632014-09-02 15:31:18 -0700395 page = get_node_page(F2FS_I_SB(dir), inode->i_ino);
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900396 if (IS_ERR(page))
397 return page;
398
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900399 set_cold_node(inode, page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900400 }
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900401
Jaegeuk Kimb97a9b52014-06-20 21:37:02 -0700402 if (name)
403 init_dent_inode(name, page);
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900404
Jaegeuk Kim83d5d6f2013-05-28 12:25:47 +0900405 /*
406 * This file should be checkpointed during fsync.
407 * We lost i_pino from now on.
408 */
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900409 if (is_inode_flag_set(F2FS_I(inode), FI_INC_LINK)) {
Jaegeuk Kim354a3392013-06-14 08:52:35 +0900410 file_lost_pino(inode);
Chao Yu50732df2014-06-19 16:23:19 +0800411 /*
412 * If link the tmpfile to alias through linkat path,
413 * we should remove this inode from orphan list.
414 */
415 if (inode->i_nlink == 0)
Jaegeuk Kim40813632014-09-02 15:31:18 -0700416 remove_orphan_inode(F2FS_I_SB(dir), inode->i_ino);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900417 inc_nlink(inode);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900418 }
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900419 return page;
420
Jaegeuk Kima8865372013-12-27 17:04:17 +0900421put_error:
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900422 f2fs_put_page(page, 1);
Chao Yu90d72452014-06-24 10:34:00 +0800423error:
Jaegeuk Kimbd859c62014-02-05 11:16:39 +0900424 /* once the failed inode becomes a bad inode, i_mode is S_IFREG */
425 truncate_inode_pages(&inode->i_data, 0);
Jaegeuk Kim764aa3e2014-08-14 16:32:54 -0700426 truncate_blocks(inode, 0, false);
Jaegeuk Kimbd859c62014-02-05 11:16:39 +0900427 remove_dirty_dir_inode(inode);
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900428 remove_inode_page(inode);
429 return ERR_PTR(err);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900430}
431
Chao Yudbeacf02014-09-24 18:17:04 +0800432void update_parent_metadata(struct inode *dir, struct inode *inode,
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900433 unsigned int current_depth)
434{
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900435 if (is_inode_flag_set(F2FS_I(inode), FI_NEW_INODE)) {
436 if (S_ISDIR(inode->i_mode)) {
437 inc_nlink(dir);
Jaegeuk Kim699489b2013-06-07 22:08:23 +0900438 set_inode_flag(F2FS_I(dir), FI_UPDATE_DIR);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900439 }
440 clear_inode_flag(F2FS_I(inode), FI_NEW_INODE);
441 }
442 dir->i_mtime = dir->i_ctime = CURRENT_TIME;
Jaegeuk Kima18ff062014-01-21 13:32:12 +0900443 mark_inode_dirty(dir);
444
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900445 if (F2FS_I(dir)->i_current_depth != current_depth) {
446 F2FS_I(dir)->i_current_depth = current_depth;
Jaegeuk Kim699489b2013-06-07 22:08:23 +0900447 set_inode_flag(F2FS_I(dir), FI_UPDATE_DIR);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900448 }
449
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900450 if (is_inode_flag_set(F2FS_I(inode), FI_INC_LINK))
451 clear_inode_flag(F2FS_I(inode), FI_INC_LINK);
452}
453
Jaegeuk Kima82afa22014-10-13 16:28:13 -0700454int room_for_filename(const void *bitmap, int slots, int max_slots)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900455{
456 int bit_start = 0;
457 int zero_start, zero_end;
458next:
Jaegeuk Kima82afa22014-10-13 16:28:13 -0700459 zero_start = find_next_zero_bit_le(bitmap, max_slots, bit_start);
460 if (zero_start >= max_slots)
461 return max_slots;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900462
Jaegeuk Kima82afa22014-10-13 16:28:13 -0700463 zero_end = find_next_bit_le(bitmap, max_slots, zero_start);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900464 if (zero_end - zero_start >= slots)
465 return zero_start;
466
467 bit_start = zero_end + 1;
468
Jaegeuk Kima82afa22014-10-13 16:28:13 -0700469 if (zero_end + 1 >= max_slots)
470 return max_slots;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900471 goto next;
472}
473
Chao Yu3b4d7322015-02-16 16:17:20 +0800474void f2fs_update_dentry(struct inode *inode, struct f2fs_dentry_ptr *d,
475 const struct qstr *name, f2fs_hash_t name_hash,
476 unsigned int bit_pos)
477{
478 struct f2fs_dir_entry *de;
479 int slots = GET_DENTRY_SLOTS(name->len);
480 int i;
481
482 de = &d->dentry[bit_pos];
483 de->hash_code = name_hash;
484 de->name_len = cpu_to_le16(name->len);
485 memcpy(d->filename[bit_pos], name->name, name->len);
486 de->ino = cpu_to_le32(inode->i_ino);
487 set_de_type(de, inode);
488 for (i = 0; i < slots; i++)
489 test_and_set_bit_le(bit_pos + i, (void *)d->bitmap);
490}
491
Jaegeuk Kim39936832012-11-22 16:21:29 +0900492/*
Chao Yu4f4124d2013-12-21 18:02:14 +0800493 * Caller should grab and release a rwsem by calling f2fs_lock_op() and
494 * f2fs_unlock_op().
Jaegeuk Kim39936832012-11-22 16:21:29 +0900495 */
Chris Fries6c311ec2014-01-17 14:44:39 -0600496int __f2fs_add_link(struct inode *dir, const struct qstr *name,
497 struct inode *inode)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900498{
499 unsigned int bit_pos;
500 unsigned int level;
501 unsigned int current_depth;
502 unsigned long bidx, block;
503 f2fs_hash_t dentry_hash;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900504 unsigned int nbucket, nblock;
Al Virob7f7a5e2013-01-25 16:15:43 -0500505 size_t namelen = name->len;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900506 struct page *dentry_page = NULL;
507 struct f2fs_dentry_block *dentry_blk = NULL;
Chao Yu3b4d7322015-02-16 16:17:20 +0800508 struct f2fs_dentry_ptr d;
Namjae Jeon457d08e2012-12-08 14:54:50 +0900509 int slots = GET_DENTRY_SLOTS(namelen);
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900510 struct page *page;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900511 int err = 0;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900512
Chao Yu622f28a2014-09-24 18:19:10 +0800513 if (f2fs_has_inline_dentry(dir)) {
514 err = f2fs_add_inline_entry(dir, name, inode);
515 if (!err || err != -EAGAIN)
516 return err;
517 else
518 err = 0;
519 }
520
Gu Zhengeee61602014-06-24 18:21:23 +0800521 dentry_hash = f2fs_dentry_hash(name);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900522 level = 0;
523 current_depth = F2FS_I(dir)->i_current_depth;
524 if (F2FS_I(dir)->chash == dentry_hash) {
525 level = F2FS_I(dir)->clevel;
526 F2FS_I(dir)->chash = 0;
527 }
528
529start:
Chao Yucfb271d2013-12-05 17:15:22 +0800530 if (unlikely(current_depth == MAX_DIR_HASH_DEPTH))
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900531 return -ENOSPC;
532
533 /* Increase the depth, if required */
534 if (level == current_depth)
535 ++current_depth;
536
Jaegeuk Kim38431542014-02-27 18:20:00 +0900537 nbucket = dir_buckets(level, F2FS_I(dir)->i_dir_level);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900538 nblock = bucket_blocks(level);
539
Jaegeuk Kim38431542014-02-27 18:20:00 +0900540 bidx = dir_block_index(level, F2FS_I(dir)->i_dir_level,
541 (le32_to_cpu(dentry_hash) % nbucket));
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900542
543 for (block = bidx; block <= (bidx + nblock - 1); block++) {
Jaegeuk Kim64aa7ed2013-05-20 09:55:50 +0900544 dentry_page = get_new_data_page(dir, NULL, block, true);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900545 if (IS_ERR(dentry_page))
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900546 return PTR_ERR(dentry_page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900547
548 dentry_blk = kmap(dentry_page);
Jaegeuk Kima82afa22014-10-13 16:28:13 -0700549 bit_pos = room_for_filename(&dentry_blk->dentry_bitmap,
550 slots, NR_DENTRY_IN_BLOCK);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900551 if (bit_pos < NR_DENTRY_IN_BLOCK)
552 goto add_dentry;
553
554 kunmap(dentry_page);
555 f2fs_put_page(dentry_page, 1);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900556 }
557
558 /* Move to next level to find the empty slot for new dentry */
559 ++level;
560 goto start;
561add_dentry:
Jaegeuk Kim3cb5ad12014-03-18 13:29:07 +0900562 f2fs_wait_on_page_writeback(dentry_page, DATA);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900563
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900564 down_write(&F2FS_I(inode)->i_sem);
Jaegeuk Kimbce8d112014-10-13 19:42:53 -0700565 page = init_inode_metadata(inode, dir, name, NULL);
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900566 if (IS_ERR(page)) {
567 err = PTR_ERR(page);
568 goto fail;
569 }
Chao Yu3b4d7322015-02-16 16:17:20 +0800570
571 make_dentry_ptr(&d, (void *)dentry_blk, 1);
572 f2fs_update_dentry(inode, &d, name, dentry_hash, bit_pos);
573
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900574 set_page_dirty(dentry_page);
Jaegeuk Kim6666e6a2012-12-10 17:52:48 +0900575
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900576 /* we don't need to mark_inode_dirty now */
Jaegeuk Kim6666e6a2012-12-10 17:52:48 +0900577 F2FS_I(inode)->i_pino = dir->i_ino;
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900578 update_inode(inode, page);
579 f2fs_put_page(page, 1);
580
581 update_parent_metadata(dir, inode, current_depth);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900582fail:
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900583 up_write(&F2FS_I(inode)->i_sem);
584
Jaegeuk Kim924a2dd2014-02-03 17:24:51 +0900585 if (is_inode_flag_set(F2FS_I(dir), FI_UPDATE_DIR)) {
586 update_inode_page(dir);
587 clear_inode_flag(F2FS_I(dir), FI_UPDATE_DIR);
588 }
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900589 kunmap(dentry_page);
590 f2fs_put_page(dentry_page, 1);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900591 return err;
592}
593
Jaegeuk Kimb97a9b52014-06-20 21:37:02 -0700594int f2fs_do_tmpfile(struct inode *inode, struct inode *dir)
595{
596 struct page *page;
597 int err = 0;
598
599 down_write(&F2FS_I(inode)->i_sem);
Jaegeuk Kimbce8d112014-10-13 19:42:53 -0700600 page = init_inode_metadata(inode, dir, NULL, NULL);
Jaegeuk Kimb97a9b52014-06-20 21:37:02 -0700601 if (IS_ERR(page)) {
602 err = PTR_ERR(page);
603 goto fail;
604 }
605 /* we don't need to mark_inode_dirty now */
606 update_inode(inode, page);
607 f2fs_put_page(page, 1);
608
609 clear_inode_flag(F2FS_I(inode), FI_NEW_INODE);
610fail:
611 up_write(&F2FS_I(inode)->i_sem);
612 return err;
613}
614
Chao Yudbeacf02014-09-24 18:17:04 +0800615void f2fs_drop_nlink(struct inode *dir, struct inode *inode, struct page *page)
616{
617 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
618
619 down_write(&F2FS_I(inode)->i_sem);
620
621 if (S_ISDIR(inode->i_mode)) {
622 drop_nlink(dir);
623 if (page)
624 update_inode(dir, page);
625 else
626 update_inode_page(dir);
627 }
628 inode->i_ctime = CURRENT_TIME;
629
630 drop_nlink(inode);
631 if (S_ISDIR(inode->i_mode)) {
632 drop_nlink(inode);
633 i_size_write(inode, 0);
634 }
635 up_write(&F2FS_I(inode)->i_sem);
636 update_inode_page(inode);
637
638 if (inode->i_nlink == 0)
639 add_orphan_inode(sbi, inode->i_ino);
640 else
641 release_orphan_inode(sbi);
642}
643
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +0900644/*
arter97e1c42042014-08-06 23:22:50 +0900645 * It only removes the dentry from the dentry page, corresponding name
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900646 * entry in name page does not need to be touched during deletion.
647 */
648void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
Chao Yudbeacf02014-09-24 18:17:04 +0800649 struct inode *dir, struct inode *inode)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900650{
651 struct f2fs_dentry_block *dentry_blk;
652 unsigned int bit_pos;
Namjae Jeon457d08e2012-12-08 14:54:50 +0900653 int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len));
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900654 int i;
655
Chao Yu622f28a2014-09-24 18:19:10 +0800656 if (f2fs_has_inline_dentry(dir))
657 return f2fs_delete_inline_entry(dentry, page, dir, inode);
658
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900659 lock_page(page);
Jaegeuk Kim3cb5ad12014-03-18 13:29:07 +0900660 f2fs_wait_on_page_writeback(page, DATA);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900661
Gu Zheng1c3bb972014-06-27 17:57:04 +0800662 dentry_blk = page_address(page);
663 bit_pos = dentry - dentry_blk->dentry;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900664 for (i = 0; i < slots; i++)
Jan Kara1f7732f2014-10-23 14:40:20 +0200665 clear_bit_le(bit_pos + i, &dentry_blk->dentry_bitmap);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900666
667 /* Let's check and deallocate this dentry page */
668 bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap,
669 NR_DENTRY_IN_BLOCK,
670 0);
671 kunmap(page); /* kunmap - pair of f2fs_find_entry */
672 set_page_dirty(page);
673
674 dir->i_ctime = dir->i_mtime = CURRENT_TIME;
675
Chao Yudbeacf02014-09-24 18:17:04 +0800676 if (inode)
677 f2fs_drop_nlink(dir, inode, NULL);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900678
679 if (bit_pos == NR_DENTRY_IN_BLOCK) {
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900680 truncate_hole(dir, page->index, page->index + 1);
681 clear_page_dirty_for_io(page);
Jaegeuk Kim2bca1e22015-02-25 19:25:01 -0800682 ClearPagePrivate(page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900683 ClearPageUptodate(page);
Jaegeuk Kima7ffdbe2014-09-12 15:53:45 -0700684 inode_dec_dirty_pages(dir);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900685 }
Namjae Jeon508198b2012-12-08 14:54:35 +0900686 f2fs_put_page(page, 1);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900687}
688
689bool f2fs_empty_dir(struct inode *dir)
690{
691 unsigned long bidx;
692 struct page *dentry_page;
693 unsigned int bit_pos;
Chao Yudbeacf02014-09-24 18:17:04 +0800694 struct f2fs_dentry_block *dentry_blk;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900695 unsigned long nblock = dir_blocks(dir);
696
Chao Yu622f28a2014-09-24 18:19:10 +0800697 if (f2fs_has_inline_dentry(dir))
698 return f2fs_empty_inline_dir(dir);
699
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900700 for (bidx = 0; bidx < nblock; bidx++) {
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900701 dentry_page = get_lock_data_page(dir, bidx);
702 if (IS_ERR(dentry_page)) {
703 if (PTR_ERR(dentry_page) == -ENOENT)
704 continue;
705 else
706 return false;
707 }
708
Gu Zheng1c3bb972014-06-27 17:57:04 +0800709 dentry_blk = kmap_atomic(dentry_page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900710 if (bidx == 0)
711 bit_pos = 2;
712 else
713 bit_pos = 0;
714 bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap,
715 NR_DENTRY_IN_BLOCK,
716 bit_pos);
Gu Zheng1c3bb972014-06-27 17:57:04 +0800717 kunmap_atomic(dentry_blk);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900718
719 f2fs_put_page(dentry_page, 1);
720
721 if (bit_pos < NR_DENTRY_IN_BLOCK)
722 return false;
723 }
724 return true;
725}
726
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700727bool f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
728 unsigned int start_pos)
Jaegeuk Kim38594de2014-10-15 21:29:51 -0700729{
730 unsigned char d_type = DT_UNKNOWN;
731 unsigned int bit_pos;
732 struct f2fs_dir_entry *de = NULL;
733
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700734 bit_pos = ((unsigned long)ctx->pos % d->max);
Jaegeuk Kim38594de2014-10-15 21:29:51 -0700735
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700736 while (bit_pos < d->max) {
737 bit_pos = find_next_bit_le(d->bitmap, d->max, bit_pos);
738 if (bit_pos >= d->max)
Jaegeuk Kim38594de2014-10-15 21:29:51 -0700739 break;
740
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700741 de = &d->dentry[bit_pos];
Jaegeuk Kim38594de2014-10-15 21:29:51 -0700742 if (de->file_type < F2FS_FT_MAX)
743 d_type = f2fs_filetype_table[de->file_type];
744 else
745 d_type = DT_UNKNOWN;
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700746 if (!dir_emit(ctx, d->filename[bit_pos],
Jaegeuk Kim38594de2014-10-15 21:29:51 -0700747 le16_to_cpu(de->name_len),
748 le32_to_cpu(de->ino), d_type))
749 return true;
750
751 bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
752 ctx->pos = start_pos + bit_pos;
753 }
754 return false;
755}
756
Al Viro6f7f2312013-05-17 18:02:17 -0400757static int f2fs_readdir(struct file *file, struct dir_context *ctx)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900758{
Al Viro496ad9a2013-01-23 17:07:38 -0500759 struct inode *inode = file_inode(file);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900760 unsigned long npages = dir_blocks(inode);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900761 struct f2fs_dentry_block *dentry_blk = NULL;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900762 struct page *dentry_page = NULL;
Chao Yu817202d92014-04-28 17:59:43 +0800763 struct file_ra_state *ra = &file->f_ra;
Al Viro6f7f2312013-05-17 18:02:17 -0400764 unsigned int n = ((unsigned long)ctx->pos / NR_DENTRY_IN_BLOCK);
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700765 struct f2fs_dentry_ptr d;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900766
Chao Yu622f28a2014-09-24 18:19:10 +0800767 if (f2fs_has_inline_dentry(inode))
768 return f2fs_read_inline_dir(file, ctx);
769
Chao Yu817202d92014-04-28 17:59:43 +0800770 /* readahead for multi pages of dir */
771 if (npages - n > 1 && !ra_has_index(ra, n))
772 page_cache_sync_readahead(inode->i_mapping, ra, file, n,
773 min(npages - n, (pgoff_t)MAX_DIR_RA_PAGES));
774
Chris Fries6c311ec2014-01-17 14:44:39 -0600775 for (; n < npages; n++) {
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900776 dentry_page = get_lock_data_page(inode, n);
777 if (IS_ERR(dentry_page))
778 continue;
779
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900780 dentry_blk = kmap(dentry_page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900781
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700782 make_dentry_ptr(&d, (void *)dentry_blk, 1);
783
784 if (f2fs_fill_dentries(ctx, &d, n * NR_DENTRY_IN_BLOCK))
Jaegeuk Kim38594de2014-10-15 21:29:51 -0700785 goto stop;
Jaegeuk Kim99b072bb2013-07-05 17:28:12 +0900786
Al Viro6f7f2312013-05-17 18:02:17 -0400787 ctx->pos = (n + 1) * NR_DENTRY_IN_BLOCK;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900788 kunmap(dentry_page);
789 f2fs_put_page(dentry_page, 1);
790 dentry_page = NULL;
791 }
Jaegeuk Kim99b072bb2013-07-05 17:28:12 +0900792stop:
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900793 if (dentry_page && !IS_ERR(dentry_page)) {
794 kunmap(dentry_page);
795 f2fs_put_page(dentry_page, 1);
796 }
797
798 return 0;
799}
800
801const struct file_operations f2fs_dir_operations = {
802 .llseek = generic_file_llseek,
803 .read = generic_read_dir,
Al Viro6f7f2312013-05-17 18:02:17 -0400804 .iterate = f2fs_readdir,
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900805 .fsync = f2fs_sync_file,
806 .unlocked_ioctl = f2fs_ioctl,
807};