1b2441318SGreg Kroah-Hartman// SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds/*
31da177e4SLinus Torvalds *  linux/fs/minix/file.c
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds *  Copyright (C) 1991, 1992 Linus Torvalds
61da177e4SLinus Torvalds *
71da177e4SLinus Torvalds *  minix regular file handling primitives
81da177e4SLinus Torvalds */
91da177e4SLinus Torvalds
101da177e4SLinus Torvalds#include "minix.h"
111da177e4SLinus Torvalds
121da177e4SLinus Torvalds/*
131da177e4SLinus Torvalds * We have mostly NULLs here: the current defaults are OK for
141da177e4SLinus Torvalds * the minix filesystem.
151da177e4SLinus Torvalds */
164b6f5d20SArjan van de Venconst struct file_operations minix_file_operations = {
171da177e4SLinus Torvalds	.llseek		= generic_file_llseek,
18aad4f8bbSAl Viro	.read_iter	= generic_file_read_iter,
198174202bSAl Viro	.write_iter	= generic_file_write_iter,
201da177e4SLinus Torvalds	.mmap		= generic_file_mmap,
211b061d92SChristoph Hellwig	.fsync		= generic_file_fsync,
225ffc4ef4SJens Axboe	.splice_read	= generic_file_splice_read,
231da177e4SLinus Torvalds};
241da177e4SLinus Torvalds
25549c7297SChristian Braunerstatic int minix_setattr(struct user_namespace *mnt_userns,
26549c7297SChristian Brauner			 struct dentry *dentry, struct iattr *attr)
27d39aae9eSChristoph Hellwig{
282b0143b5SDavid Howells	struct inode *inode = d_inode(dentry);
29d39aae9eSChristoph Hellwig	int error;
30d39aae9eSChristoph Hellwig
312f221d6fSChristian Brauner	error = setattr_prepare(&init_user_ns, dentry, attr);
32d39aae9eSChristoph Hellwig	if (error)
33d39aae9eSChristoph Hellwig		return error;
341025774cSChristoph Hellwig
351025774cSChristoph Hellwig	if ((attr->ia_valid & ATTR_SIZE) &&
361025774cSChristoph Hellwig	    attr->ia_size != i_size_read(inode)) {
377fc7cd00SMarco Stornelli		error = inode_newsize_ok(inode, attr->ia_size);
381025774cSChristoph Hellwig		if (error)
391025774cSChristoph Hellwig			return error;
407fc7cd00SMarco Stornelli
417fc7cd00SMarco Stornelli		truncate_setsize(inode, attr->ia_size);
427fc7cd00SMarco Stornelli		minix_truncate(inode);
431025774cSChristoph Hellwig	}
441025774cSChristoph Hellwig
452f221d6fSChristian Brauner	setattr_copy(&init_user_ns, inode, attr);
461025774cSChristoph Hellwig	mark_inode_dirty(inode);
471025774cSChristoph Hellwig	return 0;
48d39aae9eSChristoph Hellwig}
49d39aae9eSChristoph Hellwig
5092e1d5beSArjan van de Venconst struct inode_operations minix_file_inode_operations = {
51d39aae9eSChristoph Hellwig	.setattr	= minix_setattr,
521da177e4SLinus Torvalds	.getattr	= minix_getattr,
531da177e4SLinus Torvalds};
54