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