]> git.saurik.com Git - apple/xnu.git/blame - tools/tests/perf_index/ramdisk.c
xnu-2782.1.97.tar.gz
[apple/xnu.git] / tools / tests / perf_index / ramdisk.c
CommitLineData
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
8int 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
25int 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}