blktrans.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. struct hd_geometry;
  25. struct mtd_info;
  26. struct mtd_blktrans_ops;
  27. struct file;
  28. struct inode;
  29. struct mtd_blktrans_dev {
  30. struct mtd_blktrans_ops *tr;
  31. struct list_head list;
  32. struct mtd_info *mtd;
  33. struct mutex lock;
  34. int devnum;
  35. unsigned long size;
  36. int readonly;
  37. int open;
  38. struct kref ref;
  39. struct gendisk *disk;
  40. struct attribute_group *disk_attributes;
  41. struct task_struct *thread;
  42. struct request_queue *rq;
  43. spinlock_t queue_lock;
  44. void *priv;
  45. };
  46. struct mtd_blktrans_ops {
  47. char *name;
  48. int major;
  49. int part_bits;
  50. int blksize;
  51. int blkshift;
  52. /* Access functions */
  53. int (*readsect)(struct mtd_blktrans_dev *dev,
  54. unsigned long block, char *buffer);
  55. int (*writesect)(struct mtd_blktrans_dev *dev,
  56. unsigned long block, char *buffer);
  57. int (*discard)(struct mtd_blktrans_dev *dev,
  58. unsigned long block, unsigned nr_blocks);
  59. /* Block layer ioctls */
  60. int (*getgeo)(struct mtd_blktrans_dev *dev, struct hd_geometry *geo);
  61. int (*flush)(struct mtd_blktrans_dev *dev);
  62. /* Called with mtd_table_mutex held; no race with add/remove */
  63. int (*open)(struct mtd_blktrans_dev *dev);
  64. int (*release)(struct mtd_blktrans_dev *dev);
  65. /* Called on {de,}registration and on subsequent addition/removal
  66. of devices, with mtd_table_mutex held. */
  67. void (*add_mtd)(struct mtd_blktrans_ops *tr, struct mtd_info *mtd);
  68. void (*remove_dev)(struct mtd_blktrans_dev *dev);
  69. struct list_head devs;
  70. struct list_head list;
  71. struct module *owner;
  72. };
  73. extern int register_mtd_blktrans(struct mtd_blktrans_ops *tr);
  74. extern int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr);
  75. extern int add_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
  76. extern int del_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
  77. #endif /* __MTD_TRANS_H__ */