62fce213dee15a5d1951bd16227aa8ebe5c9df68
[openafs.git] / src / afs / LINUX / osi_compat.h
1 /* Kernel compatibility routines
2  *
3  * This file contains definitions to provide compatibility between different
4  * versions of the Linux kernel. It is an ifdef maze, but the idea is that
5  * by concentrating the horror here, the rest of the tree may remaing a
6  * little cleaner...
7  */
8
9 #ifndef AFS_LINUX_OSI_COMPAT_H
10 #define AFS_LINUX_OSI_COMPAT_H
11
12 #if defined(HAVE_LINUX_FREEZER_H)
13 # include <linux/freezer.h>
14 #endif
15
16 #if defined(LINUX_KEYRING_SUPPORT)
17 # include <linux/rwsem.h>
18 # include <linux/key.h>
19 # if defined(HAVE_LINUX_KEY_TYPE_H)
20 #  include <linux/key-type.h>
21 # endif
22 # ifndef KEY_ALLOC_IN_QUOTA
23 /* Before these flags were added in Linux commit v2.6.18-rc1~816,
24  * key_alloc just took a boolean not_in_quota */
25 #  define KEY_ALLOC_IN_QUOTA 0
26 #  define KEY_ALLOC_NOT_IN_QUOTA 1
27 # endif
28 #endif
29
30 #if defined(STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT) && !defined(DCACHE_NEED_AUTOMOUNT)
31 # define DCACHE_NEED_AUTOMOUNT DMANAGED_AUTOMOUNT
32 #endif
33
34 #ifdef HAVE_LINUX_STRUCT_VFS_PATH
35 typedef struct vfs_path afs_linux_path_t;
36 #else
37 typedef struct path afs_linux_path_t;
38 #endif
39
40 #if defined(STRUCT_DENTRY_HAS_D_U_D_ALIAS)
41 # define d_alias d_u.d_alias
42 #endif
43
44 #if defined(STRUCT_FILE_HAS_F_PATH)
45 # if !defined(f_dentry)
46 #  define f_dentry f_path.dentry
47 # endif
48 #endif
49
50 #ifndef HAVE_LINUX_FILE_DENTRY
51 #define file_dentry(file) ((file)->f_dentry)
52 #endif
53
54 #if defined(HAVE_LINUX_LOCKS_LOCK_FILE_WAIT)
55 # define flock_lock_file_wait locks_lock_file_wait
56 #endif
57
58 #if !defined(HAVE_LINUX_DO_SYNC_READ) && !defined(STRUCT_FILE_OPERATIONS_HAS_READ_ITER)
59 static inline int
60 do_sync_read(struct file *fp, char *buf, size_t count, loff_t *offp) {
61     return generic_file_read(fp, buf, count, offp);
62 }
63
64 static inline int
65 do_sync_write(struct file *fp, char *buf, size_t count, loff_t *offp) {
66     return generic_file_write(fp, buf, count, offp);
67 }
68
69 #endif /* DO_SYNC_READ */
70
71 static inline int
72 afs_posix_lock_file(struct file *fp, struct file_lock *flp) {
73 #ifdef POSIX_LOCK_FILE_WAIT_ARG
74     return posix_lock_file(fp, flp, NULL);
75 #else
76     flp->fl_flags &=~ FL_SLEEP;
77     return posix_lock_file(fp, flp);
78 #endif
79 }
80
81 static inline void
82 afs_posix_test_lock(struct file *fp, struct file_lock *flp) {
83 #if defined(POSIX_TEST_LOCK_CONFLICT_ARG)
84     struct file_lock conflict;
85     if (posix_test_lock(fp, flp, &conflict)) {
86         locks_copy_lock(flp, &conflict);
87         flp->fl_type = F_UNLCK;
88     }
89 #elif defined(POSIX_TEST_LOCK_RETURNS_CONFLICT)
90     struct file_lock *conflict;
91     conflict = posix_test_lock(fp, flp);
92     if (conflict) {
93         locks_copy_lock(flp, conflict);
94         flp->fl_type = F_UNLCK;
95     }
96 #else
97     posix_test_lock(fp, flp);
98 #endif
99 }
100
101 #ifdef DCACHE_NFSFS_RENAMED
102 static inline void
103 afs_linux_clear_nfsfs_renamed(struct dentry *dp) {
104     spin_lock(&dp->d_lock);
105     dp->d_flags &= ~DCACHE_NFSFS_RENAMED;
106     spin_unlock(&dp->d_lock);
107 }
108
109 static inline void
110 afs_linux_set_nfsfs_renamed(struct dentry *dp) {
111     spin_lock(&dp->d_lock);
112     dp->d_flags |= DCACHE_NFSFS_RENAMED;
113     spin_unlock(&dp->d_lock);
114 }
115
116 static inline int
117 afs_linux_nfsfs_renamed(struct dentry *dp) {
118     return dp->d_flags & DCACHE_NFSFS_RENAMED;
119 }
120
121 #else
122 static inline void afs_linux_clear_nfsfs_renamed(void) { return; }
123 static inline void afs_linux_set_nfsfs_renamed(void) { return; }
124 #endif
125
126 #ifndef HAVE_LINUX_HLIST_UNHASHED
127 static void
128 hlist_unhashed(const struct hlist_node *h) {
129     return (!h->pprev == NULL);
130 }
131 #endif
132
133 #if defined(WRITEPAGE_ACTIVATE)
134 #define AOP_WRITEPAGE_ACTIVATE WRITEPAGE_ACTIVATE
135 #endif
136
137 #if defined(STRUCT_ADDRESS_SPACE_OPERATIONS_HAS_WRITE_BEGIN) && !defined(HAVE_LINUX_GRAB_CACHE_PAGE_WRITE_BEGIN)
138 static inline struct page *
139 grab_cache_page_write_begin(struct address_space *mapping, pgoff_t index,
140                             unsigned int flags) {
141     return __grab_cache_page(mapping, index);
142 }
143 #endif
144
145 #if defined(HAVE_KMEM_CACHE_T)
146 #define afs_kmem_cache_t kmem_cache_t
147 #else
148 #define afs_kmem_cache_t struct kmem_cache
149 #endif
150
151 extern void init_once(void *);
152 #if defined(HAVE_KMEM_CACHE_T)
153 static inline void
154 init_once_func(void * foo, kmem_cache_t * cachep, unsigned long flags) {
155 #if defined(SLAB_CTOR_VERIFY)
156     if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
157         SLAB_CTOR_CONSTRUCTOR)
158 #endif
159     init_once(foo);
160 }
161 #elif defined(KMEM_CACHE_INIT)
162 static inline void
163 init_once_func(struct kmem_cache * cachep, void * foo) {
164     init_once(foo);
165 }
166 #elif !defined(KMEM_CACHE_CTOR_TAKES_VOID)
167 static inline void
168 init_once_func(void * foo, struct kmem_cache * cachep, unsigned long flags) {
169 #if defined(SLAB_CTOR_VERIFY)
170     if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
171         SLAB_CTOR_CONSTRUCTOR)
172 #endif
173     init_once(foo);
174 }
175 #else
176 static inline void
177 init_once_func(void * foo) {
178     init_once(foo);
179 }
180 #endif
181
182 #ifndef SLAB_RECLAIM_ACCOUNT
183 #define SLAB_RECLAIM_ACCOUNT 0
184 #endif
185
186 #if defined(SLAB_KERNEL)
187 #define KALLOC_TYPE SLAB_KERNEL
188 #else
189 #define KALLOC_TYPE GFP_KERNEL
190 #endif
191
192 #ifdef LINUX_KEYRING_SUPPORT
193 static inline struct key *
194 afs_linux_key_alloc(struct key_type *type, const char *desc, afs_kuid_t uid,
195                     afs_kgid_t gid, key_perm_t perm, unsigned long flags)
196 {
197 # if defined(KEY_ALLOC_BYPASS_RESTRICTION)
198     return key_alloc(type, desc, uid, gid, current_cred(), perm, flags, NULL);
199 # elif defined(KEY_ALLOC_NEEDS_STRUCT_TASK)
200     return key_alloc(type, desc, uid, gid, current, perm, flags);
201 # elif defined(KEY_ALLOC_NEEDS_CRED)
202     return key_alloc(type, desc, uid, gid, current_cred(), perm, flags);
203 # else
204     return key_alloc(type, desc, uid, gid, perm, flags);
205 # endif
206 }
207
208 # if defined(STRUCT_TASK_STRUCT_HAS_CRED)
209 static inline struct key *
210 afs_session_keyring(afs_ucred_t *cred)
211 {
212 #  if defined(STRUCT_CRED_HAS_SESSION_KEYRING)
213     return cred->session_keyring;
214 #  else
215     return cred->tgcred->session_keyring;
216 #  endif
217 }
218
219 static inline struct key*
220 afs_linux_search_keyring(afs_ucred_t *cred, struct key_type *type)
221 {
222     key_ref_t key_ref;
223
224     if (afs_session_keyring(cred)) {
225         key_ref = keyring_search(
226                       make_key_ref(afs_session_keyring(cred), 1),
227                       type, "_pag");
228         if (IS_ERR(key_ref))
229             return ERR_CAST(key_ref);
230
231         return key_ref_to_ptr(key_ref);
232     }
233
234     return ERR_PTR(-ENOKEY);
235 }
236 # else
237 static inline struct key*
238 afs_linux_search_keyring(afs_ucred_t *cred, struct key_type *type)
239 {
240     return request_key(type, "_pag", NULL);
241 }
242 # endif /* STRUCT_TASK_STRUCT_HAS_CRED */
243
244 static_inline struct key *
245 afs_set_session_keyring(struct key *keyring)
246 {
247     struct key *old;
248 #if defined(STRUCT_CRED_HAS_SESSION_KEYRING)
249     struct cred *new_creds;
250     old = current_session_keyring();
251     new_creds = prepare_creds();
252     rcu_assign_pointer(new_creds->session_keyring, keyring);
253     commit_creds(new_creds);
254 #else
255     spin_lock_irq(&current->sighand->siglock);
256     old = task_session_keyring(current);
257     smp_wmb();
258     task_session_keyring(current) = keyring;
259     spin_unlock_irq(&current->sighand->siglock);
260 #endif
261     return old;
262 }
263 #endif /* LINUX_KEYRING_SUPPORT */
264
265 #ifdef STRUCT_TASK_STRUCT_HAS_CRED
266 static inline int
267 afs_linux_cred_is_current(afs_ucred_t *cred)
268 {
269     return (cred == current_cred());
270 }
271 #else
272 static inline int
273 afs_linux_cred_is_current(afs_ucred_t *cred)
274 {
275     return 1;
276 }
277 #endif
278
279 #ifndef HAVE_LINUX_PAGE_OFFSET
280 static inline loff_t
281 page_offset(struct page *pp)
282 {
283     return (((loff_t) pp->index) << PAGE_SHIFT);
284 }
285 #endif
286
287 #ifndef HAVE_LINUX_ZERO_USER_SEGMENTS
288 static inline void
289 zero_user_segments(struct page *pp, unsigned int from1, unsigned int to1,
290                    unsigned int from2, unsigned int to2)
291 {
292     void *base = kmap_atomic(pp, KM_USER0);
293
294     if (to1 > from1)
295         memset(base + from1, 0, to1 - from1);
296
297     if (to2 > from2)
298         memset(base + from2, 0, to2 - from2);
299
300     flush_dcache_page(pp);
301     kunmap_atomic(base, KM_USER0);
302 }
303
304 static inline void
305 zero_user_segment(struct page *pp, unsigned int from1, unsigned int to1)
306 {
307     zero_user_segments(pp, from1, to1, 0, 0);
308 }
309 #endif
310
311 #ifndef HAVE_LINUX_KERNEL_SETSOCKOPT
312 /* Available from 2.6.19 */
313
314 static inline int
315 kernel_setsockopt(struct socket *sockp, int level, int name, char *val,
316                   unsigned int len) {
317     mm_segment_t old_fs = get_fs();
318     int ret;
319
320     set_fs(get_ds());
321     ret = sockp->ops->setsockopt(sockp, level, name, val, len);
322     set_fs(old_fs);
323
324     return ret;
325 }
326
327 static inline int
328 kernel_getsockopt(struct socket *sockp, int level, int name, char *val,
329                   int *len) {
330     mm_segment_t old_fs = get_fs();
331     int ret;
332
333     set_fs(get_ds());
334     ret = sockp->ops->getsockopt(sockp, level, name, val, len);
335     set_fs(old_fs);
336
337     return ret;
338 }
339 #endif
340
341 #ifdef HAVE_TRY_TO_FREEZE
342 static inline int
343 afs_try_to_freeze(void) {
344 # ifdef LINUX_REFRIGERATOR_TAKES_PF_FREEZE
345     return try_to_freeze(PF_FREEZE);
346 # else
347     return try_to_freeze();
348 # endif
349 }
350 #else
351 static inline int
352 afs_try_to_freeze(void) {
353 # ifdef CONFIG_PM
354     if (current->flags & PF_FREEZE) {
355         refrigerator(PF_FREEZE);
356         return 1;
357     }
358 # endif
359     return 0;
360 }
361 #endif
362
363 /* The commit which changed refrigerator so that it takes no arguments
364  * also added freezing(), so if LINUX_REFRIGERATOR_TAKES_PF_FREEZE is
365  * true, the kernel doesn't have a freezing() function.
366  */
367 #ifdef LINUX_REFRIGERATOR_TAKES_PF_FREEZE
368 static inline int
369 freezing(struct task_struct *p)
370 {
371 # ifdef CONFIG_PM
372     return p->flags & PF_FREEZE;
373 # else
374     return 0;
375 # endif
376 }
377 #endif
378
379 #if !defined(HAVE_LINUX_PAGECHECKED)
380 # if defined(HAVE_LINUX_PAGEFSMISC)
381 #  include <linux/page-flags.h>
382
383 #  define PageChecked(p)            PageFsMisc((p))
384 #  define SetPageChecked(p)         SetPageFsMisc((p))
385 #  define ClearPageChecked(p)       ClearPageFsMisc((p))
386
387 # endif
388 #endif
389
390 #if !defined(NEW_EXPORT_OPS)
391 extern struct export_operations export_op_default;
392 #endif
393
394 static inline struct dentry *
395 afs_get_dentry_from_fh(struct super_block *afs_cacheSBp, afs_dcache_id_t *ainode,
396                 int cache_fh_len, int cache_fh_type,
397                 int (*afs_fh_acceptable)(void *, struct dentry *)) {
398 #if defined(NEW_EXPORT_OPS)
399     return afs_cacheSBp->s_export_op->fh_to_dentry(afs_cacheSBp, &ainode->ufs.fh,
400                 cache_fh_len, cache_fh_type);
401 #else
402     if (afs_cacheSBp->s_export_op && afs_cacheSBp->s_export_op->decode_fh)
403         return afs_cacheSBp->s_export_op->decode_fh(afs_cacheSBp, ainode->ufs.raw,
404                         cache_fh_len, cache_fh_type, afs_fh_acceptable, NULL);
405     else
406         return export_op_default.decode_fh(afs_cacheSBp, ainode->ufs.raw,
407                         cache_fh_len, cache_fh_type, afs_fh_acceptable, NULL);
408 #endif
409 }
410
411 static inline int
412 afs_get_fh_from_dentry(struct dentry *dp, afs_ufs_dcache_id_t *ainode, int *max_lenp) {
413     if (dp->d_sb->s_export_op->encode_fh)
414 #if defined(EXPORT_OP_ENCODE_FH_TAKES_INODES)
415         return dp->d_sb->s_export_op->encode_fh(dp->d_inode, &ainode->raw[0], max_lenp, NULL);
416 #else
417         return dp->d_sb->s_export_op->encode_fh(dp, &ainode->raw[0], max_lenp, 0);
418 #endif
419 #if defined(NEW_EXPORT_OPS)
420     /* If fs doesn't provide an encode_fh method, assume the default INO32 type */
421     *max_lenp = sizeof(struct fid)/4;
422     ainode->fh.i32.ino = dp->d_inode->i_ino;
423     ainode->fh.i32.gen = dp->d_inode->i_generation;
424     return FILEID_INO32_GEN;
425 #else
426     /* or call the default encoding function for the old API */
427     return export_op_default.encode_fh(dp, &ainode->raw[0], max_lenp, 0);
428 #endif
429 }
430
431 static inline void
432 afs_init_sb_export_ops(struct super_block *sb) {
433 #if !defined(NEW_EXPORT_OPS)
434     /*
435      * decode_fh will call this function.  If not defined for this FS, make
436      * sure it points to the default
437      */
438     if (!sb->s_export_op->find_exported_dentry) {
439         /* Some kernels (at least 2.6.9) do not prototype find_exported_dentry,
440          * even though it is exported, so prototype it ourselves. Newer
441          * kernels do prototype it, but as long as our protoype matches the
442          * real one (the signature never changed before NEW_EXPORT_OPS came
443          * into play), there should be no problems. */
444         extern struct dentry * find_exported_dentry(struct super_block *sb, void *obj, void *parent,
445                                                     int (*acceptable)(void *context, struct dentry *de),
446                                                     void *context);
447         sb->s_export_op->find_exported_dentry = find_exported_dentry;
448     }
449 #endif
450 }
451
452 static inline void
453 afs_linux_lock_inode(struct inode *ip) {
454 #if defined(HAVE_LINUX_INODE_LOCK)
455     inode_lock(ip);
456 #elif defined(STRUCT_INODE_HAS_I_MUTEX)
457     mutex_lock(&ip->i_mutex);
458 #else
459     down(&ip->i_sem);
460 #endif
461 }
462
463 static inline void
464 afs_linux_unlock_inode(struct inode *ip) {
465 #if defined(HAVE_LINUX_INODE_LOCK)
466     inode_unlock(ip);
467 #elif defined(STRUCT_INODE_HAS_I_MUTEX)
468     mutex_unlock(&ip->i_mutex);
469 #else
470     up(&ip->i_sem);
471 #endif
472 }
473
474 static inline int
475 afs_inode_setattr(struct osi_file *afile, struct iattr *newattrs) {
476
477     int code = 0;
478     struct inode *inode = OSIFILE_INODE(afile);
479 #if !defined(HAVE_LINUX_INODE_SETATTR)
480     code = inode->i_op->setattr(afile->filp->f_dentry, newattrs);
481 #elif defined(INODE_SETATTR_NOT_VOID)
482     if (inode->i_op && inode->i_op->setattr)
483         code = inode->i_op->setattr(afile->filp->f_dentry, newattrs);
484     else
485         code = inode_setattr(inode, newattrs);
486 #else
487     inode_setattr(inode, newattrs);
488 #endif
489     return code;
490 }
491
492 #if defined(HAVE_LINUX_PATH_LOOKUP)
493 static inline int
494 afs_kern_path(char *aname, int flags, struct nameidata *nd) {
495     return path_lookup(aname, flags, nd);
496 }
497 #else
498 static inline int
499 afs_kern_path(char *aname, int flags, afs_linux_path_t *path) {
500     return kern_path(aname, flags, path);
501 }
502 #endif
503
504 static inline void
505 #if defined(HAVE_LINUX_PATH_LOOKUP)
506 afs_get_dentry_ref(struct nameidata *nd, struct vfsmount **mnt, struct dentry **dpp) {
507 #else
508 afs_get_dentry_ref(afs_linux_path_t *path, struct vfsmount **mnt, struct dentry **dpp) {
509 #endif
510 #if defined(HAVE_LINUX_PATH_LOOKUP)
511 # if defined(STRUCT_NAMEIDATA_HAS_PATH)
512     *dpp = dget(nd->path.dentry);
513     if (mnt)
514         *mnt = mntget(nd->path.mnt);
515     path_put(&nd->path);
516 # else
517     *dpp = dget(nd->dentry);
518     if (mnt)
519         *mnt = mntget(nd->mnt);
520     path_release(nd);
521 # endif
522 #else
523     *dpp = dget(path->dentry);
524     if (mnt)
525         *mnt = mntget(path->mnt);
526     path_put(path);
527 #endif
528 }
529
530 /* wait_event_freezable appeared with 2.6.24 */
531
532 /* These implement the original AFS wait behaviour, with respect to the
533  * refrigerator, rather than the behaviour of the current wait_event_freezable
534  * implementation.
535  */
536
537 #ifndef wait_event_freezable
538 # define wait_event_freezable(waitqueue, condition)                             \
539 ({                                                                              \
540     int _ret;                                                                   \
541     do {                                                                        \
542         _ret = wait_event_interruptible(waitqueue,                              \
543                                         (condition) || freezing(current));      \
544         if (_ret && !freezing(current))                                 \
545             break;                                                              \
546         else if (!(condition))                                                  \
547             _ret = -EINTR;                                                      \
548     } while (afs_try_to_freeze());                                              \
549     _ret;                                                                       \
550 })
551
552 # define wait_event_freezable_timeout(waitqueue, condition, timeout)            \
553 ({                                                                              \
554      int _ret;                                                                  \
555      do {                                                                       \
556         _ret = wait_event_interruptible_timeout(waitqueue,                      \
557                                                 (condition ||                   \
558                                                  freezing(current)),            \
559                                                 timeout);                       \
560      } while (afs_try_to_freeze());                                             \
561      _ret;                                                                      \
562 })
563 #endif
564
565 #if defined(STRUCT_TASK_STRUCT_HAS_CRED)
566 static inline struct file *
567 afs_dentry_open(struct dentry *dp, struct vfsmount *mnt, int flags, const struct cred *creds) {
568 #if defined(DENTRY_OPEN_TAKES_PATH)
569     afs_linux_path_t path;
570     struct file *filp;
571     path.mnt = mnt;
572     path.dentry = dp;
573     /* note that dentry_open will path_get for us */
574     filp = dentry_open(&path, flags, creds);
575     return filp;
576 #else
577     return dentry_open(dget(dp), mntget(mnt), flags, creds);
578 #endif
579 }
580 #endif
581
582 static inline int
583 afs_truncate(struct inode *inode, int len)
584 {
585     int code;
586 #if defined(STRUCT_INODE_OPERATIONS_HAS_TRUNCATE)
587     code = vmtruncate(inode, len);
588 #else
589     code = inode_newsize_ok(inode, len);
590     if (!code)
591         truncate_setsize(inode, len);
592 #endif
593     return code;
594 }
595
596 static inline struct proc_dir_entry *
597 afs_proc_create(char *name, umode_t mode, struct proc_dir_entry *parent, struct file_operations *fops) {
598 #if defined(HAVE_LINUX_PROC_CREATE)
599     return proc_create(name, mode, parent, fops);
600 #else
601     struct proc_dir_entry *entry;
602     entry = create_proc_entry(name, mode, parent);
603     if (entry)
604         entry->proc_fops = fops;
605     return entry;
606 #endif
607 }
608
609 static inline int
610 afs_dentry_count(struct dentry *dp)
611 {
612 #if defined(HAVE_LINUX_D_COUNT)
613     return d_count(dp);
614 #elif defined(D_COUNT_INT)
615     return dp->d_count;
616 #else
617     return atomic_read(&dp->d_count);
618 #endif
619 }
620
621 static inline void
622 afs_maybe_shrink_dcache(struct dentry *dp)
623 {
624 #if defined(HAVE_LINUX_D_COUNT) || defined(D_COUNT_INT)
625     spin_lock(&dp->d_lock);
626     if (afs_dentry_count(dp) > 1) {
627         spin_unlock(&dp->d_lock);
628         shrink_dcache_parent(dp);
629     } else
630         spin_unlock(&dp->d_lock);
631 #else
632     if (afs_dentry_count(dp) > 1)
633         shrink_dcache_parent(dp);
634 #endif
635 }
636
637 static inline int
638 afs_d_invalidate(struct dentry *dp)
639 {
640 #if defined(D_INVALIDATE_IS_VOID)
641     d_invalidate(dp);
642     return 0;
643 #else
644     return d_invalidate(dp);
645 #endif
646 }
647
648 #if defined(HAVE_LINUX___VFS_WRITE)
649 # define AFS_FILE_NEEDS_SET_FS 1
650 #elif defined(HAVE_LINUX_KERNEL_WRITE)
651 /* #undef AFS_FILE_NEEDS_SET_FS */
652 #else
653 # define AFS_FILE_NEEDS_SET_FS 1
654 #endif
655
656 static inline int
657 afs_file_read(struct file *filp, char __user *buf, size_t len, loff_t *pos)
658 {
659 #if defined(HAVE_LINUX___VFS_WRITE)
660     return __vfs_read(filp, buf, len, pos);
661 #elif defined(HAVE_LINUX_KERNEL_WRITE)
662 # if defined(LINUX_KERNEL_READ_OFFSET_IS_LAST)
663     return kernel_read(filp, buf, len, pos);
664 # else
665     return kernel_read(filp, *pos, buf, len);
666 # endif
667 #else
668     return filp->f_op->read(filp, buf, len, pos);
669 #endif
670 }
671
672 static inline int
673 afs_file_write(struct file *filp, char __user *buf, size_t len, loff_t *pos)
674 {
675 #if defined(HAVE_LINUX___VFS_WRITE)
676     return __vfs_write(filp, buf, len, pos);
677 #elif defined(HAVE_LINUX_KERNEL_WRITE)
678 # if defined(LINUX_KERNEL_READ_OFFSET_IS_LAST)
679     return kernel_write(filp, buf, len, pos);
680 # else
681     return kernel_write(filp, buf, len, *pos);
682 # endif
683 #else
684     return filp->f_op->write(filp, buf, len, pos);
685 #endif
686 }
687
688 #endif /* AFS_LINUX_OSI_COMPAT_H */