blob: 78a1d1cbab8cf2088d3ee1b8679d0f3851b73cc3 [file] [log] [blame]
Theodore Ts'o3839e651997-04-26 13:21:57 +00001/*
Theodore Ts'offf45482003-04-13 00:44:19 -04002 * unix_io.c --- This is the Unix (well, really POSIX) implementation
3 * of the I/O manager.
Theodore Ts'o3839e651997-04-26 13:21:57 +00004 *
5 * Implements a one-block write-through cache.
6 *
Theodore Ts'oefc6f622008-08-27 23:07:54 -04007 * Includes support for Windows NT support under Cygwin.
Theodore Ts'offf45482003-04-13 00:44:19 -04008 *
Theodore Ts'o64e1b272002-02-23 18:50:32 -05009 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
10 * 2002 by Theodore Ts'o.
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000011 *
12 * %Begin-Header%
Theodore Ts'o543547a2010-05-17 21:31:56 -040013 * This file may be redistributed under the terms of the GNU Library
14 * General Public License, version 2.
Theodore Ts'o19c78dc1997-04-29 16:17:09 +000015 * %End-Header%
Theodore Ts'o3839e651997-04-26 13:21:57 +000016 */
17
Theodore Ts'odc5f68c2000-05-25 23:31:54 +000018#define _LARGEFILE_SOURCE
19#define _LARGEFILE64_SOURCE
20
Theodore Ts'o3839e651997-04-26 13:21:57 +000021#include <stdio.h>
22#include <string.h>
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +000023#if HAVE_UNISTD_H
Theodore Ts'o3839e651997-04-26 13:21:57 +000024#include <unistd.h>
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +000025#endif
Theodore Ts'oc4e749a1998-02-20 05:33:14 +000026#if HAVE_ERRNO_H
27#include <errno.h>
28#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +000029#include <fcntl.h>
30#include <time.h>
Theodore Ts'of154d2f2002-07-14 08:33:32 -040031#ifdef __linux__
32#include <sys/utsname.h>
33#endif
Eric Sandeen7ed7a4b2008-10-10 17:17:43 -050034#ifdef HAVE_SYS_IOCTL_H
35#include <sys/ioctl.h>
36#endif
37#ifdef HAVE_SYS_MOUNT_H
38#include <sys/mount.h>
39#endif
Theodore Ts'o1d2ff461997-10-19 23:00:21 +000040#if HAVE_SYS_STAT_H
Theodore Ts'o3839e651997-04-26 13:21:57 +000041#include <sys/stat.h>
Theodore Ts'o1d2ff461997-10-19 23:00:21 +000042#endif
43#if HAVE_SYS_TYPES_H
Theodore Ts'o3839e651997-04-26 13:21:57 +000044#include <sys/types.h>
Theodore Ts'o1d2ff461997-10-19 23:00:21 +000045#endif
Theodore Ts'offf45482003-04-13 00:44:19 -040046#if HAVE_SYS_RESOURCE_H
Theodore Ts'o8880e752001-11-26 21:05:36 -050047#include <sys/resource.h>
Theodore Ts'offf45482003-04-13 00:44:19 -040048#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +000049
Eric Sandeen7ed7a4b2008-10-10 17:17:43 -050050#if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
51#define BLKROGET _IO(0x12, 94) /* Get read-only status (0 = read_write). */
52#endif
53
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +000054#include "ext2_fs.h"
Theodore Ts'o7b4e4531997-10-26 03:41:24 +000055#include "ext2fs.h"
Theodore Ts'o3839e651997-04-26 13:21:57 +000056
Theodore Ts'of3db3561997-04-26 13:34:30 +000057/*
58 * For checking structure magic numbers...
59 */
60
61#define EXT2_CHECK_MAGIC(struct, code) \
62 if ((struct)->magic != (code)) return (code)
Theodore Ts'oadfc8c62000-10-18 19:22:24 +000063
64struct unix_cache {
65 char *buf;
66 unsigned long block;
67 int access_time;
Matthias Andree83e692e2004-03-30 04:17:14 +020068 unsigned dirty:1;
69 unsigned in_use:1;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +000070};
71
72#define CACHE_SIZE 8
Theodore Ts'o82c46602002-11-09 14:56:17 -050073#define WRITE_DIRECT_SIZE 4 /* Must be smaller than CACHE_SIZE */
74#define READ_DIRECT_SIZE 4 /* Should be smaller than CACHE_SIZE */
Theodore Ts'oadfc8c62000-10-18 19:22:24 +000075
Theodore Ts'o3839e651997-04-26 13:21:57 +000076struct unix_private_data {
Theodore Ts'of3db3561997-04-26 13:34:30 +000077 int magic;
Theodore Ts'o3839e651997-04-26 13:21:57 +000078 int dev;
79 int flags;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +000080 int access_time;
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -050081 ext2_loff_t offset;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +000082 struct unix_cache cache[CACHE_SIZE];
Theodore Ts'o6d96b002007-08-03 20:07:09 -040083 struct struct_io_stats io_stats;
Theodore Ts'o3839e651997-04-26 13:21:57 +000084};
85
86static errcode_t unix_open(const char *name, int flags, io_channel *channel);
87static errcode_t unix_close(io_channel channel);
88static errcode_t unix_set_blksize(io_channel channel, int blksize);
89static errcode_t unix_read_blk(io_channel channel, unsigned long block,
90 int count, void *data);
91static errcode_t unix_write_blk(io_channel channel, unsigned long block,
92 int count, const void *data);
93static errcode_t unix_flush(io_channel channel);
Theodore Ts'oc180ac82000-10-26 20:24:43 +000094static errcode_t unix_write_byte(io_channel channel, unsigned long offset,
95 int size, const void *data);
Theodore Ts'oefc6f622008-08-27 23:07:54 -040096static errcode_t unix_set_option(io_channel channel, const char *option,
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -050097 const char *arg);
Theodore Ts'o6d96b002007-08-03 20:07:09 -040098static errcode_t unix_get_stats(io_channel channel, io_stats *stats)
99;
Theodore Ts'o23b7c8b2003-01-22 18:30:01 -0500100static void reuse_cache(io_channel channel, struct unix_private_data *data,
Jose R. Santos59ecd322008-03-03 10:41:24 -0600101 struct unix_cache *cache, unsigned long long block);
102static errcode_t unix_read_blk64(io_channel channel, unsigned long long block,
103 int count, void *data);
104static errcode_t unix_write_blk64(io_channel channel, unsigned long long block,
105 int count, const void *data);
Theodore Ts'o23b7c8b2003-01-22 18:30:01 -0500106
Matthias Andree289e0552004-03-30 03:57:41 +0200107/* __FreeBSD_kernel__ is defined by GNU/kFreeBSD - the FreeBSD kernel
108 * does not know buffered block devices - everything is raw. */
109#if defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
Matthias Andreeb34cbdd2003-12-28 18:21:26 +0100110#define NEED_BOUNCE_BUFFER
111#else
112#undef NEED_BOUNCE_BUFFER
113#endif
114
Theodore Ts'of3db3561997-04-26 13:34:30 +0000115static struct struct_io_manager struct_unix_manager = {
116 EXT2_ET_MAGIC_IO_MANAGER,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000117 "Unix I/O Manager",
118 unix_open,
119 unix_close,
120 unix_set_blksize,
121 unix_read_blk,
122 unix_write_blk,
Theodore Ts'oc180ac82000-10-26 20:24:43 +0000123 unix_flush,
Matthias Andreeb34cbdd2003-12-28 18:21:26 +0100124#ifdef NEED_BOUNCE_BUFFER
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500125 0,
Theodore Ts'offf45482003-04-13 00:44:19 -0400126#else
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500127 unix_write_byte,
Theodore Ts'offf45482003-04-13 00:44:19 -0400128#endif
Theodore Ts'o6d96b002007-08-03 20:07:09 -0400129 unix_set_option,
130 unix_get_stats,
Jose R. Santos59ecd322008-03-03 10:41:24 -0600131 unix_read_blk64,
132 unix_write_blk64,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000133};
134
135io_manager unix_io_manager = &struct_unix_manager;
136
Theodore Ts'o6d96b002007-08-03 20:07:09 -0400137static errcode_t unix_get_stats(io_channel channel, io_stats *stats)
138{
139 errcode_t retval = 0;
140
141 struct unix_private_data *data;
142
143 EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
144 data = (struct unix_private_data *) channel->private_data;
145 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
146
147 if (stats)
148 *stats = &data->io_stats;
149
150 return retval;
151}
152
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000153/*
154 * Here are the raw I/O functions
155 */
Matthias Andreeb34cbdd2003-12-28 18:21:26 +0100156#ifndef NEED_BOUNCE_BUFFER
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000157static errcode_t raw_read_blk(io_channel channel,
158 struct unix_private_data *data,
Jose R. Santos59ecd322008-03-03 10:41:24 -0600159 unsigned long long block,
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000160 int count, void *buf)
161{
162 errcode_t retval;
Theodore Ts'o54434922003-12-07 01:28:50 -0500163 ssize_t size;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000164 ext2_loff_t location;
165 int actual = 0;
166
167 size = (count < 0) ? -count : count * channel->block_size;
Theodore Ts'o6d96b002007-08-03 20:07:09 -0400168 data->io_stats.bytes_read += size;
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500169 location = ((ext2_loff_t) block * channel->block_size) + data->offset;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000170 if (ext2fs_llseek(data->dev, location, SEEK_SET) != location) {
171 retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
172 goto error_out;
173 }
174 actual = read(data->dev, buf, size);
175 if (actual != size) {
176 if (actual < 0)
177 actual = 0;
178 retval = EXT2_ET_SHORT_READ;
179 goto error_out;
180 }
181 return 0;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400182
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000183error_out:
184 memset((char *) buf+actual, 0, size-actual);
185 if (channel->read_error)
186 retval = (channel->read_error)(channel, block, count, buf,
187 size, actual, retval);
188 return retval;
189}
Matthias Andreeb34cbdd2003-12-28 18:21:26 +0100190#else /* NEED_BOUNCE_BUFFER */
Theodore Ts'offf45482003-04-13 00:44:19 -0400191/*
Matthias Andreeb34cbdd2003-12-28 18:21:26 +0100192 * Windows and FreeBSD block devices only allow sector alignment IO in offset and size
Theodore Ts'offf45482003-04-13 00:44:19 -0400193 */
194static errcode_t raw_read_blk(io_channel channel,
195 struct unix_private_data *data,
196 unsigned long block,
197 int count, void *buf)
198{
199 errcode_t retval;
200 size_t size, alignsize, fragment;
201 ext2_loff_t location;
202 int total = 0, actual;
203#define BLOCKALIGN 512
204 char sector[BLOCKALIGN];
205
206 size = (count < 0) ? -count : count * channel->block_size;
Theodore Ts'o6d96b002007-08-03 20:07:09 -0400207 data->io_stats.bytes_read += size;
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500208 location = ((ext2_loff_t) block * channel->block_size) + data->offset;
Theodore Ts'offf45482003-04-13 00:44:19 -0400209#ifdef DEBUG
Eric Sandeend0ff90d2006-09-12 14:56:15 -0400210 printf("count=%d, size=%d, block=%lu, blk_size=%d, location=%llx\n",
211 count, size, block, channel->block_size, (long long)location);
Theodore Ts'offf45482003-04-13 00:44:19 -0400212#endif
213 if (ext2fs_llseek(data->dev, location, SEEK_SET) != location) {
214 retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
215 goto error_out;
216 }
217 fragment = size % BLOCKALIGN;
218 alignsize = size - fragment;
219 if (alignsize) {
220 actual = read(data->dev, buf, alignsize);
221 if (actual != alignsize)
222 goto short_read;
223 }
224 if (fragment) {
225 actual = read(data->dev, sector, BLOCKALIGN);
226 if (actual != BLOCKALIGN)
227 goto short_read;
228 memcpy(buf+alignsize, sector, fragment);
229 }
230 return 0;
231
232short_read:
233 if (actual>0)
234 total += actual;
235 retval = EXT2_ET_SHORT_READ;
236
237error_out:
238 memset((char *) buf+total, 0, size-actual);
239 if (channel->read_error)
240 retval = (channel->read_error)(channel, block, count, buf,
241 size, actual, retval);
242 return retval;
243}
244#endif
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000245
246static errcode_t raw_write_blk(io_channel channel,
247 struct unix_private_data *data,
Jose R. Santos59ecd322008-03-03 10:41:24 -0600248 unsigned long long block,
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000249 int count, const void *buf)
250{
Theodore Ts'o54434922003-12-07 01:28:50 -0500251 ssize_t size;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000252 ext2_loff_t location;
253 int actual = 0;
254 errcode_t retval;
255
256 if (count == 1)
257 size = channel->block_size;
258 else {
259 if (count < 0)
260 size = -count;
261 else
262 size = count * channel->block_size;
263 }
Theodore Ts'o6d96b002007-08-03 20:07:09 -0400264 data->io_stats.bytes_written += size;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000265
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500266 location = ((ext2_loff_t) block * channel->block_size) + data->offset;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000267 if (ext2fs_llseek(data->dev, location, SEEK_SET) != location) {
268 retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
269 goto error_out;
270 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400271
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000272 actual = write(data->dev, buf, size);
273 if (actual != size) {
274 retval = EXT2_ET_SHORT_WRITE;
275 goto error_out;
276 }
277 return 0;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400278
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000279error_out:
280 if (channel->write_error)
281 retval = (channel->write_error)(channel, block, count, buf,
282 size, actual, retval);
283 return retval;
284}
285
286
287/*
288 * Here we implement the cache functions
289 */
290
291/* Allocate the cache buffers */
292static errcode_t alloc_cache(io_channel channel,
293 struct unix_private_data *data)
294{
295 errcode_t retval;
296 struct unix_cache *cache;
297 int i;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400298
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000299 data->access_time = 0;
300 for (i=0, cache = data->cache; i < CACHE_SIZE; i++, cache++) {
301 cache->block = 0;
302 cache->access_time = 0;
303 cache->dirty = 0;
304 cache->in_use = 0;
Theodore Ts'ofaafdb72010-09-23 13:06:31 -0400305 if (cache->buf)
306 ext2fs_free_mem(&cache->buf);
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000307 if ((retval = ext2fs_get_mem(channel->block_size,
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400308 &cache->buf)))
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000309 return retval;
310 }
311 return 0;
312}
313
314/* Free the cache buffers */
Theodore Ts'o54434922003-12-07 01:28:50 -0500315static void free_cache(struct unix_private_data *data)
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000316{
317 struct unix_cache *cache;
318 int i;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400319
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000320 data->access_time = 0;
321 for (i=0, cache = data->cache; i < CACHE_SIZE; i++, cache++) {
322 cache->block = 0;
323 cache->access_time = 0;
324 cache->dirty = 0;
325 cache->in_use = 0;
326 if (cache->buf)
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400327 ext2fs_free_mem(&cache->buf);
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000328 cache->buf = 0;
329 }
330}
331
Theodore Ts'ob8a95312003-05-13 23:41:29 -0400332#ifndef NO_IO_CACHE
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000333/*
Theodore Ts'o82c46602002-11-09 14:56:17 -0500334 * Try to find a block in the cache. If the block is not found, and
335 * eldest is a non-zero pointer, then fill in eldest with the cache
336 * entry to that should be reused.
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000337 */
Theodore Ts'o54434922003-12-07 01:28:50 -0500338static struct unix_cache *find_cached_block(struct unix_private_data *data,
Jose R. Santos59ecd322008-03-03 10:41:24 -0600339 unsigned long long block,
Theodore Ts'o82c46602002-11-09 14:56:17 -0500340 struct unix_cache **eldest)
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000341{
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000342 struct unix_cache *cache, *unused_cache, *oldest_cache;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000343 int i;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400344
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000345 unused_cache = oldest_cache = 0;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000346 for (i=0, cache = data->cache; i < CACHE_SIZE; i++, cache++) {
347 if (!cache->in_use) {
Theodore Ts'o82c46602002-11-09 14:56:17 -0500348 if (!unused_cache)
349 unused_cache = cache;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000350 continue;
351 }
352 if (cache->block == block) {
353 cache->access_time = ++data->access_time;
354 return cache;
355 }
356 if (!oldest_cache ||
357 (cache->access_time < oldest_cache->access_time))
358 oldest_cache = cache;
359 }
Theodore Ts'o82c46602002-11-09 14:56:17 -0500360 if (eldest)
361 *eldest = (unused_cache) ? unused_cache : oldest_cache;
362 return 0;
363}
364
365/*
366 * Reuse a particular cache entry for another block.
367 */
Theodore Ts'o23b7c8b2003-01-22 18:30:01 -0500368static void reuse_cache(io_channel channel, struct unix_private_data *data,
Jose R. Santos59ecd322008-03-03 10:41:24 -0600369 struct unix_cache *cache, unsigned long long block)
Theodore Ts'o82c46602002-11-09 14:56:17 -0500370{
371 if (cache->dirty && cache->in_use)
372 raw_write_blk(channel, data, cache->block, 1, cache->buf);
373
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000374 cache->in_use = 1;
Theodore Ts'o1d47dfb2002-11-09 10:33:49 -0500375 cache->dirty = 0;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000376 cache->block = block;
377 cache->access_time = ++data->access_time;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000378}
379
380/*
381 * Flush all of the blocks in the cache
382 */
383static errcode_t flush_cached_blocks(io_channel channel,
384 struct unix_private_data *data,
385 int invalidate)
386
387{
388 struct unix_cache *cache;
389 errcode_t retval, retval2;
390 int i;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400391
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000392 retval2 = 0;
393 for (i=0, cache = data->cache; i < CACHE_SIZE; i++, cache++) {
394 if (!cache->in_use)
395 continue;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400396
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000397 if (invalidate)
398 cache->in_use = 0;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400399
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000400 if (!cache->dirty)
401 continue;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400402
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000403 retval = raw_write_blk(channel, data,
404 cache->block, 1, cache->buf);
405 if (retval)
406 retval2 = retval;
407 else
408 cache->dirty = 0;
409 }
410 return retval2;
411}
Theodore Ts'ob8a95312003-05-13 23:41:29 -0400412#endif /* NO_IO_CACHE */
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000413
Theodore Ts'o3839e651997-04-26 13:21:57 +0000414static errcode_t unix_open(const char *name, int flags, io_channel *channel)
415{
416 io_channel io = NULL;
417 struct unix_private_data *data = NULL;
418 errcode_t retval;
Theodore Ts'odc5f68c2000-05-25 23:31:54 +0000419 int open_flags;
Theodore Ts'o8880e752001-11-26 21:05:36 -0500420 struct stat st;
Theodore Ts'of154d2f2002-07-14 08:33:32 -0400421#ifdef __linux__
422 struct utsname ut;
423#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +0000424
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000425 if (name == 0)
426 return EXT2_ET_BAD_DEVICE_NAME;
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400427 retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io);
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000428 if (retval)
429 return retval;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000430 memset(io, 0, sizeof(struct struct_io_channel));
431 io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400432 retval = ext2fs_get_mem(sizeof(struct unix_private_data), &data);
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000433 if (retval)
Theodore Ts'o3839e651997-04-26 13:21:57 +0000434 goto cleanup;
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000435
Theodore Ts'o3839e651997-04-26 13:21:57 +0000436 io->manager = unix_io_manager;
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400437 retval = ext2fs_get_mem(strlen(name)+1, &io->name);
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000438 if (retval)
Theodore Ts'o3839e651997-04-26 13:21:57 +0000439 goto cleanup;
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000440
Theodore Ts'o3839e651997-04-26 13:21:57 +0000441 strcpy(io->name, name);
442 io->private_data = data;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000443 io->block_size = 1024;
444 io->read_error = 0;
445 io->write_error = 0;
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000446 io->refcount = 1;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000447
448 memset(data, 0, sizeof(struct unix_private_data));
Theodore Ts'of3db3561997-04-26 13:34:30 +0000449 data->magic = EXT2_ET_MAGIC_UNIX_IO_CHANNEL;
Theodore Ts'o6d96b002007-08-03 20:07:09 -0400450 data->io_stats.num_fields = 2;
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000451
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000452 if ((retval = alloc_cache(io, data)))
453 goto cleanup;
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500454
Theodore Ts'odc5f68c2000-05-25 23:31:54 +0000455 open_flags = (flags & IO_FLAG_RW) ? O_RDWR : O_RDONLY;
Theodore Ts'ofa6c6532006-03-18 18:57:44 -0500456 if (flags & IO_FLAG_EXCLUSIVE)
457 open_flags |= O_EXCL;
Theodore Ts'odc5f68c2000-05-25 23:31:54 +0000458#ifdef HAVE_OPEN64
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500459 data->dev = open64(io->name, open_flags);
Theodore Ts'odc5f68c2000-05-25 23:31:54 +0000460#else
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500461 data->dev = open(io->name, open_flags);
Theodore Ts'odc5f68c2000-05-25 23:31:54 +0000462#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +0000463 if (data->dev < 0) {
464 retval = errno;
465 goto cleanup;
466 }
Theodore Ts'o64e1b272002-02-23 18:50:32 -0500467
Eric Sandeen7ed7a4b2008-10-10 17:17:43 -0500468#ifdef BLKROGET
469 if (flags & IO_FLAG_RW) {
470 int error;
471 int readonly = 0;
472
473 /* Is the block device actually writable? */
474 error = ioctl(data->dev, BLKROGET, &readonly);
475 if (!error && readonly) {
476 close(data->dev);
477 retval = EPERM;
478 goto cleanup;
479 }
480 }
481#endif
482
Theodore Ts'o64e1b272002-02-23 18:50:32 -0500483#ifdef __linux__
484#undef RLIM_INFINITY
485#if (defined(__alpha__) || ((defined(__sparc__) || defined(__mips__)) && (SIZEOF_LONG == 4)))
486#define RLIM_INFINITY ((unsigned long)(~0UL>>1))
487#else
488#define RLIM_INFINITY (~0UL)
489#endif
Theodore Ts'o8880e752001-11-26 21:05:36 -0500490 /*
Theodore Ts'of154d2f2002-07-14 08:33:32 -0400491 * Work around a bug in 2.4.10-2.4.18 kernels where writes to
492 * block devices are wrongly getting hit by the filesize
493 * limit. This workaround isn't perfect, since it won't work
494 * if glibc wasn't built against 2.2 header files. (Sigh.)
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400495 *
Theodore Ts'o8880e752001-11-26 21:05:36 -0500496 */
Theodore Ts'of154d2f2002-07-14 08:33:32 -0400497 if ((flags & IO_FLAG_RW) &&
498 (uname(&ut) == 0) &&
499 ((ut.release[0] == '2') && (ut.release[1] == '.') &&
500 (ut.release[2] == '4') && (ut.release[3] == '.') &&
501 (ut.release[4] == '1') && (ut.release[5] >= '0') &&
502 (ut.release[5] < '8')) &&
Theodore Ts'o8880e752001-11-26 21:05:36 -0500503 (fstat(data->dev, &st) == 0) &&
504 (S_ISBLK(st.st_mode))) {
505 struct rlimit rlim;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400506
Theodore Ts'o64e1b272002-02-23 18:50:32 -0500507 rlim.rlim_cur = rlim.rlim_max = (unsigned long) RLIM_INFINITY;
Theodore Ts'o8880e752001-11-26 21:05:36 -0500508 setrlimit(RLIMIT_FSIZE, &rlim);
509 getrlimit(RLIMIT_FSIZE, &rlim);
Theodore Ts'obd278802001-12-03 05:47:32 +0100510 if (((unsigned long) rlim.rlim_cur) <
511 ((unsigned long) rlim.rlim_max)) {
Theodore Ts'o8880e752001-11-26 21:05:36 -0500512 rlim.rlim_cur = rlim.rlim_max;
513 setrlimit(RLIMIT_FSIZE, &rlim);
514 }
515 }
Theodore Ts'o64e1b272002-02-23 18:50:32 -0500516#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +0000517 *channel = io;
518 return 0;
519
520cleanup:
Theodore Ts'o3839e651997-04-26 13:21:57 +0000521 if (data) {
Theodore Ts'o54434922003-12-07 01:28:50 -0500522 free_cache(data);
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400523 ext2fs_free_mem(&data);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000524 }
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000525 if (io)
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400526 ext2fs_free_mem(&io);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000527 return retval;
528}
529
530static errcode_t unix_close(io_channel channel)
531{
532 struct unix_private_data *data;
533 errcode_t retval = 0;
534
Theodore Ts'of3db3561997-04-26 13:34:30 +0000535 EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000536 data = (struct unix_private_data *) channel->private_data;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000537 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
Theodore Ts'oa29f4d31997-04-29 21:26:48 +0000538
539 if (--channel->refcount > 0)
540 return 0;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000541
Theodore Ts'ob8a95312003-05-13 23:41:29 -0400542#ifndef NO_IO_CACHE
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000543 retval = flush_cached_blocks(channel, data, 0);
Theodore Ts'ob8a95312003-05-13 23:41:29 -0400544#endif
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000545
Theodore Ts'o3839e651997-04-26 13:21:57 +0000546 if (close(data->dev) < 0)
547 retval = errno;
Theodore Ts'o54434922003-12-07 01:28:50 -0500548 free_cache(data);
Theodore Ts'of12e2852002-02-20 01:06:25 -0500549
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400550 ext2fs_free_mem(&channel->private_data);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000551 if (channel->name)
Theodore Ts'oc4e3d3f2003-08-01 09:41:07 -0400552 ext2fs_free_mem(&channel->name);
553 ext2fs_free_mem(&channel);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000554 return retval;
555}
556
557static errcode_t unix_set_blksize(io_channel channel, int blksize)
558{
559 struct unix_private_data *data;
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000560 errcode_t retval;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000561
Theodore Ts'of3db3561997-04-26 13:34:30 +0000562 EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000563 data = (struct unix_private_data *) channel->private_data;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000564 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
565
Theodore Ts'o3839e651997-04-26 13:21:57 +0000566 if (channel->block_size != blksize) {
Theodore Ts'ob8a95312003-05-13 23:41:29 -0400567#ifndef NO_IO_CACHE
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000568 if ((retval = flush_cached_blocks(channel, data, 0)))
Theodore Ts'o7b4e4531997-10-26 03:41:24 +0000569 return retval;
Theodore Ts'ob8a95312003-05-13 23:41:29 -0400570#endif
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400571
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000572 channel->block_size = blksize;
Theodore Ts'o54434922003-12-07 01:28:50 -0500573 free_cache(data);
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000574 if ((retval = alloc_cache(channel, data)))
575 return retval;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000576 }
577 return 0;
578}
579
580
Jose R. Santos59ecd322008-03-03 10:41:24 -0600581static errcode_t unix_read_blk64(io_channel channel, unsigned long long block,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000582 int count, void *buf)
583{
584 struct unix_private_data *data;
Theodore Ts'o82c46602002-11-09 14:56:17 -0500585 struct unix_cache *cache, *reuse[READ_DIRECT_SIZE];
Theodore Ts'o3839e651997-04-26 13:21:57 +0000586 errcode_t retval;
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000587 char *cp;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000588 int i, j;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000589
Theodore Ts'of3db3561997-04-26 13:34:30 +0000590 EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000591 data = (struct unix_private_data *) channel->private_data;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000592 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000593
Theodore Ts'ob8a95312003-05-13 23:41:29 -0400594#ifdef NO_IO_CACHE
595 return raw_read_blk(channel, data, block, count, buf);
596#else
Theodore Ts'o3839e651997-04-26 13:21:57 +0000597 /*
Theodore Ts'o82c46602002-11-09 14:56:17 -0500598 * If we're doing an odd-sized read or a very large read,
599 * flush out the cache and then do a direct read.
Theodore Ts'o3839e651997-04-26 13:21:57 +0000600 */
Theodore Ts'o82c46602002-11-09 14:56:17 -0500601 if (count < 0 || count > WRITE_DIRECT_SIZE) {
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000602 if ((retval = flush_cached_blocks(channel, data, 0)))
603 return retval;
604 return raw_read_blk(channel, data, block, count, buf);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000605 }
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000606
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000607 cp = buf;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000608 while (count > 0) {
609 /* If it's in the cache, use it! */
Theodore Ts'o54434922003-12-07 01:28:50 -0500610 if ((cache = find_cached_block(data, block, &reuse[0]))) {
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000611#ifdef DEBUG
Eric Sandeend0ff90d2006-09-12 14:56:15 -0400612 printf("Using cached block %lu\n", block);
Theodore Ts'of3db3561997-04-26 13:34:30 +0000613#endif
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000614 memcpy(cp, cache->buf, channel->block_size);
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000615 count--;
616 block++;
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000617 cp += channel->block_size;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000618 continue;
619 }
620 /*
621 * Find the number of uncached blocks so we can do a
622 * single read request
623 */
624 for (i=1; i < count; i++)
Theodore Ts'o54434922003-12-07 01:28:50 -0500625 if (find_cached_block(data, block+i, &reuse[i]))
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000626 break;
627#ifdef DEBUG
Eric Sandeend0ff90d2006-09-12 14:56:15 -0400628 printf("Reading %d blocks starting at %lu\n", i, block);
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000629#endif
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000630 if ((retval = raw_read_blk(channel, data, block, i, cp)))
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000631 return retval;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400632
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000633 /* Save the results in the cache */
634 for (j=0; j < i; j++) {
635 count--;
Theodore Ts'o82c46602002-11-09 14:56:17 -0500636 cache = reuse[j];
637 reuse_cache(channel, data, cache, block++);
638 memcpy(cache->buf, cp, channel->block_size);
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000639 cp += channel->block_size;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000640 }
Theodore Ts'o3839e651997-04-26 13:21:57 +0000641 }
642 return 0;
Theodore Ts'ob8a95312003-05-13 23:41:29 -0400643#endif /* NO_IO_CACHE */
Theodore Ts'o3839e651997-04-26 13:21:57 +0000644}
645
Jose R. Santos59ecd322008-03-03 10:41:24 -0600646static errcode_t unix_read_blk(io_channel channel, unsigned long block,
647 int count, void *buf)
648{
649 return unix_read_blk64(channel, block, count, buf);
650}
651
652static errcode_t unix_write_blk64(io_channel channel, unsigned long long block,
Theodore Ts'o3839e651997-04-26 13:21:57 +0000653 int count, const void *buf)
654{
655 struct unix_private_data *data;
Theodore Ts'o82c46602002-11-09 14:56:17 -0500656 struct unix_cache *cache, *reuse;
Theodore Ts'o23b7c8b2003-01-22 18:30:01 -0500657 errcode_t retval = 0;
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000658 const char *cp;
659 int writethrough;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000660
Theodore Ts'of3db3561997-04-26 13:34:30 +0000661 EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000662 data = (struct unix_private_data *) channel->private_data;
Theodore Ts'of3db3561997-04-26 13:34:30 +0000663 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000664
Theodore Ts'ob8a95312003-05-13 23:41:29 -0400665#ifdef NO_IO_CACHE
666 return raw_write_blk(channel, data, block, count, buf);
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400667#else
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000668 /*
669 * If we're doing an odd-sized write or a very large write,
670 * flush out the cache completely and then do a direct write.
671 */
Theodore Ts'o82c46602002-11-09 14:56:17 -0500672 if (count < 0 || count > WRITE_DIRECT_SIZE) {
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000673 if ((retval = flush_cached_blocks(channel, data, 1)))
674 return retval;
675 return raw_write_blk(channel, data, block, count, buf);
Theodore Ts'o3839e651997-04-26 13:21:57 +0000676 }
677
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000678 /*
679 * For a moderate-sized multi-block write, first force a write
680 * if we're in write-through cache mode, and then fill the
681 * cache with the blocks.
682 */
683 writethrough = channel->flags & CHANNEL_FLAGS_WRITETHROUGH;
684 if (writethrough)
685 retval = raw_write_blk(channel, data, block, count, buf);
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400686
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000687 cp = buf;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000688 while (count > 0) {
Theodore Ts'o54434922003-12-07 01:28:50 -0500689 cache = find_cached_block(data, block, &reuse);
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000690 if (!cache) {
Theodore Ts'o82c46602002-11-09 14:56:17 -0500691 cache = reuse;
692 reuse_cache(channel, data, cache, block);
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000693 }
Theodore Ts'o82c46602002-11-09 14:56:17 -0500694 memcpy(cache->buf, cp, channel->block_size);
695 cache->dirty = !writethrough;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000696 count--;
697 block++;
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000698 cp += channel->block_size;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000699 }
Theodore Ts'o3839e651997-04-26 13:21:57 +0000700 return retval;
Theodore Ts'ob8a95312003-05-13 23:41:29 -0400701#endif /* NO_IO_CACHE */
Theodore Ts'o3839e651997-04-26 13:21:57 +0000702}
703
Jose R. Santos59ecd322008-03-03 10:41:24 -0600704static errcode_t unix_write_blk(io_channel channel, unsigned long block,
705 int count, const void *buf)
706{
707 return unix_write_blk64(channel, block, count, buf);
708}
709
Theodore Ts'oc180ac82000-10-26 20:24:43 +0000710static errcode_t unix_write_byte(io_channel channel, unsigned long offset,
711 int size, const void *buf)
712{
713 struct unix_private_data *data;
Theodore Ts'o31dbecd2001-01-11 04:54:39 +0000714 errcode_t retval = 0;
Theodore Ts'o54434922003-12-07 01:28:50 -0500715 ssize_t actual;
Theodore Ts'oc180ac82000-10-26 20:24:43 +0000716
717 EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
718 data = (struct unix_private_data *) channel->private_data;
719 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
720
Theodore Ts'ob8a95312003-05-13 23:41:29 -0400721#ifndef NO_IO_CACHE
Theodore Ts'oc180ac82000-10-26 20:24:43 +0000722 /*
723 * Flush out the cache completely
724 */
725 if ((retval = flush_cached_blocks(channel, data, 1)))
726 return retval;
Theodore Ts'ob8a95312003-05-13 23:41:29 -0400727#endif
Theodore Ts'oc180ac82000-10-26 20:24:43 +0000728
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500729 if (lseek(data->dev, offset + data->offset, SEEK_SET) < 0)
Theodore Ts'oc180ac82000-10-26 20:24:43 +0000730 return errno;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400731
Theodore Ts'oc180ac82000-10-26 20:24:43 +0000732 actual = write(data->dev, buf, size);
733 if (actual != size)
734 return EXT2_ET_SHORT_WRITE;
735
736 return 0;
737}
738
Theodore Ts'o3839e651997-04-26 13:21:57 +0000739/*
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400740 * Flush data buffers to disk.
Theodore Ts'o3839e651997-04-26 13:21:57 +0000741 */
742static errcode_t unix_flush(io_channel channel)
743{
Theodore Ts'of3db3561997-04-26 13:34:30 +0000744 struct unix_private_data *data;
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000745 errcode_t retval = 0;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400746
Theodore Ts'of3db3561997-04-26 13:34:30 +0000747 EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
748 data = (struct unix_private_data *) channel->private_data;
749 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000750
Theodore Ts'ob8a95312003-05-13 23:41:29 -0400751#ifndef NO_IO_CACHE
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000752 retval = flush_cached_blocks(channel, data, 0);
Theodore Ts'ob8a95312003-05-13 23:41:29 -0400753#endif
Theodore Ts'o36f21431997-06-14 07:25:40 +0000754 fsync(data->dev);
Theodore Ts'oadfc8c62000-10-18 19:22:24 +0000755 return retval;
Theodore Ts'o3839e651997-04-26 13:21:57 +0000756}
757
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400758static errcode_t unix_set_option(io_channel channel, const char *option,
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500759 const char *arg)
760{
761 struct unix_private_data *data;
Theodore Ts'o2aee23f2006-11-12 10:40:40 -0500762 unsigned long long tmp;
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500763 char *end;
764
765 EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
766 data = (struct unix_private_data *) channel->private_data;
767 EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
768
769 if (!strcmp(option, "offset")) {
770 if (!arg)
771 return EXT2_ET_INVALID_ARGUMENT;
772
Theodore Ts'o2aee23f2006-11-12 10:40:40 -0500773 tmp = strtoull(arg, &end, 0);
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500774 if (*end)
775 return EXT2_ET_INVALID_ARGUMENT;
776 data->offset = tmp;
Theodore Ts'o2aee23f2006-11-12 10:40:40 -0500777 if (data->offset < 0)
778 return EXT2_ET_INVALID_ARGUMENT;
Theodore Ts'o2e8ca9a2004-11-30 14:07:11 -0500779 return 0;
780 }
781 return EXT2_ET_INVALID_ARGUMENT;
782}