1 /*
2 * linux/fs/ext2/file.c
3 *
4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
8 *
9 * from
10 *
11 * linux/fs/minix/file.c
12 *
13 * Copyright (C) 1991, 1992 Linus Torvalds
14 *
15 * ext2 fs regular file handling primitives
16 *
17 * 64-bit file support on 64-bit platforms by Jakub Jelinek
18 * (jj@sunsite.ms.mff.cuni.cz)
19 */
20
21 #include <linux/fs.h>
22 #include <linux/ext2_fs.h>
23 #include <linux/sched.h>
24
25 static loff_t ext2_file_lseek(struct file *, loff_t, int);
26 static int ext2_open_file (struct inode *, struct file *);
27
28 #define EXT2_MAX_SIZE(bits) \
29 (((EXT2_NDIR_BLOCKS + (1LL << (bits - 2)) + \
30 (1LL << (bits - 2)) * (1LL << (bits - 2)) + \
31 (1LL << (bits - 2)) * (1LL << (bits - 2)) * (1LL << (bits - 2))) * \
32 (1LL << bits)) - 1)
33
34 static long long ext2_max_sizes[] = {
35 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
36 EXT2_MAX_SIZE(10), EXT2_MAX_SIZE(11), EXT2_MAX_SIZE(12), EXT2_MAX_SIZE(13)
37 };
38
39 /*
40 * Make sure the offset never goes beyond the 32-bit mark..
41 */
42 static loff_t ext2_file_lseek(
43 struct file *file,
44 loff_t offset,
45 int origin)
46 {
47 struct inode *inode = file->f_dentry->d_inode;
48
49 switch (origin) {
50 case 2:
51 offset += inode->i_size;
52 break;
53 case 1:
54 offset += file->f_pos;
55 }
56 if (offset<0)
57 return -EINVAL;
58 if (((unsigned long long) offset >> 32) != 0) {
59 if (offset > ext2_max_sizes[EXT2_BLOCK_SIZE_BITS(inode->i_sb)])
60 return -EINVAL;
61 }
62 if (offset != file->f_pos) {
63 file->f_pos = offset;
64 file->f_reada = 0;
65 file->f_version = ++event;
66 }
67 return offset;
68 }
69
70 /*
71 * Called when an inode is released. Note that this is different
72 * from ext2_file_open: open gets called at every open, but release
73 * gets called only when /all/ the files are closed.
74 */
75 static int ext2_release_file (struct inode * inode, struct file * filp)
76 {
77 if (filp->f_mode & FMODE_WRITE)
78 ext2_discard_prealloc (inode);
79 return 0;
80 }
81
82 /*
83 * Called when an inode is about to be open.
84 * We use this to disallow opening RW large files on 32bit systems if
85 * the caller didn't specify O_LARGEFILE. On 64bit systems we force
86 * on this flag in sys_open.
87 */
88 static int ext2_open_file (struct inode * inode, struct file * filp)
89 {
90 if (!(filp->f_flags & O_LARGEFILE) &&
91 inode->i_size > 0x7FFFFFFFLL)
92 return -EFBIG;
93 return 0;
94 }
95
96 /*
97 * We have mostly NULL's here: the current defaults are ok for
98 * the ext2 filesystem.
99 */
100 struct file_operations ext2_file_operations = {
101 llseek: ext2_file_lseek,
102 read: generic_file_read,
103 write: generic_file_write,
104 ioctl: ext2_ioctl,
105 mmap: generic_file_mmap,
106 open: ext2_open_file,
107 release: ext2_release_file,
108 fsync: ext2_sync_file,
109 };
110
111 struct inode_operations ext2_file_inode_operations = {
112 truncate: ext2_truncate,
113 };
114
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.