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