qemu-fsdev.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Virtio 9p
  3. *
  4. * Copyright IBM, Corp. 2010
  5. *
  6. * Authors:
  7. * Gautham R Shenoy <ego@in.ibm.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2. See
  10. * the COPYING file in the top-level directory.
  11. *
  12. */
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include "qemu-fsdev.h"
  16. #include "qemu-queue.h"
  17. #include "osdep.h"
  18. #include "qemu-common.h"
  19. static QTAILQ_HEAD(FsTypeEntry_head, FsTypeListEntry) fstype_entries =
  20. QTAILQ_HEAD_INITIALIZER(fstype_entries);
  21. static FsTypeTable FsTypes[] = {
  22. { .name = "local", .ops = NULL},
  23. };
  24. int qemu_fsdev_add(QemuOpts *opts)
  25. {
  26. struct FsTypeListEntry *fsle;
  27. int i;
  28. if (qemu_opts_id(opts) == NULL) {
  29. fprintf(stderr, "fsdev: No id specified\n");
  30. return -1;
  31. }
  32. for (i = 0; i < ARRAY_SIZE(FsTypes); i++) {
  33. if (strcmp(FsTypes[i].name, qemu_opt_get(opts, "fstype")) == 0) {
  34. break;
  35. }
  36. }
  37. if (i == ARRAY_SIZE(FsTypes)) {
  38. fprintf(stderr, "fsdev: fstype %s not found\n",
  39. qemu_opt_get(opts, "fstype"));
  40. return -1;
  41. }
  42. fsle = qemu_malloc(sizeof(*fsle));
  43. fsle->fse.fsdev_id = qemu_strdup(qemu_opts_id(opts));
  44. fsle->fse.path = qemu_strdup(qemu_opt_get(opts, "path"));
  45. fsle->fse.ops = FsTypes[i].ops;
  46. QTAILQ_INSERT_TAIL(&fstype_entries, fsle, next);
  47. return 0;
  48. }
  49. FsTypeEntry *get_fsdev_fsentry(char *id)
  50. {
  51. struct FsTypeListEntry *fsle;
  52. QTAILQ_FOREACH(fsle, &fstype_entries, next) {
  53. if (strcmp(fsle->fse.fsdev_id, id) == 0) {
  54. return &fsle->fse;
  55. }
  56. }
  57. return NULL;
  58. }