blob: f26b569b9862013257ec30c3a344cf713ea51dbf [file] [log] [blame]
Theodore Ts'o3839e651997-04-26 13:21:57 +00001/*
2 * io.h --- the I/O manager abstraction
Theodore Ts'oefc6f622008-08-27 23:07:54 -04003 *
Theodore Ts'o19c78dc1997-04-29 16:17:09 +00004 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
5 *
6 * %Begin-Header%
Theodore Ts'o543547a2010-05-17 21:31:56 -04007 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
Theodore Ts'o19c78dc1997-04-29 16:17:09 +00009 * %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;
Theodore Ts'o6d96b002007-08-03 20:07:09 -040029typedef struct struct_io_stats *io_stats;
Theodore Ts'o3839e651997-04-26 13:21:57 +000030
Theodore Ts'oadfc8c62000-10-18 19:22:24 +000031#define CHANNEL_FLAGS_WRITETHROUGH 0x01
32
Theodore Ts'o3839e651997-04-26 13:21:57 +000033struct struct_io_channel {
Theodore Ts'o3cb6c501997-08-11 20:29:22 +000034 errcode_t magic;
Theodore Ts'o3839e651997-04-26 13:21:57 +000035 io_manager manager;
36 char *name;
37 int block_size;
38 errcode_t (*read_error)(io_channel channel,
39 unsigned long block,
40 int count,
41 void *data,
42 size_t size,
43 int actual_bytes_read,
44 errcode_t error);
45 errcode_t (*write_error)(io_channel channel,
46 unsigned long block,
47 int count,
48 const void *data,
49 size_t size,
50 int actual_bytes_written,
51 errcode_t error);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +000052 int refcount;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +000053 int flags;
Theodore Ts'o4690e622008-08-27 21:46:26 -040054 long reserved[14];
Theodore Ts'o3839e651997-04-26 13:21:57 +000055 void *private_data;
Theodore Ts'oe9affb71997-08-24 02:57:55 +000056 void *app_data;
Theodore Ts'o3839e651997-04-26 13:21:57 +000057};
58
Theodore Ts'o6d96b002007-08-03 20:07:09 -040059struct struct_io_stats {
60 int num_fields;
61 int reserved;
62 unsigned long long bytes_read;
63 unsigned long long bytes_written;
64};
65
Theodore Ts'o3839e651997-04-26 13:21:57 +000066struct struct_io_manager {
Theodore Ts'o3cb6c501997-08-11 20:29:22 +000067 errcode_t magic;
Theodore Ts'o3839e651997-04-26 13:21:57 +000068 const char *name;
69 errcode_t (*open)(const char *name, int flags, io_channel *channel);
70 errcode_t (*close)(io_channel channel);
71 errcode_t (*set_blksize)(io_channel channel, int blksize);
72 errcode_t (*read_blk)(io_channel channel, unsigned long block,
73 int count, void *data);
74 errcode_t (*write_blk)(io_channel channel, unsigned long block,
75 int count, const void *data);
76 errcode_t (*flush)(io_channel channel);
Theodore Ts'oc180ac82000-10-26 20:24:43 +000077 errcode_t (*write_byte)(io_channel channel, unsigned long offset,
78 int count, const void *data);
Theodore Ts'oefc6f622008-08-27 23:07:54 -040079 errcode_t (*set_option)(io_channel channel, const char *option,
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -050080 const char *arg);
Theodore Ts'o6d96b002007-08-03 20:07:09 -040081 errcode_t (*get_stats)(io_channel channel, io_stats *io_stats);
Jose R. Santos3154e1c2008-03-03 10:41:18 -060082 errcode_t (*read_blk64)(io_channel channel, unsigned long long block,
83 int count, void *data);
84 errcode_t (*write_blk64)(io_channel channel, unsigned long long block,
85 int count, const void *data);
Lukas Czernere90a59e2010-11-18 03:38:36 +000086 errcode_t (*discard)(io_channel channel, unsigned long long block,
87 unsigned long long count);
Theodore Ts'o4690e622008-08-27 21:46:26 -040088 long reserved[16];
Theodore Ts'o3839e651997-04-26 13:21:57 +000089};
90
Theodore Ts'ofa6c6532006-03-18 18:57:44 -050091#define IO_FLAG_RW 0x0001
92#define IO_FLAG_EXCLUSIVE 0x0002
Theodore Ts'o7f1a1fb2010-09-24 10:02:25 -040093#define IO_FLAG_DIRECT_IO 0x0004
Theodore Ts'o3839e651997-04-26 13:21:57 +000094
95/*
96 * Convenience functions....
97 */
98#define io_channel_close(c) ((c)->manager->close((c)))
99#define io_channel_set_blksize(c,s) ((c)->manager->set_blksize((c),s))
100#define io_channel_read_blk(c,b,n,d) ((c)->manager->read_blk((c),b,n,d))
101#define io_channel_write_blk(c,b,n,d) ((c)->manager->write_blk((c),b,n,d))
102#define io_channel_flush(c) ((c)->manager->flush((c)))
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000103#define io_channel_bumpcount(c) ((c)->refcount++)
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400104
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500105/* io_manager.c */
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400106extern errcode_t io_channel_set_options(io_channel channel,
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500107 const char *options);
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400108extern errcode_t io_channel_write_byte(io_channel channel,
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500109 unsigned long offset,
110 int count, const void *data);
Theodore Ts'o4690e622008-08-27 21:46:26 -0400111extern errcode_t io_channel_read_blk64(io_channel channel,
112 unsigned long long block,
113 int count, void *data);
114extern errcode_t io_channel_write_blk64(io_channel channel,
115 unsigned long long block,
116 int count, const void *data);
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500117
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000118/* unix_io.c */
Theodore Ts'o3839e651997-04-26 13:21:57 +0000119extern io_manager unix_io_manager;
120
Aneesh Kumar K.V72a168b2007-08-13 15:56:21 +0530121/* undo_io.c */
122extern io_manager undo_io_manager;
123extern errcode_t set_undo_io_backing_manager(io_manager manager);
124extern errcode_t set_undo_io_backup_file(char *file_name);
125
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000126/* test_io.c */
127extern io_manager test_io_manager, test_io_backing_manager;
128extern void (*test_io_cb_read_blk)
129 (unsigned long block, int count, errcode_t err);
130extern void (*test_io_cb_write_blk)
131 (unsigned long block, int count, errcode_t err);
Valerie Aurora Henson8f82ef92009-08-05 00:27:10 -0400132extern void (*test_io_cb_read_blk64)
133 (unsigned long long block, int count, errcode_t err);
134extern void (*test_io_cb_write_blk64)
135 (unsigned long long block, int count, errcode_t err);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000136extern void (*test_io_cb_set_blksize)
137 (int blksize, errcode_t err);
Theodore Ts'o9abd2ce1998-02-16 22:00:37 +0000138
139#endif /* _EXT2FS_EXT2_IO_H */
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400140