file.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  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);
  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. return err;
  734. err = vmtruncate(inode, new_size);
  735. if (err)
  736. goto out_budg;
  737. if (offset) {
  738. pgoff_t index = new_size >> PAGE_CACHE_SHIFT;
  739. struct page *page;
  740. page = find_lock_page(inode->i_mapping, index);
  741. if (page) {
  742. if (PageDirty(page)) {
  743. /*
  744. * 'ubifs_jnl_truncate()' will try to truncate
  745. * the last data node, but it contains
  746. * out-of-date data because the page is dirty.
  747. * Write the page now, so that
  748. * 'ubifs_jnl_truncate()' will see an already
  749. * truncated (and up to date) data node.
  750. */
  751. ubifs_assert(PagePrivate(page));
  752. clear_page_dirty_for_io(page);
  753. if (UBIFS_BLOCKS_PER_PAGE_SHIFT)
  754. offset = new_size &
  755. (PAGE_CACHE_SIZE - 1);
  756. err = do_writepage(page, offset);
  757. page_cache_release(page);
  758. if (err)
  759. goto out_budg;
  760. /*
  761. * We could now tell 'ubifs_jnl_truncate()' not
  762. * to read the last block.
  763. */
  764. } else {
  765. /*
  766. * We could 'kmap()' the page and pass the data
  767. * to 'ubifs_jnl_truncate()' to save it from
  768. * having to read it.
  769. */
  770. unlock_page(page);
  771. page_cache_release(page);
  772. }
  773. }
  774. }
  775. mutex_lock(&ui->ui_mutex);
  776. ui->ui_size = inode->i_size;
  777. /* Truncation changes inode [mc]time */
  778. inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
  779. /* The other attributes may be changed at the same time as well */
  780. do_attr_changes(inode, attr);
  781. err = ubifs_jnl_truncate(c, inode, old_size, new_size);
  782. mutex_unlock(&ui->ui_mutex);
  783. out_budg:
  784. ubifs_release_budget(c, &req);
  785. return err;
  786. }
  787. /**
  788. * do_setattr - change inode attributes.
  789. * @c: UBIFS file-system description object
  790. * @inode: inode to change attributes for
  791. * @attr: inode attribute changes description
  792. *
  793. * This function implements VFS '->setattr()' call for all cases except
  794. * truncations to smaller size. Returns zero in case of success and a negative
  795. * error code in case of failure.
  796. */
  797. static int do_setattr(struct ubifs_info *c, struct inode *inode,
  798. const struct iattr *attr)
  799. {
  800. int err, release;
  801. loff_t new_size = attr->ia_size;
  802. struct ubifs_inode *ui = ubifs_inode(inode);
  803. struct ubifs_budget_req req = { .dirtied_ino = 1,
  804. .dirtied_ino_d = ui->data_len };
  805. err = ubifs_budget_space(c, &req);
  806. if (err)
  807. return err;
  808. if (attr->ia_valid & ATTR_SIZE) {
  809. dbg_gen("size %lld -> %lld", inode->i_size, new_size);
  810. err = vmtruncate(inode, new_size);
  811. if (err)
  812. goto out;
  813. }
  814. mutex_lock(&ui->ui_mutex);
  815. if (attr->ia_valid & ATTR_SIZE) {
  816. /* Truncation changes inode [mc]time */
  817. inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
  818. /* 'vmtruncate()' changed @i_size, update @ui_size */
  819. ui->ui_size = inode->i_size;
  820. }
  821. do_attr_changes(inode, attr);
  822. release = ui->dirty;
  823. if (attr->ia_valid & ATTR_SIZE)
  824. /*
  825. * Inode length changed, so we have to make sure
  826. * @I_DIRTY_DATASYNC is set.
  827. */
  828. __mark_inode_dirty(inode, I_DIRTY_SYNC | I_DIRTY_DATASYNC);
  829. else
  830. mark_inode_dirty_sync(inode);
  831. mutex_unlock(&ui->ui_mutex);
  832. if (release)
  833. ubifs_release_budget(c, &req);
  834. if (IS_SYNC(inode))
  835. err = inode->i_sb->s_op->write_inode(inode, 1);
  836. return err;
  837. out:
  838. ubifs_release_budget(c, &req);
  839. return err;
  840. }
  841. int ubifs_setattr(struct dentry *dentry, struct iattr *attr)
  842. {
  843. int err;
  844. struct inode *inode = dentry->d_inode;
  845. struct ubifs_info *c = inode->i_sb->s_fs_info;
  846. dbg_gen("ino %lu, ia_valid %#x", inode->i_ino, attr->ia_valid);
  847. err = inode_change_ok(inode, attr);
  848. if (err)
  849. return err;
  850. err = dbg_check_synced_i_size(inode);
  851. if (err)
  852. return err;
  853. if ((attr->ia_valid & ATTR_SIZE) && attr->ia_size < inode->i_size)
  854. /* Truncation to a smaller size */
  855. err = do_truncation(c, inode, attr);
  856. else
  857. err = do_setattr(c, inode, attr);
  858. return err;
  859. }
  860. static void ubifs_invalidatepage(struct page *page, unsigned long offset)
  861. {
  862. struct inode *inode = page->mapping->host;
  863. struct ubifs_info *c = inode->i_sb->s_fs_info;
  864. ubifs_assert(PagePrivate(page));
  865. if (offset)
  866. /* Partial page remains dirty */
  867. return;
  868. if (PageChecked(page))
  869. release_new_page_budget(c);
  870. else
  871. release_existing_page_budget(c);
  872. atomic_long_dec(&c->dirty_pg_cnt);
  873. ClearPagePrivate(page);
  874. ClearPageChecked(page);
  875. }
  876. static void *ubifs_follow_link(struct dentry *dentry, struct nameidata *nd)
  877. {
  878. struct ubifs_inode *ui = ubifs_inode(dentry->d_inode);
  879. nd_set_link(nd, ui->data);
  880. return NULL;
  881. }
  882. int ubifs_fsync(struct file *file, struct dentry *dentry, int datasync)
  883. {
  884. struct inode *inode = dentry->d_inode;
  885. struct ubifs_info *c = inode->i_sb->s_fs_info;
  886. int err;
  887. dbg_gen("syncing inode %lu", inode->i_ino);
  888. /*
  889. * VFS has already synchronized dirty pages for this inode. Synchronize
  890. * the inode unless this is a 'datasync()' call.
  891. */
  892. if (!datasync || (inode->i_state & I_DIRTY_DATASYNC)) {
  893. err = inode->i_sb->s_op->write_inode(inode, 1);
  894. if (err)
  895. return err;
  896. }
  897. /*
  898. * Nodes related to this inode may still sit in a write-buffer. Flush
  899. * them.
  900. */
  901. err = ubifs_sync_wbufs_by_inode(c, inode);
  902. if (err)
  903. return err;
  904. return 0;
  905. }
  906. /**
  907. * mctime_update_needed - check if mtime or ctime update is needed.
  908. * @inode: the inode to do the check for
  909. * @now: current time
  910. *
  911. * This helper function checks if the inode mtime/ctime should be updated or
  912. * not. If current values of the time-stamps are within the UBIFS inode time
  913. * granularity, they are not updated. This is an optimization.
  914. */
  915. static inline int mctime_update_needed(const struct inode *inode,
  916. const struct timespec *now)
  917. {
  918. if (!timespec_equal(&inode->i_mtime, now) ||
  919. !timespec_equal(&inode->i_ctime, now))
  920. return 1;
  921. return 0;
  922. }
  923. /**
  924. * update_ctime - update mtime and ctime of an inode.
  925. * @c: UBIFS file-system description object
  926. * @inode: inode to update
  927. *
  928. * This function updates mtime and ctime of the inode if it is not equivalent to
  929. * current time. Returns zero in case of success and a negative error code in
  930. * case of failure.
  931. */
  932. static int update_mctime(struct ubifs_info *c, struct inode *inode)
  933. {
  934. struct timespec now = ubifs_current_time(inode);
  935. struct ubifs_inode *ui = ubifs_inode(inode);
  936. if (mctime_update_needed(inode, &now)) {
  937. int err, release;
  938. struct ubifs_budget_req req = { .dirtied_ino = 1,
  939. .dirtied_ino_d = ui->data_len };
  940. err = ubifs_budget_space(c, &req);
  941. if (err)
  942. return err;
  943. mutex_lock(&ui->ui_mutex);
  944. inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
  945. release = ui->dirty;
  946. mark_inode_dirty_sync(inode);
  947. mutex_unlock(&ui->ui_mutex);
  948. if (release)
  949. ubifs_release_budget(c, &req);
  950. }
  951. return 0;
  952. }
  953. static ssize_t ubifs_aio_write(struct kiocb *iocb, const struct iovec *iov,
  954. unsigned long nr_segs, loff_t pos)
  955. {
  956. int err;
  957. ssize_t ret;
  958. struct inode *inode = iocb->ki_filp->f_mapping->host;
  959. struct ubifs_info *c = inode->i_sb->s_fs_info;
  960. err = update_mctime(c, inode);
  961. if (err)
  962. return err;
  963. ret = generic_file_aio_write(iocb, iov, nr_segs, pos);
  964. if (ret < 0)
  965. return ret;
  966. if (ret > 0 && (IS_SYNC(inode) || iocb->ki_filp->f_flags & O_SYNC)) {
  967. err = ubifs_sync_wbufs_by_inode(c, inode);
  968. if (err)
  969. return err;
  970. }
  971. return ret;
  972. }
  973. static int ubifs_set_page_dirty(struct page *page)
  974. {
  975. int ret;
  976. ret = __set_page_dirty_nobuffers(page);
  977. /*
  978. * An attempt to dirty a page without budgeting for it - should not
  979. * happen.
  980. */
  981. ubifs_assert(ret == 0);
  982. return ret;
  983. }
  984. static int ubifs_releasepage(struct page *page, gfp_t unused_gfp_flags)
  985. {
  986. /*
  987. * An attempt to release a dirty page without budgeting for it - should
  988. * not happen.
  989. */
  990. if (PageWriteback(page))
  991. return 0;
  992. ubifs_assert(PagePrivate(page));
  993. ubifs_assert(0);
  994. ClearPagePrivate(page);
  995. ClearPageChecked(page);
  996. return 1;
  997. }
  998. /*
  999. * mmap()d file has taken write protection fault and is being made
  1000. * writable. UBIFS must ensure page is budgeted for.
  1001. */
  1002. static int ubifs_vm_page_mkwrite(struct vm_area_struct *vma, struct page *page)
  1003. {
  1004. struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
  1005. struct ubifs_info *c = inode->i_sb->s_fs_info;
  1006. struct timespec now = ubifs_current_time(inode);
  1007. struct ubifs_budget_req req = { .new_page = 1 };
  1008. int err, update_time;
  1009. dbg_gen("ino %lu, pg %lu, i_size %lld", inode->i_ino, page->index,
  1010. i_size_read(inode));
  1011. ubifs_assert(!(inode->i_sb->s_flags & MS_RDONLY));
  1012. if (unlikely(c->ro_media))
  1013. return -EROFS;
  1014. /*
  1015. * We have not locked @page so far so we may budget for changing the
  1016. * page. Note, we cannot do this after we locked the page, because
  1017. * budgeting may cause write-back which would cause deadlock.
  1018. *
  1019. * At the moment we do not know whether the page is dirty or not, so we
  1020. * assume that it is not and budget for a new page. We could look at
  1021. * the @PG_private flag and figure this out, but we may race with write
  1022. * back and the page state may change by the time we lock it, so this
  1023. * would need additional care. We do not bother with this at the
  1024. * moment, although it might be good idea to do. Instead, we allocate
  1025. * budget for a new page and amend it later on if the page was in fact
  1026. * dirty.
  1027. *
  1028. * The budgeting-related logic of this function is similar to what we
  1029. * do in 'ubifs_write_begin()' and 'ubifs_write_end()'. Glance there
  1030. * for more comments.
  1031. */
  1032. update_time = mctime_update_needed(inode, &now);
  1033. if (update_time)
  1034. /*
  1035. * We have to change inode time stamp which requires extra
  1036. * budgeting.
  1037. */
  1038. req.dirtied_ino = 1;
  1039. err = ubifs_budget_space(c, &req);
  1040. if (unlikely(err)) {
  1041. if (err == -ENOSPC)
  1042. ubifs_warn("out of space for mmapped file "
  1043. "(inode number %lu)", inode->i_ino);
  1044. return err;
  1045. }
  1046. lock_page(page);
  1047. if (unlikely(page->mapping != inode->i_mapping ||
  1048. page_offset(page) > i_size_read(inode))) {
  1049. /* Page got truncated out from underneath us */
  1050. err = -EINVAL;
  1051. goto out_unlock;
  1052. }
  1053. if (PagePrivate(page))
  1054. release_new_page_budget(c);
  1055. else {
  1056. if (!PageChecked(page))
  1057. ubifs_convert_page_budget(c);
  1058. SetPagePrivate(page);
  1059. atomic_long_inc(&c->dirty_pg_cnt);
  1060. __set_page_dirty_nobuffers(page);
  1061. }
  1062. if (update_time) {
  1063. int release;
  1064. struct ubifs_inode *ui = ubifs_inode(inode);
  1065. mutex_lock(&ui->ui_mutex);
  1066. inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
  1067. release = ui->dirty;
  1068. mark_inode_dirty_sync(inode);
  1069. mutex_unlock(&ui->ui_mutex);
  1070. if (release)
  1071. ubifs_release_dirty_inode_budget(c, ui);
  1072. }
  1073. unlock_page(page);
  1074. return 0;
  1075. out_unlock:
  1076. unlock_page(page);
  1077. ubifs_release_budget(c, &req);
  1078. return err;
  1079. }
  1080. static struct vm_operations_struct ubifs_file_vm_ops = {
  1081. .fault = filemap_fault,
  1082. .page_mkwrite = ubifs_vm_page_mkwrite,
  1083. };
  1084. static int ubifs_file_mmap(struct file *file, struct vm_area_struct *vma)
  1085. {
  1086. int err;
  1087. /* 'generic_file_mmap()' takes care of NOMMU case */
  1088. err = generic_file_mmap(file, vma);
  1089. if (err)
  1090. return err;
  1091. vma->vm_ops = &ubifs_file_vm_ops;
  1092. return 0;
  1093. }
  1094. struct address_space_operations ubifs_file_address_operations = {
  1095. .readpage = ubifs_readpage,
  1096. .writepage = ubifs_writepage,
  1097. .write_begin = ubifs_write_begin,
  1098. .write_end = ubifs_write_end,
  1099. .invalidatepage = ubifs_invalidatepage,
  1100. .set_page_dirty = ubifs_set_page_dirty,
  1101. .releasepage = ubifs_releasepage,
  1102. };
  1103. struct inode_operations ubifs_file_inode_operations = {
  1104. .setattr = ubifs_setattr,
  1105. .getattr = ubifs_getattr,
  1106. #ifdef CONFIG_UBIFS_FS_XATTR
  1107. .setxattr = ubifs_setxattr,
  1108. .getxattr = ubifs_getxattr,
  1109. .listxattr = ubifs_listxattr,
  1110. .removexattr = ubifs_removexattr,
  1111. #endif
  1112. };
  1113. struct inode_operations ubifs_symlink_inode_operations = {
  1114. .readlink = generic_readlink,
  1115. .follow_link = ubifs_follow_link,
  1116. .setattr = ubifs_setattr,
  1117. .getattr = ubifs_getattr,
  1118. };
  1119. struct file_operations ubifs_file_operations = {
  1120. .llseek = generic_file_llseek,
  1121. .read = do_sync_read,
  1122. .write = do_sync_write,
  1123. .aio_read = generic_file_aio_read,
  1124. .aio_write = ubifs_aio_write,
  1125. .mmap = ubifs_file_mmap,
  1126. .fsync = ubifs_fsync,
  1127. .unlocked_ioctl = ubifs_ioctl,
  1128. .splice_read = generic_file_splice_read,
  1129. #ifdef CONFIG_COMPAT
  1130. .compat_ioctl = ubifs_compat_ioctl,
  1131. #endif
  1132. };