1 #ifndef _LIB_RING_BUFFER_VFS_H
2 #define _LIB_RING_BUFFER_VFS_H
7 * Wait-free ring buffer VFS file operations.
9 * Copyright (C) 2005-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; only
14 * version 2.1 of the License.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
30 #include <linux/poll.h>
34 extern const struct file_operations lib_ring_buffer_file_operations
;
37 * Internal file operations.
40 int lib_ring_buffer_open(struct inode
*inode
, struct file
*file
);
41 int lib_ring_buffer_release(struct inode
*inode
, struct file
*file
);
42 unsigned int lib_ring_buffer_poll(struct file
*filp
, poll_table
*wait
);
43 ssize_t
lib_ring_buffer_splice_read(struct file
*in
, loff_t
*ppos
,
44 struct pipe_inode_info
*pipe
, size_t len
,
46 int lib_ring_buffer_mmap(struct file
*filp
, struct vm_area_struct
*vma
);
48 /* Ring Buffer ioctl() and ioctl numbers */
49 long lib_ring_buffer_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
);
51 long lib_ring_buffer_compat_ioctl(struct file
*filp
, unsigned int cmd
,
56 * Use RING_BUFFER_GET_NEXT_SUBBUF / RING_BUFFER_PUT_NEXT_SUBBUF to read and
57 * consume sub-buffers sequentially.
59 * Reading sub-buffers without consuming them can be performed with:
61 * RING_BUFFER_SNAPSHOT
62 * RING_BUFFER_SNAPSHOT_GET_CONSUMED
63 * RING_BUFFER_SNAPSHOT_GET_PRODUCED
65 * to get the offset range to consume, and then by passing each sub-buffer
66 * offset to RING_BUFFER_GET_SUBBUF, read the sub-buffer, and then release it
67 * with RING_BUFFER_PUT_SUBBUF.
69 * Note that the "snapshot" API can be used to read the sub-buffer in reverse
70 * order, which is useful for flight recorder snapshots.
73 /* Get a snapshot of the current ring buffer producer and consumer positions */
74 #define RING_BUFFER_SNAPSHOT _IO(0xF6, 0x00)
75 /* Get the consumer position (iteration start) */
76 #define RING_BUFFER_SNAPSHOT_GET_CONSUMED _IOR(0xF6, 0x01, unsigned long)
77 /* Get the producer position (iteration end) */
78 #define RING_BUFFER_SNAPSHOT_GET_PRODUCED _IOR(0xF6, 0x02, unsigned long)
79 /* Get exclusive read access to the specified sub-buffer position */
80 #define RING_BUFFER_GET_SUBBUF _IOW(0xF6, 0x03, unsigned long)
81 /* Release exclusive sub-buffer access */
82 #define RING_BUFFER_PUT_SUBBUF _IO(0xF6, 0x04)
84 /* Get exclusive read access to the next sub-buffer that can be read. */
85 #define RING_BUFFER_GET_NEXT_SUBBUF _IO(0xF6, 0x05)
86 /* Release exclusive sub-buffer access, move consumer forward. */
87 #define RING_BUFFER_PUT_NEXT_SUBBUF _IO(0xF6, 0x06)
88 /* returns the size of the current sub-buffer, without padding (for mmap). */
89 #define RING_BUFFER_GET_SUBBUF_SIZE _IOR(0xF6, 0x07, unsigned long)
90 /* returns the size of the current sub-buffer, with padding (for splice). */
91 #define RING_BUFFER_GET_PADDED_SUBBUF_SIZE _IOR(0xF6, 0x08, unsigned long)
92 /* returns the maximum size for sub-buffers. */
93 #define RING_BUFFER_GET_MAX_SUBBUF_SIZE _IOR(0xF6, 0x09, unsigned long)
94 /* returns the length to mmap. */
95 #define RING_BUFFER_GET_MMAP_LEN _IOR(0xF6, 0x0A, unsigned long)
96 /* returns the offset of the subbuffer belonging to the mmap reader. */
97 #define RING_BUFFER_GET_MMAP_READ_OFFSET _IOR(0xF6, 0x0B, unsigned long)
98 /* flush the current sub-buffer */
99 #define RING_BUFFER_FLUSH _IO(0xF6, 0x0C)
102 /* Get a snapshot of the current ring buffer producer and consumer positions */
103 #define RING_BUFFER_COMPAT_SNAPSHOT RING_BUFFER_SNAPSHOT
104 /* Get the consumer position (iteration start) */
105 #define RING_BUFFER_COMPAT_SNAPSHOT_GET_CONSUMED \
106 _IOR(0xF6, 0x01, compat_ulong_t)
107 /* Get the producer position (iteration end) */
108 #define RING_BUFFER_COMPAT_SNAPSHOT_GET_PRODUCED \
109 _IOR(0xF6, 0x02, compat_ulong_t)
110 /* Get exclusive read access to the specified sub-buffer position */
111 #define RING_BUFFER_COMPAT_GET_SUBBUF _IOW(0xF6, 0x03, compat_ulong_t)
112 /* Release exclusive sub-buffer access */
113 #define RING_BUFFER_COMPAT_PUT_SUBBUF RING_BUFFER_PUT_SUBBUF
115 /* Get exclusive read access to the next sub-buffer that can be read. */
116 #define RING_BUFFER_COMPAT_GET_NEXT_SUBBUF RING_BUFFER_GET_NEXT_SUBBUF
117 /* Release exclusive sub-buffer access, move consumer forward. */
118 #define RING_BUFFER_COMPAT_PUT_NEXT_SUBBUF RING_BUFFER_PUT_NEXT_SUBBUF
119 /* returns the size of the current sub-buffer, without padding (for mmap). */
120 #define RING_BUFFER_COMPAT_GET_SUBBUF_SIZE _IOR(0xF6, 0x07, compat_ulong_t)
121 /* returns the size of the current sub-buffer, with padding (for splice). */
122 #define RING_BUFFER_COMPAT_GET_PADDED_SUBBUF_SIZE \
123 _IOR(0xF6, 0x08, compat_ulong_t)
124 /* returns the maximum size for sub-buffers. */
125 #define RING_BUFFER_COMPAT_GET_MAX_SUBBUF_SIZE _IOR(0xF6, 0x09, compat_ulong_t)
126 /* returns the length to mmap. */
127 #define RING_BUFFER_COMPAT_GET_MMAP_LEN _IOR(0xF6, 0x0A, compat_ulong_t)
128 /* returns the offset of the subbuffer belonging to the mmap reader. */
129 #define RING_BUFFER_COMPAT_GET_MMAP_READ_OFFSET _IOR(0xF6, 0x0B, compat_ulong_t)
130 /* flush the current sub-buffer */
131 #define RING_BUFFER_COMPAT_FLUSH RING_BUFFER_FLUSH
132 #endif /* CONFIG_COMPAT */
134 #endif /* _LIB_RING_BUFFER_VFS_H */