file.c (23e6e1c9b373c164bf25d89c901eed2ac0d898a1) file.c (4493895b2bdcca135a8e7c1384deaa35316e8e22)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */
5
6#include <linux/slab.h>
7#include <linux/compat.h>
8#include <linux/cred.h>

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

143 ei->start_clu = EXFAT_EOF_CLUSTER;
144 }
145
146 i_size_write(inode, new_size);
147
148 if (ei->type == TYPE_FILE)
149 ei->attr |= ATTR_ARCHIVE;
150
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
4 */
5
6#include <linux/slab.h>
7#include <linux/compat.h>
8#include <linux/cred.h>

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

143 ei->start_clu = EXFAT_EOF_CLUSTER;
144 }
145
146 i_size_write(inode, new_size);
147
148 if (ei->type == TYPE_FILE)
149 ei->attr |= ATTR_ARCHIVE;
150
151 /* update the directory entry */
152 inode->i_mtime = current_time(inode);
151 /*
152 * update the directory entry
153 *
154 * If the directory entry is updated by mark_inode_dirty(), the
155 * directory entry will be written after a writeback cycle of
156 * updating the bitmap/FAT, which may result in clusters being
157 * freed but referenced by the directory entry in the event of a
158 * sudden power failure.
159 * __exfat_write_inode() is called for directory entry, bitmap
160 * and FAT to be written in a same writeback.
161 */
153 if (__exfat_write_inode(inode, inode_needs_sync(inode)))
154 return -EIO;
155
156 /* cut off from the FAT chain */
157 if (ei->flags == ALLOC_FAT_CHAIN && last_clu != EXFAT_FREE_CLUSTER &&
158 last_clu != EXFAT_EOF_CLUSTER) {
159 if (exfat_ent_set(sb, last_clu, EXFAT_EOF_CLUSTER))
160 return -EIO;

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

197 exfat_fs_error(sb, "tried to truncate zeroed cluster.");
198 goto write_size;
199 }
200
201 err = __exfat_truncate(inode, i_size_read(inode));
202 if (err)
203 goto write_size;
204
162 if (__exfat_write_inode(inode, inode_needs_sync(inode)))
163 return -EIO;
164
165 /* cut off from the FAT chain */
166 if (ei->flags == ALLOC_FAT_CHAIN && last_clu != EXFAT_FREE_CLUSTER &&
167 last_clu != EXFAT_EOF_CLUSTER) {
168 if (exfat_ent_set(sb, last_clu, EXFAT_EOF_CLUSTER))
169 return -EIO;

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

206 exfat_fs_error(sb, "tried to truncate zeroed cluster.");
207 goto write_size;
208 }
209
210 err = __exfat_truncate(inode, i_size_read(inode));
211 if (err)
212 goto write_size;
213
205 inode->i_ctime = inode->i_mtime = current_time(inode);
206 if (IS_DIRSYNC(inode))
207 exfat_sync_inode(inode);
208 else
209 mark_inode_dirty(inode);
210
211 inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >>
212 inode->i_blkbits;
213write_size:
214 aligned_size = i_size_read(inode);
215 if (aligned_size & (blocksize - 1)) {
216 aligned_size |= (blocksize - 1);
217 aligned_size++;
218 }

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

284 * We don't return -EPERM here. Yes, strange, but this is too
285 * old behavior.
286 */
287 if (attr->ia_valid & ATTR_MODE) {
288 if (exfat_sanitize_mode(sbi, inode, &attr->ia_mode) < 0)
289 attr->ia_valid &= ~ATTR_MODE;
290 }
291
214 inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >>
215 inode->i_blkbits;
216write_size:
217 aligned_size = i_size_read(inode);
218 if (aligned_size & (blocksize - 1)) {
219 aligned_size |= (blocksize - 1);
220 aligned_size++;
221 }

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

287 * We don't return -EPERM here. Yes, strange, but this is too
288 * old behavior.
289 */
290 if (attr->ia_valid & ATTR_MODE) {
291 if (exfat_sanitize_mode(sbi, inode, &attr->ia_mode) < 0)
292 attr->ia_valid &= ~ATTR_MODE;
293 }
294
295 if (attr->ia_valid & ATTR_SIZE)
296 inode->i_mtime = inode->i_ctime = current_time(inode);
297
298 setattr_copy(&init_user_ns, inode, attr);
299 exfat_truncate_atime(&inode->i_atime);
300
292 if (attr->ia_valid & ATTR_SIZE) {
293 error = exfat_block_truncate_page(inode, attr->ia_size);
294 if (error)
295 goto out;
296
297 down_write(&EXFAT_I(inode)->truncate_lock);
298 truncate_setsize(inode, attr->ia_size);
301 if (attr->ia_valid & ATTR_SIZE) {
302 error = exfat_block_truncate_page(inode, attr->ia_size);
303 if (error)
304 goto out;
305
306 down_write(&EXFAT_I(inode)->truncate_lock);
307 truncate_setsize(inode, attr->ia_size);
308
309 /*
310 * __exfat_write_inode() is called from exfat_truncate(), inode
311 * is already written by it, so mark_inode_dirty() is unneeded.
312 */
299 exfat_truncate(inode, attr->ia_size);
300 up_write(&EXFAT_I(inode)->truncate_lock);
313 exfat_truncate(inode, attr->ia_size);
314 up_write(&EXFAT_I(inode)->truncate_lock);
301 }
315 } else
316 mark_inode_dirty(inode);
302
317
303 setattr_copy(&init_user_ns, inode, attr);
304 exfat_truncate_atime(&inode->i_atime);
305 mark_inode_dirty(inode);
306
307out:
308 return error;
309}
310
311static int exfat_ioctl_fitrim(struct inode *inode, unsigned long arg)
312{
313 struct fstrim_range range;
314 int ret = 0;

--- 77 unchanged lines hidden ---
318out:
319 return error;
320}
321
322static int exfat_ioctl_fitrim(struct inode *inode, unsigned long arg)
323{
324 struct fstrim_range range;
325 int ret = 0;

--- 77 unchanged lines hidden ---