]>
Commit | Line | Data |
---|---|---|
716154c5 BB |
1 | /*****************************************************************************\ |
2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. | |
3 | * Copyright (C) 2007 The Regents of the University of California. | |
4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). | |
5 | * Written by Brian Behlendorf <behlendorf1@llnl.gov>. | |
6 | * UCRL-CODE-235197 | |
7 | * | |
8 | * This file is part of the SPL, Solaris Porting Layer. | |
3d6af2dd | 9 | * For details, see <http://zfsonlinux.org/>. |
716154c5 BB |
10 | * |
11 | * The SPL is free software; you can redistribute it and/or modify it | |
12 | * under the terms of the GNU General Public License as published by the | |
13 | * Free Software Foundation; either version 2 of the License, or (at your | |
14 | * option) any later version. | |
15 | * | |
16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT | |
17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
19 | * for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License along | |
22 | * with the SPL. If not, see <http://www.gnu.org/licenses/>. | |
23 | \*****************************************************************************/ | |
24 | ||
86de8532 | 25 | #ifndef _SPL_FILE_COMPAT_H |
26 | #define _SPL_FILE_COMPAT_H | |
27 | ||
55abb092 | 28 | #include <linux/fs.h> |
99d6d8dc | 29 | #include <linux/uaccess.h> |
86de8532 | 30 | #ifdef HAVE_FDTABLE_HEADER |
31 | #include <linux/fdtable.h> | |
32 | #endif | |
33 | ||
f0ff89fc BB |
34 | static inline struct file * |
35 | spl_filp_open(const char *name, int flags, int mode, int *err) | |
36 | { | |
37 | struct file *filp = NULL; | |
38 | int rc; | |
39 | ||
40 | filp = filp_open(name, flags, mode); | |
41 | if (IS_ERR(filp)) { | |
42 | rc = PTR_ERR(filp); | |
43 | if (err) | |
44 | *err = rc; | |
45 | filp = NULL; | |
46 | } | |
47 | return filp; | |
48 | } | |
49 | ||
50 | #define spl_filp_close(f) filp_close(f, NULL) | |
51 | #define spl_filp_poff(f) (&(f)->f_pos) | |
52 | #define spl_filp_write(fp, b, s, p) (fp)->f_op->write((fp), (b), (s), p) | |
53 | ||
1c7b3eaf BB |
54 | static inline int |
55 | spl_filp_fallocate(struct file *fp, int mode, loff_t offset, loff_t len) | |
56 | { | |
57 | int error = -EOPNOTSUPP; | |
58 | ||
59 | #ifdef HAVE_FILE_FALLOCATE | |
60 | if (fp->f_op->fallocate) | |
61 | error = fp->f_op->fallocate(fp, mode, offset, len); | |
62 | #else | |
10946b02 | 63 | #ifdef HAVE_INODE_FALLOCATE |
1c7b3eaf BB |
64 | if (fp->f_dentry && fp->f_dentry->d_inode && |
65 | fp->f_dentry->d_inode->i_op->fallocate) | |
66 | error = fp->f_dentry->d_inode->i_op->fallocate( | |
67 | fp->f_dentry->d_inode, mode, offset, len); | |
10946b02 | 68 | #endif /* HAVE_INODE_FALLOCATE */ |
1c7b3eaf BB |
69 | #endif /*HAVE_FILE_FALLOCATE */ |
70 | ||
71 | return (error); | |
72 | } | |
73 | ||
99d6d8dc AX |
74 | static inline ssize_t |
75 | spl_kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos) | |
76 | { | |
77 | #if defined(HAVE_KERNEL_WRITE_PPOS) | |
78 | return (kernel_write(file, buf, count, pos)); | |
79 | #else | |
80 | mm_segment_t saved_fs; | |
81 | ssize_t ret; | |
82 | ||
83 | saved_fs = get_fs(); | |
84 | set_fs(get_ds()); | |
85 | ||
86 | ret = vfs_write(file, (__force const char __user *)buf, count, pos); | |
87 | ||
88 | set_fs(saved_fs); | |
89 | ||
90 | return (ret); | |
91 | #endif | |
92 | } | |
93 | ||
94 | static inline ssize_t | |
95 | spl_kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) | |
96 | { | |
97 | #if defined(HAVE_KERNEL_READ_PPOS) | |
98 | return (kernel_read(file, buf, count, pos)); | |
99 | #else | |
100 | mm_segment_t saved_fs; | |
101 | ssize_t ret; | |
102 | ||
103 | saved_fs = get_fs(); | |
104 | set_fs(get_ds()); | |
105 | ||
106 | ret = vfs_read(file, (void __user *)buf, count, pos); | |
107 | ||
108 | set_fs(saved_fs); | |
109 | ||
110 | return (ret); | |
111 | #endif | |
112 | } | |
113 | ||
10946b02 AX |
114 | #ifdef HAVE_2ARGS_VFS_FSYNC |
115 | #define spl_filp_fsync(fp, sync) vfs_fsync(fp, sync) | |
f0ff89fc | 116 | #else |
10946b02 AX |
117 | #define spl_filp_fsync(fp, sync) vfs_fsync(fp, (fp)->f_dentry, sync) |
118 | #endif /* HAVE_2ARGS_VFS_FSYNC */ | |
f0ff89fc | 119 | |
0f836a62 AX |
120 | #ifdef HAVE_INODE_LOCK_SHARED |
121 | #define spl_inode_lock(ip) inode_lock(ip) | |
122 | #define spl_inode_unlock(ip) inode_unlock(ip) | |
123 | #define spl_inode_lock_shared(ip) inode_lock_shared(ip) | |
124 | #define spl_inode_unlock_shared(ip) inode_unlock_shared(ip) | |
125 | #define spl_inode_trylock(ip) inode_trylock(ip) | |
126 | #define spl_inode_trylock_shared(ip) inode_trylock_shared(ip) | |
127 | #define spl_inode_is_locked(ip) inode_is_locked(ip) | |
128 | #define spl_inode_lock_nested(ip, s) inode_lock_nested(ip, s) | |
129 | #else | |
10946b02 AX |
130 | #define spl_inode_lock(ip) mutex_lock(&(ip)->i_mutex) |
131 | #define spl_inode_unlock(ip) mutex_unlock(&(ip)->i_mutex) | |
0f836a62 AX |
132 | #define spl_inode_lock_shared(ip) mutex_lock(&(ip)->i_mutex) |
133 | #define spl_inode_unlock_shared(ip) mutex_unlock(&(ip)->i_mutex) | |
134 | #define spl_inode_trylock(ip) mutex_trylock(&(ip)->i_mutex) | |
135 | #define spl_inode_trylock_shared(ip) mutex_trylock(&(ip)->i_mutex) | |
136 | #define spl_inode_is_locked(ip) mutex_is_locked(&(ip)->i_mutex) | |
137 | #define spl_inode_lock_nested(ip, s) mutex_lock_nested(&(ip)->i_mutex, s) | |
138 | #endif | |
bcb15891 | 139 | |
86de8532 | 140 | #endif /* SPL_FILE_COMPAT_H */ |
141 |