fs.h (307f78f3ed90a4145eeb2c8cc79bc95b2666f57a) fs.h (f697b9432d9c7aa4c5ab5f5445ef5dc1bd40ce00)
1/*-
2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013-2018 Mellanox Technologies, Ltd.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 31 unchanged lines hidden (view full) ---

40#include <sys/filedesc.h>
41#include <linux/types.h>
42#include <linux/wait.h>
43#include <linux/semaphore.h>
44#include <linux/spinlock.h>
45#include <linux/dcache.h>
46#include <linux/capability.h>
47#include <linux/wait_bit.h>
1/*-
2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013-2018 Mellanox Technologies, Ltd.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 31 unchanged lines hidden (view full) ---

40#include <sys/filedesc.h>
41#include <linux/types.h>
42#include <linux/wait.h>
43#include <linux/semaphore.h>
44#include <linux/spinlock.h>
45#include <linux/dcache.h>
46#include <linux/capability.h>
47#include <linux/wait_bit.h>
48#include <linux/kernel.h>
49#include <linux/mutex.h>
48
49struct module;
50struct kiocb;
51struct iovec;
52struct dentry;
53struct page;
54struct file_lock;
55struct pipe_inode_info;

--- 189 unchanged lines hidden (view full) ---

245nonseekable_open(struct inode *inode, struct file *filp)
246{
247 return 0;
248}
249
250static inline int
251simple_open(struct inode *inode, struct file *filp)
252{
50
51struct module;
52struct kiocb;
53struct iovec;
54struct dentry;
55struct page;
56struct file_lock;
57struct pipe_inode_info;

--- 189 unchanged lines hidden (view full) ---

247nonseekable_open(struct inode *inode, struct file *filp)
248{
249 return 0;
250}
251
252static inline int
253simple_open(struct inode *inode, struct file *filp)
254{
255 filp->private_data = inode->i_private;
253 return 0;
254}
255
256extern unsigned int linux_iminor(struct inode *);
257#define iminor(...) linux_iminor(__VA_ARGS__)
258
259static inline struct linux_file *
260get_file(struct linux_file *f)

--- 32 unchanged lines hidden (view full) ---

293static inline loff_t
294no_llseek(struct file *file, loff_t offset, int whence)
295{
296
297 return (-ESPIPE);
298}
299
300static inline loff_t
256 return 0;
257}
258
259extern unsigned int linux_iminor(struct inode *);
260#define iminor(...) linux_iminor(__VA_ARGS__)
261
262static inline struct linux_file *
263get_file(struct linux_file *f)

--- 32 unchanged lines hidden (view full) ---

296static inline loff_t
297no_llseek(struct file *file, loff_t offset, int whence)
298{
299
300 return (-ESPIPE);
301}
302
303static inline loff_t
304default_llseek(struct file *file, loff_t offset, int whence)
305{
306 return (no_llseek(file, offset, whence));
307}
308
309static inline loff_t
301noop_llseek(struct linux_file *file, loff_t offset, int whence)
302{
303
304 return (file->_file->f_offset);
305}
306
307static inline struct vnode *
308file_inode(const struct linux_file *file)

--- 4 unchanged lines hidden (view full) ---

313
314static inline int
315call_mmap(struct linux_file *file, struct vm_area_struct *vma)
316{
317
318 return (file->f_op->mmap(file, vma));
319}
320
310noop_llseek(struct linux_file *file, loff_t offset, int whence)
311{
312
313 return (file->_file->f_offset);
314}
315
316static inline struct vnode *
317file_inode(const struct linux_file *file)

--- 4 unchanged lines hidden (view full) ---

322
323static inline int
324call_mmap(struct linux_file *file, struct vm_area_struct *vma)
325{
326
327 return (file->f_op->mmap(file, vma));
328}
329
330static inline void
331i_size_write(struct inode *inode, loff_t i_size)
332{
333}
334
335/*
336 * simple_read_from_buffer: copy data from kernel-space origin
337 * buffer into user-space destination buffer
338 *
339 * @dest: destination buffer
340 * @read_size: number of bytes to be transferred
341 * @ppos: starting transfer position pointer
342 * @orig: origin buffer
343 * @buf_size: size of destination and origin buffers
344 *
345 * Return value:
346 * On success, total bytes copied with *ppos incremented accordingly.
347 * On failure, negative value.
348 */
349static inline ssize_t
350simple_read_from_buffer(void __user *dest, size_t read_size, loff_t *ppos,
351 void *orig, size_t buf_size)
352{
353 void *read_pos = ((char *) orig) + *ppos;
354 size_t buf_remain = buf_size - *ppos;
355 ssize_t num_read;
356
357 if (buf_remain < 0 || buf_remain > buf_size)
358 return -EINVAL;
359
360 if (read_size > buf_remain)
361 read_size = buf_remain;
362
363 /* copy_to_user returns number of bytes NOT read */
364 num_read = read_size - copy_to_user(dest, read_pos, read_size);
365 if (num_read == 0)
366 return -EFAULT;
367 *ppos += num_read;
368
369 return (num_read);
370}
371
372MALLOC_DECLARE(M_LSATTR);
373
374#define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
375static inline int \
376__fops ## _open(struct inode *inode, struct file *filp) \
377{ \
378 return (simple_attr_open(inode, filp, __get, __set, __fmt)); \
379} \
380static const struct file_operations __fops = { \
381 .owner = THIS_MODULE, \
382 .open = __fops ## _open, \
383 .release = simple_attr_release, \
384 .read = simple_attr_read, \
385 .write = simple_attr_write, \
386 .llseek = no_llseek \
387}
388
389int simple_attr_open(struct inode *inode, struct file *filp,
390 int (*get)(void *, uint64_t *), int (*set)(void *, uint64_t),
391 const char *fmt);
392
393int simple_attr_release(struct inode *inode, struct file *filp);
394
395ssize_t simple_attr_read(struct file *filp, char *buf, size_t read_size, loff_t *ppos);
396
397ssize_t simple_attr_write(struct file *filp, const char *buf, size_t write_size, loff_t *ppos);
398
321#endif /* _LINUXKPI_LINUX_FS_H_ */
399#endif /* _LINUXKPI_LINUX_FS_H_ */