file.c 37 KB

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