1
/*********************************************************
2
* Copyright (C) 2006 VMware, Inc. All rights reserved.
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the
6
* Free Software Foundation version 2 and no later version.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* You should have received a copy of the GNU General Public License along
14
* with this program; if not, write to the Free Software Foundation, Inc.,
15
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
*********************************************************/
19
#ifndef __COMPAT_FS_H__
20
# define __COMPAT_FS_H__
25
* 2.6.5+ kernels define FS_BINARY_MOUNTDATA. Since it didn't exist and
26
* wasn't used prior, it's safe to define it to zero.
29
#ifndef FS_BINARY_MOUNTDATA
30
#define FS_BINARY_MOUNTDATA 0
34
* MAX_LFS_FILESIZE wasn't defined until 2.5.4.
36
#ifndef MAX_LFS_FILESIZE
37
# include <linux/pagemap.h>
38
# if BITS_PER_LONG == 32
39
# define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG - 1)) - 1)
40
# elif BITS_PER_LONG == 64
41
# define MAX_LFS_FILESIZE 0x7fffffffffffffffUL
47
* sendfile as a VFS op was born in 2.5.30. Unfortunately, it also changed
48
* signatures, first in 2.5.47, then again in 2.5.70, then again in 2.6.8.
49
* Luckily, the 2.6.8+ signature is the same as the 2.5.47 signature. And
50
* as of 2.6.23-rc1 sendfile is gone, replaced by splice_read...
52
* Let's not support sendfile from 2.5.30 to 2.5.47, because the 2.5.30
53
* signature is much different and file_send_actor isn't externed.
55
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23)
56
#define VMW_SENDFILE_NONE
57
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 8)
58
#define VMW_SENDFILE_NEW
59
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 70)
60
#define VMW_SENDFILE_OLD
61
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 47)
62
#define VMW_SENDFILE_NEW
64
#define VMW_SENDFILE_NONE
68
* splice_read is there since 2.6.17, but let's avoid 2.6.17-rcX kernels...
69
* After all nobody is using splice system call until 2.6.23 using it to
72
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18)
73
#define VMW_SPLICE_READ 1
77
* Filesystems wishing to use generic page cache read/write routines are
78
* supposed to implement aio_read and aio_write (calling into
79
* generic_file_aio_read() and generic_file_aio_write() if necessary).
81
* The VFS exports do_sync_read() and do_sync_write() as the "new"
82
* generic_file_read() and generic_file_write(), but filesystems need not
83
* actually implement read and write- the VFS will automatically call
84
* do_sync_write() and do_sync_read() when applications invoke the standard
85
* read() and write() system calls.
87
* In 2.6.19, generic_file_read() and generic_file_write() were removed,
88
* necessitating this change. AIO dates as far back as 2.5.42, but the API has
89
* changed over time, so for simplicity, we'll only enable it from 2.6.19 and
92
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
98
* The alloc_inode and destroy_inode VFS ops didn't exist prior to 2.4.21.
99
* Without these functions, file systems can't embed inodes.
101
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 21)
102
# define VMW_EMBED_INODE
107
* iget() was removed from the VFS as of 2.6.25-rc1. The replacement for iget()
108
* is iget_locked() which was added in 2.5.17.
110
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 17)
111
# define VMW_USE_IGET_LOCKED
115
* parent_ino was born in 2.5.5. For older kernels, let's use 2.5.5
116
* implementation. It uses the dcache lock which is OK because per-dentry
117
* locking appeared after 2.5.5.
119
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 5)
120
#define compat_parent_ino(dentry) parent_ino(dentry)
122
#define compat_parent_ino(dentry) \
125
spin_lock(&dcache_lock); \
126
res = dentry->d_parent->d_inode->i_ino; \
127
spin_unlock(&dcache_lock); \
134
* putname changed to __putname in 2.6.6.
136
#define compat___getname() __getname()
137
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 6)
138
#define compat___putname(name) putname(name)
140
#define compat___putname(name) __putname(name)
145
* inc_nlink, drop_nlink, and clear_nlink were added in 2.6.19.
147
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
148
#define compat_inc_nlink(inode) ((inode)->i_nlink++)
149
#define compat_drop_nlink(inode) ((inode)->i_nlink--)
150
#define compat_clear_nlink(inode) ((inode)->i_nlink = 0)
152
#define compat_inc_nlink(inode) inc_nlink(inode)
153
#define compat_drop_nlink(inode) drop_nlink(inode)
154
#define compat_clear_nlink(inode) clear_nlink(inode)
159
* i_size_write and i_size_read were introduced in 2.6.0-test1
160
* (though we'll look for them as of 2.6.1). They employ slightly different
161
* locking in order to guarantee atomicity, depending on the length of a long,
162
* whether the kernel is SMP, or whether the kernel is preemptible. Prior to
163
* i_size_write and i_size_read, there was no such locking, so that's the
164
* behavior we'll emulate.
166
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 1)
167
#define compat_i_size_read(inode) ((inode)->i_size)
168
#define compat_i_size_write(inode, size) ((inode)->i_size = size)
170
#define compat_i_size_read(inode) i_size_read(inode)
171
#define compat_i_size_write(inode, size) i_size_write(inode, size)
176
* filemap_fdatawrite was introduced in 2.5.12. Prior to that, modules used
177
* filemap_fdatasync instead. In 2.4.18, both filemap_fdatawrite and
178
* filemap_fdatawait began returning status codes. Prior to that, they were
179
* void functions, so we'll just have them return 0.
181
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 18)
182
#define compat_filemap_fdatawrite(mapping) \
185
filemap_fdatasync(mapping); \
188
#define compat_filemap_fdatawait(mapping) \
191
filemap_fdatawait(mapping); \
194
#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 12)
195
#define compat_filemap_fdatawrite(mapping) filemap_fdatasync(mapping)
196
#define compat_filemap_fdatawait(mapping) filemap_fdatawait(mapping)
198
#define compat_filemap_fdatawrite(mapping) filemap_fdatawrite(mapping)
199
#define compat_filemap_fdatawait(mapping) filemap_fdatawait(mapping)
204
* filemap_write_and_wait was introduced in 2.6.6 and exported for module use
205
* in 2.6.16. It's really just a simple wrapper around filemap_fdatawrite and
206
* and filemap_fdatawait, which initiates a flush of all dirty pages, then
207
* waits for the pages to flush. The implementation here is a simplified form
208
* of the one found in 2.6.20-rc3.
210
* Unfortunately, it just isn't possible to implement this prior to 2.4.5, when
211
* neither filemap_fdatawait nor filemap_fdatasync were exported for module
212
* use. So we'll define it out and hope for the best.
214
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 5)
215
#define compat_filemap_write_and_wait(mapping)
216
#elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
217
#define compat_filemap_write_and_wait(mapping) \
220
if (mapping->nrpages) { \
221
result = compat_filemap_fdatawrite(mapping); \
222
if (result != -EIO) { \
223
int result2 = compat_filemap_fdatawait(mapping); \
232
#define compat_filemap_write_and_wait(mapping) filemap_write_and_wait(mapping)
237
* invalidate_remote_inode was introduced in 2.6.0-test5. Prior to that,
238
* filesystems wishing to invalidate pages belonging to an inode called
239
* invalidate_inode_pages.
241
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
242
#define compat_invalidate_remote_inode(inode) invalidate_inode_pages(inode)
244
#define compat_invalidate_remote_inode(inode) invalidate_remote_inode(inode)
247
#endif /* __COMPAT_FS_H__ */