18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  linux/fs/sysv/file.c
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  minix/file.c
68c2ecf20Sopenharmony_ci *  Copyright (C) 1991, 1992  Linus Torvalds
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci *  coh/file.c
98c2ecf20Sopenharmony_ci *  Copyright (C) 1993  Pascal Haible, Bruno Haible
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci *  sysv/file.c
128c2ecf20Sopenharmony_ci *  Copyright (C) 1993  Bruno Haible
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci *  SystemV/Coherent regular file handling primitives
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include "sysv.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci/*
208c2ecf20Sopenharmony_ci * We have mostly NULLs here: the current defaults are OK for
218c2ecf20Sopenharmony_ci * the coh filesystem.
228c2ecf20Sopenharmony_ci */
238c2ecf20Sopenharmony_ciconst struct file_operations sysv_file_operations = {
248c2ecf20Sopenharmony_ci	.llseek		= generic_file_llseek,
258c2ecf20Sopenharmony_ci	.read_iter	= generic_file_read_iter,
268c2ecf20Sopenharmony_ci	.write_iter	= generic_file_write_iter,
278c2ecf20Sopenharmony_ci	.mmap		= generic_file_mmap,
288c2ecf20Sopenharmony_ci	.fsync		= generic_file_fsync,
298c2ecf20Sopenharmony_ci	.splice_read	= generic_file_splice_read,
308c2ecf20Sopenharmony_ci};
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistatic int sysv_setattr(struct dentry *dentry, struct iattr *attr)
338c2ecf20Sopenharmony_ci{
348c2ecf20Sopenharmony_ci	struct inode *inode = d_inode(dentry);
358c2ecf20Sopenharmony_ci	int error;
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	error = setattr_prepare(dentry, attr);
388c2ecf20Sopenharmony_ci	if (error)
398c2ecf20Sopenharmony_ci		return error;
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	if ((attr->ia_valid & ATTR_SIZE) &&
428c2ecf20Sopenharmony_ci	    attr->ia_size != i_size_read(inode)) {
438c2ecf20Sopenharmony_ci		error = inode_newsize_ok(inode, attr->ia_size);
448c2ecf20Sopenharmony_ci		if (error)
458c2ecf20Sopenharmony_ci			return error;
468c2ecf20Sopenharmony_ci		truncate_setsize(inode, attr->ia_size);
478c2ecf20Sopenharmony_ci		sysv_truncate(inode);
488c2ecf20Sopenharmony_ci	}
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	setattr_copy(inode, attr);
518c2ecf20Sopenharmony_ci	mark_inode_dirty(inode);
528c2ecf20Sopenharmony_ci	return 0;
538c2ecf20Sopenharmony_ci}
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ciconst struct inode_operations sysv_file_inode_operations = {
568c2ecf20Sopenharmony_ci	.setattr	= sysv_setattr,
578c2ecf20Sopenharmony_ci	.getattr	= sysv_getattr,
588c2ecf20Sopenharmony_ci};
59