file.c 1.24 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 *  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.
 */
22
const struct file_operations sysv_file_operations = {
Linus Torvalds's avatar
Linus Torvalds committed
23
	.llseek		= generic_file_llseek,
24
	.read_iter	= generic_file_read_iter,
25
	.write_iter	= generic_file_write_iter,
Linus Torvalds's avatar
Linus Torvalds committed
26
	.mmap		= generic_file_mmap,
27
	.fsync		= generic_file_fsync,
28
	.splice_read	= generic_file_splice_read,
Linus Torvalds's avatar
Linus Torvalds committed
29 30
};

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

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

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

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

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