1 /*
2 * fs/f2fs/inline.c
3 * Copyright (c) 2013, Intel Corporation
4 * Authors: Huajun Li <huajun.li@intel.com>
5 * Haicheng Li <haicheng.li@intel.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11 #include <linux/fs.h>
12 #include <linux/f2fs_fs.h>
13 #include <trace/events/android_fs.h>
14
15 #include "f2fs.h"
16 #include "node.h"
17
f2fs_may_inline_data(struct inode * inode)18 bool f2fs_may_inline_data(struct inode *inode)
19 {
20 if (f2fs_is_atomic_file(inode))
21 return false;
22
23 if (!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode))
24 return false;
25
26 if (i_size_read(inode) > MAX_INLINE_DATA(inode))
27 return false;
28
29 if (f2fs_encrypted_file(inode))
30 return false;
31
32 return true;
33 }
34
f2fs_may_inline_dentry(struct inode * inode)35 bool f2fs_may_inline_dentry(struct inode *inode)
36 {
37 if (!test_opt(F2FS_I_SB(inode), INLINE_DENTRY))
38 return false;
39
40 if (!S_ISDIR(inode->i_mode))
41 return false;
42
43 return true;
44 }
45
read_inline_data(struct page * page,struct page * ipage)46 void read_inline_data(struct page *page, struct page *ipage)
47 {
48 struct inode *inode = page->mapping->host;
49 void *src_addr, *dst_addr;
50
51 if (PageUptodate(page))
52 return;
53
54 f2fs_bug_on(F2FS_P_SB(page), page->index);
55
56 zero_user_segment(page, MAX_INLINE_DATA(inode), PAGE_SIZE);
57
58 /* Copy the whole inline data block */
59 src_addr = inline_data_addr(inode, ipage);
60 dst_addr = kmap_atomic(page);
61 memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
62 flush_dcache_page(page);
63 kunmap_atomic(dst_addr);
64 if (!PageUptodate(page))
65 SetPageUptodate(page);
66 }
67
truncate_inline_inode(struct inode * inode,struct page * ipage,u64 from)68 void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from)
69 {
70 void *addr;
71
72 if (from >= MAX_INLINE_DATA(inode))
73 return;
74
75 addr = inline_data_addr(inode, ipage);
76
77 f2fs_wait_on_page_writeback(ipage, NODE, true);
78 memset(addr + from, 0, MAX_INLINE_DATA(inode) - from);
79 set_page_dirty(ipage);
80
81 if (from == 0)
82 clear_inode_flag(inode, FI_DATA_EXIST);
83 }
84
f2fs_read_inline_data(struct inode * inode,struct page * page)85 int f2fs_read_inline_data(struct inode *inode, struct page *page)
86 {
87 struct page *ipage;
88
89 if (trace_android_fs_dataread_start_enabled()) {
90 char *path, pathbuf[MAX_TRACE_PATHBUF_LEN];
91
92 path = android_fstrace_get_pathname(pathbuf,
93 MAX_TRACE_PATHBUF_LEN,
94 page->mapping->host);
95 trace_android_fs_dataread_start(page->mapping->host,
96 page_offset(page),
97 PAGE_SIZE, current->pid,
98 path, current->comm);
99 }
100
101 ipage = get_node_page(F2FS_I_SB(inode), inode->i_ino);
102 if (IS_ERR(ipage)) {
103 trace_android_fs_dataread_end(inode, page_offset(page),
104 PAGE_SIZE);
105 unlock_page(page);
106 return PTR_ERR(ipage);
107 }
108
109 if (!f2fs_has_inline_data(inode)) {
110 f2fs_put_page(ipage, 1);
111 return -EAGAIN;
112 }
113
114 if (page->index)
115 zero_user_segment(page, 0, PAGE_SIZE);
116 else
117 read_inline_data(page, ipage);
118
119 if (!PageUptodate(page))
120 SetPageUptodate(page);
121
122 f2fs_put_page(ipage, 1);
123
124 trace_android_fs_dataread_end(inode, page_offset(page), PAGE_SIZE);
125 unlock_page(page);
126 return 0;
127 }
128
f2fs_convert_inline_page(struct dnode_of_data * dn,struct page * page)129 int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page)
130 {
131 struct f2fs_io_info fio = {
132 .sbi = F2FS_I_SB(dn->inode),
133 .ino = dn->inode->i_ino,
134 .type = DATA,
135 .op = REQ_OP_WRITE,
136 .op_flags = REQ_SYNC | REQ_PRIO,
137 .page = page,
138 .encrypted_page = NULL,
139 .io_type = FS_DATA_IO,
140 };
141 int dirty, err;
142
143 if (!f2fs_exist_data(dn->inode))
144 goto clear_out;
145
146 err = f2fs_reserve_block(dn, 0);
147 if (err)
148 return err;
149
150 f2fs_bug_on(F2FS_P_SB(page), PageWriteback(page));
151
152 read_inline_data(page, dn->inode_page);
153 set_page_dirty(page);
154
155 /* clear dirty state */
156 dirty = clear_page_dirty_for_io(page);
157
158 /* write data page to try to make data consistent */
159 set_page_writeback(page);
160 fio.old_blkaddr = dn->data_blkaddr;
161 set_inode_flag(dn->inode, FI_HOT_DATA);
162 write_data_page(dn, &fio);
163 f2fs_wait_on_page_writeback(page, DATA, true);
164 if (dirty) {
165 inode_dec_dirty_pages(dn->inode);
166 remove_dirty_inode(dn->inode);
167 }
168
169 /* this converted inline_data should be recovered. */
170 set_inode_flag(dn->inode, FI_APPEND_WRITE);
171
172 /* clear inline data and flag after data writeback */
173 truncate_inline_inode(dn->inode, dn->inode_page, 0);
174 clear_inline_node(dn->inode_page);
175 clear_out:
176 stat_dec_inline_inode(dn->inode);
177 clear_inode_flag(dn->inode, FI_INLINE_DATA);
178 f2fs_put_dnode(dn);
179 return 0;
180 }
181
f2fs_convert_inline_inode(struct inode * inode)182 int f2fs_convert_inline_inode(struct inode *inode)
183 {
184 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
185 struct dnode_of_data dn;
186 struct page *ipage, *page;
187 int err = 0;
188
189 if (!f2fs_has_inline_data(inode))
190 return 0;
191
192 page = f2fs_grab_cache_page(inode->i_mapping, 0, false);
193 if (!page)
194 return -ENOMEM;
195
196 f2fs_lock_op(sbi);
197
198 ipage = get_node_page(sbi, inode->i_ino);
199 if (IS_ERR(ipage)) {
200 err = PTR_ERR(ipage);
201 goto out;
202 }
203
204 set_new_dnode(&dn, inode, ipage, ipage, 0);
205
206 if (f2fs_has_inline_data(inode))
207 err = f2fs_convert_inline_page(&dn, page);
208
209 f2fs_put_dnode(&dn);
210 out:
211 f2fs_unlock_op(sbi);
212
213 f2fs_put_page(page, 1);
214
215 f2fs_balance_fs(sbi, dn.node_changed);
216
217 return err;
218 }
219
f2fs_write_inline_data(struct inode * inode,struct page * page)220 int f2fs_write_inline_data(struct inode *inode, struct page *page)
221 {
222 void *src_addr, *dst_addr;
223 struct dnode_of_data dn;
224 struct address_space *mapping = page_mapping(page);
225 unsigned long flags;
226 int err;
227
228 set_new_dnode(&dn, inode, NULL, NULL, 0);
229 err = get_dnode_of_data(&dn, 0, LOOKUP_NODE);
230 if (err)
231 return err;
232
233 if (!f2fs_has_inline_data(inode)) {
234 f2fs_put_dnode(&dn);
235 return -EAGAIN;
236 }
237
238 f2fs_bug_on(F2FS_I_SB(inode), page->index);
239
240 f2fs_wait_on_page_writeback(dn.inode_page, NODE, true);
241 src_addr = kmap_atomic(page);
242 dst_addr = inline_data_addr(inode, dn.inode_page);
243 memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
244 kunmap_atomic(src_addr);
245 set_page_dirty(dn.inode_page);
246
247 spin_lock_irqsave(&mapping->tree_lock, flags);
248 radix_tree_tag_clear(&mapping->page_tree, page_index(page),
249 PAGECACHE_TAG_DIRTY);
250 spin_unlock_irqrestore(&mapping->tree_lock, flags);
251
252 set_inode_flag(inode, FI_APPEND_WRITE);
253 set_inode_flag(inode, FI_DATA_EXIST);
254
255 clear_inline_node(dn.inode_page);
256 f2fs_put_dnode(&dn);
257 return 0;
258 }
259
recover_inline_data(struct inode * inode,struct page * npage)260 bool recover_inline_data(struct inode *inode, struct page *npage)
261 {
262 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
263 struct f2fs_inode *ri = NULL;
264 void *src_addr, *dst_addr;
265 struct page *ipage;
266
267 /*
268 * The inline_data recovery policy is as follows.
269 * [prev.] [next] of inline_data flag
270 * o o -> recover inline_data
271 * o x -> remove inline_data, and then recover data blocks
272 * x o -> remove inline_data, and then recover inline_data
273 * x x -> recover data blocks
274 */
275 if (IS_INODE(npage))
276 ri = F2FS_INODE(npage);
277
278 if (f2fs_has_inline_data(inode) &&
279 ri && (ri->i_inline & F2FS_INLINE_DATA)) {
280 process_inline:
281 ipage = get_node_page(sbi, inode->i_ino);
282 f2fs_bug_on(sbi, IS_ERR(ipage));
283
284 f2fs_wait_on_page_writeback(ipage, NODE, true);
285
286 src_addr = inline_data_addr(inode, npage);
287 dst_addr = inline_data_addr(inode, ipage);
288 memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
289
290 set_inode_flag(inode, FI_INLINE_DATA);
291 set_inode_flag(inode, FI_DATA_EXIST);
292
293 set_page_dirty(ipage);
294 f2fs_put_page(ipage, 1);
295 return true;
296 }
297
298 if (f2fs_has_inline_data(inode)) {
299 ipage = get_node_page(sbi, inode->i_ino);
300 f2fs_bug_on(sbi, IS_ERR(ipage));
301 truncate_inline_inode(inode, ipage, 0);
302 clear_inode_flag(inode, FI_INLINE_DATA);
303 f2fs_put_page(ipage, 1);
304 } else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) {
305 if (truncate_blocks(inode, 0, false))
306 return false;
307 goto process_inline;
308 }
309 return false;
310 }
311
find_in_inline_dir(struct inode * dir,struct fscrypt_name * fname,struct page ** res_page)312 struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir,
313 struct fscrypt_name *fname, struct page **res_page)
314 {
315 struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
316 struct qstr name = FSTR_TO_QSTR(&fname->disk_name);
317 struct f2fs_dir_entry *de;
318 struct f2fs_dentry_ptr d;
319 struct page *ipage;
320 void *inline_dentry;
321 f2fs_hash_t namehash;
322
323 ipage = get_node_page(sbi, dir->i_ino);
324 if (IS_ERR(ipage)) {
325 *res_page = ipage;
326 return NULL;
327 }
328
329 namehash = f2fs_dentry_hash(&name, fname);
330
331 inline_dentry = inline_data_addr(dir, ipage);
332
333 make_dentry_ptr_inline(dir, &d, inline_dentry);
334 de = find_target_dentry(fname, namehash, NULL, &d);
335 unlock_page(ipage);
336 if (de)
337 *res_page = ipage;
338 else
339 f2fs_put_page(ipage, 0);
340
341 return de;
342 }
343
make_empty_inline_dir(struct inode * inode,struct inode * parent,struct page * ipage)344 int make_empty_inline_dir(struct inode *inode, struct inode *parent,
345 struct page *ipage)
346 {
347 struct f2fs_dentry_ptr d;
348 void *inline_dentry;
349
350 inline_dentry = inline_data_addr(inode, ipage);
351
352 make_dentry_ptr_inline(inode, &d, inline_dentry);
353 do_make_empty_dir(inode, parent, &d);
354
355 set_page_dirty(ipage);
356
357 /* update i_size to MAX_INLINE_DATA */
358 if (i_size_read(inode) < MAX_INLINE_DATA(inode))
359 f2fs_i_size_write(inode, MAX_INLINE_DATA(inode));
360 return 0;
361 }
362
363 /*
364 * NOTE: ipage is grabbed by caller, but if any error occurs, we should
365 * release ipage in this function.
366 */
f2fs_move_inline_dirents(struct inode * dir,struct page * ipage,void * inline_dentry)367 static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage,
368 void *inline_dentry)
369 {
370 struct page *page;
371 struct dnode_of_data dn;
372 struct f2fs_dentry_block *dentry_blk;
373 struct f2fs_dentry_ptr src, dst;
374 int err;
375
376 page = f2fs_grab_cache_page(dir->i_mapping, 0, false);
377 if (!page) {
378 f2fs_put_page(ipage, 1);
379 return -ENOMEM;
380 }
381
382 set_new_dnode(&dn, dir, ipage, NULL, 0);
383 err = f2fs_reserve_block(&dn, 0);
384 if (err)
385 goto out;
386
387 f2fs_wait_on_page_writeback(page, DATA, true);
388 zero_user_segment(page, MAX_INLINE_DATA(dir), PAGE_SIZE);
389
390 dentry_blk = kmap_atomic(page);
391
392 make_dentry_ptr_inline(dir, &src, inline_dentry);
393 make_dentry_ptr_block(dir, &dst, dentry_blk);
394
395 /* copy data from inline dentry block to new dentry block */
396 memcpy(dst.bitmap, src.bitmap, src.nr_bitmap);
397 memset(dst.bitmap + src.nr_bitmap, 0, dst.nr_bitmap - src.nr_bitmap);
398 /*
399 * we do not need to zero out remainder part of dentry and filename
400 * field, since we have used bitmap for marking the usage status of
401 * them, besides, we can also ignore copying/zeroing reserved space
402 * of dentry block, because them haven't been used so far.
403 */
404 memcpy(dst.dentry, src.dentry, SIZE_OF_DIR_ENTRY * src.max);
405 memcpy(dst.filename, src.filename, src.max * F2FS_SLOT_LEN);
406
407 kunmap_atomic(dentry_blk);
408 if (!PageUptodate(page))
409 SetPageUptodate(page);
410 set_page_dirty(page);
411
412 /* clear inline dir and flag after data writeback */
413 truncate_inline_inode(dir, ipage, 0);
414
415 stat_dec_inline_dir(dir);
416 clear_inode_flag(dir, FI_INLINE_DENTRY);
417
418 f2fs_i_depth_write(dir, 1);
419 if (i_size_read(dir) < PAGE_SIZE)
420 f2fs_i_size_write(dir, PAGE_SIZE);
421 out:
422 f2fs_put_page(page, 1);
423 return err;
424 }
425
f2fs_add_inline_entries(struct inode * dir,void * inline_dentry)426 static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry)
427 {
428 struct f2fs_dentry_ptr d;
429 unsigned long bit_pos = 0;
430 int err = 0;
431
432 make_dentry_ptr_inline(dir, &d, inline_dentry);
433
434 while (bit_pos < d.max) {
435 struct f2fs_dir_entry *de;
436 struct qstr new_name;
437 nid_t ino;
438 umode_t fake_mode;
439
440 if (!test_bit_le(bit_pos, d.bitmap)) {
441 bit_pos++;
442 continue;
443 }
444
445 de = &d.dentry[bit_pos];
446
447 if (unlikely(!de->name_len)) {
448 bit_pos++;
449 continue;
450 }
451
452 new_name.name = d.filename[bit_pos];
453 new_name.len = le16_to_cpu(de->name_len);
454
455 ino = le32_to_cpu(de->ino);
456 fake_mode = get_de_type(de) << S_SHIFT;
457
458 err = f2fs_add_regular_entry(dir, &new_name, NULL, NULL,
459 ino, fake_mode);
460 if (err)
461 goto punch_dentry_pages;
462
463 bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
464 }
465 return 0;
466 punch_dentry_pages:
467 truncate_inode_pages(&dir->i_data, 0);
468 truncate_blocks(dir, 0, false);
469 remove_dirty_inode(dir);
470 return err;
471 }
472
f2fs_move_rehashed_dirents(struct inode * dir,struct page * ipage,void * inline_dentry)473 static int f2fs_move_rehashed_dirents(struct inode *dir, struct page *ipage,
474 void *inline_dentry)
475 {
476 void *backup_dentry;
477 int err;
478
479 backup_dentry = f2fs_kmalloc(F2FS_I_SB(dir),
480 MAX_INLINE_DATA(dir), GFP_F2FS_ZERO);
481 if (!backup_dentry) {
482 f2fs_put_page(ipage, 1);
483 return -ENOMEM;
484 }
485
486 memcpy(backup_dentry, inline_dentry, MAX_INLINE_DATA(dir));
487 truncate_inline_inode(dir, ipage, 0);
488
489 unlock_page(ipage);
490
491 err = f2fs_add_inline_entries(dir, backup_dentry);
492 if (err)
493 goto recover;
494
495 lock_page(ipage);
496
497 stat_dec_inline_dir(dir);
498 clear_inode_flag(dir, FI_INLINE_DENTRY);
499 kfree(backup_dentry);
500 return 0;
501 recover:
502 lock_page(ipage);
503 memcpy(inline_dentry, backup_dentry, MAX_INLINE_DATA(dir));
504 f2fs_i_depth_write(dir, 0);
505 f2fs_i_size_write(dir, MAX_INLINE_DATA(dir));
506 set_page_dirty(ipage);
507 f2fs_put_page(ipage, 1);
508
509 kfree(backup_dentry);
510 return err;
511 }
512
f2fs_convert_inline_dir(struct inode * dir,struct page * ipage,void * inline_dentry)513 static int f2fs_convert_inline_dir(struct inode *dir, struct page *ipage,
514 void *inline_dentry)
515 {
516 if (!F2FS_I(dir)->i_dir_level)
517 return f2fs_move_inline_dirents(dir, ipage, inline_dentry);
518 else
519 return f2fs_move_rehashed_dirents(dir, ipage, inline_dentry);
520 }
521
f2fs_add_inline_entry(struct inode * dir,const struct qstr * new_name,const struct qstr * orig_name,struct inode * inode,nid_t ino,umode_t mode)522 int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name,
523 const struct qstr *orig_name,
524 struct inode *inode, nid_t ino, umode_t mode)
525 {
526 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
527 struct page *ipage;
528 unsigned int bit_pos;
529 f2fs_hash_t name_hash;
530 void *inline_dentry = NULL;
531 struct f2fs_dentry_ptr d;
532 int slots = GET_DENTRY_SLOTS(new_name->len);
533 struct page *page = NULL;
534 int err = 0;
535
536 ipage = get_node_page(sbi, dir->i_ino);
537 if (IS_ERR(ipage))
538 return PTR_ERR(ipage);
539
540 inline_dentry = inline_data_addr(dir, ipage);
541 make_dentry_ptr_inline(dir, &d, inline_dentry);
542
543 bit_pos = room_for_filename(d.bitmap, slots, d.max);
544 if (bit_pos >= d.max) {
545 err = f2fs_convert_inline_dir(dir, ipage, inline_dentry);
546 if (err)
547 return err;
548 err = -EAGAIN;
549 goto out;
550 }
551
552 if (inode) {
553 down_write(&F2FS_I(inode)->i_sem);
554 page = init_inode_metadata(inode, dir, new_name,
555 orig_name, ipage);
556 if (IS_ERR(page)) {
557 err = PTR_ERR(page);
558 goto fail;
559 }
560 }
561
562 f2fs_wait_on_page_writeback(ipage, NODE, true);
563
564 name_hash = f2fs_dentry_hash(new_name, NULL);
565 f2fs_update_dentry(ino, mode, &d, new_name, name_hash, bit_pos);
566
567 set_page_dirty(ipage);
568
569 /* we don't need to mark_inode_dirty now */
570 if (inode) {
571 f2fs_i_pino_write(inode, dir->i_ino);
572 f2fs_put_page(page, 1);
573 }
574
575 update_parent_metadata(dir, inode, 0);
576 fail:
577 if (inode)
578 up_write(&F2FS_I(inode)->i_sem);
579 out:
580 f2fs_put_page(ipage, 1);
581 return err;
582 }
583
f2fs_delete_inline_entry(struct f2fs_dir_entry * dentry,struct page * page,struct inode * dir,struct inode * inode)584 void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page,
585 struct inode *dir, struct inode *inode)
586 {
587 struct f2fs_dentry_ptr d;
588 void *inline_dentry;
589 int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len));
590 unsigned int bit_pos;
591 int i;
592
593 lock_page(page);
594 f2fs_wait_on_page_writeback(page, NODE, true);
595
596 inline_dentry = inline_data_addr(dir, page);
597 make_dentry_ptr_inline(dir, &d, inline_dentry);
598
599 bit_pos = dentry - d.dentry;
600 for (i = 0; i < slots; i++)
601 __clear_bit_le(bit_pos + i, d.bitmap);
602
603 set_page_dirty(page);
604 f2fs_put_page(page, 1);
605
606 dir->i_ctime = dir->i_mtime = current_time(dir);
607 f2fs_mark_inode_dirty_sync(dir, false);
608
609 if (inode)
610 f2fs_drop_nlink(dir, inode);
611 }
612
f2fs_empty_inline_dir(struct inode * dir)613 bool f2fs_empty_inline_dir(struct inode *dir)
614 {
615 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
616 struct page *ipage;
617 unsigned int bit_pos = 2;
618 void *inline_dentry;
619 struct f2fs_dentry_ptr d;
620
621 ipage = get_node_page(sbi, dir->i_ino);
622 if (IS_ERR(ipage))
623 return false;
624
625 inline_dentry = inline_data_addr(dir, ipage);
626 make_dentry_ptr_inline(dir, &d, inline_dentry);
627
628 bit_pos = find_next_bit_le(d.bitmap, d.max, bit_pos);
629
630 f2fs_put_page(ipage, 1);
631
632 if (bit_pos < d.max)
633 return false;
634
635 return true;
636 }
637
f2fs_read_inline_dir(struct file * file,struct dir_context * ctx,struct fscrypt_str * fstr)638 int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
639 struct fscrypt_str *fstr)
640 {
641 struct inode *inode = file_inode(file);
642 struct page *ipage = NULL;
643 struct f2fs_dentry_ptr d;
644 void *inline_dentry = NULL;
645 int err;
646
647 make_dentry_ptr_inline(inode, &d, inline_dentry);
648
649 if (ctx->pos == d.max)
650 return 0;
651
652 ipage = get_node_page(F2FS_I_SB(inode), inode->i_ino);
653 if (IS_ERR(ipage))
654 return PTR_ERR(ipage);
655
656 inline_dentry = inline_data_addr(inode, ipage);
657
658 make_dentry_ptr_inline(inode, &d, inline_dentry);
659
660 err = f2fs_fill_dentries(ctx, &d, 0, fstr);
661 if (!err)
662 ctx->pos = d.max;
663
664 f2fs_put_page(ipage, 1);
665 return err < 0 ? err : 0;
666 }
667
f2fs_inline_data_fiemap(struct inode * inode,struct fiemap_extent_info * fieinfo,__u64 start,__u64 len)668 int f2fs_inline_data_fiemap(struct inode *inode,
669 struct fiemap_extent_info *fieinfo, __u64 start, __u64 len)
670 {
671 __u64 byteaddr, ilen;
672 __u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED |
673 FIEMAP_EXTENT_LAST;
674 struct node_info ni;
675 struct page *ipage;
676 int err = 0;
677
678 ipage = get_node_page(F2FS_I_SB(inode), inode->i_ino);
679 if (IS_ERR(ipage))
680 return PTR_ERR(ipage);
681
682 if (!f2fs_has_inline_data(inode)) {
683 err = -EAGAIN;
684 goto out;
685 }
686
687 ilen = min_t(size_t, MAX_INLINE_DATA(inode), i_size_read(inode));
688 if (start >= ilen)
689 goto out;
690 if (start + len < ilen)
691 ilen = start + len;
692 ilen -= start;
693
694 get_node_info(F2FS_I_SB(inode), inode->i_ino, &ni);
695 byteaddr = (__u64)ni.blk_addr << inode->i_sb->s_blocksize_bits;
696 byteaddr += (char *)inline_data_addr(inode, ipage) -
697 (char *)F2FS_INODE(ipage);
698 err = fiemap_fill_next_extent(fieinfo, start, byteaddr, ilen, flags);
699 out:
700 f2fs_put_page(ipage, 1);
701 return err;
702 }
703