xref: /aosp_15_r20/external/e2fsprogs/lib/ext2fs/inode_io.c (revision 6a54128f25917bfc36a8a6e9d722c04a0b4641b6)
1*6a54128fSAndroid Build Coastguard Worker /*
2*6a54128fSAndroid Build Coastguard Worker  * inode_io.c --- This is allows an inode in an ext2 filesystem image
3*6a54128fSAndroid Build Coastguard Worker  * 	to be accessed via the I/O manager interface.
4*6a54128fSAndroid Build Coastguard Worker  *
5*6a54128fSAndroid Build Coastguard Worker  * Copyright (C) 2002 Theodore Ts'o.
6*6a54128fSAndroid Build Coastguard Worker  *
7*6a54128fSAndroid Build Coastguard Worker  * %Begin-Header%
8*6a54128fSAndroid Build Coastguard Worker  * This file may be redistributed under the terms of the GNU Library
9*6a54128fSAndroid Build Coastguard Worker  * General Public License, version 2.
10*6a54128fSAndroid Build Coastguard Worker  * %End-Header%
11*6a54128fSAndroid Build Coastguard Worker  */
12*6a54128fSAndroid Build Coastguard Worker 
13*6a54128fSAndroid Build Coastguard Worker #include "config.h"
14*6a54128fSAndroid Build Coastguard Worker #include <stdio.h>
15*6a54128fSAndroid Build Coastguard Worker #include <string.h>
16*6a54128fSAndroid Build Coastguard Worker #if HAVE_UNISTD_H
17*6a54128fSAndroid Build Coastguard Worker #include <unistd.h>
18*6a54128fSAndroid Build Coastguard Worker #endif
19*6a54128fSAndroid Build Coastguard Worker #if HAVE_ERRNO_H
20*6a54128fSAndroid Build Coastguard Worker #include <errno.h>
21*6a54128fSAndroid Build Coastguard Worker #endif
22*6a54128fSAndroid Build Coastguard Worker #include <time.h>
23*6a54128fSAndroid Build Coastguard Worker 
24*6a54128fSAndroid Build Coastguard Worker #include "ext2_fs.h"
25*6a54128fSAndroid Build Coastguard Worker #include "ext2fs.h"
26*6a54128fSAndroid Build Coastguard Worker 
27*6a54128fSAndroid Build Coastguard Worker /*
28*6a54128fSAndroid Build Coastguard Worker  * For checking structure magic numbers...
29*6a54128fSAndroid Build Coastguard Worker  */
30*6a54128fSAndroid Build Coastguard Worker 
31*6a54128fSAndroid Build Coastguard Worker #define EXT2_CHECK_MAGIC(struct, code) \
32*6a54128fSAndroid Build Coastguard Worker 	  if ((struct)->magic != (code)) return (code)
33*6a54128fSAndroid Build Coastguard Worker 
34*6a54128fSAndroid Build Coastguard Worker struct inode_private_data {
35*6a54128fSAndroid Build Coastguard Worker 	int				magic;
36*6a54128fSAndroid Build Coastguard Worker 	char				name[32];
37*6a54128fSAndroid Build Coastguard Worker 	ext2_file_t			file;
38*6a54128fSAndroid Build Coastguard Worker 	ext2_filsys			fs;
39*6a54128fSAndroid Build Coastguard Worker 	ext2_ino_t 			ino;
40*6a54128fSAndroid Build Coastguard Worker 	struct ext2_inode		inode;
41*6a54128fSAndroid Build Coastguard Worker 	int				flags;
42*6a54128fSAndroid Build Coastguard Worker 	struct inode_private_data	*next;
43*6a54128fSAndroid Build Coastguard Worker };
44*6a54128fSAndroid Build Coastguard Worker 
45*6a54128fSAndroid Build Coastguard Worker #define CHANNEL_HAS_INODE	0x8000
46*6a54128fSAndroid Build Coastguard Worker 
47*6a54128fSAndroid Build Coastguard Worker static struct inode_private_data *top_intern;
48*6a54128fSAndroid Build Coastguard Worker static int ino_unique = 0;
49*6a54128fSAndroid Build Coastguard Worker 
50*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_open(const char *name, int flags, io_channel *channel);
51*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_close(io_channel channel);
52*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_set_blksize(io_channel channel, int blksize);
53*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_read_blk(io_channel channel, unsigned long block,
54*6a54128fSAndroid Build Coastguard Worker 			       int count, void *data);
55*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_write_blk(io_channel channel, unsigned long block,
56*6a54128fSAndroid Build Coastguard Worker 				int count, const void *data);
57*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_flush(io_channel channel);
58*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_write_byte(io_channel channel, unsigned long offset,
59*6a54128fSAndroid Build Coastguard Worker 				int size, const void *data);
60*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_read_blk64(io_channel channel,
61*6a54128fSAndroid Build Coastguard Worker 				unsigned long long block, int count, void *data);
62*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_write_blk64(io_channel channel,
63*6a54128fSAndroid Build Coastguard Worker 				unsigned long long block, int count, const void *data);
64*6a54128fSAndroid Build Coastguard Worker 
65*6a54128fSAndroid Build Coastguard Worker static struct struct_io_manager struct_inode_manager = {
66*6a54128fSAndroid Build Coastguard Worker 	.magic		= EXT2_ET_MAGIC_IO_MANAGER,
67*6a54128fSAndroid Build Coastguard Worker 	.name		= "Inode I/O Manager",
68*6a54128fSAndroid Build Coastguard Worker 	.open		= inode_open,
69*6a54128fSAndroid Build Coastguard Worker 	.close		= inode_close,
70*6a54128fSAndroid Build Coastguard Worker 	.set_blksize	= inode_set_blksize,
71*6a54128fSAndroid Build Coastguard Worker 	.read_blk	= inode_read_blk,
72*6a54128fSAndroid Build Coastguard Worker 	.write_blk	= inode_write_blk,
73*6a54128fSAndroid Build Coastguard Worker 	.flush		= inode_flush,
74*6a54128fSAndroid Build Coastguard Worker 	.write_byte	= inode_write_byte,
75*6a54128fSAndroid Build Coastguard Worker 	.read_blk64	= inode_read_blk64,
76*6a54128fSAndroid Build Coastguard Worker 	.write_blk64	= inode_write_blk64
77*6a54128fSAndroid Build Coastguard Worker };
78*6a54128fSAndroid Build Coastguard Worker 
79*6a54128fSAndroid Build Coastguard Worker io_manager inode_io_manager = &struct_inode_manager;
80*6a54128fSAndroid Build Coastguard Worker 
ext2fs_inode_io_intern2(ext2_filsys fs,ext2_ino_t ino,struct ext2_inode * inode,char ** name)81*6a54128fSAndroid Build Coastguard Worker errcode_t ext2fs_inode_io_intern2(ext2_filsys fs, ext2_ino_t ino,
82*6a54128fSAndroid Build Coastguard Worker 				  struct ext2_inode *inode,
83*6a54128fSAndroid Build Coastguard Worker 				  char **name)
84*6a54128fSAndroid Build Coastguard Worker {
85*6a54128fSAndroid Build Coastguard Worker 	struct inode_private_data 	*data;
86*6a54128fSAndroid Build Coastguard Worker 	errcode_t			retval;
87*6a54128fSAndroid Build Coastguard Worker 
88*6a54128fSAndroid Build Coastguard Worker 	if ((retval = ext2fs_get_mem(sizeof(struct inode_private_data),
89*6a54128fSAndroid Build Coastguard Worker 				     &data)))
90*6a54128fSAndroid Build Coastguard Worker 		return retval;
91*6a54128fSAndroid Build Coastguard Worker 	data->magic = EXT2_ET_MAGIC_INODE_IO_CHANNEL;
92*6a54128fSAndroid Build Coastguard Worker 	sprintf(data->name, "%u:%d", ino, ino_unique++);
93*6a54128fSAndroid Build Coastguard Worker 	data->file = 0;
94*6a54128fSAndroid Build Coastguard Worker 	data->fs = fs;
95*6a54128fSAndroid Build Coastguard Worker 	data->ino = ino;
96*6a54128fSAndroid Build Coastguard Worker 	data->flags = 0;
97*6a54128fSAndroid Build Coastguard Worker 	if (inode) {
98*6a54128fSAndroid Build Coastguard Worker 		memcpy(&data->inode, inode, sizeof(struct ext2_inode));
99*6a54128fSAndroid Build Coastguard Worker 		data->flags |= CHANNEL_HAS_INODE;
100*6a54128fSAndroid Build Coastguard Worker 	}
101*6a54128fSAndroid Build Coastguard Worker 	data->next = top_intern;
102*6a54128fSAndroid Build Coastguard Worker 	top_intern = data;
103*6a54128fSAndroid Build Coastguard Worker 	*name = data->name;
104*6a54128fSAndroid Build Coastguard Worker 	return 0;
105*6a54128fSAndroid Build Coastguard Worker }
106*6a54128fSAndroid Build Coastguard Worker 
ext2fs_inode_io_intern(ext2_filsys fs,ext2_ino_t ino,char ** name)107*6a54128fSAndroid Build Coastguard Worker errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino,
108*6a54128fSAndroid Build Coastguard Worker 				 char **name)
109*6a54128fSAndroid Build Coastguard Worker {
110*6a54128fSAndroid Build Coastguard Worker 	return ext2fs_inode_io_intern2(fs, ino, NULL, name);
111*6a54128fSAndroid Build Coastguard Worker }
112*6a54128fSAndroid Build Coastguard Worker 
113*6a54128fSAndroid Build Coastguard Worker 
inode_open(const char * name,int flags,io_channel * channel)114*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_open(const char *name, int flags, io_channel *channel)
115*6a54128fSAndroid Build Coastguard Worker {
116*6a54128fSAndroid Build Coastguard Worker 	io_channel	io = NULL;
117*6a54128fSAndroid Build Coastguard Worker 	struct inode_private_data *prev, *data = NULL;
118*6a54128fSAndroid Build Coastguard Worker 	errcode_t	retval;
119*6a54128fSAndroid Build Coastguard Worker 	int		open_flags;
120*6a54128fSAndroid Build Coastguard Worker 
121*6a54128fSAndroid Build Coastguard Worker 	if (name == 0)
122*6a54128fSAndroid Build Coastguard Worker 		return EXT2_ET_BAD_DEVICE_NAME;
123*6a54128fSAndroid Build Coastguard Worker 
124*6a54128fSAndroid Build Coastguard Worker 	for (data = top_intern, prev = NULL; data;
125*6a54128fSAndroid Build Coastguard Worker 	     prev = data, data = data->next)
126*6a54128fSAndroid Build Coastguard Worker 		if (strcmp(name, data->name) == 0)
127*6a54128fSAndroid Build Coastguard Worker 			break;
128*6a54128fSAndroid Build Coastguard Worker 	if (!data)
129*6a54128fSAndroid Build Coastguard Worker 		return ENOENT;
130*6a54128fSAndroid Build Coastguard Worker 	if (prev)
131*6a54128fSAndroid Build Coastguard Worker 		prev->next = data->next;
132*6a54128fSAndroid Build Coastguard Worker 	else
133*6a54128fSAndroid Build Coastguard Worker 		top_intern = data->next;
134*6a54128fSAndroid Build Coastguard Worker 
135*6a54128fSAndroid Build Coastguard Worker 	retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io);
136*6a54128fSAndroid Build Coastguard Worker 	if (retval)
137*6a54128fSAndroid Build Coastguard Worker 		goto cleanup;
138*6a54128fSAndroid Build Coastguard Worker 	memset(io, 0, sizeof(struct struct_io_channel));
139*6a54128fSAndroid Build Coastguard Worker 
140*6a54128fSAndroid Build Coastguard Worker 	io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
141*6a54128fSAndroid Build Coastguard Worker 	io->manager = inode_io_manager;
142*6a54128fSAndroid Build Coastguard Worker 	retval = ext2fs_get_mem(strlen(name)+1, &io->name);
143*6a54128fSAndroid Build Coastguard Worker 	if (retval)
144*6a54128fSAndroid Build Coastguard Worker 		goto cleanup;
145*6a54128fSAndroid Build Coastguard Worker 
146*6a54128fSAndroid Build Coastguard Worker 	strcpy(io->name, name);
147*6a54128fSAndroid Build Coastguard Worker 	io->private_data = data;
148*6a54128fSAndroid Build Coastguard Worker 	io->block_size = 1024;
149*6a54128fSAndroid Build Coastguard Worker 	io->read_error = 0;
150*6a54128fSAndroid Build Coastguard Worker 	io->write_error = 0;
151*6a54128fSAndroid Build Coastguard Worker 	io->refcount = 1;
152*6a54128fSAndroid Build Coastguard Worker 
153*6a54128fSAndroid Build Coastguard Worker 	open_flags = (flags & IO_FLAG_RW) ? EXT2_FILE_WRITE : 0;
154*6a54128fSAndroid Build Coastguard Worker 	retval = ext2fs_file_open2(data->fs, data->ino,
155*6a54128fSAndroid Build Coastguard Worker 				   (data->flags & CHANNEL_HAS_INODE) ?
156*6a54128fSAndroid Build Coastguard Worker 				   &data->inode : 0, open_flags,
157*6a54128fSAndroid Build Coastguard Worker 				   &data->file);
158*6a54128fSAndroid Build Coastguard Worker 	if (retval)
159*6a54128fSAndroid Build Coastguard Worker 		goto cleanup;
160*6a54128fSAndroid Build Coastguard Worker 
161*6a54128fSAndroid Build Coastguard Worker 	*channel = io;
162*6a54128fSAndroid Build Coastguard Worker 	return 0;
163*6a54128fSAndroid Build Coastguard Worker 
164*6a54128fSAndroid Build Coastguard Worker cleanup:
165*6a54128fSAndroid Build Coastguard Worker 	if (io && io->name)
166*6a54128fSAndroid Build Coastguard Worker 		ext2fs_free_mem(&io->name);
167*6a54128fSAndroid Build Coastguard Worker 	if (data)
168*6a54128fSAndroid Build Coastguard Worker 		ext2fs_free_mem(&data);
169*6a54128fSAndroid Build Coastguard Worker 	if (io)
170*6a54128fSAndroid Build Coastguard Worker 		ext2fs_free_mem(&io);
171*6a54128fSAndroid Build Coastguard Worker 	return retval;
172*6a54128fSAndroid Build Coastguard Worker }
173*6a54128fSAndroid Build Coastguard Worker 
inode_close(io_channel channel)174*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_close(io_channel channel)
175*6a54128fSAndroid Build Coastguard Worker {
176*6a54128fSAndroid Build Coastguard Worker 	struct inode_private_data *data;
177*6a54128fSAndroid Build Coastguard Worker 	errcode_t	retval = 0;
178*6a54128fSAndroid Build Coastguard Worker 
179*6a54128fSAndroid Build Coastguard Worker 	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
180*6a54128fSAndroid Build Coastguard Worker 	data = (struct inode_private_data *) channel->private_data;
181*6a54128fSAndroid Build Coastguard Worker 	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_INODE_IO_CHANNEL);
182*6a54128fSAndroid Build Coastguard Worker 
183*6a54128fSAndroid Build Coastguard Worker 	if (--channel->refcount > 0)
184*6a54128fSAndroid Build Coastguard Worker 		return 0;
185*6a54128fSAndroid Build Coastguard Worker 
186*6a54128fSAndroid Build Coastguard Worker 	retval = ext2fs_file_close(data->file);
187*6a54128fSAndroid Build Coastguard Worker 
188*6a54128fSAndroid Build Coastguard Worker 	ext2fs_free_mem(&channel->private_data);
189*6a54128fSAndroid Build Coastguard Worker 	if (channel->name)
190*6a54128fSAndroid Build Coastguard Worker 		ext2fs_free_mem(&channel->name);
191*6a54128fSAndroid Build Coastguard Worker 	ext2fs_free_mem(&channel);
192*6a54128fSAndroid Build Coastguard Worker 	return retval;
193*6a54128fSAndroid Build Coastguard Worker }
194*6a54128fSAndroid Build Coastguard Worker 
inode_set_blksize(io_channel channel,int blksize)195*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_set_blksize(io_channel channel, int blksize)
196*6a54128fSAndroid Build Coastguard Worker {
197*6a54128fSAndroid Build Coastguard Worker 	struct inode_private_data *data;
198*6a54128fSAndroid Build Coastguard Worker 
199*6a54128fSAndroid Build Coastguard Worker 	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
200*6a54128fSAndroid Build Coastguard Worker 	data = (struct inode_private_data *) channel->private_data;
201*6a54128fSAndroid Build Coastguard Worker 	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_INODE_IO_CHANNEL);
202*6a54128fSAndroid Build Coastguard Worker 
203*6a54128fSAndroid Build Coastguard Worker 	channel->block_size = blksize;
204*6a54128fSAndroid Build Coastguard Worker 	return 0;
205*6a54128fSAndroid Build Coastguard Worker }
206*6a54128fSAndroid Build Coastguard Worker 
207*6a54128fSAndroid Build Coastguard Worker 
inode_read_blk64(io_channel channel,unsigned long long block,int count,void * buf)208*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_read_blk64(io_channel channel,
209*6a54128fSAndroid Build Coastguard Worker 				unsigned long long block, int count, void *buf)
210*6a54128fSAndroid Build Coastguard Worker {
211*6a54128fSAndroid Build Coastguard Worker 	struct inode_private_data *data;
212*6a54128fSAndroid Build Coastguard Worker 	errcode_t	retval;
213*6a54128fSAndroid Build Coastguard Worker 
214*6a54128fSAndroid Build Coastguard Worker 	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
215*6a54128fSAndroid Build Coastguard Worker 	data = (struct inode_private_data *) channel->private_data;
216*6a54128fSAndroid Build Coastguard Worker 	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_INODE_IO_CHANNEL);
217*6a54128fSAndroid Build Coastguard Worker 
218*6a54128fSAndroid Build Coastguard Worker 	if ((retval = ext2fs_file_llseek(data->file,
219*6a54128fSAndroid Build Coastguard Worker 				(ext2_off64_t)(block * channel->block_size),
220*6a54128fSAndroid Build Coastguard Worker 				EXT2_SEEK_SET, 0)))
221*6a54128fSAndroid Build Coastguard Worker 		return retval;
222*6a54128fSAndroid Build Coastguard Worker 
223*6a54128fSAndroid Build Coastguard Worker 	count = (count < 0) ? -count : (count * channel->block_size);
224*6a54128fSAndroid Build Coastguard Worker 
225*6a54128fSAndroid Build Coastguard Worker 	return ext2fs_file_read(data->file, buf, count, 0);
226*6a54128fSAndroid Build Coastguard Worker }
227*6a54128fSAndroid Build Coastguard Worker 
inode_read_blk(io_channel channel,unsigned long block,int count,void * buf)228*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_read_blk(io_channel channel, unsigned long block,
229*6a54128fSAndroid Build Coastguard Worker 			       int count, void *buf)
230*6a54128fSAndroid Build Coastguard Worker {
231*6a54128fSAndroid Build Coastguard Worker 	return inode_read_blk64(channel, block, count, buf);
232*6a54128fSAndroid Build Coastguard Worker }
233*6a54128fSAndroid Build Coastguard Worker 
inode_write_blk64(io_channel channel,unsigned long long block,int count,const void * buf)234*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_write_blk64(io_channel channel,
235*6a54128fSAndroid Build Coastguard Worker 				unsigned long long block, int count, const void *buf)
236*6a54128fSAndroid Build Coastguard Worker {
237*6a54128fSAndroid Build Coastguard Worker 	struct inode_private_data *data;
238*6a54128fSAndroid Build Coastguard Worker 	errcode_t	retval;
239*6a54128fSAndroid Build Coastguard Worker 
240*6a54128fSAndroid Build Coastguard Worker 	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
241*6a54128fSAndroid Build Coastguard Worker 	data = (struct inode_private_data *) channel->private_data;
242*6a54128fSAndroid Build Coastguard Worker 	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_INODE_IO_CHANNEL);
243*6a54128fSAndroid Build Coastguard Worker 
244*6a54128fSAndroid Build Coastguard Worker 	if ((retval = ext2fs_file_llseek(data->file,
245*6a54128fSAndroid Build Coastguard Worker 				(ext2_off64_t) (block * channel->block_size),
246*6a54128fSAndroid Build Coastguard Worker 				EXT2_SEEK_SET, 0)))
247*6a54128fSAndroid Build Coastguard Worker 		return retval;
248*6a54128fSAndroid Build Coastguard Worker 
249*6a54128fSAndroid Build Coastguard Worker 	count = (count < 0) ? -count : (count * channel->block_size);
250*6a54128fSAndroid Build Coastguard Worker 
251*6a54128fSAndroid Build Coastguard Worker 	return ext2fs_file_write(data->file, buf, count, 0);
252*6a54128fSAndroid Build Coastguard Worker }
253*6a54128fSAndroid Build Coastguard Worker 
inode_write_blk(io_channel channel,unsigned long block,int count,const void * buf)254*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_write_blk(io_channel channel, unsigned long block,
255*6a54128fSAndroid Build Coastguard Worker 				int count, const void *buf)
256*6a54128fSAndroid Build Coastguard Worker {
257*6a54128fSAndroid Build Coastguard Worker 	return inode_write_blk64(channel, block, count, buf);
258*6a54128fSAndroid Build Coastguard Worker }
259*6a54128fSAndroid Build Coastguard Worker 
inode_write_byte(io_channel channel,unsigned long offset,int size,const void * buf)260*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_write_byte(io_channel channel, unsigned long offset,
261*6a54128fSAndroid Build Coastguard Worker 				 int size, const void *buf)
262*6a54128fSAndroid Build Coastguard Worker {
263*6a54128fSAndroid Build Coastguard Worker 	struct inode_private_data *data;
264*6a54128fSAndroid Build Coastguard Worker 	errcode_t	retval = 0;
265*6a54128fSAndroid Build Coastguard Worker 
266*6a54128fSAndroid Build Coastguard Worker 	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
267*6a54128fSAndroid Build Coastguard Worker 	data = (struct inode_private_data *) channel->private_data;
268*6a54128fSAndroid Build Coastguard Worker 	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_INODE_IO_CHANNEL);
269*6a54128fSAndroid Build Coastguard Worker 
270*6a54128fSAndroid Build Coastguard Worker 	if ((retval = ext2fs_file_lseek(data->file, offset,
271*6a54128fSAndroid Build Coastguard Worker 					EXT2_SEEK_SET, 0)))
272*6a54128fSAndroid Build Coastguard Worker 		return retval;
273*6a54128fSAndroid Build Coastguard Worker 
274*6a54128fSAndroid Build Coastguard Worker 	return ext2fs_file_write(data->file, buf, size, 0);
275*6a54128fSAndroid Build Coastguard Worker }
276*6a54128fSAndroid Build Coastguard Worker 
277*6a54128fSAndroid Build Coastguard Worker /*
278*6a54128fSAndroid Build Coastguard Worker  * Flush data buffers to disk.
279*6a54128fSAndroid Build Coastguard Worker  */
inode_flush(io_channel channel)280*6a54128fSAndroid Build Coastguard Worker static errcode_t inode_flush(io_channel channel)
281*6a54128fSAndroid Build Coastguard Worker {
282*6a54128fSAndroid Build Coastguard Worker 	struct inode_private_data *data;
283*6a54128fSAndroid Build Coastguard Worker 
284*6a54128fSAndroid Build Coastguard Worker 	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
285*6a54128fSAndroid Build Coastguard Worker 	data = (struct inode_private_data *) channel->private_data;
286*6a54128fSAndroid Build Coastguard Worker 	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_INODE_IO_CHANNEL);
287*6a54128fSAndroid Build Coastguard Worker 
288*6a54128fSAndroid Build Coastguard Worker 	return ext2fs_file_flush(data->file);
289*6a54128fSAndroid Build Coastguard Worker }
290*6a54128fSAndroid Build Coastguard Worker 
291