]> git.sesse.net Git - bcachefs-tools-debian/blob - include/linux/blkdev.h
Update bcachefs sources to 25de2b00dc bcachefs: Change check for invalid key types
[bcachefs-tools-debian] / include / linux / blkdev.h
1 #ifndef __TOOLS_LINUX_BLKDEV_H
2 #define __TOOLS_LINUX_BLKDEV_H
3
4 #include <linux/backing-dev.h>
5 #include <linux/blk_types.h>
6 #include <linux/kobject.h>
7 #include <linux/types.h>
8
9 #define BIO_MAX_VECS    256U
10
11 typedef unsigned fmode_t;
12 typedef __u32 __bitwise blk_opf_t;
13
14 struct bio;
15 struct user_namespace;
16
17 #define MINORBITS       20
18 #define MINORMASK       ((1U << MINORBITS) - 1)
19
20 #define MAJOR(dev)      ((unsigned int) ((dev) >> MINORBITS))
21 #define MINOR(dev)      ((unsigned int) ((dev) & MINORMASK))
22 #define MKDEV(ma,mi)    (((ma) << MINORBITS) | (mi))
23
24 /* file is open for reading */
25 #define FMODE_READ              ((__force fmode_t)0x1)
26 /* file is open for writing */
27 #define FMODE_WRITE             ((__force fmode_t)0x2)
28 /* file is seekable */
29 #define FMODE_LSEEK             ((__force fmode_t)0x4)
30 /* file can be accessed using pread */
31 #define FMODE_PREAD             ((__force fmode_t)0x8)
32 /* file can be accessed using pwrite */
33 #define FMODE_PWRITE            ((__force fmode_t)0x10)
34 /* File is opened for execution with sys_execve / sys_uselib */
35 #define FMODE_EXEC              ((__force fmode_t)0x20)
36 /* File is opened with O_NDELAY (only set for block devices) */
37 #define FMODE_NDELAY            ((__force fmode_t)0x40)
38 /* File is opened with O_EXCL (only set for block devices) */
39 #define FMODE_EXCL              ((__force fmode_t)0x80)
40 /* File is opened using open(.., 3, ..) and is writeable only for ioctls
41    (specialy hack for floppy.c) */
42 #define FMODE_WRITE_IOCTL       ((__force fmode_t)0x100)
43 /* 32bit hashes as llseek() offset (for directories) */
44 #define FMODE_32BITHASH         ((__force fmode_t)0x200)
45 /* 64bit hashes as llseek() offset (for directories) */
46 #define FMODE_64BITHASH         ((__force fmode_t)0x400)
47
48 struct inode {
49         unsigned long           i_ino;
50         loff_t                  i_size;
51         struct super_block      *i_sb;
52 };
53
54 struct file {
55         struct inode            *f_inode;
56 };
57
58 static inline struct inode *file_inode(const struct file *f)
59 {
60         return f->f_inode;
61 }
62
63 #define part_to_dev(part)       (part)
64
65 void generic_make_request(struct bio *);
66 int submit_bio_wait(struct bio *);
67
68 static inline void submit_bio(struct bio *bio)
69 {
70         generic_make_request(bio);
71 }
72
73 int blkdev_issue_discard(struct block_device *, sector_t, sector_t, gfp_t);
74 int blkdev_issue_zeroout(struct block_device *, sector_t, sector_t, gfp_t, unsigned);
75
76 #define bdev_get_queue(bdev)            (&((bdev)->queue))
77
78 #ifndef SECTOR_SHIFT
79 #define SECTOR_SHIFT 9
80 #endif
81 #ifndef SECTOR_SIZE
82 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
83 #endif
84
85 #define PAGE_SECTORS_SHIFT      (PAGE_SHIFT - SECTOR_SHIFT)
86 #define PAGE_SECTORS            (1 << PAGE_SECTORS_SHIFT)
87 #define SECTOR_MASK             (PAGE_SECTORS - 1)
88
89 #define bdev_max_discard_sectors(bdev)  ((void) (bdev), 0)
90 #define blk_queue_nonrot(q)             ((void) (q), 0)
91
92 unsigned bdev_logical_block_size(struct block_device *bdev);
93 sector_t get_capacity(struct gendisk *disk);
94
95 void blkdev_put(struct block_device *bdev, fmode_t mode);
96 void bdput(struct block_device *bdev);
97 struct block_device *blkdev_get_by_path(const char *path, fmode_t mode, void *holder);
98 int lookup_bdev(const char *path, dev_t *);
99
100 struct super_block {
101         void                    *s_fs_info;
102 };
103
104 /*
105  * File types
106  *
107  * NOTE! These match bits 12..15 of stat.st_mode
108  * (ie "(i_mode >> 12) & 15").
109  */
110 #ifndef DT_UNKNOWN
111 #define DT_UNKNOWN      0
112 #define DT_FIFO         1
113 #define DT_CHR          2
114 #define DT_DIR          4
115 #define DT_BLK          6
116 #define DT_REG          8
117 #define DT_LNK          10
118 #define DT_SOCK         12
119 #define DT_WHT          14
120 #define DT_MAX          16
121 #endif
122
123 /*
124  * This is the "filldir" function type, used by readdir() to let
125  * the kernel specify what kind of dirent layout it wants to have.
126  * This allows the kernel to read directories into kernel space or
127  * to have different dirent layouts depending on the binary type.
128  */
129 struct dir_context;
130 typedef int (*filldir_t)(struct dir_context *, const char *, int, loff_t, u64,
131                          unsigned);
132
133 struct dir_context {
134         const filldir_t actor;
135         u64 pos;
136 };
137
138 /* /sys/fs */
139 extern struct kobject *fs_kobj;
140
141 struct file_operations {
142 };
143
144 static inline int register_chrdev(unsigned int major, const char *name,
145                                   const struct file_operations *fops)
146 {
147         return 1;
148 }
149
150 static inline void unregister_chrdev(unsigned int major, const char *name)
151 {
152 }
153
154 static inline const char *bdevname(struct block_device *bdev, char *buf)
155 {
156         snprintf(buf, BDEVNAME_SIZE, "%s", bdev->name);
157         return buf;
158 }
159
160 static inline bool op_is_write(unsigned int op)
161 {
162         return op == REQ_OP_READ ? false : true;
163 }
164
165 /*
166  * return data direction, READ or WRITE
167  */
168 static inline int bio_data_dir(struct bio *bio)
169 {
170         return op_is_write(bio_op(bio)) ? WRITE : READ;
171 }
172
173 static inline bool dir_emit(struct dir_context *ctx,
174                             const char *name, int namelen,
175                             u64 ino, unsigned type)
176 {
177         return ctx->actor(ctx, name, namelen, ctx->pos, ino, type) == 0;
178 }
179
180 static inline bool dir_emit_dots(struct file *file, struct dir_context *ctx)
181 {
182         return true;
183 }
184
185 #define capable(cap)            true
186
187 int blk_status_to_errno(blk_status_t status);
188 blk_status_t errno_to_blk_status(int errno);
189 const char *blk_status_to_str(blk_status_t status);
190
191 #endif /* __TOOLS_LINUX_BLKDEV_H */
192