file.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  1. /*
  2. * This file is part of UBIFS.
  3. *
  4. * Copyright (C) 2006-2008 Nokia Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; if not, write to the Free Software Foundation, Inc., 51
  17. * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. *
  19. * Authors: Artem Bityutskiy (Битюцкий Артём)
  20. * Adrian Hunter
  21. */
  22. /*
  23. * This file implements VFS file and inode operations of regular files, device
  24. * nodes and symlinks as well as address space operations.
  25. *
  26. * UBIFS uses 2 page flags: PG_private and PG_checked. PG_private is set if the
  27. * page is dirty and is used for budgeting purposes - dirty pages should not be
  28. * budgeted. The PG_checked flag is set if full budgeting is required for the
  29. * page e.g., when it corresponds to a file hole or it is just beyond the file
  30. * size. The budgeting is done in 'ubifs_write_begin()', because it is OK to
  31. * fail in this function, and the budget is released in 'ubifs_write_end()'. So
  32. * the PG_private and PG_checked flags carry the information about how the page
  33. * was budgeted, to make it possible to release the budget properly.
  34. *
  35. * A thing to keep in mind: inode's 'i_mutex' is locked in most VFS operations
  36. * we implement. However, this is not true for '->writepage()', which might be
  37. * called with 'i_mutex' unlocked. For example, when pdflush is performing
  38. * write-back, it calls 'writepage()' with unlocked 'i_mutex', although the
  39. * inode has 'I_LOCK' flag in this case. At "normal" work-paths 'i_mutex' is
  40. * locked in '->writepage', e.g. in "sys_write -> alloc_pages -> direct reclaim
  41. * path'. So, in '->writepage()' we are only guaranteed that the page is
  42. * locked.
  43. *
  44. * Similarly, 'i_mutex' does not have to be locked in readpage(), e.g.,
  45. * readahead path does not have it locked ("sys_read -> generic_file_aio_read
  46. * -> ondemand_readahead -> readpage"). In case of readahead, 'I_LOCK' flag is
  47. * not set as well. However, UBIFS disables readahead.
  48. *
  49. * This, for example means that there might be 2 concurrent '->writepage()'
  50. * calls for the same inode, but different inode dirty pages.
  51. */
  52. #include "ubifs.h"
  53. #include <linux/mount.h>
  54. #include <linux/namei.h>
  55. static int read_block(struct inode *inode, void *addr, unsigned int block,
  56. struct ubifs_data_node *dn)
  57. {
  58. struct ubifs_info *c = inode->i_sb->s_fs_info;
  59. int err, len, out_len;
  60. union ubifs_key key;
  61. unsigned int dlen;
  62. data_key_init(c, &key, inode->i_ino, block);
  63. err = ubifs_tnc_lookup(c, &key, dn);
  64. if (err) {
  65. if (err == -ENOENT)
  66. /* Not found, so it must be a hole */
  67. memset(addr, 0, UBIFS_BLOCK_SIZE);
  68. return err;
  69. }
  70. ubifs_assert(dn->ch.sqnum > ubifs_inode(inode)->creat_sqnum);
  71. len = le32_to_cpu(dn->size);
  72. if (len <= 0 || len > UBIFS_BLOCK_SIZE)
  73. goto dump;
  74. dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ;
  75. out_len = UBIFS_BLOCK_SIZE;
  76. err = ubifs_decompress(&dn->data, dlen, addr, &out_len,
  77. le16_to_cpu(dn->compr_type));
  78. if (err || len != out_len)
  79. goto dump;
  80. /*
  81. * Data length can be less than a full block, even for blocks that are
  82. * not the last in the file (e.g., as a result of making a hole and
  83. * appending data). Ensure that the remainder is zeroed out.
  84. */
  85. if (len < UBIFS_BLOCK_SIZE)
  86. memset(addr + len, 0, UBIFS_BLOCK_SIZE - len);
  87. return 0;
  88. dump:
  89. ubifs_err("bad data node (block %u, inode %lu)",
  90. block, inode->i_ino);
  91. dbg_dump_node(c, dn);
  92. return -EINVAL;
  93. }
  94. static int do_readpage(struct page *page)
  95. {
  96. void *addr;
  97. int err = 0, i;
  98. unsigned int block, beyond;
  99. struct ubifs_data_node *dn;
  100. struct inode *inode = page->mapping->host;
  101. loff_t i_size = i_size_read(inode);
  102. dbg_gen("ino %lu, pg %lu, i_size %lld, flags %#lx",
  103. inode->i_ino, page->index, i_size, page->flags);
  104. ubifs_assert(!PageChecked(page));
  105. ubifs_assert(!PagePrivate(page));
  106. addr = kmap(page);
  107. block = page->index << UBIFS_BLOCKS_PER_PAGE_SHIFT;
  108. beyond = (i_size + UBIFS_BLOCK_SIZE - 1) >> UBIFS_BLOCK_SHIFT;
  109. if (block >= beyond) {
  110. /* Reading beyond inode */
  111. SetPageChecked(page);
  112. memset(addr, 0, PAGE_CACHE_SIZE);
  113. goto out;
  114. }
  115. dn = kmalloc(UBIFS_MAX_DATA_NODE_SZ, GFP_NOFS);
  116. if (!dn) {
  117. err = -ENOMEM;
  118. goto error;
  119. }
  120. i = 0;
  121. while (1) {
  122. int ret;
  123. if (block >= beyond) {
  124. /* Reading beyond inode */
  125. err = -ENOENT;
  126. memset(addr, 0, UBIFS_BLOCK_SIZE);
  127. } else {
  128. ret = read_block(inode, addr, block, dn);
  129. if (ret) {
  130. err = ret;
  131. if (err != -ENOENT)
  132. break;
  133. }
  134. }
  135. if (++i >= UBIFS_BLOCKS_PER_PAGE)
  136. break;
  137. block += 1;
  138. addr += UBIFS_BLOCK_SIZE;
  139. }
  140. if (err) {
  141. if (err == -ENOENT) {
  142. /* Not found, so it must be a hole */
  143. SetPageChecked(page);
  144. dbg_gen("hole");
  145. goto out_free;
  146. }
  147. ubifs_err("cannot read page %lu of inode %lu, error %d",
  148. page->index, inode->i_ino, err);
  149. goto error;
  150. }
  151. out_free:
  152. kfree(dn);
  153. out:
  154. SetPageUptodate(page);
  155. ClearPageError(page);
  156. flush_dcache_page(page);
  157. kunmap(page);
  158. return 0;
  159. error:
  160. kfree(dn);
  161. ClearPageUptodate(page);
  162. SetPageError(page);
  163. flush_dcache_page(page);
  164. kunmap(page);
  165. return err;
  166. }
  167. /**
  168. * release_new_page_budget - release budget of a new page.
  169. * @c: UBIFS file-system description object
  170. *
  171. * This is a helper function which releases budget corresponding to the budget
  172. * of one new page of data.
  173. */
  174. static void release_new_page_budget(struct ubifs_info *c)
  175. {
  176. struct ubifs_budget_req req = { .recalculate = 1, .new_page = 1 };
  177. ubifs_release_budget(c, &req);
  178. }
  179. /**
  180. * release_existing_page_budget - release budget of an existing page.
  181. * @c: UBIFS file-system description object
  182. *
  183. * This is a helper function which releases budget corresponding to the budget
  184. * of changing one one page of data which already exists on the flash media.
  185. */
  186. static void release_existing_page_budget(struct ubifs_info *c)
  187. {
  188. struct ubifs_budget_req req = { .dd_growth = c->page_budget};
  189. ubifs_release_budget(c, &req);
  190. }
  191. static int write_begin_slow(struct address_space *mapping,
  192. loff_t pos, unsigned len, struct page **pagep)
  193. {
  194. struct inode *inode = mapping->host;
  195. struct ubifs_info *c = inode->i_sb->s_fs_info;
  196. pgoff_t index = pos >> PAGE_CACHE_SHIFT;
  197. struct ubifs_budget_req req = { .new_page = 1 };
  198. int uninitialized_var(err), appending = !!(pos + len > inode->i_size);
  199. struct page *page;
  200. dbg_gen("ino %lu, pos %llu, len %u, i_size %lld",
  201. inode->i_ino, pos, len, inode->i_size);
  202. /*
  203. * At the slow path we have to budget before locking the page, because
  204. * budgeting may force write-back, which would wait on locked pages and
  205. * deadlock if we had the page locked. At this point we do not know
  206. * anything about the page, so assume that this is a new page which is
  207. * written to a hole. This corresponds to largest budget. Later the
  208. * budget will be amended if this is not true.
  209. */
  210. if (appending)
  211. /* We are appending data, budget for inode change */
  212. req.dirtied_ino = 1;
  213. err = ubifs_budget_space(c, &req);
  214. if (unlikely(err))
  215. return err;
  216. page = __grab_cache_page(mapping, index);
  217. if (unlikely(!page)) {
  218. ubifs_release_budget(c, &req);
  219. return -ENOMEM;
  220. }
  221. if (!PageUptodate(page)) {
  222. if (!(pos & PAGE_CACHE_MASK) && len == PAGE_CACHE_SIZE)
  223. SetPageChecked(page);
  224. else {
  225. err = do_readpage(page);
  226. if (err) {
  227. unlock_page(page);
  228. page_cache_release(page);
  229. return err;
  230. }
  231. }
  232. SetPageUptodate(page);
  233. ClearPageError(page);
  234. }
  235. if (PagePrivate(page))
  236. /*
  237. * The page is dirty, which means it was budgeted twice:
  238. * o first time the budget was allocated by the task which
  239. * made the page dirty and set the PG_private flag;
  240. * o and then we budgeted for it for the second time at the
  241. * very beginning of this function.
  242. *
  243. * So what we have to do is to release the page budget we
  244. * allocated.
  245. */
  246. release_new_page_budget(c);
  247. else if (!PageChecked(page))
  248. /*
  249. * We are changing a page which already exists on the media.
  250. * This means that changing the page does not make the amount
  251. * of indexing information larger, and this part of the budget
  252. * which we have already acquired may be released.
  253. */
  254. ubifs_convert_page_budget(c);
  255. if (appending) {
  256. struct ubifs_inode *ui = ubifs_inode(inode);
  257. /*
  258. * 'ubifs_write_end()' is optimized from the fast-path part of
  259. * 'ubifs_write_begin()' and expects the @ui_mutex to be locked
  260. * if data is appended.
  261. */
  262. mutex_lock(&ui->ui_mutex);
  263. if (ui->dirty)
  264. /*
  265. * The inode is dirty already, so we may free the
  266. * budget we allocated.
  267. */
  268. ubifs_release_dirty_inode_budget(c, ui);
  269. }
  270. *pagep = page;
  271. return 0;
  272. }
  273. /**
  274. * allocate_budget - allocate budget for 'ubifs_write_begin()'.
  275. * @c: UBIFS file-system description object
  276. * @page: page to allocate budget for
  277. * @ui: UBIFS inode object the page belongs to
  278. * @appending: non-zero if the page is appended
  279. *
  280. * This is a helper function for 'ubifs_write_begin()' which allocates budget
  281. * for the operation. The budget is allocated differently depending on whether
  282. * this is appending, whether the page is dirty or not, and so on. This
  283. * function leaves the @ui->ui_mutex locked in case of appending. Returns zero
  284. * in case of success and %-ENOSPC in case of failure.
  285. */
  286. static int allocate_budget(struct ubifs_info *c, struct page *page,
  287. struct ubifs_inode *ui, int appending)
  288. {
  289. struct ubifs_budget_req req = { .fast = 1 };
  290. if (PagePrivate(page)) {
  291. if (!appending)
  292. /*
  293. * The page is dirty and we are not appending, which
  294. * means no budget is needed at all.
  295. */
  296. return 0;
  297. mutex_lock(&ui->ui_mutex);
  298. if (ui->dirty)
  299. /*
  300. * The page is dirty and we are appending, so the inode
  301. * has to be marked as dirty. However, it is already
  302. * dirty, so we do not need any budget. We may return,
  303. * but @ui->ui_mutex hast to be left locked because we
  304. * should prevent write-back from flushing the inode
  305. * and freeing the budget. The lock will be released in
  306. * 'ubifs_write_end()'.
  307. */
  308. return 0;
  309. /*
  310. * The page is dirty, we are appending, the inode is clean, so
  311. * we need to budget the inode change.
  312. */
  313. req.dirtied_ino = 1;
  314. } else {
  315. if (PageChecked(page))
  316. /*
  317. * The page corresponds to a hole and does not
  318. * exist on the media. So changing it makes
  319. * make the amount of indexing information
  320. * larger, and we have to budget for a new
  321. * page.
  322. */
  323. req.new_page = 1;
  324. else
  325. /*
  326. * Not a hole, the change will not add any new
  327. * indexing information, budget for page
  328. * change.
  329. */
  330. req.dirtied_page = 1;
  331. if (appending) {
  332. mutex_lock(&ui->ui_mutex);
  333. if (!ui->dirty)
  334. /*
  335. * The inode is clean but we will have to mark
  336. * it as dirty because we are appending. This
  337. * needs a budget.
  338. */
  339. req.dirtied_ino = 1;
  340. }
  341. }
  342. return ubifs_budget_space(c, &req);
  343. }
  344. /*
  345. * This function is called when a page of data is going to be written. Since
  346. * the page of data will not necessarily go to the flash straight away, UBIFS
  347. * has to reserve space on the media for it, which is done by means of
  348. * budgeting.
  349. *
  350. * This is the hot-path of the file-system and we are trying to optimize it as
  351. * much as possible. For this reasons it is split on 2 parts - slow and fast.
  352. *
  353. * There many budgeting cases:
  354. * o a new page is appended - we have to budget for a new page and for
  355. * changing the inode; however, if the inode is already dirty, there is
  356. * no need to budget for it;
  357. * o an existing clean page is changed - we have budget for it; if the page
  358. * does not exist on the media (a hole), we have to budget for a new
  359. * page; otherwise, we may budget for changing an existing page; the
  360. * difference between these cases is that changing an existing page does
  361. * not introduce anything new to the FS indexing information, so it does
  362. * not grow, and smaller budget is acquired in this case;
  363. * o an existing dirty page is changed - no need to budget at all, because
  364. * the page budget has been acquired by earlier, when the page has been
  365. * marked dirty.
  366. *
  367. * UBIFS budgeting sub-system may force write-back if it thinks there is no
  368. * space to reserve. This imposes some locking restrictions and makes it
  369. * impossible to take into account the above cases, and makes it impossible to
  370. * optimize budgeting.
  371. *
  372. * The solution for this is that the fast path of 'ubifs_write_begin()' assumes
  373. * there is a plenty of flash space and the budget will be acquired quickly,
  374. * without forcing write-back. The slow path does not make this assumption.
  375. */
  376. static int ubifs_write_begin(struct file *file, struct address_space *mapping,
  377. loff_t pos, unsigned len, unsigned flags,
  378. struct page **pagep, void **fsdata)
  379. {
  380. struct inode *inode = mapping->host;
  381. struct ubifs_info *c = inode->i_sb->s_fs_info;
  382. struct ubifs_inode *ui = ubifs_inode(inode);
  383. pgoff_t index = pos >> PAGE_CACHE_SHIFT;
  384. int uninitialized_var(err), appending = !!(pos + len > inode->i_size);
  385. struct page *page;
  386. ubifs_assert(ubifs_inode(inode)->ui_size == inode->i_size);
  387. if (unlikely(c->ro_media))
  388. return -EROFS;
  389. /* Try out the fast-path part first */
  390. page = __grab_cache_page(mapping, index);
  391. if (unlikely(!page))
  392. return -ENOMEM;
  393. if (!PageUptodate(page)) {
  394. /* The page is not loaded from the flash */
  395. if (!(pos & PAGE_CACHE_MASK) && len == PAGE_CACHE_SIZE)
  396. /*
  397. * We change whole page so no need to load it. But we
  398. * have to set the @PG_checked flag to make the further
  399. * code the page is new. This might be not true, but it
  400. * is better to budget more that to read the page from
  401. * the media.
  402. */
  403. SetPageChecked(page);
  404. else {
  405. err = do_readpage(page);
  406. if (err) {
  407. unlock_page(page);
  408. page_cache_release(page);
  409. return err;
  410. }
  411. }
  412. SetPageUptodate(page);
  413. ClearPageError(page);
  414. }
  415. err = allocate_budget(c, page, ui, appending);
  416. if (unlikely(err)) {
  417. ubifs_assert(err == -ENOSPC);
  418. /*
  419. * Budgeting failed which means it would have to force
  420. * write-back but didn't, because we set the @fast flag in the
  421. * request. Write-back cannot be done now, while we have the
  422. * page locked, because it would deadlock. Unlock and free
  423. * everything and fall-back to slow-path.
  424. */
  425. if (appending) {
  426. ubifs_assert(mutex_is_locked(&ui->ui_mutex));
  427. mutex_unlock(&ui->ui_mutex);
  428. }
  429. unlock_page(page);
  430. page_cache_release(page);
  431. return write_begin_slow(mapping, pos, len, pagep);
  432. }
  433. /*
  434. * Whee, we aquired budgeting quickly - without involving
  435. * garbage-collection, committing or forceing write-back. We return
  436. * with @ui->ui_mutex locked if we are appending pages, and unlocked
  437. * otherwise. This is an optimization (slightly hacky though).
  438. */
  439. *pagep = page;
  440. return 0;
  441. }
  442. /**
  443. * cancel_budget - cancel budget.
  444. * @c: UBIFS file-system description object
  445. * @page: page to cancel budget for
  446. * @ui: UBIFS inode object the page belongs to
  447. * @appending: non-zero if the page is appended
  448. *
  449. * This is a helper function for a page write operation. It unlocks the
  450. * @ui->ui_mutex in case of appending.
  451. */
  452. static void cancel_budget(struct ubifs_info *c, struct page *page,
  453. struct ubifs_inode *ui, int appending)
  454. {
  455. if (appending) {
  456. if (!ui->dirty)
  457. ubifs_release_dirty_inode_budget(c, ui);
  458. mutex_unlock(&ui->ui_mutex);
  459. }
  460. if (!PagePrivate(page)) {
  461. if (PageChecked(page))
  462. release_new_page_budget(c);
  463. else
  464. release_existing_page_budget(c);
  465. }
  466. }
  467. static int ubifs_write_end(struct file *file, struct address_space *mapping,
  468. loff_t pos, unsigned len, unsigned copied,
  469. struct page *page, void *fsdata)
  470. {
  471. struct inode *inode = mapping->host;
  472. struct ubifs_inode *ui = ubifs_inode(inode);
  473. struct ubifs_info *c = inode->i_sb->s_fs_info;
  474. loff_t end_pos = pos + len;
  475. int appending = !!(end_pos > inode->i_size);
  476. dbg_gen("ino %lu, pos %llu, pg %lu, len %u, copied %d, i_size %lld",
  477. inode->i_ino, pos, page->index, len, copied, inode->i_size);
  478. if (unlikely(copied < len && len == PAGE_CACHE_SIZE)) {
  479. /*
  480. * VFS copied less data to the page that it intended and
  481. * declared in its '->write_begin()' call via the @len
  482. * argument. If the page was not up-to-date, and @len was
  483. * @PAGE_CACHE_SIZE, the 'ubifs_write_begin()' function did
  484. * not load it from the media (for optimization reasons). This
  485. * means that part of the page contains garbage. So read the
  486. * page now.
  487. */
  488. dbg_gen("copied %d instead of %d, read page and repeat",
  489. copied, len);
  490. cancel_budget(c, page, ui, appending);
  491. /*
  492. * Return 0 to force VFS to repeat the whole operation, or the
  493. * error code if 'do_readpage()' failes.
  494. */
  495. copied = do_readpage(page);
  496. goto out;
  497. }
  498. if (!PagePrivate(page)) {
  499. SetPagePrivate(page);
  500. atomic_long_inc(&c->dirty_pg_cnt);
  501. __set_page_dirty_nobuffers(page);
  502. }
  503. if (appending) {
  504. i_size_write(inode, end_pos);
  505. ui->ui_size = end_pos;
  506. /*
  507. * Note, we do not set @I_DIRTY_PAGES (which means that the
  508. * inode has dirty pages), this has been done in
  509. * '__set_page_dirty_nobuffers()'.
  510. */
  511. __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
  512. ubifs_assert(mutex_is_locked(&ui->ui_mutex));
  513. mutex_unlock(&ui->ui_mutex);
  514. }
  515. out:
  516. unlock_page(page);
  517. page_cache_release(page);
  518. return copied;
  519. }
  520. static int ubifs_readpage(struct file *file, struct page *page)
  521. {
  522. do_readpage(page);
  523. unlock_page(page);
  524. return 0;
  525. }
  526. static int do_writepage(struct page *page, int len)
  527. {
  528. int err = 0, i, blen;
  529. unsigned int block;
  530. void *addr;
  531. union ubifs_key key;
  532. struct inode *inode = page->mapping->host;
  533. struct ubifs_info *c = inode->i_sb->s_fs_info;
  534. #ifdef UBIFS_DEBUG
  535. spin_lock(&ui->ui_lock);
  536. ubifs_assert(page->index <= ui->synced_i_size << PAGE_CACHE_SIZE);
  537. spin_unlock(&ui->ui_lock);
  538. #endif
  539. /* Update radix tree tags */
  540. set_page_writeback(page);
  541. addr = kmap(page);
  542. block = page->index << UBIFS_BLOCKS_PER_PAGE_SHIFT;
  543. i = 0;
  544. while (len) {
  545. blen = min_t(int, len, UBIFS_BLOCK_SIZE);
  546. data_key_init(c, &key, inode->i_ino, block);
  547. err = ubifs_jnl_write_data(c, inode, &key, addr, blen);
  548. if (err)
  549. break;
  550. if (++i >= UBIFS_BLOCKS_PER_PAGE)
  551. break;
  552. block += 1;
  553. addr += blen;
  554. len -= blen;
  555. }
  556. if (err) {
  557. SetPageError(page);
  558. ubifs_err("cannot write page %lu of inode %lu, error %d",
  559. page->index, inode->i_ino, err);
  560. ubifs_ro_mode(c, err);
  561. }
  562. ubifs_assert(PagePrivate(page));
  563. if (PageChecked(page))
  564. release_new_page_budget(c);
  565. else
  566. release_existing_page_budget(c);
  567. atomic_long_dec(&c->dirty_pg_cnt);
  568. ClearPagePrivate(page);
  569. ClearPageChecked(page);
  570. kunmap(page);
  571. unlock_page(page);
  572. end_page_writeback(page);
  573. return err;
  574. }
  575. /*
  576. * When writing-back dirty inodes, VFS first writes-back pages belonging to the
  577. * inode, then the inode itself. For UBIFS this may cause a problem. Consider a
  578. * situation when a we have an inode with size 0, then a megabyte of data is
  579. * appended to the inode, then write-back starts and flushes some amount of the
  580. * dirty pages, the journal becomes full, commit happens and finishes, and then
  581. * an unclean reboot happens. When the file system is mounted next time, the
  582. * inode size would still be 0, but there would be many pages which are beyond
  583. * the inode size, they would be indexed and consume flash space. Because the
  584. * journal has been committed, the replay would not be able to detect this
  585. * situation and correct the inode size. This means UBIFS would have to scan
  586. * whole index and correct all inode sizes, which is long an unacceptable.
  587. *
  588. * To prevent situations like this, UBIFS writes pages back only if they are
  589. * within last synchronized inode size, i.e. the the size which has been
  590. * written to the flash media last time. Otherwise, UBIFS forces inode
  591. * write-back, thus making sure the on-flash inode contains current inode size,
  592. * and then keeps writing pages back.
  593. *
  594. * Some locking issues explanation. 'ubifs_writepage()' first is called with
  595. * the page locked, and it locks @ui_mutex. However, write-back does take inode
  596. * @i_mutex, which means other VFS operations may be run on this inode at the
  597. * same time. And the problematic one is truncation to smaller size, from where
  598. * we have to call 'vmtruncate()', which first changes @inode->i_size, then
  599. * drops the truncated pages. And while dropping the pages, it takes the page
  600. * lock. This means that 'do_truncation()' cannot call 'vmtruncate()' with
  601. * @ui_mutex locked, because it would deadlock with 'ubifs_writepage()'. This
  602. * means that @inode->i_size is changed while @ui_mutex is unlocked.
  603. *
  604. * But in 'ubifs_writepage()' we have to guarantee that we do not write beyond
  605. * inode size. How do we do this if @inode->i_size may became smaller while we
  606. * are in the middle of 'ubifs_writepage()'? The UBIFS solution is the
  607. * @ui->ui_isize "shadow" field which UBIFS uses instead of @inode->i_size
  608. * internally and updates it under @ui_mutex.
  609. *
  610. * Q: why we do not worry that if we race with truncation, we may end up with a
  611. * situation when the inode is truncated while we are in the middle of
  612. * 'do_writepage()', so we do write beyond inode size?
  613. * A: If we are in the middle of 'do_writepage()', truncation would be locked
  614. * on the page lock and it would not write the truncated inode node to the
  615. * journal before we have finished.
  616. */
  617. static int ubifs_writepage(struct page *page, struct writeback_control *wbc)
  618. {
  619. struct inode *inode = page->mapping->host;
  620. struct ubifs_inode *ui = ubifs_inode(inode);
  621. loff_t i_size = i_size_read(inode), synced_i_size;
  622. pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT;
  623. int err, len = i_size & (PAGE_CACHE_SIZE - 1);
  624. void *kaddr;
  625. dbg_gen("ino %lu, pg %lu, pg flags %#lx",
  626. inode->i_ino, page->index, page->flags);
  627. ubifs_assert(PagePrivate(page));
  628. /* Is the page fully outside @i_size? (truncate in progress) */
  629. if (page->index > end_index || (page->index == end_index && !len)) {
  630. err = 0;
  631. goto out_unlock;
  632. }
  633. spin_lock(&ui->ui_lock);
  634. synced_i_size = ui->synced_i_size;
  635. spin_unlock(&ui->ui_lock);
  636. /* Is the page fully inside @i_size? */
  637. if (page->index < end_index) {
  638. if (page->index >= synced_i_size >> PAGE_CACHE_SHIFT) {
  639. err = inode->i_sb->s_op->write_inode(inode, 1);
  640. if (err)
  641. goto out_unlock;
  642. /*
  643. * The inode has been written, but the write-buffer has
  644. * not been synchronized, so in case of an unclean
  645. * reboot we may end up with some pages beyond inode
  646. * size, but they would be in the journal (because
  647. * commit flushes write buffers) and recovery would deal
  648. * with this.
  649. */
  650. }
  651. return do_writepage(page, PAGE_CACHE_SIZE);
  652. }
  653. /*
  654. * The page straddles @i_size. It must be zeroed out on each and every
  655. * writepage invocation because it may be mmapped. "A file is mapped
  656. * in multiples of the page size. For a file that is not a multiple of
  657. * the page size, the remaining memory is zeroed when mapped, and
  658. * writes to that region are not written out to the file."
  659. */
  660. kaddr = kmap_atomic(page, KM_USER0);
  661. memset(kaddr + len, 0, PAGE_CACHE_SIZE - len);
  662. flush_dcache_page(page);
  663. kunmap_atomic(kaddr, KM_USER0);
  664. if (i_size > synced_i_size) {
  665. err = inode->i_sb->s_op->write_inode(inode, 1);
  666. if (err)
  667. goto out_unlock;
  668. }
  669. return do_writepage(page, len);
  670. out_unlock:
  671. unlock_page(page);
  672. return err;
  673. }
  674. /**
  675. * do_attr_changes - change inode attributes.
  676. * @inode: inode to change attributes for
  677. * @attr: describes attributes to change
  678. */
  679. static void do_attr_changes(struct inode *inode, const struct iattr *attr)
  680. {
  681. if (attr->ia_valid & ATTR_UID)
  682. inode->i_uid = attr->ia_uid;
  683. if (attr->ia_valid & ATTR_GID)
  684. inode->i_gid = attr->ia_gid;
  685. if (attr->ia_valid & ATTR_ATIME)
  686. inode->i_atime = timespec_trunc(attr->ia_atime,
  687. inode->i_sb->s_time_gran);
  688. if (attr->ia_valid & ATTR_MTIME)
  689. inode->i_mtime = timespec_trunc(attr->ia_mtime,
  690. inode->i_sb->s_time_gran);
  691. if (attr->ia_valid & ATTR_CTIME)
  692. inode->i_ctime = timespec_trunc(attr->ia_ctime,
  693. inode->i_sb->s_time_gran);
  694. if (attr->ia_valid & ATTR_MODE) {
  695. umode_t mode = attr->ia_mode;
  696. if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
  697. mode &= ~S_ISGID;
  698. inode->i_mode = mode;
  699. }
  700. }
  701. /**
  702. * do_truncation - truncate an inode.
  703. * @c: UBIFS file-system description object
  704. * @inode: inode to truncate
  705. * @attr: inode attribute changes description
  706. *
  707. * This function implements VFS '->setattr()' call when the inode is truncated
  708. * to a smaller size. Returns zero in case of success and a negative error code
  709. * in case of failure.
  710. */
  711. static int do_truncation(struct ubifs_info *c, struct inode *inode,
  712. const struct iattr *attr)
  713. {
  714. int err;
  715. struct ubifs_budget_req req;
  716. loff_t old_size = inode->i_size, new_size = attr->ia_size;
  717. int offset = new_size & (UBIFS_BLOCK_SIZE - 1), budgeted = 1;
  718. struct ubifs_inode *ui = ubifs_inode(inode);
  719. dbg_gen("ino %lu, size %lld -> %lld", inode->i_ino, old_size, new_size);
  720. memset(&req, 0, sizeof(struct ubifs_budget_req));
  721. /*
  722. * If this is truncation to a smaller size, and we do not truncate on a
  723. * block boundary, budget for changing one data block, because the last
  724. * block will be re-written.
  725. */
  726. if (new_size & (UBIFS_BLOCK_SIZE - 1))
  727. req.dirtied_page = 1;
  728. req.dirtied_ino = 1;
  729. /* A funny way to budget for truncation node */
  730. req.dirtied_ino_d = UBIFS_TRUN_NODE_SZ;
  731. err = ubifs_budget_space(c, &req);
  732. if (err) {
  733. /*
  734. * Treat truncations to zero as deletion and always allow them,
  735. * just like we do for '->unlink()'.
  736. */
  737. if (new_size || err != -ENOSPC)
  738. return err;
  739. budgeted = 0;
  740. }
  741. err = vmtruncate(inode, new_size);
  742. if (err)
  743. goto out_budg;
  744. if (offset) {
  745. pgoff_t index = new_size >> PAGE_CACHE_SHIFT;
  746. struct page *page;
  747. page = find_lock_page(inode->i_mapping, index);
  748. if (page) {
  749. if (PageDirty(page)) {
  750. /*
  751. * 'ubifs_jnl_truncate()' will try to truncate
  752. * the last data node, but it contains
  753. * out-of-date data because the page is dirty.
  754. * Write the page now, so that
  755. * 'ubifs_jnl_truncate()' will see an already
  756. * truncated (and up to date) data node.
  757. */
  758. ubifs_assert(PagePrivate(page));
  759. clear_page_dirty_for_io(page);
  760. if (UBIFS_BLOCKS_PER_PAGE_SHIFT)
  761. offset = new_size &
  762. (PAGE_CACHE_SIZE - 1);
  763. err = do_writepage(page, offset);
  764. page_cache_release(page);
  765. if (err)
  766. goto out_budg;
  767. /*
  768. * We could now tell 'ubifs_jnl_truncate()' not
  769. * to read the last block.
  770. */
  771. } else {
  772. /*
  773. * We could 'kmap()' the page and pass the data
  774. * to 'ubifs_jnl_truncate()' to save it from
  775. * having to read it.
  776. */
  777. unlock_page(page);
  778. page_cache_release(page);
  779. }
  780. }
  781. }
  782. mutex_lock(&ui->ui_mutex);
  783. ui->ui_size = inode->i_size;
  784. /* Truncation changes inode [mc]time */
  785. inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
  786. /* The other attributes may be changed at the same time as well */
  787. do_attr_changes(inode, attr);
  788. err = ubifs_jnl_truncate(c, inode, old_size, new_size);
  789. mutex_unlock(&ui->ui_mutex);
  790. out_budg:
  791. if (budgeted)
  792. ubifs_release_budget(c, &req);
  793. else {
  794. c->nospace = c->nospace_rp = 0;
  795. smp_wmb();
  796. }
  797. return err;
  798. }
  799. /**
  800. * do_setattr - change inode attributes.
  801. * @c: UBIFS file-system description object
  802. * @inode: inode to change attributes for
  803. * @attr: inode attribute changes description
  804. *
  805. * This function implements VFS '->setattr()' call for all cases except
  806. * truncations to smaller size. Returns zero in case of success and a negative
  807. * error code in case of failure.
  808. */
  809. static int do_setattr(struct ubifs_info *c, struct inode *inode,
  810. const struct iattr *attr)
  811. {
  812. int err, release;
  813. loff_t new_size = attr->ia_size;
  814. struct ubifs_inode *ui = ubifs_inode(inode);
  815. struct ubifs_budget_req req = { .dirtied_ino = 1,
  816. .dirtied_ino_d = ALIGN(ui->data_len, 8) };
  817. err = ubifs_budget_space(c, &req);
  818. if (err)
  819. return err;
  820. if (attr->ia_valid & ATTR_SIZE) {
  821. dbg_gen("size %lld -> %lld", inode->i_size, new_size);
  822. err = vmtruncate(inode, new_size);
  823. if (err)
  824. goto out;
  825. }
  826. mutex_lock(&ui->ui_mutex);
  827. if (attr->ia_valid & ATTR_SIZE) {
  828. /* Truncation changes inode [mc]time */
  829. inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
  830. /* 'vmtruncate()' changed @i_size, update @ui_size */
  831. ui->ui_size = inode->i_size;
  832. }
  833. do_attr_changes(inode, attr);
  834. release = ui->dirty;
  835. if (attr->ia_valid & ATTR_SIZE)
  836. /*
  837. * Inode length changed, so we have to make sure
  838. * @I_DIRTY_DATASYNC is set.
  839. */
  840. __mark_inode_dirty(inode, I_DIRTY_SYNC | I_DIRTY_DATASYNC);
  841. else
  842. mark_inode_dirty_sync(inode);
  843. mutex_unlock(&ui->ui_mutex);
  844. if (release)
  845. ubifs_release_budget(c, &req);
  846. if (IS_SYNC(inode))
  847. err = inode->i_sb->s_op->write_inode(inode, 1);
  848. return err;
  849. out:
  850. ubifs_release_budget(c, &req);
  851. return err;
  852. }
  853. int ubifs_setattr(struct dentry *dentry, struct iattr *attr)
  854. {
  855. int err;
  856. struct inode *inode = dentry->d_inode;
  857. struct ubifs_info *c = inode->i_sb->s_fs_info;
  858. dbg_gen("ino %lu, mode %#x, ia_valid %#x",
  859. inode->i_ino, inode->i_mode, attr->ia_valid);
  860. err = inode_change_ok(inode, attr);
  861. if (err)
  862. return err;
  863. err = dbg_check_synced_i_size(inode);
  864. if (err)
  865. return err;
  866. if ((attr->ia_valid & ATTR_SIZE) && attr->ia_size < inode->i_size)
  867. /* Truncation to a smaller size */
  868. err = do_truncation(c, inode, attr);
  869. else
  870. err = do_setattr(c, inode, attr);
  871. return err;
  872. }
  873. static void ubifs_invalidatepage(struct page *page, unsigned long offset)
  874. {
  875. struct inode *inode = page->mapping->host;
  876. struct ubifs_info *c = inode->i_sb->s_fs_info;
  877. ubifs_assert(PagePrivate(page));
  878. if (offset)
  879. /* Partial page remains dirty */
  880. return;
  881. if (PageChecked(page))
  882. release_new_page_budget(c);
  883. else
  884. release_existing_page_budget(c);
  885. atomic_long_dec(&c->dirty_pg_cnt);
  886. ClearPagePrivate(page);
  887. ClearPageChecked(page);
  888. }
  889. static void *ubifs_follow_link(struct dentry *dentry, struct nameidata *nd)
  890. {
  891. struct ubifs_inode *ui = ubifs_inode(dentry->d_inode);
  892. nd_set_link(nd, ui->data);
  893. return NULL;
  894. }
  895. int ubifs_fsync(struct file *file, struct dentry *dentry, int datasync)
  896. {
  897. struct inode *inode = dentry->d_inode;
  898. struct ubifs_info *c = inode->i_sb->s_fs_info;
  899. int err;
  900. dbg_gen("syncing inode %lu", inode->i_ino);
  901. /*
  902. * VFS has already synchronized dirty pages for this inode. Synchronize
  903. * the inode unless this is a 'datasync()' call.
  904. */
  905. if (!datasync || (inode->i_state & I_DIRTY_DATASYNC)) {
  906. err = inode->i_sb->s_op->write_inode(inode, 1);
  907. if (err)
  908. return err;
  909. }
  910. /*
  911. * Nodes related to this inode may still sit in a write-buffer. Flush
  912. * them.
  913. */
  914. err = ubifs_sync_wbufs_by_inode(c, inode);
  915. if (err)
  916. return err;
  917. return 0;
  918. }
  919. /**
  920. * mctime_update_needed - check if mtime or ctime update is needed.
  921. * @inode: the inode to do the check for
  922. * @now: current time
  923. *
  924. * This helper function checks if the inode mtime/ctime should be updated or
  925. * not. If current values of the time-stamps are within the UBIFS inode time
  926. * granularity, they are not updated. This is an optimization.
  927. */
  928. static inline int mctime_update_needed(const struct inode *inode,
  929. const struct timespec *now)
  930. {
  931. if (!timespec_equal(&inode->i_mtime, now) ||
  932. !timespec_equal(&inode->i_ctime, now))
  933. return 1;
  934. return 0;
  935. }
  936. /**
  937. * update_ctime - update mtime and ctime of an inode.
  938. * @c: UBIFS file-system description object
  939. * @inode: inode to update
  940. *
  941. * This function updates mtime and ctime of the inode if it is not equivalent to
  942. * current time. Returns zero in case of success and a negative error code in
  943. * case of failure.
  944. */
  945. static int update_mctime(struct ubifs_info *c, struct inode *inode)
  946. {
  947. struct timespec now = ubifs_current_time(inode);
  948. struct ubifs_inode *ui = ubifs_inode(inode);
  949. if (mctime_update_needed(inode, &now)) {
  950. int err, release;
  951. struct ubifs_budget_req req = { .dirtied_ino = 1,
  952. .dirtied_ino_d = ALIGN(ui->data_len, 8) };
  953. err = ubifs_budget_space(c, &req);
  954. if (err)
  955. return err;
  956. mutex_lock(&ui->ui_mutex);
  957. inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
  958. release = ui->dirty;
  959. mark_inode_dirty_sync(inode);
  960. mutex_unlock(&ui->ui_mutex);
  961. if (release)
  962. ubifs_release_budget(c, &req);
  963. }
  964. return 0;
  965. }
  966. static ssize_t ubifs_aio_write(struct kiocb *iocb, const struct iovec *iov,
  967. unsigned long nr_segs, loff_t pos)
  968. {
  969. int err;
  970. ssize_t ret;
  971. struct inode *inode = iocb->ki_filp->f_mapping->host;
  972. struct ubifs_info *c = inode->i_sb->s_fs_info;
  973. err = update_mctime(c, inode);
  974. if (err)
  975. return err;
  976. ret = generic_file_aio_write(iocb, iov, nr_segs, pos);
  977. if (ret < 0)
  978. return ret;
  979. if (ret > 0 && (IS_SYNC(inode) || iocb->ki_filp->f_flags & O_SYNC)) {
  980. err = ubifs_sync_wbufs_by_inode(c, inode);
  981. if (err)
  982. return err;
  983. }
  984. return ret;
  985. }
  986. static int ubifs_set_page_dirty(struct page *page)
  987. {
  988. int ret;
  989. ret = __set_page_dirty_nobuffers(page);
  990. /*
  991. * An attempt to dirty a page without budgeting for it - should not
  992. * happen.
  993. */
  994. ubifs_assert(ret == 0);
  995. return ret;
  996. }
  997. static int ubifs_releasepage(struct page *page, gfp_t unused_gfp_flags)
  998. {
  999. /*
  1000. * An attempt to release a dirty page without budgeting for it - should
  1001. * not happen.
  1002. */
  1003. if (PageWriteback(page))
  1004. return 0;
  1005. ubifs_assert(PagePrivate(page));
  1006. ubifs_assert(0);
  1007. ClearPagePrivate(page);
  1008. ClearPageChecked(page);
  1009. return 1;
  1010. }
  1011. /*
  1012. * mmap()d file has taken write protection fault and is being made
  1013. * writable. UBIFS must ensure page is budgeted for.
  1014. */
  1015. static int ubifs_vm_page_mkwrite(struct vm_area_struct *vma, struct page *page)
  1016. {
  1017. struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
  1018. struct ubifs_info *c = inode->i_sb->s_fs_info;
  1019. struct timespec now = ubifs_current_time(inode);
  1020. struct ubifs_budget_req req = { .new_page = 1 };
  1021. int err, update_time;
  1022. dbg_gen("ino %lu, pg %lu, i_size %lld", inode->i_ino, page->index,
  1023. i_size_read(inode));
  1024. ubifs_assert(!(inode->i_sb->s_flags & MS_RDONLY));
  1025. if (unlikely(c->ro_media))
  1026. return -EROFS;
  1027. /*
  1028. * We have not locked @page so far so we may budget for changing the
  1029. * page. Note, we cannot do this after we locked the page, because
  1030. * budgeting may cause write-back which would cause deadlock.
  1031. *
  1032. * At the moment we do not know whether the page is dirty or not, so we
  1033. * assume that it is not and budget for a new page. We could look at
  1034. * the @PG_private flag and figure this out, but we may race with write
  1035. * back and the page state may change by the time we lock it, so this
  1036. * would need additional care. We do not bother with this at the
  1037. * moment, although it might be good idea to do. Instead, we allocate
  1038. * budget for a new page and amend it later on if the page was in fact
  1039. * dirty.
  1040. *
  1041. * The budgeting-related logic of this function is similar to what we
  1042. * do in 'ubifs_write_begin()' and 'ubifs_write_end()'. Glance there
  1043. * for more comments.
  1044. */
  1045. update_time = mctime_update_needed(inode, &now);
  1046. if (update_time)
  1047. /*
  1048. * We have to change inode time stamp which requires extra
  1049. * budgeting.
  1050. */
  1051. req.dirtied_ino = 1;
  1052. err = ubifs_budget_space(c, &req);
  1053. if (unlikely(err)) {
  1054. if (err == -ENOSPC)
  1055. ubifs_warn("out of space for mmapped file "
  1056. "(inode number %lu)", inode->i_ino);
  1057. return err;
  1058. }
  1059. lock_page(page);
  1060. if (unlikely(page->mapping != inode->i_mapping ||
  1061. page_offset(page) > i_size_read(inode))) {
  1062. /* Page got truncated out from underneath us */
  1063. err = -EINVAL;
  1064. goto out_unlock;
  1065. }
  1066. if (PagePrivate(page))
  1067. release_new_page_budget(c);
  1068. else {
  1069. if (!PageChecked(page))
  1070. ubifs_convert_page_budget(c);
  1071. SetPagePrivate(page);
  1072. atomic_long_inc(&c->dirty_pg_cnt);
  1073. __set_page_dirty_nobuffers(page);
  1074. }
  1075. if (update_time) {
  1076. int release;
  1077. struct ubifs_inode *ui = ubifs_inode(inode);
  1078. mutex_lock(&ui->ui_mutex);
  1079. inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
  1080. release = ui->dirty;
  1081. mark_inode_dirty_sync(inode);
  1082. mutex_unlock(&ui->ui_mutex);
  1083. if (release)
  1084. ubifs_release_dirty_inode_budget(c, ui);
  1085. }
  1086. unlock_page(page);
  1087. return 0;
  1088. out_unlock:
  1089. unlock_page(page);
  1090. ubifs_release_budget(c, &req);
  1091. return err;
  1092. }
  1093. static struct vm_operations_struct ubifs_file_vm_ops = {
  1094. .fault = filemap_fault,
  1095. .page_mkwrite = ubifs_vm_page_mkwrite,
  1096. };
  1097. static int ubifs_file_mmap(struct file *file, struct vm_area_struct *vma)
  1098. {
  1099. int err;
  1100. /* 'generic_file_mmap()' takes care of NOMMU case */
  1101. err = generic_file_mmap(file, vma);
  1102. if (err)
  1103. return err;
  1104. vma->vm_ops = &ubifs_file_vm_ops;
  1105. return 0;
  1106. }
  1107. struct address_space_operations ubifs_file_address_operations = {
  1108. .readpage = ubifs_readpage,
  1109. .writepage = ubifs_writepage,
  1110. .write_begin = ubifs_write_begin,
  1111. .write_end = ubifs_write_end,
  1112. .invalidatepage = ubifs_invalidatepage,
  1113. .set_page_dirty = ubifs_set_page_dirty,
  1114. .releasepage = ubifs_releasepage,
  1115. };
  1116. struct inode_operations ubifs_file_inode_operations = {
  1117. .setattr = ubifs_setattr,
  1118. .getattr = ubifs_getattr,
  1119. #ifdef CONFIG_UBIFS_FS_XATTR
  1120. .setxattr = ubifs_setxattr,
  1121. .getxattr = ubifs_getxattr,
  1122. .listxattr = ubifs_listxattr,
  1123. .removexattr = ubifs_removexattr,
  1124. #endif
  1125. };
  1126. struct inode_operations ubifs_symlink_inode_operations = {
  1127. .readlink = generic_readlink,
  1128. .follow_link = ubifs_follow_link,
  1129. .setattr = ubifs_setattr,
  1130. .getattr = ubifs_getattr,
  1131. };
  1132. struct file_operations ubifs_file_operations = {
  1133. .llseek = generic_file_llseek,
  1134. .read = do_sync_read,
  1135. .write = do_sync_write,
  1136. .aio_read = generic_file_aio_read,
  1137. .aio_write = ubifs_aio_write,
  1138. .mmap = ubifs_file_mmap,
  1139. .fsync = ubifs_fsync,
  1140. .unlocked_ioctl = ubifs_ioctl,
  1141. .splice_read = generic_file_splice_read,
  1142. .splice_write = generic_file_splice_write,
  1143. #ifdef CONFIG_COMPAT
  1144. .compat_ioctl = ubifs_compat_ioctl,
  1145. #endif
  1146. };