blktrans.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. void (*background)(struct mtd_blktrans_dev *dev);
  60. /* Block layer ioctls */
  61. int (*getgeo)(struct mtd_blktrans_dev *dev, struct hd_geometry *geo);
  62. int (*flush)(struct mtd_blktrans_dev *dev);
  63. /* Called with mtd_table_mutex held; no race with add/remove */
  64. int (*open)(struct mtd_blktrans_dev *dev);
  65. int (*release)(struct mtd_blktrans_dev *dev);
  66. /* Called on {de,}registration and on subsequent addition/removal
  67. of devices, with mtd_table_mutex held. */
  68. void (*add_mtd)(struct mtd_blktrans_ops *tr, struct mtd_info *mtd);
  69. void (*remove_dev)(struct mtd_blktrans_dev *dev);
  70. struct list_head devs;
  71. struct list_head list;
  72. struct module *owner;
  73. };
  74. extern int register_mtd_blktrans(struct mtd_blktrans_ops *tr);
  75. extern int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr);
  76. extern int add_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
  77. extern int del_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
  78. extern int mtd_blktrans_cease_background(struct mtd_blktrans_dev *dev);
  79. #endif /* __MTD_TRANS_H__ */