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_VECS 256U
11 typedef unsigned fmode_t;
12 typedef __u32 __bitwise blk_opf_t;
15 struct user_namespace;
18 #define MINORMASK ((1U << MINORBITS) - 1)
20 #define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
21 #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
22 #define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi))
24 /* file is open for reading */
25 #define FMODE_READ ((__force fmode_t)0x1)
26 /* file is open for writing */
27 #define FMODE_WRITE ((__force fmode_t)0x2)
28 /* file is seekable */
29 #define FMODE_LSEEK ((__force fmode_t)0x4)
30 /* file can be accessed using pread */
31 #define FMODE_PREAD ((__force fmode_t)0x8)
32 /* file can be accessed using pwrite */
33 #define FMODE_PWRITE ((__force fmode_t)0x10)
34 /* File is opened for execution with sys_execve / sys_uselib */
35 #define FMODE_EXEC ((__force fmode_t)0x20)
36 /* File is opened with O_NDELAY (only set for block devices) */
37 #define FMODE_NDELAY ((__force fmode_t)0x40)
38 /* File is opened with O_EXCL (only set for block devices) */
39 #define FMODE_EXCL ((__force fmode_t)0x80)
40 /* File is opened using open(.., 3, ..) and is writeable only for ioctls
41 (specialy hack for floppy.c) */
42 #define FMODE_WRITE_IOCTL ((__force fmode_t)0x100)
43 /* 32bit hashes as llseek() offset (for directories) */
44 #define FMODE_32BITHASH ((__force fmode_t)0x200)
45 /* 64bit hashes as llseek() offset (for directories) */
46 #define FMODE_64BITHASH ((__force fmode_t)0x400)
51 struct super_block *i_sb;
55 struct inode *f_inode;
58 static inline struct inode *file_inode(const struct file *f)
63 #define part_to_dev(part) (part)
65 void generic_make_request(struct bio *);
66 int submit_bio_wait(struct bio *);
68 static inline void submit_bio(struct bio *bio)
70 generic_make_request(bio);
73 int blkdev_issue_discard(struct block_device *, sector_t, sector_t, gfp_t);
74 int blkdev_issue_zeroout(struct block_device *, sector_t, sector_t, gfp_t, unsigned);
76 #define bdev_get_queue(bdev) (&((bdev)->queue))
79 #define SECTOR_SHIFT 9
82 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
85 #define PAGE_SECTORS_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
86 #define PAGE_SECTORS (1 << PAGE_SECTORS_SHIFT)
87 #define SECTOR_MASK (PAGE_SECTORS - 1)
89 #define bdev_max_discard_sectors(bdev) ((void) (bdev), 0)
90 #define blk_queue_nonrot(q) ((void) (q), 0)
92 unsigned bdev_logical_block_size(struct block_device *bdev);
93 sector_t get_capacity(struct gendisk *disk);
95 void blkdev_put(struct block_device *bdev, fmode_t mode);
96 void bdput(struct block_device *bdev);
97 struct block_device *blkdev_get_by_path(const char *path, fmode_t mode, void *holder);
98 int lookup_bdev(const char *path, dev_t *);
107 * NOTE! These match bits 12..15 of stat.st_mode
108 * (ie "(i_mode >> 12) & 15").
124 * This is the "filldir" function type, used by readdir() to let
125 * the kernel specify what kind of dirent layout it wants to have.
126 * This allows the kernel to read directories into kernel space or
127 * to have different dirent layouts depending on the binary type.
130 typedef int (*filldir_t)(struct dir_context *, const char *, int, loff_t, u64,
134 const filldir_t actor;
139 extern struct kobject *fs_kobj;
141 struct file_operations {
144 static inline int register_chrdev(unsigned int major, const char *name,
145 const struct file_operations *fops)
150 static inline void unregister_chrdev(unsigned int major, const char *name)
154 static inline const char *bdevname(struct block_device *bdev, char *buf)
156 snprintf(buf, BDEVNAME_SIZE, "%s", bdev->name);
160 static inline bool op_is_write(unsigned int op)
162 return op == REQ_OP_READ ? false : true;
166 * return data direction, READ or WRITE
168 static inline int bio_data_dir(struct bio *bio)
170 return op_is_write(bio_op(bio)) ? WRITE : READ;
173 static inline bool dir_emit(struct dir_context *ctx,
174 const char *name, int namelen,
175 u64 ino, unsigned type)
177 return ctx->actor(ctx, name, namelen, ctx->pos, ino, type) == 0;
180 static inline bool dir_emit_dots(struct file *file, struct dir_context *ctx)
185 #define capable(cap) true
187 int blk_status_to_errno(blk_status_t status);
188 blk_status_t errno_to_blk_status(int errno);
189 const char *blk_status_to_str(blk_status_t status);
191 #endif /* __TOOLS_LINUX_BLKDEV_H */