]> git.saurik.com Git - apple/xnu.git/blob - tools/tests/perf_index/ramdisk.c
xnu-3248.60.10.tar.gz
[apple/xnu.git] / tools / tests / perf_index / ramdisk.c
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 setup_ram_volume(const char* name, char* path) {
9 char *cmd;
10 int retval;
11
12 retval = asprintf(&cmd, "diskutil erasevolume HFS+ '%s' `hdiutil attach -nomount ram://1500000` >/dev/null", name);
13 VERIFY(retval > 0, "asprintf failed");
14
15 retval = system(cmd);
16 VERIFY(retval == 0, "diskutil command failed");
17
18 snprintf(path, MAXPATHLEN, "/Volumes/%s", name);
19
20 free(cmd);
21
22 return PERFINDEX_SUCCESS;
23 }
24
25 int cleanup_ram_volume(char* path) {
26 char *cmd;
27 int retval;
28
29 retval = asprintf(&cmd, "umount -f '%s' >/dev/null", path);
30 VERIFY(retval > 0, "asprintf failed");
31
32 retval = system(cmd);
33 VERIFY(retval == 0, "diskutil command failed");
34
35 free(cmd);
36
37 return PERFINDEX_SUCCESS;
38 }