1#ifndef _LINUX_LOOP_H 2#define _LINUX_LOOP_H 3 4#include <linux/kdev_t.h> 5 6/* 7 * include/linux/loop.h 8 * 9 * Written by Theodore Ts'o, 3/29/93. 10 * 11 * Copyright 1993 by Theodore Ts'o. Redistribution of this file is 12 * permitted under the GNU General Public License. 13 */ 14 15#define LO_NAME_SIZE 64 16#define LO_KEY_SIZE 32 17 18#ifdef __KERNEL__ 19 20/* Possible states of device */ 21enum { 22 Lo_unbound, 23 Lo_bound, 24 Lo_rundown, 25}; 26 27struct loop_device { 28 int lo_number; 29 int lo_refcnt; 30 kdev_t lo_device; 31 int lo_offset; 32 int lo_encrypt_type; 33 int lo_encrypt_key_size; 34 int lo_flags; 35 int (*transfer)(struct loop_device *, int cmd, 36 char *raw_buf, char *loop_buf, int size, 37 int real_block); 38 char lo_name[LO_NAME_SIZE]; 39 char lo_encrypt_key[LO_KEY_SIZE]; 40 __u32 lo_init[2]; 41 uid_t lo_key_owner; /* Who set the key */ 42 int (*ioctl)(struct loop_device *, int cmd, 43 unsigned long arg); 44 45 struct file * lo_backing_file; 46 void *key_data; 47 char key_reserved[48]; /* for use by the filter modules */ 48 49 int old_gfp_mask; 50 51 spinlock_t lo_lock; 52 struct buffer_head *lo_bh; 53 struct buffer_head *lo_bhtail; 54 int lo_state; 55 struct semaphore lo_sem; 56 struct semaphore lo_ctl_mutex; 57 struct semaphore lo_bh_mutex; 58 atomic_t lo_pending; 59}; 60 61typedef int (* transfer_proc_t)(struct loop_device *, int cmd, 62 char *raw_buf, char *loop_buf, int size, 63 int real_block); 64 65static inline int lo_do_transfer(struct loop_device *lo, int cmd, char *rbuf, 66 char *lbuf, int size, int rblock) 67{ 68 if (!lo->transfer) 69 return 0; 70 71 return lo->transfer(lo, cmd, rbuf, lbuf, size, rblock); 72} 73#endif /* __KERNEL__ */ 74 75/* 76 * Loop flags 77 */ 78#define LO_FLAGS_DO_BMAP 1 79#define LO_FLAGS_READ_ONLY 2 80#define LO_FLAGS_BH_REMAP 4 81 82/* 83 * Note that this structure gets the wrong offsets when directly used 84 * from a glibc program, because glibc has a 32bit dev_t. 85 * Prevent people from shooting in their own foot. 86 */ 87#if __GLIBC__ >= 2 && !defined(dev_t) 88#error "Wrong dev_t in loop.h" 89#endif 90 91/* 92 * This uses kdev_t because glibc currently has no appropiate 93 * conversion version for the loop ioctls. 94 * The situation is very unpleasant 95 */ 96 97struct loop_info { 98 int lo_number; /* ioctl r/o */ 99 dev_t lo_device; /* ioctl r/o */ 100 unsigned long lo_inode; /* ioctl r/o */ 101 dev_t lo_rdevice; /* ioctl r/o */ 102 int lo_offset; 103 int lo_encrypt_type; 104 int lo_encrypt_key_size; /* ioctl w/o */ 105 int lo_flags; /* ioctl r/o */ 106 char lo_name[LO_NAME_SIZE]; 107 unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */ 108 unsigned long lo_init[2]; 109 char reserved[4]; 110}; 111 112/* 113 * Loop filter types 114 */ 115 116#define LO_CRYPT_NONE 0 117#define LO_CRYPT_XOR 1 118#define LO_CRYPT_DES 2 119#define LO_CRYPT_FISH2 3 /* Brand new Twofish encryption */ 120#define LO_CRYPT_BLOW 4 121#define LO_CRYPT_CAST128 5 122#define LO_CRYPT_IDEA 6 123#define LO_CRYPT_DUMMY 9 124#define LO_CRYPT_SKIPJACK 10 125#define MAX_LO_CRYPT 20 126 127#ifdef __KERNEL__ 128/* Support for loadable transfer modules */ 129struct loop_func_table { 130 int number; /* filter type */ 131 int (*transfer)(struct loop_device *lo, int cmd, char *raw_buf, 132 char *loop_buf, int size, int real_block); 133 int (*init)(struct loop_device *, struct loop_info *); 134 /* release is called from loop_unregister_transfer or clr_fd */ 135 int (*release)(struct loop_device *); 136 int (*ioctl)(struct loop_device *, int cmd, unsigned long arg); 137 /* lock and unlock manage the module use counts */ 138 void (*lock)(struct loop_device *); 139 void (*unlock)(struct loop_device *); 140}; 141 142int loop_register_transfer(struct loop_func_table *funcs); 143int loop_unregister_transfer(int number); 144 145#endif 146/* 147 * IOCTL commands --- we will commandeer 0x4C ('L') 148 */ 149 150#define LOOP_SET_FD 0x4C00 151#define LOOP_CLR_FD 0x4C01 152#define LOOP_SET_STATUS 0x4C02 153#define LOOP_GET_STATUS 0x4C03 154 155#endif 156