Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/fs/minix/file.c |
| 4 | * |
| 5 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 6 | * |
| 7 | * minix regular file handling primitives |
| 8 | */ |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #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 Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 16 | const struct file_operations minix_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | .llseek = generic_file_llseek, |
Al Viro | aad4f8b | 2014-04-02 14:33:16 -0400 | [diff] [blame] | 18 | .read_iter = generic_file_read_iter, |
Al Viro | 8174202 | 2014-04-03 03:17:43 -0400 | [diff] [blame] | 19 | .write_iter = generic_file_write_iter, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | .mmap = generic_file_mmap, |
Christoph Hellwig | 1b061d9 | 2010-05-26 17:53:41 +0200 | [diff] [blame] | 21 | .fsync = generic_file_fsync, |
Jens Axboe | 5ffc4ef | 2007-06-01 11:49:19 +0200 | [diff] [blame] | 22 | .splice_read = generic_file_splice_read, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | }; |
| 24 | |
Christoph Hellwig | d39aae9 | 2010-06-04 11:29:59 +0200 | [diff] [blame] | 25 | static int minix_setattr(struct dentry *dentry, struct iattr *attr) |
| 26 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 27 | struct inode *inode = d_inode(dentry); |
Christoph Hellwig | d39aae9 | 2010-06-04 11:29:59 +0200 | [diff] [blame] | 28 | int error; |
| 29 | |
Jan Kara | 31051c8 | 2016-05-26 16:55:18 +0200 | [diff] [blame] | 30 | error = setattr_prepare(dentry, attr); |
Christoph Hellwig | d39aae9 | 2010-06-04 11:29:59 +0200 | [diff] [blame] | 31 | if (error) |
| 32 | return error; |
Christoph Hellwig | 1025774 | 2010-06-04 11:30:02 +0200 | [diff] [blame] | 33 | |
| 34 | if ((attr->ia_valid & ATTR_SIZE) && |
| 35 | attr->ia_size != i_size_read(inode)) { |
Marco Stornelli | 7fc7cd0 | 2012-12-15 11:56:25 +0100 | [diff] [blame] | 36 | error = inode_newsize_ok(inode, attr->ia_size); |
Christoph Hellwig | 1025774 | 2010-06-04 11:30:02 +0200 | [diff] [blame] | 37 | if (error) |
| 38 | return error; |
Marco Stornelli | 7fc7cd0 | 2012-12-15 11:56:25 +0100 | [diff] [blame] | 39 | |
| 40 | truncate_setsize(inode, attr->ia_size); |
| 41 | minix_truncate(inode); |
Christoph Hellwig | 1025774 | 2010-06-04 11:30:02 +0200 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | setattr_copy(inode, attr); |
| 45 | mark_inode_dirty(inode); |
| 46 | return 0; |
Christoph Hellwig | d39aae9 | 2010-06-04 11:29:59 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 49 | const struct inode_operations minix_file_inode_operations = { |
Christoph Hellwig | d39aae9 | 2010-06-04 11:29:59 +0200 | [diff] [blame] | 50 | .setattr = minix_setattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | .getattr = minix_getattr, |
| 52 | }; |