1 // SPDX-License-Identifier: GPL-2.0
2 #ifndef IOU_FILE_TABLE_H
3 #define IOU_FILE_TABLE_H
8 * FFS_SCM is only available on 64-bit archs, for 32-bit we just define it as 0
9 * and define IO_URING_SCM_ALL. For this case, we use SCM for all files as we
10 * can't safely always dereference the file when the task has exited and ring
11 * cleanup is done. If a file is tracked and part of SCM, then unix gc on
12 * process exit may reap it before __io_sqe_files_unregister() is run.
14 #define FFS_NOWAIT 0x1UL
15 #define FFS_ISREG 0x2UL
16 #if defined(CONFIG_64BIT)
19 #define IO_URING_SCM_ALL
22 #define FFS_MASK ~(FFS_NOWAIT|FFS_ISREG|FFS_SCM)
24 struct io_fixed_file {
25 /* file * with additional FFS_* flags */
26 unsigned long file_ptr;
29 struct io_file_table {
30 struct io_fixed_file *files;
31 unsigned long *bitmap;
32 unsigned int alloc_hint;
35 bool io_alloc_file_tables(struct io_file_table *table, unsigned nr_files);
36 void io_free_file_tables(struct io_file_table *table);
37 int io_file_bitmap_get(struct io_ring_ctx *ctx);
39 static inline void io_file_bitmap_clear(struct io_file_table *table, int bit)
41 __clear_bit(bit, table->bitmap);
42 table->alloc_hint = bit;
45 static inline void io_file_bitmap_set(struct io_file_table *table, int bit)
47 WARN_ON_ONCE(test_bit(bit, table->bitmap));
48 __set_bit(bit, table->bitmap);
49 table->alloc_hint = bit + 1;
52 static inline struct io_fixed_file *
53 io_fixed_file_slot(struct io_file_table *table, unsigned i)
55 return &table->files[i];