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 #include <linux/fiemap.h> 12 13 #include "f2fs.h" 14 #include "node.h" 15 16 bool f2fs_may_inline_data(struct inode *inode) 17 { 18 if (f2fs_is_atomic_file(inode)) 19 return false; 20 21 if (!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode)) 22 return false; 23 24 if (i_size_read(inode) > MAX_INLINE_DATA(inode)) 25 return false; 26 27 if (f2fs_post_read_required(inode)) 28 return false; 29 30 return true; 31 } 32 33 bool f2fs_may_inline_dentry(struct inode *inode) 34 { 35 if (!test_opt(F2FS_I_SB(inode), INLINE_DENTRY)) 36 return false; 37 38 if (!S_ISDIR(inode->i_mode)) 39 return false; 40 41 return true; 42 } 43 44 void f2fs_do_read_inline_data(struct page *page, struct page *ipage) 45 { 46 struct inode *inode = page->mapping->host; 47 void *src_addr, *dst_addr; 48 49 if (PageUptodate(page)) 50 return; 51 52 f2fs_bug_on(F2FS_P_SB(page), page->index); 53 54 zero_user_segment(page, MAX_INLINE_DATA(inode), PAGE_SIZE); 55 56 /* Copy the whole inline data block */ 57 src_addr = inline_data_addr(inode, ipage); 58 dst_addr = kmap_atomic(page); 59 memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode)); 60 flush_dcache_page(page); 61 kunmap_atomic(dst_addr); 62 if (!PageUptodate(page)) 63 SetPageUptodate(page); 64 } 65 66 void f2fs_truncate_inline_inode(struct inode *inode, 67 struct page *ipage, u64 from) 68 { 69 void *addr; 70 71 if (from >= MAX_INLINE_DATA(inode)) 72 return; 73 74 addr = inline_data_addr(inode, ipage); 75 76 f2fs_wait_on_page_writeback(ipage, NODE, true, true); 77 memset(addr + from, 0, MAX_INLINE_DATA(inode) - from); 78 set_page_dirty(ipage); 79 80 if (from == 0) 81 clear_inode_flag(inode, FI_DATA_EXIST); 82 } 83 84 int f2fs_read_inline_data(struct inode *inode, struct page *page) 85 { 86 struct page *ipage; 87 88 ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino); 89 if (IS_ERR(ipage)) { 90 unlock_page(page); 91 return PTR_ERR(ipage); 92 } 93 94 if (!f2fs_has_inline_data(inode)) { 95 f2fs_put_page(ipage, 1); 96 return -EAGAIN; 97 } 98 99 if (page->index) 100 zero_user_segment(page, 0, PAGE_SIZE); 101 else 102 f2fs_do_read_inline_data(page, ipage); 103 104 if (!PageUptodate(page)) 105 SetPageUptodate(page); 106 f2fs_put_page(ipage, 1); 107 unlock_page(page); 108 return 0; 109 } 110 111 int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page) 112 { 113 struct f2fs_io_info fio = { 114 .sbi = F2FS_I_SB(dn->inode), 115 .ino = dn->inode->i_ino, 116 .type = DATA, 117 .op = REQ_OP_WRITE, 118 .op_flags = REQ_SYNC | REQ_PRIO, 119 .page = page, 120 .encrypted_page = NULL, 121 .io_type = FS_DATA_IO, 122 }; 123 struct node_info ni; 124 int dirty, err; 125 126 if (!f2fs_exist_data(dn->inode)) 127 goto clear_out; 128 129 err = f2fs_reserve_block(dn, 0); 130 if (err) 131 return err; 132 133 err = f2fs_get_node_info(fio.sbi, dn->nid, &ni); 134 if (err) { 135 f2fs_truncate_data_blocks_range(dn, 1); 136 f2fs_put_dnode(dn); 137 return err; 138 } 139 140 fio.version = ni.version; 141 142 if (unlikely(dn->data_blkaddr != NEW_ADDR)) { 143 f2fs_put_dnode(dn); 144 set_sbi_flag(fio.sbi, SBI_NEED_FSCK); 145 f2fs_warn(fio.sbi, "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, run fsck to fix.", 146 __func__, dn->inode->i_ino, dn->data_blkaddr); 147 return -EFSCORRUPTED; 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 const struct f2fs_filename *fname, 310 struct page **res_page) 311 { 312 struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); 313 struct f2fs_dir_entry *de; 314 struct f2fs_dentry_ptr d; 315 struct page *ipage; 316 void *inline_dentry; 317 318 ipage = f2fs_get_node_page(sbi, dir->i_ino); 319 if (IS_ERR(ipage)) { 320 *res_page = ipage; 321 return NULL; 322 } 323 324 inline_dentry = inline_data_addr(dir, ipage); 325 326 make_dentry_ptr_inline(dir, &d, inline_dentry); 327 de = f2fs_find_target_dentry(&d, fname, NULL); 328 unlock_page(ipage); 329 if (de) 330 *res_page = ipage; 331 else 332 f2fs_put_page(ipage, 0); 333 334 return de; 335 } 336 337 int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent, 338 struct page *ipage) 339 { 340 struct f2fs_dentry_ptr d; 341 void *inline_dentry; 342 343 inline_dentry = inline_data_addr(inode, ipage); 344 345 make_dentry_ptr_inline(inode, &d, inline_dentry); 346 f2fs_do_make_empty_dir(inode, parent, &d); 347 348 set_page_dirty(ipage); 349 350 /* update i_size to MAX_INLINE_DATA */ 351 if (i_size_read(inode) < MAX_INLINE_DATA(inode)) 352 f2fs_i_size_write(inode, MAX_INLINE_DATA(inode)); 353 return 0; 354 } 355 356 /* 357 * NOTE: ipage is grabbed by caller, but if any error occurs, we should 358 * release ipage in this function. 359 */ 360 static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage, 361 void *inline_dentry) 362 { 363 struct page *page; 364 struct dnode_of_data dn; 365 struct f2fs_dentry_block *dentry_blk; 366 struct f2fs_dentry_ptr src, dst; 367 int err; 368 369 page = f2fs_grab_cache_page(dir->i_mapping, 0, true); 370 if (!page) { 371 f2fs_put_page(ipage, 1); 372 return -ENOMEM; 373 } 374 375 set_new_dnode(&dn, dir, ipage, NULL, 0); 376 err = f2fs_reserve_block(&dn, 0); 377 if (err) 378 goto out; 379 380 if (unlikely(dn.data_blkaddr != NEW_ADDR)) { 381 f2fs_put_dnode(&dn); 382 set_sbi_flag(F2FS_P_SB(page), SBI_NEED_FSCK); 383 f2fs_warn(F2FS_P_SB(page), "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, run fsck to fix.", 384 __func__, dir->i_ino, dn.data_blkaddr); 385 err = -EFSCORRUPTED; 386 goto out; 387 } 388 389 f2fs_wait_on_page_writeback(page, DATA, true, true); 390 391 dentry_blk = page_address(page); 392 393 make_dentry_ptr_inline(dir, &src, inline_dentry); 394 make_dentry_ptr_block(dir, &dst, dentry_blk); 395 396 /* copy data from inline dentry block to new dentry block */ 397 memcpy(dst.bitmap, src.bitmap, src.nr_bitmap); 398 memset(dst.bitmap + src.nr_bitmap, 0, dst.nr_bitmap - src.nr_bitmap); 399 /* 400 * we do not need to zero out remainder part of dentry and filename 401 * field, since we have used bitmap for marking the usage status of 402 * them, besides, we can also ignore copying/zeroing reserved space 403 * of dentry block, because them haven't been used so far. 404 */ 405 memcpy(dst.dentry, src.dentry, SIZE_OF_DIR_ENTRY * src.max); 406 memcpy(dst.filename, src.filename, src.max * F2FS_SLOT_LEN); 407 408 if (!PageUptodate(page)) 409 SetPageUptodate(page); 410 set_page_dirty(page); 411 412 /* clear inline dir and flag after data writeback */ 413 f2fs_truncate_inline_inode(dir, ipage, 0); 414 415 stat_dec_inline_dir(dir); 416 clear_inode_flag(dir, FI_INLINE_DENTRY); 417 418 /* 419 * should retrieve reserved space which was used to keep 420 * inline_dentry's structure for backward compatibility. 421 */ 422 if (!f2fs_sb_has_flexible_inline_xattr(F2FS_I_SB(dir)) && 423 !f2fs_has_inline_xattr(dir)) 424 F2FS_I(dir)->i_inline_xattr_size = 0; 425 426 f2fs_i_depth_write(dir, 1); 427 if (i_size_read(dir) < PAGE_SIZE) 428 f2fs_i_size_write(dir, PAGE_SIZE); 429 out: 430 f2fs_put_page(page, 1); 431 return err; 432 } 433 434 static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry) 435 { 436 struct f2fs_dentry_ptr d; 437 unsigned long bit_pos = 0; 438 int err = 0; 439 440 make_dentry_ptr_inline(dir, &d, inline_dentry); 441 442 while (bit_pos < d.max) { 443 struct f2fs_dir_entry *de; 444 struct f2fs_filename fname; 445 nid_t ino; 446 umode_t fake_mode; 447 448 if (!test_bit_le(bit_pos, d.bitmap)) { 449 bit_pos++; 450 continue; 451 } 452 453 de = &d.dentry[bit_pos]; 454 455 if (unlikely(!de->name_len)) { 456 bit_pos++; 457 continue; 458 } 459 460 /* 461 * We only need the disk_name and hash to move the dentry. 462 * We don't need the original or casefolded filenames. 463 */ 464 memset(&fname, 0, sizeof(fname)); 465 fname.disk_name.name = d.filename[bit_pos]; 466 fname.disk_name.len = le16_to_cpu(de->name_len); 467 fname.hash = de->hash_code; 468 469 ino = le32_to_cpu(de->ino); 470 fake_mode = f2fs_get_de_type(de) << S_SHIFT; 471 472 err = f2fs_add_regular_entry(dir, &fname, NULL, 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 do_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_try_convert_inline_dir(struct inode *dir, struct dentry *dentry) 546 { 547 struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 548 struct page *ipage; 549 struct f2fs_filename fname; 550 void *inline_dentry = NULL; 551 int err = 0; 552 553 if (!f2fs_has_inline_dentry(dir)) 554 return 0; 555 556 f2fs_lock_op(sbi); 557 558 err = f2fs_setup_filename(dir, &dentry->d_name, 0, &fname); 559 if (err) 560 goto out; 561 562 ipage = f2fs_get_node_page(sbi, dir->i_ino); 563 if (IS_ERR(ipage)) { 564 err = PTR_ERR(ipage); 565 goto out_fname; 566 } 567 568 if (f2fs_has_enough_room(dir, ipage, &fname)) { 569 f2fs_put_page(ipage, 1); 570 goto out_fname; 571 } 572 573 inline_dentry = inline_data_addr(dir, ipage); 574 575 err = do_convert_inline_dir(dir, ipage, inline_dentry); 576 if (!err) 577 f2fs_put_page(ipage, 1); 578 out_fname: 579 f2fs_free_filename(&fname); 580 out: 581 f2fs_unlock_op(sbi); 582 return err; 583 } 584 585 int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname, 586 struct inode *inode, nid_t ino, umode_t mode) 587 { 588 struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 589 struct page *ipage; 590 unsigned int bit_pos; 591 void *inline_dentry = NULL; 592 struct f2fs_dentry_ptr d; 593 int slots = GET_DENTRY_SLOTS(fname->disk_name.len); 594 struct page *page = NULL; 595 int err = 0; 596 597 ipage = f2fs_get_node_page(sbi, dir->i_ino); 598 if (IS_ERR(ipage)) 599 return PTR_ERR(ipage); 600 601 inline_dentry = inline_data_addr(dir, ipage); 602 make_dentry_ptr_inline(dir, &d, inline_dentry); 603 604 bit_pos = f2fs_room_for_filename(d.bitmap, slots, d.max); 605 if (bit_pos >= d.max) { 606 err = do_convert_inline_dir(dir, ipage, inline_dentry); 607 if (err) 608 return err; 609 err = -EAGAIN; 610 goto out; 611 } 612 613 if (inode) { 614 down_write(&F2FS_I(inode)->i_sem); 615 page = f2fs_init_inode_metadata(inode, dir, fname, ipage); 616 if (IS_ERR(page)) { 617 err = PTR_ERR(page); 618 goto fail; 619 } 620 } 621 622 f2fs_wait_on_page_writeback(ipage, NODE, true, true); 623 624 f2fs_update_dentry(ino, mode, &d, &fname->disk_name, fname->hash, 625 bit_pos); 626 627 set_page_dirty(ipage); 628 629 /* we don't need to mark_inode_dirty now */ 630 if (inode) { 631 f2fs_i_pino_write(inode, dir->i_ino); 632 633 /* synchronize inode page's data from inode cache */ 634 if (is_inode_flag_set(inode, FI_NEW_INODE)) 635 f2fs_update_inode(inode, page); 636 637 f2fs_put_page(page, 1); 638 } 639 640 f2fs_update_parent_metadata(dir, inode, 0); 641 fail: 642 if (inode) 643 up_write(&F2FS_I(inode)->i_sem); 644 out: 645 f2fs_put_page(ipage, 1); 646 return err; 647 } 648 649 void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 650 struct inode *dir, struct inode *inode) 651 { 652 struct f2fs_dentry_ptr d; 653 void *inline_dentry; 654 int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len)); 655 unsigned int bit_pos; 656 int i; 657 658 lock_page(page); 659 f2fs_wait_on_page_writeback(page, NODE, true, true); 660 661 inline_dentry = inline_data_addr(dir, page); 662 make_dentry_ptr_inline(dir, &d, inline_dentry); 663 664 bit_pos = dentry - d.dentry; 665 for (i = 0; i < slots; i++) 666 __clear_bit_le(bit_pos + i, d.bitmap); 667 668 set_page_dirty(page); 669 f2fs_put_page(page, 1); 670 671 dir->i_ctime = dir->i_mtime = current_time(dir); 672 f2fs_mark_inode_dirty_sync(dir, false); 673 674 if (inode) 675 f2fs_drop_nlink(dir, inode); 676 } 677 678 bool f2fs_empty_inline_dir(struct inode *dir) 679 { 680 struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 681 struct page *ipage; 682 unsigned int bit_pos = 2; 683 void *inline_dentry; 684 struct f2fs_dentry_ptr d; 685 686 ipage = f2fs_get_node_page(sbi, dir->i_ino); 687 if (IS_ERR(ipage)) 688 return false; 689 690 inline_dentry = inline_data_addr(dir, ipage); 691 make_dentry_ptr_inline(dir, &d, inline_dentry); 692 693 bit_pos = find_next_bit_le(d.bitmap, d.max, bit_pos); 694 695 f2fs_put_page(ipage, 1); 696 697 if (bit_pos < d.max) 698 return false; 699 700 return true; 701 } 702 703 int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 704 struct fscrypt_str *fstr) 705 { 706 struct inode *inode = file_inode(file); 707 struct page *ipage = NULL; 708 struct f2fs_dentry_ptr d; 709 void *inline_dentry = NULL; 710 int err; 711 712 make_dentry_ptr_inline(inode, &d, inline_dentry); 713 714 if (ctx->pos == d.max) 715 return 0; 716 717 ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino); 718 if (IS_ERR(ipage)) 719 return PTR_ERR(ipage); 720 721 /* 722 * f2fs_readdir was protected by inode.i_rwsem, it is safe to access 723 * ipage without page's lock held. 724 */ 725 unlock_page(ipage); 726 727 inline_dentry = inline_data_addr(inode, ipage); 728 729 make_dentry_ptr_inline(inode, &d, inline_dentry); 730 731 err = f2fs_fill_dentries(ctx, &d, 0, fstr); 732 if (!err) 733 ctx->pos = d.max; 734 735 f2fs_put_page(ipage, 0); 736 return err < 0 ? err : 0; 737 } 738 739 int f2fs_inline_data_fiemap(struct inode *inode, 740 struct fiemap_extent_info *fieinfo, __u64 start, __u64 len) 741 { 742 __u64 byteaddr, ilen; 743 __u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED | 744 FIEMAP_EXTENT_LAST; 745 struct node_info ni; 746 struct page *ipage; 747 int err = 0; 748 749 ipage = f2fs_get_node_page(F2FS_I_SB(inode), inode->i_ino); 750 if (IS_ERR(ipage)) 751 return PTR_ERR(ipage); 752 753 if ((S_ISREG(inode->i_mode) || S_ISLNK(inode->i_mode)) && 754 !f2fs_has_inline_data(inode)) { 755 err = -EAGAIN; 756 goto out; 757 } 758 759 if (S_ISDIR(inode->i_mode) && !f2fs_has_inline_dentry(inode)) { 760 err = -EAGAIN; 761 goto out; 762 } 763 764 ilen = min_t(size_t, MAX_INLINE_DATA(inode), i_size_read(inode)); 765 if (start >= ilen) 766 goto out; 767 if (start + len < ilen) 768 ilen = start + len; 769 ilen -= start; 770 771 err = f2fs_get_node_info(F2FS_I_SB(inode), inode->i_ino, &ni); 772 if (err) 773 goto out; 774 775 byteaddr = (__u64)ni.blk_addr << inode->i_sb->s_blocksize_bits; 776 byteaddr += (char *)inline_data_addr(inode, ipage) - 777 (char *)F2FS_INODE(ipage); 778 err = fiemap_fill_next_extent(fieinfo, start, byteaddr, ilen, flags); 779 out: 780 f2fs_put_page(ipage, 1); 781 return err; 782 } 783