blob: a28909d9aea8956c58a34d848e716dcb04479cb2 [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 if (bit_pos == 0)
131 max_len = 1;
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700132 else if (!test_bit_le(bit_pos - 1, d->bitmap))
Jaegeuk Kim5d0c66712014-02-27 13:57:53 +0900133 max_len++;
134 bit_pos++;
135 continue;
136 }
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700137 de = &d->dentry[bit_pos];
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -0700138 if (early_match_name(name->len, namehash, de) &&
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700139 !memcmp(d->filename[bit_pos], name->name, name->len))
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -0700140 goto found;
141
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700142 if (max_slots && *max_slots >= 0 && max_len > *max_slots) {
Jaegeuk Kim5d0c66712014-02-27 13:57:53 +0900143 *max_slots = max_len;
144 max_len = 0;
145 }
Chao Yu81e366f2014-07-10 12:37:46 +0800146
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -0700147 /* remain bug on condition */
148 if (unlikely(!de->name_len))
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700149 d->max = -1;
Chao Yu81e366f2014-07-10 12:37:46 +0800150
Jaegeuk Kim5d0c66712014-02-27 13:57:53 +0900151 bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900152 }
153
154 de = NULL;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900155found:
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700156 if (max_slots && max_len > *max_slots)
Jaegeuk Kim5d0c66712014-02-27 13:57:53 +0900157 *max_slots = max_len;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900158 return de;
159}
160
161static struct f2fs_dir_entry *find_in_level(struct inode *dir,
Gu Zhengeee61602014-06-24 18:21:23 +0800162 unsigned int level, struct qstr *name,
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900163 f2fs_hash_t namehash, struct page **res_page)
164{
Gu Zhengeee61602014-06-24 18:21:23 +0800165 int s = GET_DENTRY_SLOTS(name->len);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900166 unsigned int nbucket, nblock;
167 unsigned int bidx, end_block;
168 struct page *dentry_page;
169 struct f2fs_dir_entry *de = NULL;
170 bool room = false;
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -0700171 int max_slots;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900172
Jaegeuk Kim9850cf42014-09-02 15:52:58 -0700173 f2fs_bug_on(F2FS_I_SB(dir), level > MAX_DIR_HASH_DEPTH);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900174
Jaegeuk Kim38431542014-02-27 18:20:00 +0900175 nbucket = dir_buckets(level, F2FS_I(dir)->i_dir_level);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900176 nblock = bucket_blocks(level);
177
Jaegeuk Kim38431542014-02-27 18:20:00 +0900178 bidx = dir_block_index(level, F2FS_I(dir)->i_dir_level,
179 le32_to_cpu(namehash) % nbucket);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900180 end_block = bidx + nblock;
181
182 for (; bidx < end_block; bidx++) {
183 /* no need to allocate new dentry pages to all the indices */
Jaegeuk Kimc718379b2013-04-24 13:19:56 +0900184 dentry_page = find_data_page(dir, bidx, true);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900185 if (IS_ERR(dentry_page)) {
186 room = true;
187 continue;
188 }
189
Jaegeuk Kim4e6ebf62014-10-13 17:26:14 -0700190 de = find_in_block(dentry_page, name, &max_slots, res_page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900191 if (de)
192 break;
193
194 if (max_slots >= s)
195 room = true;
196 f2fs_put_page(dentry_page, 0);
197 }
198
199 if (!de && room && F2FS_I(dir)->chash != namehash) {
200 F2FS_I(dir)->chash = namehash;
201 F2FS_I(dir)->clevel = level;
202 }
203
204 return de;
205}
206
207/*
208 * Find an entry in the specified directory with the wanted name.
209 * It returns the page where the entry was found (as a parameter - res_page),
210 * and the entry itself. Page is returned mapped and unlocked.
211 * Entry is guaranteed to be valid.
212 */
213struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,
214 struct qstr *child, struct page **res_page)
215{
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900216 unsigned long npages = dir_blocks(dir);
217 struct f2fs_dir_entry *de = NULL;
218 f2fs_hash_t name_hash;
219 unsigned int max_depth;
220 unsigned int level;
221
Yuan Zhongb1f73b72015-03-07 10:07:42 +0000222 *res_page = NULL;
223
Chao Yu622f28a2014-09-24 18:19:10 +0800224 if (f2fs_has_inline_dentry(dir))
225 return find_in_inline_dir(dir, child, res_page);
226
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900227 if (npages == 0)
228 return NULL;
229
Gu Zhengeee61602014-06-24 18:21:23 +0800230 name_hash = f2fs_dentry_hash(child);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900231 max_depth = F2FS_I(dir)->i_current_depth;
232
233 for (level = 0; level < max_depth; level++) {
Gu Zhengeee61602014-06-24 18:21:23 +0800234 de = find_in_level(dir, level, child, name_hash, res_page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900235 if (de)
236 break;
237 }
238 if (!de && F2FS_I(dir)->chash != name_hash) {
239 F2FS_I(dir)->chash = name_hash;
240 F2FS_I(dir)->clevel = level - 1;
241 }
242 return de;
243}
244
245struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p)
246{
Namjae Jeon4777f862013-05-23 22:58:07 +0900247 struct page *page;
248 struct f2fs_dir_entry *de;
249 struct f2fs_dentry_block *dentry_blk;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900250
Chao Yu622f28a2014-09-24 18:19:10 +0800251 if (f2fs_has_inline_dentry(dir))
252 return f2fs_parent_inline_dir(dir, p);
253
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900254 page = get_lock_data_page(dir, 0);
255 if (IS_ERR(page))
256 return NULL;
257
258 dentry_blk = kmap(page);
259 de = &dentry_blk->dentry[1];
260 *p = page;
261 unlock_page(page);
262 return de;
263}
264
265ino_t f2fs_inode_by_name(struct inode *dir, struct qstr *qstr)
266{
267 ino_t res = 0;
268 struct f2fs_dir_entry *de;
269 struct page *page;
270
271 de = f2fs_find_entry(dir, qstr, &page);
272 if (de) {
273 res = le32_to_cpu(de->ino);
Jaegeuk Kim9486ba42014-11-21 16:36:28 -0800274 f2fs_dentry_kunmap(dir, page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900275 f2fs_put_page(page, 0);
276 }
277
278 return res;
279}
280
281void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
282 struct page *page, struct inode *inode)
283{
Jaegeuk Kim59a06152014-10-13 19:34:26 -0700284 enum page_type type = f2fs_has_inline_dentry(dir) ? NODE : DATA;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900285 lock_page(page);
Jaegeuk Kim59a06152014-10-13 19:34:26 -0700286 f2fs_wait_on_page_writeback(page, type);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900287 de->ino = cpu_to_le32(inode->i_ino);
288 set_de_type(de, inode);
Jaegeuk Kim5df1f1d2014-12-13 13:13:11 -0800289 f2fs_dentry_kunmap(dir, page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900290 set_page_dirty(page);
291 dir->i_mtime = dir->i_ctime = CURRENT_TIME;
292 mark_inode_dirty(dir);
Jaegeuk Kim6666e6a2012-12-10 17:52:48 +0900293
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900294 f2fs_put_page(page, 1);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900295}
296
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900297static void init_dent_inode(const struct qstr *name, struct page *ipage)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900298{
Jaegeuk Kim58bfaf42013-12-26 16:30:41 +0900299 struct f2fs_inode *ri;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900300
Jaegeuk Kim54b591d2014-04-29 17:28:32 +0900301 f2fs_wait_on_page_writeback(ipage, NODE);
302
Al Viro53dc9a62013-01-25 16:01:21 -0500303 /* copy name info. to this inode page */
Jaegeuk Kim58bfaf42013-12-26 16:30:41 +0900304 ri = F2FS_INODE(ipage);
305 ri->i_namelen = cpu_to_le32(name->len);
306 memcpy(ri->i_name, name->name, name->len);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900307 set_page_dirty(ipage);
308}
309
Jaegeuk Kim1cd14ca2013-07-18 18:02:31 +0900310int update_dent_inode(struct inode *inode, const struct qstr *name)
311{
Jaegeuk Kim1cd14ca2013-07-18 18:02:31 +0900312 struct page *page;
313
Jaegeuk Kim40813632014-09-02 15:31:18 -0700314 page = get_node_page(F2FS_I_SB(inode), inode->i_ino);
Jaegeuk Kim1cd14ca2013-07-18 18:02:31 +0900315 if (IS_ERR(page))
316 return PTR_ERR(page);
317
318 init_dent_inode(name, page);
319 f2fs_put_page(page, 1);
320
321 return 0;
322}
323
Jaegeuk Kim062a3e72014-10-18 23:06:41 -0700324void do_make_empty_dir(struct inode *inode, struct inode *parent,
325 struct f2fs_dentry_ptr *d)
326{
327 struct f2fs_dir_entry *de;
328
329 de = &d->dentry[0];
330 de->name_len = cpu_to_le16(1);
331 de->hash_code = 0;
332 de->ino = cpu_to_le32(inode->i_ino);
333 memcpy(d->filename[0], ".", 1);
334 set_de_type(de, inode);
335
336 de = &d->dentry[1];
337 de->hash_code = 0;
338 de->name_len = cpu_to_le16(2);
339 de->ino = cpu_to_le32(parent->i_ino);
340 memcpy(d->filename[1], "..", 2);
341 set_de_type(de, inode);
342
343 test_and_set_bit_le(0, (void *)d->bitmap);
344 test_and_set_bit_le(1, (void *)d->bitmap);
345}
346
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900347static int make_empty_dir(struct inode *inode,
348 struct inode *parent, struct page *page)
Jaegeuk Kim39936832012-11-22 16:21:29 +0900349{
350 struct page *dentry_page;
351 struct f2fs_dentry_block *dentry_blk;
Jaegeuk Kim062a3e72014-10-18 23:06:41 -0700352 struct f2fs_dentry_ptr d;
Jaegeuk Kim39936832012-11-22 16:21:29 +0900353
Chao Yu622f28a2014-09-24 18:19:10 +0800354 if (f2fs_has_inline_dentry(inode))
355 return make_empty_inline_dir(inode, parent, page);
356
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900357 dentry_page = get_new_data_page(inode, page, 0, true);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900358 if (IS_ERR(dentry_page))
359 return PTR_ERR(dentry_page);
360
Gu Zheng1c3bb972014-06-27 17:57:04 +0800361 dentry_blk = kmap_atomic(dentry_page);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900362
Jaegeuk Kim062a3e72014-10-18 23:06:41 -0700363 make_dentry_ptr(&d, (void *)dentry_blk, 1);
364 do_make_empty_dir(inode, parent, &d);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900365
Gu Zheng1c3bb972014-06-27 17:57:04 +0800366 kunmap_atomic(dentry_blk);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900367
368 set_page_dirty(dentry_page);
369 f2fs_put_page(dentry_page, 1);
370 return 0;
371}
372
Jaegeuk Kimbce8d112014-10-13 19:42:53 -0700373struct page *init_inode_metadata(struct inode *inode, struct inode *dir,
374 const struct qstr *name, struct page *dpage)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900375{
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900376 struct page *page;
377 int err;
378
Jaegeuk Kimb97a9b52014-06-20 21:37:02 -0700379 if (is_inode_flag_set(F2FS_I(inode), FI_NEW_INODE)) {
Jaegeuk Kima014e032014-06-20 21:44:02 -0700380 page = new_inode_page(inode);
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900381 if (IS_ERR(page))
382 return page;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900383
384 if (S_ISDIR(inode->i_mode)) {
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900385 err = make_empty_dir(inode, dir, page);
386 if (err)
387 goto error;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900388 }
389
Jaegeuk Kimbce8d112014-10-13 19:42:53 -0700390 err = f2fs_init_acl(inode, dir, page, dpage);
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900391 if (err)
Jaegeuk Kima8865372013-12-27 17:04:17 +0900392 goto put_error;
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900393
Jaegeuk Kim8ae8f162013-06-03 19:46:19 +0900394 err = f2fs_init_security(inode, dir, name, page);
395 if (err)
Jaegeuk Kima8865372013-12-27 17:04:17 +0900396 goto put_error;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900397 } else {
Jaegeuk Kim40813632014-09-02 15:31:18 -0700398 page = get_node_page(F2FS_I_SB(dir), inode->i_ino);
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900399 if (IS_ERR(page))
400 return page;
401
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900402 set_cold_node(inode, page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900403 }
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900404
Jaegeuk Kimb97a9b52014-06-20 21:37:02 -0700405 if (name)
406 init_dent_inode(name, page);
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900407
Jaegeuk Kim83d5d6f2013-05-28 12:25:47 +0900408 /*
409 * This file should be checkpointed during fsync.
410 * We lost i_pino from now on.
411 */
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900412 if (is_inode_flag_set(F2FS_I(inode), FI_INC_LINK)) {
Jaegeuk Kim354a3392013-06-14 08:52:35 +0900413 file_lost_pino(inode);
Chao Yu50732df2014-06-19 16:23:19 +0800414 /*
415 * If link the tmpfile to alias through linkat path,
416 * we should remove this inode from orphan list.
417 */
418 if (inode->i_nlink == 0)
Jaegeuk Kim40813632014-09-02 15:31:18 -0700419 remove_orphan_inode(F2FS_I_SB(dir), inode->i_ino);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900420 inc_nlink(inode);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900421 }
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900422 return page;
423
Jaegeuk Kima8865372013-12-27 17:04:17 +0900424put_error:
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900425 f2fs_put_page(page, 1);
Chao Yu90d72452014-06-24 10:34:00 +0800426error:
Jaegeuk Kimbd859c62014-02-05 11:16:39 +0900427 /* once the failed inode becomes a bad inode, i_mode is S_IFREG */
428 truncate_inode_pages(&inode->i_data, 0);
Jaegeuk Kim764aa3e2014-08-14 16:32:54 -0700429 truncate_blocks(inode, 0, false);
Jaegeuk Kimbd859c62014-02-05 11:16:39 +0900430 remove_dirty_dir_inode(inode);
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900431 remove_inode_page(inode);
432 return ERR_PTR(err);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900433}
434
Chao Yudbeacf02014-09-24 18:17:04 +0800435void update_parent_metadata(struct inode *dir, struct inode *inode,
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900436 unsigned int current_depth)
437{
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900438 if (is_inode_flag_set(F2FS_I(inode), FI_NEW_INODE)) {
439 if (S_ISDIR(inode->i_mode)) {
440 inc_nlink(dir);
Jaegeuk Kim699489b2013-06-07 22:08:23 +0900441 set_inode_flag(F2FS_I(dir), FI_UPDATE_DIR);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900442 }
443 clear_inode_flag(F2FS_I(inode), FI_NEW_INODE);
444 }
445 dir->i_mtime = dir->i_ctime = CURRENT_TIME;
Jaegeuk Kima18ff062014-01-21 13:32:12 +0900446 mark_inode_dirty(dir);
447
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900448 if (F2FS_I(dir)->i_current_depth != current_depth) {
449 F2FS_I(dir)->i_current_depth = current_depth;
Jaegeuk Kim699489b2013-06-07 22:08:23 +0900450 set_inode_flag(F2FS_I(dir), FI_UPDATE_DIR);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900451 }
452
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900453 if (is_inode_flag_set(F2FS_I(inode), FI_INC_LINK))
454 clear_inode_flag(F2FS_I(inode), FI_INC_LINK);
455}
456
Jaegeuk Kima82afa22014-10-13 16:28:13 -0700457int room_for_filename(const void *bitmap, int slots, int max_slots)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900458{
459 int bit_start = 0;
460 int zero_start, zero_end;
461next:
Jaegeuk Kima82afa22014-10-13 16:28:13 -0700462 zero_start = find_next_zero_bit_le(bitmap, max_slots, bit_start);
463 if (zero_start >= max_slots)
464 return max_slots;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900465
Jaegeuk Kima82afa22014-10-13 16:28:13 -0700466 zero_end = find_next_bit_le(bitmap, max_slots, zero_start);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900467 if (zero_end - zero_start >= slots)
468 return zero_start;
469
470 bit_start = zero_end + 1;
471
Jaegeuk Kima82afa22014-10-13 16:28:13 -0700472 if (zero_end + 1 >= max_slots)
473 return max_slots;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900474 goto next;
475}
476
Chao Yu3b4d7322015-02-16 16:17:20 +0800477void f2fs_update_dentry(struct inode *inode, struct f2fs_dentry_ptr *d,
478 const struct qstr *name, f2fs_hash_t name_hash,
479 unsigned int bit_pos)
480{
481 struct f2fs_dir_entry *de;
482 int slots = GET_DENTRY_SLOTS(name->len);
483 int i;
484
485 de = &d->dentry[bit_pos];
486 de->hash_code = name_hash;
487 de->name_len = cpu_to_le16(name->len);
488 memcpy(d->filename[bit_pos], name->name, name->len);
489 de->ino = cpu_to_le32(inode->i_ino);
490 set_de_type(de, inode);
491 for (i = 0; i < slots; i++)
492 test_and_set_bit_le(bit_pos + i, (void *)d->bitmap);
493}
494
Jaegeuk Kim39936832012-11-22 16:21:29 +0900495/*
Chao Yu4f4124d2013-12-21 18:02:14 +0800496 * Caller should grab and release a rwsem by calling f2fs_lock_op() and
497 * f2fs_unlock_op().
Jaegeuk Kim39936832012-11-22 16:21:29 +0900498 */
Chris Fries6c311ec2014-01-17 14:44:39 -0600499int __f2fs_add_link(struct inode *dir, const struct qstr *name,
500 struct inode *inode)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900501{
502 unsigned int bit_pos;
503 unsigned int level;
504 unsigned int current_depth;
505 unsigned long bidx, block;
506 f2fs_hash_t dentry_hash;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900507 unsigned int nbucket, nblock;
Al Virob7f7a5e2013-01-25 16:15:43 -0500508 size_t namelen = name->len;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900509 struct page *dentry_page = NULL;
510 struct f2fs_dentry_block *dentry_blk = NULL;
Chao Yu3b4d7322015-02-16 16:17:20 +0800511 struct f2fs_dentry_ptr d;
Namjae Jeon457d08e2012-12-08 14:54:50 +0900512 int slots = GET_DENTRY_SLOTS(namelen);
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900513 struct page *page;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900514 int err = 0;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900515
Chao Yu622f28a2014-09-24 18:19:10 +0800516 if (f2fs_has_inline_dentry(dir)) {
517 err = f2fs_add_inline_entry(dir, name, inode);
518 if (!err || err != -EAGAIN)
519 return err;
520 else
521 err = 0;
522 }
523
Gu Zhengeee61602014-06-24 18:21:23 +0800524 dentry_hash = f2fs_dentry_hash(name);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900525 level = 0;
526 current_depth = F2FS_I(dir)->i_current_depth;
527 if (F2FS_I(dir)->chash == dentry_hash) {
528 level = F2FS_I(dir)->clevel;
529 F2FS_I(dir)->chash = 0;
530 }
531
532start:
Chao Yucfb271d2013-12-05 17:15:22 +0800533 if (unlikely(current_depth == MAX_DIR_HASH_DEPTH))
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900534 return -ENOSPC;
535
536 /* Increase the depth, if required */
537 if (level == current_depth)
538 ++current_depth;
539
Jaegeuk Kim38431542014-02-27 18:20:00 +0900540 nbucket = dir_buckets(level, F2FS_I(dir)->i_dir_level);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900541 nblock = bucket_blocks(level);
542
Jaegeuk Kim38431542014-02-27 18:20:00 +0900543 bidx = dir_block_index(level, F2FS_I(dir)->i_dir_level,
544 (le32_to_cpu(dentry_hash) % nbucket));
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900545
546 for (block = bidx; block <= (bidx + nblock - 1); block++) {
Jaegeuk Kim64aa7ed2013-05-20 09:55:50 +0900547 dentry_page = get_new_data_page(dir, NULL, block, true);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900548 if (IS_ERR(dentry_page))
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900549 return PTR_ERR(dentry_page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900550
551 dentry_blk = kmap(dentry_page);
Jaegeuk Kima82afa22014-10-13 16:28:13 -0700552 bit_pos = room_for_filename(&dentry_blk->dentry_bitmap,
553 slots, NR_DENTRY_IN_BLOCK);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900554 if (bit_pos < NR_DENTRY_IN_BLOCK)
555 goto add_dentry;
556
557 kunmap(dentry_page);
558 f2fs_put_page(dentry_page, 1);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900559 }
560
561 /* Move to next level to find the empty slot for new dentry */
562 ++level;
563 goto start;
564add_dentry:
Jaegeuk Kim3cb5ad12014-03-18 13:29:07 +0900565 f2fs_wait_on_page_writeback(dentry_page, DATA);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900566
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900567 down_write(&F2FS_I(inode)->i_sem);
Jaegeuk Kimbce8d112014-10-13 19:42:53 -0700568 page = init_inode_metadata(inode, dir, name, NULL);
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900569 if (IS_ERR(page)) {
570 err = PTR_ERR(page);
571 goto fail;
572 }
Chao Yu3b4d7322015-02-16 16:17:20 +0800573
574 make_dentry_ptr(&d, (void *)dentry_blk, 1);
575 f2fs_update_dentry(inode, &d, name, dentry_hash, bit_pos);
576
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900577 set_page_dirty(dentry_page);
Jaegeuk Kim6666e6a2012-12-10 17:52:48 +0900578
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900579 /* we don't need to mark_inode_dirty now */
Jaegeuk Kim6666e6a2012-12-10 17:52:48 +0900580 F2FS_I(inode)->i_pino = dir->i_ino;
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900581 update_inode(inode, page);
582 f2fs_put_page(page, 1);
583
584 update_parent_metadata(dir, inode, current_depth);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900585fail:
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900586 up_write(&F2FS_I(inode)->i_sem);
587
Jaegeuk Kim924a2dd2014-02-03 17:24:51 +0900588 if (is_inode_flag_set(F2FS_I(dir), FI_UPDATE_DIR)) {
589 update_inode_page(dir);
590 clear_inode_flag(F2FS_I(dir), FI_UPDATE_DIR);
591 }
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900592 kunmap(dentry_page);
593 f2fs_put_page(dentry_page, 1);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900594 return err;
595}
596
Jaegeuk Kimb97a9b52014-06-20 21:37:02 -0700597int f2fs_do_tmpfile(struct inode *inode, struct inode *dir)
598{
599 struct page *page;
600 int err = 0;
601
602 down_write(&F2FS_I(inode)->i_sem);
Jaegeuk Kimbce8d112014-10-13 19:42:53 -0700603 page = init_inode_metadata(inode, dir, NULL, NULL);
Jaegeuk Kimb97a9b52014-06-20 21:37:02 -0700604 if (IS_ERR(page)) {
605 err = PTR_ERR(page);
606 goto fail;
607 }
608 /* we don't need to mark_inode_dirty now */
609 update_inode(inode, page);
610 f2fs_put_page(page, 1);
611
612 clear_inode_flag(F2FS_I(inode), FI_NEW_INODE);
613fail:
614 up_write(&F2FS_I(inode)->i_sem);
615 return err;
616}
617
Chao Yudbeacf02014-09-24 18:17:04 +0800618void f2fs_drop_nlink(struct inode *dir, struct inode *inode, struct page *page)
619{
620 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
621
622 down_write(&F2FS_I(inode)->i_sem);
623
624 if (S_ISDIR(inode->i_mode)) {
625 drop_nlink(dir);
626 if (page)
627 update_inode(dir, page);
628 else
629 update_inode_page(dir);
630 }
631 inode->i_ctime = CURRENT_TIME;
632
633 drop_nlink(inode);
634 if (S_ISDIR(inode->i_mode)) {
635 drop_nlink(inode);
636 i_size_write(inode, 0);
637 }
638 up_write(&F2FS_I(inode)->i_sem);
639 update_inode_page(inode);
640
641 if (inode->i_nlink == 0)
642 add_orphan_inode(sbi, inode->i_ino);
643 else
644 release_orphan_inode(sbi);
645}
646
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +0900647/*
arter97e1c42042014-08-06 23:22:50 +0900648 * It only removes the dentry from the dentry page, corresponding name
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900649 * entry in name page does not need to be touched during deletion.
650 */
651void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
Chao Yudbeacf02014-09-24 18:17:04 +0800652 struct inode *dir, struct inode *inode)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900653{
654 struct f2fs_dentry_block *dentry_blk;
655 unsigned int bit_pos;
Namjae Jeon457d08e2012-12-08 14:54:50 +0900656 int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len));
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900657 int i;
658
Chao Yu622f28a2014-09-24 18:19:10 +0800659 if (f2fs_has_inline_dentry(dir))
660 return f2fs_delete_inline_entry(dentry, page, dir, inode);
661
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900662 lock_page(page);
Jaegeuk Kim3cb5ad12014-03-18 13:29:07 +0900663 f2fs_wait_on_page_writeback(page, DATA);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900664
Gu Zheng1c3bb972014-06-27 17:57:04 +0800665 dentry_blk = page_address(page);
666 bit_pos = dentry - dentry_blk->dentry;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900667 for (i = 0; i < slots; i++)
Jan Kara1f7732f2014-10-23 14:40:20 +0200668 clear_bit_le(bit_pos + i, &dentry_blk->dentry_bitmap);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900669
670 /* Let's check and deallocate this dentry page */
671 bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap,
672 NR_DENTRY_IN_BLOCK,
673 0);
674 kunmap(page); /* kunmap - pair of f2fs_find_entry */
675 set_page_dirty(page);
676
677 dir->i_ctime = dir->i_mtime = CURRENT_TIME;
678
Chao Yudbeacf02014-09-24 18:17:04 +0800679 if (inode)
680 f2fs_drop_nlink(dir, inode, NULL);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900681
682 if (bit_pos == NR_DENTRY_IN_BLOCK) {
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900683 truncate_hole(dir, page->index, page->index + 1);
684 clear_page_dirty_for_io(page);
Jaegeuk Kim2bca1e22015-02-25 19:25:01 -0800685 ClearPagePrivate(page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900686 ClearPageUptodate(page);
Jaegeuk Kima7ffdbe2014-09-12 15:53:45 -0700687 inode_dec_dirty_pages(dir);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900688 }
Namjae Jeon508198b2012-12-08 14:54:35 +0900689 f2fs_put_page(page, 1);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900690}
691
692bool f2fs_empty_dir(struct inode *dir)
693{
694 unsigned long bidx;
695 struct page *dentry_page;
696 unsigned int bit_pos;
Chao Yudbeacf02014-09-24 18:17:04 +0800697 struct f2fs_dentry_block *dentry_blk;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900698 unsigned long nblock = dir_blocks(dir);
699
Chao Yu622f28a2014-09-24 18:19:10 +0800700 if (f2fs_has_inline_dentry(dir))
701 return f2fs_empty_inline_dir(dir);
702
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900703 for (bidx = 0; bidx < nblock; bidx++) {
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900704 dentry_page = get_lock_data_page(dir, bidx);
705 if (IS_ERR(dentry_page)) {
706 if (PTR_ERR(dentry_page) == -ENOENT)
707 continue;
708 else
709 return false;
710 }
711
Gu Zheng1c3bb972014-06-27 17:57:04 +0800712 dentry_blk = kmap_atomic(dentry_page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900713 if (bidx == 0)
714 bit_pos = 2;
715 else
716 bit_pos = 0;
717 bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap,
718 NR_DENTRY_IN_BLOCK,
719 bit_pos);
Gu Zheng1c3bb972014-06-27 17:57:04 +0800720 kunmap_atomic(dentry_blk);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900721
722 f2fs_put_page(dentry_page, 1);
723
724 if (bit_pos < NR_DENTRY_IN_BLOCK)
725 return false;
726 }
727 return true;
728}
729
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700730bool f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
731 unsigned int start_pos)
Jaegeuk Kim38594de2014-10-15 21:29:51 -0700732{
733 unsigned char d_type = DT_UNKNOWN;
734 unsigned int bit_pos;
735 struct f2fs_dir_entry *de = NULL;
736
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700737 bit_pos = ((unsigned long)ctx->pos % d->max);
Jaegeuk Kim38594de2014-10-15 21:29:51 -0700738
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700739 while (bit_pos < d->max) {
740 bit_pos = find_next_bit_le(d->bitmap, d->max, bit_pos);
741 if (bit_pos >= d->max)
Jaegeuk Kim38594de2014-10-15 21:29:51 -0700742 break;
743
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700744 de = &d->dentry[bit_pos];
Jaegeuk Kim38594de2014-10-15 21:29:51 -0700745 if (de->file_type < F2FS_FT_MAX)
746 d_type = f2fs_filetype_table[de->file_type];
747 else
748 d_type = DT_UNKNOWN;
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700749 if (!dir_emit(ctx, d->filename[bit_pos],
Jaegeuk Kim38594de2014-10-15 21:29:51 -0700750 le16_to_cpu(de->name_len),
751 le32_to_cpu(de->ino), d_type))
752 return true;
753
754 bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
755 ctx->pos = start_pos + bit_pos;
756 }
757 return false;
758}
759
Al Viro6f7f2312013-05-17 18:02:17 -0400760static int f2fs_readdir(struct file *file, struct dir_context *ctx)
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900761{
Al Viro496ad9a2013-01-23 17:07:38 -0500762 struct inode *inode = file_inode(file);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900763 unsigned long npages = dir_blocks(inode);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900764 struct f2fs_dentry_block *dentry_blk = NULL;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900765 struct page *dentry_page = NULL;
Chao Yu817202d92014-04-28 17:59:43 +0800766 struct file_ra_state *ra = &file->f_ra;
Al Viro6f7f2312013-05-17 18:02:17 -0400767 unsigned int n = ((unsigned long)ctx->pos / NR_DENTRY_IN_BLOCK);
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700768 struct f2fs_dentry_ptr d;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900769
Chao Yu622f28a2014-09-24 18:19:10 +0800770 if (f2fs_has_inline_dentry(inode))
771 return f2fs_read_inline_dir(file, ctx);
772
Chao Yu817202d92014-04-28 17:59:43 +0800773 /* readahead for multi pages of dir */
774 if (npages - n > 1 && !ra_has_index(ra, n))
775 page_cache_sync_readahead(inode->i_mapping, ra, file, n,
776 min(npages - n, (pgoff_t)MAX_DIR_RA_PAGES));
777
Chris Fries6c311ec2014-01-17 14:44:39 -0600778 for (; n < npages; n++) {
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900779 dentry_page = get_lock_data_page(inode, n);
780 if (IS_ERR(dentry_page))
781 continue;
782
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900783 dentry_blk = kmap(dentry_page);
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900784
Jaegeuk Kim7b3cd7d2014-10-18 22:52:52 -0700785 make_dentry_ptr(&d, (void *)dentry_blk, 1);
786
787 if (f2fs_fill_dentries(ctx, &d, n * NR_DENTRY_IN_BLOCK))
Jaegeuk Kim38594de2014-10-15 21:29:51 -0700788 goto stop;
Jaegeuk Kim99b072bb2013-07-05 17:28:12 +0900789
Al Viro6f7f2312013-05-17 18:02:17 -0400790 ctx->pos = (n + 1) * NR_DENTRY_IN_BLOCK;
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900791 kunmap(dentry_page);
792 f2fs_put_page(dentry_page, 1);
793 dentry_page = NULL;
794 }
Jaegeuk Kim99b072bb2013-07-05 17:28:12 +0900795stop:
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900796 if (dentry_page && !IS_ERR(dentry_page)) {
797 kunmap(dentry_page);
798 f2fs_put_page(dentry_page, 1);
799 }
800
801 return 0;
802}
803
804const struct file_operations f2fs_dir_operations = {
805 .llseek = generic_file_llseek,
806 .read = generic_read_dir,
Al Viro6f7f2312013-05-17 18:02:17 -0400807 .iterate = f2fs_readdir,
Jaegeuk Kim6b4ea012012-11-14 16:59:04 +0900808 .fsync = f2fs_sync_file,
809 .unlocked_ioctl = f2fs_ioctl,
810};