blob: 1894fb8cab122db822771a1a138c885bdb0ad895 [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
Lukas Czernerd8665992010-11-18 03:38:37 +000032#define CHANNEL_FLAGS_DISCARD_ZEROES 0x02
Lukas Czernerd2bfdc72011-09-15 23:44:59 -040033#define CHANNEL_FLAGS_BLOCK_DEVICE 0x04
Lukas Czernerd8665992010-11-18 03:38:37 +000034
35#define io_channel_discard_zeroes_data(i) (i->flags & CHANNEL_FLAGS_DISCARD_ZEROES)
Theodore Ts'oadfc8c62000-10-18 19:22:24 +000036
Theodore Ts'o3839e651997-04-26 13:21:57 +000037struct struct_io_channel {
Theodore Ts'o3cb6c501997-08-11 20:29:22 +000038 errcode_t magic;
Theodore Ts'o3839e651997-04-26 13:21:57 +000039 io_manager manager;
40 char *name;
41 int block_size;
42 errcode_t (*read_error)(io_channel channel,
43 unsigned long block,
44 int count,
45 void *data,
46 size_t size,
47 int actual_bytes_read,
48 errcode_t error);
49 errcode_t (*write_error)(io_channel channel,
50 unsigned long block,
51 int count,
52 const void *data,
53 size_t size,
54 int actual_bytes_written,
55 errcode_t error);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +000056 int refcount;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +000057 int flags;
Theodore Ts'o4690e622008-08-27 21:46:26 -040058 long reserved[14];
Theodore Ts'o3839e651997-04-26 13:21:57 +000059 void *private_data;
Theodore Ts'oe9affb71997-08-24 02:57:55 +000060 void *app_data;
Theodore Ts'o0a05b902012-05-07 12:56:07 -040061 int align;
Theodore Ts'o3839e651997-04-26 13:21:57 +000062};
63
Theodore Ts'o6d96b002007-08-03 20:07:09 -040064struct struct_io_stats {
65 int num_fields;
66 int reserved;
67 unsigned long long bytes_read;
68 unsigned long long bytes_written;
69};
70
Theodore Ts'o3839e651997-04-26 13:21:57 +000071struct struct_io_manager {
Theodore Ts'o3cb6c501997-08-11 20:29:22 +000072 errcode_t magic;
Theodore Ts'o3839e651997-04-26 13:21:57 +000073 const char *name;
74 errcode_t (*open)(const char *name, int flags, io_channel *channel);
75 errcode_t (*close)(io_channel channel);
76 errcode_t (*set_blksize)(io_channel channel, int blksize);
77 errcode_t (*read_blk)(io_channel channel, unsigned long block,
78 int count, void *data);
79 errcode_t (*write_blk)(io_channel channel, unsigned long block,
80 int count, const void *data);
81 errcode_t (*flush)(io_channel channel);
Theodore Ts'oc180ac82000-10-26 20:24:43 +000082 errcode_t (*write_byte)(io_channel channel, unsigned long offset,
83 int count, const void *data);
Theodore Ts'oefc6f622008-08-27 23:07:54 -040084 errcode_t (*set_option)(io_channel channel, const char *option,
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -050085 const char *arg);
Theodore Ts'o6d96b002007-08-03 20:07:09 -040086 errcode_t (*get_stats)(io_channel channel, io_stats *io_stats);
Jose R. Santos3154e1c2008-03-03 10:41:18 -060087 errcode_t (*read_blk64)(io_channel channel, unsigned long long block,
88 int count, void *data);
89 errcode_t (*write_blk64)(io_channel channel, unsigned long long block,
90 int count, const void *data);
Lukas Czernere90a59e2010-11-18 03:38:36 +000091 errcode_t (*discard)(io_channel channel, unsigned long long block,
92 unsigned long long count);
Theodore Ts'o4690e622008-08-27 21:46:26 -040093 long reserved[16];
Theodore Ts'o3839e651997-04-26 13:21:57 +000094};
95
Theodore Ts'ofa6c6532006-03-18 18:57:44 -050096#define IO_FLAG_RW 0x0001
97#define IO_FLAG_EXCLUSIVE 0x0002
Theodore Ts'o7f1a1fb2010-09-24 10:02:25 -040098#define IO_FLAG_DIRECT_IO 0x0004
Theodore Ts'o3839e651997-04-26 13:21:57 +000099
100/*
101 * Convenience functions....
102 */
103#define io_channel_close(c) ((c)->manager->close((c)))
104#define io_channel_set_blksize(c,s) ((c)->manager->set_blksize((c),s))
105#define io_channel_read_blk(c,b,n,d) ((c)->manager->read_blk((c),b,n,d))
106#define io_channel_write_blk(c,b,n,d) ((c)->manager->write_blk((c),b,n,d))
107#define io_channel_flush(c) ((c)->manager->flush((c)))
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000108#define io_channel_bumpcount(c) ((c)->refcount++)
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400109
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500110/* io_manager.c */
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400111extern errcode_t io_channel_set_options(io_channel channel,
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500112 const char *options);
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400113extern errcode_t io_channel_write_byte(io_channel channel,
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500114 unsigned long offset,
115 int count, const void *data);
Theodore Ts'o4690e622008-08-27 21:46:26 -0400116extern errcode_t io_channel_read_blk64(io_channel channel,
117 unsigned long long block,
118 int count, void *data);
119extern errcode_t io_channel_write_blk64(io_channel channel,
120 unsigned long long block,
121 int count, const void *data);
Theodore Ts'oaa07cb72011-02-27 20:09:54 -0500122extern errcode_t io_channel_discard(io_channel channel,
123 unsigned long long block,
124 unsigned long long count);
Theodore Ts'ofd1c5a02012-05-07 14:41:49 -0400125extern errcode_t io_channel_alloc_buf(io_channel channel,
126 int count, void *ptr);
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500127
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000128/* unix_io.c */
Theodore Ts'o3839e651997-04-26 13:21:57 +0000129extern io_manager unix_io_manager;
130
Aneesh Kumar K.V72a168b2007-08-13 15:56:21 +0530131/* undo_io.c */
132extern io_manager undo_io_manager;
133extern errcode_t set_undo_io_backing_manager(io_manager manager);
134extern errcode_t set_undo_io_backup_file(char *file_name);
135
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000136/* test_io.c */
137extern io_manager test_io_manager, test_io_backing_manager;
138extern void (*test_io_cb_read_blk)
139 (unsigned long block, int count, errcode_t err);
140extern void (*test_io_cb_write_blk)
141 (unsigned long block, int count, errcode_t err);
Valerie Aurora Henson8f82ef92009-08-05 00:27:10 -0400142extern void (*test_io_cb_read_blk64)
143 (unsigned long long block, int count, errcode_t err);
144extern void (*test_io_cb_write_blk64)
145 (unsigned long long block, int count, errcode_t err);
Theodore Ts'o19c78dc1997-04-29 16:17:09 +0000146extern void (*test_io_cb_set_blksize)
147 (int blksize, errcode_t err);
Theodore Ts'o9abd2ce1998-02-16 22:00:37 +0000148
149#endif /* _EXT2FS_EXT2_IO_H */
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400150