file.c (a97131c29c997e81b6fa1d1adf8f3ca07b63a2e1) file.c (d3624466b56dd5b1886c1dff500525b544c19c83)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 *
4 * Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved.
5 *
6 * Regular file handling primitives for NTFS-based filesystems.
7 *
8 */

--- 176 unchanged lines hidden (view full) ---

185 ni->i_valid = valid;
186 ntfs_inode_warn(inode, "failed to extend initialized size to %llx.",
187 new_valid);
188 return err;
189}
190
191/*
192 * ntfs_zero_range - Helper function for punch_hole.
1// SPDX-License-Identifier: GPL-2.0
2/*
3 *
4 * Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved.
5 *
6 * Regular file handling primitives for NTFS-based filesystems.
7 *
8 */

--- 176 unchanged lines hidden (view full) ---

185 ni->i_valid = valid;
186 ntfs_inode_warn(inode, "failed to extend initialized size to %llx.",
187 new_valid);
188 return err;
189}
190
191/*
192 * ntfs_zero_range - Helper function for punch_hole.
193 * It zeroes a range [vbo, vbo_to)
193 *
194 * It zeroes a range [vbo, vbo_to).
194 */
195static int ntfs_zero_range(struct inode *inode, u64 vbo, u64 vbo_to)
196{
197 int err = 0;
198 struct address_space *mapping = inode->i_mapping;
199 u32 blocksize = 1 << inode->i_blkbits;
200 pgoff_t idx = vbo >> PAGE_SHIFT;
201 u32 z_start = vbo & (PAGE_SIZE - 1);

--- 24 unchanged lines hidden (view full) ---

226 do {
227 bh_next = bh_off + blocksize;
228
229 if (bh_next <= z_start || bh_off >= z_end)
230 continue;
231
232 if (!buffer_mapped(bh)) {
233 ntfs_get_block(inode, iblock, bh, 0);
195 */
196static int ntfs_zero_range(struct inode *inode, u64 vbo, u64 vbo_to)
197{
198 int err = 0;
199 struct address_space *mapping = inode->i_mapping;
200 u32 blocksize = 1 << inode->i_blkbits;
201 pgoff_t idx = vbo >> PAGE_SHIFT;
202 u32 z_start = vbo & (PAGE_SIZE - 1);

--- 24 unchanged lines hidden (view full) ---

227 do {
228 bh_next = bh_off + blocksize;
229
230 if (bh_next <= z_start || bh_off >= z_end)
231 continue;
232
233 if (!buffer_mapped(bh)) {
234 ntfs_get_block(inode, iblock, bh, 0);
234 /* unmapped? It's a hole - nothing to do */
235 /* Unmapped? It's a hole - nothing to do. */
235 if (!buffer_mapped(bh))
236 continue;
237 }
238
236 if (!buffer_mapped(bh))
237 continue;
238 }
239
239 /* Ok, it's mapped. Make sure it's up-to-date */
240 /* Ok, it's mapped. Make sure it's up-to-date. */
240 if (PageUptodate(page))
241 set_buffer_uptodate(bh);
242
243 if (!buffer_uptodate(bh)) {
244 lock_buffer(bh);
245 bh->b_end_io = end_buffer_read_sync;
246 get_bh(bh);
247 submit_bh(REQ_OP_READ, 0, bh);

--- 19 unchanged lines hidden (view full) ---

267 cond_resched();
268 }
269out:
270 mark_inode_dirty(inode);
271 return err;
272}
273
274/*
241 if (PageUptodate(page))
242 set_buffer_uptodate(bh);
243
244 if (!buffer_uptodate(bh)) {
245 lock_buffer(bh);
246 bh->b_end_io = end_buffer_read_sync;
247 get_bh(bh);
248 submit_bh(REQ_OP_READ, 0, bh);

--- 19 unchanged lines hidden (view full) ---

268 cond_resched();
269 }
270out:
271 mark_inode_dirty(inode);
272 return err;
273}
274
275/*
275 * ntfs_sparse_cluster
276 * ntfs_sparse_cluster - Helper function to zero a new allocated clusters.
276 *
277 *
277 * Helper function to zero a new allocated clusters
278 * NOTE: 512 <= cluster size <= 2M
279 */
280void ntfs_sparse_cluster(struct inode *inode, struct page *page0, CLST vcn,
281 CLST len)
282{
283 struct address_space *mapping = inode->i_mapping;
284 struct ntfs_sb_info *sbi = inode->i_sb->s_fs_info;
285 u64 vbo = (u64)vcn << sbi->cluster_bits;

--- 297 unchanged lines hidden (view full) ---

583 if (err)
584 goto out;
585
586 inode_dio_wait(inode);
587
588 truncate_pagecache(inode, vbo_down);
589
590 if (!is_sparsed(ni) && !is_compressed(ni)) {
278 * NOTE: 512 <= cluster size <= 2M
279 */
280void ntfs_sparse_cluster(struct inode *inode, struct page *page0, CLST vcn,
281 CLST len)
282{
283 struct address_space *mapping = inode->i_mapping;
284 struct ntfs_sb_info *sbi = inode->i_sb->s_fs_info;
285 u64 vbo = (u64)vcn << sbi->cluster_bits;

--- 297 unchanged lines hidden (view full) ---

583 if (err)
584 goto out;
585
586 inode_dio_wait(inode);
587
588 truncate_pagecache(inode, vbo_down);
589
590 if (!is_sparsed(ni) && !is_compressed(ni)) {
591 /* normal file */
591 /* Normal file. */
592 err = ntfs_zero_range(inode, vbo, end);
593 goto out;
594 }
595
596 ni_lock(ni);
597 err = attr_punch_hole(ni, vbo, len, &frame_size);
598 ni_unlock(ni);
599 if (err != E_NTFS_NOTALIGNED)
600 goto out;
601
592 err = ntfs_zero_range(inode, vbo, end);
593 goto out;
594 }
595
596 ni_lock(ni);
597 err = attr_punch_hole(ni, vbo, len, &frame_size);
598 ni_unlock(ni);
599 if (err != E_NTFS_NOTALIGNED)
600 goto out;
601
602 /* process not aligned punch */
602 /* Process not aligned punch. */
603 mask = frame_size - 1;
604 vbo_a = (vbo + mask) & ~mask;
605 end_a = end & ~mask;
606
607 tmp = min(vbo_a, end);
608 if (tmp > vbo) {
609 err = ntfs_zero_range(inode, vbo, tmp);
610 if (err)

--- 31 unchanged lines hidden (view full) ---

642 * Write data that will be shifted to preserve them
643 * when discarding page cache below.
644 */
645 err = filemap_write_and_wait_range(inode->i_mapping, end,
646 LLONG_MAX);
647 if (err)
648 goto out;
649
603 mask = frame_size - 1;
604 vbo_a = (vbo + mask) & ~mask;
605 end_a = end & ~mask;
606
607 tmp = min(vbo_a, end);
608 if (tmp > vbo) {
609 err = ntfs_zero_range(inode, vbo, tmp);
610 if (err)

--- 31 unchanged lines hidden (view full) ---

642 * Write data that will be shifted to preserve them
643 * when discarding page cache below.
644 */
645 err = filemap_write_and_wait_range(inode->i_mapping, end,
646 LLONG_MAX);
647 if (err)
648 goto out;
649
650 /* Wait for existing dio to complete */
650 /* Wait for existing dio to complete. */
651 inode_dio_wait(inode);
652
653 truncate_pagecache(inode, vbo_down);
654
655 ni_lock(ni);
656 err = attr_collapse_range(ni, vbo, len);
657 ni_unlock(ni);
658 } else {

--- 463 unchanged lines hidden (view full) ---

1122 inode_lock(inode);
1123 }
1124
1125 ret = generic_write_checks(iocb, from);
1126 if (ret <= 0)
1127 goto out;
1128
1129 if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
651 inode_dio_wait(inode);
652
653 truncate_pagecache(inode, vbo_down);
654
655 ni_lock(ni);
656 err = attr_collapse_range(ni, vbo, len);
657 ni_unlock(ni);
658 } else {

--- 463 unchanged lines hidden (view full) ---

1122 inode_lock(inode);
1123 }
1124
1125 ret = generic_write_checks(iocb, from);
1126 if (ret <= 0)
1127 goto out;
1128
1129 if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MASK)) {
1130 /* Should never be here, see ntfs_file_open() */
1130 /* Should never be here, see ntfs_file_open(). */
1131 ret = -EOPNOTSUPP;
1132 goto out;
1133 }
1134
1135 ret = ntfs_extend(inode, iocb->ki_pos, ret, file);
1136 if (ret)
1137 goto out;
1138

--- 116 unchanged lines hidden ---
1131 ret = -EOPNOTSUPP;
1132 goto out;
1133 }
1134
1135 ret = ntfs_extend(inode, iocb->ki_pos, ret, file);
1136 if (ret)
1137 goto out;
1138

--- 116 unchanged lines hidden ---