]> git.sesse.net Git - bcachefs-tools-debian/blob - include/linux/blkdev.h
7d378ab2cdf0a16587de7de7e74acf03e2e0cfff
[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 #define FMODE_BUFFERED          ((__force fmode_t)0x800)
48
49 struct inode {
50         unsigned long           i_ino;
51         loff_t                  i_size;
52         struct super_block      *i_sb;
53 };
54
55 struct file {
56         struct inode            *f_inode;
57 };
58
59 static inline struct inode *file_inode(const struct file *f)
60 {
61         return f->f_inode;
62 }
63
64 #define part_to_dev(part)       (part)
65
66 void generic_make_request(struct bio *);
67 int submit_bio_wait(struct bio *);
68
69 static inline void submit_bio(struct bio *bio)
70 {
71         generic_make_request(bio);
72 }
73
74 int blkdev_issue_discard(struct block_device *, sector_t, sector_t, gfp_t);
75 int blkdev_issue_zeroout(struct block_device *, sector_t, sector_t, gfp_t, unsigned);
76
77 #define bdev_get_queue(bdev)            (&((bdev)->queue))
78
79 #ifndef SECTOR_SHIFT
80 #define SECTOR_SHIFT 9
81 #endif
82 #ifndef SECTOR_SIZE
83 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
84 #endif
85
86 #define PAGE_SECTORS_SHIFT      (PAGE_SHIFT - SECTOR_SHIFT)
87 #define PAGE_SECTORS            (1 << PAGE_SECTORS_SHIFT)
88 #define SECTOR_MASK             (PAGE_SECTORS - 1)
89
90 #define bdev_max_discard_sectors(bdev)  ((void) (bdev), 0)
91 #define blk_queue_nonrot(q)             ((void) (q), 0)
92
93 unsigned bdev_logical_block_size(struct block_device *bdev);
94 sector_t get_capacity(struct gendisk *disk);
95
96 void blkdev_put(struct block_device *bdev, fmode_t mode);
97 void bdput(struct block_device *bdev);
98 struct block_device *blkdev_get_by_path(const char *path, fmode_t mode, void *holder);
99 int lookup_bdev(const char *path, dev_t *);
100
101 struct super_block {
102         void                    *s_fs_info;
103 };
104
105 /*
106  * File types
107  *
108  * NOTE! These match bits 12..15 of stat.st_mode
109  * (ie "(i_mode >> 12) & 15").
110  */
111 #ifndef DT_UNKNOWN
112 #define DT_UNKNOWN      0
113 #define DT_FIFO         1
114 #define DT_CHR          2
115 #define DT_DIR          4
116 #define DT_BLK          6
117 #define DT_REG          8
118 #define DT_LNK          10
119 #define DT_SOCK         12
120 #define DT_WHT          14
121 #define DT_MAX          16
122 #endif
123
124 /*
125  * This is the "filldir" function type, used by readdir() to let
126  * the kernel specify what kind of dirent layout it wants to have.
127  * This allows the kernel to read directories into kernel space or
128  * to have different dirent layouts depending on the binary type.
129  */
130 struct dir_context;
131 typedef int (*filldir_t)(struct dir_context *, const char *, int, loff_t, u64,
132                          unsigned);
133
134 struct dir_context {
135         const filldir_t actor;
136         u64 pos;
137 };
138
139 /* /sys/fs */
140 extern struct kobject *fs_kobj;
141
142 struct file_operations {
143 };
144
145 static inline int register_chrdev(unsigned int major, const char *name,
146                                   const struct file_operations *fops)
147 {
148         return 1;
149 }
150
151 static inline void unregister_chrdev(unsigned int major, const char *name)
152 {
153 }
154
155 static inline const char *bdevname(struct block_device *bdev, char *buf)
156 {
157         snprintf(buf, BDEVNAME_SIZE, "%s", bdev->name);
158         return buf;
159 }
160
161 static inline bool op_is_write(unsigned int op)
162 {
163         return op == REQ_OP_READ ? false : true;
164 }
165
166 /*
167  * return data direction, READ or WRITE
168  */
169 static inline int bio_data_dir(struct bio *bio)
170 {
171         return op_is_write(bio_op(bio)) ? WRITE : READ;
172 }
173
174 static inline bool dir_emit(struct dir_context *ctx,
175                             const char *name, int namelen,
176                             u64 ino, unsigned type)
177 {
178         return ctx->actor(ctx, name, namelen, ctx->pos, ino, type) == 0;
179 }
180
181 static inline bool dir_emit_dots(struct file *file, struct dir_context *ctx)
182 {
183         return true;
184 }
185
186 #define capable(cap)            true
187
188 int blk_status_to_errno(blk_status_t status);
189 blk_status_t errno_to_blk_status(int errno);
190 const char *blk_status_to_str(blk_status_t status);
191
192 #endif /* __TOOLS_LINUX_BLKDEV_H */
193