ext2_io.h 3.1 KB

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