2 * This file is part of UBIFS.
4 * Copyright (C) 2006-2008 Nokia Corporation.
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.
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
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
19 * Authors: Artem Bityutskiy (Битюцкий Артём)
24 * This file implements VFS file and inode operations for regular files, device
25 * nodes and symlinks as well as address space operations.
27 * UBIFS uses 2 page flags: @PG_private and @PG_checked. @PG_private is set if
28 * the page is dirty and is used for optimization purposes - dirty pages are
29 * not budgeted so the flag shows that 'ubifs_write_end()' should not release
30 * the budget for this page. The @PG_checked flag is set if full budgeting is
31 * required for the page e.g., when it corresponds to a file hole or it is
32 * beyond the file size. The budgeting is done in 'ubifs_write_begin()', because
33 * it is OK to fail in this function, and the budget is released in
34 * 'ubifs_write_end()'. So the @PG_private and @PG_checked flags carry
35 * information about how the page was budgeted, to make it possible to release
36 * the budget properly.
38 * A thing to keep in mind: inode @i_mutex is locked in most VFS operations we
39 * implement. However, this is not true for 'ubifs_writepage()', which may be
40 * called with @i_mutex unlocked. For example, when flusher thread is doing
41 * background write-back, it calls 'ubifs_writepage()' with unlocked @i_mutex.
42 * At "normal" work-paths the @i_mutex is locked in 'ubifs_writepage()', e.g.
43 * in the "sys_write -> alloc_pages -> direct reclaim path". So, in
44 * 'ubifs_writepage()' we are only guaranteed that the page is locked.
46 * Similarly, @i_mutex is not always locked in 'ubifs_readpage()', e.g., the
47 * read-ahead path does not lock it ("sys_read -> generic_file_aio_read ->
48 * ondemand_readahead -> readpage"). In case of readahead, @I_SYNC flag is not
49 * set as well. However, UBIFS disables readahead.
53 #include <linux/aio.h>
54 #include <linux/mount.h>
55 #include <linux/namei.h>
56 #include <linux/slab.h>
58 static int read_block(struct inode
*inode
, void *addr
, unsigned int block
,
59 struct ubifs_data_node
*dn
)
61 struct ubifs_info
*c
= inode
->i_sb
->s_fs_info
;
62 int err
, len
, out_len
;
66 data_key_init(c
, &key
, inode
->i_ino
, block
);
67 err
= ubifs_tnc_lookup(c
, &key
, dn
);
70 /* Not found, so it must be a hole */
71 memset(addr
, 0, UBIFS_BLOCK_SIZE
);
75 ubifs_assert(le64_to_cpu(dn
->ch
.sqnum
) >
76 ubifs_inode(inode
)->creat_sqnum
);
77 len
= le32_to_cpu(dn
->size
);
78 if (len
<= 0 || len
> UBIFS_BLOCK_SIZE
)
81 dlen
= le32_to_cpu(dn
->ch
.len
) - UBIFS_DATA_NODE_SZ
;
83 if (UBIFS_COMPR_LZ4K
== le16_to_cpu(dn
->compr_type
))
84 out_len
= len
; //Jack modify for lz4k decompress
86 out_len
= UBIFS_BLOCK_SIZE
;
87 err
= ubifs_decompress(&dn
->data
, dlen
, addr
, &out_len
,
88 le16_to_cpu(dn
->compr_type
));
89 if (err
|| len
!= out_len
)
93 * Data length can be less than a full block, even for blocks that are
94 * not the last in the file (e.g., as a result of making a hole and
95 * appending data). Ensure that the remainder is zeroed out.
97 if (len
< UBIFS_BLOCK_SIZE
)
98 memset(addr
+ len
, 0, UBIFS_BLOCK_SIZE
- len
);
103 ubifs_err("bad data node (block %u, inode %lu)",
104 block
, inode
->i_ino
);
105 ubifs_dump_node(c
, dn
);
109 static int do_readpage(struct page
*page
)
113 unsigned int block
, beyond
;
114 struct ubifs_data_node
*dn
;
115 struct inode
*inode
= page
->mapping
->host
;
116 loff_t i_size
= i_size_read(inode
);
118 dbg_gen("ino %lu, pg %lu, i_size %lld, flags %#lx",
119 inode
->i_ino
, page
->index
, i_size
, page
->flags
);
120 ubifs_assert(!PageChecked(page
));
121 ubifs_assert(!PagePrivate(page
));
125 block
= page
->index
<< UBIFS_BLOCKS_PER_PAGE_SHIFT
;
126 beyond
= (i_size
+ UBIFS_BLOCK_SIZE
- 1) >> UBIFS_BLOCK_SHIFT
;
127 if (block
>= beyond
) {
128 /* Reading beyond inode */
129 SetPageChecked(page
);
130 memset(addr
, 0, PAGE_CACHE_SIZE
);
134 dn
= kmalloc(UBIFS_MAX_DATA_NODE_SZ
, GFP_NOFS
);
144 if (block
>= beyond
) {
145 /* Reading beyond inode */
147 memset(addr
, 0, UBIFS_BLOCK_SIZE
);
149 ret
= read_block(inode
, addr
, block
, dn
);
154 } else if (block
+ 1 == beyond
) {
155 int dlen
= le32_to_cpu(dn
->size
);
156 int ilen
= i_size
& (UBIFS_BLOCK_SIZE
- 1);
158 if (ilen
&& ilen
< dlen
)
159 memset(addr
+ ilen
, 0, dlen
- ilen
);
162 if (++i
>= UBIFS_BLOCKS_PER_PAGE
)
165 addr
+= UBIFS_BLOCK_SIZE
;
168 if (err
== -ENOENT
) {
169 /* Not found, so it must be a hole */
170 SetPageChecked(page
);
174 ubifs_err("cannot read page %lu of inode %lu, error %d",
175 page
->index
, inode
->i_ino
, err
);
182 SetPageUptodate(page
);
183 ClearPageError(page
);
184 flush_dcache_page(page
);
190 ClearPageUptodate(page
);
192 flush_dcache_page(page
);
198 * release_new_page_budget - release budget of a new page.
199 * @c: UBIFS file-system description object
201 * This is a helper function which releases budget corresponding to the budget
202 * of one new page of data.
204 static void release_new_page_budget(struct ubifs_info
*c
)
206 struct ubifs_budget_req req
= { .recalculate
= 1, .new_page
= 1 };
208 ubifs_release_budget(c
, &req
);
212 * release_existing_page_budget - release budget of an existing page.
213 * @c: UBIFS file-system description object
215 * This is a helper function which releases budget corresponding to the budget
216 * of changing one one page of data which already exists on the flash media.
218 static void release_existing_page_budget(struct ubifs_info
*c
)
220 struct ubifs_budget_req req
= { .dd_growth
= c
->bi
.page_budget
};
222 ubifs_release_budget(c
, &req
);
225 static int write_begin_slow(struct address_space
*mapping
,
226 loff_t pos
, unsigned len
, struct page
**pagep
,
229 struct inode
*inode
= mapping
->host
;
230 struct ubifs_info
*c
= inode
->i_sb
->s_fs_info
;
231 pgoff_t index
= pos
>> PAGE_CACHE_SHIFT
;
232 struct ubifs_budget_req req
= { .new_page
= 1 };
233 int uninitialized_var(err
), appending
= !!(pos
+ len
> inode
->i_size
);
236 dbg_gen("ino %lu, pos %llu, len %u, i_size %lld",
237 inode
->i_ino
, pos
, len
, inode
->i_size
);
240 * At the slow path we have to budget before locking the page, because
241 * budgeting may force write-back, which would wait on locked pages and
242 * deadlock if we had the page locked. At this point we do not know
243 * anything about the page, so assume that this is a new page which is
244 * written to a hole. This corresponds to largest budget. Later the
245 * budget will be amended if this is not true.
248 /* We are appending data, budget for inode change */
251 err
= ubifs_budget_space(c
, &req
);
255 page
= grab_cache_page_write_begin(mapping
, index
, flags
);
256 if (unlikely(!page
)) {
257 ubifs_release_budget(c
, &req
);
261 if (!PageUptodate(page
)) {
262 if (!(pos
& ~PAGE_CACHE_MASK
) && len
== PAGE_CACHE_SIZE
)
263 SetPageChecked(page
);
265 err
= do_readpage(page
);
268 page_cache_release(page
);
273 SetPageUptodate(page
);
274 ClearPageError(page
);
277 if (PagePrivate(page
))
279 * The page is dirty, which means it was budgeted twice:
280 * o first time the budget was allocated by the task which
281 * made the page dirty and set the PG_private flag;
282 * o and then we budgeted for it for the second time at the
283 * very beginning of this function.
285 * So what we have to do is to release the page budget we
288 release_new_page_budget(c
);
289 else if (!PageChecked(page
))
291 * We are changing a page which already exists on the media.
292 * This means that changing the page does not make the amount
293 * of indexing information larger, and this part of the budget
294 * which we have already acquired may be released.
296 ubifs_convert_page_budget(c
);
299 struct ubifs_inode
*ui
= ubifs_inode(inode
);
302 * 'ubifs_write_end()' is optimized from the fast-path part of
303 * 'ubifs_write_begin()' and expects the @ui_mutex to be locked
304 * if data is appended.
306 mutex_lock(&ui
->ui_mutex
);
309 * The inode is dirty already, so we may free the
310 * budget we allocated.
312 ubifs_release_dirty_inode_budget(c
, ui
);
320 * allocate_budget - allocate budget for 'ubifs_write_begin()'.
321 * @c: UBIFS file-system description object
322 * @page: page to allocate budget for
323 * @ui: UBIFS inode object the page belongs to
324 * @appending: non-zero if the page is appended
326 * This is a helper function for 'ubifs_write_begin()' which allocates budget
327 * for the operation. The budget is allocated differently depending on whether
328 * this is appending, whether the page is dirty or not, and so on. This
329 * function leaves the @ui->ui_mutex locked in case of appending. Returns zero
330 * in case of success and %-ENOSPC in case of failure.
332 static int allocate_budget(struct ubifs_info
*c
, struct page
*page
,
333 struct ubifs_inode
*ui
, int appending
)
335 struct ubifs_budget_req req
= { .fast
= 1 };
337 if (PagePrivate(page
)) {
340 * The page is dirty and we are not appending, which
341 * means no budget is needed at all.
345 mutex_lock(&ui
->ui_mutex
);
348 * The page is dirty and we are appending, so the inode
349 * has to be marked as dirty. However, it is already
350 * dirty, so we do not need any budget. We may return,
351 * but @ui->ui_mutex hast to be left locked because we
352 * should prevent write-back from flushing the inode
353 * and freeing the budget. The lock will be released in
354 * 'ubifs_write_end()'.
359 * The page is dirty, we are appending, the inode is clean, so
360 * we need to budget the inode change.
364 if (PageChecked(page
))
366 * The page corresponds to a hole and does not
367 * exist on the media. So changing it makes
368 * make the amount of indexing information
369 * larger, and we have to budget for a new
375 * Not a hole, the change will not add any new
376 * indexing information, budget for page
379 req
.dirtied_page
= 1;
382 mutex_lock(&ui
->ui_mutex
);
385 * The inode is clean but we will have to mark
386 * it as dirty because we are appending. This
393 return ubifs_budget_space(c
, &req
);
397 * This function is called when a page of data is going to be written. Since
398 * the page of data will not necessarily go to the flash straight away, UBIFS
399 * has to reserve space on the media for it, which is done by means of
402 * This is the hot-path of the file-system and we are trying to optimize it as
403 * much as possible. For this reasons it is split on 2 parts - slow and fast.
405 * There many budgeting cases:
406 * o a new page is appended - we have to budget for a new page and for
407 * changing the inode; however, if the inode is already dirty, there is
408 * no need to budget for it;
409 * o an existing clean page is changed - we have budget for it; if the page
410 * does not exist on the media (a hole), we have to budget for a new
411 * page; otherwise, we may budget for changing an existing page; the
412 * difference between these cases is that changing an existing page does
413 * not introduce anything new to the FS indexing information, so it does
414 * not grow, and smaller budget is acquired in this case;
415 * o an existing dirty page is changed - no need to budget at all, because
416 * the page budget has been acquired by earlier, when the page has been
419 * UBIFS budgeting sub-system may force write-back if it thinks there is no
420 * space to reserve. This imposes some locking restrictions and makes it
421 * impossible to take into account the above cases, and makes it impossible to
422 * optimize budgeting.
424 * The solution for this is that the fast path of 'ubifs_write_begin()' assumes
425 * there is a plenty of flash space and the budget will be acquired quickly,
426 * without forcing write-back. The slow path does not make this assumption.
428 static int ubifs_write_begin(struct file
*file
, struct address_space
*mapping
,
429 loff_t pos
, unsigned len
, unsigned flags
,
430 struct page
**pagep
, void **fsdata
)
432 struct inode
*inode
= mapping
->host
;
433 struct ubifs_info
*c
= inode
->i_sb
->s_fs_info
;
434 struct ubifs_inode
*ui
= ubifs_inode(inode
);
435 pgoff_t index
= pos
>> PAGE_CACHE_SHIFT
;
436 int uninitialized_var(err
), appending
= !!(pos
+ len
> inode
->i_size
);
437 int skipped_read
= 0;
440 ubifs_assert(ubifs_inode(inode
)->ui_size
== inode
->i_size
);
441 ubifs_assert(!c
->ro_media
&& !c
->ro_mount
);
443 if (unlikely(c
->ro_error
))
446 /* Try out the fast-path part first */
447 page
= grab_cache_page_write_begin(mapping
, index
, flags
);
451 if (!PageUptodate(page
)) {
452 /* The page is not loaded from the flash */
453 if (!(pos
& ~PAGE_CACHE_MASK
) && len
== PAGE_CACHE_SIZE
) {
455 * We change whole page so no need to load it. But we
456 * do not know whether this page exists on the media or
457 * not, so we assume the latter because it requires
458 * larger budget. The assumption is that it is better
459 * to budget a bit more than to read the page from the
460 * media. Thus, we are setting the @PG_checked flag
463 SetPageChecked(page
);
466 err
= do_readpage(page
);
469 page_cache_release(page
);
474 SetPageUptodate(page
);
475 ClearPageError(page
);
478 err
= allocate_budget(c
, page
, ui
, appending
);
480 ubifs_assert(err
== -ENOSPC
);
482 * If we skipped reading the page because we were going to
483 * write all of it, then it is not up to date.
486 ClearPageChecked(page
);
487 ClearPageUptodate(page
);
490 * Budgeting failed which means it would have to force
491 * write-back but didn't, because we set the @fast flag in the
492 * request. Write-back cannot be done now, while we have the
493 * page locked, because it would deadlock. Unlock and free
494 * everything and fall-back to slow-path.
497 ubifs_assert(mutex_is_locked(&ui
->ui_mutex
));
498 mutex_unlock(&ui
->ui_mutex
);
501 page_cache_release(page
);
503 return write_begin_slow(mapping
, pos
, len
, pagep
, flags
);
507 * Whee, we acquired budgeting quickly - without involving
508 * garbage-collection, committing or forcing write-back. We return
509 * with @ui->ui_mutex locked if we are appending pages, and unlocked
510 * otherwise. This is an optimization (slightly hacky though).
518 * cancel_budget - cancel budget.
519 * @c: UBIFS file-system description object
520 * @page: page to cancel budget for
521 * @ui: UBIFS inode object the page belongs to
522 * @appending: non-zero if the page is appended
524 * This is a helper function for a page write operation. It unlocks the
525 * @ui->ui_mutex in case of appending.
527 static void cancel_budget(struct ubifs_info
*c
, struct page
*page
,
528 struct ubifs_inode
*ui
, int appending
)
532 ubifs_release_dirty_inode_budget(c
, ui
);
533 mutex_unlock(&ui
->ui_mutex
);
535 if (!PagePrivate(page
)) {
536 if (PageChecked(page
))
537 release_new_page_budget(c
);
539 release_existing_page_budget(c
);
543 static int ubifs_write_end(struct file
*file
, struct address_space
*mapping
,
544 loff_t pos
, unsigned len
, unsigned copied
,
545 struct page
*page
, void *fsdata
)
547 struct inode
*inode
= mapping
->host
;
548 struct ubifs_inode
*ui
= ubifs_inode(inode
);
549 struct ubifs_info
*c
= inode
->i_sb
->s_fs_info
;
550 loff_t end_pos
= pos
+ len
;
551 int appending
= !!(end_pos
> inode
->i_size
);
553 dbg_gen("ino %lu, pos %llu, pg %lu, len %u, copied %d, i_size %lld",
554 inode
->i_ino
, pos
, page
->index
, len
, copied
, inode
->i_size
);
556 if (unlikely(copied
< len
&& len
== PAGE_CACHE_SIZE
)) {
558 * VFS copied less data to the page that it intended and
559 * declared in its '->write_begin()' call via the @len
560 * argument. If the page was not up-to-date, and @len was
561 * @PAGE_CACHE_SIZE, the 'ubifs_write_begin()' function did
562 * not load it from the media (for optimization reasons). This
563 * means that part of the page contains garbage. So read the
566 dbg_gen("copied %d instead of %d, read page and repeat",
568 cancel_budget(c
, page
, ui
, appending
);
569 ClearPageChecked(page
);
572 * Return 0 to force VFS to repeat the whole operation, or the
573 * error code if 'do_readpage()' fails.
575 copied
= do_readpage(page
);
579 if (!PagePrivate(page
)) {
580 SetPagePrivate(page
);
581 atomic_long_inc(&c
->dirty_pg_cnt
);
582 __set_page_dirty_nobuffers(page
);
586 i_size_write(inode
, end_pos
);
587 ui
->ui_size
= end_pos
;
589 * Note, we do not set @I_DIRTY_PAGES (which means that the
590 * inode has dirty pages), this has been done in
591 * '__set_page_dirty_nobuffers()'.
593 __mark_inode_dirty(inode
, I_DIRTY_DATASYNC
);
594 ubifs_assert(mutex_is_locked(&ui
->ui_mutex
));
595 mutex_unlock(&ui
->ui_mutex
);
600 page_cache_release(page
);
605 * populate_page - copy data nodes into a page for bulk-read.
606 * @c: UBIFS file-system description object
608 * @bu: bulk-read information
609 * @n: next zbranch slot
611 * This function returns %0 on success and a negative error code on failure.
613 static int populate_page(struct ubifs_info
*c
, struct page
*page
,
614 struct bu_info
*bu
, int *n
)
616 int i
= 0, nn
= *n
, offs
= bu
->zbranch
[0].offs
, hole
= 0, read
= 0;
617 struct inode
*inode
= page
->mapping
->host
;
618 loff_t i_size
= i_size_read(inode
);
619 unsigned int page_block
;
623 dbg_gen("ino %lu, pg %lu, i_size %lld, flags %#lx",
624 inode
->i_ino
, page
->index
, i_size
, page
->flags
);
626 addr
= zaddr
= kmap(page
);
628 end_index
= (i_size
- 1) >> PAGE_CACHE_SHIFT
;
629 if (!i_size
|| page
->index
> end_index
) {
631 memset(addr
, 0, PAGE_CACHE_SIZE
);
635 page_block
= page
->index
<< UBIFS_BLOCKS_PER_PAGE_SHIFT
;
637 int err
, len
, out_len
, dlen
;
641 memset(addr
, 0, UBIFS_BLOCK_SIZE
);
642 } else if (key_block(c
, &bu
->zbranch
[nn
].key
) == page_block
) {
643 struct ubifs_data_node
*dn
;
645 dn
= bu
->buf
+ (bu
->zbranch
[nn
].offs
- offs
);
647 ubifs_assert(le64_to_cpu(dn
->ch
.sqnum
) >
648 ubifs_inode(inode
)->creat_sqnum
);
650 len
= le32_to_cpu(dn
->size
);
651 if (len
<= 0 || len
> UBIFS_BLOCK_SIZE
)
654 dlen
= le32_to_cpu(dn
->ch
.len
) - UBIFS_DATA_NODE_SZ
;
656 if (UBIFS_COMPR_LZ4K
== le16_to_cpu(dn
->compr_type
))
657 out_len
= len
; //Jack modify for lz4k decompress
659 out_len
= UBIFS_BLOCK_SIZE
;
660 err
= ubifs_decompress(&dn
->data
, dlen
, addr
, &out_len
,
661 le16_to_cpu(dn
->compr_type
));
662 if (err
|| len
!= out_len
)
665 if (len
< UBIFS_BLOCK_SIZE
)
666 memset(addr
+ len
, 0, UBIFS_BLOCK_SIZE
- len
);
669 read
= (i
<< UBIFS_BLOCK_SHIFT
) + len
;
670 } else if (key_block(c
, &bu
->zbranch
[nn
].key
) < page_block
) {
675 memset(addr
, 0, UBIFS_BLOCK_SIZE
);
677 if (++i
>= UBIFS_BLOCKS_PER_PAGE
)
679 addr
+= UBIFS_BLOCK_SIZE
;
683 if (end_index
== page
->index
) {
684 int len
= i_size
& (PAGE_CACHE_SIZE
- 1);
686 if (len
&& len
< read
)
687 memset(zaddr
+ len
, 0, read
- len
);
692 SetPageChecked(page
);
696 SetPageUptodate(page
);
697 ClearPageError(page
);
698 flush_dcache_page(page
);
704 ClearPageUptodate(page
);
706 flush_dcache_page(page
);
708 ubifs_err("bad data node (block %u, inode %lu)",
709 page_block
, inode
->i_ino
);
714 * ubifs_do_bulk_read - do bulk-read.
715 * @c: UBIFS file-system description object
716 * @bu: bulk-read information
717 * @page1: first page to read
719 * This function returns %1 if the bulk-read is done, otherwise %0 is returned.
721 static int ubifs_do_bulk_read(struct ubifs_info
*c
, struct bu_info
*bu
,
724 pgoff_t offset
= page1
->index
, end_index
;
725 struct address_space
*mapping
= page1
->mapping
;
726 struct inode
*inode
= mapping
->host
;
727 struct ubifs_inode
*ui
= ubifs_inode(inode
);
728 int err
, page_idx
, page_cnt
, ret
= 0, n
= 0;
729 int allocate
= bu
->buf
? 0 : 1;
732 err
= ubifs_tnc_get_bu_keys(c
, bu
);
737 /* Turn off bulk-read at the end of the file */
738 ui
->read_in_a_row
= 1;
742 page_cnt
= bu
->blk_cnt
>> UBIFS_BLOCKS_PER_PAGE_SHIFT
;
745 * This happens when there are multiple blocks per page and the
746 * blocks for the first page we are looking for, are not
747 * together. If all the pages were like this, bulk-read would
748 * reduce performance, so we turn it off for a while.
756 * Allocate bulk-read buffer depending on how many data
757 * nodes we are going to read.
759 bu
->buf_len
= bu
->zbranch
[bu
->cnt
- 1].offs
+
760 bu
->zbranch
[bu
->cnt
- 1].len
-
762 ubifs_assert(bu
->buf_len
> 0);
763 ubifs_assert(bu
->buf_len
<= c
->leb_size
);
764 bu
->buf
= kmalloc(bu
->buf_len
, GFP_NOFS
| __GFP_NOWARN
);
769 err
= ubifs_tnc_bulk_read(c
, bu
);
774 err
= populate_page(c
, page1
, bu
, &n
);
781 isize
= i_size_read(inode
);
784 end_index
= ((isize
- 1) >> PAGE_CACHE_SHIFT
);
786 for (page_idx
= 1; page_idx
< page_cnt
; page_idx
++) {
787 pgoff_t page_offset
= offset
+ page_idx
;
790 if (page_offset
> end_index
)
792 page
= find_or_create_page(mapping
, page_offset
,
793 GFP_NOFS
| __GFP_COLD
);
796 if (!PageUptodate(page
))
797 err
= populate_page(c
, page
, bu
, &n
);
799 page_cache_release(page
);
804 ui
->last_page_read
= offset
+ page_idx
- 1;
812 ubifs_warn("ignoring error %d and skipping bulk-read", err
);
816 ui
->read_in_a_row
= ui
->bulk_read
= 0;
821 * ubifs_bulk_read - determine whether to bulk-read and, if so, do it.
822 * @page: page from which to start bulk-read.
824 * Some flash media are capable of reading sequentially at faster rates. UBIFS
825 * bulk-read facility is designed to take advantage of that, by reading in one
826 * go consecutive data nodes that are also located consecutively in the same
827 * LEB. This function returns %1 if a bulk-read is done and %0 otherwise.
829 static int ubifs_bulk_read(struct page
*page
)
831 struct inode
*inode
= page
->mapping
->host
;
832 struct ubifs_info
*c
= inode
->i_sb
->s_fs_info
;
833 struct ubifs_inode
*ui
= ubifs_inode(inode
);
834 pgoff_t index
= page
->index
, last_page_read
= ui
->last_page_read
;
836 int err
= 0, allocated
= 0;
838 ui
->last_page_read
= index
;
843 * Bulk-read is protected by @ui->ui_mutex, but it is an optimization,
844 * so don't bother if we cannot lock the mutex.
846 if (!mutex_trylock(&ui
->ui_mutex
))
849 if (index
!= last_page_read
+ 1) {
850 /* Turn off bulk-read if we stop reading sequentially */
851 ui
->read_in_a_row
= 1;
857 if (!ui
->bulk_read
) {
858 ui
->read_in_a_row
+= 1;
859 if (ui
->read_in_a_row
< 3)
861 /* Three reads in a row, so switch on bulk-read */
866 * If possible, try to use pre-allocated bulk-read information, which
867 * is protected by @c->bu_mutex.
869 if (mutex_trylock(&c
->bu_mutex
))
872 bu
= kmalloc(sizeof(struct bu_info
), GFP_NOFS
| __GFP_NOWARN
);
880 bu
->buf_len
= c
->max_bu_buf_len
;
881 data_key_init(c
, &bu
->key
, inode
->i_ino
,
882 page
->index
<< UBIFS_BLOCKS_PER_PAGE_SHIFT
);
883 err
= ubifs_do_bulk_read(c
, bu
, page
);
886 mutex_unlock(&c
->bu_mutex
);
891 mutex_unlock(&ui
->ui_mutex
);
895 static int ubifs_readpage(struct file
*file
, struct page
*page
)
897 if (ubifs_bulk_read(page
))
904 static int do_writepage(struct page
*page
, int len
)
906 int err
= 0, i
, blen
;
910 struct inode
*inode
= page
->mapping
->host
;
911 struct ubifs_info
*c
= inode
->i_sb
->s_fs_info
;
914 spin_lock(&ui
->ui_lock
);
915 ubifs_assert(page
->index
<= ui
->synced_i_size
<< PAGE_CACHE_SIZE
);
916 spin_unlock(&ui
->ui_lock
);
919 /* Update radix tree tags */
920 set_page_writeback(page
);
923 block
= page
->index
<< UBIFS_BLOCKS_PER_PAGE_SHIFT
;
926 blen
= min_t(int, len
, UBIFS_BLOCK_SIZE
);
927 data_key_init(c
, &key
, inode
->i_ino
, block
);
928 err
= ubifs_jnl_write_data(c
, inode
, &key
, addr
, blen
);
931 if (++i
>= UBIFS_BLOCKS_PER_PAGE
)
939 ubifs_err("cannot write page %lu of inode %lu, error %d",
940 page
->index
, inode
->i_ino
, err
);
941 ubifs_ro_mode(c
, err
);
944 ubifs_assert(PagePrivate(page
));
945 if (PageChecked(page
))
946 release_new_page_budget(c
);
948 release_existing_page_budget(c
);
950 atomic_long_dec(&c
->dirty_pg_cnt
);
951 ClearPagePrivate(page
);
952 ClearPageChecked(page
);
956 end_page_writeback(page
);
961 * When writing-back dirty inodes, VFS first writes-back pages belonging to the
962 * inode, then the inode itself. For UBIFS this may cause a problem. Consider a
963 * situation when a we have an inode with size 0, then a megabyte of data is
964 * appended to the inode, then write-back starts and flushes some amount of the
965 * dirty pages, the journal becomes full, commit happens and finishes, and then
966 * an unclean reboot happens. When the file system is mounted next time, the
967 * inode size would still be 0, but there would be many pages which are beyond
968 * the inode size, they would be indexed and consume flash space. Because the
969 * journal has been committed, the replay would not be able to detect this
970 * situation and correct the inode size. This means UBIFS would have to scan
971 * whole index and correct all inode sizes, which is long an unacceptable.
973 * To prevent situations like this, UBIFS writes pages back only if they are
974 * within the last synchronized inode size, i.e. the size which has been
975 * written to the flash media last time. Otherwise, UBIFS forces inode
976 * write-back, thus making sure the on-flash inode contains current inode size,
977 * and then keeps writing pages back.
979 * Some locking issues explanation. 'ubifs_writepage()' first is called with
980 * the page locked, and it locks @ui_mutex. However, write-back does take inode
981 * @i_mutex, which means other VFS operations may be run on this inode at the
982 * same time. And the problematic one is truncation to smaller size, from where
983 * we have to call 'truncate_setsize()', which first changes @inode->i_size,
984 * then drops the truncated pages. And while dropping the pages, it takes the
985 * page lock. This means that 'do_truncation()' cannot call 'truncate_setsize()'
986 * with @ui_mutex locked, because it would deadlock with 'ubifs_writepage()'.
987 * This means that @inode->i_size is changed while @ui_mutex is unlocked.
989 * XXX(truncate): with the new truncate sequence this is not true anymore,
990 * and the calls to truncate_setsize can be move around freely. They should
991 * be moved to the very end of the truncate sequence.
993 * But in 'ubifs_writepage()' we have to guarantee that we do not write beyond
994 * inode size. How do we do this if @inode->i_size may became smaller while we
995 * are in the middle of 'ubifs_writepage()'? The UBIFS solution is the
996 * @ui->ui_isize "shadow" field which UBIFS uses instead of @inode->i_size
997 * internally and updates it under @ui_mutex.
999 * Q: why we do not worry that if we race with truncation, we may end up with a
1000 * situation when the inode is truncated while we are in the middle of
1001 * 'do_writepage()', so we do write beyond inode size?
1002 * A: If we are in the middle of 'do_writepage()', truncation would be locked
1003 * on the page lock and it would not write the truncated inode node to the
1004 * journal before we have finished.
1006 static int ubifs_writepage(struct page
*page
, struct writeback_control
*wbc
)
1008 struct inode
*inode
= page
->mapping
->host
;
1009 struct ubifs_inode
*ui
= ubifs_inode(inode
);
1010 loff_t i_size
= i_size_read(inode
), synced_i_size
;
1011 pgoff_t end_index
= i_size
>> PAGE_CACHE_SHIFT
;
1012 int err
, len
= i_size
& (PAGE_CACHE_SIZE
- 1);
1015 dbg_gen("ino %lu, pg %lu, pg flags %#lx",
1016 inode
->i_ino
, page
->index
, page
->flags
);
1017 ubifs_assert(PagePrivate(page
));
1019 /* Is the page fully outside @i_size? (truncate in progress) */
1020 if (page
->index
> end_index
|| (page
->index
== end_index
&& !len
)) {
1025 spin_lock(&ui
->ui_lock
);
1026 synced_i_size
= ui
->synced_i_size
;
1027 spin_unlock(&ui
->ui_lock
);
1029 /* Is the page fully inside @i_size? */
1030 if (page
->index
< end_index
) {
1031 if (page
->index
>= synced_i_size
>> PAGE_CACHE_SHIFT
) {
1032 err
= inode
->i_sb
->s_op
->write_inode(inode
, NULL
);
1036 * The inode has been written, but the write-buffer has
1037 * not been synchronized, so in case of an unclean
1038 * reboot we may end up with some pages beyond inode
1039 * size, but they would be in the journal (because
1040 * commit flushes write buffers) and recovery would deal
1044 return do_writepage(page
, PAGE_CACHE_SIZE
);
1048 * The page straddles @i_size. It must be zeroed out on each and every
1049 * writepage invocation because it may be mmapped. "A file is mapped
1050 * in multiples of the page size. For a file that is not a multiple of
1051 * the page size, the remaining memory is zeroed when mapped, and
1052 * writes to that region are not written out to the file."
1054 kaddr
= kmap_atomic(page
);
1055 memset(kaddr
+ len
, 0, PAGE_CACHE_SIZE
- len
);
1056 flush_dcache_page(page
);
1057 kunmap_atomic(kaddr
);
1059 if (i_size
> synced_i_size
) {
1060 err
= inode
->i_sb
->s_op
->write_inode(inode
, NULL
);
1065 return do_writepage(page
, len
);
1073 * do_attr_changes - change inode attributes.
1074 * @inode: inode to change attributes for
1075 * @attr: describes attributes to change
1077 static void do_attr_changes(struct inode
*inode
, const struct iattr
*attr
)
1079 if (attr
->ia_valid
& ATTR_UID
)
1080 inode
->i_uid
= attr
->ia_uid
;
1081 if (attr
->ia_valid
& ATTR_GID
)
1082 inode
->i_gid
= attr
->ia_gid
;
1083 if (attr
->ia_valid
& ATTR_ATIME
)
1084 inode
->i_atime
= timespec_trunc(attr
->ia_atime
,
1085 inode
->i_sb
->s_time_gran
);
1086 if (attr
->ia_valid
& ATTR_MTIME
)
1087 inode
->i_mtime
= timespec_trunc(attr
->ia_mtime
,
1088 inode
->i_sb
->s_time_gran
);
1089 if (attr
->ia_valid
& ATTR_CTIME
)
1090 inode
->i_ctime
= timespec_trunc(attr
->ia_ctime
,
1091 inode
->i_sb
->s_time_gran
);
1092 if (attr
->ia_valid
& ATTR_MODE
) {
1093 umode_t mode
= attr
->ia_mode
;
1095 if (!in_group_p(inode
->i_gid
) && !capable(CAP_FSETID
))
1097 inode
->i_mode
= mode
;
1102 * do_truncation - truncate an inode.
1103 * @c: UBIFS file-system description object
1104 * @inode: inode to truncate
1105 * @attr: inode attribute changes description
1107 * This function implements VFS '->setattr()' call when the inode is truncated
1108 * to a smaller size. Returns zero in case of success and a negative error code
1109 * in case of failure.
1111 static int do_truncation(struct ubifs_info
*c
, struct inode
*inode
,
1112 const struct iattr
*attr
)
1115 struct ubifs_budget_req req
;
1116 loff_t old_size
= inode
->i_size
, new_size
= attr
->ia_size
;
1117 int offset
= new_size
& (UBIFS_BLOCK_SIZE
- 1), budgeted
= 1;
1118 struct ubifs_inode
*ui
= ubifs_inode(inode
);
1120 dbg_gen("ino %lu, size %lld -> %lld", inode
->i_ino
, old_size
, new_size
);
1121 memset(&req
, 0, sizeof(struct ubifs_budget_req
));
1124 * If this is truncation to a smaller size, and we do not truncate on a
1125 * block boundary, budget for changing one data block, because the last
1126 * block will be re-written.
1128 if (new_size
& (UBIFS_BLOCK_SIZE
- 1))
1129 req
.dirtied_page
= 1;
1131 req
.dirtied_ino
= 1;
1132 /* A funny way to budget for truncation node */
1133 req
.dirtied_ino_d
= UBIFS_TRUN_NODE_SZ
;
1134 err
= ubifs_budget_space(c
, &req
);
1137 * Treat truncations to zero as deletion and always allow them,
1138 * just like we do for '->unlink()'.
1140 if (new_size
|| err
!= -ENOSPC
)
1145 truncate_setsize(inode
, new_size
);
1148 pgoff_t index
= new_size
>> PAGE_CACHE_SHIFT
;
1151 page
= find_lock_page(inode
->i_mapping
, index
);
1153 if (PageDirty(page
)) {
1155 * 'ubifs_jnl_truncate()' will try to truncate
1156 * the last data node, but it contains
1157 * out-of-date data because the page is dirty.
1158 * Write the page now, so that
1159 * 'ubifs_jnl_truncate()' will see an already
1160 * truncated (and up to date) data node.
1162 ubifs_assert(PagePrivate(page
));
1164 clear_page_dirty_for_io(page
);
1165 if (UBIFS_BLOCKS_PER_PAGE_SHIFT
)
1167 (PAGE_CACHE_SIZE
- 1);
1168 err
= do_writepage(page
, offset
);
1169 page_cache_release(page
);
1173 * We could now tell 'ubifs_jnl_truncate()' not
1174 * to read the last block.
1178 * We could 'kmap()' the page and pass the data
1179 * to 'ubifs_jnl_truncate()' to save it from
1180 * having to read it.
1183 page_cache_release(page
);
1188 mutex_lock(&ui
->ui_mutex
);
1189 ui
->ui_size
= inode
->i_size
;
1190 /* Truncation changes inode [mc]time */
1191 inode
->i_mtime
= inode
->i_ctime
= ubifs_current_time(inode
);
1192 /* Other attributes may be changed at the same time as well */
1193 do_attr_changes(inode
, attr
);
1194 err
= ubifs_jnl_truncate(c
, inode
, old_size
, new_size
);
1195 mutex_unlock(&ui
->ui_mutex
);
1199 ubifs_release_budget(c
, &req
);
1201 c
->bi
.nospace
= c
->bi
.nospace_rp
= 0;
1208 * do_setattr - change inode attributes.
1209 * @c: UBIFS file-system description object
1210 * @inode: inode to change attributes for
1211 * @attr: inode attribute changes description
1213 * This function implements VFS '->setattr()' call for all cases except
1214 * truncations to smaller size. Returns zero in case of success and a negative
1215 * error code in case of failure.
1217 static int do_setattr(struct ubifs_info
*c
, struct inode
*inode
,
1218 const struct iattr
*attr
)
1221 loff_t new_size
= attr
->ia_size
;
1222 struct ubifs_inode
*ui
= ubifs_inode(inode
);
1223 struct ubifs_budget_req req
= { .dirtied_ino
= 1,
1224 .dirtied_ino_d
= ALIGN(ui
->data_len
, 8) };
1226 err
= ubifs_budget_space(c
, &req
);
1230 if (attr
->ia_valid
& ATTR_SIZE
) {
1231 dbg_gen("size %lld -> %lld", inode
->i_size
, new_size
);
1232 truncate_setsize(inode
, new_size
);
1235 mutex_lock(&ui
->ui_mutex
);
1236 if (attr
->ia_valid
& ATTR_SIZE
) {
1237 /* Truncation changes inode [mc]time */
1238 inode
->i_mtime
= inode
->i_ctime
= ubifs_current_time(inode
);
1239 /* 'truncate_setsize()' changed @i_size, update @ui_size */
1240 ui
->ui_size
= inode
->i_size
;
1243 do_attr_changes(inode
, attr
);
1245 release
= ui
->dirty
;
1246 if (attr
->ia_valid
& ATTR_SIZE
)
1248 * Inode length changed, so we have to make sure
1249 * @I_DIRTY_DATASYNC is set.
1251 __mark_inode_dirty(inode
, I_DIRTY_SYNC
| I_DIRTY_DATASYNC
);
1253 mark_inode_dirty_sync(inode
);
1254 mutex_unlock(&ui
->ui_mutex
);
1257 ubifs_release_budget(c
, &req
);
1259 err
= inode
->i_sb
->s_op
->write_inode(inode
, NULL
);
1263 int ubifs_setattr(struct dentry
*dentry
, struct iattr
*attr
)
1266 struct inode
*inode
= dentry
->d_inode
;
1267 struct ubifs_info
*c
= inode
->i_sb
->s_fs_info
;
1269 dbg_gen("ino %lu, mode %#x, ia_valid %#x",
1270 inode
->i_ino
, inode
->i_mode
, attr
->ia_valid
);
1271 err
= inode_change_ok(inode
, attr
);
1275 err
= dbg_check_synced_i_size(c
, inode
);
1279 if ((attr
->ia_valid
& ATTR_SIZE
) && attr
->ia_size
< inode
->i_size
)
1280 /* Truncation to a smaller size */
1281 err
= do_truncation(c
, inode
, attr
);
1283 err
= do_setattr(c
, inode
, attr
);
1288 static void ubifs_invalidatepage(struct page
*page
, unsigned long offset
)
1290 struct inode
*inode
= page
->mapping
->host
;
1291 struct ubifs_info
*c
= inode
->i_sb
->s_fs_info
;
1293 ubifs_assert(PagePrivate(page
));
1295 /* Partial page remains dirty */
1298 if (PageChecked(page
))
1299 release_new_page_budget(c
);
1301 release_existing_page_budget(c
);
1303 atomic_long_dec(&c
->dirty_pg_cnt
);
1304 ClearPagePrivate(page
);
1305 ClearPageChecked(page
);
1308 static void *ubifs_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
1310 struct ubifs_inode
*ui
= ubifs_inode(dentry
->d_inode
);
1312 nd_set_link(nd
, ui
->data
);
1316 int ubifs_fsync(struct file
*file
, loff_t start
, loff_t end
, int datasync
)
1318 struct inode
*inode
= file
->f_mapping
->host
;
1319 struct ubifs_info
*c
= inode
->i_sb
->s_fs_info
;
1322 dbg_gen("syncing inode %lu", inode
->i_ino
);
1326 * For some really strange reasons VFS does not filter out
1327 * 'fsync()' for R/O mounted file-systems as per 2.6.39.
1331 err
= filemap_write_and_wait_range(inode
->i_mapping
, start
, end
);
1334 mutex_lock(&inode
->i_mutex
);
1336 /* Synchronize the inode unless this is a 'datasync()' call. */
1337 if (!datasync
|| (inode
->i_state
& I_DIRTY_DATASYNC
)) {
1338 err
= inode
->i_sb
->s_op
->write_inode(inode
, NULL
);
1344 * Nodes related to this inode may still sit in a write-buffer. Flush
1347 err
= ubifs_sync_wbufs_by_inode(c
, inode
);
1349 mutex_unlock(&inode
->i_mutex
);
1354 * mctime_update_needed - check if mtime or ctime update is needed.
1355 * @inode: the inode to do the check for
1356 * @now: current time
1358 * This helper function checks if the inode mtime/ctime should be updated or
1359 * not. If current values of the time-stamps are within the UBIFS inode time
1360 * granularity, they are not updated. This is an optimization.
1362 static inline int mctime_update_needed(const struct inode
*inode
,
1363 const struct timespec
*now
)
1365 if (!timespec_equal(&inode
->i_mtime
, now
) ||
1366 !timespec_equal(&inode
->i_ctime
, now
))
1372 * update_ctime - update mtime and ctime of an inode.
1373 * @c: UBIFS file-system description object
1374 * @inode: inode to update
1376 * This function updates mtime and ctime of the inode if it is not equivalent to
1377 * current time. Returns zero in case of success and a negative error code in
1380 static int update_mctime(struct ubifs_info
*c
, struct inode
*inode
)
1382 struct timespec now
= ubifs_current_time(inode
);
1383 struct ubifs_inode
*ui
= ubifs_inode(inode
);
1385 if (mctime_update_needed(inode
, &now
)) {
1387 struct ubifs_budget_req req
= { .dirtied_ino
= 1,
1388 .dirtied_ino_d
= ALIGN(ui
->data_len
, 8) };
1390 err
= ubifs_budget_space(c
, &req
);
1394 mutex_lock(&ui
->ui_mutex
);
1395 inode
->i_mtime
= inode
->i_ctime
= ubifs_current_time(inode
);
1396 release
= ui
->dirty
;
1397 mark_inode_dirty_sync(inode
);
1398 mutex_unlock(&ui
->ui_mutex
);
1400 ubifs_release_budget(c
, &req
);
1406 static ssize_t
ubifs_aio_write(struct kiocb
*iocb
, const struct iovec
*iov
,
1407 unsigned long nr_segs
, loff_t pos
)
1410 struct inode
*inode
= iocb
->ki_filp
->f_mapping
->host
;
1411 struct ubifs_info
*c
= inode
->i_sb
->s_fs_info
;
1413 err
= update_mctime(c
, inode
);
1417 return generic_file_aio_write(iocb
, iov
, nr_segs
, pos
);
1420 static int ubifs_set_page_dirty(struct page
*page
)
1424 ret
= __set_page_dirty_nobuffers(page
);
1426 * An attempt to dirty a page without budgeting for it - should not
1429 ubifs_assert(ret
== 0);
1433 static int ubifs_releasepage(struct page
*page
, gfp_t unused_gfp_flags
)
1436 * An attempt to release a dirty page without budgeting for it - should
1439 if (PageWriteback(page
))
1441 ubifs_assert(PagePrivate(page
));
1443 ClearPagePrivate(page
);
1444 ClearPageChecked(page
);
1449 * mmap()d file has taken write protection fault and is being made writable.
1450 * UBIFS must ensure page is budgeted for.
1452 static int ubifs_vm_page_mkwrite(struct vm_area_struct
*vma
,
1453 struct vm_fault
*vmf
)
1455 struct page
*page
= vmf
->page
;
1456 struct inode
*inode
= file_inode(vma
->vm_file
);
1457 struct ubifs_info
*c
= inode
->i_sb
->s_fs_info
;
1458 struct timespec now
= ubifs_current_time(inode
);
1459 struct ubifs_budget_req req
= { .new_page
= 1 };
1460 int err
, update_time
;
1462 dbg_gen("ino %lu, pg %lu, i_size %lld", inode
->i_ino
, page
->index
,
1463 i_size_read(inode
));
1464 ubifs_assert(!c
->ro_media
&& !c
->ro_mount
);
1466 if (unlikely(c
->ro_error
))
1467 return VM_FAULT_SIGBUS
; /* -EROFS */
1470 * We have not locked @page so far so we may budget for changing the
1471 * page. Note, we cannot do this after we locked the page, because
1472 * budgeting may cause write-back which would cause deadlock.
1474 * At the moment we do not know whether the page is dirty or not, so we
1475 * assume that it is not and budget for a new page. We could look at
1476 * the @PG_private flag and figure this out, but we may race with write
1477 * back and the page state may change by the time we lock it, so this
1478 * would need additional care. We do not bother with this at the
1479 * moment, although it might be good idea to do. Instead, we allocate
1480 * budget for a new page and amend it later on if the page was in fact
1483 * The budgeting-related logic of this function is similar to what we
1484 * do in 'ubifs_write_begin()' and 'ubifs_write_end()'. Glance there
1485 * for more comments.
1487 update_time
= mctime_update_needed(inode
, &now
);
1490 * We have to change inode time stamp which requires extra
1493 req
.dirtied_ino
= 1;
1495 err
= ubifs_budget_space(c
, &req
);
1496 if (unlikely(err
)) {
1498 ubifs_warn("out of space for mmapped file (inode number %lu)",
1500 return VM_FAULT_SIGBUS
;
1504 if (unlikely(page
->mapping
!= inode
->i_mapping
||
1505 page_offset(page
) > i_size_read(inode
))) {
1506 /* Page got truncated out from underneath us */
1511 if (PagePrivate(page
))
1512 release_new_page_budget(c
);
1514 if (!PageChecked(page
))
1515 ubifs_convert_page_budget(c
);
1516 SetPagePrivate(page
);
1517 atomic_long_inc(&c
->dirty_pg_cnt
);
1518 __set_page_dirty_nobuffers(page
);
1523 struct ubifs_inode
*ui
= ubifs_inode(inode
);
1525 mutex_lock(&ui
->ui_mutex
);
1526 inode
->i_mtime
= inode
->i_ctime
= ubifs_current_time(inode
);
1527 release
= ui
->dirty
;
1528 mark_inode_dirty_sync(inode
);
1529 mutex_unlock(&ui
->ui_mutex
);
1531 ubifs_release_dirty_inode_budget(c
, ui
);
1534 wait_for_stable_page(page
);
1535 return VM_FAULT_LOCKED
;
1539 ubifs_release_budget(c
, &req
);
1541 err
= VM_FAULT_SIGBUS
;
1545 static const struct vm_operations_struct ubifs_file_vm_ops
= {
1546 .fault
= filemap_fault
,
1547 .page_mkwrite
= ubifs_vm_page_mkwrite
,
1548 .remap_pages
= generic_file_remap_pages
,
1551 static int ubifs_file_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1555 err
= generic_file_mmap(file
, vma
);
1558 vma
->vm_ops
= &ubifs_file_vm_ops
;
1563 long ubifs_fallocate(struct file
*file
, int mode
, loff_t offset
, loff_t len
)
1566 struct inode
*inode
= file
->f_mapping
->host
;
1567 struct ubifs_info
*c
= inode
->i_sb
->s_fs_info
;
1568 struct iattr newattrs
;
1570 loff_t new_len
= offset
+ len
;
1571 if (len
< 0 || offset
< 0)
1574 if(new_len
< inode
->i_size
)
1577 newattrs
.ia_size
= new_len
;
1578 newattrs
.ia_valid
= ATTR_SIZE
| ATTR_MTIME
|ATTR_CTIME
;
1579 newattrs
.ia_file
= file
;
1580 newattrs
.ia_valid
|= ATTR_FILE
;
1583 err
= do_setattr(c
, inode
, &newattrs
);
1587 const struct address_space_operations ubifs_file_address_operations
= {
1588 .readpage
= ubifs_readpage
,
1589 .writepage
= ubifs_writepage
,
1590 .write_begin
= ubifs_write_begin
,
1591 .write_end
= ubifs_write_end
,
1592 .invalidatepage
= ubifs_invalidatepage
,
1593 .set_page_dirty
= ubifs_set_page_dirty
,
1594 .releasepage
= ubifs_releasepage
,
1597 const struct inode_operations ubifs_file_inode_operations
= {
1598 .setattr
= ubifs_setattr
,
1599 .getattr
= ubifs_getattr
,
1600 .setxattr
= ubifs_setxattr
,
1601 .getxattr
= ubifs_getxattr
,
1602 .listxattr
= ubifs_listxattr
,
1603 .removexattr
= ubifs_removexattr
,
1606 const struct inode_operations ubifs_symlink_inode_operations
= {
1607 .readlink
= generic_readlink
,
1608 .follow_link
= ubifs_follow_link
,
1609 .setattr
= ubifs_setattr
,
1610 .getattr
= ubifs_getattr
,
1611 .setxattr
= ubifs_setxattr
,
1612 .getxattr
= ubifs_getxattr
,
1613 .listxattr
= ubifs_listxattr
,
1614 .removexattr
= ubifs_removexattr
,
1617 const struct file_operations ubifs_file_operations
= {
1618 .llseek
= generic_file_llseek
,
1619 .read
= do_sync_read
,
1620 .write
= do_sync_write
,
1621 .aio_read
= generic_file_aio_read
,
1622 .aio_write
= ubifs_aio_write
,
1623 .mmap
= ubifs_file_mmap
,
1624 .fsync
= ubifs_fsync
,
1625 .unlocked_ioctl
= ubifs_ioctl
,
1626 .splice_read
= generic_file_splice_read
,
1627 .splice_write
= generic_file_splice_write
,
1628 #ifdef CONFIG_COMPAT
1629 .compat_ioctl
= ubifs_compat_ioctl
,
1631 .fallocate
= ubifs_fallocate
,