7ed4d057edc5a89df1382718913d0890a103b950
[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 /* Use this instead of dget for dentry operations
475  * that occur under a higher lock (e.g. alias processing).
476  * Requires that the higher lock (e.g. dcache_lock or
477  * inode->i_lock) is already held.
478  */
479 static inline void
480 afs_linux_dget(struct dentry *dp) {
481 #if defined(HAVE_DCACHE_LOCK)
482     dget_locked(dp);
483 #else
484     dget(dp);
485 #endif
486 }
487
488
489 static inline int
490 afs_inode_setattr(struct osi_file *afile, struct iattr *newattrs) {
491
492     int code = 0;
493     struct inode *inode = OSIFILE_INODE(afile);
494 #if !defined(HAVE_LINUX_INODE_SETATTR)
495     code = inode->i_op->setattr(afile->filp->f_dentry, newattrs);
496 #elif defined(INODE_SETATTR_NOT_VOID)
497     if (inode->i_op && inode->i_op->setattr)
498         code = inode->i_op->setattr(afile->filp->f_dentry, newattrs);
499     else
500         code = inode_setattr(inode, newattrs);
501 #else
502     inode_setattr(inode, newattrs);
503 #endif
504     return code;
505 }
506
507 #if defined(HAVE_LINUX_PATH_LOOKUP)
508 static inline int
509 afs_kern_path(char *aname, int flags, struct nameidata *nd) {
510     return path_lookup(aname, flags, nd);
511 }
512 #else
513 static inline int
514 afs_kern_path(char *aname, int flags, afs_linux_path_t *path) {
515     return kern_path(aname, flags, path);
516 }
517 #endif
518
519 static inline void
520 #if defined(HAVE_LINUX_PATH_LOOKUP)
521 afs_get_dentry_ref(struct nameidata *nd, struct vfsmount **mnt, struct dentry **dpp) {
522 #else
523 afs_get_dentry_ref(afs_linux_path_t *path, struct vfsmount **mnt, struct dentry **dpp) {
524 #endif
525 #if defined(HAVE_LINUX_PATH_LOOKUP)
526 # if defined(STRUCT_NAMEIDATA_HAS_PATH)
527     *dpp = dget(nd->path.dentry);
528     if (mnt)
529         *mnt = mntget(nd->path.mnt);
530     path_put(&nd->path);
531 # else
532     *dpp = dget(nd->dentry);
533     if (mnt)
534         *mnt = mntget(nd->mnt);
535     path_release(nd);
536 # endif
537 #else
538     *dpp = dget(path->dentry);
539     if (mnt)
540         *mnt = mntget(path->mnt);
541     path_put(path);
542 #endif
543 }
544
545 /* wait_event_freezable appeared with 2.6.24 */
546
547 /* These implement the original AFS wait behaviour, with respect to the
548  * refrigerator, rather than the behaviour of the current wait_event_freezable
549  * implementation.
550  */
551
552 #ifndef wait_event_freezable
553 # define wait_event_freezable(waitqueue, condition)                             \
554 ({                                                                              \
555     int _ret;                                                                   \
556     do {                                                                        \
557         _ret = wait_event_interruptible(waitqueue,                              \
558                                         (condition) || freezing(current));      \
559         if (_ret && !freezing(current))                                 \
560             break;                                                              \
561         else if (!(condition))                                                  \
562             _ret = -EINTR;                                                      \
563     } while (afs_try_to_freeze());                                              \
564     _ret;                                                                       \
565 })
566
567 # define wait_event_freezable_timeout(waitqueue, condition, timeout)            \
568 ({                                                                              \
569      int _ret;                                                                  \
570      do {                                                                       \
571         _ret = wait_event_interruptible_timeout(waitqueue,                      \
572                                                 (condition ||                   \
573                                                  freezing(current)),            \
574                                                 timeout);                       \
575      } while (afs_try_to_freeze());                                             \
576      _ret;                                                                      \
577 })
578 #endif
579
580 #if defined(STRUCT_TASK_STRUCT_HAS_CRED)
581 static inline struct file *
582 afs_dentry_open(struct dentry *dp, struct vfsmount *mnt, int flags, const struct cred *creds) {
583 #if defined(DENTRY_OPEN_TAKES_PATH)
584     afs_linux_path_t path;
585     struct file *filp;
586     path.mnt = mnt;
587     path.dentry = dp;
588     /* note that dentry_open will path_get for us */
589     filp = dentry_open(&path, flags, creds);
590     return filp;
591 #else
592     return dentry_open(dget(dp), mntget(mnt), flags, creds);
593 #endif
594 }
595 #endif
596
597 static inline int
598 afs_truncate(struct inode *inode, int len)
599 {
600     int code;
601 #if defined(STRUCT_INODE_OPERATIONS_HAS_TRUNCATE)
602     code = vmtruncate(inode, len);
603 #else
604     code = inode_newsize_ok(inode, len);
605     if (!code)
606         truncate_setsize(inode, len);
607 #endif
608     return code;
609 }
610
611 static inline struct proc_dir_entry *
612 afs_proc_create(char *name, umode_t mode, struct proc_dir_entry *parent, struct file_operations *fops) {
613 #if defined(HAVE_LINUX_PROC_CREATE)
614     return proc_create(name, mode, parent, fops);
615 #else
616     struct proc_dir_entry *entry;
617     entry = create_proc_entry(name, mode, parent);
618     if (entry)
619         entry->proc_fops = fops;
620     return entry;
621 #endif
622 }
623
624 static inline int
625 afs_dentry_count(struct dentry *dp)
626 {
627 #if defined(HAVE_LINUX_D_COUNT)
628     return d_count(dp);
629 #elif defined(D_COUNT_INT)
630     return dp->d_count;
631 #else
632     return atomic_read(&dp->d_count);
633 #endif
634 }
635
636 static inline void
637 afs_maybe_shrink_dcache(struct dentry *dp)
638 {
639 #if defined(HAVE_LINUX_D_COUNT) || defined(D_COUNT_INT)
640     spin_lock(&dp->d_lock);
641     if (afs_dentry_count(dp) > 1) {
642         spin_unlock(&dp->d_lock);
643         shrink_dcache_parent(dp);
644     } else
645         spin_unlock(&dp->d_lock);
646 #else
647     if (afs_dentry_count(dp) > 1)
648         shrink_dcache_parent(dp);
649 #endif
650 }
651
652 static inline int
653 afs_d_invalidate(struct dentry *dp)
654 {
655 #if defined(D_INVALIDATE_IS_VOID)
656     d_invalidate(dp);
657     return 0;
658 #else
659     return d_invalidate(dp);
660 #endif
661 }
662
663 #if defined(HAVE_LINUX___VFS_WRITE)
664 # define AFS_FILE_NEEDS_SET_FS 1
665 #elif defined(HAVE_LINUX_KERNEL_WRITE)
666 /* #undef AFS_FILE_NEEDS_SET_FS */
667 #else
668 # define AFS_FILE_NEEDS_SET_FS 1
669 #endif
670
671 static inline int
672 afs_file_read(struct file *filp, char __user *buf, size_t len, loff_t *pos)
673 {
674 #if defined(HAVE_LINUX___VFS_WRITE)
675     return __vfs_read(filp, buf, len, pos);
676 #elif defined(HAVE_LINUX_KERNEL_WRITE)
677 # if defined(KERNEL_READ_OFFSET_IS_LAST)
678     return kernel_read(filp, buf, len, pos);
679 # else
680     return kernel_read(filp, *pos, buf, len);
681 # endif
682 #else
683     return filp->f_op->read(filp, buf, len, pos);
684 #endif
685 }
686
687 static inline int
688 afs_file_write(struct file *filp, char __user *buf, size_t len, loff_t *pos)
689 {
690 #if defined(HAVE_LINUX___VFS_WRITE)
691     return __vfs_write(filp, buf, len, pos);
692 #elif defined(HAVE_LINUX_KERNEL_WRITE)
693 # if defined(KERNEL_READ_OFFSET_IS_LAST)
694     return kernel_write(filp, buf, len, pos);
695 # else
696     return kernel_write(filp, buf, len, *pos);
697 # endif
698 #else
699     return filp->f_op->write(filp, buf, len, pos);
700 #endif
701 }
702
703 #endif /* AFS_LINUX_OSI_COMPAT_H */