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