blob: c50b0a20fcd9c15ecf4a2bd8887bce9a8b6e88f8 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/fs/minix/file.c
4 *
5 * Copyright (C) 1991, 1992 Linus Torvalds
6 *
7 * minix regular file handling primitives
8 */
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include "minix.h"
11
12/*
13 * We have mostly NULLs here: the current defaults are OK for
14 * the minix filesystem.
15 */
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080016const struct file_operations minix_file_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 .llseek = generic_file_llseek,
Al Viroaad4f8b2014-04-02 14:33:16 -040018 .read_iter = generic_file_read_iter,
Al Viro81742022014-04-03 03:17:43 -040019 .write_iter = generic_file_write_iter,
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 .mmap = generic_file_mmap,
Christoph Hellwig1b061d92010-05-26 17:53:41 +020021 .fsync = generic_file_fsync,
Jens Axboe5ffc4ef2007-06-01 11:49:19 +020022 .splice_read = generic_file_splice_read,
Linus Torvalds1da177e2005-04-16 15:20:36 -070023};
24
Christoph Hellwigd39aae92010-06-04 11:29:59 +020025static int minix_setattr(struct dentry *dentry, struct iattr *attr)
26{
David Howells2b0143b2015-03-17 22:25:59 +000027 struct inode *inode = d_inode(dentry);
Christoph Hellwigd39aae92010-06-04 11:29:59 +020028 int error;
29
Jan Kara31051c82016-05-26 16:55:18 +020030 error = setattr_prepare(dentry, attr);
Christoph Hellwigd39aae92010-06-04 11:29:59 +020031 if (error)
32 return error;
Christoph Hellwig10257742010-06-04 11:30:02 +020033
34 if ((attr->ia_valid & ATTR_SIZE) &&
35 attr->ia_size != i_size_read(inode)) {
Marco Stornelli7fc7cd02012-12-15 11:56:25 +010036 error = inode_newsize_ok(inode, attr->ia_size);
Christoph Hellwig10257742010-06-04 11:30:02 +020037 if (error)
38 return error;
Marco Stornelli7fc7cd02012-12-15 11:56:25 +010039
40 truncate_setsize(inode, attr->ia_size);
41 minix_truncate(inode);
Christoph Hellwig10257742010-06-04 11:30:02 +020042 }
43
44 setattr_copy(inode, attr);
45 mark_inode_dirty(inode);
46 return 0;
Christoph Hellwigd39aae92010-06-04 11:29:59 +020047}
48
Arjan van de Ven92e1d5b2007-02-12 00:55:39 -080049const struct inode_operations minix_file_inode_operations = {
Christoph Hellwigd39aae92010-06-04 11:29:59 +020050 .setattr = minix_setattr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 .getattr = minix_getattr,
52};