file.c 2.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 *  linux/fs/ext2/file.c
 *
 * Copyright (C) 1992, 1993, 1994, 1995
 * Remy Card (card@masi.ibp.fr)
 * Laboratoire MASI - Institut Blaise Pascal
 * Universite Pierre et Marie Curie (Paris VI)
 *
 *  from
 *
 *  linux/fs/minix/file.c
 *
 *  Copyright (C) 1991, 1992  Linus Torvalds
 *
 *  ext2 fs regular file handling primitives
 *
 *  64-bit file support on 64-bit platforms by Jakub Jelinek
 * 	(jj@sunsite.ms.mff.cuni.cz)
 */

#include <linux/time.h>
22
#include <linux/pagemap.h>
23
#include <linux/quotaops.h>
L
Linus Torvalds 已提交
24 25 26 27 28
#include "ext2.h"
#include "xattr.h"
#include "acl.h"

/*
29 30 31
 * Called when filp is released. This happens when all file descriptors
 * for a single struct file are closed. Note that different open() calls
 * for the same file yield different struct file structures.
L
Linus Torvalds 已提交
32 33 34
 */
static int ext2_release_file (struct inode * inode, struct file * filp)
{
M
Martin J. Bligh 已提交
35 36 37 38 39
	if (filp->f_mode & FMODE_WRITE) {
		mutex_lock(&EXT2_I(inode)->truncate_mutex);
		ext2_discard_reservation(inode);
		mutex_unlock(&EXT2_I(inode)->truncate_mutex);
	}
L
Linus Torvalds 已提交
40 41 42
	return 0;
}

43
int ext2_fsync(struct file *file, loff_t start, loff_t end, int datasync)
44 45
{
	int ret;
46
	struct super_block *sb = file->f_mapping->host->i_sb;
47 48
	struct address_space *mapping = sb->s_bdev->bd_inode->i_mapping;

49
	ret = generic_file_fsync(file, start, end, datasync);
50 51 52 53 54 55 56 57 58
	if (ret == -EIO || test_and_clear_bit(AS_EIO, &mapping->flags)) {
		/* We don't really know where the IO error happened... */
		ext2_error(sb, __func__,
			   "detected IO error when writing metadata buffers");
		ret = -EIO;
	}
	return ret;
}

L
Linus Torvalds 已提交
59 60 61 62
/*
 * We have mostly NULL's here: the current defaults are ok for
 * the ext2 filesystem.
 */
63
const struct file_operations ext2_file_operations = {
L
Linus Torvalds 已提交
64
	.llseek		= generic_file_llseek,
65
	.read		= new_sync_read,
66
	.write		= do_sync_write,
67
	.read_iter	= generic_file_read_iter,
L
Linus Torvalds 已提交
68
	.aio_write	= generic_file_aio_write,
69
	.unlocked_ioctl = ext2_ioctl,
70 71 72
#ifdef CONFIG_COMPAT
	.compat_ioctl	= ext2_compat_ioctl,
#endif
L
Linus Torvalds 已提交
73
	.mmap		= generic_file_mmap,
74
	.open		= dquot_file_open,
L
Linus Torvalds 已提交
75
	.release	= ext2_release_file,
76
	.fsync		= ext2_fsync,
77 78
	.splice_read	= generic_file_splice_read,
	.splice_write	= generic_file_splice_write,
L
Linus Torvalds 已提交
79 80
};

81
#ifdef CONFIG_EXT2_FS_XIP
82
const struct file_operations ext2_xip_file_operations = {
83
	.llseek		= generic_file_llseek,
84 85
	.read		= xip_file_read,
	.write		= xip_file_write,
86
	.unlocked_ioctl = ext2_ioctl,
87 88 89
#ifdef CONFIG_COMPAT
	.compat_ioctl	= ext2_compat_ioctl,
#endif
90
	.mmap		= xip_file_mmap,
91
	.open		= dquot_file_open,
92
	.release	= ext2_release_file,
93
	.fsync		= ext2_fsync,
94 95 96
};
#endif

97
const struct inode_operations ext2_file_inode_operations = {
L
Linus Torvalds 已提交
98 99 100 101 102 103 104
#ifdef CONFIG_EXT2_FS_XATTR
	.setxattr	= generic_setxattr,
	.getxattr	= generic_getxattr,
	.listxattr	= ext2_listxattr,
	.removexattr	= generic_removexattr,
#endif
	.setattr	= ext2_setattr,
105
	.get_acl	= ext2_get_acl,
106
	.set_acl	= ext2_set_acl,
107
	.fiemap		= ext2_fiemap,
L
Linus Torvalds 已提交
108
};