3
0

io_manager.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * io_manager.c --- the I/O manager abstraction
  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. #include "ext2_fs.h"
  19. #include "ext2fs.h"
  20. errcode_t io_channel_set_options(io_channel channel, const char *opts)
  21. {
  22. errcode_t retval = 0;
  23. char *next, *ptr, *options, *arg;
  24. EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
  25. if (!opts)
  26. return 0;
  27. if (!channel->manager->set_option)
  28. return EXT2_ET_INVALID_ARGUMENT;
  29. options = malloc(strlen(opts)+1);
  30. if (!options)
  31. return EXT2_ET_NO_MEMORY;
  32. strcpy(options, opts);
  33. ptr = options;
  34. while (ptr && *ptr) {
  35. next = strchr(ptr, '&');
  36. if (next)
  37. *next++ = 0;
  38. arg = strchr(ptr, '=');
  39. if (arg)
  40. *arg++ = 0;
  41. retval = (channel->manager->set_option)(channel, ptr, arg);
  42. if (retval)
  43. break;
  44. ptr = next;
  45. }
  46. free(options);
  47. return retval;
  48. }
  49. errcode_t io_channel_write_byte(io_channel channel, unsigned long offset,
  50. int count, const void *data)
  51. {
  52. EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
  53. if (channel->manager->write_byte)
  54. return channel->manager->write_byte(channel, offset,
  55. count, data);
  56. return EXT2_ET_UNIMPLEMENTED;
  57. }