1 #ifndef __TOOLS_LINUX_BLKDEV_H
2 #define __TOOLS_LINUX_BLKDEV_H
4 #include <linux/backing-dev.h>
5 #include <linux/blk_types.h>
6 #include <linux/kobject.h>
7 #include <linux/types.h>
9 #define BIO_MAX_PAGES 256
11 typedef unsigned fmode_t;
14 struct user_namespace;
17 #define MINORMASK ((1U << MINORBITS) - 1)
19 #define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
20 #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
21 #define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi))
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)
50 struct super_block *i_sb;
54 struct inode *f_inode;
57 static inline struct inode *file_inode(const struct file *f)
62 #define BDEVNAME_SIZE 32
64 struct request_queue {
65 struct backing_dev_info *backing_dev_info;
75 #define part_to_dev(part) (part)
78 char name[BDEVNAME_SIZE];
79 struct inode *bd_inode;
80 struct request_queue queue;
82 struct hd_struct *bd_part;
83 struct gendisk *bd_disk;
84 struct gendisk __bd_disk;
88 struct backing_dev_info *bd_bdi;
89 struct backing_dev_info __bd_bdi;
92 void generic_make_request(struct bio *);
93 int submit_bio_wait(struct bio *);
95 static inline void submit_bio(struct bio *bio)
97 generic_make_request(bio);
100 int blkdev_issue_discard(struct block_device *, sector_t,
101 sector_t, gfp_t, unsigned long);
103 #define bdev_get_queue(bdev) (&((bdev)->queue))
105 #define blk_queue_discard(q) ((void) (q), 0)
106 #define blk_queue_nonrot(q) ((void) (q), 0)
108 unsigned bdev_logical_block_size(struct block_device *bdev);
109 sector_t get_capacity(struct gendisk *disk);
111 void blkdev_put(struct block_device *bdev, fmode_t mode);
112 void bdput(struct block_device *bdev);
113 struct block_device *blkdev_get_by_path(const char *path, fmode_t mode, void *holder);
114 struct block_device *lookup_bdev(const char *path);
123 * NOTE! These match bits 12..15 of stat.st_mode
124 * (ie "(i_mode >> 12) & 15").
139 * This is the "filldir" function type, used by readdir() to let
140 * the kernel specify what kind of dirent layout it wants to have.
141 * This allows the kernel to read directories into kernel space or
142 * to have different dirent layouts depending on the binary type.
145 typedef int (*filldir_t)(struct dir_context *, const char *, int, loff_t, u64,
149 const filldir_t actor;
154 extern struct kobject *fs_kobj;
156 struct file_operations {
159 static inline int register_chrdev(unsigned int major, const char *name,
160 const struct file_operations *fops)
165 static inline void unregister_chrdev(unsigned int major, const char *name)
169 static inline const char *bdevname(struct block_device *bdev, char *buf)
171 snprintf(buf, BDEVNAME_SIZE, "%s", bdev->name);
175 static inline bool op_is_write(unsigned int op)
177 return op == REQ_OP_READ ? false : true;
181 * return data direction, READ or WRITE
183 static inline int bio_data_dir(struct bio *bio)
185 return op_is_write(bio_op(bio)) ? WRITE : READ;
188 static inline bool dir_emit(struct dir_context *ctx,
189 const char *name, int namelen,
190 u64 ino, unsigned type)
192 return ctx->actor(ctx, name, namelen, ctx->pos, ino, type) == 0;
195 static inline bool dir_emit_dots(struct file *file, struct dir_context *ctx)
200 #define capable(cap) true
202 int blk_status_to_errno(blk_status_t status);
203 blk_status_t errno_to_blk_status(int errno);
204 const char *blk_status_to_str(blk_status_t status);
206 #endif /* __TOOLS_LINUX_BLKDEV_H */