]> git.sesse.net Git - bcachefs-tools-debian/blob - include/linux/blkdev.h
Update bcachefs sources to 90a9c61e2b bcachefs: Switch bch2_btree_delete_range()...
[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
13 struct bio;
14 struct user_namespace;
15
16 #define MINORBITS       20
17 #define MINORMASK       ((1U << MINORBITS) - 1)
18
19 #define MAJOR(dev)      ((unsigned int) ((dev) >> MINORBITS))
20 #define MINOR(dev)      ((unsigned int) ((dev) & MINORMASK))
21 #define MKDEV(ma,mi)    (((ma) << MINORBITS) | (mi))
22
23 /* file is open for reading */
24 #define FMODE_READ              ((__force fmode_t)0x1)
25 /* file is open for writing */
26 #define FMODE_WRITE             ((__force fmode_t)0x2)
27 /* file is seekable */
28 #define FMODE_LSEEK             ((__force fmode_t)0x4)
29 /* file can be accessed using pread */
30 #define FMODE_PREAD             ((__force fmode_t)0x8)
31 /* file can be accessed using pwrite */
32 #define FMODE_PWRITE            ((__force fmode_t)0x10)
33 /* File is opened for execution with sys_execve / sys_uselib */
34 #define FMODE_EXEC              ((__force fmode_t)0x20)
35 /* File is opened with O_NDELAY (only set for block devices) */
36 #define FMODE_NDELAY            ((__force fmode_t)0x40)
37 /* File is opened with O_EXCL (only set for block devices) */
38 #define FMODE_EXCL              ((__force fmode_t)0x80)
39 /* File is opened using open(.., 3, ..) and is writeable only for ioctls
40    (specialy hack for floppy.c) */
41 #define FMODE_WRITE_IOCTL       ((__force fmode_t)0x100)
42 /* 32bit hashes as llseek() offset (for directories) */
43 #define FMODE_32BITHASH         ((__force fmode_t)0x200)
44 /* 64bit hashes as llseek() offset (for directories) */
45 #define FMODE_64BITHASH         ((__force fmode_t)0x400)
46
47 struct inode {
48         unsigned long           i_ino;
49         loff_t                  i_size;
50         struct super_block      *i_sb;
51 };
52
53 struct file {
54         struct inode            *f_inode;
55 };
56
57 static inline struct inode *file_inode(const struct file *f)
58 {
59         return f->f_inode;
60 }
61
62 #define part_to_dev(part)       (part)
63
64 void generic_make_request(struct bio *);
65 int submit_bio_wait(struct bio *);
66
67 static inline void submit_bio(struct bio *bio)
68 {
69         generic_make_request(bio);
70 }
71
72 int blkdev_issue_discard(struct block_device *, sector_t, sector_t, gfp_t);
73
74 #define bdev_get_queue(bdev)            (&((bdev)->queue))
75
76 #ifndef SECTOR_SHIFT
77 #define SECTOR_SHIFT 9
78 #endif
79 #ifndef SECTOR_SIZE
80 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
81 #endif
82
83 #define PAGE_SECTORS_SHIFT      (PAGE_SHIFT - SECTOR_SHIFT)
84 #define PAGE_SECTORS            (1 << PAGE_SECTORS_SHIFT)
85 #define SECTOR_MASK             (PAGE_SECTORS - 1)
86
87 #define bdev_max_discard_sectors(bdev)  ((void) (bdev), 0)
88 #define blk_queue_nonrot(q)             ((void) (q), 0)
89
90 unsigned bdev_logical_block_size(struct block_device *bdev);
91 sector_t get_capacity(struct gendisk *disk);
92
93 void blkdev_put(struct block_device *bdev, fmode_t mode);
94 void bdput(struct block_device *bdev);
95 struct block_device *blkdev_get_by_path(const char *path, fmode_t mode, void *holder);
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