loop.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * loop.h
  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. */
  9. #ifndef _LINUX_LOOP_H
  10. #define _LINUX_LOOP_H
  11. #include <linux/bio.h>
  12. #include <linux/blkdev.h>
  13. #include <linux/blk-mq.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/mutex.h>
  16. #include <linux/kthread.h>
  17. #include <uapi/linux/loop.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. atomic_t 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. kuid_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. int lo_state;
  51. struct kthread_worker worker;
  52. struct task_struct *worker_task;
  53. bool use_dio;
  54. bool sysfs_inited;
  55. struct request_queue *lo_queue;
  56. struct blk_mq_tag_set tag_set;
  57. struct gendisk *lo_disk;
  58. };
  59. struct loop_cmd {
  60. struct kthread_work work;
  61. struct request *rq;
  62. struct list_head list;
  63. bool use_aio; /* use AIO interface to handle I/O */
  64. struct kiocb iocb;
  65. };
  66. /* Support for loadable transfer modules */
  67. struct loop_func_table {
  68. int number; /* filter type */
  69. int (*transfer)(struct loop_device *lo, int cmd,
  70. struct page *raw_page, unsigned raw_off,
  71. struct page *loop_page, unsigned loop_off,
  72. int size, sector_t real_block);
  73. int (*init)(struct loop_device *, const struct loop_info64 *);
  74. /* release is called from loop_unregister_transfer or clr_fd */
  75. int (*release)(struct loop_device *);
  76. int (*ioctl)(struct loop_device *, int cmd, unsigned long arg);
  77. struct module *owner;
  78. };
  79. int loop_register_transfer(struct loop_func_table *funcs);
  80. int loop_unregister_transfer(int number);
  81. #endif