xref: /openbmc/linux/fs/sysv/file.c (revision 6f4eaea2)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *  linux/fs/sysv/file.c
4  *
5  *  minix/file.c
6  *  Copyright (C) 1991, 1992  Linus Torvalds
7  *
8  *  coh/file.c
9  *  Copyright (C) 1993  Pascal Haible, Bruno Haible
10  *
11  *  sysv/file.c
12  *  Copyright (C) 1993  Bruno Haible
13  *
14  *  SystemV/Coherent regular file handling primitives
15  */
16 
17 #include "sysv.h"
18 
19 /*
20  * We have mostly NULLs here: the current defaults are OK for
21  * the coh filesystem.
22  */
23 const struct file_operations sysv_file_operations = {
24 	.llseek		= generic_file_llseek,
25 	.read_iter	= generic_file_read_iter,
26 	.write_iter	= generic_file_write_iter,
27 	.mmap		= generic_file_mmap,
28 	.fsync		= generic_file_fsync,
29 	.splice_read	= generic_file_splice_read,
30 };
31 
32 static int sysv_setattr(struct user_namespace *mnt_userns,
33 			struct dentry *dentry, struct iattr *attr)
34 {
35 	struct inode *inode = d_inode(dentry);
36 	int error;
37 
38 	error = setattr_prepare(&init_user_ns, dentry, attr);
39 	if (error)
40 		return error;
41 
42 	if ((attr->ia_valid & ATTR_SIZE) &&
43 	    attr->ia_size != i_size_read(inode)) {
44 		error = inode_newsize_ok(inode, attr->ia_size);
45 		if (error)
46 			return error;
47 		truncate_setsize(inode, attr->ia_size);
48 		sysv_truncate(inode);
49 	}
50 
51 	setattr_copy(&init_user_ns, inode, attr);
52 	mark_inode_dirty(inode);
53 	return 0;
54 }
55 
56 const struct inode_operations sysv_file_inode_operations = {
57 	.setattr	= sysv_setattr,
58 	.getattr	= sysv_getattr,
59 };
60