119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project/*
219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project * io.h --- the I/O manager abstraction
33984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt *
419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project *
619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project * %Begin-Header%
78558eab78390d1924cd6b255686ceef133f294d5Ken Sumrall * This file may be redistributed under the terms of the GNU Library
88558eab78390d1924cd6b255686ceef133f294d5Ken Sumrall * General Public License, version 2.
919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project * %End-Header%
1019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project */
1119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
1219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#ifndef _EXT2FS_EXT2_IO_H
1319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#define _EXT2FS_EXT2_IO_H
1419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
1519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project/*
1619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project * ext2_loff_t is defined here since unix_io.c needs it.
1719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project */
1819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#if defined(__GNUC__) || defined(HAS_LONG_LONG)
1919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projecttypedef long long	ext2_loff_t;
2019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#else
2119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projecttypedef long		ext2_loff_t;
2219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#endif
2319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
2419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project/* llseek.c */
2519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectext2_loff_t ext2fs_llseek (int, ext2_loff_t, int);
2619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
2719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projecttypedef struct struct_io_manager *io_manager;
2819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projecttypedef struct struct_io_channel *io_channel;
293984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidttypedef struct struct_io_stats *io_stats;
3019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
3119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#define CHANNEL_FLAGS_WRITETHROUGH	0x01
3219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
3319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectstruct struct_io_channel {
3419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	errcode_t	magic;
3519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	io_manager	manager;
3619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	char		*name;
3719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int		block_size;
3819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	errcode_t	(*read_error)(io_channel channel,
3919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				      unsigned long block,
4019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				      int count,
4119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				      void *data,
4219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				      size_t size,
4319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				      int actual_bytes_read,
4419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				      errcode_t	error);
4519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	errcode_t	(*write_error)(io_channel channel,
4619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				       unsigned long block,
4719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				       int count,
4819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				       const void *data,
4919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				       size_t size,
5019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				       int actual_bytes_written,
5119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				       errcode_t error);
5219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int		refcount;
5319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	int		flags;
543984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	long		reserved[14];
5519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	void		*private_data;
5619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	void		*app_data;
5719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project};
5819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
593984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidtstruct struct_io_stats {
603984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	int			num_fields;
613984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	int			reserved;
623984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	unsigned long long	bytes_read;
633984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	unsigned long long	bytes_written;
643984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt};
653984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt
6619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectstruct struct_io_manager {
6719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	errcode_t magic;
6819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	const char *name;
6919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	errcode_t (*open)(const char *name, int flags, io_channel *channel);
7019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	errcode_t (*close)(io_channel channel);
7119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	errcode_t (*set_blksize)(io_channel channel, int blksize);
7219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	errcode_t (*read_blk)(io_channel channel, unsigned long block,
7319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			      int count, void *data);
7419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	errcode_t (*write_blk)(io_channel channel, unsigned long block,
7519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project			       int count, const void *data);
7619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	errcode_t (*flush)(io_channel channel);
7719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	errcode_t (*write_byte)(io_channel channel, unsigned long offset,
7819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				int count, const void *data);
793984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	errcode_t (*set_option)(io_channel channel, const char *option,
8019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				const char *arg);
813984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	errcode_t (*get_stats)(io_channel channel, io_stats *io_stats);
823984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	errcode_t (*read_blk64)(io_channel channel, unsigned long long block,
833984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt					int count, void *data);
843984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	errcode_t (*write_blk64)(io_channel channel, unsigned long long block,
853984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt					int count, const void *data);
863984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt	long	reserved[16];
8719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project};
8819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
8919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#define IO_FLAG_RW		0x0001
9019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#define IO_FLAG_EXCLUSIVE	0x0002
918558eab78390d1924cd6b255686ceef133f294d5Ken Sumrall#define IO_FLAG_DIRECT_IO	0x0004
9219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
9319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project/*
9419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project * Convenience functions....
9519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project */
9619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#define io_channel_close(c) 		((c)->manager->close((c)))
9719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#define io_channel_set_blksize(c,s)	((c)->manager->set_blksize((c),s))
9819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#define io_channel_read_blk(c,b,n,d)	((c)->manager->read_blk((c),b,n,d))
9919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#define io_channel_write_blk(c,b,n,d)	((c)->manager->write_blk((c),b,n,d))
10019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#define io_channel_flush(c) 		((c)->manager->flush((c)))
10119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#define io_channel_bumpcount(c)		((c)->refcount++)
1023984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt
10319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project/* io_manager.c */
1043984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidtextern errcode_t io_channel_set_options(io_channel channel,
10519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project					const char *options);
1063984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidtextern errcode_t io_channel_write_byte(io_channel channel,
10719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				       unsigned long offset,
10819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project				       int count, const void *data);
1093984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidtextern errcode_t io_channel_read_blk64(io_channel channel,
1103984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				       unsigned long long block,
1113984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt				       int count, void *data);
1123984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidtextern errcode_t io_channel_write_blk64(io_channel channel,
1133984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt					unsigned long long block,
1143984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt					int count, const void *data);
11519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
11619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project/* unix_io.c */
11719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectextern io_manager unix_io_manager;
11819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
1193984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt/* undo_io.c */
1203984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidtextern io_manager undo_io_manager;
1213984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidtextern errcode_t set_undo_io_backing_manager(io_manager manager);
1223984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidtextern errcode_t set_undo_io_backup_file(char *file_name);
1233984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt
12419dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project/* test_io.c */
12519dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectextern io_manager test_io_manager, test_io_backing_manager;
12619dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectextern void (*test_io_cb_read_blk)
12719dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	(unsigned long block, int count, errcode_t err);
12819dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectextern void (*test_io_cb_write_blk)
12919dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	(unsigned long block, int count, errcode_t err);
13019dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Projectextern void (*test_io_cb_set_blksize)
13119dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project	(int blksize, errcode_t err);
13219dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project
13319dacda2b02bb08c0ffb649f84526b249c749279The Android Open Source Project#endif /* _EXT2FS_EXT2_IO_H */
1343984b61df41c68966bdfbb2a5e5a45ef4b9a536cDmitry Shmidt
135