blktrans.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright © 2003-2010 David Woodhouse <dwmw2@infradead.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. *
  18. */
  19. #ifndef __MTD_TRANS_H__
  20. #define __MTD_TRANS_H__
  21. #include <linux/mutex.h>
  22. #include <linux/kref.h>
  23. #include <linux/sysfs.h>
  24. #include <linux/workqueue.h>
  25. struct hd_geometry;
  26. struct mtd_info;
  27. struct mtd_blktrans_ops;
  28. struct file;
  29. struct inode;
  30. struct mtd_blktrans_dev {
  31. struct mtd_blktrans_ops *tr;
  32. struct list_head list;
  33. struct mtd_info *mtd;
  34. struct mutex lock;
  35. int devnum;
  36. bool bg_stop;
  37. unsigned long size;
  38. int readonly;
  39. int open;
  40. struct kref ref;
  41. struct gendisk *disk;
  42. struct attribute_group *disk_attributes;
  43. struct workqueue_struct *wq;
  44. struct work_struct work;
  45. struct request_queue *rq;
  46. spinlock_t queue_lock;
  47. void *priv;
  48. fmode_t file_mode;
  49. };
  50. struct mtd_blktrans_ops {
  51. char *name;
  52. int major;
  53. int part_bits;
  54. int blksize;
  55. int blkshift;
  56. /* Access functions */
  57. int (*readsect)(struct mtd_blktrans_dev *dev,
  58. unsigned long block, char *buffer);
  59. int (*writesect)(struct mtd_blktrans_dev *dev,
  60. unsigned long block, char *buffer);
  61. int (*discard)(struct mtd_blktrans_dev *dev,
  62. unsigned long block, unsigned nr_blocks);
  63. void (*background)(struct mtd_blktrans_dev *dev);
  64. /* Block layer ioctls */
  65. int (*getgeo)(struct mtd_blktrans_dev *dev, struct hd_geometry *geo);
  66. int (*flush)(struct mtd_blktrans_dev *dev);
  67. /* Called with mtd_table_mutex held; no race with add/remove */
  68. int (*open)(struct mtd_blktrans_dev *dev);
  69. void (*release)(struct mtd_blktrans_dev *dev);
  70. /* Called on {de,}registration and on subsequent addition/removal
  71. of devices, with mtd_table_mutex held. */
  72. void (*add_mtd)(struct mtd_blktrans_ops *tr, struct mtd_info *mtd);
  73. void (*remove_dev)(struct mtd_blktrans_dev *dev);
  74. struct list_head devs;
  75. struct list_head list;
  76. struct module *owner;
  77. };
  78. extern int register_mtd_blktrans(struct mtd_blktrans_ops *tr);
  79. extern int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr);
  80. extern int add_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
  81. extern int del_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
  82. extern int mtd_blktrans_cease_background(struct mtd_blktrans_dev *dev);
  83. #endif /* __MTD_TRANS_H__ */