Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_LOOP_H |
| 2 | #define _LINUX_LOOP_H |
| 3 | |
| 4 | /* |
| 5 | * include/linux/loop.h |
| 6 | * |
| 7 | * Written by Theodore Ts'o, 3/29/93. |
| 8 | * |
| 9 | * Copyright 1993 by Theodore Ts'o. Redistribution of this file is |
| 10 | * permitted under the GNU General Public License. |
| 11 | */ |
| 12 | |
| 13 | #define LO_NAME_SIZE 64 |
| 14 | #define LO_KEY_SIZE 32 |
| 15 | |
| 16 | #ifdef __KERNEL__ |
| 17 | #include <linux/bio.h> |
| 18 | #include <linux/blkdev.h> |
| 19 | #include <linux/spinlock.h> |
Ingo Molnar | f85221d | 2006-03-23 03:00:38 -0800 | [diff] [blame] | 20 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | /* Possible states of device */ |
| 23 | enum { |
| 24 | Lo_unbound, |
| 25 | Lo_bound, |
| 26 | Lo_rundown, |
| 27 | }; |
| 28 | |
| 29 | struct loop_func_table; |
| 30 | |
| 31 | struct loop_device { |
| 32 | int lo_number; |
| 33 | int lo_refcnt; |
| 34 | loff_t lo_offset; |
| 35 | loff_t lo_sizelimit; |
| 36 | int lo_flags; |
| 37 | int (*transfer)(struct loop_device *, int cmd, |
| 38 | struct page *raw_page, unsigned raw_off, |
| 39 | struct page *loop_page, unsigned loop_off, |
| 40 | int size, sector_t real_block); |
| 41 | char lo_file_name[LO_NAME_SIZE]; |
| 42 | char lo_crypt_name[LO_NAME_SIZE]; |
| 43 | char lo_encrypt_key[LO_KEY_SIZE]; |
| 44 | int lo_encrypt_key_size; |
| 45 | struct loop_func_table *lo_encryption; |
| 46 | __u32 lo_init[2]; |
| 47 | uid_t lo_key_owner; /* Who set the key */ |
| 48 | int (*ioctl)(struct loop_device *, int cmd, |
| 49 | unsigned long arg); |
| 50 | |
| 51 | struct file * lo_backing_file; |
| 52 | struct block_device *lo_device; |
| 53 | unsigned lo_blocksize; |
| 54 | void *key_data; |
| 55 | |
Al Viro | b4e3ca1 | 2005-10-21 03:22:34 -0400 | [diff] [blame] | 56 | gfp_t old_gfp_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | spinlock_t lo_lock; |
Akinobu Mita | e686307 | 2009-04-17 08:41:21 +0200 | [diff] [blame] | 59 | struct bio_list lo_bio_list; |
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; |
Serge E. Hallyn | 6c99791 | 2006-09-29 01:59:11 -0700 | [diff] [blame] | 62 | struct task_struct *lo_thread; |
| 63 | wait_queue_head_t lo_event; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Arnd Bergmann | 01e457c | 2007-07-23 18:44:00 -0700 | [diff] [blame] | 65 | struct request_queue *lo_queue; |
Ken Chen | 7328508 | 2007-05-08 00:28:20 -0700 | [diff] [blame] | 66 | struct gendisk *lo_disk; |
| 67 | struct list_head lo_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | #endif /* __KERNEL__ */ |
| 71 | |
| 72 | /* |
| 73 | * Loop flags |
| 74 | */ |
| 75 | enum { |
| 76 | LO_FLAGS_READ_ONLY = 1, |
| 77 | LO_FLAGS_USE_AOPS = 2, |
David Woodhouse | 96c5865 | 2008-02-06 01:36:27 -0800 | [diff] [blame] | 78 | LO_FLAGS_AUTOCLEAR = 4, |
Kay Sievers | e03c8dd | 2011-08-23 20:12:04 +0200 | [diff] [blame] | 79 | LO_FLAGS_PARTSCAN = 8, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | #include <asm/posix_types.h> /* for __kernel_old_dev_t */ |
Jaswinder Singh Rajput | 00bfdda | 2009-01-15 13:51:26 -0800 | [diff] [blame] | 83 | #include <linux/types.h> /* for __u64 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | /* Backwards compatibility version */ |
| 86 | struct loop_info { |
| 87 | int lo_number; /* ioctl r/o */ |
| 88 | __kernel_old_dev_t lo_device; /* ioctl r/o */ |
| 89 | unsigned long lo_inode; /* ioctl r/o */ |
| 90 | __kernel_old_dev_t lo_rdevice; /* ioctl r/o */ |
| 91 | int lo_offset; |
| 92 | int lo_encrypt_type; |
| 93 | int lo_encrypt_key_size; /* ioctl w/o */ |
| 94 | int lo_flags; /* ioctl r/o */ |
| 95 | char lo_name[LO_NAME_SIZE]; |
| 96 | unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */ |
| 97 | unsigned long lo_init[2]; |
| 98 | char reserved[4]; |
| 99 | }; |
| 100 | |
| 101 | struct loop_info64 { |
| 102 | __u64 lo_device; /* ioctl r/o */ |
| 103 | __u64 lo_inode; /* ioctl r/o */ |
| 104 | __u64 lo_rdevice; /* ioctl r/o */ |
| 105 | __u64 lo_offset; |
| 106 | __u64 lo_sizelimit;/* bytes, 0 == max available */ |
| 107 | __u32 lo_number; /* ioctl r/o */ |
| 108 | __u32 lo_encrypt_type; |
| 109 | __u32 lo_encrypt_key_size; /* ioctl w/o */ |
| 110 | __u32 lo_flags; /* ioctl r/o */ |
| 111 | __u8 lo_file_name[LO_NAME_SIZE]; |
| 112 | __u8 lo_crypt_name[LO_NAME_SIZE]; |
| 113 | __u8 lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */ |
| 114 | __u64 lo_init[2]; |
| 115 | }; |
| 116 | |
| 117 | /* |
| 118 | * Loop filter types |
| 119 | */ |
| 120 | |
| 121 | #define LO_CRYPT_NONE 0 |
| 122 | #define LO_CRYPT_XOR 1 |
| 123 | #define LO_CRYPT_DES 2 |
| 124 | #define LO_CRYPT_FISH2 3 /* Twofish encryption */ |
| 125 | #define LO_CRYPT_BLOW 4 |
| 126 | #define LO_CRYPT_CAST128 5 |
| 127 | #define LO_CRYPT_IDEA 6 |
| 128 | #define LO_CRYPT_DUMMY 9 |
| 129 | #define LO_CRYPT_SKIPJACK 10 |
| 130 | #define LO_CRYPT_CRYPTOAPI 18 |
| 131 | #define MAX_LO_CRYPT 20 |
| 132 | |
| 133 | #ifdef __KERNEL__ |
| 134 | /* Support for loadable transfer modules */ |
| 135 | struct loop_func_table { |
| 136 | int number; /* filter type */ |
| 137 | int (*transfer)(struct loop_device *lo, int cmd, |
| 138 | struct page *raw_page, unsigned raw_off, |
| 139 | struct page *loop_page, unsigned loop_off, |
| 140 | int size, sector_t real_block); |
| 141 | int (*init)(struct loop_device *, const struct loop_info64 *); |
| 142 | /* release is called from loop_unregister_transfer or clr_fd */ |
| 143 | int (*release)(struct loop_device *); |
| 144 | int (*ioctl)(struct loop_device *, int cmd, unsigned long arg); |
| 145 | struct module *owner; |
| 146 | }; |
| 147 | |
| 148 | int loop_register_transfer(struct loop_func_table *funcs); |
| 149 | int loop_unregister_transfer(int number); |
| 150 | |
| 151 | #endif |
| 152 | /* |
| 153 | * IOCTL commands --- we will commandeer 0x4C ('L') |
| 154 | */ |
| 155 | |
| 156 | #define LOOP_SET_FD 0x4C00 |
| 157 | #define LOOP_CLR_FD 0x4C01 |
| 158 | #define LOOP_SET_STATUS 0x4C02 |
| 159 | #define LOOP_GET_STATUS 0x4C03 |
| 160 | #define LOOP_SET_STATUS64 0x4C04 |
| 161 | #define LOOP_GET_STATUS64 0x4C05 |
| 162 | #define LOOP_CHANGE_FD 0x4C06 |
J. R. Okajima | 53d6660 | 2009-03-31 15:23:43 -0700 | [diff] [blame] | 163 | #define LOOP_SET_CAPACITY 0x4C07 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | #endif |