loop.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #ifndef _LINUX_LOOP_H
  2. #define _LINUX_LOOP_H
  3. /*
  4. * include/linux/loop.h
  5. *
  6. * Written by Theodore Ts'o, 3/29/93.
  7. *
  8. * Copyright 1993 by Theodore Ts'o. Redistribution of this file is
  9. * permitted under the GNU General Public License.
  10. */
  11. #define LO_NAME_SIZE 64
  12. #define LO_KEY_SIZE 32
  13. #ifdef __KERNEL__
  14. #include <linux/bio.h>
  15. #include <linux/blkdev.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/mutex.h>
  18. /* Possible states of device */
  19. enum {
  20. Lo_unbound,
  21. Lo_bound,
  22. Lo_rundown,
  23. };
  24. struct loop_func_table;
  25. struct loop_device {
  26. int lo_number;
  27. int lo_refcnt;
  28. loff_t lo_offset;
  29. loff_t lo_sizelimit;
  30. int lo_flags;
  31. int (*transfer)(struct loop_device *, int cmd,
  32. struct page *raw_page, unsigned raw_off,
  33. struct page *loop_page, unsigned loop_off,
  34. int size, sector_t real_block);
  35. char lo_file_name[LO_NAME_SIZE];
  36. char lo_crypt_name[LO_NAME_SIZE];
  37. char lo_encrypt_key[LO_KEY_SIZE];
  38. int lo_encrypt_key_size;
  39. struct loop_func_table *lo_encryption;
  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. struct file * lo_backing_file;
  45. struct block_device *lo_device;
  46. unsigned lo_blocksize;
  47. void *key_data;
  48. gfp_t old_gfp_mask;
  49. spinlock_t lo_lock;
  50. struct bio *lo_bio;
  51. struct bio *lo_biotail;
  52. int lo_state;
  53. struct mutex lo_ctl_mutex;
  54. struct task_struct *lo_thread;
  55. wait_queue_head_t lo_event;
  56. request_queue_t *lo_queue;
  57. };
  58. #endif /* __KERNEL__ */
  59. /*
  60. * Loop flags
  61. */
  62. enum {
  63. LO_FLAGS_READ_ONLY = 1,
  64. LO_FLAGS_USE_AOPS = 2,
  65. };
  66. #include <asm/posix_types.h> /* for __kernel_old_dev_t */
  67. #include <asm/types.h> /* for __u64 */
  68. /* Backwards compatibility version */
  69. struct loop_info {
  70. int lo_number; /* ioctl r/o */
  71. __kernel_old_dev_t lo_device; /* ioctl r/o */
  72. unsigned long lo_inode; /* ioctl r/o */
  73. __kernel_old_dev_t lo_rdevice; /* ioctl r/o */
  74. int lo_offset;
  75. int lo_encrypt_type;
  76. int lo_encrypt_key_size; /* ioctl w/o */
  77. int lo_flags; /* ioctl r/o */
  78. char lo_name[LO_NAME_SIZE];
  79. unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */
  80. unsigned long lo_init[2];
  81. char reserved[4];
  82. };
  83. struct loop_info64 {
  84. __u64 lo_device; /* ioctl r/o */
  85. __u64 lo_inode; /* ioctl r/o */
  86. __u64 lo_rdevice; /* ioctl r/o */
  87. __u64 lo_offset;
  88. __u64 lo_sizelimit;/* bytes, 0 == max available */
  89. __u32 lo_number; /* ioctl r/o */
  90. __u32 lo_encrypt_type;
  91. __u32 lo_encrypt_key_size; /* ioctl w/o */
  92. __u32 lo_flags; /* ioctl r/o */
  93. __u8 lo_file_name[LO_NAME_SIZE];
  94. __u8 lo_crypt_name[LO_NAME_SIZE];
  95. __u8 lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */
  96. __u64 lo_init[2];
  97. };
  98. /*
  99. * Loop filter types
  100. */
  101. #define LO_CRYPT_NONE 0
  102. #define LO_CRYPT_XOR 1
  103. #define LO_CRYPT_DES 2
  104. #define LO_CRYPT_FISH2 3 /* Twofish encryption */
  105. #define LO_CRYPT_BLOW 4
  106. #define LO_CRYPT_CAST128 5
  107. #define LO_CRYPT_IDEA 6
  108. #define LO_CRYPT_DUMMY 9
  109. #define LO_CRYPT_SKIPJACK 10
  110. #define LO_CRYPT_CRYPTOAPI 18
  111. #define MAX_LO_CRYPT 20
  112. #ifdef __KERNEL__
  113. /* Support for loadable transfer modules */
  114. struct loop_func_table {
  115. int number; /* filter type */
  116. int (*transfer)(struct loop_device *lo, int cmd,
  117. struct page *raw_page, unsigned raw_off,
  118. struct page *loop_page, unsigned loop_off,
  119. int size, sector_t real_block);
  120. int (*init)(struct loop_device *, const struct loop_info64 *);
  121. /* release is called from loop_unregister_transfer or clr_fd */
  122. int (*release)(struct loop_device *);
  123. int (*ioctl)(struct loop_device *, int cmd, unsigned long arg);
  124. struct module *owner;
  125. };
  126. int loop_register_transfer(struct loop_func_table *funcs);
  127. int loop_unregister_transfer(int number);
  128. #endif
  129. /*
  130. * IOCTL commands --- we will commandeer 0x4C ('L')
  131. */
  132. #define LOOP_SET_FD 0x4C00
  133. #define LOOP_CLR_FD 0x4C01
  134. #define LOOP_SET_STATUS 0x4C02
  135. #define LOOP_GET_STATUS 0x4C03
  136. #define LOOP_SET_STATUS64 0x4C04
  137. #define LOOP_GET_STATUS64 0x4C05
  138. #define LOOP_CHANGE_FD 0x4C06
  139. #endif