Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/include/linux/fs.h
Show All 39 Lines | |||||
#include <sys/filedesc.h> | #include <sys/filedesc.h> | ||||
#include <linux/types.h> | #include <linux/types.h> | ||||
#include <linux/wait.h> | #include <linux/wait.h> | ||||
#include <linux/semaphore.h> | #include <linux/semaphore.h> | ||||
#include <linux/spinlock.h> | #include <linux/spinlock.h> | ||||
#include <linux/dcache.h> | #include <linux/dcache.h> | ||||
#include <linux/capability.h> | #include <linux/capability.h> | ||||
#include <linux/wait_bit.h> | #include <linux/wait_bit.h> | ||||
#include <linux/kernel.h> | |||||
#include <linux/mutex.h> | |||||
struct module; | struct module; | ||||
struct kiocb; | struct kiocb; | ||||
struct iovec; | struct iovec; | ||||
struct dentry; | struct dentry; | ||||
struct page; | struct page; | ||||
struct file_lock; | struct file_lock; | ||||
struct pipe_inode_info; | struct pipe_inode_info; | ||||
▲ Show 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | |||||
nonseekable_open(struct inode *inode, struct file *filp) | nonseekable_open(struct inode *inode, struct file *filp) | ||||
{ | { | ||||
return 0; | return 0; | ||||
} | } | ||||
static inline int | static inline int | ||||
simple_open(struct inode *inode, struct file *filp) | simple_open(struct inode *inode, struct file *filp) | ||||
{ | { | ||||
filp->private_data = inode->i_private; | |||||
return 0; | return 0; | ||||
} | } | ||||
extern unsigned int linux_iminor(struct inode *); | extern unsigned int linux_iminor(struct inode *); | ||||
#define iminor(...) linux_iminor(__VA_ARGS__) | #define iminor(...) linux_iminor(__VA_ARGS__) | ||||
static inline struct linux_file * | static inline struct linux_file * | ||||
get_file(struct linux_file *f) | get_file(struct linux_file *f) | ||||
Show All 30 Lines | |||||
} | } | ||||
static inline loff_t | static inline loff_t | ||||
no_llseek(struct file *file, loff_t offset, int whence) | no_llseek(struct file *file, loff_t offset, int whence) | ||||
{ | { | ||||
return (-ESPIPE); | return (-ESPIPE); | ||||
} | } | ||||
#define default_llseek no_llseek | |||||
hselasky: Can you make this a static inline function, instead of using a macro?
static inline loff_t… | |||||
static inline loff_t | static inline loff_t | ||||
noop_llseek(struct linux_file *file, loff_t offset, int whence) | noop_llseek(struct linux_file *file, loff_t offset, int whence) | ||||
{ | { | ||||
return (file->_file->f_offset); | return (file->_file->f_offset); | ||||
} | } | ||||
static inline struct vnode * | static inline struct vnode * | ||||
file_inode(const struct linux_file *file) | file_inode(const struct linux_file *file) | ||||
{ | { | ||||
return (file->f_vnode); | return (file->f_vnode); | ||||
} | } | ||||
static inline int | static inline int | ||||
call_mmap(struct linux_file *file, struct vm_area_struct *vma) | call_mmap(struct linux_file *file, struct vm_area_struct *vma) | ||||
{ | { | ||||
return (file->f_op->mmap(file, vma)); | return (file->f_op->mmap(file, vma)); | ||||
} | } | ||||
static inline void | |||||
i_size_write(struct inode *inode, loff_t i_size) | |||||
{ | |||||
/* inode->i_size = i_size; */ | |||||
markjUnsubmitted Done Inline ActionsWhy is this commented out? markj: Why is this commented out? | |||||
Done Inline ActionsPlease remove this comment. hselasky: Please remove this comment. | |||||
return; | |||||
} | |||||
/* | |||||
* simple_read_from_buffer: copy data from kernel-space origin | |||||
* buffer into user-space destination buffer | |||||
* | |||||
* @dest: destination buffer | |||||
* @read_size: number of bytes to be transferred | |||||
* @ppos: starting transfer position pointer | |||||
* @orig: origin buffer | |||||
* @buf_size: size of destination and origin buffers | |||||
* | |||||
* Return value: | |||||
* On success, total bytes copied with *ppos incremented accordingly. | |||||
* On failure, negative value. | |||||
*/ | |||||
static inline ssize_t | |||||
simple_read_from_buffer(void __user *dest, size_t read_size, loff_t *ppos, | |||||
void *orig, size_t buf_size) | |||||
{ | |||||
void *read_pos = ((char *) orig) + *ppos; | |||||
size_t buf_remain = buf_size - *ppos; | |||||
ssize_t num_read; | |||||
if (buf_remain < 0 || buf_remain > buf_size) | |||||
return -EINVAL; | |||||
if (read_size > buf_remain) | |||||
read_size = buf_remain; | |||||
/* copy_to_user returns number of bytes NOT read */ | |||||
num_read = read_size - copy_to_user(dest, read_pos, read_size); | |||||
if (num_read == 0) | |||||
return -EFAULT; | |||||
*ppos += num_read; | |||||
return (num_read); | |||||
} | |||||
MALLOC_DECLARE(M_LSATTR); | |||||
#define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \ | |||||
static inline int \ | |||||
__fops ## _open(struct inode *inode, struct file *filp) \ | |||||
{ \ | |||||
return (simple_attr_open(inode, filp, __get, __set, __fmt)); \ | |||||
} \ | |||||
static const struct file_operations __fops = { \ | |||||
.owner = THIS_MODULE, \ | |||||
.open = __fops ## _open, \ | |||||
.release = simple_attr_release, \ | |||||
.read = simple_attr_read, \ | |||||
.write = simple_attr_write, \ | |||||
.llseek = no_llseek \ | |||||
} | |||||
int simple_attr_open(struct inode *inode, struct file *filp, | |||||
int (*get)(void *, uint64_t *), int (*set)(void *, uint64_t), | |||||
const char *fmt); | |||||
int simple_attr_release(struct inode *inode, struct file *filp); | |||||
ssize_t simple_attr_read(struct file *filp, char *buf, size_t read_size, loff_t *ppos); | |||||
ssize_t simple_attr_write(struct file *filp, const char __user *buf, | |||||
size_t write_size, loff_t *ppos); | |||||
#endif /* _LINUXKPI_LINUX_FS_H_ */ | #endif /* _LINUXKPI_LINUX_FS_H_ */ |
Can you make this a static inline function, instead of using a macro?
static inline loff_t
default_llseek(....)
This avoids the macro, which may match more than it should.