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