Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Al Viro | 83a8761 | 2013-05-12 10:14:07 -0400 | [diff] [blame] | 2 | * loop.h |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Written by Theodore Ts'o, 3/29/93. |
| 5 | * |
| 6 | * Copyright 1993 by Theodore Ts'o. Redistribution of this file is |
| 7 | * permitted under the GNU General Public License. |
| 8 | */ |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 9 | #ifndef _LINUX_LOOP_H |
| 10 | #define _LINUX_LOOP_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/bio.h> |
| 13 | #include <linux/blkdev.h> |
Jens Axboe | 78e367a | 2015-01-02 15:20:25 -0700 | [diff] [blame] | 14 | #include <linux/blk-mq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/spinlock.h> |
Ingo Molnar | f85221d | 2006-03-23 03:00:38 -0800 | [diff] [blame] | 16 | #include <linux/mutex.h> |
Ming Lei | b5dd2f6 | 2014-12-31 13:22:57 +0000 | [diff] [blame] | 17 | #include <linux/workqueue.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 18 | #include <uapi/linux/loop.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | /* Possible states of device */ |
| 21 | enum { |
| 22 | Lo_unbound, |
| 23 | Lo_bound, |
| 24 | Lo_rundown, |
| 25 | }; |
| 26 | |
| 27 | struct loop_func_table; |
| 28 | |
| 29 | struct loop_device { |
| 30 | int lo_number; |
| 31 | int lo_refcnt; |
| 32 | loff_t lo_offset; |
| 33 | loff_t lo_sizelimit; |
| 34 | int lo_flags; |
| 35 | int (*transfer)(struct loop_device *, int cmd, |
| 36 | struct page *raw_page, unsigned raw_off, |
| 37 | struct page *loop_page, unsigned loop_off, |
| 38 | int size, sector_t real_block); |
| 39 | char lo_file_name[LO_NAME_SIZE]; |
| 40 | char lo_crypt_name[LO_NAME_SIZE]; |
| 41 | char lo_encrypt_key[LO_KEY_SIZE]; |
| 42 | int lo_encrypt_key_size; |
| 43 | struct loop_func_table *lo_encryption; |
| 44 | __u32 lo_init[2]; |
Eric W. Biederman | e484973 | 2012-02-11 11:23:51 -0800 | [diff] [blame] | 45 | kuid_t lo_key_owner; /* Who set the key */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | int (*ioctl)(struct loop_device *, int cmd, |
| 47 | unsigned long arg); |
| 48 | |
| 49 | struct file * lo_backing_file; |
| 50 | struct block_device *lo_device; |
| 51 | unsigned lo_blocksize; |
| 52 | void *key_data; |
| 53 | |
Al Viro | b4e3ca1 | 2005-10-21 03:22:34 -0400 | [diff] [blame] | 54 | gfp_t old_gfp_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | spinlock_t lo_lock; |
Ming Lei | b5dd2f6 | 2014-12-31 13:22:57 +0000 | [diff] [blame] | 57 | struct list_head write_cmd_head; |
| 58 | struct work_struct write_work; |
| 59 | bool write_started; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | int lo_state; |
Ingo Molnar | f85221d | 2006-03-23 03:00:38 -0800 | [diff] [blame] | 61 | struct mutex lo_ctl_mutex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Arnd Bergmann | 01e457c | 2007-07-23 18:44:00 -0700 | [diff] [blame] | 63 | struct request_queue *lo_queue; |
Ming Lei | b5dd2f6 | 2014-12-31 13:22:57 +0000 | [diff] [blame] | 64 | struct blk_mq_tag_set tag_set; |
Ken Chen | 7328508 | 2007-05-08 00:28:20 -0700 | [diff] [blame] | 65 | struct gendisk *lo_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
Ming Lei | b5dd2f6 | 2014-12-31 13:22:57 +0000 | [diff] [blame] | 68 | struct loop_cmd { |
| 69 | struct work_struct read_work; |
| 70 | struct request *rq; |
| 71 | struct list_head list; |
| 72 | }; |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | /* Support for loadable transfer modules */ |
| 75 | struct loop_func_table { |
| 76 | int number; /* filter type */ |
| 77 | int (*transfer)(struct loop_device *lo, int cmd, |
| 78 | struct page *raw_page, unsigned raw_off, |
| 79 | struct page *loop_page, unsigned loop_off, |
| 80 | int size, sector_t real_block); |
| 81 | int (*init)(struct loop_device *, const struct loop_info64 *); |
| 82 | /* release is called from loop_unregister_transfer or clr_fd */ |
| 83 | int (*release)(struct loop_device *); |
| 84 | int (*ioctl)(struct loop_device *, int cmd, unsigned long arg); |
| 85 | struct module *owner; |
| 86 | }; |
| 87 | |
| 88 | int loop_register_transfer(struct loop_func_table *funcs); |
| 89 | int loop_unregister_transfer(int number); |
| 90 | |
| 91 | #endif |