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