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