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