blob: eada278ea6753b45f406f042717827921bd78f60 [file] [log] [blame]
Theodore Ts'o3839e651997-04-26 13:21:57 +00001/*
2 * io.h --- the I/O manager abstraction
3 *
Theodore Ts'o19c78dc1997-04-29 16:17:09 +00004 * 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%
Theodore Ts'o3839e651997-04-26 13:21:57 +000010 */
11
Theodore Ts'o9abd2ce1998-02-16 22:00:37 +000012#ifndef _EXT2FS_EXT2_IO_H
13#define _EXT2FS_EXT2_IO_H
14
Theodore Ts'of3db3561997-04-26 13:34:30 +000015/*
16 * ext2_loff_t is defined here since unix_io.c needs it.
17 */
18#if defined(__GNUC__) || defined(HAS_LONG_LONG)
19typedef long long ext2_loff_t;
20#else
21typedef long ext2_loff_t;
22#endif
23
24/* llseek.c */
Theodore Ts'o1c27cac1997-08-14 17:20:42 +000025ext2_loff_t ext2fs_llseek (int, ext2_loff_t, int);
Theodore Ts'of3db3561997-04-26 13:34:30 +000026
Theodore Ts'o3839e651997-04-26 13:21:57 +000027typedef struct struct_io_manager *io_manager;
28typedef struct struct_io_channel *io_channel;
29
Theodore Ts'oadfc8c62000-10-18 19:22:24 +000030#define CHANNEL_FLAGS_WRITETHROUGH 0x01
31
Theodore Ts'o3839e651997-04-26 13:21:57 +000032struct struct_io_channel {
Theodore Ts'o3cb6c501997-08-11 20:29:22 +000033 errcode_t magic;
Theodore Ts'o3839e651997-04-26 13:21:57 +000034 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);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +000051 int refcount;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +000052 int flags;
53 int reserved[14];
Theodore Ts'o3839e651997-04-26 13:21:57 +000054 void *private_data;
Theodore Ts'oe9affb71997-08-24 02:57:55 +000055 void *app_data;
Theodore Ts'o3839e651997-04-26 13:21:57 +000056};
57
58struct struct_io_manager {
Theodore Ts'o3cb6c501997-08-11 20:29:22 +000059 errcode_t magic;
Theodore Ts'o3839e651997-04-26 13:21:57 +000060 const char *name;
61 errcode_t (*open)(const char *name, int flags, io_channel *channel);
62 errcode_t (*close)(io_channel channel);
63 errcode_t (*set_blksize)(io_channel channel, int blksize);
64 errcode_t (*read_blk)(io_channel channel, unsigned long block,
65 int count, void *data);
66 errcode_t (*write_blk)(io_channel channel, unsigned long block,
67 int count, const void *data);
68 errcode_t (*flush)(io_channel channel);
Theodore Ts'oc180ac82000-10-26 20:24:43 +000069 errcode_t (*write_byte)(io_channel channel, unsigned long offset,
70 int count, const void *data);
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -050071 errcode_t (*set_option)(io_channel channel, const char *option,
72 const char *arg);
73 int reserved[14];
Theodore Ts'o3839e651997-04-26 13:21:57 +000074};
75
Theodore Ts'ofa6c6532006-03-18 18:57:44 -050076#define IO_FLAG_RW 0x0001
77#define IO_FLAG_EXCLUSIVE 0x0002
Theodore Ts'o3839e651997-04-26 13:21:57 +000078
79/*
80 * Convenience functions....
81 */
82#define io_channel_close(c) ((c)->manager->close((c)))
83#define io_channel_set_blksize(c,s) ((c)->manager->set_blksize((c),s))
84#define io_channel_read_blk(c,b,n,d) ((c)->manager->read_blk((c),b,n,d))
85#define io_channel_write_blk(c,b,n,d) ((c)->manager->write_blk((c),b,n,d))
86#define io_channel_flush(c) ((c)->manager->flush((c)))
Theodore Ts'oa29f4d31997-04-29 21:26:48 +000087#define io_channel_bumpcount(c) ((c)->refcount++)
Theodore Ts'o3839e651997-04-26 13:21:57 +000088
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -050089/* io_manager.c */
90extern errcode_t io_channel_set_options(io_channel channel,
91 const char *options);
92extern errcode_t io_channel_write_byte(io_channel channel,
93 unsigned long offset,
94 int count, const void *data);
95
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000096/* unix_io.c */
Theodore Ts'o3839e651997-04-26 13:21:57 +000097extern io_manager unix_io_manager;
98
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000099/* test_io.c */
100extern io_manager test_io_manager, test_io_backing_manager;
101extern void (*test_io_cb_read_blk)
102 (unsigned long block, int count, errcode_t err);
103extern void (*test_io_cb_write_blk)
104 (unsigned long block, int count, errcode_t err);
105extern void (*test_io_cb_set_blksize)
106 (int blksize, errcode_t err);
Theodore Ts'o9abd2ce1998-02-16 22:00:37 +0000107
108#endif /* _EXT2FS_EXT2_IO_H */
109