Ok. I didn't make 2.4.0 in 2000. Tough. I tried, but we had some
[davej-history.git] / fs / ext2 / file.c
blobd92e37ccc3014b0d983ea58710bda3b053058e17
1 /*
2 * linux/fs/ext2/file.c
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)
9 * from
11 * linux/fs/minix/file.c
13 * Copyright (C) 1991, 1992 Linus Torvalds
15 * ext2 fs regular file handling primitives
17 * 64-bit file support on 64-bit platforms by Jakub Jelinek
18 * (jj@sunsite.ms.mff.cuni.cz)
21 #include <linux/fs.h>
22 #include <linux/ext2_fs.h>
23 #include <linux/sched.h>
25 static loff_t ext2_file_lseek(struct file *, loff_t,int);
26 static intext2_open_file(struct inode *,struct file *);
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)
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)
40 * Make sure the offset never goes beyond the 32-bit mark..
42 static loff_t ext2_file_lseek(
43 struct file *file,
44 loff_t offset,
45 int origin)
47 struct inode *inode = file->f_dentry->d_inode;
49 switch(origin) {
50 case2:
51 offset += inode->i_size;
52 break;
53 case1:
54 offset += file->f_pos;
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;
62 if(offset != file->f_pos) {
63 file->f_pos = offset;
64 file->f_reada =0;
65 file->f_version = ++event;
67 return offset;
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.
75 static intext2_release_file(struct inode * inode,struct file * filp)
77 if(filp->f_mode & FMODE_WRITE)
78 ext2_discard_prealloc(inode);
79 return0;
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.
88 static intext2_open_file(struct inode * inode,struct file * filp)
90 if(!(filp->f_flags & O_LARGEFILE) &&
91 inode->i_size >0x7FFFFFFFLL)
92 return-EFBIG;
93 return0;
97 * We have mostly NULL's here: the current defaults are ok for
98 * the ext2 filesystem.
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,
111 struct inode_operations ext2_file_inode_operations = {
112 truncate: ext2_truncate,
close