file.c 1.27 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0
Linus Torvalds's avatar
Linus Torvalds committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 *  linux/fs/sysv/file.c
 *
 *  minix/file.c
 *  Copyright (C) 1991, 1992  Linus Torvalds
 *
 *  coh/file.c
 *  Copyright (C) 1993  Pascal Haible, Bruno Haible
 *
 *  sysv/file.c
 *  Copyright (C) 1993  Bruno Haible
 *
 *  SystemV/Coherent regular file handling primitives
 */

#include "sysv.h"

/*
 * We have mostly NULLs here: the current defaults are OK for
 * the coh filesystem.
 */
23
const struct file_operations sysv_file_operations = {
Linus Torvalds's avatar
Linus Torvalds committed
24
	.llseek		= generic_file_llseek,
25
	.read_iter	= generic_file_read_iter,
26
	.write_iter	= generic_file_write_iter,
Linus Torvalds's avatar
Linus Torvalds committed
27
	.mmap		= generic_file_mmap,
28
	.fsync		= generic_file_fsync,
29
	.splice_read	= generic_file_splice_read,
Linus Torvalds's avatar
Linus Torvalds committed
30 31
};

32 33
static int sysv_setattr(struct dentry *dentry, struct iattr *attr)
{
34
	struct inode *inode = d_inode(dentry);
35 36
	int error;

37
	error = setattr_prepare(dentry, attr);
38 39
	if (error)
		return error;
Christoph Hellwig's avatar
Christoph Hellwig committed
40 41 42

	if ((attr->ia_valid & ATTR_SIZE) &&
	    attr->ia_size != i_size_read(inode)) {
Marco Stornelli's avatar
Marco Stornelli committed
43
		error = inode_newsize_ok(inode, attr->ia_size);
Christoph Hellwig's avatar
Christoph Hellwig committed
44 45
		if (error)
			return error;
Marco Stornelli's avatar
Marco Stornelli committed
46 47
		truncate_setsize(inode, attr->ia_size);
		sysv_truncate(inode);
Christoph Hellwig's avatar
Christoph Hellwig committed
48 49 50 51 52
	}

	setattr_copy(inode, attr);
	mark_inode_dirty(inode);
	return 0;
53 54
}

55
const struct inode_operations sysv_file_inode_operations = {
56
	.setattr	= sysv_setattr,
Linus Torvalds's avatar
Linus Torvalds committed
57 58
	.getattr	= sysv_getattr,
};