1 #ifndef __TOOLS_LINUX_BLKDEV_H
2 #define __TOOLS_LINUX_BLKDEV_H
4 #include <linux/backing-dev.h>
5 #include <linux/blk_types.h>
8 typedef unsigned fmode_t;
11 struct user_namespace;
14 #define MINORMASK ((1U << MINORBITS) - 1)
16 #define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
17 #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
18 #define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi))
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)
47 struct super_block *i_sb;
51 struct inode *f_inode;
54 static inline struct inode *file_inode(const struct file *f)
59 #define BDEVNAME_SIZE 32
61 struct request_queue {
62 struct backing_dev_info backing_dev_info;
69 char name[BDEVNAME_SIZE];
70 struct inode *bd_inode;
71 struct request_queue queue;
73 struct gendisk *bd_disk;
74 struct gendisk __bd_disk;
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);
83 #define bdev_get_queue(bdev) (&((bdev)->queue))
85 #define blk_queue_discard(q) ((void) (q), 0)
86 #define blk_queue_nonrot(q) ((void) (q), 0)
88 static inline struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev)
90 struct request_queue *q = bdev_get_queue(bdev);
92 return &q->backing_dev_info;
95 unsigned bdev_logical_block_size(struct block_device *bdev);
96 sector_t get_capacity(struct gendisk *disk);
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);
110 * NOTE! These match bits 12..15 of stat.st_mode
111 * (ie "(i_mode >> 12) & 15").
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.
132 typedef int (*filldir_t)(struct dir_context *, const char *, int, loff_t, u64,
136 const filldir_t actor;
141 extern struct kobject *fs_kobj;
143 struct file_operations {
146 static inline int register_chrdev(unsigned int major, const char *name,
147 const struct file_operations *fops)
152 static inline void unregister_chrdev(unsigned int major, const char *name)
156 static inline const char *bdevname(struct block_device *bdev, char *buf)
158 snprintf(buf, BDEVNAME_SIZE, "%s", bdev->name);
162 static inline bool op_is_write(unsigned int op)
164 return op == REQ_OP_READ ? false : true;
168 * return data direction, READ or WRITE
170 static inline int bio_data_dir(struct bio *bio)
172 return op_is_write(bio_op(bio)) ? WRITE : READ;
175 static inline bool dir_emit(struct dir_context *ctx,
176 const char *name, int namelen,
177 u64 ino, unsigned type)
179 return ctx->actor(ctx, name, namelen, ctx->pos, ino, type) == 0;
182 static inline bool dir_emit_dots(struct file *file, struct dir_context *ctx)
187 #define capable(cap) true
189 #endif /* __TOOLS_LINUX_BLKDEV_H */