3
0

ext2_io.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * io.h --- the I/O manager abstraction
  3. *
  4. * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
  5. *
  6. * %Begin-Header%
  7. * This file may be redistributed under the terms of the GNU Public
  8. * License.
  9. * %End-Header%
  10. */
  11. #ifndef _EXT2FS_EXT2_IO_H
  12. #define _EXT2FS_EXT2_IO_H
  13. /*
  14. * ext2_loff_t is defined here since unix_io.c needs it.
  15. */
  16. #if defined(__GNUC__) || defined(HAS_LONG_LONG)
  17. typedef long long ext2_loff_t;
  18. #else
  19. typedef long ext2_loff_t;
  20. #endif
  21. /* llseek.c */
  22. ext2_loff_t ext2fs_llseek (int, ext2_loff_t, int);
  23. typedef struct struct_io_manager *io_manager;
  24. typedef struct struct_io_channel *io_channel;
  25. #define CHANNEL_FLAGS_WRITETHROUGH 0x01
  26. struct struct_io_channel {
  27. errcode_t magic;
  28. io_manager manager;
  29. char *name;
  30. int block_size;
  31. errcode_t (*read_error)(io_channel channel,
  32. unsigned long block,
  33. int count,
  34. void *data,
  35. size_t size,
  36. int actual_bytes_read,
  37. errcode_t error);
  38. errcode_t (*write_error)(io_channel channel,
  39. unsigned long block,
  40. int count,
  41. const void *data,
  42. size_t size,
  43. int actual_bytes_written,
  44. errcode_t error);
  45. int refcount;
  46. int flags;
  47. int reserved[14];
  48. void *private_data;
  49. void *app_data;
  50. };
  51. struct struct_io_manager {
  52. errcode_t magic;
  53. const char *name;
  54. errcode_t (*open)(const char *name, int flags, io_channel *channel);
  55. errcode_t (*close)(io_channel channel);
  56. errcode_t (*set_blksize)(io_channel channel, int blksize);
  57. errcode_t (*read_blk)(io_channel channel, unsigned long block,
  58. int count, void *data);
  59. errcode_t (*write_blk)(io_channel channel, unsigned long block,
  60. int count, const void *data);
  61. errcode_t (*flush)(io_channel channel);
  62. errcode_t (*write_byte)(io_channel channel, unsigned long offset,
  63. int count, const void *data);
  64. errcode_t (*set_option)(io_channel channel, const char *option,
  65. const char *arg);
  66. int reserved[14];
  67. };
  68. #define IO_FLAG_RW 1
  69. /*
  70. * Convenience functions....
  71. */
  72. #define io_channel_close(c) ((c)->manager->close((c)))
  73. #define io_channel_set_blksize(c,s) ((c)->manager->set_blksize((c),s))
  74. #define io_channel_read_blk(c,b,n,d) ((c)->manager->read_blk((c),b,n,d))
  75. #define io_channel_write_blk(c,b,n,d) ((c)->manager->write_blk((c),b,n,d))
  76. #define io_channel_flush(c) ((c)->manager->flush((c)))
  77. #define io_channel_bumpcount(c) ((c)->refcount++)
  78. /* io_manager.c */
  79. extern errcode_t io_channel_set_options(io_channel channel,
  80. const char *options);
  81. extern errcode_t io_channel_write_byte(io_channel channel,
  82. unsigned long offset,
  83. int count, const void *data);
  84. /* unix_io.c */
  85. extern io_manager unix_io_manager;
  86. /* test_io.c */
  87. extern io_manager test_io_manager, test_io_backing_manager;
  88. extern void (*test_io_cb_read_blk)
  89. (unsigned long block, int count, errcode_t err);
  90. extern void (*test_io_cb_write_blk)
  91. (unsigned long block, int count, errcode_t err);
  92. extern void (*test_io_cb_set_blksize)
  93. (int blksize, errcode_t err);
  94. #endif /* _EXT2FS_EXT2_IO_H */