0001
0002 #ifndef IOU_FILE_TABLE_H
0003 #define IOU_FILE_TABLE_H
0004
0005 #include <linux/file.h>
0006 #include <linux/io_uring_types.h>
0007
0008
0009
0010
0011
0012
0013
0014
0015 #define FFS_NOWAIT 0x1UL
0016 #define FFS_ISREG 0x2UL
0017 #if defined(CONFIG_64BIT)
0018 #define FFS_SCM 0x4UL
0019 #else
0020 #define IO_URING_SCM_ALL
0021 #define FFS_SCM 0x0UL
0022 #endif
0023 #define FFS_MASK ~(FFS_NOWAIT|FFS_ISREG|FFS_SCM)
0024
0025 bool io_alloc_file_tables(struct io_file_table *table, unsigned nr_files);
0026 void io_free_file_tables(struct io_file_table *table);
0027
0028 int io_fixed_fd_install(struct io_kiocb *req, unsigned int issue_flags,
0029 struct file *file, unsigned int file_slot);
0030 int __io_fixed_fd_install(struct io_ring_ctx *ctx, struct file *file,
0031 unsigned int file_slot);
0032 int io_fixed_fd_remove(struct io_ring_ctx *ctx, unsigned int offset);
0033
0034 int io_register_file_alloc_range(struct io_ring_ctx *ctx,
0035 struct io_uring_file_index_range __user *arg);
0036
0037 unsigned int io_file_get_flags(struct file *file);
0038
0039 static inline void io_file_bitmap_clear(struct io_file_table *table, int bit)
0040 {
0041 __clear_bit(bit, table->bitmap);
0042 table->alloc_hint = bit;
0043 }
0044
0045 static inline void io_file_bitmap_set(struct io_file_table *table, int bit)
0046 {
0047 WARN_ON_ONCE(test_bit(bit, table->bitmap));
0048 __set_bit(bit, table->bitmap);
0049 table->alloc_hint = bit + 1;
0050 }
0051
0052 static inline struct io_fixed_file *
0053 io_fixed_file_slot(struct io_file_table *table, unsigned i)
0054 {
0055 return &table->files[i];
0056 }
0057
0058 static inline struct file *io_file_from_index(struct io_file_table *table,
0059 int index)
0060 {
0061 struct io_fixed_file *slot = io_fixed_file_slot(table, index);
0062
0063 return (struct file *) (slot->file_ptr & FFS_MASK);
0064 }
0065
0066 static inline void io_fixed_file_set(struct io_fixed_file *file_slot,
0067 struct file *file)
0068 {
0069 unsigned long file_ptr = (unsigned long) file;
0070
0071 file_ptr |= io_file_get_flags(file);
0072 file_slot->file_ptr = file_ptr;
0073 }
0074
0075 static inline void io_reset_alloc_hint(struct io_ring_ctx *ctx)
0076 {
0077 ctx->file_table.alloc_hint = ctx->file_alloc_start;
0078 }
0079
0080 static inline void io_file_table_set_alloc_range(struct io_ring_ctx *ctx,
0081 unsigned off, unsigned len)
0082 {
0083 ctx->file_alloc_start = off;
0084 ctx->file_alloc_end = off + len;
0085 io_reset_alloc_hint(ctx);
0086 }
0087
0088 #endif