blktrans.h 2.8 KB

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