inline.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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. #include <linux/fs.h>
  11. #include <linux/f2fs_fs.h>
  12. #include "f2fs.h"
  13. #include "node.h"
  14. bool f2fs_may_inline_data(struct inode *inode)
  15. {
  16. if (f2fs_is_atomic_file(inode))
  17. return false;
  18. if (!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode))
  19. return false;
  20. if (i_size_read(inode) > MAX_INLINE_DATA)
  21. return false;
  22. if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
  23. return false;
  24. return true;
  25. }
  26. bool f2fs_may_inline_dentry(struct inode *inode)
  27. {
  28. if (!test_opt(F2FS_I_SB(inode), INLINE_DENTRY))
  29. return false;
  30. if (!S_ISDIR(inode->i_mode))
  31. return false;
  32. return true;
  33. }
  34. void read_inline_data(struct page *page, struct page *ipage)
  35. {
  36. void *src_addr, *dst_addr;
  37. if (PageUptodate(page))
  38. return;
  39. f2fs_bug_on(F2FS_P_SB(page), page->index);
  40. zero_user_segment(page, MAX_INLINE_DATA, PAGE_SIZE);
  41. /* Copy the whole inline data block */
  42. src_addr = inline_data_addr(ipage);
  43. dst_addr = kmap_atomic(page);
  44. memcpy(dst_addr, src_addr, MAX_INLINE_DATA);
  45. flush_dcache_page(page);
  46. kunmap_atomic(dst_addr);
  47. if (!PageUptodate(page))
  48. SetPageUptodate(page);
  49. }
  50. bool truncate_inline_inode(struct page *ipage, u64 from)
  51. {
  52. void *addr;
  53. if (from >= MAX_INLINE_DATA)
  54. return false;
  55. addr = inline_data_addr(ipage);
  56. f2fs_wait_on_page_writeback(ipage, NODE, true);
  57. memset(addr + from, 0, MAX_INLINE_DATA - from);
  58. set_page_dirty(ipage);
  59. return true;
  60. }
  61. int f2fs_read_inline_data(struct inode *inode, struct page *page)
  62. {
  63. struct page *ipage;
  64. ipage = get_node_page(F2FS_I_SB(inode), inode->i_ino);
  65. if (IS_ERR(ipage)) {
  66. unlock_page(page);
  67. return PTR_ERR(ipage);
  68. }
  69. if (!f2fs_has_inline_data(inode)) {
  70. f2fs_put_page(ipage, 1);
  71. return -EAGAIN;
  72. }
  73. if (page->index)
  74. zero_user_segment(page, 0, PAGE_SIZE);
  75. else
  76. read_inline_data(page, ipage);
  77. if (!PageUptodate(page))
  78. SetPageUptodate(page);
  79. f2fs_put_page(ipage, 1);
  80. unlock_page(page);
  81. return 0;
  82. }
  83. int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page)
  84. {
  85. struct f2fs_io_info fio = {
  86. .sbi = F2FS_I_SB(dn->inode),
  87. .type = DATA,
  88. .rw = WRITE_SYNC | REQ_PRIO,
  89. .page = page,
  90. .encrypted_page = NULL,
  91. };
  92. int dirty, err;
  93. if (!f2fs_exist_data(dn->inode))
  94. goto clear_out;
  95. err = f2fs_reserve_block(dn, 0);
  96. if (err)
  97. return err;
  98. if (unlikely(dn->data_blkaddr != NEW_ADDR)) {
  99. f2fs_put_dnode(dn);
  100. set_sbi_flag(fio.sbi, SBI_NEED_FSCK);
  101. f2fs_msg(fio.sbi->sb, KERN_WARNING,
  102. "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, "
  103. "run fsck to fix.",
  104. __func__, dn->inode->i_ino, dn->data_blkaddr);
  105. return -EINVAL;
  106. }
  107. f2fs_bug_on(F2FS_P_SB(page), PageWriteback(page));
  108. read_inline_data(page, dn->inode_page);
  109. set_page_dirty(page);
  110. /* clear dirty state */
  111. dirty = clear_page_dirty_for_io(page);
  112. /* write data page to try to make data consistent */
  113. set_page_writeback(page);
  114. fio.old_blkaddr = dn->data_blkaddr;
  115. write_data_page(dn, &fio);
  116. f2fs_wait_on_page_writeback(page, DATA, true);
  117. if (dirty) {
  118. inode_dec_dirty_pages(dn->inode);
  119. remove_dirty_inode(dn->inode);
  120. }
  121. /* this converted inline_data should be recovered. */
  122. set_inode_flag(dn->inode, FI_APPEND_WRITE);
  123. /* clear inline data and flag after data writeback */
  124. truncate_inline_inode(dn->inode_page, 0);
  125. clear_inline_node(dn->inode_page);
  126. clear_out:
  127. stat_dec_inline_inode(dn->inode);
  128. f2fs_clear_inline_inode(dn->inode);
  129. f2fs_put_dnode(dn);
  130. return 0;
  131. }
  132. int f2fs_convert_inline_inode(struct inode *inode)
  133. {
  134. struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
  135. struct dnode_of_data dn;
  136. struct page *ipage, *page;
  137. int err = 0;
  138. if (!f2fs_has_inline_data(inode))
  139. return 0;
  140. page = f2fs_grab_cache_page(inode->i_mapping, 0, false);
  141. if (!page)
  142. return -ENOMEM;
  143. f2fs_lock_op(sbi);
  144. ipage = get_node_page(sbi, inode->i_ino);
  145. if (IS_ERR(ipage)) {
  146. err = PTR_ERR(ipage);
  147. goto out;
  148. }
  149. set_new_dnode(&dn, inode, ipage, ipage, 0);
  150. if (f2fs_has_inline_data(inode))
  151. err = f2fs_convert_inline_page(&dn, page);
  152. f2fs_put_dnode(&dn);
  153. out:
  154. f2fs_unlock_op(sbi);
  155. f2fs_put_page(page, 1);
  156. f2fs_balance_fs(sbi, dn.node_changed);
  157. return err;
  158. }
  159. int f2fs_write_inline_data(struct inode *inode, struct page *page)
  160. {
  161. void *src_addr, *dst_addr;
  162. struct dnode_of_data dn;
  163. int err;
  164. set_new_dnode(&dn, inode, NULL, NULL, 0);
  165. err = get_dnode_of_data(&dn, 0, LOOKUP_NODE);
  166. if (err)
  167. return err;
  168. if (!f2fs_has_inline_data(inode)) {
  169. f2fs_put_dnode(&dn);
  170. return -EAGAIN;
  171. }
  172. f2fs_bug_on(F2FS_I_SB(inode), page->index);
  173. f2fs_wait_on_page_writeback(dn.inode_page, NODE, true);
  174. src_addr = kmap_atomic(page);
  175. dst_addr = inline_data_addr(dn.inode_page);
  176. memcpy(dst_addr, src_addr, MAX_INLINE_DATA);
  177. kunmap_atomic(src_addr);
  178. set_page_dirty(dn.inode_page);
  179. set_inode_flag(inode, FI_APPEND_WRITE);
  180. set_inode_flag(inode, FI_DATA_EXIST);
  181. clear_inline_node(dn.inode_page);
  182. f2fs_put_dnode(&dn);
  183. return 0;
  184. }
  185. bool recover_inline_data(struct inode *inode, struct page *npage)
  186. {
  187. struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
  188. struct f2fs_inode *ri = NULL;
  189. void *src_addr, *dst_addr;
  190. struct page *ipage;
  191. /*
  192. * The inline_data recovery policy is as follows.
  193. * [prev.] [next] of inline_data flag
  194. * o o -> recover inline_data
  195. * o x -> remove inline_data, and then recover data blocks
  196. * x o -> remove inline_data, and then recover inline_data
  197. * x x -> recover data blocks
  198. */
  199. if (IS_INODE(npage))
  200. ri = F2FS_INODE(npage);
  201. if (f2fs_has_inline_data(inode) &&
  202. ri && (ri->i_inline & F2FS_INLINE_DATA)) {
  203. process_inline:
  204. ipage = get_node_page(sbi, inode->i_ino);
  205. f2fs_bug_on(sbi, IS_ERR(ipage));
  206. f2fs_wait_on_page_writeback(ipage, NODE, true);
  207. src_addr = inline_data_addr(npage);
  208. dst_addr = inline_data_addr(ipage);
  209. memcpy(dst_addr, src_addr, MAX_INLINE_DATA);
  210. set_inode_flag(inode, FI_INLINE_DATA);
  211. set_inode_flag(inode, FI_DATA_EXIST);
  212. set_page_dirty(ipage);
  213. f2fs_put_page(ipage, 1);
  214. return true;
  215. }
  216. if (f2fs_has_inline_data(inode)) {
  217. ipage = get_node_page(sbi, inode->i_ino);
  218. f2fs_bug_on(sbi, IS_ERR(ipage));
  219. if (!truncate_inline_inode(ipage, 0))
  220. return false;
  221. f2fs_clear_inline_inode(inode);
  222. f2fs_put_page(ipage, 1);
  223. } else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) {
  224. if (truncate_blocks(inode, 0, false))
  225. return false;
  226. goto process_inline;
  227. }
  228. return false;
  229. }
  230. struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir,
  231. struct fscrypt_name *fname, struct page **res_page)
  232. {
  233. struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
  234. struct f2fs_inline_dentry *inline_dentry;
  235. struct qstr name = FSTR_TO_QSTR(&fname->disk_name);
  236. struct f2fs_dir_entry *de;
  237. struct f2fs_dentry_ptr d;
  238. struct page *ipage;
  239. f2fs_hash_t namehash;
  240. ipage = get_node_page(sbi, dir->i_ino);
  241. if (IS_ERR(ipage)) {
  242. *res_page = ipage;
  243. return NULL;
  244. }
  245. namehash = f2fs_dentry_hash(&name);
  246. inline_dentry = inline_data_addr(ipage);
  247. make_dentry_ptr(NULL, &d, (void *)inline_dentry, 2);
  248. de = find_target_dentry(fname, namehash, NULL, &d);
  249. unlock_page(ipage);
  250. if (de)
  251. *res_page = ipage;
  252. else
  253. f2fs_put_page(ipage, 0);
  254. return de;
  255. }
  256. int make_empty_inline_dir(struct inode *inode, struct inode *parent,
  257. struct page *ipage)
  258. {
  259. struct f2fs_inline_dentry *dentry_blk;
  260. struct f2fs_dentry_ptr d;
  261. dentry_blk = inline_data_addr(ipage);
  262. make_dentry_ptr(NULL, &d, (void *)dentry_blk, 2);
  263. do_make_empty_dir(inode, parent, &d);
  264. set_page_dirty(ipage);
  265. /* update i_size to MAX_INLINE_DATA */
  266. if (i_size_read(inode) < MAX_INLINE_DATA)
  267. f2fs_i_size_write(inode, MAX_INLINE_DATA);
  268. return 0;
  269. }
  270. /*
  271. * NOTE: ipage is grabbed by caller, but if any error occurs, we should
  272. * release ipage in this function.
  273. */
  274. static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage,
  275. struct f2fs_inline_dentry *inline_dentry)
  276. {
  277. struct page *page;
  278. struct dnode_of_data dn;
  279. struct f2fs_dentry_block *dentry_blk;
  280. int err;
  281. page = f2fs_grab_cache_page(dir->i_mapping, 0, false);
  282. if (!page) {
  283. f2fs_put_page(ipage, 1);
  284. return -ENOMEM;
  285. }
  286. set_new_dnode(&dn, dir, ipage, NULL, 0);
  287. err = f2fs_reserve_block(&dn, 0);
  288. if (err)
  289. goto out;
  290. if (unlikely(dn.data_blkaddr != NEW_ADDR)) {
  291. f2fs_put_dnode(&dn);
  292. set_sbi_flag(F2FS_P_SB(page), SBI_NEED_FSCK);
  293. f2fs_msg(F2FS_P_SB(page)->sb, KERN_WARNING,
  294. "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, "
  295. "run fsck to fix.",
  296. __func__, dir->i_ino, dn.data_blkaddr);
  297. err = -EINVAL;
  298. goto out;
  299. }
  300. f2fs_wait_on_page_writeback(page, DATA, true);
  301. zero_user_segment(page, MAX_INLINE_DATA, PAGE_SIZE);
  302. dentry_blk = kmap_atomic(page);
  303. /* copy data from inline dentry block to new dentry block */
  304. memcpy(dentry_blk->dentry_bitmap, inline_dentry->dentry_bitmap,
  305. INLINE_DENTRY_BITMAP_SIZE);
  306. memset(dentry_blk->dentry_bitmap + INLINE_DENTRY_BITMAP_SIZE, 0,
  307. SIZE_OF_DENTRY_BITMAP - INLINE_DENTRY_BITMAP_SIZE);
  308. /*
  309. * we do not need to zero out remainder part of dentry and filename
  310. * field, since we have used bitmap for marking the usage status of
  311. * them, besides, we can also ignore copying/zeroing reserved space
  312. * of dentry block, because them haven't been used so far.
  313. */
  314. memcpy(dentry_blk->dentry, inline_dentry->dentry,
  315. sizeof(struct f2fs_dir_entry) * NR_INLINE_DENTRY);
  316. memcpy(dentry_blk->filename, inline_dentry->filename,
  317. NR_INLINE_DENTRY * F2FS_SLOT_LEN);
  318. kunmap_atomic(dentry_blk);
  319. if (!PageUptodate(page))
  320. SetPageUptodate(page);
  321. set_page_dirty(page);
  322. /* clear inline dir and flag after data writeback */
  323. truncate_inline_inode(ipage, 0);
  324. stat_dec_inline_dir(dir);
  325. clear_inode_flag(dir, FI_INLINE_DENTRY);
  326. f2fs_i_depth_write(dir, 1);
  327. if (i_size_read(dir) < PAGE_SIZE)
  328. f2fs_i_size_write(dir, PAGE_SIZE);
  329. out:
  330. f2fs_put_page(page, 1);
  331. return err;
  332. }
  333. static int f2fs_add_inline_entries(struct inode *dir,
  334. struct f2fs_inline_dentry *inline_dentry)
  335. {
  336. struct f2fs_dentry_ptr d;
  337. unsigned long bit_pos = 0;
  338. int err = 0;
  339. make_dentry_ptr(NULL, &d, (void *)inline_dentry, 2);
  340. while (bit_pos < d.max) {
  341. struct f2fs_dir_entry *de;
  342. struct qstr new_name;
  343. nid_t ino;
  344. umode_t fake_mode;
  345. if (!test_bit_le(bit_pos, d.bitmap)) {
  346. bit_pos++;
  347. continue;
  348. }
  349. de = &d.dentry[bit_pos];
  350. if (unlikely(!de->name_len)) {
  351. bit_pos++;
  352. continue;
  353. }
  354. new_name.name = d.filename[bit_pos];
  355. new_name.len = le16_to_cpu(de->name_len);
  356. ino = le32_to_cpu(de->ino);
  357. fake_mode = get_de_type(de) << S_SHIFT;
  358. err = f2fs_add_regular_entry(dir, &new_name, NULL, NULL,
  359. ino, fake_mode);
  360. if (err)
  361. goto punch_dentry_pages;
  362. bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
  363. }
  364. return 0;
  365. punch_dentry_pages:
  366. truncate_inode_pages(&dir->i_data, 0);
  367. truncate_blocks(dir, 0, false);
  368. remove_dirty_inode(dir);
  369. return err;
  370. }
  371. static int f2fs_move_rehashed_dirents(struct inode *dir, struct page *ipage,
  372. struct f2fs_inline_dentry *inline_dentry)
  373. {
  374. struct f2fs_inline_dentry *backup_dentry;
  375. int err;
  376. backup_dentry = f2fs_kmalloc(F2FS_I_SB(dir),
  377. sizeof(struct f2fs_inline_dentry), GFP_F2FS_ZERO);
  378. if (!backup_dentry) {
  379. f2fs_put_page(ipage, 1);
  380. return -ENOMEM;
  381. }
  382. memcpy(backup_dentry, inline_dentry, MAX_INLINE_DATA);
  383. truncate_inline_inode(ipage, 0);
  384. unlock_page(ipage);
  385. err = f2fs_add_inline_entries(dir, backup_dentry);
  386. if (err)
  387. goto recover;
  388. lock_page(ipage);
  389. stat_dec_inline_dir(dir);
  390. clear_inode_flag(dir, FI_INLINE_DENTRY);
  391. kfree(backup_dentry);
  392. return 0;
  393. recover:
  394. lock_page(ipage);
  395. memcpy(inline_dentry, backup_dentry, MAX_INLINE_DATA);
  396. f2fs_i_depth_write(dir, 0);
  397. f2fs_i_size_write(dir, MAX_INLINE_DATA);
  398. set_page_dirty(ipage);
  399. f2fs_put_page(ipage, 1);
  400. kfree(backup_dentry);
  401. return err;
  402. }
  403. static int f2fs_convert_inline_dir(struct inode *dir, struct page *ipage,
  404. struct f2fs_inline_dentry *inline_dentry)
  405. {
  406. if (!F2FS_I(dir)->i_dir_level)
  407. return f2fs_move_inline_dirents(dir, ipage, inline_dentry);
  408. else
  409. return f2fs_move_rehashed_dirents(dir, ipage, inline_dentry);
  410. }
  411. int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name,
  412. const struct qstr *orig_name,
  413. struct inode *inode, nid_t ino, umode_t mode)
  414. {
  415. struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
  416. struct page *ipage;
  417. unsigned int bit_pos;
  418. f2fs_hash_t name_hash;
  419. struct f2fs_inline_dentry *dentry_blk = NULL;
  420. struct f2fs_dentry_ptr d;
  421. int slots = GET_DENTRY_SLOTS(new_name->len);
  422. struct page *page = NULL;
  423. int err = 0;
  424. ipage = get_node_page(sbi, dir->i_ino);
  425. if (IS_ERR(ipage))
  426. return PTR_ERR(ipage);
  427. dentry_blk = inline_data_addr(ipage);
  428. bit_pos = room_for_filename(&dentry_blk->dentry_bitmap,
  429. slots, NR_INLINE_DENTRY);
  430. if (bit_pos >= NR_INLINE_DENTRY) {
  431. err = f2fs_convert_inline_dir(dir, ipage, dentry_blk);
  432. if (err)
  433. return err;
  434. err = -EAGAIN;
  435. goto out;
  436. }
  437. if (inode) {
  438. down_write(&F2FS_I(inode)->i_sem);
  439. page = init_inode_metadata(inode, dir, new_name,
  440. orig_name, ipage);
  441. if (IS_ERR(page)) {
  442. err = PTR_ERR(page);
  443. goto fail;
  444. }
  445. if (f2fs_encrypted_inode(dir))
  446. file_set_enc_name(inode);
  447. }
  448. f2fs_wait_on_page_writeback(ipage, NODE, true);
  449. name_hash = f2fs_dentry_hash(new_name);
  450. make_dentry_ptr(NULL, &d, (void *)dentry_blk, 2);
  451. f2fs_update_dentry(ino, mode, &d, new_name, name_hash, bit_pos);
  452. set_page_dirty(ipage);
  453. /* we don't need to mark_inode_dirty now */
  454. if (inode) {
  455. f2fs_i_pino_write(inode, dir->i_ino);
  456. f2fs_put_page(page, 1);
  457. }
  458. update_parent_metadata(dir, inode, 0);
  459. fail:
  460. if (inode)
  461. up_write(&F2FS_I(inode)->i_sem);
  462. out:
  463. f2fs_put_page(ipage, 1);
  464. return err;
  465. }
  466. void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page,
  467. struct inode *dir, struct inode *inode)
  468. {
  469. struct f2fs_inline_dentry *inline_dentry;
  470. int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len));
  471. unsigned int bit_pos;
  472. int i;
  473. lock_page(page);
  474. f2fs_wait_on_page_writeback(page, NODE, true);
  475. inline_dentry = inline_data_addr(page);
  476. bit_pos = dentry - inline_dentry->dentry;
  477. for (i = 0; i < slots; i++)
  478. __clear_bit_le(bit_pos + i,
  479. &inline_dentry->dentry_bitmap);
  480. set_page_dirty(page);
  481. f2fs_put_page(page, 1);
  482. dir->i_ctime = dir->i_mtime = current_time(dir);
  483. f2fs_mark_inode_dirty_sync(dir, false);
  484. if (inode)
  485. f2fs_drop_nlink(dir, inode);
  486. }
  487. bool f2fs_empty_inline_dir(struct inode *dir)
  488. {
  489. struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
  490. struct page *ipage;
  491. unsigned int bit_pos = 2;
  492. struct f2fs_inline_dentry *dentry_blk;
  493. ipage = get_node_page(sbi, dir->i_ino);
  494. if (IS_ERR(ipage))
  495. return false;
  496. dentry_blk = inline_data_addr(ipage);
  497. bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap,
  498. NR_INLINE_DENTRY,
  499. bit_pos);
  500. f2fs_put_page(ipage, 1);
  501. if (bit_pos < NR_INLINE_DENTRY)
  502. return false;
  503. return true;
  504. }
  505. int f2fs_read_inline_dir(struct file *file, void *dirent, filldir_t filldir,
  506. struct fscrypt_str *fstr)
  507. {
  508. unsigned long pos = file->f_pos;
  509. unsigned int bit_pos = 0;
  510. struct inode *inode = file_inode(file);
  511. struct f2fs_inline_dentry *inline_dentry = NULL;
  512. struct page *ipage = NULL;
  513. struct f2fs_dentry_ptr d;
  514. if (pos >= NR_INLINE_DENTRY)
  515. return 0;
  516. bit_pos = (pos % NR_INLINE_DENTRY);
  517. ipage = get_node_page(F2FS_I_SB(inode), inode->i_ino);
  518. if (IS_ERR(ipage))
  519. return PTR_ERR(ipage);
  520. inline_dentry = inline_data_addr(ipage);
  521. make_dentry_ptr(inode, &d, (void *)inline_dentry, 2);
  522. if (!f2fs_fill_dentries(file, dirent, filldir, &d, 0, bit_pos, fstr))
  523. file->f_pos = NR_INLINE_DENTRY;
  524. f2fs_put_page(ipage, 1);
  525. return 0;
  526. }
  527. int f2fs_inline_data_fiemap(struct inode *inode,
  528. struct fiemap_extent_info *fieinfo, __u64 start, __u64 len)
  529. {
  530. __u64 byteaddr, ilen;
  531. __u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED |
  532. FIEMAP_EXTENT_LAST;
  533. struct node_info ni;
  534. struct page *ipage;
  535. int err = 0;
  536. ipage = get_node_page(F2FS_I_SB(inode), inode->i_ino);
  537. if (IS_ERR(ipage))
  538. return PTR_ERR(ipage);
  539. if (!f2fs_has_inline_data(inode)) {
  540. err = -EAGAIN;
  541. goto out;
  542. }
  543. ilen = min_t(size_t, MAX_INLINE_DATA, i_size_read(inode));
  544. if (start >= ilen)
  545. goto out;
  546. if (start + len < ilen)
  547. ilen = start + len;
  548. ilen -= start;
  549. get_node_info(F2FS_I_SB(inode), inode->i_ino, &ni);
  550. byteaddr = (__u64)ni.blk_addr << inode->i_sb->s_blocksize_bits;
  551. byteaddr += (char *)inline_data_addr(ipage) - (char *)F2FS_INODE(ipage);
  552. err = fiemap_fill_next_extent(fieinfo, start, byteaddr, ilen, flags);
  553. out:
  554. f2fs_put_page(ipage, 1);
  555. return err;
  556. }