]> git.saurik.com Git - apple/xnu.git/blobdiff - tools/tests/perf_index/ramdisk.c
xnu-2782.1.97.tar.gz
[apple/xnu.git] / tools / tests / perf_index / ramdisk.c
diff --git a/tools/tests/perf_index/ramdisk.c b/tools/tests/perf_index/ramdisk.c
new file mode 100644 (file)
index 0000000..357fbf4
--- /dev/null
@@ -0,0 +1,38 @@
+#include "ramdisk.h"
+#include "fail.h"
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/param.h>
+
+int setup_ram_volume(const char* name, char* path) {
+  char *cmd;
+  int retval;
+  
+  retval = asprintf(&cmd, "diskutil erasevolume HFS+ '%s' `hdiutil attach -nomount ram://1500000` >/dev/null", name);
+  VERIFY(retval > 0, "asprintf failed");
+
+  retval = system(cmd);
+  VERIFY(retval == 0, "diskutil command failed");
+
+  snprintf(path, MAXPATHLEN, "/Volumes/%s", name);
+
+  free(cmd);
+
+  return PERFINDEX_SUCCESS;
+}
+
+int cleanup_ram_volume(char* path) {
+  char *cmd;
+  int retval;
+
+  retval = asprintf(&cmd, "umount -f '%s' >/dev/null", path);
+  VERIFY(retval > 0, "asprintf failed");
+
+  retval = system(cmd);
+  VERIFY(retval == 0, "diskutil command failed");
+
+  free(cmd);
+
+  return PERFINDEX_SUCCESS;
+}