Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * io_manager.c --- the I/O manager abstraction |
| 4 | */ |
| 5 | |
| 6 | #include <stdio.h> |
| 7 | #include <string.h> |
| 8 | #if HAVE_UNISTD_H |
| 9 | #include <unistd.h> |
| 10 | #endif |
| 11 | #include <fcntl.h> |
| 12 | #include <time.h> |
| 13 | #if HAVE_SYS_STAT_H |
| 14 | #include <sys/stat.h> |
| 15 | #endif |
| 16 | #if HAVE_SYS_TYPES_H |
| 17 | #include <sys/types.h> |
| 18 | #endif |
| 19 | |
| 20 | #include "ext2_fs.h" |
| 21 | #include "ext2fs.h" |
| 22 | |
| 23 | errcode_t io_channel_set_options(io_channel channel, const char *opts) |
| 24 | { |
| 25 | errcode_t retval = 0; |
| 26 | char *next, *ptr, *options, *arg; |
| 27 | |
| 28 | EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); |
| 29 | |
| 30 | if (!opts) |
| 31 | return 0; |
| 32 | |
| 33 | if (!channel->manager->set_option) |
| 34 | return EXT2_ET_INVALID_ARGUMENT; |
| 35 | |
| 36 | options = malloc(strlen(opts)+1); |
| 37 | if (!options) |
| 38 | return EXT2_ET_NO_MEMORY; |
| 39 | strcpy(options, opts); |
| 40 | ptr = options; |
| 41 | |
| 42 | while (ptr && *ptr) { |
| 43 | next = strchr(ptr, '&'); |
| 44 | if (next) |
| 45 | *next++ = 0; |
| 46 | |
| 47 | arg = strchr(ptr, '='); |
| 48 | if (arg) |
| 49 | *arg++ = 0; |
| 50 | |
| 51 | retval = (channel->manager->set_option)(channel, ptr, arg); |
| 52 | if (retval) |
| 53 | break; |
| 54 | ptr = next; |
| 55 | } |
| 56 | free(options); |
| 57 | return retval; |
| 58 | } |
| 59 | |
| 60 | errcode_t io_channel_write_byte(io_channel channel, unsigned long offset, |
| 61 | int count, const void *data) |
| 62 | { |
| 63 | EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); |
| 64 | |
| 65 | if (channel->manager->write_byte) |
| 66 | return channel->manager->write_byte(channel, offset, |
| 67 | count, data); |
| 68 | |
| 69 | return EXT2_ET_UNIMPLEMENTED; |
| 70 | } |