]>
Commit | Line | Data |
---|---|---|
1 | #include "ramdisk.h" | |
2 | #include "fail.h" | |
3 | #include <assert.h> | |
4 | #include <stdlib.h> | |
5 | #include <stdio.h> | |
6 | #include <sys/param.h> | |
7 | ||
8 | int | |
9 | setup_ram_volume(const char* name, char* path) | |
10 | { | |
11 | char *cmd; | |
12 | int retval; | |
13 | ||
14 | retval = asprintf(&cmd, "diskutil erasevolume HFS+ '%s' `hdiutil attach -nomount ram://1500000` >/dev/null", name); | |
15 | VERIFY(retval > 0, "asprintf failed"); | |
16 | ||
17 | retval = system(cmd); | |
18 | VERIFY(retval == 0, "diskutil command failed"); | |
19 | ||
20 | snprintf(path, MAXPATHLEN, "/Volumes/%s", name); | |
21 | ||
22 | free(cmd); | |
23 | ||
24 | return PERFINDEX_SUCCESS; | |
25 | } | |
26 | ||
27 | int | |
28 | cleanup_ram_volume(char* path) | |
29 | { | |
30 | char *cmd; | |
31 | int retval; | |
32 | ||
33 | retval = asprintf(&cmd, "umount -f '%s' >/dev/null", path); | |
34 | VERIFY(retval > 0, "asprintf failed"); | |
35 | ||
36 | retval = system(cmd); | |
37 | VERIFY(retval == 0, "diskutil command failed"); | |
38 | ||
39 | free(cmd); | |
40 | ||
41 | return PERFINDEX_SUCCESS; | |
42 | } |