am f298f6be: Merge "Use errno correctly."

* commit 'f298f6be4c8df8745735676e37ccc963909ff3b2':
  Use errno correctly.
diff --git a/Android.mk b/Android.mk
index 94d6ca2..1a4f8dd 100644
--- a/Android.mk
+++ b/Android.mk
@@ -3,22 +3,30 @@
 common_src_files := \
 	VolumeManager.cpp \
 	CommandListener.cpp \
+	CryptCommandListener.cpp \
 	VoldCommand.cpp \
 	NetlinkManager.cpp \
 	NetlinkHandler.cpp \
-	Volume.cpp \
-	DirectVolume.cpp \
 	Process.cpp \
-	Ext4.cpp \
-	Fat.cpp \
+	fs/Ext4.cpp \
+	fs/F2fs.cpp \
+	fs/Vfat.cpp \
 	Loop.cpp \
 	Devmapper.cpp \
 	ResponseCode.cpp \
 	CheckBattery.cpp \
 	Ext4Crypt.cpp \
 	VoldUtil.c \
-	fstrim.c \
-	cryptfs.c
+	cryptfs.c \
+	Disk.cpp \
+	VolumeBase.cpp \
+	PublicVolume.cpp \
+	PrivateVolume.cpp \
+	EmulatedVolume.cpp \
+	Utils.cpp \
+	MoveTask.cpp \
+	Benchmark.cpp \
+	TrimTask.cpp \
 
 common_c_includes := \
 	system/extras/ext4_utils \
@@ -54,7 +62,7 @@
 	libbatteryservice
 
 vold_conlyflags := -std=c11
-vold_cflags := -Werror -Wall -Wno-missing-field-initializers
+vold_cflags := -Werror -Wall -Wno-missing-field-initializers -Wno-unused-variable -Wno-unused-parameter
 
 include $(CLEAR_VARS)
 
diff --git a/Benchmark.cpp b/Benchmark.cpp
new file mode 100644
index 0000000..810adf4
--- /dev/null
+++ b/Benchmark.cpp
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Benchmark.h"
+#include "BenchmarkGen.h"
+#include "VolumeManager.h"
+#include "ResponseCode.h"
+
+#include <base/file.h>
+#include <base/logging.h>
+#include <cutils/iosched_policy.h>
+#include <private/android_filesystem_config.h>
+
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <unistd.h>
+
+#define ENABLE_DROP_CACHES 1
+
+using android::base::ReadFileToString;
+using android::base::WriteStringToFile;
+
+namespace android {
+namespace vold {
+
+static void notifyResult(const std::string& path, int64_t create_d,
+        int64_t drop_d, int64_t run_d, int64_t destroy_d) {
+    std::string res(path +
+            + " " + BenchmarkIdent()
+            + " " + std::to_string(create_d)
+            + " " + std::to_string(drop_d)
+            + " " + std::to_string(run_d)
+            + " " + std::to_string(destroy_d));
+    VolumeManager::Instance()->getBroadcaster()->sendBroadcast(
+            ResponseCode::BenchmarkResult, res.c_str(), false);
+}
+
+static nsecs_t benchmark(const std::string& path) {
+    errno = 0;
+    int orig_prio = getpriority(PRIO_PROCESS, 0);
+    if (errno != 0) {
+        PLOG(ERROR) << "Failed to getpriority";
+        return -1;
+    }
+    if (setpriority(PRIO_PROCESS, 0, -10) != 0) {
+        PLOG(ERROR) << "Failed to setpriority";
+        return -1;
+    }
+
+    IoSchedClass orig_clazz = IoSchedClass_NONE;
+    int orig_ioprio = 0;
+    if (android_get_ioprio(0, &orig_clazz, &orig_ioprio)) {
+        PLOG(ERROR) << "Failed to android_get_ioprio";
+        return -1;
+    }
+    if (android_set_ioprio(0, IoSchedClass_RT, 0)) {
+        PLOG(ERROR) << "Failed to android_set_ioprio";
+        return -1;
+    }
+
+    char orig_cwd[PATH_MAX];
+    if (getcwd(orig_cwd, PATH_MAX) == NULL) {
+        PLOG(ERROR) << "Failed getcwd";
+        return -1;
+    }
+    if (chdir(path.c_str()) != 0) {
+        PLOG(ERROR) << "Failed chdir";
+        return -1;
+    }
+
+    sync();
+
+    LOG(INFO) << "Benchmarking " << path;
+    nsecs_t start = systemTime(SYSTEM_TIME_BOOTTIME);
+
+    BenchmarkCreate();
+    sync();
+    nsecs_t create = systemTime(SYSTEM_TIME_BOOTTIME);
+
+#if ENABLE_DROP_CACHES
+    LOG(VERBOSE) << "Before drop_caches";
+    if (!WriteStringToFile("3", "/proc/sys/vm/drop_caches")) {
+        PLOG(ERROR) << "Failed to drop_caches";
+    }
+    LOG(VERBOSE) << "After drop_caches";
+#endif
+    nsecs_t drop = systemTime(SYSTEM_TIME_BOOTTIME);
+
+    BenchmarkRun();
+    sync();
+    nsecs_t run = systemTime(SYSTEM_TIME_BOOTTIME);
+
+    BenchmarkDestroy();
+    sync();
+    nsecs_t destroy = systemTime(SYSTEM_TIME_BOOTTIME);
+
+    if (chdir(orig_cwd) != 0) {
+        PLOG(ERROR) << "Failed to chdir";
+    }
+    if (android_set_ioprio(0, orig_clazz, orig_ioprio)) {
+        PLOG(ERROR) << "Failed to android_set_ioprio";
+    }
+    if (setpriority(PRIO_PROCESS, 0, orig_prio) != 0) {
+        PLOG(ERROR) << "Failed to setpriority";
+    }
+
+    nsecs_t create_d = create - start;
+    nsecs_t drop_d = drop - create;
+    nsecs_t run_d = run - drop;
+    nsecs_t destroy_d = destroy - run;
+
+    LOG(INFO) << "create took " << nanoseconds_to_milliseconds(create_d) << "ms";
+    LOG(INFO) << "drop took " << nanoseconds_to_milliseconds(drop_d) << "ms";
+    LOG(INFO) << "run took " << nanoseconds_to_milliseconds(run_d) << "ms";
+    LOG(INFO) << "destroy took " << nanoseconds_to_milliseconds(destroy_d) << "ms";
+
+    notifyResult(path, create_d, drop_d, run_d, destroy_d);
+
+    return run_d;
+}
+
+nsecs_t BenchmarkPrivate(const std::string& path) {
+    std::string benchPath(path);
+    benchPath += "/misc";
+    if (android::vold::PrepareDir(benchPath, 01771, AID_SYSTEM, AID_MISC)) {
+        return -1;
+    }
+    benchPath += "/vold";
+    if (android::vold::PrepareDir(benchPath, 0700, AID_ROOT, AID_ROOT)) {
+        return -1;
+    }
+    benchPath += "/bench";
+    if (android::vold::PrepareDir(benchPath, 0700, AID_ROOT, AID_ROOT)) {
+        return -1;
+    }
+    return benchmark(benchPath);
+}
+
+}  // namespace vold
+}  // namespace android
diff --git a/Benchmark.h b/Benchmark.h
new file mode 100644
index 0000000..13f9009
--- /dev/null
+++ b/Benchmark.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_VOLD_BENCHMARK_H
+#define ANDROID_VOLD_BENCHMARK_H
+
+#include <utils/Errors.h>
+#include <utils/Timers.h>
+
+#include <string>
+
+namespace android {
+namespace vold {
+
+/* Benchmark a private volume mounted at the given path */
+nsecs_t BenchmarkPrivate(const std::string& path);
+
+}  // namespace vold
+}  // namespace android
+
+#endif
diff --git a/BenchmarkGen.h b/BenchmarkGen.h
new file mode 100644
index 0000000..6813b08
--- /dev/null
+++ b/BenchmarkGen.h
@@ -0,0 +1,4438 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+/******************************************************************
+ * THIS CODE WAS GENERATED BY benchgen.py, DO NOT MODIFY DIRECTLY *
+ ******************************************************************/
+
+
+#include <base/logging.h>
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/sendfile.h>
+#include <fcntl.h>
+
+#include <algorithm>
+#include <string>
+
+#include <Utils.h>
+
+namespace android {
+namespace vold {
+
+static status_t BenchmarkRun() {
+
+char* buf = (char*) malloc(1048576);
+int  t3433f17 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(lseek(t3433f17, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3433f17, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3433f17, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 30, 278721));
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 19, 278751));
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 25119, 278528)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 30, 37276895));
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 14, 37276925));
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 914520, 37273600)); // mmap2
+int  t3433f18 = TEMP_FAILURE_RETRY(open("file1", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 466944, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4096, 466944)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 471040, 0)); // mmap2
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 30, 5965501));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 11, 5965531));
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file2", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 1048576, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4096, 57012224)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 1048576, 0)); // mmap2
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 30, 6473855));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 12, 6473885));
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 30, 8916226));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 12, 8916256));
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 30, 11368292));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 12, 11368322));
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 30, 13996125));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 12, 13996155));
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 30, 16595549));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 12, 16595579));
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 30, 19217798));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 12, 19217828));
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 30, 22047170));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 12, 22047200));
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3433f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3433f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 30, 24961213));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 12, 24961243));
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file3", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file4", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file5", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 38736, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4304, 36864)); // mmap2
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file6", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 2348, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4636, 0)); // mmap2
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file7", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 778948, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 16736, 778240)); // mmap2
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file8", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 18099, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4264, 16384)); // mmap2
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file9", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 22960, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4108, 20480)); // mmap2
+close(t3433f18);
+t3433f18 = TEMP_FAILURE_RETRY(open("file10", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 13748, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f18, buf, 4196, 12288)); // mmap2
+close(t3433f18);
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 30, 278721));
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 19, 278751));
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 25119, 278528)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 30, 35727447));
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 33, 35727477));
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 2805, 35725312)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 30, 29869066));
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 33, 29869096));
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 1891, 29868032)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 30, 34413225));
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 49, 34413255));
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 3143, 34410496)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 30, 32521955));
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 45, 32521985));
+TEMP_FAILURE_RETRY(pread(t3433f17, buf, 6350, 32518144)); // mmap2
+int  t3450f18 = TEMP_FAILURE_RETRY(open("file11", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+int  t3450f22 = TEMP_FAILURE_RETRY(open("file12", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3450f22, buf, 1));
+close(t3450f22);
+t3450f22 = TEMP_FAILURE_RETRY(open("file13", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3450f22);
+t3450f22 = TEMP_FAILURE_RETRY(open("file14", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3450f22);
+t3450f22 = TEMP_FAILURE_RETRY(open("file15", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3450f22, buf, 1));
+TEMP_FAILURE_RETRY(fsync(t3450f22));
+close(t3450f22);
+close(t3450f18);
+int  t3454f26 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(lseek(t3454f26, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3454f26, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3454f26, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3454f26, buf, 769726, 38187008)); // mmap2
+close(t3454f26);
+t3454f26 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(lseek(t3454f26, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3454f26, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3454f26, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3454f26, buf, 769726, 38187008)); // mmap2
+close(t3454f26);
+int  t3455f17 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(lseek(t3455f17, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3455f17, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3455f17, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 278721));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 19, 278751));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 25119, 278528)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 37276895));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 14, 37276925));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 914520, 37273600)); // mmap2
+int  t3454f29 = TEMP_FAILURE_RETRY(open("file16", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(pread(t3454f29, buf, 14048, 0)); // mmap2
+close(t3454f29);
+int  t3455f18 = TEMP_FAILURE_RETRY(open("file1", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 466944, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4096, 466944)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 471040, 0)); // mmap2
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 30, 5965501));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 11, 5965531));
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file2", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 1048576, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4096, 57012224)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 1048576, 0)); // mmap2
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 30, 6473855));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 12, 6473885));
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 30, 8916226));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 12, 8916256));
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 30, 11368292));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 12, 11368322));
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 30, 13996125));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 12, 13996155));
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 30, 16595549));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 12, 16595579));
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 30, 19217798));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 12, 19217828));
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 30, 22047170));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 12, 22047200));
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 4));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_SET));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3455f18, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3455f18, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 769726, 38187008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 30, 24961213));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 12, 24961243));
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file3", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file4", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file5", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 38736, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4304, 36864)); // mmap2
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file6", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 2348, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4636, 0)); // mmap2
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file7", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 778948, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 16736, 778240)); // mmap2
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file8", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 18099, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4264, 16384)); // mmap2
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file9", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 22960, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4108, 20480)); // mmap2
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file11", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 3513185));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 46, 3513215));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3262, 3510272)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 3513185));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 46, 3513215));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3262, 3510272)); // mmap2
+int  t3455f19 = TEMP_FAILURE_RETRY(open("file12", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3455f19, buf, 1));
+close(t3455f19);
+t3455f19 = TEMP_FAILURE_RETRY(open("file13", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3455f19);
+t3455f19 = TEMP_FAILURE_RETRY(open("file14", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3455f19);
+t3455f19 = TEMP_FAILURE_RETRY(open("file15", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3455f19, buf, 1));
+TEMP_FAILURE_RETRY(fsync(t3455f19));
+close(t3455f19);
+close(t3455f18);
+t3455f18 = TEMP_FAILURE_RETRY(open("file10", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 13748, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f18, buf, 4196, 12288)); // mmap2
+close(t3455f18);
+int  t3483f20 = TEMP_FAILURE_RETRY(open("file17", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 100, 0));
+int  t3483f21 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3483f21, buf, 1, 0));
+close(t3483f21);
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 0));
+t3483f21 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3483f21, buf, 1, 0));
+close(t3483f21);
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 16, 24));
+t3483f21 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3483f21, buf, 1, 0));
+close(t3483f21);
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 8192));
+t3483f21 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3483f21, buf, 1, 0));
+close(t3483f21);
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 16, 24));
+t3483f21 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3483f21, buf, 1, 0));
+close(t3483f21);
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 16384));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 12288));
+int  t3483f22 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3483f22, buf, 1, 0));
+close(t3483f22);
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 20480));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 28672));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 32768));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 36864));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 81920));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 98304));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 163840));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 57344));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 147456));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 151552));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 155648));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 143360));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 65536));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 122880));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 73728));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 126976));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 90112));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 135168));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 106496));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 110592));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 49152));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 139264));
+TEMP_FAILURE_RETRY(pread(t3483f20, buf, 4096, 172032));
+int  t3483f25 = TEMP_FAILURE_RETRY(open("file19", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 100, 0));
+int  t3483f26 = TEMP_FAILURE_RETRY(open("file20", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3483f26, buf, 1, 0));
+close(t3483f26);
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 0));
+t3483f26 = TEMP_FAILURE_RETRY(open("file20", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3483f26, buf, 1, 0));
+close(t3483f26);
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 16, 24));
+t3483f26 = TEMP_FAILURE_RETRY(open("file20", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3483f26, buf, 1, 0));
+close(t3483f26);
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 8192));
+t3483f26 = TEMP_FAILURE_RETRY(open("file20", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3483f26, buf, 1, 0));
+close(t3483f26);
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 16, 24));
+t3483f26 = TEMP_FAILURE_RETRY(open("file20", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3483f26, buf, 1, 0));
+close(t3483f26);
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 16384));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 12288));
+int  t3483f27 = TEMP_FAILURE_RETRY(open("file20", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3483f27, buf, 1, 0));
+close(t3483f27);
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 24576));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 40960));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 20480));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 110592));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 172032));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 151552));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 77824));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 155648));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 180224));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 106496));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 167936));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 94208));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 163840));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 49152));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 159744));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 176128));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 36864));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 98304));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 61440));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 86016));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 147456));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 143360));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 45056));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 73728));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 32768));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 122880));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 126976));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 28672));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 53248));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 118784));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 57344));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 135168));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 65536));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 184320));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 69632));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 81920));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 90112));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 102400));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 114688));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 131072));
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 4096, 139264));
+t3483f27 = TEMP_FAILURE_RETRY(open("file20", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3483f27, buf, 1, 0));
+close(t3483f27);
+TEMP_FAILURE_RETRY(pread(t3483f25, buf, 16, 24));
+int  t3498f30 = TEMP_FAILURE_RETRY(open("file21", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3498f30, buf, 16384));
+close(t3498f30);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 278721));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 19, 278751));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 25119, 278528)); // mmap2
+int  t3499f30 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f30, buf, 1, 0));
+close(t3499f30);
+int  t3499f31 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f31, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f31));
+t3499f30 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f30));
+close(t3499f30);
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f31));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f31));
+close(t3499f31);
+t3499f30 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f30, buf, 1, 0));
+close(t3499f30);
+t3499f30 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f30, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f30));
+t3499f31 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f31));
+close(t3499f31);
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f30));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f30));
+close(t3499f30);
+int  t3500f30 = TEMP_FAILURE_RETRY(open("file23", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 27898, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 4124, 24576)); // mmap2
+close(t3500f30);
+t3500f30 = TEMP_FAILURE_RETRY(open("file24", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 91256, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 4108, 90112)); // mmap2
+close(t3500f30);
+t3500f30 = TEMP_FAILURE_RETRY(open("file25", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 30332, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 4200, 28672)); // mmap2
+close(t3500f30);
+t3500f30 = TEMP_FAILURE_RETRY(open("file26", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 26408, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 4100, 24576)); // mmap2
+close(t3500f30);
+t3500f30 = TEMP_FAILURE_RETRY(open("file27", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 50044, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 4128, 49152)); // mmap2
+close(t3500f30);
+t3500f30 = TEMP_FAILURE_RETRY(open("file28", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 1048576, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3500f30, buf, 122564, 3059712)); // mmap2
+close(t3500f30);
+int  t3502f30 = TEMP_FAILURE_RETRY(open("file29", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 4));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 44));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 29));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 36));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 21));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 17));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 47));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 23));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 28));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 24));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 45));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 21));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 37));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 22));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 17));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 36));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 37));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 22));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 22));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 46));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 29));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 31));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 32));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 31));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 37));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 1));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 2));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 21));
+TEMP_FAILURE_RETRY(read(t3502f30, buf, 8));
+close(t3502f30);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35167565));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 36, 35167595));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4148, 35164160)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34342181));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 49, 34342211));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1656, 34340864)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32761881));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 36, 32761911));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3104, 32759808)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34343387));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 32, 34343417));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2828, 34340864)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34343692));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 47, 34343722));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3201, 34340864)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34344392));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 43, 34344422));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3897, 34340864)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34344065));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 41, 34344095));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3528, 34340864)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34344761));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 46, 34344791));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4269, 34340864)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34345456));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 42, 34345486));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 865, 34344960)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34345133));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 40, 34345163));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 496, 34344960)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 36096678));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 29, 36096708));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3292, 36093952)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34698049));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 42, 34698079));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1211, 34697216)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32760711));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 31, 32760741));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2073, 32759808)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32273035));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 37, 32273065));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1692, 32272384)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34612102));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 38, 34612132));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1313, 34611200)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34765885));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 37, 34765915));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3387, 34762752)); // mmap2
+t3499f31 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f31, buf, 1, 0));
+close(t3499f31);
+t3499f31 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f31, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f31));
+int  t3499f32 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f32));
+close(t3499f32);
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f31));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f31));
+close(t3499f31);
+t3499f31 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f31, buf, 1, 0));
+close(t3499f31);
+t3499f31 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f31, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f31));
+t3499f32 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f32));
+close(t3499f32);
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f31));
+TEMP_FAILURE_RETRY(pwrite(t3499f31, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f31));
+close(t3499f31);
+int  t3492f31 = TEMP_FAILURE_RETRY(open("file30", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 100, 0));
+int  t3492f32 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3492f32, buf, 1, 0));
+close(t3492f32);
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 0));
+t3492f32 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3492f32, buf, 1, 0));
+close(t3492f32);
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 16, 24));
+t3492f32 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3492f32, buf, 1, 0));
+close(t3492f32);
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 8192));
+t3492f32 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3492f32, buf, 1, 0));
+close(t3492f32);
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 16, 24));
+t3492f32 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3492f32, buf, 1, 0));
+close(t3492f32);
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35635385));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 49, 35635415));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1005, 35635200)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 16384));
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 12288));
+int  t3492f33 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3492f33, buf, 1, 0));
+close(t3492f33);
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 24576));
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 20480));
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 77824));
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 73728));
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 69632));
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 81920));
+t3492f33 = TEMP_FAILURE_RETRY(open("file32", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(pread(t3492f33, buf, 23336, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 36386416));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 32, 36386446));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2082, 36384768)); // mmap2
+t3499f30 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f30, buf, 1, 0));
+close(t3499f30);
+t3499f30 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f30, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f30));
+int  t3499f34 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f34));
+close(t3499f34);
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f30));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f30));
+close(t3499f30);
+t3499f30 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f30, buf, 1, 0));
+close(t3499f30);
+t3499f30 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f30, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f30));
+t3499f34 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f34));
+close(t3499f34);
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f30));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f30));
+close(t3499f30);
+t3499f30 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f30, buf, 1, 0));
+close(t3499f30);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 36389306));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 23, 36389336));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1664, 36388864)); // mmap2
+t3499f30 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f30, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f30));
+t3499f34 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f34));
+close(t3499f34);
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f30));
+TEMP_FAILURE_RETRY(pwrite(t3499f30, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f30));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34762881));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 54, 34762911));
+close(t3499f30);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 463, 34762752)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 28270957));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 45, 28270987));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 667, 28270592)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34750025));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 37, 34750055));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4004, 34746368)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 1468611));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 28, 1468641));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 58877, 1466368)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31697557));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 55, 31697587));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3884, 31694848)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34293434));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 45, 34293464));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2090, 34291712)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32918186));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 40, 32918216));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3139, 32915456)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32915891));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 46, 32915921));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2060, 32915456)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32917516));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 39, 32917546));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2476, 32915456)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32918595));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 44, 32918625));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4994, 32915456)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32917932));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 35, 32917962));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2730, 32915456)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35461407));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 31, 35461437));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2723, 35459072)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35474138));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 43, 35474168));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3682, 35471360)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34394223));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 41, 34394253));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 481, 34394112)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32648704));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 48, 32648734));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4644, 32645120)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32654567));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 58, 32654597));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1606, 32653312)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32649764));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 52, 32649794));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1553, 32649216)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32654918));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 62, 32654948));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1979, 32653312)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31696162));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 56, 31696192));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2367, 31694848)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3492f33, buf, 9032, 20480)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3492f33, buf, 24216, 28672)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3492f33, buf, 25168, 49152)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3492f33, buf, 10560, 73728)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3492f33, buf, 13256, 81920)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3492f33, buf, 6664, 94208)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3492f33, buf, 22688, 98304)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3492f33, buf, 57408, 118784)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3492f33, buf, 3064, 176128)); // mmap2
+close(t3492f33);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 36097244));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 38, 36097274));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3608, 36093952)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 36096678));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 29, 36096708));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3292, 36093952)); // mmap2
+int  t3509f41 = TEMP_FAILURE_RETRY(open("file33", O_RDONLY|O_LARGEFILE));
+int  t3492f42 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3492f42, buf, 1, 0));
+close(t3492f42);
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 53248));
+int  t3499f42 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f42, buf, 1, 0));
+close(t3499f42);
+TEMP_FAILURE_RETRY(read(t3509f41, buf, 8192));
+TEMP_FAILURE_RETRY(read(t3509f41, buf, 8091));
+close(t3509f41);
+int  t3499f41 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f41, buf, 1, 0));
+close(t3499f41);
+t3499f41 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f41, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f41));
+t3499f42 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f42));
+close(t3499f42);
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f41));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f41));
+close(t3499f41);
+t3499f41 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f41, buf, 1, 0));
+close(t3499f41);
+t3499f41 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f41, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f41));
+t3499f42 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f42));
+close(t3499f42);
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f41));
+TEMP_FAILURE_RETRY(pwrite(t3499f41, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f41));
+close(t3499f41);
+t3499f41 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f41, buf, 1, 0));
+close(t3499f41);
+int  t3499f40 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f40, buf, 1, 0));
+close(t3499f40);
+int  t3492f40 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3492f40, buf, 1, 0));
+close(t3492f40);
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 36864));
+t3499f40 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f40, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f40));
+t3499f42 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f42));
+close(t3499f42);
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f40));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f40));
+close(t3499f40);
+t3499f40 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f40, buf, 1, 0));
+close(t3499f40);
+t3499f40 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f40, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f40));
+t3499f42 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f42));
+close(t3499f42);
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f40));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f40));
+close(t3499f40);
+t3499f40 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f40, buf, 1, 0));
+close(t3499f40);
+t3499f40 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f40, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f40));
+t3499f42 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f42));
+close(t3499f42);
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f40));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f40));
+close(t3499f40);
+t3499f40 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f40, buf, 1, 0));
+close(t3499f40);
+int  t3492f41 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3492f41, buf, 1, 0));
+close(t3492f41);
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 45056));
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 90112));
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 94208));
+t3492f41 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3492f41, buf, 1, 0));
+close(t3492f41);
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 61440));
+t3499f40 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f40, buf, 1, 0));
+close(t3499f40);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35636928));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 60, 35636958));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2062, 35635200)); // mmap2
+t3499f40 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f40, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f40));
+t3499f41 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f41));
+close(t3499f41);
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f40));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f40));
+close(t3499f40);
+t3499f40 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f40, buf, 1, 0));
+close(t3499f40);
+t3499f40 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f40, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f40));
+int  t3508f42 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(lseek(t3508f42, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3508f42, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3508f42, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3508f42, buf, 769726, 38187008)); // mmap2
+close(t3508f42);
+t3508f42 = TEMP_FAILURE_RETRY(open("file0", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(lseek(t3508f42, 0, SEEK_END));
+TEMP_FAILURE_RETRY(lseek(t3508f42, 38891199, SEEK_SET));
+TEMP_FAILURE_RETRY(read(t3508f42, buf, 65557));
+TEMP_FAILURE_RETRY(pread(t3508f42, buf, 769726, 38187008)); // mmap2
+close(t3508f42);
+int  t3499f43 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f43));
+close(t3499f43);
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f40));
+TEMP_FAILURE_RETRY(pwrite(t3499f40, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f40));
+close(t3499f40);
+int  t3508f40 = TEMP_FAILURE_RETRY(open("file16", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(pread(t3508f40, buf, 14048, 0)); // mmap2
+close(t3508f40);
+int  t3499f33 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f33, buf, 1, 0));
+close(t3499f33);
+t3499f33 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f33, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f33));
+int  t3499f39 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f39));
+close(t3499f39);
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f33));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f33));
+close(t3499f33);
+t3499f33 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f33, buf, 1, 0));
+close(t3499f33);
+t3499f33 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f33, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f33));
+t3499f39 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f39));
+close(t3499f39);
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f33));
+TEMP_FAILURE_RETRY(pwrite(t3499f33, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f33));
+close(t3499f33);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35635115));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 36, 35635145));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4281, 35631104)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35448800));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 31, 35448830));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2408, 35446784)); // mmap2
+int  t3519f33 = TEMP_FAILURE_RETRY(open("file34", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3519f33, buf, 1422));
+TEMP_FAILURE_RETRY(read(t3519f33, buf, 1));
+close(t3519f33);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35378185));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 33, 35378215));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1535, 35377152)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35378687));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 40, 35378717));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2578, 35377152)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35194783));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 27, 35194813));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2574, 35192832)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34408303));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 36, 34408333));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2280, 34406400)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32465635));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 48, 32465665));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4145, 32464896)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35284839));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 38, 35284869));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2433, 35282944)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34435656));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 44, 34435686));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 905, 34435072)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32557274));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 64, 32557304));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 8345, 32555008)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32547670));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 63, 32547700));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 10458, 32546816)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32547259));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 49, 32547289));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 854, 32546816)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35562037));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 49, 35562067));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1486, 35561472)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34535858));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 48, 34535888));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2793, 34533376)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34103026));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 44, 34103056));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4170, 34099200)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35453961));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 42, 35453991));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3619, 35450880)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 29898896));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 48, 29898926));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2817, 29896704)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 28212186));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 28, 28212216));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3308, 28209152)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 28212460));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 29, 28212490));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3585, 28209152)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34435977));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 46, 34436007));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1227, 34435072)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 29899521));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 53, 29899551));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3195, 29896704)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 29898513));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 45, 29898543));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2192, 29896704)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35344567));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 28, 35344597));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 529, 35344384)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35344913));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 33, 35344943));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1043, 35344384)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32576839));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 49, 32576869));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 5361, 32575488)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35254403));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 39, 35254433));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 650, 35254272)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35722278));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 43, 35722308));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1541, 35721216)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35894101));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 51, 35894131));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1698, 35893248)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34723655));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 40, 34723685));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2180, 34721792)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35610903));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 37, 35610933));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 726, 35610624)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35722757));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 41, 35722787));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1939, 35721216)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35283991));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 42, 35284021));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1461, 35282944)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35276797));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 28, 35276827));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2365, 35274752)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 29897692));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 34, 29897722));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1809, 29896704)); // mmap2
+int  t3523f49 = TEMP_FAILURE_RETRY(open("file33", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3523f49, buf, 8192));
+TEMP_FAILURE_RETRY(read(t3523f49, buf, 8091));
+close(t3523f49);
+int  t3455f50 = TEMP_FAILURE_RETRY(open("file7", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+close(t3455f50);
+t3455f50 = TEMP_FAILURE_RETRY(open("file35", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3455f50, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3455f50, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f50, buf, 117507, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f50, buf, 4100, 114688)); // mmap2
+close(t3455f50);
+t3455f50 = TEMP_FAILURE_RETRY(open("file36", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3455f50, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3455f50, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f50, buf, 187587, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f50, buf, 4128, 188416)); // mmap2
+close(t3455f50);
+t3455f50 = TEMP_FAILURE_RETRY(open("file24", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+close(t3455f50);
+t3455f50 = TEMP_FAILURE_RETRY(open("file37", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3455f50, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3455f50, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f50, buf, 155576, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f50, buf, 4104, 155648)); // mmap2
+close(t3455f50);
+t3455f50 = TEMP_FAILURE_RETRY(open("file38", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3455f50, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3455f50, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f50, buf, 61218, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f50, buf, 4280, 61440)); // mmap2
+close(t3455f50);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 29922405));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 45, 29922435));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1962, 29921280)); // mmap2
+int  t3499f50 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f50, buf, 1, 0));
+close(t3499f50);
+t3499f50 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f50, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f50));
+int  t3499f52 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f52));
+close(t3499f52);
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f50));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f50));
+close(t3499f50);
+t3499f50 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f50, buf, 1, 0));
+close(t3499f50);
+t3499f50 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f50, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f50));
+t3499f52 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f52));
+close(t3499f52);
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f50));
+TEMP_FAILURE_RETRY(pwrite(t3499f50, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f50));
+close(t3499f50);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34609966));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 26, 34609996));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3291, 34607104)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31439600));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 39, 31439630));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3729, 31436800)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 33255456));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 43, 33255486));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 795, 33255424)); // mmap2
+int  t3492f52 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3492f52, buf, 1, 0));
+close(t3492f52);
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 4096, 28672));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35345427));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 31, 35345457));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1460, 35344384)); // mmap2
+t3492f52 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3492f52, buf, 1, 0));
+close(t3492f52);
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35946630));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 27, 35946660));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 376, 35946496)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35282311));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 35, 35282341));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4412, 35278848)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 28266007));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 38, 28266037));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3898, 28262400)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 28271259));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 33, 28271289));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 960, 28270592)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 29218555));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 42, 29218585));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2281, 29216768)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 28771544));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 44, 28771574));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2470, 28770304)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31103055));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 41, 31103085));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3471, 31100928)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34430076));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 48, 34430106));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3543, 34426880)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32574817));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 46, 32574847));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4265, 32571392)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35511105));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 28, 35511135));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3217, 35508224)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35511441));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 40, 35511471));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3780, 35508224)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35512004));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 33, 35512034));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4299, 35508224)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 29943458));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 44, 29943488));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2309, 29941760)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35513993));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 34, 35514023));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2120, 35512320)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34446657));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 53, 34446687));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3721, 34443264)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35513539));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 37, 35513569));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1673, 35512320)); // mmap2
+int  t3526f50 = TEMP_FAILURE_RETRY(open("file39", O_RDONLY|O_LARGEFILE));
+int  t3526f52 = TEMP_FAILURE_RETRY(open("file40", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3526f52, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3526f52, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3526f52, buf, 1584, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3526f52, buf, 4172, 0)); // mmap2
+close(t3526f52);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34434708));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 48, 34434738));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4060, 34430976)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32576277));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 46, 32576307));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1351, 32575488)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31155301));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 47, 31155331));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1721, 31154176)); // mmap2
+TEMP_FAILURE_RETRY(read(t3526f50, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3526f50, buf, 16384));
+close(t3526f50);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34433783));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 44, 34433813));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3113, 34430976)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32575657));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 49, 32575687));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 451, 32575488)); // mmap2
+int  t3519f50 = TEMP_FAILURE_RETRY(open("file41", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3519f50, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3519f50, buf, 16384));
+close(t3519f50);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 36042811));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 38, 36042841));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2688, 36040704)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31522913));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 39, 31522943));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2245, 31522816)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 29920348));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 42, 29920378));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 5221, 29917184)); // mmap2
+int  t3527f50 = TEMP_FAILURE_RETRY(open("file42", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3527f50, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3527f50, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32567874));
+TEMP_FAILURE_RETRY(pread(t3527f50, buf, 26358, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 53, 32567904));
+TEMP_FAILURE_RETRY(pread(t3527f50, buf, 4160, 24576)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 6297, 32567296)); // mmap2
+close(t3527f50);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32566237));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 55, 32566267));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4674, 32563200)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32564659));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 55, 32564689));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3037, 32563200)); // mmap2
+t3519f50 = TEMP_FAILURE_RETRY(open("file43", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3519f50, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3519f50, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3519f50, buf, 16384));
+close(t3519f50);
+int  t3492f50 = TEMP_FAILURE_RETRY(open("file44", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3492f50, buf, 52, 0));
+TEMP_FAILURE_RETRY(pread(t3492f50, buf, 4096, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3492f50, buf, 10313, 0)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3492f50, buf, 4136, 8192)); // mmap2
+close(t3492f50);
+t3519f50 = TEMP_FAILURE_RETRY(open("file45", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3519f50, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3519f50, buf, 16384));
+t3526f52 = TEMP_FAILURE_RETRY(open("file46", O_RDONLY|O_LARGEFILE));
+close(t3519f50);
+TEMP_FAILURE_RETRY(read(t3526f52, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3526f52, buf, 16384));
+close(t3526f52);
+int  t3532f53 = TEMP_FAILURE_RETRY(open("file47", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3532f53, buf, 16384));
+int  t3533f47 = TEMP_FAILURE_RETRY(open("file48", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3532f53, buf, 16384));
+close(t3532f53);
+TEMP_FAILURE_RETRY(read(t3533f47, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3533f47, buf, 16384));
+close(t3533f47);
+int  t3519f43 = TEMP_FAILURE_RETRY(open("file49", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3519f43, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3519f43, buf, 16384));
+close(t3519f43);
+int  t3532f43 = TEMP_FAILURE_RETRY(open("file50", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3532f43, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3532f43, buf, 16384));
+close(t3532f43);
+int  t3533f43 = TEMP_FAILURE_RETRY(open("file51", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3533f43, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3533f43, buf, 16384));
+close(t3533f43);
+t3519f43 = TEMP_FAILURE_RETRY(open("file52", O_RDONLY|O_LARGEFILE));
+t3532f53 = TEMP_FAILURE_RETRY(open("file53", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3519f43, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3519f43, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3519f43, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3532f53, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3532f53, buf, 16384));
+close(t3519f43);
+close(t3532f53);
+int  t3492f57 = TEMP_FAILURE_RETRY(open("file54", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3492f57, buf, 39938));
+close(t3492f57);
+int  t3492f61 = TEMP_FAILURE_RETRY(open("file55", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3492f61, buf, 8192));
+TEMP_FAILURE_RETRY(read(t3492f61, buf, 8192));
+close(t3492f61);
+t3492f61 = TEMP_FAILURE_RETRY(open("file56", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3492f61, buf, 8192));
+TEMP_FAILURE_RETRY(read(t3492f61, buf, 8192));
+close(t3492f61);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34957756));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 29, 34957786));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3273, 34955264)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34267550));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 49, 34267580));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 722, 34267136)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34439777));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 46, 34439807));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 920, 34439168)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35154576));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 29, 35154606));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3467, 35151872)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34418681));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 41, 34418711));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 339, 34418688)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31439600));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 39, 31439630));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3729, 31436800)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34420375));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 46, 34420405));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2143, 34418688)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31439101));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 42, 31439131));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2800, 31436800)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34420831));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 48, 34420861));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2549, 34418688)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31442196));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 40, 31442226));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2300, 31440896)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34421573));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 47, 34421603));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3344, 34418688)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34429110));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 51, 34429140));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2566, 34426880)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32573593));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 49, 32573623));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2814, 32571392)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 36353719));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 43, 36353749));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2179, 36352000)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35512004));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 33, 35512034));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4299, 35508224)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34434392));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 49, 34434422));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3732, 34430976)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34442017));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 42, 34442047));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3276, 34439168)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34957756));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 29, 34957786));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3273, 34955264)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35154576));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 29, 35154606));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3467, 35151872)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34433472));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 49, 34433502));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2807, 34430976)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34438470));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 63, 34438500));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3681, 34435072)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35281553));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 34, 35281583));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3463, 35278848)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34419413));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 51, 34419443));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1188, 34418688)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35511105));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 28, 35511135));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3217, 35508224)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35511441));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 40, 35511471));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3780, 35508224)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35512004));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 33, 35512034));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4299, 35508224)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35513993));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 34, 35514023));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2120, 35512320)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35513539));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 37, 35513569));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1673, 35512320)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 28977951));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 48, 28977981));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3292, 28975104)); // mmap2
+int  t3499f55 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f55, buf, 1, 0));
+close(t3499f55);
+t3499f55 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f55, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f55));
+int  t3499f56 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f56));
+close(t3499f56);
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f55));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f55));
+close(t3499f55);
+int  t3505f55 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3505f55, buf, 1, 0));
+close(t3505f55);
+int  t3519f55 = TEMP_FAILURE_RETRY(open("file57", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3519f55, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3519f55, buf, 16384));
+close(t3519f55);
+int  t3532f55 = TEMP_FAILURE_RETRY(open("file58", O_RDONLY|O_LARGEFILE));
+t3499f56 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f56, buf, 1, 0));
+close(t3499f56);
+TEMP_FAILURE_RETRY(read(t3532f55, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3532f55, buf, 16384));
+close(t3532f55);
+t3499f55 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+int  t3505f56 = TEMP_FAILURE_RETRY(open("file59", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f55, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f55));
+int  t3499f59 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f59));
+close(t3499f59);
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f55));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f55));
+close(t3499f55);
+int  t3533f55 = TEMP_FAILURE_RETRY(open("file60", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3533f55, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3533f55, buf, 16384));
+close(t3533f55);
+int  t3499f58 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f58, buf, 1, 0));
+close(t3499f58);
+t3499f58 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f58, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f58, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f58, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f58, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f58, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f58, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f58, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f58, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f58, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f58, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f58, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f58));
+t3499f59 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f59));
+close(t3499f59);
+TEMP_FAILURE_RETRY(pwrite(t3499f58, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f58));
+TEMP_FAILURE_RETRY(pwrite(t3499f58, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f58));
+close(t3499f58);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 36353719));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 43, 36353749));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2179, 36352000)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34428771));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 59, 34428801));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2230, 34426880)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34441089));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 45, 34441119));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2381, 34439168)); // mmap2
+t3499f55 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f55, buf, 1, 0));
+close(t3499f55);
+t3499f55 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f55, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f55));
+t3499f58 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f58));
+close(t3499f58);
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f55));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f55));
+close(t3499f55);
+t3499f55 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f55, buf, 1, 0));
+close(t3499f55);
+t3499f55 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f55, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f55));
+t3499f58 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f58));
+close(t3499f58);
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f55));
+TEMP_FAILURE_RETRY(pwrite(t3499f55, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f55));
+close(t3499f55);
+TEMP_FAILURE_RETRY(read(t3505f56, buf, 20552));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35601253));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 36, 35601283));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3224, 35598336)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35601560));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 45, 35601590));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3832, 35598336)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35511441));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 40, 35511471));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3780, 35508224)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 29923242));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 40, 29923272));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3511, 29921280)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 28272466));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 38, 28272496));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2171, 28270592)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35513993));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 34, 35514023));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2120, 35512320)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34446657));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 53, 34446687));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3721, 34443264)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35513539));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 37, 35513569));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1673, 35512320)); // mmap2
+TEMP_FAILURE_RETRY(read(t3505f56, buf, 16008));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31153857));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 48, 31153887));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4461, 31150080)); // mmap2
+TEMP_FAILURE_RETRY(read(t3505f56, buf, 10864));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34907552));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 39, 34907582));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2551, 34906112)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31809921));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 71, 31809951));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 7755, 31809536)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34423668));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 60, 34423698));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1203, 34422784)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 30431338));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 42, 30431368));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4400, 30429184)); // mmap2
+TEMP_FAILURE_RETRY(read(t3505f56, buf, 14320));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34416128));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 43, 34416158));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1855, 34414592)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 29893363));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 66, 29893393));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1244, 29892608)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 29892892));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 58, 29892922));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 755, 29892608)); // mmap2
+TEMP_FAILURE_RETRY(read(t3505f56, buf, 12208));
+TEMP_FAILURE_RETRY(read(t3505f56, buf, 20736));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 36353719));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 43, 36353749));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2179, 36352000)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35512004));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 33, 35512034));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4299, 35508224)); // mmap2
+TEMP_FAILURE_RETRY(read(t3505f56, buf, 8936));
+TEMP_FAILURE_RETRY(read(t3505f56, buf, 2800));
+TEMP_FAILURE_RETRY(read(t3505f56, buf, 20216));
+TEMP_FAILURE_RETRY(read(t3505f56, buf, 16912));
+close(t3505f56);
+t3505f56 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3505f56, buf, 1, 0));
+close(t3505f56);
+t3505f56 = TEMP_FAILURE_RETRY(open("file31", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4, 16924));
+int  t3499f62 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f62, buf, 1, 0));
+close(t3499f62);
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4, 16928));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4096, 16932));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4, 21028));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4, 21032));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4096, 21036));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 4, 25132));
+t3499f62 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f62, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f62));
+int  t3499f68 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f68));
+close(t3499f68);
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f62));
+TEMP_FAILURE_RETRY(pread(t3505f56, buf, 8, 25600));
+TEMP_FAILURE_RETRY(fdatasync(t3505f56));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f62));
+close(t3499f62);
+int  t3505f62 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3505f62));
+close(t3505f62);
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3505f56));
+TEMP_FAILURE_RETRY(pwrite(t3505f56, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3505f56));
+close(t3505f56);
+t3505f56 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3505f56, buf, 1, 0));
+close(t3505f56);
+int  t3533f56 = TEMP_FAILURE_RETRY(open("file61", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3533f56, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3533f56, buf, 16384));
+close(t3533f56);
+int  t3532f56 = TEMP_FAILURE_RETRY(open("file62", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3532f56, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3532f56, buf, 16384));
+close(t3532f56);
+t3532f56 = TEMP_FAILURE_RETRY(open("file63", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3532f56, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3532f56, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3532f56, buf, 16384));
+close(t3532f56);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 36042811));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 38, 36042841));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2688, 36040704)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 29922405));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 45, 29922435));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1962, 29921280)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31522913));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 39, 31522943));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2245, 31522816)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 29920348));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 42, 29920378));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 5221, 29917184)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32567874));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 53, 32567904));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 6297, 32567296)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32566237));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 55, 32566267));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4674, 32563200)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 32564659));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 55, 32564689));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3037, 32563200)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35154576));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 29, 35154606));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3467, 35151872)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34420375));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 46, 34420405));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2143, 34418688)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34420831));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 48, 34420861));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2549, 34418688)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34421573));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 47, 34421603));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3344, 34418688)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34438470));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 63, 34438500));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3681, 34435072)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 36457841));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 38, 36457871));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4242, 36454400)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35939717));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 29, 35939747));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1726, 35938304)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 28356265));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 47, 28356295));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4322, 28352512)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 29935078));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 50, 29935108));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1983, 29933568)); // mmap2
+int  t3499f66 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f66, buf, 1, 0));
+close(t3499f66);
+t3499f66 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 36467015));
+int  t3532f68 = TEMP_FAILURE_RETRY(open("file64", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 41, 36467045));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1083, 36466688)); // mmap2
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f66, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f66));
+TEMP_FAILURE_RETRY(read(t3532f68, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3532f68, buf, 16384));
+int  t3499f73 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(read(t3532f68, buf, 16384));
+TEMP_FAILURE_RETRY(fdatasync(t3499f73));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34267550));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 49, 34267580));
+close(t3499f73);
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 12, 0));
+close(t3532f68);
+TEMP_FAILURE_RETRY(fdatasync(t3499f66));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 722, 34267136)); // mmap2
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f66));
+close(t3499f66);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35511105));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 28, 35511135));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3217, 35508224)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35511441));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 40, 35511471));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3780, 35508224)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35512004));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 33, 35512034));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4299, 35508224)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35513993));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 34, 35514023));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2120, 35512320)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35513539));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 37, 35513569));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1673, 35512320)); // mmap2
+int  t3532f61 = TEMP_FAILURE_RETRY(open("file65", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3532f61, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3532f61, buf, 16384));
+close(t3532f61);
+int  t3533f61 = TEMP_FAILURE_RETRY(open("file66", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3533f61, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3533f61, buf, 16384));
+close(t3533f61);
+t3532f61 = TEMP_FAILURE_RETRY(open("file67", O_RDONLY|O_LARGEFILE));
+t3499f62 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f62, buf, 1, 0));
+close(t3499f62);
+TEMP_FAILURE_RETRY(read(t3532f61, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3532f61, buf, 16384));
+close(t3532f61);
+t3533f61 = TEMP_FAILURE_RETRY(open("file68", O_RDONLY|O_LARGEFILE));
+t3499f62 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 512, 0));
+TEMP_FAILURE_RETRY(read(t3533f61, buf, 16384));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4, 512));
+TEMP_FAILURE_RETRY(read(t3533f61, buf, 16384));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4, 8716));
+close(t3533f61);
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f62, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f62));
+int  t3499f61 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f61));
+close(t3499f61);
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f62));
+TEMP_FAILURE_RETRY(pwrite(t3499f62, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f62));
+t3532f61 = TEMP_FAILURE_RETRY(open("file69", O_RDONLY|O_LARGEFILE));
+close(t3499f62);
+TEMP_FAILURE_RETRY(read(t3532f61, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3532f61, buf, 16384));
+close(t3532f61);
+t3533f61 = TEMP_FAILURE_RETRY(open("file70", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3533f61, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3533f61, buf, 16384));
+close(t3533f61);
+int  t3519f61 = TEMP_FAILURE_RETRY(open("file71", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3519f61, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3519f61, buf, 16384));
+close(t3519f61);
+int  t3499f80 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f80, buf, 1, 0));
+close(t3499f80);
+t3499f80 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f80, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f80, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f80, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f80, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f80, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f80, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f80, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f80, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f80, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f80, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f80, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f80));
+int  t3499f81 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f81));
+close(t3499f81);
+TEMP_FAILURE_RETRY(pwrite(t3499f80, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f80));
+TEMP_FAILURE_RETRY(pwrite(t3499f80, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f80));
+close(t3499f80);
+t3499f66 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f66, buf, 1, 0));
+close(t3499f66);
+t3499f66 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f66, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f66));
+t3499f68 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f68));
+close(t3499f68);
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f66));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f66));
+close(t3499f66);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34957756));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 29, 34957786));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3273, 34955264)); // mmap2
+int  t3519f68 = TEMP_FAILURE_RETRY(open("file72", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file73", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file74", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file75", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file76", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file77", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file78", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file79", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file80", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file81", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file82", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+int  t3519f70 = TEMP_FAILURE_RETRY(open("file83", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f70);
+t3519f68 = TEMP_FAILURE_RETRY(open("file84", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file85", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file86", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file87", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file88", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file89", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file90", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file91", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file92", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f70 = TEMP_FAILURE_RETRY(open("file93", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f70);
+t3519f70 = TEMP_FAILURE_RETRY(open("file94", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f70);
+t3519f70 = TEMP_FAILURE_RETRY(open("file95", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+int  t3492f72 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3492f72, buf, 1, 0));
+close(t3492f72);
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 16, 24));
+close(t3519f70);
+int  t3492f70 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3492f70, buf, 1, 0));
+close(t3492f70);
+TEMP_FAILURE_RETRY(pread(t3492f31, buf, 16, 24));
+t3519f68 = TEMP_FAILURE_RETRY(open("file96", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file97", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file98", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file99", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file100", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file101", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file102", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file103", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file104", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file105", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file106", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file107", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file108", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+t3519f68 = TEMP_FAILURE_RETRY(open("file109", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f68);
+int  t3519f72 = TEMP_FAILURE_RETRY(open("file110", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f72);
+int  t3519f80 = TEMP_FAILURE_RETRY(open("file111", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f80);
+int  t3519f81 = TEMP_FAILURE_RETRY(open("file112", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f81);
+t3519f81 = TEMP_FAILURE_RETRY(open("file113", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f81);
+int  t3519f76 = TEMP_FAILURE_RETRY(open("file114", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f76);
+t3519f70 = TEMP_FAILURE_RETRY(open("file115", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f70);
+t3519f70 = TEMP_FAILURE_RETRY(open("file116", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f70);
+t3519f70 = TEMP_FAILURE_RETRY(open("file117", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f70);
+int  t3519f67 = TEMP_FAILURE_RETRY(open("file118", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f67);
+t3519f67 = TEMP_FAILURE_RETRY(open("file119", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f67);
+t3519f67 = TEMP_FAILURE_RETRY(open("file120", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f67);
+t3519f67 = TEMP_FAILURE_RETRY(open("file121", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f67);
+t3519f67 = TEMP_FAILURE_RETRY(open("file122", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f67);
+t3519f67 = TEMP_FAILURE_RETRY(open("file123", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f67);
+t3519f67 = TEMP_FAILURE_RETRY(open("file124", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f67);
+t3519f67 = TEMP_FAILURE_RETRY(open("file125", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f67);
+t3519f67 = TEMP_FAILURE_RETRY(open("file126", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f67);
+t3519f67 = TEMP_FAILURE_RETRY(open("file127", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3519f67);
+t3519f70 = TEMP_FAILURE_RETRY(open("file128", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3519f70);
+int  t3526f70 = TEMP_FAILURE_RETRY(open("file129", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+int  t3519f75 = TEMP_FAILURE_RETRY(open("file128", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+close(t3526f70);
+t3526f70 = TEMP_FAILURE_RETRY(open("file129", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3519f75, buf, 2991));
+close(t3519f75);
+TEMP_FAILURE_RETRY(read(t3526f70, buf, 3974));
+close(t3526f70);
+t3519f67 = TEMP_FAILURE_RETRY(open("file130", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3519f67, buf, 16384));
+int  t3499f72 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f72, buf, 1, 0));
+close(t3499f72);
+TEMP_FAILURE_RETRY(read(t3519f67, buf, 16384));
+t3499f72 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4, 8716));
+close(t3519f67);
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f72, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f72));
+int  t3499f67 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f67));
+close(t3499f67);
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f72));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f72));
+close(t3499f72);
+t3526f70 = TEMP_FAILURE_RETRY(open("file131", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3526f70);
+t3526f70 = TEMP_FAILURE_RETRY(open("file131", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3526f70, buf, 4622));
+close(t3526f70);
+int  t3526f72 = TEMP_FAILURE_RETRY(open("file132", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3526f72);
+t3526f72 = TEMP_FAILURE_RETRY(open("file132", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3526f72, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3526f72, buf, 6849));
+close(t3526f72);
+t3526f70 = TEMP_FAILURE_RETRY(open("file133", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3526f70);
+int  t3526f75 = TEMP_FAILURE_RETRY(open("file133", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3526f75, buf, 13332));
+close(t3526f75);
+int  t3495f70 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3495f70, buf, 1, 0));
+close(t3495f70);
+t3495f70 = TEMP_FAILURE_RETRY(open("file31", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3495f70, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3495f70));
+int  t3495f75 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3495f75));
+close(t3495f75);
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3495f70));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3495f70));
+close(t3495f70);
+int  t3526f93 = TEMP_FAILURE_RETRY(open("file134", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3526f93);
+int  t3526f88 = TEMP_FAILURE_RETRY(open("file134", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3526f88, buf, 15056));
+close(t3526f88);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34433108));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 56, 34433138));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2496, 34430976)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34432434));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 50, 34432464));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1795, 34430976)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34431679));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 72, 34431709));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1083, 34430976)); // mmap2
+t3495f75 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3495f75, buf, 1, 0));
+close(t3495f75);
+t3495f75 = TEMP_FAILURE_RETRY(open("file31", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3495f75, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3495f75, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3495f75, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3495f75, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3495f75, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3495f75, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3495f75, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3495f75, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3495f75, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3495f75, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3495f75, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3495f75));
+int  t3495f86 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3495f86));
+close(t3495f86);
+TEMP_FAILURE_RETRY(pwrite(t3495f75, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3495f75));
+TEMP_FAILURE_RETRY(pwrite(t3495f75, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3495f75));
+close(t3495f75);
+int  t3499f74 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f74, buf, 1, 0));
+close(t3499f74);
+t3499f74 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f74, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f74, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f74, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f74, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f74, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f74, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f74, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f74, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f74, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f74, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f74, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f74));
+int  t3499f75 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f75));
+close(t3499f75);
+TEMP_FAILURE_RETRY(pwrite(t3499f74, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f74));
+TEMP_FAILURE_RETRY(pwrite(t3499f74, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f74));
+close(t3499f74);
+int  t3526f64 = TEMP_FAILURE_RETRY(open("file135", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3526f64);
+t3526f64 = TEMP_FAILURE_RETRY(open("file135", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3526f64, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3526f64, buf, 4873));
+close(t3526f64);
+int  t3526f90 = TEMP_FAILURE_RETRY(open("file136", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3526f90);
+t3526f90 = TEMP_FAILURE_RETRY(open("file136", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3526f90, buf, 4199));
+close(t3526f90);
+int  t3499f90 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f90, buf, 1, 0));
+close(t3499f90);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35511105));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 28, 35511135));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3217, 35508224)); // mmap2
+t3499f90 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35511441));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 40, 35511471));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 512));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3780, 35508224)); // mmap2
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35512004));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 33, 35512034));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4299, 35508224)); // mmap2
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f90, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f90));
+int  t3499f92 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f92));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35513993));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 34, 35514023));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2120, 35512320)); // mmap2
+close(t3499f92);
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f90));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35513539));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 37, 35513569));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1673, 35512320)); // mmap2
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f90));
+close(t3499f90);
+t3499f90 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f90, buf, 1, 0));
+close(t3499f90);
+t3499f90 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f90, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f90));
+t3499f92 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f92));
+close(t3499f92);
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f90));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f90));
+close(t3499f90);
+t3499f90 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f90, buf, 1, 0));
+close(t3499f90);
+t3499f90 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f90, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f90));
+t3499f92 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f92));
+close(t3499f92);
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f90));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f90));
+close(t3499f90);
+int  t3495f72 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3495f72, buf, 1, 0));
+close(t3495f72);
+int  t3499f84 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f84, buf, 1, 0));
+close(t3499f84);
+t3499f72 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4096, 516));
+int  t3495f84 = TEMP_FAILURE_RETRY(open("file31", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3495f84, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3495f84, buf, 4, 512));
+TEMP_FAILURE_RETRY(pread(t3499f72, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f72));
+TEMP_FAILURE_RETRY(pwrite(t3495f84, buf, 4096, 516));
+int  t3499f88 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f88));
+TEMP_FAILURE_RETRY(pwrite(t3495f84, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3495f84, buf, 4, 4616));
+close(t3499f88);
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 12, 0));
+TEMP_FAILURE_RETRY(pwrite(t3495f84, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(fdatasync(t3499f72));
+TEMP_FAILURE_RETRY(pwrite(t3495f84, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3495f84, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3495f84, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3495f84, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3495f84, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3495f84));
+TEMP_FAILURE_RETRY(pwrite(t3499f72, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f72));
+int  t3495f88 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31156572));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 58, 31156602));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3099, 31154176)); // mmap2
+TEMP_FAILURE_RETRY(fdatasync(t3495f88));
+close(t3499f72);
+close(t3495f88);
+TEMP_FAILURE_RETRY(pwrite(t3495f84, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3495f84));
+TEMP_FAILURE_RETRY(pwrite(t3495f84, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3495f84));
+close(t3495f84);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34907552));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 39, 34907582));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2551, 34906112)); // mmap2
+int  t3495f66 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3495f66, buf, 1, 0));
+close(t3495f66);
+t3495f66 = TEMP_FAILURE_RETRY(open("file31", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3495f66, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3495f66, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3495f66, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3495f66, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3495f66, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3495f66, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3495f66, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3495f66, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3495f66, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3495f66, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3495f66, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3495f66));
+t3495f72 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3495f72));
+close(t3495f72);
+TEMP_FAILURE_RETRY(pwrite(t3495f66, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3495f66));
+TEMP_FAILURE_RETRY(pwrite(t3495f66, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3495f66));
+close(t3495f66);
+t3499f66 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f66, buf, 1, 0));
+close(t3499f66);
+t3499f66 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f66, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f66));
+int  t3499f70 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f70));
+close(t3499f70);
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f66));
+TEMP_FAILURE_RETRY(pwrite(t3499f66, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f66));
+close(t3499f66);
+int  t3526f66 = TEMP_FAILURE_RETRY(open("file137", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3526f66, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3526f66, buf, 16384));
+close(t3526f66);
+int  t3505f66 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3505f66, buf, 1, 0));
+close(t3505f66);
+t3505f66 = TEMP_FAILURE_RETRY(open("file138", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+t3526f70 = TEMP_FAILURE_RETRY(open("file139", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3526f70, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3526f70, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3526f70, buf, 16384));
+close(t3526f70);
+TEMP_FAILURE_RETRY(read(t3505f66, buf, 10432));
+TEMP_FAILURE_RETRY(read(t3505f66, buf, 4464));
+t3495f70 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3495f70, buf, 1, 0));
+close(t3495f70);
+t3495f70 = TEMP_FAILURE_RETRY(open("file31", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3495f70, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3495f70));
+t3495f72 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3495f72));
+close(t3495f72);
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3495f70));
+TEMP_FAILURE_RETRY(pwrite(t3495f70, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3495f70));
+close(t3495f70);
+TEMP_FAILURE_RETRY(read(t3505f66, buf, 10592));
+int  t3533f70 = TEMP_FAILURE_RETRY(open("file140", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3533f70);
+t3533f70 = TEMP_FAILURE_RETRY(open("file140", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3533f70, buf, 4042));
+close(t3533f70);
+TEMP_FAILURE_RETRY(read(t3505f66, buf, 9664));
+TEMP_FAILURE_RETRY(read(t3505f66, buf, 23656));
+t3533f70 = TEMP_FAILURE_RETRY(open("file141", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3533f70);
+t3526f70 = TEMP_FAILURE_RETRY(open("file142", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+int  t3533f72 = TEMP_FAILURE_RETRY(open("file141", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+close(t3526f70);
+t3526f70 = TEMP_FAILURE_RETRY(open("file142", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3526f70, buf, 5057));
+TEMP_FAILURE_RETRY(read(t3533f72, buf, 4595));
+close(t3526f70);
+close(t3533f72);
+TEMP_FAILURE_RETRY(read(t3505f66, buf, 19744));
+TEMP_FAILURE_RETRY(read(t3505f66, buf, 9344));
+t3499f70 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f70, buf, 1, 0));
+close(t3499f70);
+t3499f70 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f70, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f70, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f70, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f70, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f70, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f70, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f70, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f70, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f70, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f70, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f70, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f70));
+TEMP_FAILURE_RETRY(read(t3505f66, buf, 24672));
+t3499f72 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f72));
+close(t3499f72);
+TEMP_FAILURE_RETRY(pwrite(t3499f70, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f70));
+TEMP_FAILURE_RETRY(pwrite(t3499f70, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f70));
+close(t3499f70);
+TEMP_FAILURE_RETRY(read(t3505f66, buf, 7584));
+TEMP_FAILURE_RETRY(read(t3505f66, buf, 10736));
+close(t3505f66);
+t3505f66 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3505f66, buf, 1, 0));
+close(t3505f66);
+t3505f66 = TEMP_FAILURE_RETRY(open("file31", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 16928));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4096, 16932));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 21028));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 21032));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4096, 21036));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 25132));
+TEMP_FAILURE_RETRY(pread(t3505f66, buf, 8, 25600));
+TEMP_FAILURE_RETRY(fdatasync(t3505f66));
+int  t3505f70 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3505f70));
+close(t3505f70);
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3505f66));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3505f66));
+close(t3505f66);
+t3505f66 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3505f66, buf, 1, 0));
+close(t3505f66);
+t3505f66 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3505f66, buf, 1, 0));
+close(t3505f66);
+t3505f66 = TEMP_FAILURE_RETRY(open("file31", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3505f66, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3505f66));
+t3505f70 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3505f70));
+close(t3505f70);
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3505f66));
+TEMP_FAILURE_RETRY(pwrite(t3505f66, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3505f66));
+close(t3505f66);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 36227657));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 38, 36227687));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3166, 36225024)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 30377994));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 33, 30378024));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4545, 30375936)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35333764));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 45, 35333794));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3019, 35332096)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34435036));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 44, 34435066));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 324, 34435072)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34742552));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 42, 34742582));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 602, 34742272)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31308722));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 42, 31308752));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3902, 31305728)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31307465));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 46, 31307495));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2994, 31305728)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31306529));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 41, 31306559));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1737, 31305728)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34261624));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 49, 34261654));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2993, 34258944)); // mmap2
+int  t3533f91 = TEMP_FAILURE_RETRY(open("file143", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3533f91);
+t3533f91 = TEMP_FAILURE_RETRY(open("file143", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31210525));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 44, 31210555));
+TEMP_FAILURE_RETRY(read(t3533f91, buf, 16384));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3673, 31207424)); // mmap2
+TEMP_FAILURE_RETRY(read(t3533f91, buf, 2024));
+close(t3533f91);
+int  t3499f91 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f91, buf, 1, 0));
+close(t3499f91);
+t3499f91 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f91, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f91, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f91, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f91, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f91, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f91, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f91, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f91, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f91, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f91, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f91, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f91));
+int  t3499f93 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f93));
+close(t3499f93);
+TEMP_FAILURE_RETRY(pwrite(t3499f91, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f91));
+TEMP_FAILURE_RETRY(pwrite(t3499f91, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f91));
+close(t3499f91);
+int  t3505f84 = TEMP_FAILURE_RETRY(open("file31", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3505f84, buf, 1, 0));
+close(t3505f84);
+t3505f84 = TEMP_FAILURE_RETRY(open("file31", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3505f84, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3505f84, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3505f84, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3505f84, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3505f84, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3505f84, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3505f84, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3505f84, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3505f84, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3505f84, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3505f84, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3505f84));
+int  t3505f90 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3505f90));
+close(t3505f90);
+TEMP_FAILURE_RETRY(pwrite(t3505f84, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3505f84));
+TEMP_FAILURE_RETRY(pwrite(t3505f84, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3505f84));
+close(t3505f84);
+int  t3533f102 = TEMP_FAILURE_RETRY(open("file144", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3533f102);
+t3533f72 = TEMP_FAILURE_RETRY(open("file144", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3533f72, buf, 5550));
+close(t3533f72);
+int  t3526f84 = TEMP_FAILURE_RETRY(open("file145", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3526f84);
+int  t3526f101 = TEMP_FAILURE_RETRY(open("file145", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3526f101, buf, 3612));
+close(t3526f101);
+t3526f90 = TEMP_FAILURE_RETRY(open("file146", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3526f90);
+t3526f90 = TEMP_FAILURE_RETRY(open("file146", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3526f90, buf, 5414));
+int  t3533f96 = TEMP_FAILURE_RETRY(open("file147", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3533f96);
+t3533f96 = TEMP_FAILURE_RETRY(open("file147", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+close(t3526f90);
+TEMP_FAILURE_RETRY(read(t3533f96, buf, 3834));
+close(t3533f96);
+int  t3519f90 = TEMP_FAILURE_RETRY(open("file148", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3519f90);
+t3519f90 = TEMP_FAILURE_RETRY(open("file148", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3519f90, buf, 3461));
+int  t3526f96 = TEMP_FAILURE_RETRY(open("file149", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3526f96);
+close(t3519f90);
+t3526f90 = TEMP_FAILURE_RETRY(open("file149", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3526f90, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3526f90, buf, 12766));
+close(t3526f90);
+int  t3533f90 = TEMP_FAILURE_RETRY(open("file150", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3533f90);
+t3533f90 = TEMP_FAILURE_RETRY(open("file150", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+int  t3505f96 = TEMP_FAILURE_RETRY(open("file151", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 100, 0));
+TEMP_FAILURE_RETRY(read(t3533f90, buf, 10056));
+close(t3533f90);
+t3505f90 = TEMP_FAILURE_RETRY(open("file152", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3505f90, buf, 1, 0));
+close(t3505f90);
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 4096, 0));
+t3505f90 = TEMP_FAILURE_RETRY(open("file152", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3505f90, buf, 1, 0));
+close(t3505f90);
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 16, 24));
+t3505f90 = TEMP_FAILURE_RETRY(open("file152", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3505f90, buf, 1, 0));
+close(t3505f90);
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 4096, 8192));
+t3505f90 = TEMP_FAILURE_RETRY(open("file152", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3505f90, buf, 1, 0));
+close(t3505f90);
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 16, 24));
+t3505f90 = TEMP_FAILURE_RETRY(open("file152", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+int  t3533f99 = TEMP_FAILURE_RETRY(open("file153", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+close(t3533f99);
+TEMP_FAILURE_RETRY(pread(t3505f90, buf, 1, 0));
+close(t3505f90);
+t3533f90 = TEMP_FAILURE_RETRY(open("file153", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 16, 24));
+TEMP_FAILURE_RETRY(read(t3533f90, buf, 13271));
+close(t3533f90);
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 4096, 16384));
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 4096, 12288));
+int  t3505f99 = TEMP_FAILURE_RETRY(open("file152", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3505f99, buf, 1, 0));
+close(t3505f99);
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 4096, 20480));
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 4096, 147456));
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 4096, 151552));
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 4096, 196608));
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 4096, 253952));
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 4096, 303104));
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 4096, 335872));
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 4096, 450560));
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 4096, 495616));
+t3505f99 = TEMP_FAILURE_RETRY(open("file152", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3505f99, buf, 1, 0));
+close(t3505f99);
+TEMP_FAILURE_RETRY(pread(t3505f96, buf, 16, 24));
+t3499f90 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f90, buf, 1, 0));
+close(t3499f90);
+t3499f90 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f90, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f90));
+int  t3499f97 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f97));
+close(t3499f97);
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f90));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f90));
+close(t3499f90);
+t3499f90 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f90, buf, 1, 0));
+close(t3499f90);
+t3499f90 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f90, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f90));
+t3499f92 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f92));
+close(t3499f92);
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f90));
+TEMP_FAILURE_RETRY(pwrite(t3499f90, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f90));
+close(t3499f90);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34438470));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 63, 34438500));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3681, 34435072)); // mmap2
+int  t3576f95 = TEMP_FAILURE_RETRY(open("file152", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3576f95, buf, 1, 0));
+close(t3576f95);
+t3499f92 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f92, buf, 1, 0));
+close(t3499f92);
+t3499f92 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f92, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f92));
+int  t3499f95 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f95));
+close(t3499f95);
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f92));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f92));
+close(t3499f92);
+t3499f92 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f92, buf, 1, 0));
+close(t3499f92);
+t3499f92 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f92, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f92));
+t3499f95 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f95));
+close(t3499f95);
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f92));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 31156572));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 58, 31156602));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3099, 31154176)); // mmap2
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f92));
+close(t3499f92);
+t3576f95 = TEMP_FAILURE_RETRY(open("file152", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3576f95, buf, 1, 0));
+close(t3576f95);
+int  t3499f100 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f100, buf, 1, 0));
+close(t3499f100);
+t3499f100 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f100, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f100));
+int  t3499f106 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f106));
+close(t3499f106);
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f100));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f100));
+close(t3499f100);
+t3499f100 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f100, buf, 1, 0));
+close(t3499f100);
+t3499f100 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f100, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f100));
+int  t3499f105 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f105));
+close(t3499f105);
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f100));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f100));
+close(t3499f100);
+t3499f100 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f100, buf, 1, 0));
+close(t3499f100);
+t3499f100 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f100, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f100));
+t3499f105 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f105));
+close(t3499f105);
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f100));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f100));
+close(t3499f100);
+t3499f100 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f100, buf, 1, 0));
+close(t3499f100);
+t3499f100 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f100, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f100));
+t3499f105 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f105));
+close(t3499f105);
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f100));
+TEMP_FAILURE_RETRY(pwrite(t3499f100, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f100));
+close(t3499f100);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35636928));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 60, 35636958));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2062, 35635200)); // mmap2
+t3499f84 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f84, buf, 1, 0));
+close(t3499f84);
+int  t3499f27 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f27, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f27, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f27, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f27, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f27, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f27, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f27, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f27, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f27, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f27, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f27, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f27, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f27, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f27, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f27));
+t3499f84 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f84));
+close(t3499f84);
+TEMP_FAILURE_RETRY(pwrite(t3499f27, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f27));
+TEMP_FAILURE_RETRY(pwrite(t3499f27, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f27));
+close(t3499f27);
+t3499f27 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f27, buf, 1, 0));
+close(t3499f27);
+t3499f92 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f92, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f92));
+t3499f97 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f97));
+close(t3499f97);
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f92));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f92));
+close(t3499f92);
+t3499f92 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f92, buf, 1, 0));
+close(t3499f92);
+t3499f92 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3499f92, buf, 8, 17408));
+TEMP_FAILURE_RETRY(fdatasync(t3499f92));
+t3499f97 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f97));
+close(t3499f97);
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f92));
+TEMP_FAILURE_RETRY(pwrite(t3499f92, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f92));
+close(t3499f92);
+int  t3545f92 = TEMP_FAILURE_RETRY(open("file154", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 100, 0));
+int  t3545f97 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f97, buf, 1, 0));
+close(t3545f97);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 4096, 0));
+t3545f97 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f97, buf, 1, 0));
+close(t3545f97);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+t3545f97 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f97, buf, 1, 0));
+close(t3545f97);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 4096, 8192));
+t3545f97 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f97, buf, 1, 0));
+close(t3545f97);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34965811));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 36, 34965841));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3053, 34963456)); // mmap2
+t3545f97 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f97, buf, 1, 0));
+close(t3545f97);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 4096, 16384));
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 4096, 12288));
+t3545f97 = TEMP_FAILURE_RETRY(open("file156", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3545f97, buf, 8));
+TEMP_FAILURE_RETRY(read(t3545f97, buf, 1));
+close(t3545f97);
+int  t3545f100 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f100, buf, 1, 0));
+close(t3545f100);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 4096, 24576));
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 4096, 20480));
+t3545f97 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f97, buf, 1, 0));
+close(t3545f97);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+t3545f97 = TEMP_FAILURE_RETRY(open("file155", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3545f97, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3545f97));
+t3545f100 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3545f100));
+close(t3545f100);
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3545f97));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 0));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 20480));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 24576));
+TEMP_FAILURE_RETRY(fdatasync(t3545f92));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3545f97));
+close(t3545f97);
+int  t3545f104 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f104, buf, 1, 0));
+close(t3545f104);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+int  t3545f29 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f29, buf, 1, 0));
+close(t3545f29);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+t3545f97 = TEMP_FAILURE_RETRY(open("file155", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3545f97, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3545f97));
+t3545f29 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3545f29));
+close(t3545f29);
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3545f97));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 0));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 20480));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 24576));
+TEMP_FAILURE_RETRY(fdatasync(t3545f92));
+TEMP_FAILURE_RETRY(pwrite(t3545f97, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3545f97));
+close(t3545f97);
+int  t3575f29 = TEMP_FAILURE_RETRY(open("file16", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3575f29, buf, 17344));
+close(t3575f29);
+t3545f97 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f97, buf, 1, 0));
+close(t3545f97);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+t3545f29 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f29, buf, 1, 0));
+close(t3545f29);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+t3545f29 = TEMP_FAILURE_RETRY(open("file155", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3545f29, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3545f29));
+t3545f97 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3545f97));
+close(t3545f97);
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3545f29));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 0));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 20480));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 24576));
+TEMP_FAILURE_RETRY(fdatasync(t3545f92));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3545f29));
+close(t3545f29);
+int  t3499f26 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f26, buf, 1, 0));
+close(t3499f26);
+t3499f26 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f26, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f26, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f26, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f26, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f26, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f26, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f26, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f26, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f26, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f26, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f26, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f26));
+t3499f97 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f97));
+close(t3499f97);
+TEMP_FAILURE_RETRY(pwrite(t3499f26, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f26));
+TEMP_FAILURE_RETRY(pwrite(t3499f26, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f26));
+close(t3499f26);
+t3499f26 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f26, buf, 1, 0));
+close(t3499f26);
+int  t3499f28 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f28, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f28));
+t3499f97 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f97));
+close(t3499f97);
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f28));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f28));
+close(t3499f28);
+t3545f97 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f97, buf, 1, 0));
+close(t3545f97);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+int  t3545f90 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f90, buf, 1, 0));
+close(t3545f90);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 4096, 28672));
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 4096, 36864));
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 4096, 40960));
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 4096, 45056));
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 4096, 49152));
+t3545f90 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f90, buf, 1, 0));
+close(t3545f90);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+t3545f90 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f90, buf, 1, 0));
+close(t3545f90);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+t3545f29 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f29, buf, 1, 0));
+close(t3545f29);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+t3545f29 = TEMP_FAILURE_RETRY(open("file155", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3545f29, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3545f29));
+t3545f90 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3545f90));
+close(t3545f90);
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3545f29));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 0));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 20480));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 24576));
+TEMP_FAILURE_RETRY(fdatasync(t3545f92));
+TEMP_FAILURE_RETRY(pwrite(t3545f29, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3545f29));
+close(t3545f29);
+int  t3545f84 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f84, buf, 1, 0));
+close(t3545f84);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+int  t3584f84 = TEMP_FAILURE_RETRY(open("file157", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 100, 0));
+int  t3584f90 = TEMP_FAILURE_RETRY(open("file158", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3584f90, buf, 1, 0));
+close(t3584f90);
+t3545f90 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 4096, 0));
+TEMP_FAILURE_RETRY(pread(t3545f90, buf, 1, 0));
+close(t3545f90);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+t3545f90 = TEMP_FAILURE_RETRY(open("file155", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3545f90, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3545f90, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3545f90, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3545f90, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3545f90, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3545f90, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3545f90, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3545f90, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3545f90, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3545f90, buf, 4, 12820));
+int  t3584f99 = TEMP_FAILURE_RETRY(open("file158", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f90, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3545f90));
+TEMP_FAILURE_RETRY(pread(t3584f99, buf, 1, 0));
+close(t3584f99);
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 16, 24));
+int  t3545f99 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3545f99));
+close(t3545f99);
+TEMP_FAILURE_RETRY(pwrite(t3545f90, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3545f90));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 0));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 20480));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 24576));
+TEMP_FAILURE_RETRY(fdatasync(t3545f92));
+TEMP_FAILURE_RETRY(pwrite(t3545f90, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3545f90));
+close(t3545f90);
+int  t3584f29 = TEMP_FAILURE_RETRY(open("file158", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3584f29, buf, 1, 0));
+close(t3584f29);
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 4096, 8192));
+int  t3584f27 = TEMP_FAILURE_RETRY(open("file158", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3584f27, buf, 1, 0));
+close(t3584f27);
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 16, 24));
+int  t3545f95 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+t3584f99 = TEMP_FAILURE_RETRY(open("file158", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3545f95, buf, 1, 0));
+TEMP_FAILURE_RETRY(pread(t3584f99, buf, 1, 0));
+close(t3545f95);
+close(t3584f99);
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 4096, 16384));
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 4096, 12288));
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 4096, 32768));
+t3545f99 = TEMP_FAILURE_RETRY(open("file155", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 4, 8716));
+int  t3584f95 = TEMP_FAILURE_RETRY(open("file159", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3584f95, buf, 8));
+TEMP_FAILURE_RETRY(read(t3584f95, buf, 1));
+close(t3584f95);
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 4, 12824));
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 4096, 12828));
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 4, 16924));
+TEMP_FAILURE_RETRY(pread(t3545f92, buf, 4096, 4096));
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 4, 16928));
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 4096, 16932));
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 4, 21028));
+int  t3584f101 = TEMP_FAILURE_RETRY(open("file158", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3584f101, buf, 1, 0));
+close(t3584f101);
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 4096, 40960));
+t3584f101 = TEMP_FAILURE_RETRY(open("file158", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3584f101, buf, 1, 0));
+close(t3584f101);
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 4096, 20480));
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 4096, 45056));
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 4096, 49152));
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 4096, 53248));
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 4096, 57344));
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 4096, 61440));
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 4096, 65536));
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 4096, 69632));
+t3584f101 = TEMP_FAILURE_RETRY(open("file158", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3584f101, buf, 1, 0));
+close(t3584f101);
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3584f84, buf, 4096, 32768));
+TEMP_FAILURE_RETRY(pread(t3545f99, buf, 8, 21504));
+TEMP_FAILURE_RETRY(fdatasync(t3545f99));
+t3545f95 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3545f95));
+close(t3545f95);
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3545f99));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 0));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 4096));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 28672));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 32768));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 49152));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 53248));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 57344));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 61440));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 65536));
+TEMP_FAILURE_RETRY(pwrite(t3545f92, buf, 4096, 69632));
+TEMP_FAILURE_RETRY(fdatasync(t3545f92));
+TEMP_FAILURE_RETRY(pwrite(t3545f99, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3545f99));
+close(t3545f99);
+int  t3581f99 = TEMP_FAILURE_RETRY(open("file155", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3581f99, buf, 1, 0));
+close(t3581f99);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34970937));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 48, 34970967));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 3831, 34967552)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34291385));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 47, 34291415));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 4092, 34287616)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 30004037));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 36, 30004067));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2007, 30003200)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35001738));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 44, 35001768));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 1840, 35000320)); // mmap2
+t3533f90 = TEMP_FAILURE_RETRY(open("file160", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3533f90, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3533f90, buf, 16384));
+close(t3533f90);
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 1580859));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 1580889));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 60268, 1576960)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 35002160));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 36, 35002190));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2527, 35000320)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 34269564));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 55, 34269594));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 2753, 34267136)); // mmap2
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 30, 1637228));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 31, 1637258));
+TEMP_FAILURE_RETRY(pread(t3455f17, buf, 58435, 1634304)); // mmap2
+t3533f90 = TEMP_FAILURE_RETRY(open("file161", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3533f90, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3533f90, buf, 16384));
+close(t3533f90);
+t3526f90 = TEMP_FAILURE_RETRY(open("file162", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3526f90, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3526f90, buf, 16384));
+close(t3526f90);
+t3526f90 = TEMP_FAILURE_RETRY(open("file163", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3526f90, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3526f90, buf, 16384));
+close(t3526f90);
+t3533f90 = TEMP_FAILURE_RETRY(open("file164", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3533f90, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3533f90, buf, 16384));
+close(t3533f90);
+t3526f90 = TEMP_FAILURE_RETRY(open("file165", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3526f90, buf, 16384));
+TEMP_FAILURE_RETRY(read(t3526f90, buf, 16384));
+close(t3526f90);
+int  t3586f102 = TEMP_FAILURE_RETRY(open("file166", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3586f102);
+int  t3586f97 = TEMP_FAILURE_RETRY(open("file167", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3586f97, buf, 8192));
+TEMP_FAILURE_RETRY(read(t3586f97, buf, 8192));
+close(t3586f97);
+int  t3587f95 = TEMP_FAILURE_RETRY(open("file168", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3587f95, buf, 16384));
+close(t3587f95);
+t3499f28 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f28, buf, 1, 0));
+close(t3499f28);
+int  t3496f28 = TEMP_FAILURE_RETRY(open("file169", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE));
+int  t3499f103 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f103, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f103, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f103, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f103, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f103, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f103, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f103, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f103, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f103, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f103, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f103, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f103));
+t3499f105 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f105));
+TEMP_FAILURE_RETRY(read(t3496f28, buf, 8188));
+close(t3499f105);
+TEMP_FAILURE_RETRY(pwrite(t3499f103, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f103));
+TEMP_FAILURE_RETRY(read(t3496f28, buf, 3166));
+TEMP_FAILURE_RETRY(pwrite(t3499f103, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f103));
+close(t3499f103);
+TEMP_FAILURE_RETRY(fsync(t3496f28));
+t3499f106 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f106, buf, 1, 0));
+close(t3499f106);
+close(t3496f28);
+t3499f28 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f28, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f28));
+t3499f105 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f105));
+close(t3499f105);
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f28));
+TEMP_FAILURE_RETRY(pwrite(t3499f28, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f28));
+close(t3499f28);
+int  t3541f103 = TEMP_FAILURE_RETRY(open("file170", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3541f103, buf, 100, 0));
+int  t3541f105 = TEMP_FAILURE_RETRY(open("file171", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3541f105, buf, 1, 0));
+close(t3541f105);
+TEMP_FAILURE_RETRY(pread(t3541f103, buf, 4096, 0));
+t3541f105 = TEMP_FAILURE_RETRY(open("file171", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3541f105, buf, 1, 0));
+close(t3541f105);
+TEMP_FAILURE_RETRY(pread(t3541f103, buf, 16, 24));
+t3541f105 = TEMP_FAILURE_RETRY(open("file171", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3541f105, buf, 1, 0));
+close(t3541f105);
+TEMP_FAILURE_RETRY(pread(t3541f103, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3541f103, buf, 4096, 8192));
+t3541f105 = TEMP_FAILURE_RETRY(open("file171", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3541f105, buf, 1, 0));
+close(t3541f105);
+TEMP_FAILURE_RETRY(pread(t3541f103, buf, 16, 24));
+t3541f105 = TEMP_FAILURE_RETRY(open("file171", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3541f105, buf, 1, 0));
+close(t3541f105);
+TEMP_FAILURE_RETRY(pread(t3541f103, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3541f103, buf, 4096, 16384));
+TEMP_FAILURE_RETRY(pread(t3541f103, buf, 4096, 12288));
+t3541f105 = TEMP_FAILURE_RETRY(open("file172", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3541f105, buf, 8));
+TEMP_FAILURE_RETRY(read(t3541f105, buf, 1));
+close(t3541f105);
+int  t3541f106 = TEMP_FAILURE_RETRY(open("file171", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3541f106, buf, 1, 0));
+close(t3541f106);
+TEMP_FAILURE_RETRY(pread(t3541f103, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3541f103, buf, 4096, 20480));
+int  t3499f107 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f107, buf, 1, 0));
+close(t3499f107);
+t3499f107 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f107, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f107, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f107, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f107, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f107, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f107, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f107, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f107, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f107, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f107, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f107, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f107));
+int  t3499f108 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f108));
+close(t3499f108);
+TEMP_FAILURE_RETRY(pwrite(t3499f107, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f107));
+TEMP_FAILURE_RETRY(pwrite(t3499f107, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f107));
+close(t3499f107);
+t3499f107 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f107, buf, 1, 0));
+close(t3499f107);
+t3499f105 = TEMP_FAILURE_RETRY(open("file18", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pwrite(t3499f105, buf, 512, 0));
+TEMP_FAILURE_RETRY(pwrite(t3499f105, buf, 4, 512));
+TEMP_FAILURE_RETRY(pwrite(t3499f105, buf, 4096, 516));
+TEMP_FAILURE_RETRY(pwrite(t3499f105, buf, 4, 4612));
+TEMP_FAILURE_RETRY(pwrite(t3499f105, buf, 4, 4616));
+TEMP_FAILURE_RETRY(pwrite(t3499f105, buf, 4096, 4620));
+TEMP_FAILURE_RETRY(pwrite(t3499f105, buf, 4, 8716));
+TEMP_FAILURE_RETRY(pwrite(t3499f105, buf, 4, 8720));
+TEMP_FAILURE_RETRY(pwrite(t3499f105, buf, 4096, 8724));
+TEMP_FAILURE_RETRY(pwrite(t3499f105, buf, 4, 12820));
+TEMP_FAILURE_RETRY(pread(t3499f105, buf, 8, 13312));
+TEMP_FAILURE_RETRY(fdatasync(t3499f105));
+t3499f106 = TEMP_FAILURE_RETRY(open("file22", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(fdatasync(t3499f106));
+close(t3499f106);
+TEMP_FAILURE_RETRY(pwrite(t3499f105, buf, 12, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f105));
+TEMP_FAILURE_RETRY(pwrite(t3499f105, buf, 28, 0));
+TEMP_FAILURE_RETRY(fdatasync(t3499f105));
+close(t3499f105);
+int  t3505f106 = TEMP_FAILURE_RETRY(open("file171", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3505f106, buf, 1, 0));
+close(t3505f106);
+int  t3540f107 = TEMP_FAILURE_RETRY(open("file173", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3540f107, buf, 100, 0));
+int  t3540f108 = TEMP_FAILURE_RETRY(open("file174", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3540f108, buf, 1, 0));
+close(t3540f108);
+TEMP_FAILURE_RETRY(pread(t3540f107, buf, 4096, 0));
+int  t3540f105 = TEMP_FAILURE_RETRY(open("file174", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3540f105, buf, 1, 0));
+close(t3540f105);
+TEMP_FAILURE_RETRY(pread(t3540f107, buf, 16, 24));
+t3540f105 = TEMP_FAILURE_RETRY(open("file174", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3540f105, buf, 1, 0));
+close(t3540f105);
+TEMP_FAILURE_RETRY(pread(t3540f107, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3540f107, buf, 4096, 8192));
+t3540f105 = TEMP_FAILURE_RETRY(open("file174", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3540f105, buf, 1, 0));
+close(t3540f105);
+TEMP_FAILURE_RETRY(pread(t3540f107, buf, 16, 24));
+t3540f105 = TEMP_FAILURE_RETRY(open("file174", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3540f105, buf, 1, 0));
+close(t3540f105);
+TEMP_FAILURE_RETRY(pread(t3540f107, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3540f107, buf, 4096, 16384));
+TEMP_FAILURE_RETRY(pread(t3540f107, buf, 4096, 12288));
+t3540f105 = TEMP_FAILURE_RETRY(open("file175", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3540f105, buf, 8));
+TEMP_FAILURE_RETRY(read(t3540f105, buf, 1));
+close(t3540f105);
+int  t3540f106 = TEMP_FAILURE_RETRY(open("file174", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3540f106, buf, 1, 0));
+close(t3540f106);
+TEMP_FAILURE_RETRY(pread(t3540f107, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3540f107, buf, 4096, 24576));
+TEMP_FAILURE_RETRY(pread(t3540f107, buf, 4096, 20480));
+t3540f106 = TEMP_FAILURE_RETRY(open("file174", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3540f106, buf, 1, 0));
+close(t3540f106);
+TEMP_FAILURE_RETRY(pread(t3540f107, buf, 16, 24));
+t3540f106 = TEMP_FAILURE_RETRY(open("file174", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3540f106, buf, 1, 0));
+close(t3540f106);
+TEMP_FAILURE_RETRY(pread(t3540f107, buf, 16, 24));
+int  t3496f105 = TEMP_FAILURE_RETRY(open("file176", O_RDONLY|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC));
+close(t3496f105);
+t3499f108 = TEMP_FAILURE_RETRY(open("file18", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3499f108, buf, 1, 0));
+close(t3499f108);
+int  t3597f108 = TEMP_FAILURE_RETRY(open("file177", O_RDWR|O_CREAT|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3597f108, buf, 100, 0));
+int  t3597f109 = TEMP_FAILURE_RETRY(open("file178", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3597f109, buf, 1, 0));
+close(t3597f109);
+TEMP_FAILURE_RETRY(pread(t3597f108, buf, 4096, 0));
+t3597f109 = TEMP_FAILURE_RETRY(open("file178", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3597f109, buf, 1, 0));
+close(t3597f109);
+TEMP_FAILURE_RETRY(pread(t3597f108, buf, 16, 24));
+t3597f109 = TEMP_FAILURE_RETRY(open("file178", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3597f109, buf, 1, 0));
+close(t3597f109);
+TEMP_FAILURE_RETRY(pread(t3597f108, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3597f108, buf, 4096, 8192));
+t3597f109 = TEMP_FAILURE_RETRY(open("file178", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3597f109, buf, 1, 0));
+close(t3597f109);
+TEMP_FAILURE_RETRY(pread(t3597f108, buf, 16, 24));
+int  t3540f109 = TEMP_FAILURE_RETRY(open("file179", O_RDONLY|O_LARGEFILE));
+TEMP_FAILURE_RETRY(read(t3540f109, buf, 4000));
+int  t3597f110 = TEMP_FAILURE_RETRY(open("file178", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3597f110, buf, 1, 0));
+close(t3597f110);
+TEMP_FAILURE_RETRY(pread(t3597f108, buf, 16, 24));
+close(t3540f109);
+TEMP_FAILURE_RETRY(pread(t3597f108, buf, 4096, 16384));
+TEMP_FAILURE_RETRY(pread(t3597f108, buf, 4096, 12288));
+t3597f109 = TEMP_FAILURE_RETRY(open("file178", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3597f109, buf, 1, 0));
+close(t3597f109);
+TEMP_FAILURE_RETRY(pread(t3597f108, buf, 16, 24));
+int  t3597f111 = TEMP_FAILURE_RETRY(open("file178", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3597f111, buf, 1, 0));
+close(t3597f111);
+TEMP_FAILURE_RETRY(pread(t3597f108, buf, 16, 24));
+TEMP_FAILURE_RETRY(pread(t3597f108, buf, 4096, 24576));
+TEMP_FAILURE_RETRY(pread(t3597f108, buf, 4096, 20480));
+TEMP_FAILURE_RETRY(pread(t3597f108, buf, 4096, 57344));
+int  t3598f111 = TEMP_FAILURE_RETRY(open("file178", O_RDONLY|O_LARGEFILE|O_CLOEXEC));
+TEMP_FAILURE_RETRY(pread(t3598f111, buf, 1, 0));
+close(t3598f111);
+close(t3540f107);
+close(t3541f103);
+close(t3545f92);
+close(t3492f31);
+close(t3505f96);
+close(t3433f17);
+close(t3597f108);
+close(t3584f84);
+close(t3455f17);
+close(t3483f25);
+close(t3483f20);
+
+free(buf);
+return 0;
+}
+
+static status_t CreateFile(const char* name, int len) {
+    int chunk = std::min(len, 65536);
+    int out = -1;
+    std::string buf;
+
+    if (android::vold::ReadRandomBytes(chunk, buf) != OK) {
+        LOG(ERROR) << "Failed to read random data";
+        return -EIO;
+    }
+    if ((out = TEMP_FAILURE_RETRY(open(name, O_WRONLY|O_CREAT|O_TRUNC))) < 0) {
+        PLOG(ERROR) << "Failed to open " << name;
+        return -errno;
+    }
+
+    while (len > 0) {
+        int n = write(out, buf.c_str(), std::min(len, chunk));
+        if (n < 0) {
+            PLOG(ERROR) << "Failed to write";
+            close(out);
+            return -errno;
+        }
+        len -= n;
+    }
+
+    close(out);
+    return OK;
+}
+
+static status_t BenchmarkCreate() {
+status_t res = 0;
+res |= CreateFile("stub", 0);
+
+res |= CreateFile("file115", 0);
+res |= CreateFile("file125", 0);
+res |= CreateFile("file43", 49152);
+res |= CreateFile("file2", 57016320);
+res |= CreateFile("file17", 176128);
+res |= CreateFile("file126", 0);
+res |= CreateFile("file4", 0);
+res |= CreateFile("file175", 9);
+res |= CreateFile("file76", 0);
+res |= CreateFile("file140", 4042);
+res |= CreateFile("file80", 0);
+res |= CreateFile("file139", 49152);
+res |= CreateFile("file50", 32768);
+res |= CreateFile("file179", 4000);
+res |= CreateFile("file144", 5550);
+res |= CreateFile("file138", 130888);
+res |= CreateFile("file28", 3182276);
+res |= CreateFile("file161", 32768);
+res |= CreateFile("file34", 1423);
+res |= CreateFile("file53", 32768);
+res |= CreateFile("file72", 0);
+res |= CreateFile("file55", 16384);
+res |= CreateFile("file54", 39938);
+res |= CreateFile("file129", 3974);
+res |= CreateFile("file107", 0);
+res |= CreateFile("file95", 0);
+res |= CreateFile("file82", 0);
+res |= CreateFile("file27", 53280);
+res |= CreateFile("file167", 16384);
+res |= CreateFile("file9", 24588);
+res |= CreateFile("file123", 0);
+res |= CreateFile("file89", 0);
+res |= CreateFile("file40", 4172);
+res |= CreateFile("file20", 1);
+res |= CreateFile("file151", 499712);
+res |= CreateFile("file106", 0);
+res |= CreateFile("file159", 9);
+res |= CreateFile("file47", 32768);
+res |= CreateFile("file146", 5414);
+res |= CreateFile("file153", 13271);
+res |= CreateFile("file12", 2);
+res |= CreateFile("file137", 32768);
+res |= CreateFile("file157", 73728);
+res |= CreateFile("file172", 9);
+res |= CreateFile("file148", 3461);
+res |= CreateFile("file7", 794976);
+res |= CreateFile("file68", 32768);
+res |= CreateFile("file109", 0);
+res |= CreateFile("file142", 5057);
+res |= CreateFile("file147", 3834);
+res |= CreateFile("file117", 0);
+res |= CreateFile("file94", 0);
+res |= CreateFile("file81", 0);
+res |= CreateFile("file75", 0);
+res |= CreateFile("file111", 0);
+res |= CreateFile("file105", 0);
+res |= CreateFile("file79", 0);
+res |= CreateFile("file65", 32768);
+res |= CreateFile("file135", 21257);
+res |= CreateFile("file124", 0);
+res |= CreateFile("file87", 0);
+res |= CreateFile("file64", 49152);
+res |= CreateFile("file131", 4622);
+res |= CreateFile("file130", 32768);
+res |= CreateFile("file59", 143552);
+res |= CreateFile("file141", 4595);
+res |= CreateFile("file149", 29150);
+res |= CreateFile("file178", 1);
+res |= CreateFile("file163", 32768);
+res |= CreateFile("file67", 32768);
+res |= CreateFile("file155", 21512);
+res |= CreateFile("file156", 9);
+res |= CreateFile("file23", 28700);
+res |= CreateFile("file61", 32768);
+res |= CreateFile("file0", 40464617);
+res |= CreateFile("file39", 32768);
+res |= CreateFile("file145", 3612);
+res |= CreateFile("file70", 32768);
+res |= CreateFile("file69", 32768);
+res |= CreateFile("file24", 94220);
+res |= CreateFile("file57", 32768);
+res |= CreateFile("file104", 0);
+res |= CreateFile("file113", 0);
+res |= CreateFile("file99", 0);
+res |= CreateFile("file120", 0);
+res |= CreateFile("file154", 73728);
+res |= CreateFile("file127", 0);
+res |= CreateFile("file38", 65720);
+res |= CreateFile("file77", 0);
+res |= CreateFile("file85", 0);
+res |= CreateFile("file119", 0);
+res |= CreateFile("file96", 0);
+res |= CreateFile("file91", 0);
+res |= CreateFile("file158", 1);
+res |= CreateFile("file174", 1);
+res |= CreateFile("file48", 32768);
+res |= CreateFile("file33", 32566);
+res |= CreateFile("file83", 0);
+res |= CreateFile("file32", 179192);
+res |= CreateFile("file118", 0);
+res |= CreateFile("file121", 0);
+res |= CreateFile("file101", 0);
+res |= CreateFile("file168", 16384);
+res |= CreateFile("file16", 31392);
+res |= CreateFile("file164", 32768);
+res |= CreateFile("file36", 192544);
+res |= CreateFile("file6", 4636);
+res |= CreateFile("file10", 16484);
+res |= CreateFile("file150", 10056);
+res |= CreateFile("file62", 32768);
+res |= CreateFile("file165", 32768);
+res |= CreateFile("file42", 28736);
+res |= CreateFile("file19", 188416);
+res |= CreateFile("file128", 2991);
+res |= CreateFile("file112", 0);
+res |= CreateFile("file100", 0);
+res |= CreateFile("file103", 0);
+res |= CreateFile("file26", 28676);
+res |= CreateFile("file46", 32768);
+res |= CreateFile("file60", 32768);
+res |= CreateFile("file162", 32768);
+res |= CreateFile("file25", 32872);
+res |= CreateFile("file21", 16384);
+res |= CreateFile("file45", 32768);
+res |= CreateFile("file3", 0);
+res |= CreateFile("file171", 1);
+res |= CreateFile("file15", 2);
+res |= CreateFile("file51", 32768);
+res |= CreateFile("file37", 159752);
+res |= CreateFile("file73", 0);
+res |= CreateFile("file71", 32768);
+res |= CreateFile("file98", 0);
+res |= CreateFile("file74", 0);
+res |= CreateFile("file93", 0);
+res |= CreateFile("file122", 0);
+res |= CreateFile("file143", 18408);
+res |= CreateFile("file8", 20648);
+res |= CreateFile("file152", 1);
+res |= CreateFile("file66", 32768);
+res |= CreateFile("file136", 4199);
+res |= CreateFile("file132", 23233);
+res |= CreateFile("file92", 0);
+res |= CreateFile("file11", 0);
+res |= CreateFile("file86", 0);
+res |= CreateFile("file22", 0);
+res |= CreateFile("file56", 16384);
+res |= CreateFile("file78", 0);
+res |= CreateFile("file41", 32768);
+res |= CreateFile("file110", 0);
+res |= CreateFile("file90", 0);
+res |= CreateFile("file44", 12328);
+res |= CreateFile("file63", 49152);
+res |= CreateFile("file116", 0);
+res |= CreateFile("file29", 1035);
+res |= CreateFile("file35", 118788);
+res |= CreateFile("file170", 24576);
+res |= CreateFile("file30", 98304);
+res |= CreateFile("file14", 0);
+res |= CreateFile("file160", 32768);
+res |= CreateFile("file176", 0);
+res |= CreateFile("file1", 471040);
+res |= CreateFile("file108", 0);
+res |= CreateFile("file173", 28672);
+res |= CreateFile("file18", 17416);
+res |= CreateFile("file134", 15056);
+res |= CreateFile("file31", 25608);
+res |= CreateFile("file97", 0);
+res |= CreateFile("file84", 0);
+res |= CreateFile("file114", 0);
+res |= CreateFile("file88", 0);
+res |= CreateFile("file102", 0);
+res |= CreateFile("file58", 32768);
+res |= CreateFile("file52", 49152);
+res |= CreateFile("file13", 0);
+res |= CreateFile("file5", 41168);
+res |= CreateFile("file133", 13332);
+res |= CreateFile("file169", 11354);
+res |= CreateFile("file166", 0);
+res |= CreateFile("file49", 32768);
+res |= CreateFile("file177", 61440);
+
+return res;
+}
+
+static status_t BenchmarkDestroy() {
+status_t res = 0;
+res |= unlink("stub");
+
+res |= unlink("file115");
+res |= unlink("file125");
+res |= unlink("file43");
+res |= unlink("file2");
+res |= unlink("file17");
+res |= unlink("file126");
+res |= unlink("file4");
+res |= unlink("file175");
+res |= unlink("file76");
+res |= unlink("file140");
+res |= unlink("file80");
+res |= unlink("file139");
+res |= unlink("file50");
+res |= unlink("file179");
+res |= unlink("file144");
+res |= unlink("file138");
+res |= unlink("file28");
+res |= unlink("file161");
+res |= unlink("file34");
+res |= unlink("file53");
+res |= unlink("file72");
+res |= unlink("file55");
+res |= unlink("file54");
+res |= unlink("file129");
+res |= unlink("file107");
+res |= unlink("file95");
+res |= unlink("file82");
+res |= unlink("file27");
+res |= unlink("file167");
+res |= unlink("file9");
+res |= unlink("file123");
+res |= unlink("file89");
+res |= unlink("file40");
+res |= unlink("file20");
+res |= unlink("file151");
+res |= unlink("file106");
+res |= unlink("file159");
+res |= unlink("file47");
+res |= unlink("file146");
+res |= unlink("file153");
+res |= unlink("file12");
+res |= unlink("file137");
+res |= unlink("file157");
+res |= unlink("file172");
+res |= unlink("file148");
+res |= unlink("file7");
+res |= unlink("file68");
+res |= unlink("file109");
+res |= unlink("file142");
+res |= unlink("file147");
+res |= unlink("file117");
+res |= unlink("file94");
+res |= unlink("file81");
+res |= unlink("file75");
+res |= unlink("file111");
+res |= unlink("file105");
+res |= unlink("file79");
+res |= unlink("file65");
+res |= unlink("file135");
+res |= unlink("file124");
+res |= unlink("file87");
+res |= unlink("file64");
+res |= unlink("file131");
+res |= unlink("file130");
+res |= unlink("file59");
+res |= unlink("file141");
+res |= unlink("file149");
+res |= unlink("file178");
+res |= unlink("file163");
+res |= unlink("file67");
+res |= unlink("file155");
+res |= unlink("file156");
+res |= unlink("file23");
+res |= unlink("file61");
+res |= unlink("file0");
+res |= unlink("file39");
+res |= unlink("file145");
+res |= unlink("file70");
+res |= unlink("file69");
+res |= unlink("file24");
+res |= unlink("file57");
+res |= unlink("file104");
+res |= unlink("file113");
+res |= unlink("file99");
+res |= unlink("file120");
+res |= unlink("file154");
+res |= unlink("file127");
+res |= unlink("file38");
+res |= unlink("file77");
+res |= unlink("file85");
+res |= unlink("file119");
+res |= unlink("file96");
+res |= unlink("file91");
+res |= unlink("file158");
+res |= unlink("file174");
+res |= unlink("file48");
+res |= unlink("file33");
+res |= unlink("file83");
+res |= unlink("file32");
+res |= unlink("file118");
+res |= unlink("file121");
+res |= unlink("file101");
+res |= unlink("file168");
+res |= unlink("file16");
+res |= unlink("file164");
+res |= unlink("file36");
+res |= unlink("file6");
+res |= unlink("file10");
+res |= unlink("file150");
+res |= unlink("file62");
+res |= unlink("file165");
+res |= unlink("file42");
+res |= unlink("file19");
+res |= unlink("file128");
+res |= unlink("file112");
+res |= unlink("file100");
+res |= unlink("file103");
+res |= unlink("file26");
+res |= unlink("file46");
+res |= unlink("file60");
+res |= unlink("file162");
+res |= unlink("file25");
+res |= unlink("file21");
+res |= unlink("file45");
+res |= unlink("file3");
+res |= unlink("file171");
+res |= unlink("file15");
+res |= unlink("file51");
+res |= unlink("file37");
+res |= unlink("file73");
+res |= unlink("file71");
+res |= unlink("file98");
+res |= unlink("file74");
+res |= unlink("file93");
+res |= unlink("file122");
+res |= unlink("file143");
+res |= unlink("file8");
+res |= unlink("file152");
+res |= unlink("file66");
+res |= unlink("file136");
+res |= unlink("file132");
+res |= unlink("file92");
+res |= unlink("file11");
+res |= unlink("file86");
+res |= unlink("file22");
+res |= unlink("file56");
+res |= unlink("file78");
+res |= unlink("file41");
+res |= unlink("file110");
+res |= unlink("file90");
+res |= unlink("file44");
+res |= unlink("file63");
+res |= unlink("file116");
+res |= unlink("file29");
+res |= unlink("file35");
+res |= unlink("file170");
+res |= unlink("file30");
+res |= unlink("file14");
+res |= unlink("file160");
+res |= unlink("file176");
+res |= unlink("file1");
+res |= unlink("file108");
+res |= unlink("file173");
+res |= unlink("file18");
+res |= unlink("file134");
+res |= unlink("file31");
+res |= unlink("file97");
+res |= unlink("file84");
+res |= unlink("file114");
+res |= unlink("file88");
+res |= unlink("file102");
+res |= unlink("file58");
+res |= unlink("file52");
+res |= unlink("file13");
+res |= unlink("file5");
+res |= unlink("file133");
+res |= unlink("file169");
+res |= unlink("file166");
+res |= unlink("file49");
+res |= unlink("file177");
+
+return res;
+}
+
+static std::string BenchmarkIdent() {
+return "r1572:w1001:s285";
+}
+
+}  // namespace vold
+}  // namespace android
diff --git a/CommandListener.cpp b/CommandListener.cpp
index 696e37d..a9a8031 100644
--- a/CommandListener.cpp
+++ b/CommandListener.cpp
@@ -25,8 +25,13 @@
 #include <fs_mgr.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdint.h>
+#include <inttypes.h>
 
 #define LOG_TAG "VoldCmdListener"
+
+#include <base/stringprintf.h>
+#include <cutils/fs.h>
 #include <cutils/log.h>
 
 #include <sysutils/SocketClient.h>
@@ -34,13 +39,15 @@
 
 #include "CommandListener.h"
 #include "VolumeManager.h"
+#include "VolumeBase.h"
 #include "ResponseCode.h"
 #include "Process.h"
 #include "Loop.h"
 #include "Devmapper.h"
 #include "Ext4Crypt.h"
 #include "cryptfs.h"
-#include "fstrim.h"
+#include "MoveTask.h"
+#include "TrimTask.h"
 
 #define DUMP_ARGS 0
 
@@ -51,7 +58,6 @@
     registerCmd(new AsecCmd());
     registerCmd(new ObbCmd());
     registerCmd(new StorageCmd());
-    registerCmd(new CryptfsCmd());
     registerCmd(new FstrimCmd());
 }
 
@@ -87,6 +93,14 @@
 void CommandListener::dumpArgs(int /*argc*/, char ** /*argv*/, int /*argObscure*/) { }
 #endif
 
+int CommandListener::sendGenericOkFail(SocketClient *cli, int cond) {
+    if (!cond) {
+        return cli->sendMsg(ResponseCode::CommandOkay, "Command succeeded", false);
+    } else {
+        return cli->sendMsg(ResponseCode::OperationFailed, "Command failed", false);
+    }
+}
+
 CommandListener::DumpCmd::DumpCmd() :
                  VoldCommand("dump") {
 }
@@ -130,99 +144,135 @@
     }
 
     VolumeManager *vm = VolumeManager::Instance();
-    int rc = 0;
+    std::lock_guard<std::mutex> lock(vm->getLock());
 
-    if (!strcmp(argv[1], "list")) {
-        bool broadcast = argc >= 3 && !strcmp(argv[2], "broadcast");
-        return vm->listVolumes(cli, broadcast);
-    } else if (!strcmp(argv[1], "debug")) {
-        if (argc != 3 || (argc == 3 && (strcmp(argv[2], "off") && strcmp(argv[2], "on")))) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: volume debug <off/on>", false);
-            return 0;
-        }
-        vm->setDebug(!strcmp(argv[2], "on") ? true : false);
-    } else if (!strcmp(argv[1], "mount")) {
-        if (argc != 3) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: volume mount <path>", false);
-            return 0;
-        }
-        rc = vm->mountVolume(argv[2]);
-    } else if (!strcmp(argv[1], "unmount")) {
-        if (argc < 3 || argc > 4 ||
-           ((argc == 4 && strcmp(argv[3], "force")) &&
-            (argc == 4 && strcmp(argv[3], "force_and_revert")))) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: volume unmount <path> [force|force_and_revert]", false);
-            return 0;
+    // TODO: tease out methods not directly related to volumes
+
+    std::string cmd(argv[1]);
+    if (cmd == "reset") {
+        return sendGenericOkFail(cli, vm->reset());
+
+    } else if (cmd == "shutdown") {
+        return sendGenericOkFail(cli, vm->shutdown());
+
+    } else if (cmd == "debug") {
+        return sendGenericOkFail(cli, vm->setDebug(true));
+
+    } else if (cmd == "partition" && argc > 3) {
+        // partition [diskId] [public|private|mixed] [ratio]
+        std::string id(argv[2]);
+        auto disk = vm->findDisk(id);
+        if (disk == nullptr) {
+            return cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown disk", false);
         }
 
-        bool force = false;
-        bool revert = false;
-        if (argc >= 4 && !strcmp(argv[3], "force")) {
-            force = true;
-        } else if (argc >= 4 && !strcmp(argv[3], "force_and_revert")) {
-            force = true;
-            revert = true;
-        }
-        rc = vm->unmountVolume(argv[2], force, revert);
-    } else if (!strcmp(argv[1], "format")) {
-        if (argc < 3 || argc > 4 ||
-            (argc == 4 && strcmp(argv[3], "wipe"))) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: volume format <path> [wipe]", false);
-            return 0;
-        }
-        bool wipe = false;
-        if (argc >= 4 && !strcmp(argv[3], "wipe")) {
-            wipe = true;
-        }
-        rc = vm->formatVolume(argv[2], wipe);
-    } else if (!strcmp(argv[1], "share")) {
-        if (argc != 4) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError,
-                    "Usage: volume share <path> <method>", false);
-            return 0;
-        }
-        rc = vm->shareVolume(argv[2], argv[3]);
-    } else if (!strcmp(argv[1], "unshare")) {
-        if (argc != 4) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError,
-                    "Usage: volume unshare <path> <method>", false);
-            return 0;
-        }
-        rc = vm->unshareVolume(argv[2], argv[3]);
-    } else if (!strcmp(argv[1], "shared")) {
-        bool enabled = false;
-        if (argc != 4) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError,
-                    "Usage: volume shared <path> <method>", false);
-            return 0;
-        }
-
-        if (vm->shareEnabled(argv[2], argv[3], &enabled)) {
-            cli->sendMsg(
-                    ResponseCode::OperationFailed, "Failed to determine share enable state", true);
+        std::string type(argv[3]);
+        if (type == "public") {
+            return sendGenericOkFail(cli, disk->partitionPublic());
+        } else if (type == "private") {
+            return sendGenericOkFail(cli, disk->partitionPrivate());
+        } else if (type == "mixed") {
+            if (argc < 4) {
+                return cli->sendMsg(ResponseCode::CommandSyntaxError, nullptr, false);
+            }
+            int frac = atoi(argv[4]);
+            return sendGenericOkFail(cli, disk->partitionMixed(frac));
         } else {
-            cli->sendMsg(ResponseCode::ShareEnabledResult,
-                    (enabled ? "Share enabled" : "Share disabled"), false);
+            return cli->sendMsg(ResponseCode::CommandSyntaxError, nullptr, false);
         }
-        return 0;
-    } else if (!strcmp(argv[1], "mkdirs")) {
-        if (argc != 3) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: volume mkdirs <path>", false);
-            return 0;
+
+    } else if (cmd == "mkdirs" && argc > 2) {
+        // mkdirs [path]
+        return sendGenericOkFail(cli, vm->mkdirs(argv[2]));
+
+    } else if (cmd == "user_added" && argc > 3) {
+        // user_added [user] [serial]
+        return sendGenericOkFail(cli, vm->onUserAdded(atoi(argv[2]), atoi(argv[3])));
+
+    } else if (cmd == "user_removed" && argc > 2) {
+        // user_removed [user]
+        return sendGenericOkFail(cli, vm->onUserRemoved(atoi(argv[2])));
+
+    } else if (cmd == "user_started" && argc > 2) {
+        // user_started [user]
+        return sendGenericOkFail(cli, vm->onUserStarted(atoi(argv[2])));
+
+    } else if (cmd == "user_stopped" && argc > 2) {
+        // user_stopped [user]
+        return sendGenericOkFail(cli, vm->onUserStopped(atoi(argv[2])));
+
+    } else if (cmd == "mount" && argc > 2) {
+        // mount [volId] [flags] [user]
+        std::string id(argv[2]);
+        auto vol = vm->findVolume(id);
+        if (vol == nullptr) {
+            return cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown volume", false);
         }
-        rc = vm->mkdirs(argv[2]);
-    } else {
-        cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown volume cmd", false);
+
+        int mountFlags = (argc > 3) ? atoi(argv[3]) : 0;
+        userid_t mountUserId = (argc > 4) ? atoi(argv[4]) : -1;
+
+        vol->setMountFlags(mountFlags);
+        vol->setMountUserId(mountUserId);
+
+        int res = vol->mount();
+        if (mountFlags & android::vold::VolumeBase::MountFlags::kPrimary) {
+            vm->setPrimary(vol);
+        }
+        return sendGenericOkFail(cli, res);
+
+    } else if (cmd == "unmount" && argc > 2) {
+        // unmount [volId]
+        std::string id(argv[2]);
+        auto vol = vm->findVolume(id);
+        if (vol == nullptr) {
+            return cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown volume", false);
+        }
+
+        return sendGenericOkFail(cli, vol->unmount());
+
+    } else if (cmd == "format" && argc > 3) {
+        // format [volId] [fsType|auto]
+        std::string id(argv[2]);
+        std::string fsType(argv[3]);
+        auto vol = vm->findVolume(id);
+        if (vol == nullptr) {
+            return cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown volume", false);
+        }
+
+        return sendGenericOkFail(cli, vol->format(fsType));
+
+    } else if (cmd == "move_storage" && argc > 3) {
+        // move_storage [fromVolId] [toVolId]
+        auto fromVol = vm->findVolume(std::string(argv[2]));
+        auto toVol = vm->findVolume(std::string(argv[3]));
+        if (fromVol == nullptr || toVol == nullptr) {
+            return cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown volume", false);
+        }
+
+        (new android::vold::MoveTask(fromVol, toVol))->start();
+        return sendGenericOkFail(cli, 0);
+
+    } else if (cmd == "benchmark" && argc > 2) {
+        // benchmark [volId]
+        std::string id(argv[2]);
+        nsecs_t res = vm->benchmarkPrivate(id);
+        return cli->sendMsg(ResponseCode::CommandOkay,
+                android::base::StringPrintf("%" PRId64, res).c_str(), false);
+
+    } else if (cmd == "forget_partition" && argc > 2) {
+        // forget_partition [partGuid]
+        std::string partGuid(argv[2]);
+        return sendGenericOkFail(cli, vm->forgetPartition(partGuid));
+
+    } else if (cmd == "remount_uid" && argc > 3) {
+        // remount_uid [uid] [none|default|read|write]
+        uid_t uid = atoi(argv[2]);
+        std::string mode(argv[3]);
+        return sendGenericOkFail(cli, vm->remountUid(uid, mode));
     }
 
-    if (!rc) {
-        cli->sendMsg(ResponseCode::CommandOkay, "volume operation succeeded", false);
-    } else {
-        rc = ResponseCode::convertFromErrno();
-        cli->sendMsg(rc, "volume operation failed", true);
-    }
-
-    return 0;
+    return cli->sendMsg(ResponseCode::CommandSyntaxError, nullptr, false);
 }
 
 CommandListener::StorageCmd::StorageCmd() :
@@ -347,8 +397,8 @@
     if (!strcmp(argv[1], "list")) {
         dumpArgs(argc, argv, -1);
 
-        listAsecsInDirectory(cli, Volume::SEC_ASECDIR_EXT);
-        listAsecsInDirectory(cli, Volume::SEC_ASECDIR_INT);
+        listAsecsInDirectory(cli, VolumeManager::SEC_ASECDIR_EXT);
+        listAsecsInDirectory(cli, VolumeManager::SEC_ASECDIR_INT);
     } else if (!strcmp(argv[1], "create")) {
         dumpArgs(argc, argv, 5);
         if (argc != 8) {
@@ -536,238 +586,6 @@
     return 0;
 }
 
-CommandListener::CryptfsCmd::CryptfsCmd() :
-                 VoldCommand("cryptfs") {
-}
-
-static int getType(const char* type)
-{
-    if (!strcmp(type, "default")) {
-        return CRYPT_TYPE_DEFAULT;
-    } else if (!strcmp(type, "password")) {
-        return CRYPT_TYPE_PASSWORD;
-    } else if (!strcmp(type, "pin")) {
-        return CRYPT_TYPE_PIN;
-    } else if (!strcmp(type, "pattern")) {
-        return CRYPT_TYPE_PATTERN;
-    } else {
-        return -1;
-    }
-}
-
-int CommandListener::CryptfsCmd::runCommand(SocketClient *cli,
-                                                      int argc, char **argv) {
-    if ((cli->getUid() != 0) && (cli->getUid() != AID_SYSTEM)) {
-        cli->sendMsg(ResponseCode::CommandNoPermission, "No permission to run cryptfs commands", false);
-        return 0;
-    }
-
-    if (argc < 2) {
-        cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing Argument", false);
-        return 0;
-    }
-
-    int rc = 0;
-
-    if (!strcmp(argv[1], "checkpw")) {
-        if (argc != 3) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: cryptfs checkpw <passwd>", false);
-            return 0;
-        }
-        dumpArgs(argc, argv, 2);
-        rc = cryptfs_check_passwd(argv[2]);
-    } else if (!strcmp(argv[1], "restart")) {
-        if (argc != 2) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: cryptfs restart", false);
-            return 0;
-        }
-        dumpArgs(argc, argv, -1);
-        rc = cryptfs_restart();
-    } else if (!strcmp(argv[1], "cryptocomplete")) {
-        if (argc != 2) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: cryptfs cryptocomplete", false);
-            return 0;
-        }
-        dumpArgs(argc, argv, -1);
-        rc = cryptfs_crypto_complete();
-    } else if (!strcmp(argv[1], "enablecrypto")) {
-        const char* syntax = "Usage: cryptfs enablecrypto <wipe|inplace> "
-                             "default|password|pin|pattern [passwd]";
-        if ( (argc != 4 && argc != 5)
-             || (strcmp(argv[2], "wipe") && strcmp(argv[2], "inplace")) ) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, syntax, false);
-            return 0;
-        }
-        dumpArgs(argc, argv, 4);
-
-        int tries;
-        for (tries = 0; tries < 2; ++tries) {
-            int type = getType(argv[3]);
-            if (type == -1) {
-                cli->sendMsg(ResponseCode::CommandSyntaxError, syntax,
-                             false);
-                return 0;
-            } else if (type == CRYPT_TYPE_DEFAULT) {
-              rc = cryptfs_enable_default(argv[2], /*allow_reboot*/false);
-            } else {
-                rc = cryptfs_enable(argv[2], type, argv[4],
-                                    /*allow_reboot*/false);
-            }
-
-            if (rc == 0) {
-                break;
-            } else if (tries == 0) {
-                Process::killProcessesWithOpenFiles(DATA_MNT_POINT, 2);
-            }
-        }
-    } else if (!strcmp(argv[1], "enablefilecrypto")) {
-        const char* syntax = "Usage: cryptfs enablefilecrypto";
-        if (argc != 2) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, syntax, false);
-            return 0;
-        }
-        dumpArgs(argc, argv, -1);
-        rc = cryptfs_enable_file();
-    } else if (!strcmp(argv[1], "changepw")) {
-        const char* syntax = "Usage: cryptfs changepw "
-                             "default|password|pin|pattern [newpasswd]";
-        const char* password;
-        if (argc == 3) {
-            password = "";
-        } else if (argc == 4) {
-            password = argv[3];
-        } else {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, syntax, false);
-            return 0;
-        }
-        int type = getType(argv[2]);
-        if (type == -1) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, syntax, false);
-            return 0;
-        }
-        SLOGD("cryptfs changepw %s {}", argv[2]);
-        rc = cryptfs_changepw(type, password);
-    } else if (!strcmp(argv[1], "verifypw")) {
-        if (argc != 3) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: cryptfs verifypw <passwd>", false);
-            return 0;
-        }
-        SLOGD("cryptfs verifypw {}");
-        rc = cryptfs_verify_passwd(argv[2]);
-    } else if (!strcmp(argv[1], "getfield")) {
-        char *valbuf;
-        int valbuf_len = PROPERTY_VALUE_MAX;
-
-        if (argc != 3) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: cryptfs getfield <fieldname>", false);
-            return 0;
-        }
-        dumpArgs(argc, argv, -1);
-
-        // Increase the buffer size until it is big enough for the field value stored.
-        while (1) {
-            valbuf = (char*)malloc(valbuf_len);
-            if (valbuf == NULL) {
-                cli->sendMsg(ResponseCode::OperationFailed, "Failed to allocate memory", false);
-                return 0;
-            }
-            rc = cryptfs_getfield(argv[2], valbuf, valbuf_len);
-            if (rc != CRYPTO_GETFIELD_ERROR_BUF_TOO_SMALL) {
-                break;
-            }
-            free(valbuf);
-            valbuf_len *= 2;
-        }
-        if (rc == CRYPTO_GETFIELD_OK) {
-            cli->sendMsg(ResponseCode::CryptfsGetfieldResult, valbuf, false);
-        }
-        free(valbuf);
-    } else if (!strcmp(argv[1], "setfield")) {
-        if (argc != 4) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: cryptfs setfield <fieldname> <value>", false);
-            return 0;
-        }
-        dumpArgs(argc, argv, -1);
-        rc = cryptfs_setfield(argv[2], argv[3]);
-    } else if (!strcmp(argv[1], "mountdefaultencrypted")) {
-        SLOGD("cryptfs mountdefaultencrypted");
-        dumpArgs(argc, argv, -1);
-        rc = cryptfs_mount_default_encrypted();
-    } else if (!strcmp(argv[1], "getpwtype")) {
-        SLOGD("cryptfs getpwtype");
-        dumpArgs(argc, argv, -1);
-        switch(cryptfs_get_password_type()) {
-        case CRYPT_TYPE_PASSWORD:
-            cli->sendMsg(ResponseCode::PasswordTypeResult, "password", false);
-            return 0;
-        case CRYPT_TYPE_PATTERN:
-            cli->sendMsg(ResponseCode::PasswordTypeResult, "pattern", false);
-            return 0;
-        case CRYPT_TYPE_PIN:
-            cli->sendMsg(ResponseCode::PasswordTypeResult, "pin", false);
-            return 0;
-        case CRYPT_TYPE_DEFAULT:
-            cli->sendMsg(ResponseCode::PasswordTypeResult, "default", false);
-            return 0;
-        default:
-          /** @TODO better error and make sure handled by callers */
-            cli->sendMsg(ResponseCode::OpFailedStorageNotFound, "Error", false);
-            return 0;
-        }
-    } else if (!strcmp(argv[1], "getpw")) {
-        SLOGD("cryptfs getpw");
-        dumpArgs(argc, argv, -1);
-        const char* password = cryptfs_get_password();
-        if (password) {
-            char* message = 0;
-            int size = asprintf(&message, "{{sensitive}} %s", password);
-            if (size != -1) {
-                cli->sendMsg(ResponseCode::CommandOkay, message, false);
-                memset(message, 0, size);
-                free (message);
-                return 0;
-            }
-        }
-        rc = -1;
-    } else if (!strcmp(argv[1], "clearpw")) {
-        SLOGD("cryptfs clearpw");
-        dumpArgs(argc, argv, -1);
-        cryptfs_clear_password();
-        rc = 0;
-    } else if (!strcmp(argv[1], "setusercryptopolicies")) {
-        if (argc != 3) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError,
-                "Usage: cryptfs setusercryptopolicies <path>", false);
-            return 0;
-        }
-        SLOGD("cryptfs setusercryptopolicies");
-        dumpArgs(argc, argv, -1);
-        rc = e4crypt_set_user_crypto_policies(argv[2]);
-    } else if (!strcmp(argv[1], "createnewuserdir")) {
-        if (argc != 4) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError,
-                "Usage: cryptfs createnewuserdir <userHandle> <path>", false);
-            return 0;
-        }
-        // ext4enc:TODO: send a CommandSyntaxError if argv[2] not an integer
-        SLOGD("cryptfs createnewuserdir");
-        dumpArgs(argc, argv, -1);
-        rc = e4crypt_create_new_user_dir(argv[2], argv[3]);
-    } else {
-        dumpArgs(argc, argv, -1);
-        cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown cryptfs cmd", false);
-        return 0;
-    }
-
-    // Always report that the command succeeded and return the error code.
-    // The caller will check the return value to see what the error was.
-    char msg[255];
-    snprintf(msg, sizeof(msg), "%d", rc);
-    cli->sendMsg(ResponseCode::CommandOkay, msg, false);
-
-    return 0;
-}
-
 CommandListener::FstrimCmd::FstrimCmd() :
                  VoldCommand("fstrim") {
 }
@@ -783,32 +601,23 @@
         return 0;
     }
 
-    int rc = 0;
+    VolumeManager *vm = VolumeManager::Instance();
+    std::lock_guard<std::mutex> lock(vm->getLock());
 
-    if (!strcmp(argv[1], "dotrim")) {
-        if (argc != 2) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: fstrim dotrim", false);
-            return 0;
-        }
-        dumpArgs(argc, argv, -1);
-        rc = fstrim_filesystems(0);
-    } else if (!strcmp(argv[1], "dodtrim")) {
-        if (argc != 2) {
-            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: fstrim dodtrim", false);
-            return 0;
-        }
-        dumpArgs(argc, argv, -1);
-        rc = fstrim_filesystems(1);   /* Do Deep Discard trim */
-    } else {
-        dumpArgs(argc, argv, -1);
-        cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown fstrim cmd", false);
+    int flags = 0;
+
+    std::string cmd(argv[1]);
+    if (cmd == "dotrim") {
+        flags = 0;
+    } else if (cmd == "dotrimbench") {
+        flags = android::vold::TrimTask::Flags::kBenchmarkAfter;
+    } else if (cmd == "dodtrim") {
+        flags = android::vold::TrimTask::Flags::kDeepTrim;
+    } else if (cmd == "dodtrimbench") {
+        flags = android::vold::TrimTask::Flags::kDeepTrim
+                | android::vold::TrimTask::Flags::kBenchmarkAfter;
     }
 
-    // Always report that the command succeeded and return the error code.
-    // The caller will check the return value to see what the error was.
-    char msg[255];
-    snprintf(msg, sizeof(msg), "%d", rc);
-    cli->sendMsg(ResponseCode::CommandOkay, msg, false);
-
-    return 0;
+    (new android::vold::TrimTask(flags))->start();
+    return sendGenericOkFail(cli, 0);
 }
diff --git a/CommandListener.h b/CommandListener.h
index 0bd51d2..6ed099b 100644
--- a/CommandListener.h
+++ b/CommandListener.h
@@ -18,6 +18,7 @@
 #define _COMMANDLISTENER_H__
 
 #include <sysutils/FrameworkListener.h>
+#include <utils/Errors.h>
 #include "VoldCommand.h"
 
 class CommandListener : public FrameworkListener {
@@ -27,6 +28,7 @@
 
 private:
     static void dumpArgs(int argc, char **argv, int argObscure);
+    static int sendGenericOkFail(SocketClient *cli, int cond);
 
     class DumpCmd : public VoldCommand {
     public:
@@ -65,13 +67,6 @@
         int runCommand(SocketClient *c, int argc, char ** argv);
     };
 
-    class CryptfsCmd : public VoldCommand {
-    public:
-        CryptfsCmd();
-        virtual ~CryptfsCmd() {}
-        int runCommand(SocketClient *c, int argc, char ** argv);
-    };
-
     class FstrimCmd : public VoldCommand {
     public:
         FstrimCmd();
diff --git a/CryptCommandListener.cpp b/CryptCommandListener.cpp
new file mode 100644
index 0000000..2e46919
--- /dev/null
+++ b/CryptCommandListener.cpp
@@ -0,0 +1,304 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <fs_mgr.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <inttypes.h>
+
+#define LOG_TAG "VoldCryptCmdListener"
+
+#include <base/stringprintf.h>
+#include <cutils/fs.h>
+#include <cutils/log.h>
+#include <cutils/sockets.h>
+
+#include <sysutils/SocketClient.h>
+#include <private/android_filesystem_config.h>
+
+#include "CryptCommandListener.h"
+#include "Process.h"
+#include "ResponseCode.h"
+#include "cryptfs.h"
+
+#define DUMP_ARGS 0
+
+CryptCommandListener::CryptCommandListener() :
+FrameworkListener("cryptd", true) {
+    registerCmd(new CryptfsCmd());
+}
+
+#if DUMP_ARGS
+void CryptCommandListener::dumpArgs(int argc, char **argv, int argObscure) {
+    char buffer[4096];
+    char *p = buffer;
+
+    memset(buffer, 0, sizeof(buffer));
+    int i;
+    for (i = 0; i < argc; i++) {
+        unsigned int len = strlen(argv[i]) + 1; // Account for space
+        if (i == argObscure) {
+            len += 2; // Account for {}
+        }
+        if (((p - buffer) + len) < (sizeof(buffer)-1)) {
+            if (i == argObscure) {
+                *p++ = '{';
+                *p++ = '}';
+                *p++ = ' ';
+                continue;
+            }
+            strcpy(p, argv[i]);
+            p+= strlen(argv[i]);
+            if (i != (argc -1)) {
+                *p++ = ' ';
+            }
+        }
+    }
+    SLOGD("%s", buffer);
+}
+#else
+void CryptCommandListener::dumpArgs(int /*argc*/, char ** /*argv*/, int /*argObscure*/) { }
+#endif
+
+int CryptCommandListener::sendGenericOkFail(SocketClient *cli, int cond) {
+    if (!cond) {
+        return cli->sendMsg(ResponseCode::CommandOkay, "Command succeeded", false);
+    } else {
+        return cli->sendMsg(ResponseCode::OperationFailed, "Command failed", false);
+    }
+}
+
+CryptCommandListener::CryptfsCmd::CryptfsCmd() :
+                 VoldCommand("cryptfs") {
+}
+
+static int getType(const char* type)
+{
+    if (!strcmp(type, "default")) {
+        return CRYPT_TYPE_DEFAULT;
+    } else if (!strcmp(type, "password")) {
+        return CRYPT_TYPE_PASSWORD;
+    } else if (!strcmp(type, "pin")) {
+        return CRYPT_TYPE_PIN;
+    } else if (!strcmp(type, "pattern")) {
+        return CRYPT_TYPE_PATTERN;
+    } else {
+        return -1;
+    }
+}
+
+int CryptCommandListener::CryptfsCmd::runCommand(SocketClient *cli,
+                                                 int argc, char **argv) {
+    if ((cli->getUid() != 0) && (cli->getUid() != AID_SYSTEM)) {
+        cli->sendMsg(ResponseCode::CommandNoPermission, "No permission to run cryptfs commands", false);
+        return 0;
+    }
+
+    if (argc < 2) {
+        cli->sendMsg(ResponseCode::CommandSyntaxError, "Missing Argument", false);
+        return 0;
+    }
+
+    int rc = 0;
+
+    if (!strcmp(argv[1], "checkpw")) {
+        if (argc != 3) {
+            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: cryptfs checkpw <passwd>", false);
+            return 0;
+        }
+        dumpArgs(argc, argv, 2);
+        rc = cryptfs_check_passwd(argv[2]);
+    } else if (!strcmp(argv[1], "restart")) {
+        if (argc != 2) {
+            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: cryptfs restart", false);
+            return 0;
+        }
+        dumpArgs(argc, argv, -1);
+        rc = cryptfs_restart();
+    } else if (!strcmp(argv[1], "cryptocomplete")) {
+        if (argc != 2) {
+            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: cryptfs cryptocomplete", false);
+            return 0;
+        }
+        dumpArgs(argc, argv, -1);
+        rc = cryptfs_crypto_complete();
+    } else if (!strcmp(argv[1], "enablecrypto")) {
+        const char* syntax = "Usage: cryptfs enablecrypto <wipe|inplace> "
+                             "default|password|pin|pattern [passwd]";
+        if ( (argc != 4 && argc != 5)
+             || (strcmp(argv[2], "wipe") && strcmp(argv[2], "inplace")) ) {
+            cli->sendMsg(ResponseCode::CommandSyntaxError, syntax, false);
+            return 0;
+        }
+        dumpArgs(argc, argv, 4);
+
+        int tries;
+        for (tries = 0; tries < 2; ++tries) {
+            int type = getType(argv[3]);
+            if (type == -1) {
+                cli->sendMsg(ResponseCode::CommandSyntaxError, syntax,
+                             false);
+                return 0;
+            } else if (type == CRYPT_TYPE_DEFAULT) {
+              rc = cryptfs_enable_default(argv[2], /*allow_reboot*/false);
+            } else {
+                rc = cryptfs_enable(argv[2], type, argv[4],
+                                    /*allow_reboot*/false);
+            }
+
+            if (rc == 0) {
+                break;
+            } else if (tries == 0) {
+                Process::killProcessesWithOpenFiles(DATA_MNT_POINT, SIGKILL);
+            }
+        }
+    } else if (!strcmp(argv[1], "enablefilecrypto")) {
+        const char* syntax = "Usage: cryptfs enablefilecrypto";
+        if (argc != 2) {
+            cli->sendMsg(ResponseCode::CommandSyntaxError, syntax, false);
+            return 0;
+        }
+        dumpArgs(argc, argv, -1);
+        rc = cryptfs_enable_file();
+    } else if (!strcmp(argv[1], "changepw")) {
+        const char* syntax = "Usage: cryptfs changepw "
+                             "default|password|pin|pattern [newpasswd]";
+        const char* password;
+        if (argc == 3) {
+            password = "";
+        } else if (argc == 4) {
+            password = argv[3];
+        } else {
+            cli->sendMsg(ResponseCode::CommandSyntaxError, syntax, false);
+            return 0;
+        }
+        int type = getType(argv[2]);
+        if (type == -1) {
+            cli->sendMsg(ResponseCode::CommandSyntaxError, syntax, false);
+            return 0;
+        }
+        SLOGD("cryptfs changepw %s {}", argv[2]);
+        rc = cryptfs_changepw(type, password);
+    } else if (!strcmp(argv[1], "verifypw")) {
+        if (argc != 3) {
+            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: cryptfs verifypw <passwd>", false);
+            return 0;
+        }
+        SLOGD("cryptfs verifypw {}");
+        rc = cryptfs_verify_passwd(argv[2]);
+    } else if (!strcmp(argv[1], "getfield")) {
+        char *valbuf;
+        int valbuf_len = PROPERTY_VALUE_MAX;
+
+        if (argc != 3) {
+            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: cryptfs getfield <fieldname>", false);
+            return 0;
+        }
+        dumpArgs(argc, argv, -1);
+
+        // Increase the buffer size until it is big enough for the field value stored.
+        while (1) {
+            valbuf = (char*)malloc(valbuf_len);
+            if (valbuf == NULL) {
+                cli->sendMsg(ResponseCode::OperationFailed, "Failed to allocate memory", false);
+                return 0;
+            }
+            rc = cryptfs_getfield(argv[2], valbuf, valbuf_len);
+            if (rc != CRYPTO_GETFIELD_ERROR_BUF_TOO_SMALL) {
+                break;
+            }
+            free(valbuf);
+            valbuf_len *= 2;
+        }
+        if (rc == CRYPTO_GETFIELD_OK) {
+            cli->sendMsg(ResponseCode::CryptfsGetfieldResult, valbuf, false);
+        }
+        free(valbuf);
+    } else if (!strcmp(argv[1], "setfield")) {
+        if (argc != 4) {
+            cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: cryptfs setfield <fieldname> <value>", false);
+            return 0;
+        }
+        dumpArgs(argc, argv, -1);
+        rc = cryptfs_setfield(argv[2], argv[3]);
+    } else if (!strcmp(argv[1], "mountdefaultencrypted")) {
+        SLOGD("cryptfs mountdefaultencrypted");
+        dumpArgs(argc, argv, -1);
+        rc = cryptfs_mount_default_encrypted();
+    } else if (!strcmp(argv[1], "getpwtype")) {
+        SLOGD("cryptfs getpwtype");
+        dumpArgs(argc, argv, -1);
+        switch(cryptfs_get_password_type()) {
+        case CRYPT_TYPE_PASSWORD:
+            cli->sendMsg(ResponseCode::PasswordTypeResult, "password", false);
+            return 0;
+        case CRYPT_TYPE_PATTERN:
+            cli->sendMsg(ResponseCode::PasswordTypeResult, "pattern", false);
+            return 0;
+        case CRYPT_TYPE_PIN:
+            cli->sendMsg(ResponseCode::PasswordTypeResult, "pin", false);
+            return 0;
+        case CRYPT_TYPE_DEFAULT:
+            cli->sendMsg(ResponseCode::PasswordTypeResult, "default", false);
+            return 0;
+        default:
+          /** @TODO better error and make sure handled by callers */
+            cli->sendMsg(ResponseCode::OpFailedStorageNotFound, "Error", false);
+            return 0;
+        }
+    } else if (!strcmp(argv[1], "getpw")) {
+        SLOGD("cryptfs getpw");
+        dumpArgs(argc, argv, -1);
+        const char* password = cryptfs_get_password();
+        if (password) {
+            char* message = 0;
+            int size = asprintf(&message, "{{sensitive}} %s", password);
+            if (size != -1) {
+                cli->sendMsg(ResponseCode::CommandOkay, message, false);
+                memset(message, 0, size);
+                free (message);
+                return 0;
+            }
+        }
+        rc = -1;
+    } else if (!strcmp(argv[1], "clearpw")) {
+        SLOGD("cryptfs clearpw");
+        dumpArgs(argc, argv, -1);
+        cryptfs_clear_password();
+        rc = 0;
+    } else {
+        dumpArgs(argc, argv, -1);
+        cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown cryptfs cmd", false);
+        return 0;
+    }
+
+    // Always report that the command succeeded and return the error code.
+    // The caller will check the return value to see what the error was.
+    char msg[255];
+    snprintf(msg, sizeof(msg), "%d", rc);
+    cli->sendMsg(ResponseCode::CommandOkay, msg, false);
+
+    return 0;
+}
diff --git a/CryptCommandListener.h b/CryptCommandListener.h
new file mode 100644
index 0000000..1653239
--- /dev/null
+++ b/CryptCommandListener.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CRYPTCOMMANDLISTENER_H__
+#define _CRYPTCOMMANDLISTENER_H__
+
+#include <sysutils/FrameworkListener.h>
+#include <utils/Errors.h>
+#include "VoldCommand.h"
+
+class CryptCommandListener : public FrameworkListener {
+public:
+    CryptCommandListener();
+    virtual ~CryptCommandListener() {}
+
+private:
+    static void dumpArgs(int argc, char **argv, int argObscure);
+    static int sendGenericOkFail(SocketClient *cli, int cond);
+
+    class CryptfsCmd : public VoldCommand {
+    public:
+        CryptfsCmd();
+        virtual ~CryptfsCmd() {}
+        int runCommand(SocketClient *c, int argc, char ** argv);
+    };
+    int getSocket();
+};
+
+#endif
diff --git a/Devmapper.cpp b/Devmapper.cpp
index 703902f..703eade 100644
--- a/Devmapper.cpp
+++ b/Devmapper.cpp
@@ -55,7 +55,7 @@
     }
 
     int fd;
-    if ((fd = open("/dev/device-mapper", O_RDWR)) < 0) {
+    if ((fd = open("/dev/device-mapper", O_RDWR | O_CLOEXEC)) < 0) {
         SLOGE("Error opening devmapper (%s)", strerror(errno));
         free(buffer);
         free(buffer2);
@@ -138,7 +138,7 @@
     }
 
     int fd;
-    if ((fd = open("/dev/device-mapper", O_RDWR)) < 0) {
+    if ((fd = open("/dev/device-mapper", O_RDWR | O_CLOEXEC)) < 0) {
         SLOGE("Error opening devmapper (%s)", strerror(errno));
         free(buffer);
         return -1;
@@ -172,7 +172,7 @@
     }
 
     int fd;
-    if ((fd = open("/dev/device-mapper", O_RDWR)) < 0) {
+    if ((fd = open("/dev/device-mapper", O_RDWR | O_CLOEXEC)) < 0) {
         SLOGE("Error opening devmapper (%s)", strerror(errno));
         free(buffer);
         return -1;
@@ -269,7 +269,7 @@
     }
 
     int fd;
-    if ((fd = open("/dev/device-mapper", O_RDWR)) < 0) {
+    if ((fd = open("/dev/device-mapper", O_RDWR | O_CLOEXEC)) < 0) {
         SLOGE("Error opening devmapper (%s)", strerror(errno));
         free(buffer);
         return -1;
diff --git a/DirectVolume.cpp b/DirectVolume.cpp
deleted file mode 100644
index 64d7744..0000000
--- a/DirectVolume.cpp
+++ /dev/null
@@ -1,512 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <fnmatch.h>
-
-#include <linux/kdev_t.h>
-
-#define LOG_TAG "DirectVolume"
-
-#include <cutils/log.h>
-#include <sysutils/NetlinkEvent.h>
-
-#include "DirectVolume.h"
-#include "VolumeManager.h"
-#include "ResponseCode.h"
-#include "cryptfs.h"
-
-// #define PARTITION_DEBUG
-
-PathInfo::PathInfo(const char *p)
-{
-    warned = false;
-    pattern = strdup(p);
-
-    if (!strchr(pattern, '*')) {
-        patternType = prefix;
-    } else {
-        patternType = wildcard;
-    }
-}
-
-PathInfo::~PathInfo()
-{
-    free(pattern);
-}
-
-bool PathInfo::match(const char *path)
-{
-    switch (patternType) {
-    case prefix:
-    {
-        bool ret = (strncmp(path, pattern, strlen(pattern)) == 0);
-        if (!warned && ret && (strlen(pattern) != strlen(path))) {
-            SLOGW("Deprecated implied prefix pattern detected, please use '%s*' instead", pattern);
-            warned = true;
-        }
-        return ret;
-    }
-    case wildcard:
-        return fnmatch(pattern, path, 0) == 0;
-    }
-    SLOGE("Bad matching type");
-    return false;
-}
-
-DirectVolume::DirectVolume(VolumeManager *vm, const fstab_rec* rec, int flags) :
-        Volume(vm, rec, flags) {
-    mPaths = new PathCollection();
-    for (int i = 0; i < MAX_PARTITIONS; i++)
-        mPartMinors[i] = -1;
-    mPendingPartCount = 0;
-    mDiskMajor = -1;
-    mDiskMinor = -1;
-    mDiskNumParts = 0;
-    mIsDecrypted = 0;
-
-    if (strcmp(rec->mount_point, "auto") != 0) {
-        ALOGE("Vold managed volumes must have auto mount point; ignoring %s",
-              rec->mount_point);
-    }
-
-    char mount[PATH_MAX];
-
-    snprintf(mount, PATH_MAX, "%s/%s", Volume::MEDIA_DIR, rec->label);
-    mMountpoint = strdup(mount);
-    snprintf(mount, PATH_MAX, "%s/%s", Volume::FUSE_DIR, rec->label);
-    mFuseMountpoint = strdup(mount);
-
-    setState(Volume::State_NoMedia);
-}
-
-DirectVolume::~DirectVolume() {
-    PathCollection::iterator it;
-
-    for (it = mPaths->begin(); it != mPaths->end(); ++it)
-        delete *it;
-    delete mPaths;
-}
-
-int DirectVolume::addPath(const char *path) {
-    mPaths->push_back(new PathInfo(path));
-    return 0;
-}
-
-dev_t DirectVolume::getDiskDevice() {
-    return MKDEV(mDiskMajor, mDiskMinor);
-}
-
-dev_t DirectVolume::getShareDevice() {
-    if (mPartIdx != -1) {
-        return MKDEV(mDiskMajor, mPartIdx);
-    } else {
-        return MKDEV(mDiskMajor, mDiskMinor);
-    }
-}
-
-void DirectVolume::handleVolumeShared() {
-    setState(Volume::State_Shared);
-}
-
-void DirectVolume::handleVolumeUnshared() {
-    setState(Volume::State_Idle);
-}
-
-int DirectVolume::handleBlockEvent(NetlinkEvent *evt) {
-    const char *dp = evt->findParam("DEVPATH");
-
-    PathCollection::iterator  it;
-    for (it = mPaths->begin(); it != mPaths->end(); ++it) {
-        if ((*it)->match(dp)) {
-            /* We can handle this disk */
-            int action = evt->getAction();
-            const char *devtype = evt->findParam("DEVTYPE");
-
-            if (action == NetlinkEvent::NlActionAdd) {
-                int major = atoi(evt->findParam("MAJOR"));
-                int minor = atoi(evt->findParam("MINOR"));
-                char nodepath[255];
-
-                snprintf(nodepath,
-                         sizeof(nodepath), "/dev/block/vold/%d:%d",
-                         major, minor);
-                if (createDeviceNode(nodepath, major, minor)) {
-                    SLOGE("Error making device node '%s' (%s)", nodepath,
-                                                               strerror(errno));
-                }
-                if (!strcmp(devtype, "disk")) {
-                    handleDiskAdded(dp, evt);
-                } else {
-                    handlePartitionAdded(dp, evt);
-                }
-                /* Send notification iff disk is ready (ie all partitions found) */
-                if (getState() == Volume::State_Idle) {
-                    char msg[255];
-
-                    snprintf(msg, sizeof(msg),
-                             "Volume %s %s disk inserted (%d:%d)", getLabel(),
-                             getFuseMountpoint(), mDiskMajor, mDiskMinor);
-                    mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskInserted,
-                                                         msg, false);
-                }
-            } else if (action == NetlinkEvent::NlActionRemove) {
-                if (!strcmp(devtype, "disk")) {
-                    handleDiskRemoved(dp, evt);
-                } else {
-                    handlePartitionRemoved(dp, evt);
-                }
-            } else if (action == NetlinkEvent::NlActionChange) {
-                if (!strcmp(devtype, "disk")) {
-                    handleDiskChanged(dp, evt);
-                } else {
-                    handlePartitionChanged(dp, evt);
-                }
-            } else {
-                    SLOGW("Ignoring non add/remove/change event");
-            }
-
-            return 0;
-        }
-    }
-    errno = ENODEV;
-    return -1;
-}
-
-void DirectVolume::handleDiskAdded(const char * /*devpath*/,
-                                   NetlinkEvent *evt) {
-    mDiskMajor = atoi(evt->findParam("MAJOR"));
-    mDiskMinor = atoi(evt->findParam("MINOR"));
-
-    const char *tmp = evt->findParam("NPARTS");
-    if (tmp) {
-        mDiskNumParts = atoi(tmp);
-    } else {
-        SLOGW("Kernel block uevent missing 'NPARTS'");
-        mDiskNumParts = 1;
-    }
-
-    mPendingPartCount = mDiskNumParts;
-    for (int i = 0; i < MAX_PARTITIONS; i++)
-        mPartMinors[i] = -1;
-
-    if (mDiskNumParts == 0) {
-#ifdef PARTITION_DEBUG
-        SLOGD("Dv::diskIns - No partitions - good to go son!");
-#endif
-        setState(Volume::State_Idle);
-    } else {
-#ifdef PARTITION_DEBUG
-        SLOGD("Dv::diskIns - waiting for %d pending partitions", mPendingPartCount);
-#endif
-        setState(Volume::State_Pending);
-    }
-}
-
-void DirectVolume::handlePartitionAdded(const char *devpath, NetlinkEvent *evt) {
-    int major = atoi(evt->findParam("MAJOR"));
-    int minor = atoi(evt->findParam("MINOR"));
-
-    int part_num;
-
-    const char *tmp = evt->findParam("PARTN");
-
-    if (tmp) {
-        part_num = atoi(tmp);
-    } else {
-        SLOGW("Kernel block uevent missing 'PARTN'");
-        part_num = 1;
-    }
-
-    if (part_num > MAX_PARTITIONS || part_num < 1) {
-        SLOGE("Invalid 'PARTN' value");
-        return;
-    }
-
-    if (part_num > mDiskNumParts) {
-        mDiskNumParts = part_num;
-    }
-
-    if (major != mDiskMajor) {
-        SLOGE("Partition '%s' has a different major than its disk!", devpath);
-        return;
-    }
-#ifdef PARTITION_DEBUG
-    SLOGD("Dv:partAdd: part_num = %d, minor = %d\n", part_num, minor);
-#endif
-    if (part_num >= MAX_PARTITIONS) {
-        SLOGE("Dv:partAdd: ignoring part_num = %d (max: %d)\n", part_num, MAX_PARTITIONS-1);
-    } else {
-        if ((mPartMinors[part_num - 1] == -1) && mPendingPartCount)
-            mPendingPartCount--;
-        mPartMinors[part_num -1] = minor;
-    }
-
-    if (!mPendingPartCount) {
-#ifdef PARTITION_DEBUG
-        SLOGD("Dv:partAdd: Got all partitions - ready to rock!");
-#endif
-        if (getState() != Volume::State_Formatting) {
-            setState(Volume::State_Idle);
-            if (mRetryMount == true) {
-                mRetryMount = false;
-                mountVol();
-            }
-        }
-    } else {
-#ifdef PARTITION_DEBUG
-        SLOGD("Dv:partAdd: pending %d disk", mPendingPartCount);
-#endif
-    }
-}
-
-void DirectVolume::handleDiskChanged(const char * /*devpath*/,
-                                     NetlinkEvent *evt) {
-    int major = atoi(evt->findParam("MAJOR"));
-    int minor = atoi(evt->findParam("MINOR"));
-
-    if ((major != mDiskMajor) || (minor != mDiskMinor)) {
-        return;
-    }
-
-    SLOGI("Volume %s disk has changed", getLabel());
-    const char *tmp = evt->findParam("NPARTS");
-    if (tmp) {
-        mDiskNumParts = atoi(tmp);
-    } else {
-        SLOGW("Kernel block uevent missing 'NPARTS'");
-        mDiskNumParts = 1;
-    }
-
-    mPendingPartCount = mDiskNumParts;
-    for (int i = 0; i < MAX_PARTITIONS; i++)
-        mPartMinors[i] = -1;
-
-    if (getState() != Volume::State_Formatting) {
-        if (mDiskNumParts == 0) {
-            setState(Volume::State_Idle);
-        } else {
-            setState(Volume::State_Pending);
-        }
-    }
-}
-
-void DirectVolume::handlePartitionChanged(const char * /*devpath*/,
-                                          NetlinkEvent *evt) {
-    int major = atoi(evt->findParam("MAJOR"));
-    int minor = atoi(evt->findParam("MINOR"));
-    SLOGD("Volume %s %s partition %d:%d changed\n", getLabel(), getMountpoint(), major, minor);
-}
-
-void DirectVolume::handleDiskRemoved(const char * /*devpath*/,
-                                     NetlinkEvent *evt) {
-    int major = atoi(evt->findParam("MAJOR"));
-    int minor = atoi(evt->findParam("MINOR"));
-    char msg[255];
-    bool enabled;
-
-    SLOGD("Volume %s %s disk %d:%d removed\n", getLabel(), getMountpoint(), major, minor);
-    if ((dev_t) MKDEV(major, minor) == mCurrentlyMountedKdev) {
-        /*
-         * Yikes, our mounted disk is going away!
-         */
-
-        doUnmount(major, minor);
-    } else if (mVm->shareEnabled(getLabel(), "ums", &enabled) == 0 && enabled) {
-        mVm->unshareVolume(getLabel(), "ums");
-    }
-
-    snprintf(msg, sizeof(msg), "Volume %s %s disk removed (%d:%d)",
-             getLabel(), getFuseMountpoint(), major, minor);
-    mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskRemoved,
-                                             msg, false);
-    setState(Volume::State_NoMedia);
-}
-
-void DirectVolume::handlePartitionRemoved(const char * /*devpath*/,
-                                          NetlinkEvent *evt) {
-    int major = atoi(evt->findParam("MAJOR"));
-    int minor = atoi(evt->findParam("MINOR"));
-    char msg[255];
-    int state;
-
-    SLOGD("Volume %s %s partition %d:%d removed\n", getLabel(), getMountpoint(), major, minor);
-
-    /*
-     * The framework doesn't need to get notified of
-     * partition removal unless it's mounted. Otherwise
-     * the removal notification will be sent on the Disk
-     * itself
-     */
-    state = getState();
-    if (state != Volume::State_Mounted && state != Volume::State_Shared) {
-        return;
-    }
-
-    if ((dev_t) MKDEV(major, minor) == mCurrentlyMountedKdev) {
-        /*
-         * Yikes, our mounted partition is going away!
-         */
-        doUnmount(major, minor);
-    } else if (state == Volume::State_Shared) {
-        /* removed during mass storage */
-        snprintf(msg, sizeof(msg), "Volume %s bad removal (%d:%d)",
-                 getLabel(), major, minor);
-        mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval,
-                                             msg, false);
-
-        if (mVm->unshareVolume(getLabel(), "ums")) {
-            SLOGE("Failed to unshare volume on bad removal (%s)",
-                strerror(errno));
-        } else {
-            SLOGD("Crisis averted");
-        }
-    }
-}
-
-void DirectVolume::doUnmount(int major, int minor) {
-    char msg[255];
-    bool providesAsec = (getFlags() & VOL_PROVIDES_ASEC) != 0;
-    if (providesAsec && mVm->cleanupAsec(this, true)) {
-        SLOGE("Failed to cleanup ASEC - unmount will probably fail!");
-    }
-
-    snprintf(msg, sizeof(msg), "Volume %s %s bad removal (%d:%d)",
-                getLabel(), getFuseMountpoint(), major, minor);
-    mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval,
-                                            msg, false);
-
-    if (Volume::unmountVol(true, false)) {
-        SLOGE("Failed to unmount volume on bad removal (%s)",
-                strerror(errno));
-        // XXX: At this point we're screwed for now
-    } else {
-        SLOGD("Crisis averted");
-    }
-}
-
-/*
- * Called from base to get a list of devicenodes for mounting
- */
-int DirectVolume::getDeviceNodes(dev_t *devs, int max) {
-
-    if (mPartIdx == -1) {
-        // If the disk has no partitions, try the disk itself
-        if (!mDiskNumParts) {
-            devs[0] = MKDEV(mDiskMajor, mDiskMinor);
-            return 1;
-        }
-
-        int i;
-        for (i = 0; i < mDiskNumParts; i++) {
-            if (i == max)
-                break;
-            devs[i] = MKDEV(mDiskMajor, mPartMinors[i]);
-        }
-        return mDiskNumParts;
-    }
-    devs[0] = MKDEV(mDiskMajor, mPartMinors[mPartIdx -1]);
-    return 1;
-}
-
-/*
- * Called from base to update device info,
- * e.g. When setting up an dm-crypt mapping for the sd card.
- */
-int DirectVolume::updateDeviceInfo(char *new_path, int new_major, int new_minor)
-{
-    PathCollection::iterator it;
-
-    if (mPartIdx == -1) {
-        SLOGE("Can only change device info on a partition\n");
-        return -1;
-    }
-
-    /*
-     * This is to change the sysfs path associated with a partition, in particular,
-     * for an internal SD card partition that is encrypted.  Thus, the list is
-     * expected to be only 1 entry long.  Check that and bail if not.
-     */
-    if (mPaths->size() != 1) {
-        SLOGE("Cannot change path if there are more than one for a volume\n");
-        return -1;
-    }
-
-    it = mPaths->begin();
-    delete *it; /* Free the string storage */
-    mPaths->erase(it); /* Remove it from the list */
-    addPath(new_path); /* Put the new path on the list */
-
-    /* Save away original info so we can restore it when doing factory reset.
-     * Then, when doing the format, it will format the original device in the
-     * clear, otherwise it just formats the encrypted device which is not
-     * readable when the device boots unencrypted after the reset.
-     */
-    mOrigDiskMajor = mDiskMajor;
-    mOrigDiskMinor = mDiskMinor;
-    mOrigPartIdx = mPartIdx;
-    memcpy(mOrigPartMinors, mPartMinors, sizeof(mPartMinors));
-
-    mDiskMajor = new_major;
-    mDiskMinor = new_minor;
-    /* Ugh, virual block devices don't use minor 0 for whole disk and minor > 0 for
-     * partition number.  They don't have partitions, they are just virtual block
-     * devices, and minor number 0 is the first dm-crypt device.  Luckily the first
-     * dm-crypt device is for the userdata partition, which gets minor number 0, and
-     * it is not managed by vold.  So the next device is minor number one, which we
-     * will call partition one.
-     */
-    mPartIdx = new_minor;
-    mPartMinors[new_minor-1] = new_minor;
-
-    mIsDecrypted = 1;
-
-    return 0;
-}
-
-/*
- * Called from base to revert device info to the way it was before a
- * crypto mapping was created for it.
- */
-void DirectVolume::revertDeviceInfo(void)
-{
-    if (mIsDecrypted) {
-        mDiskMajor = mOrigDiskMajor;
-        mDiskMinor = mOrigDiskMinor;
-        mPartIdx = mOrigPartIdx;
-        memcpy(mPartMinors, mOrigPartMinors, sizeof(mPartMinors));
-
-        mIsDecrypted = 0;
-    }
-
-    return;
-}
-
-/*
- * Called from base to give cryptfs all the info it needs to encrypt eligible volumes
- */
-int DirectVolume::getVolInfo(struct volume_info *v)
-{
-    strcpy(v->label, mLabel);
-    strcpy(v->mnt_point, mMountpoint);
-    v->flags = getFlags();
-    /* Other fields of struct volume_info are filled in by the caller or cryptfs.c */
-
-    return 0;
-}
diff --git a/DirectVolume.h b/DirectVolume.h
deleted file mode 100644
index 96f46af..0000000
--- a/DirectVolume.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _DEVICEVOLUME_H
-#define _DEVICEVOLUME_H
-
-#include <utils/List.h>
-
-#include "Volume.h"
-
-class PathInfo {
-public:
-	PathInfo(const char *pattern);
-	~PathInfo();
-	bool match(const char *path);
-private:
-	bool warned;
-	char *pattern;
-	enum PatternType { prefix, wildcard };
-	PatternType patternType;
-};
-
-typedef android::List<PathInfo *> PathCollection;
-
-class DirectVolume : public Volume {
-public:
-    static const int MAX_PARTITIONS = 32;
-protected:
-    const char* mMountpoint;
-    const char* mFuseMountpoint;
-
-    PathCollection *mPaths;
-    int            mDiskMajor;
-    int            mDiskMinor;
-    int            mPartMinors[MAX_PARTITIONS];
-    int            mOrigDiskMajor;
-    int            mOrigDiskMinor;
-    int            mOrigPartMinors[MAX_PARTITIONS];
-    int            mDiskNumParts;
-    int            mPendingPartCount;
-    int            mIsDecrypted;
-
-public:
-    DirectVolume(VolumeManager *vm, const fstab_rec* rec, int flags);
-    virtual ~DirectVolume();
-
-    int addPath(const char *path);
-
-    const char *getMountpoint() { return mMountpoint; }
-    const char *getFuseMountpoint() { return mFuseMountpoint; }
-
-    int handleBlockEvent(NetlinkEvent *evt);
-    dev_t getDiskDevice();
-    dev_t getShareDevice();
-    void handleVolumeShared();
-    void handleVolumeUnshared();
-    int getVolInfo(struct volume_info *v);
-
-protected:
-    int getDeviceNodes(dev_t *devs, int max);
-    int updateDeviceInfo(char *new_path, int new_major, int new_minor);
-    virtual void revertDeviceInfo(void);
-    int isDecrypted() { return mIsDecrypted; }
-
-private:
-    void handleDiskAdded(const char *devpath, NetlinkEvent *evt);
-    void handleDiskRemoved(const char *devpath, NetlinkEvent *evt);
-    void handleDiskChanged(const char *devpath, NetlinkEvent *evt);
-    void handlePartitionAdded(const char *devpath, NetlinkEvent *evt);
-    void handlePartitionRemoved(const char *devpath, NetlinkEvent *evt);
-    void handlePartitionChanged(const char *devpath, NetlinkEvent *evt);
-
-    int doMountVfat(const char *deviceNode, const char *mountPoint);
-    void doUnmount(int major, int minor);
-
-};
-
-typedef android::List<DirectVolume *> DirectVolumeCollection;
-
-#endif
diff --git a/Disk.cpp b/Disk.cpp
new file mode 100644
index 0000000..1e76bee
--- /dev/null
+++ b/Disk.cpp
@@ -0,0 +1,503 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Disk.h"
+#include "PublicVolume.h"
+#include "PrivateVolume.h"
+#include "Utils.h"
+#include "VolumeBase.h"
+#include "VolumeManager.h"
+#include "ResponseCode.h"
+
+#include <base/file.h>
+#include <base/stringprintf.h>
+#include <base/logging.h>
+#include <diskconfig/diskconfig.h>
+
+#include <vector>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mount.h>
+
+using android::base::ReadFileToString;
+using android::base::WriteStringToFile;
+using android::base::StringPrintf;
+
+namespace android {
+namespace vold {
+
+static const char* kSgdiskPath = "/system/bin/sgdisk";
+static const char* kSgdiskToken = " \t\n";
+
+static const char* kSysfsMmcMaxMinors = "/sys/module/mmcblk/parameters/perdev_minors";
+
+static const unsigned int kMajorBlockScsiA = 8;
+static const unsigned int kMajorBlockScsiB = 65;
+static const unsigned int kMajorBlockScsiC = 66;
+static const unsigned int kMajorBlockScsiD = 67;
+static const unsigned int kMajorBlockScsiE = 68;
+static const unsigned int kMajorBlockScsiF = 69;
+static const unsigned int kMajorBlockScsiG = 70;
+static const unsigned int kMajorBlockScsiH = 71;
+static const unsigned int kMajorBlockScsiI = 128;
+static const unsigned int kMajorBlockScsiJ = 129;
+static const unsigned int kMajorBlockScsiK = 130;
+static const unsigned int kMajorBlockScsiL = 131;
+static const unsigned int kMajorBlockScsiM = 132;
+static const unsigned int kMajorBlockScsiN = 133;
+static const unsigned int kMajorBlockScsiO = 134;
+static const unsigned int kMajorBlockScsiP = 135;
+static const unsigned int kMajorBlockMmc = 179;
+
+static const char* kGptBasicData = "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7";
+static const char* kGptAndroidMeta = "19A710A2-B3CA-11E4-B026-10604B889DCF";
+static const char* kGptAndroidExpand = "193D1EA4-B3CA-11E4-B075-10604B889DCF";
+
+enum class Table {
+    kUnknown,
+    kMbr,
+    kGpt,
+};
+
+Disk::Disk(const std::string& eventPath, dev_t device,
+        const std::string& nickname, int flags) :
+        mDevice(device), mSize(-1), mNickname(nickname), mFlags(flags), mCreated(
+                false), mJustPartitioned(false) {
+    mId = StringPrintf("disk:%u,%u", major(device), minor(device));
+    mEventPath = eventPath;
+    mSysPath = StringPrintf("/sys/%s", eventPath.c_str());
+    mDevPath = StringPrintf("/dev/block/vold/%s", mId.c_str());
+    CreateDeviceNode(mDevPath, mDevice);
+}
+
+Disk::~Disk() {
+    CHECK(!mCreated);
+    DestroyDeviceNode(mDevPath);
+}
+
+std::shared_ptr<VolumeBase> Disk::findVolume(const std::string& id) {
+    for (auto vol : mVolumes) {
+        if (vol->getId() == id) {
+            return vol;
+        }
+        auto stackedVol = vol->findVolume(id);
+        if (stackedVol != nullptr) {
+            return stackedVol;
+        }
+    }
+    return nullptr;
+}
+
+void Disk::listVolumes(VolumeBase::Type type, std::list<std::string>& list) {
+    for (auto vol : mVolumes) {
+        if (vol->getType() == type) {
+            list.push_back(vol->getId());
+        }
+        // TODO: consider looking at stacked volumes
+    }
+}
+
+status_t Disk::create() {
+    CHECK(!mCreated);
+    mCreated = true;
+    notifyEvent(ResponseCode::DiskCreated, StringPrintf("%d", mFlags));
+    readMetadata();
+    readPartitions();
+    return OK;
+}
+
+status_t Disk::destroy() {
+    CHECK(mCreated);
+    destroyAllVolumes();
+    mCreated = false;
+    notifyEvent(ResponseCode::DiskDestroyed);
+    return OK;
+}
+
+void Disk::createPublicVolume(dev_t device) {
+    auto vol = std::shared_ptr<VolumeBase>(new PublicVolume(device));
+    if (mJustPartitioned) {
+        LOG(DEBUG) << "Device just partitioned; silently formatting";
+        vol->setSilent(true);
+        vol->create();
+        vol->format("auto");
+        vol->destroy();
+        vol->setSilent(false);
+    }
+
+    mVolumes.push_back(vol);
+    vol->setDiskId(getId());
+    vol->create();
+}
+
+void Disk::createPrivateVolume(dev_t device, const std::string& partGuid) {
+    std::string normalizedGuid;
+    if (NormalizeHex(partGuid, normalizedGuid)) {
+        LOG(WARNING) << "Invalid GUID " << partGuid;
+        return;
+    }
+
+    std::string keyRaw;
+    if (!ReadFileToString(BuildKeyPath(normalizedGuid), &keyRaw)) {
+        PLOG(ERROR) << "Failed to load key for GUID " << normalizedGuid;
+        return;
+    }
+
+    LOG(DEBUG) << "Found key for GUID " << normalizedGuid;
+
+    auto vol = std::shared_ptr<VolumeBase>(new PrivateVolume(device, keyRaw));
+    if (mJustPartitioned) {
+        LOG(DEBUG) << "Device just partitioned; silently formatting";
+        vol->setSilent(true);
+        vol->create();
+        vol->format("auto");
+        vol->destroy();
+        vol->setSilent(false);
+    }
+
+    mVolumes.push_back(vol);
+    vol->setDiskId(getId());
+    vol->setPartGuid(partGuid);
+    vol->create();
+}
+
+void Disk::destroyAllVolumes() {
+    for (auto vol : mVolumes) {
+        vol->destroy();
+    }
+    mVolumes.clear();
+}
+
+status_t Disk::readMetadata() {
+    mSize = -1;
+    mLabel.clear();
+
+    int fd = open(mDevPath.c_str(), O_RDONLY | O_CLOEXEC);
+    if (fd != -1) {
+        if (ioctl(fd, BLKGETSIZE64, &mSize)) {
+            mSize = -1;
+        }
+        close(fd);
+    }
+
+    switch (major(mDevice)) {
+    case kMajorBlockScsiA: case kMajorBlockScsiB: case kMajorBlockScsiC: case kMajorBlockScsiD:
+    case kMajorBlockScsiE: case kMajorBlockScsiF: case kMajorBlockScsiG: case kMajorBlockScsiH:
+    case kMajorBlockScsiI: case kMajorBlockScsiJ: case kMajorBlockScsiK: case kMajorBlockScsiL:
+    case kMajorBlockScsiM: case kMajorBlockScsiN: case kMajorBlockScsiO: case kMajorBlockScsiP: {
+        std::string path(mSysPath + "/device/vendor");
+        std::string tmp;
+        if (!ReadFileToString(path, &tmp)) {
+            PLOG(WARNING) << "Failed to read vendor from " << path;
+            return -errno;
+        }
+        mLabel = tmp;
+        break;
+    }
+    case kMajorBlockMmc: {
+        std::string path(mSysPath + "/device/manfid");
+        std::string tmp;
+        if (!ReadFileToString(path, &tmp)) {
+            PLOG(WARNING) << "Failed to read manufacturer from " << path;
+            return -errno;
+        }
+        uint64_t manfid = strtoll(tmp.c_str(), nullptr, 16);
+        // Our goal here is to give the user a meaningful label, ideally
+        // matching whatever is silk-screened on the card.  To reduce
+        // user confusion, this list doesn't contain white-label manfid.
+        switch (manfid) {
+        case 0x000003: mLabel = "SanDisk"; break;
+        case 0x00001b: mLabel = "Samsung"; break;
+        case 0x000028: mLabel = "Lexar"; break;
+        case 0x000074: mLabel = "Transcend"; break;
+        }
+        break;
+    }
+    default: {
+        LOG(WARNING) << "Unsupported block major type" << major(mDevice);
+        return -ENOTSUP;
+    }
+    }
+
+    notifyEvent(ResponseCode::DiskSizeChanged, StringPrintf("%" PRId64, mSize));
+    notifyEvent(ResponseCode::DiskLabelChanged, mLabel);
+    notifyEvent(ResponseCode::DiskSysPathChanged, mSysPath);
+    return OK;
+}
+
+status_t Disk::readPartitions() {
+    int8_t maxMinors = getMaxMinors();
+    if (maxMinors < 0) {
+        return -ENOTSUP;
+    }
+
+    destroyAllVolumes();
+
+    // Parse partition table
+
+    std::vector<std::string> cmd;
+    cmd.push_back(kSgdiskPath);
+    cmd.push_back("--android-dump");
+    cmd.push_back(mDevPath);
+
+    std::vector<std::string> output;
+    status_t res = ForkExecvp(cmd, output);
+    if (res != OK) {
+        LOG(WARNING) << "sgdisk failed to scan " << mDevPath;
+        notifyEvent(ResponseCode::DiskScanned);
+        mJustPartitioned = false;
+        return res;
+    }
+
+    Table table = Table::kUnknown;
+    bool foundParts = false;
+    for (auto line : output) {
+        char* cline = (char*) line.c_str();
+        char* token = strtok(cline, kSgdiskToken);
+        if (token == nullptr) continue;
+
+        if (!strcmp(token, "DISK")) {
+            const char* type = strtok(nullptr, kSgdiskToken);
+            if (!strcmp(type, "mbr")) {
+                table = Table::kMbr;
+            } else if (!strcmp(type, "gpt")) {
+                table = Table::kGpt;
+            }
+        } else if (!strcmp(token, "PART")) {
+            foundParts = true;
+            int i = strtol(strtok(nullptr, kSgdiskToken), nullptr, 10);
+            if (i <= 0 || i > maxMinors) {
+                LOG(WARNING) << mId << " is ignoring partition " << i
+                        << " beyond max supported devices";
+                continue;
+            }
+            dev_t partDevice = makedev(major(mDevice), minor(mDevice) + i);
+
+            if (table == Table::kMbr) {
+                const char* type = strtok(nullptr, kSgdiskToken);
+
+                switch (strtol(type, nullptr, 16)) {
+                case 0x06: // FAT16
+                case 0x0b: // W95 FAT32 (LBA)
+                case 0x0c: // W95 FAT32 (LBA)
+                case 0x0e: // W95 FAT16 (LBA)
+                    createPublicVolume(partDevice);
+                    break;
+                }
+            } else if (table == Table::kGpt) {
+                const char* typeGuid = strtok(nullptr, kSgdiskToken);
+                const char* partGuid = strtok(nullptr, kSgdiskToken);
+
+                if (!strcasecmp(typeGuid, kGptBasicData)) {
+                    createPublicVolume(partDevice);
+                } else if (!strcasecmp(typeGuid, kGptAndroidExpand)) {
+                    createPrivateVolume(partDevice, partGuid);
+                }
+            }
+        }
+    }
+
+    // Ugly last ditch effort, treat entire disk as partition
+    if (table == Table::kUnknown || !foundParts) {
+        LOG(WARNING) << mId << " has unknown partition table; trying entire device";
+
+        std::string fsType;
+        std::string unused;
+        if (ReadMetadataUntrusted(mDevPath, fsType, unused, unused) == OK) {
+            createPublicVolume(mDevice);
+        } else {
+            LOG(WARNING) << mId << " failed to identify, giving up";
+        }
+    }
+
+    notifyEvent(ResponseCode::DiskScanned);
+    mJustPartitioned = false;
+    return OK;
+}
+
+status_t Disk::unmountAll() {
+    for (auto vol : mVolumes) {
+        vol->unmount();
+    }
+    return OK;
+}
+
+status_t Disk::partitionPublic() {
+    // TODO: improve this code
+    destroyAllVolumes();
+    mJustPartitioned = true;
+
+    struct disk_info dinfo;
+    memset(&dinfo, 0, sizeof(dinfo));
+
+    if (!(dinfo.part_lst = (struct part_info *) malloc(
+            MAX_NUM_PARTS * sizeof(struct part_info)))) {
+        return -1;
+    }
+
+    memset(dinfo.part_lst, 0, MAX_NUM_PARTS * sizeof(struct part_info));
+    dinfo.device = strdup(mDevPath.c_str());
+    dinfo.scheme = PART_SCHEME_MBR;
+    dinfo.sect_size = 512;
+    dinfo.skip_lba = 2048;
+    dinfo.num_lba = 0;
+    dinfo.num_parts = 1;
+
+    struct part_info *pinfo = &dinfo.part_lst[0];
+
+    pinfo->name = strdup("android_sdcard");
+    pinfo->flags |= PART_ACTIVE_FLAG;
+    pinfo->type = PC_PART_TYPE_FAT32;
+    pinfo->len_kb = -1;
+
+    int rc = apply_disk_config(&dinfo, 0);
+    if (rc) {
+        LOG(ERROR) << "Failed to apply disk configuration: " << rc;
+        goto out;
+    }
+
+out:
+    free(pinfo->name);
+    free(dinfo.device);
+    free(dinfo.part_lst);
+
+    return rc;
+}
+
+status_t Disk::partitionPrivate() {
+    return partitionMixed(0);
+}
+
+status_t Disk::partitionMixed(int8_t ratio) {
+    int res;
+
+    destroyAllVolumes();
+    mJustPartitioned = true;
+
+    // First nuke any existing partition table
+    std::vector<std::string> cmd;
+    cmd.push_back(kSgdiskPath);
+    cmd.push_back("--zap-all");
+    cmd.push_back(mDevPath);
+
+    // Zap sometimes returns an error when it actually succeeded, so
+    // just log as warning and keep rolling forward.
+    if ((res = ForkExecvp(cmd)) != 0) {
+        LOG(WARNING) << "Failed to zap; status " << res;
+    }
+
+    // We've had some success above, so generate both the private partition
+    // GUID and encryption key and persist them.
+    std::string partGuidRaw;
+    std::string keyRaw;
+    if (ReadRandomBytes(16, partGuidRaw) || ReadRandomBytes(16, keyRaw)) {
+        LOG(ERROR) << "Failed to generate GUID or key";
+        return -EIO;
+    }
+
+    std::string partGuid;
+    StrToHex(partGuidRaw, partGuid);
+
+    if (!WriteStringToFile(keyRaw, BuildKeyPath(partGuid))) {
+        LOG(ERROR) << "Failed to persist key";
+        return -EIO;
+    } else {
+        LOG(DEBUG) << "Persisted key for GUID " << partGuid;
+    }
+
+    // Now let's build the new GPT table. We heavily rely on sgdisk to
+    // force optimal alignment on the created partitions.
+    cmd.clear();
+    cmd.push_back(kSgdiskPath);
+
+    // If requested, create a public partition first. Mixed-mode partitioning
+    // like this is an experimental feature.
+    if (ratio > 0) {
+        if (ratio < 10 || ratio > 90) {
+            LOG(ERROR) << "Mixed partition ratio must be between 10-90%";
+            return -EINVAL;
+        }
+
+        uint64_t splitMb = ((mSize / 100) * ratio) / 1024 / 1024;
+        cmd.push_back(StringPrintf("--new=0:0:+%" PRId64 "M", splitMb));
+        cmd.push_back(StringPrintf("--typecode=0:%s", kGptBasicData));
+        cmd.push_back("--change-name=0:shared");
+    }
+
+    // Define a metadata partition which is designed for future use; there
+    // should only be one of these per physical device, even if there are
+    // multiple private volumes.
+    cmd.push_back("--new=0:0:+16M");
+    cmd.push_back(StringPrintf("--typecode=0:%s", kGptAndroidMeta));
+    cmd.push_back("--change-name=0:android_meta");
+
+    // Define a single private partition filling the rest of disk.
+    cmd.push_back("--new=0:0:-0");
+    cmd.push_back(StringPrintf("--typecode=0:%s", kGptAndroidExpand));
+    cmd.push_back(StringPrintf("--partition-guid=0:%s", partGuid.c_str()));
+    cmd.push_back("--change-name=0:android_expand");
+
+    cmd.push_back(mDevPath);
+
+    if ((res = ForkExecvp(cmd)) != 0) {
+        LOG(ERROR) << "Failed to partition; status " << res;
+        return res;
+    }
+
+    return OK;
+}
+
+void Disk::notifyEvent(int event) {
+    VolumeManager::Instance()->getBroadcaster()->sendBroadcast(event,
+            getId().c_str(), false);
+}
+
+void Disk::notifyEvent(int event, const std::string& value) {
+    VolumeManager::Instance()->getBroadcaster()->sendBroadcast(event,
+            StringPrintf("%s %s", getId().c_str(), value.c_str()).c_str(), false);
+}
+
+int Disk::getMaxMinors() {
+    // Figure out maximum partition devices supported
+    switch (major(mDevice)) {
+    case kMajorBlockScsiA: case kMajorBlockScsiB: case kMajorBlockScsiC: case kMajorBlockScsiD:
+    case kMajorBlockScsiE: case kMajorBlockScsiF: case kMajorBlockScsiG: case kMajorBlockScsiH:
+    case kMajorBlockScsiI: case kMajorBlockScsiJ: case kMajorBlockScsiK: case kMajorBlockScsiL:
+    case kMajorBlockScsiM: case kMajorBlockScsiN: case kMajorBlockScsiO: case kMajorBlockScsiP: {
+        // Per Documentation/devices.txt this is static
+        return 15;
+    }
+    case kMajorBlockMmc: {
+        // Per Documentation/devices.txt this is dynamic
+        std::string tmp;
+        if (!ReadFileToString(kSysfsMmcMaxMinors, &tmp)) {
+            LOG(ERROR) << "Failed to read max minors";
+            return -errno;
+        }
+        return atoi(tmp.c_str());
+    }
+    }
+
+    LOG(ERROR) << "Unsupported block major type " << major(mDevice);
+    return -ENOTSUP;
+}
+
+}  // namespace vold
+}  // namespace android
diff --git a/Disk.h b/Disk.h
new file mode 100644
index 0000000..77ec7df
--- /dev/null
+++ b/Disk.h
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_VOLD_DISK_H
+#define ANDROID_VOLD_DISK_H
+
+#include "Utils.h"
+#include "VolumeBase.h"
+
+#include <utils/Errors.h>
+
+#include <vector>
+
+namespace android {
+namespace vold {
+
+class VolumeBase;
+
+/*
+ * Representation of detected physical media.
+ *
+ * Knows how to create volumes based on the partition tables found, and also
+ * how to repartition itself.
+ */
+class Disk {
+public:
+    Disk(const std::string& eventPath, dev_t device, const std::string& nickname, int flags);
+    virtual ~Disk();
+
+    enum Flags {
+        /* Flag that disk is adoptable */
+        kAdoptable = 1 << 0,
+        /* Flag that disk is considered primary when the user hasn't
+         * explicitly picked a primary storage location */
+        kDefaultPrimary = 1 << 1,
+        /* Flag that disk is SD card */
+        kSd = 1 << 2,
+        /* Flag that disk is USB disk */
+        kUsb = 1 << 3,
+        /* Flag that disk is EMMC internal */
+        kEmmc = 1 << 4,
+    };
+
+    const std::string& getId() { return mId; }
+    const std::string& getEventPath() { return mEventPath; }
+    const std::string& getSysPath() { return mSysPath; }
+    const std::string& getDevPath() { return mDevPath; }
+    dev_t getDevice() { return mDevice; }
+    uint64_t getSize() { return mSize; }
+    const std::string& getLabel() { return mLabel; }
+    int getFlags() { return mFlags; }
+
+    std::shared_ptr<VolumeBase> findVolume(const std::string& id);
+
+    void listVolumes(VolumeBase::Type type, std::list<std::string>& list);
+
+    status_t create();
+    status_t destroy();
+
+    status_t readMetadata();
+    status_t readPartitions();
+
+    status_t unmountAll();
+
+    status_t partitionPublic();
+    status_t partitionPrivate();
+    status_t partitionMixed(int8_t ratio);
+
+    void notifyEvent(int msg);
+    void notifyEvent(int msg, const std::string& value);
+
+private:
+    /* ID that uniquely references this disk */
+    std::string mId;
+    /* Original event path */
+    std::string mEventPath;
+    /* Device path under sysfs */
+    std::string mSysPath;
+    /* Device path under dev */
+    std::string mDevPath;
+    /* Kernel device representing disk */
+    dev_t mDevice;
+    /* Size of disk, in bytes */
+    uint64_t mSize;
+    /* User-visible label, such as manufacturer */
+    std::string mLabel;
+    /* Current partitions on disk */
+    std::vector<std::shared_ptr<VolumeBase>> mVolumes;
+    /* Nickname for this disk */
+    std::string mNickname;
+    /* Flags applicable to this disk */
+    int mFlags;
+    /* Flag indicating object is created */
+    bool mCreated;
+    /* Flag that we just partitioned and should format all volumes */
+    bool mJustPartitioned;
+
+    void createPublicVolume(dev_t device);
+    void createPrivateVolume(dev_t device, const std::string& partGuid);
+
+    void destroyAllVolumes();
+
+    int getMaxMinors();
+
+    DISALLOW_COPY_AND_ASSIGN(Disk);
+};
+
+}  // namespace vold
+}  // namespace android
+
+#endif
diff --git a/EmulatedVolume.cpp b/EmulatedVolume.cpp
new file mode 100644
index 0000000..6e440cc
--- /dev/null
+++ b/EmulatedVolume.cpp
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "EmulatedVolume.h"
+#include "Utils.h"
+
+#include <base/stringprintf.h>
+#include <base/logging.h>
+#include <cutils/fs.h>
+#include <private/android_filesystem_config.h>
+
+#include <fcntl.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+using android::base::StringPrintf;
+
+namespace android {
+namespace vold {
+
+static const char* kFusePath = "/system/bin/sdcard";
+
+EmulatedVolume::EmulatedVolume(const std::string& rawPath) :
+        VolumeBase(Type::kEmulated), mFusePid(0) {
+    setId("emulated");
+    mRawPath = rawPath;
+    mLabel = "emulated";
+}
+
+EmulatedVolume::EmulatedVolume(const std::string& rawPath, dev_t device,
+        const std::string& fsUuid) : VolumeBase(Type::kEmulated), mFusePid(0) {
+    setId(StringPrintf("emulated:%u,%u", major(device), minor(device)));
+    mRawPath = rawPath;
+    mLabel = fsUuid;
+}
+
+EmulatedVolume::~EmulatedVolume() {
+}
+
+status_t EmulatedVolume::doMount() {
+    // We could have migrated storage to an adopted private volume, so always
+    // call primary storage "emulated" to avoid media rescans.
+    std::string label = mLabel;
+    if (getMountFlags() & MountFlags::kPrimary) {
+        label = "emulated";
+    }
+
+    mFuseDefault = StringPrintf("/mnt/runtime/default/%s", label.c_str());
+    mFuseRead = StringPrintf("/mnt/runtime/read/%s", label.c_str());
+    mFuseWrite = StringPrintf("/mnt/runtime/write/%s", label.c_str());
+
+    setInternalPath(mRawPath);
+    setPath(StringPrintf("/storage/%s", label.c_str()));
+
+    if (fs_prepare_dir(mFuseDefault.c_str(), 0700, AID_ROOT, AID_ROOT) ||
+            fs_prepare_dir(mFuseRead.c_str(), 0700, AID_ROOT, AID_ROOT) ||
+            fs_prepare_dir(mFuseWrite.c_str(), 0700, AID_ROOT, AID_ROOT)) {
+        PLOG(ERROR) << getId() << " failed to create mount points";
+        return -errno;
+    }
+
+    dev_t before = GetDevice(mFuseWrite);
+
+    if (!(mFusePid = fork())) {
+        if (execl(kFusePath, kFusePath,
+                "-u", "1023", // AID_MEDIA_RW
+                "-g", "1023", // AID_MEDIA_RW
+                "-m",
+                "-w",
+                mRawPath.c_str(),
+                label.c_str(),
+                NULL)) {
+            PLOG(ERROR) << "Failed to exec";
+        }
+
+        LOG(ERROR) << "FUSE exiting";
+        _exit(1);
+    }
+
+    if (mFusePid == -1) {
+        PLOG(ERROR) << getId() << " failed to fork";
+        return -errno;
+    }
+
+    while (before == GetDevice(mFuseWrite)) {
+        LOG(VERBOSE) << "Waiting for FUSE to spin up...";
+        usleep(50000); // 50ms
+    }
+
+    return OK;
+}
+
+status_t EmulatedVolume::doUnmount() {
+    if (mFusePid > 0) {
+        kill(mFusePid, SIGTERM);
+        TEMP_FAILURE_RETRY(waitpid(mFusePid, nullptr, 0));
+        mFusePid = 0;
+    }
+
+    ForceUnmount(mFuseDefault);
+    ForceUnmount(mFuseRead);
+    ForceUnmount(mFuseWrite);
+
+    rmdir(mFuseDefault.c_str());
+    rmdir(mFuseRead.c_str());
+    rmdir(mFuseWrite.c_str());
+
+    mFuseDefault.clear();
+    mFuseRead.clear();
+    mFuseWrite.clear();
+
+    return OK;
+}
+
+}  // namespace vold
+}  // namespace android
diff --git a/EmulatedVolume.h b/EmulatedVolume.h
new file mode 100644
index 0000000..09686c1
--- /dev/null
+++ b/EmulatedVolume.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_VOLD_EMULATED_VOLUME_H
+#define ANDROID_VOLD_EMULATED_VOLUME_H
+
+#include "VolumeBase.h"
+
+#include <cutils/multiuser.h>
+
+namespace android {
+namespace vold {
+
+/*
+ * Shared storage emulated on top of private storage.
+ *
+ * Knows how to spawn a FUSE daemon to synthesize permissions.  ObbVolume
+ * can be stacked above it.
+ *
+ * This volume is always multi-user aware, but is only binds itself to
+ * users when its primary storage.  This volume should never be presented
+ * as secondary storage, since we're strongly encouraging developers to
+ * store data local to their app.
+ */
+class EmulatedVolume : public VolumeBase {
+public:
+    EmulatedVolume(const std::string& rawPath);
+    EmulatedVolume(const std::string& rawPath, dev_t device, const std::string& fsUuid);
+    virtual ~EmulatedVolume();
+
+protected:
+    status_t doMount() override;
+    status_t doUnmount() override;
+
+private:
+    std::string mRawPath;
+    std::string mLabel;
+
+    std::string mFuseDefault;
+    std::string mFuseRead;
+    std::string mFuseWrite;
+
+    /* PID of FUSE wrapper */
+    pid_t mFusePid;
+
+    DISALLOW_COPY_AND_ASSIGN(EmulatedVolume);
+};
+
+}  // namespace vold
+}  // namespace android
+
+#endif
diff --git a/Ext4.cpp b/Ext4.cpp
deleted file mode 100644
index f5a964a..0000000
--- a/Ext4.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <dirent.h>
-#include <errno.h>
-#include <fcntl.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/mount.h>
-#include <sys/wait.h>
-
-#include <linux/kdev_t.h>
-
-#define LOG_TAG "Vold"
-
-#include <cutils/log.h>
-#include <cutils/properties.h>
-
-#include <logwrap/logwrap.h>
-
-#include "Ext4.h"
-#include "VoldUtil.h"
-
-#define MKEXT4FS_PATH "/system/bin/make_ext4fs"
-#define RESIZE2FS_PATH "/system/bin/resize2fs"
-
-int Ext4::doMount(const char *fsPath, const char *mountPoint, bool ro, bool remount,
-        bool executable) {
-    int rc;
-    unsigned long flags;
-
-    flags = MS_NOATIME | MS_NODEV | MS_NOSUID | MS_DIRSYNC;
-
-    flags |= (executable ? 0 : MS_NOEXEC);
-    flags |= (ro ? MS_RDONLY : 0);
-    flags |= (remount ? MS_REMOUNT : 0);
-
-    rc = mount(fsPath, mountPoint, "ext4", flags, NULL);
-
-    if (rc && errno == EROFS) {
-        SLOGE("%s appears to be a read only filesystem - retrying mount RO", fsPath);
-        flags |= MS_RDONLY;
-        rc = mount(fsPath, mountPoint, "ext4", flags, NULL);
-    }
-
-    return rc;
-}
-
-int Ext4::resize(const char *fspath, unsigned int numSectors) {
-    const char *args[4];
-    char* size_str;
-    int rc;
-    int status;
-
-    args[0] = RESIZE2FS_PATH;
-    args[1] = "-f";
-    args[2] = fspath;
-    if (asprintf(&size_str, "%ds", numSectors) < 0)
-    {
-      SLOGE("Filesystem (ext4) resize failed to set size");
-      return -1;
-    }
-    args[3] = size_str;
-    rc = android_fork_execvp(ARRAY_SIZE(args), (char **)args, &status, false,
-            true);
-    free(size_str);
-    if (rc != 0) {
-        SLOGE("Filesystem (ext4) resize failed due to logwrap error");
-        errno = EIO;
-        return -1;
-    }
-
-    if (!WIFEXITED(status)) {
-        SLOGE("Filesystem (ext4) resize did not exit properly");
-        errno = EIO;
-        return -1;
-    }
-
-    status = WEXITSTATUS(status);
-
-    if (status == 0) {
-        SLOGI("Filesystem (ext4) resized OK");
-        return 0;
-    } else {
-        SLOGE("Resize (ext4) failed (unknown exit code %d)", status);
-        errno = EIO;
-        return -1;
-    }
-    return 0;
-}
-
-int Ext4::format(const char *fsPath, unsigned int numSectors, const char *mountpoint) {
-    const char *args[7];
-    int rc;
-    int status;
-
-    args[0] = MKEXT4FS_PATH;
-    args[1] = "-J";
-    args[2] = "-a";
-    args[3] = mountpoint;
-    if (numSectors) {
-        char tmp[32];
-        snprintf(tmp, sizeof(tmp), "%u", numSectors * 512);
-        const char *size = tmp;
-        args[4] = "-l";
-        args[5] = size;
-        args[6] = fsPath;
-        rc = android_fork_execvp(ARRAY_SIZE(args), (char **)args, &status, false, true);
-    } else {
-        args[4] = fsPath;
-        rc = android_fork_execvp(5, (char **)args, &status, false, true);
-    }
-    rc = android_fork_execvp(ARRAY_SIZE(args), (char **)args, &status, false,
-            true);
-    if (rc != 0) {
-        SLOGE("Filesystem (ext4) format failed due to logwrap error");
-        errno = EIO;
-        return -1;
-    }
-
-    if (!WIFEXITED(status)) {
-        SLOGE("Filesystem (ext4) format did not exit properly");
-        errno = EIO;
-        return -1;
-    }
-
-    status = WEXITSTATUS(status);
-
-    if (status == 0) {
-        SLOGI("Filesystem (ext4) formatted OK");
-        return 0;
-    } else {
-        SLOGE("Format (ext4) failed (unknown exit code %d)", status);
-        errno = EIO;
-        return -1;
-    }
-    return 0;
-}
diff --git a/Ext4.h b/Ext4.h
deleted file mode 100644
index c768f5a..0000000
--- a/Ext4.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _EXT4_H
-#define _EXT4_H
-
-#include <unistd.h>
-
-class Ext4 {
-public:
-    static int doMount(const char *fsPath, const char *mountPoint, bool ro, bool remount,
-            bool executable);
-    static int format(const char *fsPath, unsigned int numSectors, const char *mountpoint);
-    static int resize(const char *fsPath, unsigned int numSectors);
-};
-
-#endif
diff --git a/Fat.cpp b/Fat.cpp
deleted file mode 100644
index 0c0bdaa..0000000
--- a/Fat.cpp
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <dirent.h>
-#include <errno.h>
-#include <fcntl.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/mount.h>
-#include <sys/wait.h>
-#include <linux/fs.h>
-#include <sys/ioctl.h>
-
-#include <linux/kdev_t.h>
-
-#define LOG_TAG "Vold"
-
-#include <cutils/log.h>
-#include <cutils/properties.h>
-
-#include <logwrap/logwrap.h>
-
-#include "Fat.h"
-#include "VoldUtil.h"
-
-static char FSCK_MSDOS_PATH[] = "/system/bin/fsck_msdos";
-static char MKDOSFS_PATH[] = "/system/bin/newfs_msdos";
-extern "C" int mount(const char *, const char *, const char *, unsigned long, const void *);
-
-int Fat::check(const char *fsPath) {
-    if (access(FSCK_MSDOS_PATH, X_OK)) {
-        SLOGW("Skipping fs checks\n");
-        return 0;
-    }
-
-    int pass = 1;
-    int rc = 0;
-    do {
-        const char *args[4];
-        int status;
-        args[0] = FSCK_MSDOS_PATH;
-        args[1] = "-p";
-        args[2] = "-f";
-        args[3] = fsPath;
-
-        rc = android_fork_execvp(ARRAY_SIZE(args), (char **)args, &status,
-                false, true);
-        if (rc != 0) {
-            SLOGE("Filesystem check failed due to logwrap error");
-            errno = EIO;
-            return -1;
-        }
-
-        if (!WIFEXITED(status)) {
-            SLOGE("Filesystem check did not exit properly");
-            errno = EIO;
-            return -1;
-        }
-
-        status = WEXITSTATUS(status);
-
-        switch(status) {
-        case 0:
-            SLOGI("Filesystem check completed OK");
-            return 0;
-
-        case 2:
-            SLOGE("Filesystem check failed (not a FAT filesystem)");
-            errno = ENODATA;
-            return -1;
-
-        case 4:
-            if (pass++ <= 3) {
-                SLOGW("Filesystem modified - rechecking (pass %d)",
-                        pass);
-                continue;
-            }
-            SLOGE("Failing check after too many rechecks");
-            errno = EIO;
-            return -1;
-
-        default:
-            SLOGE("Filesystem check failed (unknown exit code %d)", status);
-            errno = EIO;
-            return -1;
-        }
-    } while (0);
-
-    return 0;
-}
-
-int Fat::doMount(const char *fsPath, const char *mountPoint,
-                 bool ro, bool remount, bool executable,
-                 int ownerUid, int ownerGid, int permMask, bool createLost) {
-    int rc;
-    unsigned long flags;
-    char mountData[255];
-
-    flags = MS_NODEV | MS_NOSUID | MS_DIRSYNC;
-
-    flags |= (executable ? 0 : MS_NOEXEC);
-    flags |= (ro ? MS_RDONLY : 0);
-    flags |= (remount ? MS_REMOUNT : 0);
-
-    sprintf(mountData,
-            "utf8,uid=%d,gid=%d,fmask=%o,dmask=%o,shortname=mixed",
-            ownerUid, ownerGid, permMask, permMask);
-
-    rc = mount(fsPath, mountPoint, "vfat", flags, mountData);
-
-    if (rc && errno == EROFS) {
-        SLOGE("%s appears to be a read only filesystem - retrying mount RO", fsPath);
-        flags |= MS_RDONLY;
-        rc = mount(fsPath, mountPoint, "vfat", flags, mountData);
-    }
-
-    if (rc == 0 && createLost) {
-        char *lost_path;
-        asprintf(&lost_path, "%s/LOST.DIR", mountPoint);
-        if (access(lost_path, F_OK)) {
-            /*
-             * Create a LOST.DIR in the root so we have somewhere to put
-             * lost cluster chains (fsck_msdos doesn't currently do this)
-             */
-            if (mkdir(lost_path, 0755)) {
-                SLOGE("Unable to create LOST.DIR (%s)", strerror(errno));
-            }
-        }
-        free(lost_path);
-    }
-
-    return rc;
-}
-
-int Fat::format(const char *fsPath, unsigned int numSectors, bool wipe) {
-    const char *args[11];
-    int rc;
-    int status;
-
-    if (wipe) {
-        Fat::wipe(fsPath, numSectors);
-    }
-
-    args[0] = MKDOSFS_PATH;
-    args[1] = "-F";
-    args[2] = "32";
-    args[3] = "-O";
-    args[4] = "android";
-    args[5] = "-c";
-    args[6] = "64";
-    args[7] = "-A";
-
-    if (numSectors) {
-        char tmp[32];
-        snprintf(tmp, sizeof(tmp), "%u", numSectors);
-        const char *size = tmp;
-        args[8] = "-s";
-        args[9] = size;
-        args[10] = fsPath;
-        rc = android_fork_execvp(ARRAY_SIZE(args), (char **)args, &status,
-                false, true);
-    } else {
-        args[8] = fsPath;
-        rc = android_fork_execvp(9, (char **)args, &status, false,
-                true);
-    }
-
-    if (rc != 0) {
-        SLOGE("Filesystem format failed due to logwrap error");
-        errno = EIO;
-        return -1;
-    }
-
-    if (!WIFEXITED(status)) {
-        SLOGE("Filesystem format did not exit properly");
-        errno = EIO;
-        return -1;
-    }
-
-    status = WEXITSTATUS(status);
-
-    if (status == 0) {
-        SLOGI("Filesystem formatted OK");
-        return 0;
-    } else {
-        SLOGE("Format failed (unknown exit code %d)", status);
-        errno = EIO;
-        return -1;
-    }
-    return 0;
-}
-
-void Fat::wipe(const char *fsPath, unsigned int numSectors) {
-    unsigned long long range[2];
-
-    int fd = open(fsPath, O_RDWR);
-    if (fd == -1) {
-        SLOGE("Fat wipe failed to open device %s", fsPath);
-        return;
-    }
-
-    if (numSectors == 0) {
-        unsigned long nr_sec;
-        get_blkdev_size(fd, &nr_sec);
-        if (nr_sec > UINT32_MAX) {
-            SLOGE("Too many sectors for FAT: %ld", nr_sec);
-            close(fd);
-            return;
-        }
-        numSectors = nr_sec;
-    }
-    if (numSectors == 0) {
-        SLOGE("Fat wipe failed to determine size of %s", fsPath);
-        close(fd);
-        return;
-    }
-    range[0] = 0;
-    range[1] = (unsigned long long)numSectors * 512;
-    if (ioctl(fd, BLKDISCARD, &range) < 0) {
-        SLOGE("Fat wipe failed to discard blocks on %s", fsPath);
-    } else {
-        SLOGI("Fat wipe %d sectors on %s succeeded", numSectors, fsPath);
-    }
-    close(fd);
-}
diff --git a/Fat.h b/Fat.h
deleted file mode 100644
index 19614d1..0000000
--- a/Fat.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _FAT_H
-#define _FAT_H
-
-#include <unistd.h>
-
-class Fat {
-public:
-    static int check(const char *fsPath);
-    static int doMount(const char *fsPath, const char *mountPoint,
-                       bool ro, bool remount, bool executable,
-                       int ownerUid, int ownerGid, int permMask,
-                       bool createLost);
-    static int format(const char *fsPath, unsigned int numSectors, bool wipe);
-
-private:
-    static void wipe(const char *fsPath, unsigned int numSectors);
-};
-
-#endif
diff --git a/Loop.cpp b/Loop.cpp
index 37ad102..059b963 100644
--- a/Loop.cpp
+++ b/Loop.cpp
@@ -49,7 +49,7 @@
 
         sprintf(filename, "/dev/block/loop%d", i);
 
-        if ((fd = open(filename, O_RDWR)) < 0) {
+        if ((fd = open(filename, O_RDWR | O_CLOEXEC)) < 0) {
             if (errno != ENOENT) {
                 SLOGE("Unable to open %s (%s)", filename, strerror(errno));
             } else {
@@ -93,7 +93,7 @@
 
         sprintf(filename, "/dev/block/loop%d", i);
 
-        if ((fd = open(filename, O_RDWR)) < 0) {
+        if ((fd = open(filename, O_RDWR | O_CLOEXEC)) < 0) {
             if (errno != ENOENT) {
                 SLOGE("Unable to open %s (%s)", filename, strerror(errno));
             } else {
@@ -169,7 +169,7 @@
             setfscreatecon(NULL);
         }
 
-        if ((fd = open(filename, O_RDWR)) < 0) {
+        if ((fd = open(filename, O_RDWR | O_CLOEXEC)) < 0) {
             SLOGE("Unable to open %s (%s)", filename, strerror(errno));
             return -1;
         }
@@ -197,7 +197,7 @@
 
     int file_fd;
 
-    if ((file_fd = open(loopFile, O_RDWR)) < 0) {
+    if ((file_fd = open(loopFile, O_RDWR | O_CLOEXEC)) < 0) {
         SLOGE("Unable to open %s (%s)", loopFile, strerror(errno));
         close(fd);
         return -1;
@@ -232,7 +232,7 @@
 int Loop::destroyByDevice(const char *loopDevice) {
     int device_fd;
 
-    device_fd = open(loopDevice, O_RDONLY);
+    device_fd = open(loopDevice, O_RDONLY | O_CLOEXEC);
     if (device_fd < 0) {
         SLOGE("Failed to open loop (%d)", errno);
         return -1;
@@ -273,7 +273,7 @@
 int Loop::resizeImageFile(const char *file, unsigned int numSectors) {
     int fd;
 
-    if ((fd = open(file, O_RDWR)) < 0) {
+    if ((fd = open(file, O_RDWR | O_CLOEXEC)) < 0) {
         SLOGE("Error opening imagefile (%s)", strerror(errno));
         return -1;
     }
@@ -302,7 +302,7 @@
     int fd;
     struct asec_superblock buffer;
 
-    if ((fd = open(loopDevice, O_RDONLY)) < 0) {
+    if ((fd = open(loopDevice, O_RDONLY | O_CLOEXEC)) < 0) {
         SLOGE("Failed to open loopdevice (%s)", strerror(errno));
         destroyByDevice(loopDevice);
         return -1;
diff --git a/MoveTask.cpp b/MoveTask.cpp
new file mode 100644
index 0000000..10cd549
--- /dev/null
+++ b/MoveTask.cpp
@@ -0,0 +1,224 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "MoveTask.h"
+#include "Utils.h"
+#include "VolumeManager.h"
+#include "ResponseCode.h"
+
+#include <base/stringprintf.h>
+#include <base/logging.h>
+#include <private/android_filesystem_config.h>
+#include <hardware_legacy/power.h>
+
+#include <dirent.h>
+#include <sys/wait.h>
+
+#define CONSTRAIN(amount, low, high) (amount < low ? low : (amount > high ? high : amount))
+
+using android::base::StringPrintf;
+
+namespace android {
+namespace vold {
+
+// TODO: keep in sync with PackageManager
+static const int kMoveSucceeded = -100;
+static const int kMoveFailedInternalError = -6;
+
+static const char* kCpPath = "/system/bin/cp";
+static const char* kRmPath = "/system/bin/rm";
+
+static const char* kWakeLock = "MoveTask";
+
+MoveTask::MoveTask(const std::shared_ptr<VolumeBase>& from,
+        const std::shared_ptr<VolumeBase>& to) :
+        mFrom(from), mTo(to) {
+}
+
+MoveTask::~MoveTask() {
+}
+
+void MoveTask::start() {
+    mThread = std::thread(&MoveTask::run, this);
+}
+
+static void notifyProgress(int progress) {
+    VolumeManager::Instance()->getBroadcaster()->sendBroadcast(ResponseCode::MoveStatus,
+            StringPrintf("%d", progress).c_str(), false);
+}
+
+static status_t pushBackContents(const std::string& path, std::vector<std::string>& cmd) {
+    DIR* dir = opendir(path.c_str());
+    if (dir == NULL) {
+        return -1;
+    }
+    bool found = false;
+    struct dirent* ent;
+    while ((ent = readdir(dir)) != NULL) {
+        if ((!strcmp(ent->d_name, ".")) || (!strcmp(ent->d_name, ".."))) {
+            continue;
+        }
+        cmd.push_back(StringPrintf("%s/%s", path.c_str(), ent->d_name));
+        found = true;
+    }
+    closedir(dir);
+    return found ? OK : -1;
+}
+
+static status_t execRm(const std::string& path, int startProgress, int stepProgress) {
+    notifyProgress(startProgress);
+
+    uint64_t expectedBytes = GetTreeBytes(path);
+    uint64_t startFreeBytes = GetFreeBytes(path);
+
+    std::vector<std::string> cmd;
+    cmd.push_back(kRmPath);
+    cmd.push_back("-f"); /* force: remove without confirmation, no error if it doesn't exist */
+    cmd.push_back("-R"); /* recursive: remove directory contents */
+    if (pushBackContents(path, cmd) != OK) {
+        LOG(WARNING) << "No contents in " << path;
+        return OK;
+    }
+
+    pid_t pid = ForkExecvpAsync(cmd);
+    if (pid == -1) return -1;
+
+    int status;
+    while (true) {
+        if (waitpid(pid, &status, WNOHANG) == pid) {
+            if (WIFEXITED(status)) {
+                LOG(DEBUG) << "Finished rm with status " << WEXITSTATUS(status);
+                return (WEXITSTATUS(status) == 0) ? OK : -1;
+            } else {
+                break;
+            }
+        }
+
+        sleep(1);
+        uint64_t deltaFreeBytes = GetFreeBytes(path) - startFreeBytes;
+        notifyProgress(startProgress + CONSTRAIN((int)
+                ((deltaFreeBytes * stepProgress) / expectedBytes), 0, stepProgress));
+    }
+    return -1;
+}
+
+static status_t execCp(const std::string& fromPath, const std::string& toPath,
+        int startProgress, int stepProgress) {
+    notifyProgress(startProgress);
+
+    uint64_t expectedBytes = GetTreeBytes(fromPath);
+    uint64_t startFreeBytes = GetFreeBytes(toPath);
+
+    std::vector<std::string> cmd;
+    cmd.push_back(kCpPath);
+    cmd.push_back("-p"); /* preserve timestamps, ownership, and permissions */
+    cmd.push_back("-R"); /* recurse into subdirectories (DEST must be a directory) */
+    cmd.push_back("-P"); /* Do not follow symlinks [default] */
+    cmd.push_back("-d"); /* don't dereference symlinks */
+    if (pushBackContents(fromPath, cmd) != OK) {
+        LOG(WARNING) << "No contents in " << fromPath;
+        return OK;
+    }
+    cmd.push_back(toPath.c_str());
+
+    pid_t pid = ForkExecvpAsync(cmd);
+    if (pid == -1) return -1;
+
+    int status;
+    while (true) {
+        if (waitpid(pid, &status, WNOHANG) == pid) {
+            if (WIFEXITED(status)) {
+                LOG(DEBUG) << "Finished cp with status " << WEXITSTATUS(status);
+                return (WEXITSTATUS(status) == 0) ? OK : -1;
+            } else {
+                break;
+            }
+        }
+
+        sleep(1);
+        uint64_t deltaFreeBytes = startFreeBytes - GetFreeBytes(toPath);
+        notifyProgress(startProgress + CONSTRAIN((int)
+                ((deltaFreeBytes * stepProgress) / expectedBytes), 0, stepProgress));
+    }
+    return -1;
+}
+
+static void bringOffline(const std::shared_ptr<VolumeBase>& vol) {
+    vol->destroy();
+    vol->setSilent(true);
+    vol->create();
+    vol->setMountFlags(0);
+    vol->mount();
+}
+
+static void bringOnline(const std::shared_ptr<VolumeBase>& vol) {
+    vol->destroy();
+    vol->setSilent(false);
+    vol->create();
+}
+
+void MoveTask::run() {
+    acquire_wake_lock(PARTIAL_WAKE_LOCK, kWakeLock);
+
+    std::string fromPath;
+    std::string toPath;
+
+    // TODO: add support for public volumes
+    if (mFrom->getType() != VolumeBase::Type::kEmulated) goto fail;
+    if (mTo->getType() != VolumeBase::Type::kEmulated) goto fail;
+
+    // Step 1: tear down volumes and mount silently without making
+    // visible to userspace apps
+    bringOffline(mFrom);
+    bringOffline(mTo);
+
+    fromPath = mFrom->getInternalPath();
+    toPath = mTo->getInternalPath();
+
+    // Step 2: clean up any stale data
+    if (execRm(toPath, 10, 10) != OK) {
+        goto fail;
+    }
+
+    // Step 3: perform actual copy
+    if (execCp(fromPath, toPath, 20, 60) != OK) {
+        goto fail;
+    }
+
+    // NOTE: MountService watches for this magic value to know
+    // that move was successful
+    notifyProgress(82);
+    bringOnline(mFrom);
+    bringOnline(mTo);
+
+    // Step 4: clean up old data
+    if (execRm(fromPath, 85, 15) != OK) {
+        goto fail;
+    }
+
+    notifyProgress(kMoveSucceeded);
+    release_wake_lock(kWakeLock);
+    return;
+fail:
+    bringOnline(mFrom);
+    bringOnline(mTo);
+    notifyProgress(kMoveFailedInternalError);
+    release_wake_lock(kWakeLock);
+    return;
+}
+
+}  // namespace vold
+}  // namespace android
diff --git a/MoveTask.h b/MoveTask.h
new file mode 100644
index 0000000..b1777c0
--- /dev/null
+++ b/MoveTask.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_VOLD_MOVE_TASK_H
+#define ANDROID_VOLD_MOVE_TASK_H
+
+#include "Utils.h"
+#include "VolumeBase.h"
+
+#include <thread>
+
+namespace android {
+namespace vold {
+
+class MoveTask {
+public:
+    MoveTask(const std::shared_ptr<VolumeBase>& from, const std::shared_ptr<VolumeBase>& to);
+    virtual ~MoveTask();
+
+    void start();
+
+private:
+    std::shared_ptr<VolumeBase> mFrom;
+    std::shared_ptr<VolumeBase> mTo;
+    std::thread mThread;
+
+    void run();
+
+    DISALLOW_COPY_AND_ASSIGN(MoveTask);
+};
+
+}  // namespace vold
+}  // namespace android
+
+#endif
diff --git a/NetlinkManager.cpp b/NetlinkManager.cpp
index d2e16b2..b5069a6 100644
--- a/NetlinkManager.cpp
+++ b/NetlinkManager.cpp
@@ -58,8 +58,8 @@
     nladdr.nl_pid = getpid();
     nladdr.nl_groups = 0xffffffff;
 
-    if ((mSock = socket(PF_NETLINK,
-                        SOCK_DGRAM,NETLINK_KOBJECT_UEVENT)) < 0) {
+    if ((mSock = socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC,
+            NETLINK_KOBJECT_UEVENT)) < 0) {
         SLOGE("Unable to create uevent socket: %s", strerror(errno));
         return -1;
     }
diff --git a/PrivateVolume.cpp b/PrivateVolume.cpp
new file mode 100644
index 0000000..6ddef3f
--- /dev/null
+++ b/PrivateVolume.cpp
@@ -0,0 +1,223 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "fs/Ext4.h"
+#include "fs/F2fs.h"
+#include "PrivateVolume.h"
+#include "EmulatedVolume.h"
+#include "Utils.h"
+#include "VolumeManager.h"
+#include "ResponseCode.h"
+#include "cryptfs.h"
+
+#include <base/stringprintf.h>
+#include <base/logging.h>
+#include <cutils/fs.h>
+#include <private/android_filesystem_config.h>
+
+#include <fcntl.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/param.h>
+
+using android::base::StringPrintf;
+
+namespace android {
+namespace vold {
+
+static const unsigned int kMajorBlockMmc = 179;
+
+PrivateVolume::PrivateVolume(dev_t device, const std::string& keyRaw) :
+        VolumeBase(Type::kPrivate), mRawDevice(device), mKeyRaw(keyRaw) {
+    setId(StringPrintf("private:%u,%u", major(device), minor(device)));
+    mRawDevPath = StringPrintf("/dev/block/vold/%s", getId().c_str());
+}
+
+PrivateVolume::~PrivateVolume() {
+}
+
+status_t PrivateVolume::readMetadata() {
+    status_t res = ReadMetadata(mDmDevPath, mFsType, mFsUuid, mFsLabel);
+    notifyEvent(ResponseCode::VolumeFsTypeChanged, mFsType);
+    notifyEvent(ResponseCode::VolumeFsUuidChanged, mFsUuid);
+    notifyEvent(ResponseCode::VolumeFsLabelChanged, mFsLabel);
+    return res;
+}
+
+status_t PrivateVolume::doCreate() {
+    if (CreateDeviceNode(mRawDevPath, mRawDevice)) {
+        return -EIO;
+    }
+
+    // Recover from stale vold by tearing down any old mappings
+    cryptfs_revert_ext_volume(getId().c_str());
+
+    // TODO: figure out better SELinux labels for private volumes
+
+    unsigned char* key = (unsigned char*) mKeyRaw.data();
+    char crypto_blkdev[MAXPATHLEN];
+    int res = cryptfs_setup_ext_volume(getId().c_str(), mRawDevPath.c_str(),
+            key, mKeyRaw.size(), crypto_blkdev);
+    mDmDevPath = crypto_blkdev;
+    if (res != 0) {
+        PLOG(ERROR) << getId() << " failed to setup cryptfs";
+        return -EIO;
+    }
+
+    return OK;
+}
+
+status_t PrivateVolume::doDestroy() {
+    if (cryptfs_revert_ext_volume(getId().c_str())) {
+        LOG(ERROR) << getId() << " failed to revert cryptfs";
+    }
+    return DestroyDeviceNode(mRawDevPath);
+}
+
+status_t PrivateVolume::doMount() {
+    if (readMetadata()) {
+        LOG(ERROR) << getId() << " failed to read metadata";
+        return -EIO;
+    }
+
+    mPath = StringPrintf("/mnt/expand/%s", mFsUuid.c_str());
+    setPath(mPath);
+
+    if (PrepareDir(mPath, 0700, AID_ROOT, AID_ROOT)) {
+        PLOG(ERROR) << getId() << " failed to create mount point " << mPath;
+        return -EIO;
+    }
+
+    if (mFsType == "ext4") {
+        int res = ext4::Check(mDmDevPath, mPath);
+        if (res == 0 || res == 1) {
+            LOG(DEBUG) << getId() << " passed filesystem check";
+        } else {
+            PLOG(ERROR) << getId() << " failed filesystem check";
+            return -EIO;
+        }
+
+        if (ext4::Mount(mDmDevPath, mPath, false, false, true)) {
+            PLOG(ERROR) << getId() << " failed to mount";
+            return -EIO;
+        }
+
+    } else if (mFsType == "f2fs") {
+        int res = f2fs::Check(mDmDevPath);
+        if (res == 0) {
+            LOG(DEBUG) << getId() << " passed filesystem check";
+        } else {
+            PLOG(ERROR) << getId() << " failed filesystem check";
+            return -EIO;
+        }
+
+        if (f2fs::Mount(mDmDevPath, mPath)) {
+            PLOG(ERROR) << getId() << " failed to mount";
+            return -EIO;
+        }
+
+    } else {
+        LOG(ERROR) << getId() << " unsupported filesystem " << mFsType;
+        return -EIO;
+    }
+
+    LOG(VERBOSE) << "Starting restorecon of " << mPath;
+
+    // TODO: find a cleaner way of waiting for restorecon to finish
+    property_set("selinux.restorecon_recursive", "");
+    property_set("selinux.restorecon_recursive", mPath.c_str());
+
+    char value[PROPERTY_VALUE_MAX];
+    while (true) {
+        property_get("selinux.restorecon_recursive", value, "");
+        if (strcmp(mPath.c_str(), value) == 0) {
+            break;
+        }
+        sleep(1);
+        LOG(VERBOSE) << "Waiting for restorecon...";
+    }
+
+    LOG(VERBOSE) << "Finished restorecon of " << mPath;
+
+    // Verify that common directories are ready to roll
+    if (PrepareDir(mPath + "/app", 0771, AID_SYSTEM, AID_SYSTEM) ||
+            PrepareDir(mPath + "/user", 0711, AID_SYSTEM, AID_SYSTEM) ||
+            PrepareDir(mPath + "/media", 0770, AID_MEDIA_RW, AID_MEDIA_RW) ||
+            PrepareDir(mPath + "/media/0", 0770, AID_MEDIA_RW, AID_MEDIA_RW) ||
+            PrepareDir(mPath + "/local", 0751, AID_ROOT, AID_ROOT) ||
+            PrepareDir(mPath + "/local/tmp", 0771, AID_SHELL, AID_SHELL)) {
+        PLOG(ERROR) << getId() << " failed to prepare";
+        return -EIO;
+    }
+
+    // Create a new emulated volume stacked above us, it will automatically
+    // be destroyed during unmount
+    std::string mediaPath(mPath + "/media");
+    auto vol = std::shared_ptr<VolumeBase>(
+            new EmulatedVolume(mediaPath, mRawDevice, mFsUuid));
+    addVolume(vol);
+    vol->create();
+
+    return OK;
+}
+
+status_t PrivateVolume::doUnmount() {
+    ForceUnmount(mPath);
+
+    if (TEMP_FAILURE_RETRY(rmdir(mPath.c_str()))) {
+        PLOG(ERROR) << getId() << " failed to rmdir mount point " << mPath;
+    }
+
+    return OK;
+}
+
+status_t PrivateVolume::doFormat(const std::string& fsType) {
+    std::string resolvedFsType = fsType;
+    if (fsType == "auto") {
+        // For now, assume that all MMC devices are flash-based SD cards, and
+        // give everyone else ext4 because sysfs rotational isn't reliable.
+        if ((major(mRawDevice) == kMajorBlockMmc) && f2fs::IsSupported()) {
+            resolvedFsType = "f2fs";
+        } else {
+            resolvedFsType = "ext4";
+        }
+        LOG(DEBUG) << "Resolved auto to " << resolvedFsType;
+    }
+
+    if (resolvedFsType == "ext4") {
+        // TODO: change reported mountpoint once we have better selinux support
+        if (ext4::Format(mDmDevPath, 0, "/data")) {
+            PLOG(ERROR) << getId() << " failed to format";
+            return -EIO;
+        }
+    } else if (resolvedFsType == "f2fs") {
+        if (f2fs::Format(mDmDevPath)) {
+            PLOG(ERROR) << getId() << " failed to format";
+            return -EIO;
+        }
+    } else {
+        LOG(ERROR) << getId() << " unsupported filesystem " << fsType;
+        return -EINVAL;
+    }
+
+    return OK;
+}
+
+}  // namespace vold
+}  // namespace android
diff --git a/PrivateVolume.h b/PrivateVolume.h
new file mode 100644
index 0000000..95b718d
--- /dev/null
+++ b/PrivateVolume.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_VOLD_PRIVATE_VOLUME_H
+#define ANDROID_VOLD_PRIVATE_VOLUME_H
+
+#include "VolumeBase.h"
+
+#include <cutils/multiuser.h>
+
+namespace android {
+namespace vold {
+
+/*
+ * Private storage provided by an encrypted partition.
+ *
+ * Given a raw block device, it knows how to wrap it in dm-crypt and
+ * format as ext4/f2fs.  EmulatedVolume can be stacked above it.
+ *
+ * This volume is designed to behave much like the internal /data
+ * partition, both in layout and function.  For example, apps and
+ * private app data can be safely stored on this volume because the
+ * keys are tightly tied to this device.
+ */
+class PrivateVolume : public VolumeBase {
+public:
+    PrivateVolume(dev_t device, const std::string& keyRaw);
+    virtual ~PrivateVolume();
+
+protected:
+    status_t doCreate() override;
+    status_t doDestroy() override;
+    status_t doMount() override;
+    status_t doUnmount() override;
+    status_t doFormat(const std::string& fsType) override;
+
+    status_t readMetadata();
+
+private:
+    /* Kernel device of raw, encrypted partition */
+    dev_t mRawDevice;
+    /* Path to raw, encrypted block device */
+    std::string mRawDevPath;
+    /* Path to decrypted block device */
+    std::string mDmDevPath;
+    /* Path where decrypted device is mounted */
+    std::string mPath;
+
+    /* Encryption key as raw bytes */
+    std::string mKeyRaw;
+
+    /* Filesystem type */
+    std::string mFsType;
+    /* Filesystem UUID */
+    std::string mFsUuid;
+    /* User-visible filesystem label */
+    std::string mFsLabel;
+
+    DISALLOW_COPY_AND_ASSIGN(PrivateVolume);
+};
+
+}  // namespace vold
+}  // namespace android
+
+#endif
diff --git a/Process.cpp b/Process.cpp
index cc06998..a6f0cc6 100644
--- a/Process.cpp
+++ b/Process.cpp
@@ -66,7 +66,7 @@
 void Process::getProcessName(int pid, char *buffer, size_t max) {
     int fd;
     snprintf(buffer, max, "/proc/%d/cmdline", pid);
-    fd = open(buffer, O_RDONLY);
+    fd = open(buffer, O_RDONLY | O_CLOEXEC);
     if (fd < 0) {
         strcpy(buffer, "???");
     } else {
@@ -170,18 +170,14 @@
     return result;
 }
 
-extern "C" void vold_killProcessesWithOpenFiles(const char *path, int action) {
-	Process::killProcessesWithOpenFiles(path, action);
+extern "C" void vold_killProcessesWithOpenFiles(const char *path, int signal) {
+	Process::killProcessesWithOpenFiles(path, signal);
 }
 
 /*
  * Hunt down processes that have files open at the given mount point.
- * action = 0 to just warn,
- * action = 1 to SIGHUP,
- * action = 2 to SIGKILL
  */
-// hunt down and kill processes that have files open on the given mount point
-void Process::killProcessesWithOpenFiles(const char *path, int action) {
+void Process::killProcessesWithOpenFiles(const char *path, int signal) {
     DIR*    dir;
     struct dirent* de;
 
@@ -213,12 +209,10 @@
         } else {
             continue;
         }
-        if (action == 1) {
-            SLOGW("Sending SIGHUP to process %d", pid);
-            kill(pid, SIGTERM);
-        } else if (action == 2) {
-            SLOGE("Sending SIGKILL to process %d", pid);
-            kill(pid, SIGKILL);
+
+        if (signal != 0) {
+            SLOGW("Sending %s to process %d", strsignal(signal), pid);
+            kill(pid, signal);
         }
     }
     closedir(dir);
diff --git a/Process.h b/Process.h
index e745ca4..81b5f18 100644
--- a/Process.h
+++ b/Process.h
@@ -21,7 +21,7 @@
 
 class Process {
 public:
-    static void killProcessesWithOpenFiles(const char *path, int action);
+    static void killProcessesWithOpenFiles(const char *path, int signal);
     static int getPid(const char *s);
     static int checkSymLink(int pid, const char *path, const char *name);
     static int checkFileMaps(int pid, const char *path);
@@ -36,7 +36,7 @@
 
 extern "C" {
 #endif /* __cplusplus */
-	void vold_killProcessesWithOpenFiles(const char *path, int action);
+	void vold_killProcessesWithOpenFiles(const char *path, int signal);
 #ifdef __cplusplus
 }
 #endif
diff --git a/PublicVolume.cpp b/PublicVolume.cpp
new file mode 100644
index 0000000..eb550c3
--- /dev/null
+++ b/PublicVolume.cpp
@@ -0,0 +1,237 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "fs/Vfat.h"
+#include "PublicVolume.h"
+#include "Utils.h"
+#include "VolumeManager.h"
+#include "ResponseCode.h"
+
+#include <base/stringprintf.h>
+#include <base/logging.h>
+#include <cutils/fs.h>
+#include <private/android_filesystem_config.h>
+
+#include <fcntl.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+using android::base::StringPrintf;
+
+namespace android {
+namespace vold {
+
+static const char* kFusePath = "/system/bin/sdcard";
+
+static const char* kAsecPath = "/mnt/secure/asec";
+
+PublicVolume::PublicVolume(dev_t device) :
+        VolumeBase(Type::kPublic), mDevice(device), mFusePid(0) {
+    setId(StringPrintf("public:%u,%u", major(device), minor(device)));
+    mDevPath = StringPrintf("/dev/block/vold/%s", getId().c_str());
+}
+
+PublicVolume::~PublicVolume() {
+}
+
+status_t PublicVolume::readMetadata() {
+    status_t res = ReadMetadataUntrusted(mDevPath, mFsType, mFsUuid, mFsLabel);
+    notifyEvent(ResponseCode::VolumeFsTypeChanged, mFsType);
+    notifyEvent(ResponseCode::VolumeFsUuidChanged, mFsUuid);
+    notifyEvent(ResponseCode::VolumeFsLabelChanged, mFsLabel);
+    return res;
+}
+
+status_t PublicVolume::initAsecStage() {
+    std::string legacyPath(mRawPath + "/android_secure");
+    std::string securePath(mRawPath + "/.android_secure");
+
+    // Recover legacy secure path
+    if (!access(legacyPath.c_str(), R_OK | X_OK)
+            && access(securePath.c_str(), R_OK | X_OK)) {
+        if (rename(legacyPath.c_str(), securePath.c_str())) {
+            PLOG(WARNING) << getId() << " failed to rename legacy ASEC dir";
+        }
+    }
+
+    if (TEMP_FAILURE_RETRY(mkdir(securePath.c_str(), 0700))) {
+        if (errno != EEXIST) {
+            PLOG(WARNING) << getId() << " creating ASEC stage failed";
+            return -errno;
+        }
+    }
+
+    BindMount(securePath, kAsecPath);
+
+    return OK;
+}
+
+status_t PublicVolume::doCreate() {
+    return CreateDeviceNode(mDevPath, mDevice);
+}
+
+status_t PublicVolume::doDestroy() {
+    return DestroyDeviceNode(mDevPath);
+}
+
+status_t PublicVolume::doMount() {
+    // TODO: expand to support mounting other filesystems
+    readMetadata();
+
+    if (mFsType != "vfat") {
+        LOG(ERROR) << getId() << " unsupported filesystem " << mFsType;
+        return -EIO;
+    }
+
+    if (vfat::Check(mDevPath)) {
+        LOG(ERROR) << getId() << " failed filesystem check";
+        return -EIO;
+    }
+
+    // Use UUID as stable name, if available
+    std::string stableName = getId();
+    if (!mFsUuid.empty()) {
+        stableName = mFsUuid;
+    }
+
+    mRawPath = StringPrintf("/mnt/media_rw/%s", stableName.c_str());
+
+    mFuseDefault = StringPrintf("/mnt/runtime/default/%s", stableName.c_str());
+    mFuseRead = StringPrintf("/mnt/runtime/read/%s", stableName.c_str());
+    mFuseWrite = StringPrintf("/mnt/runtime/write/%s", stableName.c_str());
+
+    setInternalPath(mRawPath);
+    if (getMountFlags() & MountFlags::kVisible) {
+        setPath(StringPrintf("/storage/%s", stableName.c_str()));
+    } else {
+        setPath(mRawPath);
+    }
+
+    if (fs_prepare_dir(mRawPath.c_str(), 0700, AID_ROOT, AID_ROOT) ||
+            fs_prepare_dir(mFuseDefault.c_str(), 0700, AID_ROOT, AID_ROOT) ||
+            fs_prepare_dir(mFuseRead.c_str(), 0700, AID_ROOT, AID_ROOT) ||
+            fs_prepare_dir(mFuseWrite.c_str(), 0700, AID_ROOT, AID_ROOT)) {
+        PLOG(ERROR) << getId() << " failed to create mount points";
+        return -errno;
+    }
+
+    if (vfat::Mount(mDevPath, mRawPath, false, false, false,
+            AID_MEDIA_RW, AID_MEDIA_RW, 0007, true)) {
+        PLOG(ERROR) << getId() << " failed to mount " << mDevPath;
+        return -EIO;
+    }
+
+    if (getMountFlags() & MountFlags::kPrimary) {
+        initAsecStage();
+    }
+
+    if (!(getMountFlags() & MountFlags::kVisible)) {
+        // Not visible to apps, so no need to spin up FUSE
+        return OK;
+    }
+
+    dev_t before = GetDevice(mFuseWrite);
+
+    if (!(mFusePid = fork())) {
+        if (getMountFlags() & MountFlags::kPrimary) {
+            if (execl(kFusePath, kFusePath,
+                    "-u", "1023", // AID_MEDIA_RW
+                    "-g", "1023", // AID_MEDIA_RW
+                    "-U", std::to_string(getMountUserId()).c_str(),
+                    "-w",
+                    mRawPath.c_str(),
+                    stableName.c_str(),
+                    NULL)) {
+                PLOG(ERROR) << "Failed to exec";
+            }
+        } else {
+            if (execl(kFusePath, kFusePath,
+                    "-u", "1023", // AID_MEDIA_RW
+                    "-g", "1023", // AID_MEDIA_RW
+                    "-U", std::to_string(getMountUserId()).c_str(),
+                    mRawPath.c_str(),
+                    stableName.c_str(),
+                    NULL)) {
+                PLOG(ERROR) << "Failed to exec";
+            }
+        }
+
+        LOG(ERROR) << "FUSE exiting";
+        _exit(1);
+    }
+
+    if (mFusePid == -1) {
+        PLOG(ERROR) << getId() << " failed to fork";
+        return -errno;
+    }
+
+    while (before == GetDevice(mFuseWrite)) {
+        LOG(VERBOSE) << "Waiting for FUSE to spin up...";
+        usleep(50000); // 50ms
+    }
+
+    return OK;
+}
+
+status_t PublicVolume::doUnmount() {
+    if (mFusePid > 0) {
+        kill(mFusePid, SIGTERM);
+        TEMP_FAILURE_RETRY(waitpid(mFusePid, nullptr, 0));
+        mFusePid = 0;
+    }
+
+    ForceUnmount(kAsecPath);
+
+    ForceUnmount(mFuseDefault);
+    ForceUnmount(mFuseRead);
+    ForceUnmount(mFuseWrite);
+    ForceUnmount(mRawPath);
+
+    rmdir(mFuseDefault.c_str());
+    rmdir(mFuseRead.c_str());
+    rmdir(mFuseWrite.c_str());
+    rmdir(mRawPath.c_str());
+
+    mFuseDefault.clear();
+    mFuseRead.clear();
+    mFuseWrite.clear();
+    mRawPath.clear();
+
+    return OK;
+}
+
+status_t PublicVolume::doFormat(const std::string& fsType) {
+    if (fsType == "vfat" || fsType == "auto") {
+        if (WipeBlockDevice(mDevPath) != OK) {
+            LOG(WARNING) << getId() << " failed to wipe";
+        }
+        if (vfat::Format(mDevPath, 0)) {
+            LOG(ERROR) << getId() << " failed to format";
+            return -errno;
+        }
+    } else {
+        LOG(ERROR) << "Unsupported filesystem " << fsType;
+        return -EINVAL;
+    }
+
+    return OK;
+}
+
+}  // namespace vold
+}  // namespace android
diff --git a/PublicVolume.h b/PublicVolume.h
new file mode 100644
index 0000000..3aa7a73
--- /dev/null
+++ b/PublicVolume.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_VOLD_PUBLIC_VOLUME_H
+#define ANDROID_VOLD_PUBLIC_VOLUME_H
+
+#include "VolumeBase.h"
+
+#include <cutils/multiuser.h>
+
+namespace android {
+namespace vold {
+
+/*
+ * Shared storage provided by public (vfat) partition.
+ *
+ * Knows how to mount itself and then spawn a FUSE daemon to synthesize
+ * permissions.  AsecVolume and ObbVolume can be stacked above it.
+ *
+ * This volume is not inherently multi-user aware, so it has two possible
+ * modes of operation:
+ * 1. If primary storage for the device, it only binds itself to the
+ * owner user.
+ * 2. If secondary storage, it binds itself for all users, but masks
+ * away the Android directory for secondary users.
+ */
+class PublicVolume : public VolumeBase {
+public:
+    explicit PublicVolume(dev_t device);
+    virtual ~PublicVolume();
+
+protected:
+    status_t doCreate() override;
+    status_t doDestroy() override;
+    status_t doMount() override;
+    status_t doUnmount() override;
+    status_t doFormat(const std::string& fsType) override;
+
+    status_t readMetadata();
+    status_t initAsecStage();
+
+private:
+    /* Kernel device representing partition */
+    dev_t mDevice;
+    /* Block device path */
+    std::string mDevPath;
+    /* Mount point of raw partition */
+    std::string mRawPath;
+
+    std::string mFuseDefault;
+    std::string mFuseRead;
+    std::string mFuseWrite;
+
+    /* PID of FUSE wrapper */
+    pid_t mFusePid;
+
+    /* Filesystem type */
+    std::string mFsType;
+    /* Filesystem UUID */
+    std::string mFsUuid;
+    /* User-visible filesystem label */
+    std::string mFsLabel;
+
+    DISALLOW_COPY_AND_ASSIGN(PublicVolume);
+};
+
+}  // namespace vold
+}  // namespace android
+
+#endif
diff --git a/ResponseCode.h b/ResponseCode.h
index 0dc0500..f2c533e 100644
--- a/ResponseCode.h
+++ b/ResponseCode.h
@@ -66,6 +66,26 @@
     static const int VolumeDiskRemoved             = 631;
     static const int VolumeBadRemoval              = 632;
 
+    static const int DiskCreated = 640;
+    static const int DiskSizeChanged = 641;
+    static const int DiskLabelChanged = 642;
+    static const int DiskScanned = 643;
+    static const int DiskSysPathChanged = 644;
+    static const int DiskDestroyed = 649;
+
+    static const int VolumeCreated = 650;
+    static const int VolumeStateChanged = 651;
+    static const int VolumeFsTypeChanged = 652;
+    static const int VolumeFsUuidChanged = 653;
+    static const int VolumeFsLabelChanged = 654;
+    static const int VolumePathChanged = 655;
+    static const int VolumeInternalPathChanged = 656;
+    static const int VolumeDestroyed = 659;
+
+    static const int MoveStatus = 660;
+    static const int BenchmarkResult = 661;
+    static const int TrimResult = 662;
+
     static int convertFromErrno();
 };
 #endif
diff --git a/TrimTask.cpp b/TrimTask.cpp
new file mode 100644
index 0000000..1c6eb1f
--- /dev/null
+++ b/TrimTask.cpp
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "TrimTask.h"
+#include "Benchmark.h"
+#include "Utils.h"
+#include "VolumeManager.h"
+#include "ResponseCode.h"
+
+#include <base/stringprintf.h>
+#include <base/logging.h>
+#include <cutils/properties.h>
+#include <fs_mgr.h>
+#include <private/android_filesystem_config.h>
+#include <hardware_legacy/power.h>
+
+#include <dirent.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+
+/* From a would-be kernel header */
+#define FIDTRIM         _IOWR('f', 128, struct fstrim_range)    /* Deep discard trim */
+
+#define BENCHMARK_ENABLED 0
+
+using android::base::StringPrintf;
+
+namespace android {
+namespace vold {
+
+static const char* kWakeLock = "TrimTask";
+
+TrimTask::TrimTask(int flags) : mFlags(flags) {
+    // Collect both fstab and vold volumes
+    addFromFstab();
+
+    VolumeManager* vm = VolumeManager::Instance();
+    std::list<std::string> privateIds;
+    vm->listVolumes(VolumeBase::Type::kPrivate, privateIds);
+    for (auto id : privateIds) {
+        auto vol = vm->findVolume(id);
+        if (vol != nullptr && vol->getState() == VolumeBase::State::kMounted) {
+            mPaths.push_back(vol->getPath());
+        }
+    }
+}
+
+TrimTask::~TrimTask() {
+}
+
+void TrimTask::addFromFstab() {
+    struct fstab *fstab;
+    struct fstab_rec *prev_rec = NULL;
+
+    fstab = fs_mgr_read_fstab(android::vold::DefaultFstabPath().c_str());
+    for (int i = 0; i < fstab->num_entries; i++) {
+        /* Skip raw partitions */
+        if (!strcmp(fstab->recs[i].fs_type, "emmc") ||
+            !strcmp(fstab->recs[i].fs_type, "mtd")) {
+            continue;
+        }
+        /* Skip read-only filesystems */
+        if (fstab->recs[i].flags & MS_RDONLY) {
+            continue;
+        }
+        if (fs_mgr_is_voldmanaged(&fstab->recs[i])) {
+            continue; /* Should we trim fat32 filesystems? */
+        }
+        if (fs_mgr_is_notrim(&fstab->recs[i])) {
+            continue;
+        }
+
+        /* Skip the multi-type partitions, which are required to be following each other.
+         * See fs_mgr.c's mount_with_alternatives().
+         */
+        if (prev_rec && !strcmp(prev_rec->mount_point, fstab->recs[i].mount_point)) {
+            continue;
+        }
+
+        mPaths.push_back(fstab->recs[i].mount_point);
+        prev_rec = &fstab->recs[i];
+    }
+    fs_mgr_free_fstab(fstab);
+}
+
+void TrimTask::start() {
+    mThread = std::thread(&TrimTask::run, this);
+}
+
+static void notifyResult(const std::string& path, int64_t bytes, int64_t delta) {
+    std::string res(path
+            + " " + std::to_string(bytes)
+            + " " + std::to_string(delta));
+    VolumeManager::Instance()->getBroadcaster()->sendBroadcast(
+            ResponseCode::TrimResult, res.c_str(), false);
+}
+
+void TrimTask::run() {
+    acquire_wake_lock(PARTIAL_WAKE_LOCK, kWakeLock);
+
+    for (auto path : mPaths) {
+        LOG(DEBUG) << "Starting trim of " << path;
+
+        int fd = open(path.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
+        if (fd < 0) {
+            PLOG(WARNING) << "Failed to open " << path;
+            continue;
+        }
+
+        struct fstrim_range range;
+        memset(&range, 0, sizeof(range));
+        range.len = ULLONG_MAX;
+
+        nsecs_t start = systemTime(SYSTEM_TIME_BOOTTIME);
+        if (ioctl(fd, (mFlags & Flags::kDeepTrim) ? FIDTRIM : FITRIM, &range)) {
+            PLOG(WARNING) << "Trim failed on " << path;
+            notifyResult(path, -1, -1);
+        } else {
+            nsecs_t delta = systemTime(SYSTEM_TIME_BOOTTIME) - start;
+            LOG(INFO) << "Trimmed " << range.len << " bytes on " << path
+                    << " in " << nanoseconds_to_milliseconds(delta) << "ms";
+            notifyResult(path, range.len, delta);
+        }
+        close(fd);
+
+        if (mFlags & Flags::kBenchmarkAfter) {
+#if BENCHMARK_ENABLED
+            BenchmarkPrivate(path);
+#else
+            LOG(DEBUG) << "Benchmark disabled";
+#endif
+        }
+    }
+
+    release_wake_lock(kWakeLock);
+}
+
+}  // namespace vold
+}  // namespace android
diff --git a/TrimTask.h b/TrimTask.h
new file mode 100644
index 0000000..57be802
--- /dev/null
+++ b/TrimTask.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_VOLD_TRIM_TASK_H
+#define ANDROID_VOLD_TRIM_TASK_H
+
+#include "Utils.h"
+
+#include <thread>
+#include <list>
+
+namespace android {
+namespace vold {
+
+class TrimTask {
+public:
+    TrimTask(int flags);
+    virtual ~TrimTask();
+
+    enum Flags {
+        kDeepTrim = 1 << 0,
+        kBenchmarkAfter = 1 << 1,
+    };
+
+    void start();
+
+private:
+    int mFlags;
+    std::list<std::string> mPaths;
+    std::thread mThread;
+
+    void addFromFstab();
+    void run();
+
+    DISALLOW_COPY_AND_ASSIGN(TrimTask);
+};
+
+}  // namespace vold
+}  // namespace android
+
+#endif
diff --git a/Utils.cpp b/Utils.cpp
new file mode 100644
index 0000000..e19c9df
--- /dev/null
+++ b/Utils.cpp
@@ -0,0 +1,549 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "sehandle.h"
+#include "Utils.h"
+#include "Process.h"
+
+#include <base/file.h>
+#include <base/logging.h>
+#include <base/stringprintf.h>
+#include <cutils/fs.h>
+#include <cutils/properties.h>
+#include <private/android_filesystem_config.h>
+#include <logwrap/logwrap.h>
+
+#include <mutex>
+#include <dirent.h>
+#include <fcntl.h>
+#include <linux/fs.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <sys/statvfs.h>
+
+#ifndef UMOUNT_NOFOLLOW
+#define UMOUNT_NOFOLLOW    0x00000008  /* Don't follow symlink on umount */
+#endif
+
+using android::base::ReadFileToString;
+using android::base::StringPrintf;
+
+namespace android {
+namespace vold {
+
+security_context_t sBlkidContext = nullptr;
+security_context_t sBlkidUntrustedContext = nullptr;
+security_context_t sFsckContext = nullptr;
+security_context_t sFsckUntrustedContext = nullptr;
+
+static const char* kBlkidPath = "/system/bin/blkid";
+static const char* kKeyPath = "/data/misc/vold";
+
+static const char* kProcFilesystems = "/proc/filesystems";
+
+status_t CreateDeviceNode(const std::string& path, dev_t dev) {
+    const char* cpath = path.c_str();
+    status_t res = 0;
+
+    char* secontext = nullptr;
+    if (sehandle) {
+        if (!selabel_lookup(sehandle, &secontext, cpath, S_IFBLK)) {
+            setfscreatecon(secontext);
+        }
+    }
+
+    mode_t mode = 0660 | S_IFBLK;
+    if (mknod(cpath, mode, dev) < 0) {
+        if (errno != EEXIST) {
+            PLOG(ERROR) << "Failed to create device node for " << major(dev)
+                    << ":" << minor(dev) << " at " << path;
+            res = -errno;
+        }
+    }
+
+    if (secontext) {
+        setfscreatecon(nullptr);
+        freecon(secontext);
+    }
+
+    return res;
+}
+
+status_t DestroyDeviceNode(const std::string& path) {
+    const char* cpath = path.c_str();
+    if (TEMP_FAILURE_RETRY(unlink(cpath))) {
+        return -errno;
+    } else {
+        return OK;
+    }
+}
+
+status_t PrepareDir(const std::string& path, mode_t mode, uid_t uid, gid_t gid) {
+    const char* cpath = path.c_str();
+
+    char* secontext = nullptr;
+    if (sehandle) {
+        if (!selabel_lookup(sehandle, &secontext, cpath, S_IFDIR)) {
+            setfscreatecon(secontext);
+        }
+    }
+
+    int res = fs_prepare_dir(cpath, mode, uid, gid);
+
+    if (secontext) {
+        setfscreatecon(nullptr);
+        freecon(secontext);
+    }
+
+    if (res == 0) {
+        return OK;
+    } else {
+        return -errno;
+    }
+}
+
+status_t ForceUnmount(const std::string& path) {
+    const char* cpath = path.c_str();
+    if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
+        return OK;
+    }
+    PLOG(WARNING) << "Failed to unmount " << path;
+
+    sleep(5);
+    Process::killProcessesWithOpenFiles(cpath, SIGINT);
+
+    if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
+        return OK;
+    }
+    PLOG(WARNING) << "Failed to unmount " << path;
+
+    sleep(5);
+    Process::killProcessesWithOpenFiles(cpath, SIGTERM);
+
+    if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
+        return OK;
+    }
+    PLOG(WARNING) << "Failed to unmount " << path;
+
+    sleep(5);
+    Process::killProcessesWithOpenFiles(cpath, SIGKILL);
+
+    if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
+        return OK;
+    }
+    PLOG(ERROR) << "Failed to unmount " << path;
+
+    return -errno;
+}
+
+status_t BindMount(const std::string& source, const std::string& target) {
+    if (::mount(source.c_str(), target.c_str(), "", MS_BIND, NULL)) {
+        PLOG(ERROR) << "Failed to bind mount " << source << " to " << target;
+        return -errno;
+    }
+    return OK;
+}
+
+static status_t readMetadata(const std::string& path, std::string& fsType,
+        std::string& fsUuid, std::string& fsLabel, bool untrusted) {
+    fsType.clear();
+    fsUuid.clear();
+    fsLabel.clear();
+
+    std::vector<std::string> cmd;
+    cmd.push_back(kBlkidPath);
+    cmd.push_back("-c");
+    cmd.push_back("/dev/null");
+    cmd.push_back("-s");
+    cmd.push_back("TYPE");
+    cmd.push_back("-s");
+    cmd.push_back("UUID");
+    cmd.push_back("-s");
+    cmd.push_back("LABEL");
+    cmd.push_back(path);
+
+    std::vector<std::string> output;
+    status_t res = ForkExecvp(cmd, output, untrusted ? sBlkidUntrustedContext : sBlkidContext);
+    if (res != OK) {
+        LOG(WARNING) << "blkid failed to identify " << path;
+        return res;
+    }
+
+    char value[128];
+    for (auto line : output) {
+        // Extract values from blkid output, if defined
+        const char* cline = line.c_str();
+        char* start = strstr(cline, "TYPE=");
+        if (start != nullptr && sscanf(start + 5, "\"%127[^\"]\"", value) == 1) {
+            fsType = value;
+        }
+
+        start = strstr(cline, "UUID=");
+        if (start != nullptr && sscanf(start + 5, "\"%127[^\"]\"", value) == 1) {
+            fsUuid = value;
+        }
+
+        start = strstr(cline, "LABEL=");
+        if (start != nullptr && sscanf(start + 6, "\"%127[^\"]\"", value) == 1) {
+            fsLabel = value;
+        }
+    }
+
+    return OK;
+}
+
+status_t ReadMetadata(const std::string& path, std::string& fsType,
+        std::string& fsUuid, std::string& fsLabel) {
+    return readMetadata(path, fsType, fsUuid, fsLabel, false);
+}
+
+status_t ReadMetadataUntrusted(const std::string& path, std::string& fsType,
+        std::string& fsUuid, std::string& fsLabel) {
+    return readMetadata(path, fsType, fsUuid, fsLabel, true);
+}
+
+status_t ForkExecvp(const std::vector<std::string>& args) {
+    return ForkExecvp(args, nullptr);
+}
+
+status_t ForkExecvp(const std::vector<std::string>& args, security_context_t context) {
+    size_t argc = args.size();
+    char** argv = (char**) calloc(argc, sizeof(char*));
+    for (size_t i = 0; i < argc; i++) {
+        argv[i] = (char*) args[i].c_str();
+        if (i == 0) {
+            LOG(VERBOSE) << args[i];
+        } else {
+            LOG(VERBOSE) << "    " << args[i];
+        }
+    }
+
+    if (setexeccon(context)) {
+        LOG(ERROR) << "Failed to setexeccon";
+        abort();
+    }
+    status_t res = android_fork_execvp(argc, argv, NULL, false, true);
+    if (setexeccon(nullptr)) {
+        LOG(ERROR) << "Failed to setexeccon";
+        abort();
+    }
+
+    free(argv);
+    return res;
+}
+
+status_t ForkExecvp(const std::vector<std::string>& args,
+        std::vector<std::string>& output) {
+    return ForkExecvp(args, output, nullptr);
+}
+
+status_t ForkExecvp(const std::vector<std::string>& args,
+        std::vector<std::string>& output, security_context_t context) {
+    std::string cmd;
+    for (size_t i = 0; i < args.size(); i++) {
+        cmd += args[i] + " ";
+        if (i == 0) {
+            LOG(VERBOSE) << args[i];
+        } else {
+            LOG(VERBOSE) << "    " << args[i];
+        }
+    }
+    output.clear();
+
+    if (setexeccon(context)) {
+        LOG(ERROR) << "Failed to setexeccon";
+        abort();
+    }
+    FILE* fp = popen(cmd.c_str(), "r");
+    if (setexeccon(nullptr)) {
+        LOG(ERROR) << "Failed to setexeccon";
+        abort();
+    }
+
+    if (!fp) {
+        PLOG(ERROR) << "Failed to popen " << cmd;
+        return -errno;
+    }
+    char line[1024];
+    while (fgets(line, sizeof(line), fp) != nullptr) {
+        LOG(VERBOSE) << line;
+        output.push_back(std::string(line));
+    }
+    if (pclose(fp) != 0) {
+        PLOG(ERROR) << "Failed to pclose " << cmd;
+        return -errno;
+    }
+
+    return OK;
+}
+
+pid_t ForkExecvpAsync(const std::vector<std::string>& args) {
+    size_t argc = args.size();
+    char** argv = (char**) calloc(argc + 1, sizeof(char*));
+    for (size_t i = 0; i < argc; i++) {
+        argv[i] = (char*) args[i].c_str();
+        if (i == 0) {
+            LOG(VERBOSE) << args[i];
+        } else {
+            LOG(VERBOSE) << "    " << args[i];
+        }
+    }
+
+    pid_t pid = fork();
+    if (pid == 0) {
+        close(STDIN_FILENO);
+        close(STDOUT_FILENO);
+        close(STDERR_FILENO);
+
+        if (execvp(argv[0], argv)) {
+            PLOG(ERROR) << "Failed to exec";
+        }
+
+        _exit(1);
+    }
+
+    if (pid == -1) {
+        PLOG(ERROR) << "Failed to exec";
+    }
+
+    free(argv);
+    return pid;
+}
+
+status_t ReadRandomBytes(size_t bytes, std::string& out) {
+    out.clear();
+
+    int fd = TEMP_FAILURE_RETRY(open("/dev/urandom", O_RDONLY | O_CLOEXEC | O_NOFOLLOW));
+    if (fd == -1) {
+        return -errno;
+    }
+
+    char buf[BUFSIZ];
+    size_t n;
+    while ((n = TEMP_FAILURE_RETRY(read(fd, &buf[0], std::min(sizeof(buf), bytes)))) > 0) {
+        out.append(buf, n);
+        bytes -= n;
+    }
+    close(fd);
+
+    if (bytes == 0) {
+        return OK;
+    } else {
+        return -EIO;
+    }
+}
+
+status_t HexToStr(const std::string& hex, std::string& str) {
+    str.clear();
+    bool even = true;
+    char cur = 0;
+    for (size_t i = 0; i < hex.size(); i++) {
+        int val = 0;
+        switch (hex[i]) {
+        case ' ': case '-': case ':': continue;
+        case 'f': case 'F': val = 15; break;
+        case 'e': case 'E': val = 14; break;
+        case 'd': case 'D': val = 13; break;
+        case 'c': case 'C': val = 12; break;
+        case 'b': case 'B': val = 11; break;
+        case 'a': case 'A': val = 10; break;
+        case '9': val = 9; break;
+        case '8': val = 8; break;
+        case '7': val = 7; break;
+        case '6': val = 6; break;
+        case '5': val = 5; break;
+        case '4': val = 4; break;
+        case '3': val = 3; break;
+        case '2': val = 2; break;
+        case '1': val = 1; break;
+        case '0': val = 0; break;
+        default: return -EINVAL;
+        }
+
+        if (even) {
+            cur = val << 4;
+        } else {
+            cur += val;
+            str.push_back(cur);
+            cur = 0;
+        }
+        even = !even;
+    }
+    return even ? OK : -EINVAL;
+}
+
+static const char* kLookup = "0123456789abcdef";
+
+status_t StrToHex(const std::string& str, std::string& hex) {
+    hex.clear();
+    for (size_t i = 0; i < str.size(); i++) {
+        hex.push_back(kLookup[(str[i] & 0xF0) >> 4]);
+        hex.push_back(kLookup[str[i] & 0x0F]);
+    }
+    return OK;
+}
+
+status_t NormalizeHex(const std::string& in, std::string& out) {
+    std::string tmp;
+    if (HexToStr(in, tmp)) {
+        return -EINVAL;
+    }
+    return StrToHex(tmp, out);
+}
+
+uint64_t GetFreeBytes(const std::string& path) {
+    struct statvfs sb;
+    if (statvfs(path.c_str(), &sb) == 0) {
+        return sb.f_bfree * sb.f_bsize;
+    } else {
+        return -1;
+    }
+}
+
+// TODO: borrowed from frameworks/native/libs/diskusage/ which should
+// eventually be migrated into system/
+static int64_t stat_size(struct stat *s) {
+    int64_t blksize = s->st_blksize;
+    // count actual blocks used instead of nominal file size
+    int64_t size = s->st_blocks * 512;
+
+    if (blksize) {
+        /* round up to filesystem block size */
+        size = (size + blksize - 1) & (~(blksize - 1));
+    }
+
+    return size;
+}
+
+// TODO: borrowed from frameworks/native/libs/diskusage/ which should
+// eventually be migrated into system/
+int64_t calculate_dir_size(int dfd) {
+    int64_t size = 0;
+    struct stat s;
+    DIR *d;
+    struct dirent *de;
+
+    d = fdopendir(dfd);
+    if (d == NULL) {
+        close(dfd);
+        return 0;
+    }
+
+    while ((de = readdir(d))) {
+        const char *name = de->d_name;
+        if (fstatat(dfd, name, &s, AT_SYMLINK_NOFOLLOW) == 0) {
+            size += stat_size(&s);
+        }
+        if (de->d_type == DT_DIR) {
+            int subfd;
+
+            /* always skip "." and ".." */
+            if (name[0] == '.') {
+                if (name[1] == 0)
+                    continue;
+                if ((name[1] == '.') && (name[2] == 0))
+                    continue;
+            }
+
+            subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY);
+            if (subfd >= 0) {
+                size += calculate_dir_size(subfd);
+            }
+        }
+    }
+    closedir(d);
+    return size;
+}
+
+uint64_t GetTreeBytes(const std::string& path) {
+    int dirfd = open(path.c_str(), O_DIRECTORY, O_RDONLY);
+    if (dirfd < 0) {
+        PLOG(WARNING) << "Failed to open " << path;
+        return -1;
+    } else {
+        uint64_t res = calculate_dir_size(dirfd);
+        close(dirfd);
+        return res;
+    }
+}
+
+bool IsFilesystemSupported(const std::string& fsType) {
+    std::string supported;
+    if (!ReadFileToString(kProcFilesystems, &supported)) {
+        PLOG(ERROR) << "Failed to read supported filesystems";
+        return false;
+    }
+    return supported.find(fsType + "\n") != std::string::npos;
+}
+
+status_t WipeBlockDevice(const std::string& path) {
+    status_t res = -1;
+    const char* c_path = path.c_str();
+    unsigned long nr_sec = 0;
+    unsigned long long range[2];
+
+    int fd = TEMP_FAILURE_RETRY(open(c_path, O_RDWR | O_CLOEXEC));
+    if (fd == -1) {
+        PLOG(ERROR) << "Failed to open " << path;
+        goto done;
+    }
+
+    if ((ioctl(fd, BLKGETSIZE, nr_sec)) == -1) {
+        PLOG(ERROR) << "Failed to determine size of " << path;
+        goto done;
+    }
+
+    range[0] = 0;
+    range[1] = (unsigned long long) nr_sec * 512;
+
+    LOG(INFO) << "About to discard " << range[1] << " on " << path;
+    if (ioctl(fd, BLKDISCARD, &range) == 0) {
+        LOG(INFO) << "Discard success on " << path;
+        res = 0;
+    } else {
+        PLOG(ERROR) << "Discard failure on " << path;
+    }
+
+done:
+    close(fd);
+    return res;
+}
+
+std::string BuildKeyPath(const std::string& partGuid) {
+    return StringPrintf("%s/expand_%s.key", kKeyPath, partGuid.c_str());
+}
+
+dev_t GetDevice(const std::string& path) {
+    struct stat sb;
+    if (stat(path.c_str(), &sb)) {
+        PLOG(WARNING) << "Failed to stat " << path;
+        return 0;
+    } else {
+        return sb.st_dev;
+    }
+}
+
+std::string DefaultFstabPath() {
+    char hardware[PROPERTY_VALUE_MAX];
+    property_get("ro.hardware", hardware, "");
+    return StringPrintf("/fstab.%s", hardware);
+}
+
+}  // namespace vold
+}  // namespace android
diff --git a/Utils.h b/Utils.h
new file mode 100644
index 0000000..f33a379
--- /dev/null
+++ b/Utils.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_VOLD_UTILS_H
+#define ANDROID_VOLD_UTILS_H
+
+#include <utils/Errors.h>
+#include <selinux/selinux.h>
+
+#include <vector>
+#include <string>
+
+// DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions. It goes in the private:
+// declarations in a class.
+#if !defined(DISALLOW_COPY_AND_ASSIGN)
+#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
+    TypeName(const TypeName&) = delete;  \
+    void operator=(const TypeName&) = delete
+#endif
+
+namespace android {
+namespace vold {
+
+/* SELinux contexts used depending on the block device type */
+extern security_context_t sBlkidContext;
+extern security_context_t sBlkidUntrustedContext;
+extern security_context_t sFsckContext;
+extern security_context_t sFsckUntrustedContext;
+
+status_t CreateDeviceNode(const std::string& path, dev_t dev);
+status_t DestroyDeviceNode(const std::string& path);
+
+/* fs_prepare_dir wrapper that creates with SELinux context */
+status_t PrepareDir(const std::string& path, mode_t mode, uid_t uid, gid_t gid);
+
+/* Really unmounts the path, killing active processes along the way */
+status_t ForceUnmount(const std::string& path);
+
+/* Creates bind mount from source to target */
+status_t BindMount(const std::string& source, const std::string& target);
+
+/* Reads filesystem metadata from device at path */
+status_t ReadMetadata(const std::string& path, std::string& fsType,
+        std::string& fsUuid, std::string& fsLabel);
+
+/* Reads filesystem metadata from untrusted device at path */
+status_t ReadMetadataUntrusted(const std::string& path, std::string& fsType,
+        std::string& fsUuid, std::string& fsLabel);
+
+/* Returns either WEXITSTATUS() status, or a negative errno */
+status_t ForkExecvp(const std::vector<std::string>& args);
+status_t ForkExecvp(const std::vector<std::string>& args, security_context_t context);
+
+status_t ForkExecvp(const std::vector<std::string>& args,
+        std::vector<std::string>& output);
+status_t ForkExecvp(const std::vector<std::string>& args,
+        std::vector<std::string>& output, security_context_t context);
+
+pid_t ForkExecvpAsync(const std::vector<std::string>& args);
+
+status_t ReadRandomBytes(size_t bytes, std::string& out);
+
+/* Converts hex string to raw bytes, ignoring [ :-] */
+status_t HexToStr(const std::string& hex, std::string& str);
+/* Converts raw bytes to hex string */
+status_t StrToHex(const std::string& str, std::string& hex);
+/* Normalize given hex string into consistent format */
+status_t NormalizeHex(const std::string& in, std::string& out);
+
+uint64_t GetFreeBytes(const std::string& path);
+uint64_t GetTreeBytes(const std::string& path);
+
+bool IsFilesystemSupported(const std::string& fsType);
+
+/* Wipes contents of block device at given path */
+status_t WipeBlockDevice(const std::string& path);
+
+std::string BuildKeyPath(const std::string& partGuid);
+
+dev_t GetDevice(const std::string& path);
+
+std::string DefaultFstabPath();
+
+}  // namespace vold
+}  // namespace android
+
+#endif
diff --git a/Volume.cpp b/Volume.cpp
deleted file mode 100644
index ce4ed1e..0000000
--- a/Volume.cpp
+++ /dev/null
@@ -1,707 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <dirent.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <mntent.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/mount.h>
-#include <sys/param.h>
-
-#include <linux/kdev_t.h>
-
-#include <cutils/properties.h>
-
-#include <diskconfig/diskconfig.h>
-
-#include <private/android_filesystem_config.h>
-
-#define LOG_TAG "Vold"
-
-#include <cutils/fs.h>
-#include <cutils/log.h>
-
-#include <string>
-
-#include "Volume.h"
-#include "VolumeManager.h"
-#include "ResponseCode.h"
-#include "Fat.h"
-#include "Process.h"
-#include "cryptfs.h"
-#include "sehandle.h"
-
-extern "C" void dos_partition_dec(void const *pp, struct dos_partition *d);
-extern "C" void dos_partition_enc(void *pp, struct dos_partition *d);
-
-
-/*
- * Media directory - stuff that only media_rw user can see
- */
-const char *Volume::MEDIA_DIR           = "/mnt/media_rw";
-
-/*
- * Fuse directory - location where fuse wrapped filesystems go
- */
-const char *Volume::FUSE_DIR           = "/storage";
-
-/*
- * Path to external storage where *only* root can access ASEC image files
- */
-const char *Volume::SEC_ASECDIR_EXT   = "/mnt/secure/asec";
-
-/*
- * Path to internal storage where *only* root can access ASEC image files
- */
-const char *Volume::SEC_ASECDIR_INT   = "/data/app-asec";
-
-/*
- * Path to where secure containers are mounted
- */
-const char *Volume::ASECDIR           = "/mnt/asec";
-
-/*
- * Path to where OBBs are mounted
- */
-const char *Volume::LOOPDIR           = "/mnt/obb";
-
-const char *Volume::BLKID_PATH = "/system/bin/blkid";
-
-static const char *stateToStr(int state) {
-    if (state == Volume::State_Init)
-        return "Initializing";
-    else if (state == Volume::State_NoMedia)
-        return "No-Media";
-    else if (state == Volume::State_Idle)
-        return "Idle-Unmounted";
-    else if (state == Volume::State_Pending)
-        return "Pending";
-    else if (state == Volume::State_Mounted)
-        return "Mounted";
-    else if (state == Volume::State_Unmounting)
-        return "Unmounting";
-    else if (state == Volume::State_Checking)
-        return "Checking";
-    else if (state == Volume::State_Formatting)
-        return "Formatting";
-    else if (state == Volume::State_Shared)
-        return "Shared-Unmounted";
-    else if (state == Volume::State_SharedMnt)
-        return "Shared-Mounted";
-    else
-        return "Unknown-Error";
-}
-
-Volume::Volume(VolumeManager *vm, const fstab_rec* rec, int flags) {
-    mVm = vm;
-    mDebug = false;
-    mLabel = strdup(rec->label);
-    mUuid = NULL;
-    mUserLabel = NULL;
-    mState = Volume::State_Init;
-    mFlags = flags;
-    mCurrentlyMountedKdev = -1;
-    mPartIdx = rec->partnum;
-    mRetryMount = false;
-}
-
-Volume::~Volume() {
-    free(mLabel);
-    free(mUuid);
-    free(mUserLabel);
-}
-
-void Volume::setDebug(bool enable) {
-    mDebug = enable;
-}
-
-dev_t Volume::getDiskDevice() {
-    return MKDEV(0, 0);
-};
-
-dev_t Volume::getShareDevice() {
-    return getDiskDevice();
-}
-
-void Volume::handleVolumeShared() {
-}
-
-void Volume::handleVolumeUnshared() {
-}
-
-int Volume::handleBlockEvent(NetlinkEvent * /*evt*/) {
-    errno = ENOSYS;
-    return -1;
-}
-
-void Volume::setUuid(const char* uuid) {
-    char msg[256];
-
-    if (mUuid) {
-        free(mUuid);
-    }
-
-    if (uuid) {
-        mUuid = strdup(uuid);
-        snprintf(msg, sizeof(msg), "%s %s \"%s\"", getLabel(),
-                getFuseMountpoint(), mUuid);
-    } else {
-        mUuid = NULL;
-        snprintf(msg, sizeof(msg), "%s %s", getLabel(), getFuseMountpoint());
-    }
-
-    mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeUuidChange, msg,
-            false);
-}
-
-void Volume::setUserLabel(const char* userLabel) {
-    char msg[256];
-
-    if (mUserLabel) {
-        free(mUserLabel);
-    }
-
-    if (userLabel) {
-        mUserLabel = strdup(userLabel);
-        snprintf(msg, sizeof(msg), "%s %s \"%s\"", getLabel(),
-                getFuseMountpoint(), mUserLabel);
-    } else {
-        mUserLabel = NULL;
-        snprintf(msg, sizeof(msg), "%s %s", getLabel(), getFuseMountpoint());
-    }
-
-    mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeUserLabelChange,
-            msg, false);
-}
-
-void Volume::setState(int state) {
-    char msg[255];
-    int oldState = mState;
-
-    if (oldState == state) {
-        SLOGW("Duplicate state (%d)\n", state);
-        return;
-    }
-
-    if ((oldState == Volume::State_Pending) && (state != Volume::State_Idle)) {
-        mRetryMount = false;
-    }
-
-    mState = state;
-
-    SLOGD("Volume %s state changing %d (%s) -> %d (%s)", mLabel,
-         oldState, stateToStr(oldState), mState, stateToStr(mState));
-    snprintf(msg, sizeof(msg),
-             "Volume %s %s state changed from %d (%s) to %d (%s)", getLabel(),
-             getFuseMountpoint(), oldState, stateToStr(oldState), mState,
-             stateToStr(mState));
-
-    mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeStateChange,
-                                         msg, false);
-}
-
-int Volume::createDeviceNode(const char *path, int major, int minor) {
-    char *secontext = NULL;
-    mode_t mode = 0660 | S_IFBLK;
-    dev_t dev = (major << 8) | minor;
-    int rc;
-    if (sehandle) {
-        rc = selabel_lookup(sehandle, &secontext, path, S_IFBLK);
-        if (rc == 0)
-            setfscreatecon(secontext);
-    }
-    if (mknod(path, mode, dev) < 0) {
-        if (errno != EEXIST) {
-            int sverrno = errno;
-            if (secontext) {
-                freecon(secontext);
-                setfscreatecon(NULL);
-            }
-            errno = sverrno;
-            return -1;
-        }
-    }
-    if (secontext) {
-        setfscreatecon(NULL);
-        freecon(secontext);
-    }
-    return 0;
-}
-
-int Volume::formatVol(bool wipe) {
-
-    if (getState() == Volume::State_NoMedia) {
-        errno = ENODEV;
-        return -1;
-    } else if (getState() != Volume::State_Idle) {
-        errno = EBUSY;
-        return -1;
-    }
-
-    if (isMountpointMounted(getMountpoint())) {
-        SLOGW("Volume is idle but appears to be mounted - fixing");
-        setState(Volume::State_Mounted);
-        // mCurrentlyMountedKdev = XXX
-        errno = EBUSY;
-        return -1;
-    }
-
-    bool formatEntireDevice = (mPartIdx == -1);
-    char devicePath[255];
-    dev_t diskNode = getDiskDevice();
-    dev_t partNode =
-        MKDEV(MAJOR(diskNode),
-              MINOR(diskNode) + (formatEntireDevice ? 0 : mPartIdx));
-
-    setState(Volume::State_Formatting);
-
-    int ret = -1;
-    // Only initialize the MBR if we are formatting the entire device
-    if (formatEntireDevice) {
-        sprintf(devicePath, "/dev/block/vold/%d:%d",
-                major(diskNode), minor(diskNode));
-
-        if (initializeMbr(devicePath)) {
-            SLOGE("Failed to initialize MBR (%s)", strerror(errno));
-            goto err;
-        }
-    }
-
-    sprintf(devicePath, "/dev/block/vold/%d:%d",
-            major(partNode), minor(partNode));
-
-    if (mDebug) {
-        SLOGI("Formatting volume %s (%s)", getLabel(), devicePath);
-    }
-
-    if (Fat::format(devicePath, 0, wipe)) {
-        SLOGE("Failed to format (%s)", strerror(errno));
-        goto err;
-    }
-
-    ret = 0;
-
-err:
-    setState(Volume::State_Idle);
-    return ret;
-}
-
-bool Volume::isMountpointMounted(const char *path) {
-    FILE *fp = setmntent("/proc/mounts", "r");
-    if (fp == NULL) {
-        SLOGE("Error opening /proc/mounts (%s)", strerror(errno));
-        return false;
-    }
-
-    bool found_path = false;
-    mntent* mentry;
-    while ((mentry = getmntent(fp)) != NULL) {
-        if (strcmp(mentry->mnt_dir, path) == 0) {
-            found_path = true;
-            break;
-        }
-    }
-    endmntent(fp);
-    return found_path;
-}
-
-int Volume::mountVol() {
-    dev_t deviceNodes[4];
-    int n, i;
-    char errmsg[255];
-
-    int flags = getFlags();
-    bool providesAsec = (flags & VOL_PROVIDES_ASEC) != 0;
-
-    // TODO: handle "bind" style mounts, for emulated storage
-
-    char decrypt_state[PROPERTY_VALUE_MAX];
-    char crypto_state[PROPERTY_VALUE_MAX];
-    char encrypt_progress[PROPERTY_VALUE_MAX];
-
-    property_get("vold.decrypt", decrypt_state, "");
-    property_get("vold.encrypt_progress", encrypt_progress, "");
-
-    /* Don't try to mount the volumes if we have not yet entered the disk password
-     * or are in the process of encrypting.
-     */
-    if ((getState() == Volume::State_NoMedia) ||
-        ((!strcmp(decrypt_state, "1") || encrypt_progress[0]) && providesAsec)) {
-        snprintf(errmsg, sizeof(errmsg),
-                 "Volume %s %s mount failed - no media",
-                 getLabel(), getFuseMountpoint());
-        mVm->getBroadcaster()->sendBroadcast(
-                                         ResponseCode::VolumeMountFailedNoMedia,
-                                         errmsg, false);
-        errno = ENODEV;
-        return -1;
-    } else if (getState() != Volume::State_Idle) {
-        errno = EBUSY;
-        if (getState() == Volume::State_Pending) {
-            mRetryMount = true;
-        }
-        return -1;
-    }
-
-    if (isMountpointMounted(getMountpoint())) {
-        SLOGW("Volume is idle but appears to be mounted - fixing");
-        setState(Volume::State_Mounted);
-        // mCurrentlyMountedKdev = XXX
-        return 0;
-    }
-
-    n = getDeviceNodes((dev_t *) &deviceNodes, 4);
-    if (!n) {
-        SLOGE("Failed to get device nodes (%s)\n", strerror(errno));
-        return -1;
-    }
-
-    /* If we're running encrypted, and the volume is marked as encryptable and nonremovable,
-     * and also marked as providing Asec storage, then we need to decrypt
-     * that partition, and update the volume object to point to it's new decrypted
-     * block device
-     */
-    property_get("ro.crypto.state", crypto_state, "");
-    if (providesAsec &&
-        ((flags & (VOL_NONREMOVABLE | VOL_ENCRYPTABLE))==(VOL_NONREMOVABLE | VOL_ENCRYPTABLE)) &&
-        !strcmp(crypto_state, "encrypted") && !isDecrypted()) {
-       char new_sys_path[MAXPATHLEN];
-       char nodepath[256];
-       int new_major, new_minor;
-
-       if (n != 1) {
-           /* We only expect one device node returned when mounting encryptable volumes */
-           SLOGE("Too many device nodes returned when mounting %s\n", getMountpoint());
-           return -1;
-       }
-
-       if (cryptfs_setup_volume(getLabel(), MAJOR(deviceNodes[0]), MINOR(deviceNodes[0]),
-                                new_sys_path, sizeof(new_sys_path),
-                                &new_major, &new_minor)) {
-           SLOGE("Cannot setup encryption mapping for %s\n", getMountpoint());
-           return -1;
-       }
-       /* We now have the new sysfs path for the decrypted block device, and the
-        * majore and minor numbers for it.  So, create the device, update the
-        * path to the new sysfs path, and continue.
-        */
-        snprintf(nodepath,
-                 sizeof(nodepath), "/dev/block/vold/%d:%d",
-                 new_major, new_minor);
-        if (createDeviceNode(nodepath, new_major, new_minor)) {
-            SLOGE("Error making device node '%s' (%s)", nodepath,
-                                                       strerror(errno));
-        }
-
-        // Todo: Either create sys filename from nodepath, or pass in bogus path so
-        //       vold ignores state changes on this internal device.
-        updateDeviceInfo(nodepath, new_major, new_minor);
-
-        /* Get the device nodes again, because they just changed */
-        n = getDeviceNodes((dev_t *) &deviceNodes, 4);
-        if (!n) {
-            SLOGE("Failed to get device nodes (%s)\n", strerror(errno));
-            return -1;
-        }
-    }
-
-    for (i = 0; i < n; i++) {
-        char devicePath[255];
-
-        sprintf(devicePath, "/dev/block/vold/%d:%d", major(deviceNodes[i]),
-                minor(deviceNodes[i]));
-
-        SLOGI("%s being considered for volume %s\n", devicePath, getLabel());
-
-        errno = 0;
-        setState(Volume::State_Checking);
-
-        if (Fat::check(devicePath)) {
-            if (errno == ENODATA) {
-                SLOGW("%s does not contain a FAT filesystem\n", devicePath);
-                continue;
-            }
-            errno = EIO;
-            /* Badness - abort the mount */
-            SLOGE("%s failed FS checks (%s)", devicePath, strerror(errno));
-            setState(Volume::State_Idle);
-            return -1;
-        }
-
-        errno = 0;
-
-        if (Fat::doMount(devicePath, getMountpoint(), false, false, false,
-                AID_MEDIA_RW, AID_MEDIA_RW, 0007, true)) {
-            SLOGE("%s failed to mount via VFAT (%s)\n", devicePath, strerror(errno));
-            continue;
-        }
-
-        extractMetadata(devicePath);
-
-        if (providesAsec && mountAsecExternal() != 0) {
-            SLOGE("Failed to mount secure area (%s)", strerror(errno));
-            umount(getMountpoint());
-            setState(Volume::State_Idle);
-            return -1;
-        }
-
-        char service[64];
-        snprintf(service, 64, "fuse_%s", getLabel());
-        property_set("ctl.start", service);
-
-        setState(Volume::State_Mounted);
-        mCurrentlyMountedKdev = deviceNodes[i];
-        return 0;
-    }
-
-    SLOGE("Volume %s found no suitable devices for mounting :(\n", getLabel());
-    setState(Volume::State_Idle);
-
-    return -1;
-}
-
-int Volume::mountAsecExternal() {
-    char legacy_path[PATH_MAX];
-    char secure_path[PATH_MAX];
-
-    snprintf(legacy_path, PATH_MAX, "%s/android_secure", getMountpoint());
-    snprintf(secure_path, PATH_MAX, "%s/.android_secure", getMountpoint());
-
-    // Recover legacy secure path
-    if (!access(legacy_path, R_OK | X_OK) && access(secure_path, R_OK | X_OK)) {
-        if (rename(legacy_path, secure_path)) {
-            SLOGE("Failed to rename legacy asec dir (%s)", strerror(errno));
-        }
-    }
-
-    if (fs_prepare_dir(secure_path, 0770, AID_MEDIA_RW, AID_MEDIA_RW) != 0) {
-        SLOGW("fs_prepare_dir failed: %s", strerror(errno));
-        return -1;
-    }
-
-    if (mount(secure_path, SEC_ASECDIR_EXT, "", MS_BIND, NULL)) {
-        SLOGE("Failed to bind mount points %s -> %s (%s)", secure_path,
-                SEC_ASECDIR_EXT, strerror(errno));
-        return -1;
-    }
-
-    return 0;
-}
-
-int Volume::doUnmount(const char *path, bool force) {
-    int retries = 10;
-
-    if (mDebug) {
-        SLOGD("Unmounting {%s}, force = %d", path, force);
-    }
-
-    while (retries--) {
-        if (!umount(path) || errno == EINVAL || errno == ENOENT) {
-            SLOGI("%s sucessfully unmounted", path);
-            return 0;
-        }
-
-        int action = 0;
-
-        if (force) {
-            if (retries == 1) {
-                action = 2; // SIGKILL
-            } else if (retries == 2) {
-                action = 1; // SIGHUP
-            }
-        }
-
-        SLOGW("Failed to unmount %s (%s, retries %d, action %d)",
-                path, strerror(errno), retries, action);
-
-        Process::killProcessesWithOpenFiles(path, action);
-        usleep(1000*1000);
-    }
-    errno = EBUSY;
-    SLOGE("Giving up on unmount %s (%s)", path, strerror(errno));
-    return -1;
-}
-
-int Volume::unmountVol(bool force, bool revert) {
-    int flags = getFlags();
-    bool providesAsec = (flags & VOL_PROVIDES_ASEC) != 0;
-
-    if (getState() != Volume::State_Mounted) {
-        SLOGE("Volume %s unmount request when not mounted", getLabel());
-        errno = EINVAL;
-        return UNMOUNT_NOT_MOUNTED_ERR;
-    }
-
-    setState(Volume::State_Unmounting);
-    usleep(1000 * 1000); // Give the framework some time to react
-
-    char service[64];
-    snprintf(service, 64, "fuse_%s", getLabel());
-    property_set("ctl.stop", service);
-    /* Give it a chance to stop.  I wish we had a synchronous way to determine this... */
-    sleep(1);
-
-    // TODO: determine failure mode if FUSE times out
-
-    if (providesAsec && doUnmount(Volume::SEC_ASECDIR_EXT, force) != 0) {
-        SLOGE("Failed to unmount secure area on %s (%s)", getMountpoint(), strerror(errno));
-        goto out_mounted;
-    }
-
-    /* Now that the fuse daemon is dead, unmount it */
-    if (doUnmount(getFuseMountpoint(), force) != 0) {
-        SLOGE("Failed to unmount %s (%s)", getFuseMountpoint(), strerror(errno));
-        goto fail_remount_secure;
-    }
-
-    /* Unmount the real sd card */
-    if (doUnmount(getMountpoint(), force) != 0) {
-        SLOGE("Failed to unmount %s (%s)", getMountpoint(), strerror(errno));
-        goto fail_remount_secure;
-    }
-
-    SLOGI("%s unmounted successfully", getMountpoint());
-
-    /* If this is an encrypted volume, and we've been asked to undo
-     * the crypto mapping, then revert the dm-crypt mapping, and revert
-     * the device info to the original values.
-     */
-    if (revert && isDecrypted()) {
-        cryptfs_revert_volume(getLabel());
-        revertDeviceInfo();
-        SLOGI("Encrypted volume %s reverted successfully", getMountpoint());
-    }
-
-    setUuid(NULL);
-    setUserLabel(NULL);
-    setState(Volume::State_Idle);
-    mCurrentlyMountedKdev = -1;
-    return 0;
-
-fail_remount_secure:
-    if (providesAsec && mountAsecExternal() != 0) {
-        SLOGE("Failed to remount secure area (%s)", strerror(errno));
-        goto out_nomedia;
-    }
-
-out_mounted:
-    setState(Volume::State_Mounted);
-    return -1;
-
-out_nomedia:
-    setState(Volume::State_NoMedia);
-    return -1;
-}
-
-int Volume::initializeMbr(const char *deviceNode) {
-    struct disk_info dinfo;
-
-    memset(&dinfo, 0, sizeof(dinfo));
-
-    if (!(dinfo.part_lst = (struct part_info *) malloc(MAX_NUM_PARTS * sizeof(struct part_info)))) {
-        SLOGE("Failed to malloc prt_lst");
-        return -1;
-    }
-
-    memset(dinfo.part_lst, 0, MAX_NUM_PARTS * sizeof(struct part_info));
-    dinfo.device = strdup(deviceNode);
-    dinfo.scheme = PART_SCHEME_MBR;
-    dinfo.sect_size = 512;
-    dinfo.skip_lba = 2048;
-    dinfo.num_lba = 0;
-    dinfo.num_parts = 1;
-
-    struct part_info *pinfo = &dinfo.part_lst[0];
-
-    pinfo->name = strdup("android_sdcard");
-    pinfo->flags |= PART_ACTIVE_FLAG;
-    pinfo->type = PC_PART_TYPE_FAT32;
-    pinfo->len_kb = -1;
-
-    int rc = apply_disk_config(&dinfo, 0);
-
-    if (rc) {
-        SLOGE("Failed to apply disk configuration (%d)", rc);
-        goto out;
-    }
-
- out:
-    free(pinfo->name);
-    free(dinfo.device);
-    free(dinfo.part_lst);
-
-    return rc;
-}
-
-/*
- * Use blkid to extract UUID and label from device, since it handles many
- * obscure edge cases around partition types and formats. Always broadcasts
- * updated metadata values.
- */
-int Volume::extractMetadata(const char* devicePath) {
-    int res = 0;
-
-    std::string cmd;
-    cmd = BLKID_PATH;
-    cmd += " -c /dev/null ";
-    cmd += devicePath;
-
-    FILE* fp = popen(cmd.c_str(), "r");
-    if (!fp) {
-        ALOGE("Failed to run %s: %s", cmd.c_str(), strerror(errno));
-        res = -1;
-        goto done;
-    }
-
-    char line[1024];
-    char value[128];
-    if (fgets(line, sizeof(line), fp) != NULL) {
-        ALOGD("blkid identified as %s", line);
-
-        char* start = strstr(line, "UUID=");
-        if (start != NULL && sscanf(start + 5, "\"%127[^\"]\"", value) == 1) {
-            setUuid(value);
-        } else {
-            setUuid(NULL);
-        }
-
-        start = strstr(line, "LABEL=");
-        if (start != NULL && sscanf(start + 6, "\"%127[^\"]\"", value) == 1) {
-            setUserLabel(value);
-        } else {
-            setUserLabel(NULL);
-        }
-    } else {
-        ALOGW("blkid failed to identify %s", devicePath);
-        res = -1;
-    }
-
-    pclose(fp);
-
-done:
-    if (res == -1) {
-        setUuid(NULL);
-        setUserLabel(NULL);
-    }
-    return res;
-}
diff --git a/Volume.h b/Volume.h
deleted file mode 100644
index 1444ed3..0000000
--- a/Volume.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _VOLUME_H
-#define _VOLUME_H
-
-#include <utils/List.h>
-#include <fs_mgr.h>
-
-class NetlinkEvent;
-class VolumeManager;
-
-class Volume {
-private:
-    int mState;
-    int mFlags;
-
-public:
-    static const int State_Init       = -1;
-    static const int State_NoMedia    = 0;
-    static const int State_Idle       = 1;
-    static const int State_Pending    = 2;
-    static const int State_Checking   = 3;
-    static const int State_Mounted    = 4;
-    static const int State_Unmounting = 5;
-    static const int State_Formatting = 6;
-    static const int State_Shared     = 7;
-    static const int State_SharedMnt  = 8;
-
-    static const char *MEDIA_DIR;
-    static const char *FUSE_DIR;
-    static const char *SEC_ASECDIR_EXT;
-    static const char *SEC_ASECDIR_INT;
-    static const char *ASECDIR;
-    static const char *LOOPDIR;
-    static const char *BLKID_PATH;
-
-protected:
-    char* mLabel;
-    char* mUuid;
-    char* mUserLabel;
-    VolumeManager *mVm;
-    bool mDebug;
-    int mPartIdx;
-    int mOrigPartIdx;
-    bool mRetryMount;
-
-    /*
-     * The major/minor tuple of the currently mounted filesystem.
-     */
-    dev_t mCurrentlyMountedKdev;
-
-public:
-    Volume(VolumeManager *vm, const fstab_rec* rec, int flags);
-    virtual ~Volume();
-
-    int mountVol();
-    int unmountVol(bool force, bool revert);
-    int formatVol(bool wipe);
-
-    const char* getLabel() { return mLabel; }
-    const char* getUuid() { return mUuid; }
-    const char* getUserLabel() { return mUserLabel; }
-    int getState() { return mState; }
-    int getFlags() { return mFlags; };
-
-    /* Mountpoint of the raw volume */
-    virtual const char *getMountpoint() = 0;
-    virtual const char *getFuseMountpoint() = 0;
-
-    virtual int handleBlockEvent(NetlinkEvent *evt);
-    virtual dev_t getDiskDevice();
-    virtual dev_t getShareDevice();
-    virtual void handleVolumeShared();
-    virtual void handleVolumeUnshared();
-
-    void setDebug(bool enable);
-    virtual int getVolInfo(struct volume_info *v) = 0;
-
-protected:
-    void setUuid(const char* uuid);
-    void setUserLabel(const char* userLabel);
-    void setState(int state);
-
-    virtual int getDeviceNodes(dev_t *devs, int max) = 0;
-    virtual int updateDeviceInfo(char *new_path, int new_major, int new_minor) = 0;
-    virtual void revertDeviceInfo(void) = 0;
-    virtual int isDecrypted(void) = 0;
-
-    int createDeviceNode(const char *path, int major, int minor);
-
-private:
-    int initializeMbr(const char *deviceNode);
-    bool isMountpointMounted(const char *path);
-    int mountAsecExternal();
-    int doUnmount(const char *path, bool force);
-    int extractMetadata(const char* devicePath);
-};
-
-typedef android::List<Volume *> VolumeCollection;
-
-#endif
diff --git a/VolumeBase.cpp b/VolumeBase.cpp
new file mode 100644
index 0000000..4dcdb0e
--- /dev/null
+++ b/VolumeBase.cpp
@@ -0,0 +1,256 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Utils.h"
+#include "VolumeBase.h"
+#include "VolumeManager.h"
+#include "ResponseCode.h"
+
+#include <base/stringprintf.h>
+#include <base/logging.h>
+
+#include <fcntl.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+using android::base::StringPrintf;
+
+#define DEBUG 1
+
+namespace android {
+namespace vold {
+
+VolumeBase::VolumeBase(Type type) :
+        mType(type), mMountFlags(0), mMountUserId(-1), mCreated(false), mState(
+                State::kUnmounted), mSilent(false) {
+}
+
+VolumeBase::~VolumeBase() {
+    CHECK(!mCreated);
+}
+
+void VolumeBase::setState(State state) {
+    mState = state;
+    notifyEvent(ResponseCode::VolumeStateChanged, StringPrintf("%d", mState));
+}
+
+status_t VolumeBase::setDiskId(const std::string& diskId) {
+    if (mCreated) {
+        LOG(WARNING) << getId() << " diskId change requires destroyed";
+        return -EBUSY;
+    }
+
+    mDiskId = diskId;
+    return OK;
+}
+
+status_t VolumeBase::setPartGuid(const std::string& partGuid) {
+    if (mCreated) {
+        LOG(WARNING) << getId() << " partGuid change requires destroyed";
+        return -EBUSY;
+    }
+
+    mPartGuid = partGuid;
+    return OK;
+}
+
+status_t VolumeBase::setMountFlags(int mountFlags) {
+    if ((mState != State::kUnmounted) && (mState != State::kUnmountable)) {
+        LOG(WARNING) << getId() << " flags change requires state unmounted or unmountable";
+        return -EBUSY;
+    }
+
+    mMountFlags = mountFlags;
+    return OK;
+}
+
+status_t VolumeBase::setMountUserId(userid_t mountUserId) {
+    if ((mState != State::kUnmounted) && (mState != State::kUnmountable)) {
+        LOG(WARNING) << getId() << " user change requires state unmounted or unmountable";
+        return -EBUSY;
+    }
+
+    mMountUserId = mountUserId;
+    return OK;
+}
+
+status_t VolumeBase::setSilent(bool silent) {
+    if (mCreated) {
+        LOG(WARNING) << getId() << " silence change requires destroyed";
+        return -EBUSY;
+    }
+
+    mSilent = silent;
+    return OK;
+}
+
+status_t VolumeBase::setId(const std::string& id) {
+    if (mCreated) {
+        LOG(WARNING) << getId() << " id change requires not created";
+        return -EBUSY;
+    }
+
+    mId = id;
+    return OK;
+}
+
+status_t VolumeBase::setPath(const std::string& path) {
+    if (mState != State::kChecking) {
+        LOG(WARNING) << getId() << " path change requires state checking";
+        return -EBUSY;
+    }
+
+    mPath = path;
+    notifyEvent(ResponseCode::VolumePathChanged, mPath);
+    return OK;
+}
+
+status_t VolumeBase::setInternalPath(const std::string& internalPath) {
+    if (mState != State::kChecking) {
+        LOG(WARNING) << getId() << " internal path change requires state checking";
+        return -EBUSY;
+    }
+
+    mInternalPath = internalPath;
+    notifyEvent(ResponseCode::VolumeInternalPathChanged, mInternalPath);
+    return OK;
+}
+
+void VolumeBase::notifyEvent(int event) {
+    if (mSilent) return;
+    VolumeManager::Instance()->getBroadcaster()->sendBroadcast(event,
+            getId().c_str(), false);
+}
+
+void VolumeBase::notifyEvent(int event, const std::string& value) {
+    if (mSilent) return;
+    VolumeManager::Instance()->getBroadcaster()->sendBroadcast(event,
+            StringPrintf("%s %s", getId().c_str(), value.c_str()).c_str(), false);
+}
+
+void VolumeBase::addVolume(const std::shared_ptr<VolumeBase>& volume) {
+    mVolumes.push_back(volume);
+}
+
+void VolumeBase::removeVolume(const std::shared_ptr<VolumeBase>& volume) {
+    mVolumes.remove(volume);
+}
+
+std::shared_ptr<VolumeBase> VolumeBase::findVolume(const std::string& id) {
+    for (auto vol : mVolumes) {
+        if (vol->getId() == id) {
+            return vol;
+        }
+    }
+    return nullptr;
+}
+
+status_t VolumeBase::create() {
+    CHECK(!mCreated);
+
+    mCreated = true;
+    status_t res = doCreate();
+    notifyEvent(ResponseCode::VolumeCreated,
+            StringPrintf("%d \"%s\" \"%s\"", mType, mDiskId.c_str(), mPartGuid.c_str()));
+    setState(State::kUnmounted);
+    return res;
+}
+
+status_t VolumeBase::doCreate() {
+    return OK;
+}
+
+status_t VolumeBase::destroy() {
+    CHECK(mCreated);
+
+    if (mState == State::kMounted) {
+        unmount();
+        setState(State::kBadRemoval);
+    } else {
+        setState(State::kRemoved);
+    }
+
+    notifyEvent(ResponseCode::VolumeDestroyed);
+    status_t res = doDestroy();
+    mCreated = false;
+    return res;
+}
+
+status_t VolumeBase::doDestroy() {
+    return OK;
+}
+
+status_t VolumeBase::mount() {
+    if ((mState != State::kUnmounted) && (mState != State::kUnmountable)) {
+        LOG(WARNING) << getId() << " mount requires state unmounted or unmountable";
+        return -EBUSY;
+    }
+
+    setState(State::kChecking);
+    status_t res = doMount();
+    if (res == OK) {
+        setState(State::kMounted);
+    } else {
+        setState(State::kUnmountable);
+    }
+
+    return res;
+}
+
+status_t VolumeBase::unmount() {
+    if (mState != State::kMounted) {
+        LOG(WARNING) << getId() << " unmount requires state mounted";
+        return -EBUSY;
+    }
+
+    setState(State::kEjecting);
+    for (auto vol : mVolumes) {
+        if (vol->destroy()) {
+            LOG(WARNING) << getId() << " failed to destroy " << vol->getId()
+                    << " stacked above";
+        }
+    }
+    mVolumes.clear();
+
+    status_t res = doUnmount();
+    setState(State::kUnmounted);
+    return res;
+}
+
+status_t VolumeBase::format(const std::string& fsType) {
+    if (mState == State::kMounted) {
+        unmount();
+    }
+
+    if ((mState != State::kUnmounted) && (mState != State::kUnmountable)) {
+        LOG(WARNING) << getId() << " format requires state unmounted or unmountable";
+        return -EBUSY;
+    }
+
+    setState(State::kFormatting);
+    status_t res = doFormat(fsType);
+    setState(State::kUnmounted);
+    return res;
+}
+
+status_t VolumeBase::doFormat(const std::string& fsType) {
+    return -ENOTSUP;
+}
+
+}  // namespace vold
+}  // namespace android
diff --git a/VolumeBase.h b/VolumeBase.h
new file mode 100644
index 0000000..d417019
--- /dev/null
+++ b/VolumeBase.h
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_VOLD_VOLUME_BASE_H
+#define ANDROID_VOLD_VOLUME_BASE_H
+
+#include "Utils.h"
+
+#include <cutils/multiuser.h>
+#include <utils/Errors.h>
+
+#include <sys/types.h>
+#include <list>
+#include <string>
+
+namespace android {
+namespace vold {
+
+/*
+ * Representation of a mounted volume ready for presentation.
+ *
+ * Various subclasses handle the different mounting prerequisites, such as
+ * encryption details, etc.  Volumes can also be "stacked" above other
+ * volumes to help communicate dependencies.  For example, an ASEC volume
+ * can be stacked on a vfat volume.
+ *
+ * Mounted volumes can be asked to manage bind mounts to present themselves
+ * to specific users on the device.
+ *
+ * When an unmount is requested, the volume recursively unmounts any stacked
+ * volumes and removes any bind mounts before finally unmounting itself.
+ */
+class VolumeBase {
+public:
+    virtual ~VolumeBase();
+
+    enum class Type {
+        kPublic = 0,
+        kPrivate,
+        kEmulated,
+        kAsec,
+        kObb,
+    };
+
+    enum MountFlags {
+        /* Flag that volume is primary external storage */
+        kPrimary = 1 << 0,
+        /* Flag that volume is visible to normal apps */
+        kVisible = 1 << 1,
+    };
+
+    enum class State {
+        kUnmounted = 0,
+        kChecking,
+        kMounted,
+        kMountedReadOnly,
+        kFormatting,
+        kEjecting,
+        kUnmountable,
+        kRemoved,
+        kBadRemoval,
+    };
+
+    const std::string& getId() { return mId; }
+    const std::string& getDiskId() { return mDiskId; }
+    const std::string& getPartGuid() { return mPartGuid; }
+    Type getType() { return mType; }
+    int getMountFlags() { return mMountFlags; }
+    userid_t getMountUserId() { return mMountUserId; }
+    State getState() { return mState; }
+    const std::string& getPath() { return mPath; }
+    const std::string& getInternalPath() { return mInternalPath; }
+
+    status_t setDiskId(const std::string& diskId);
+    status_t setPartGuid(const std::string& partGuid);
+    status_t setMountFlags(int mountFlags);
+    status_t setMountUserId(userid_t mountUserId);
+    status_t setSilent(bool silent);
+
+    void addVolume(const std::shared_ptr<VolumeBase>& volume);
+    void removeVolume(const std::shared_ptr<VolumeBase>& volume);
+
+    std::shared_ptr<VolumeBase> findVolume(const std::string& id);
+
+    status_t create();
+    status_t destroy();
+    status_t mount();
+    status_t unmount();
+    status_t format(const std::string& fsType);
+
+protected:
+    explicit VolumeBase(Type type);
+
+    virtual status_t doCreate();
+    virtual status_t doDestroy();
+    virtual status_t doMount() = 0;
+    virtual status_t doUnmount() = 0;
+    virtual status_t doFormat(const std::string& fsType);
+
+    status_t setId(const std::string& id);
+    status_t setPath(const std::string& path);
+    status_t setInternalPath(const std::string& internalPath);
+
+    void notifyEvent(int msg);
+    void notifyEvent(int msg, const std::string& value);
+
+private:
+    /* ID that uniquely references volume while alive */
+    std::string mId;
+    /* ID that uniquely references parent disk while alive */
+    std::string mDiskId;
+    /* Partition GUID of this volume */
+    std::string mPartGuid;
+    /* Volume type */
+    Type mType;
+    /* Flags used when mounting this volume */
+    int mMountFlags;
+    /* User that owns this volume, otherwise -1 */
+    userid_t mMountUserId;
+    /* Flag indicating object is created */
+    bool mCreated;
+    /* Current state of volume */
+    State mState;
+    /* Path to mounted volume */
+    std::string mPath;
+    /* Path to internal backing storage */
+    std::string mInternalPath;
+    /* Flag indicating that volume should emit no events */
+    bool mSilent;
+
+    /* Volumes stacked on top of this volume */
+    std::list<std::shared_ptr<VolumeBase>> mVolumes;
+
+    void setState(State state);
+
+    DISALLOW_COPY_AND_ASSIGN(VolumeBase);
+};
+
+}  // namespace vold
+}  // namespace android
+
+#endif
diff --git a/VolumeManager.cpp b/VolumeManager.cpp
index da4deb6..ce355df 100755
--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -26,6 +26,7 @@
 #include <sys/mount.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <sys/wait.h>
 #include <unistd.h>
 
 #include <linux/kdev_t.h>
@@ -34,6 +35,8 @@
 
 #include <openssl/md5.h>
 
+#include <base/logging.h>
+#include <base/stringprintf.h>
 #include <cutils/fs.h>
 #include <cutils/log.h>
 
@@ -43,12 +46,15 @@
 
 #include <private/android_filesystem_config.h>
 
+#include "Benchmark.h"
+#include "EmulatedVolume.h"
 #include "VolumeManager.h"
-#include "DirectVolume.h"
+#include "NetlinkManager.h"
 #include "ResponseCode.h"
 #include "Loop.h"
-#include "Ext4.h"
-#include "Fat.h"
+#include "fs/Ext4.h"
+#include "fs/Vfat.h"
+#include "Utils.h"
 #include "Devmapper.h"
 #include "Process.h"
 #include "Asec.h"
@@ -60,9 +66,35 @@
 #define ROUND_UP_POWER_OF_2(number, po2) (((!!(number & ((1U << po2) - 1))) << po2)\
                                          + (number & (~((1U << po2) - 1))))
 
+using android::base::StringPrintf;
+
+/*
+ * Path to external storage where *only* root can access ASEC image files
+ */
+const char *VolumeManager::SEC_ASECDIR_EXT   = "/mnt/secure/asec";
+
+/*
+ * Path to internal storage where *only* root can access ASEC image files
+ */
+const char *VolumeManager::SEC_ASECDIR_INT   = "/data/app-asec";
+
+/*
+ * Path to where secure containers are mounted
+ */
+const char *VolumeManager::ASECDIR           = "/mnt/asec";
+
+/*
+ * Path to where OBBs are mounted
+ */
+const char *VolumeManager::LOOPDIR           = "/mnt/obb";
+
+static const char* kUserMountPath = "/mnt/user";
+
+static const unsigned int kMajorBlockMmc = 179;
+
 /* writes superblock at end of file or device given by name */
 static int writeSuperBlock(const char* name, struct asec_superblock *sb, unsigned int numImgSectors) {
-    int sbfd = open(name, O_RDWR);
+    int sbfd = open(name, O_RDWR | O_CLOEXEC);
     if (sbfd < 0) {
         SLOGE("Failed to open %s for superblock write (%s)", name, strerror(errno));
         return -1;
@@ -171,18 +203,15 @@
 
 VolumeManager::VolumeManager() {
     mDebug = false;
-    mVolumes = new VolumeCollection();
     mActiveContainers = new AsecIdCollection();
     mBroadcaster = NULL;
     mUmsSharingCount = 0;
     mSavedDirtyRatio = -1;
     // set dirty ratio to 0 when UMS is active
     mUmsDirtyRatio = 0;
-    mVolManagerDisabled = 0;
 }
 
 VolumeManager::~VolumeManager() {
-    delete mVolumes;
     delete mActiveContainers;
 }
 
@@ -218,96 +247,443 @@
     return buffer;
 }
 
-void VolumeManager::setDebug(bool enable) {
+int VolumeManager::setDebug(bool enable) {
     mDebug = enable;
-    VolumeCollection::iterator it;
-    for (it = mVolumes->begin(); it != mVolumes->end(); ++it) {
-        (*it)->setDebug(enable);
-    }
+    return 0;
 }
 
 int VolumeManager::start() {
+    // Always start from a clean slate by unmounting everything in
+    // directories that we own, in case we crashed.
+    unmountAll();
+
+    // Assume that we always have an emulated volume on internal
+    // storage; the framework will decide if it should be mounted.
+    CHECK(mInternalEmulated == nullptr);
+    mInternalEmulated = std::shared_ptr<android::vold::VolumeBase>(
+            new android::vold::EmulatedVolume("/data/media"));
+    mInternalEmulated->create();
+
     return 0;
 }
 
 int VolumeManager::stop() {
-    return 0;
-}
-
-int VolumeManager::addVolume(Volume *v) {
-    mVolumes->push_back(v);
+    CHECK(mInternalEmulated != nullptr);
+    mInternalEmulated->destroy();
+    mInternalEmulated = nullptr;
     return 0;
 }
 
 void VolumeManager::handleBlockEvent(NetlinkEvent *evt) {
-#ifdef NETLINK_DEBUG
-    const char *devpath = evt->findParam("DEVPATH");
-#endif
+    std::lock_guard<std::mutex> lock(mLock);
 
-    /* Lookup a volume to handle this device */
-    VolumeCollection::iterator it;
-    bool hit = false;
-    for (it = mVolumes->begin(); it != mVolumes->end(); ++it) {
-        if (!(*it)->handleBlockEvent(evt)) {
-#ifdef NETLINK_DEBUG
-            SLOGD("Device '%s' event handled by volume %s\n", devpath, (*it)->getLabel());
-#endif
-            hit = true;
-            break;
-        }
+    if (mDebug) {
+        LOG(VERBOSE) << "----------------";
+        LOG(VERBOSE) << "handleBlockEvent with action " << (int) evt->getAction();
+        evt->dump();
     }
 
-    if (!hit) {
-#ifdef NETLINK_DEBUG
-        SLOGW("No volumes handled block event for '%s'", devpath);
-#endif
+    std::string eventPath(evt->findParam("DEVPATH"));
+    std::string devType(evt->findParam("DEVTYPE"));
+
+    if (devType != "disk") return;
+
+    int major = atoi(evt->findParam("MAJOR"));
+    int minor = atoi(evt->findParam("MINOR"));
+    dev_t device = makedev(major, minor);
+
+    switch (evt->getAction()) {
+    case NetlinkEvent::Action::kAdd: {
+        for (auto source : mDiskSources) {
+            if (source->matches(eventPath)) {
+                // For now, assume that MMC devices are SD, and that
+                // everything else is USB
+                int flags = source->getFlags();
+                if (major == kMajorBlockMmc) {
+                    flags |= android::vold::Disk::Flags::kSd;
+                } else {
+                    flags |= android::vold::Disk::Flags::kUsb;
+                }
+
+                auto disk = new android::vold::Disk(eventPath, device,
+                        source->getNickname(), flags);
+                disk->create();
+                mDisks.push_back(std::shared_ptr<android::vold::Disk>(disk));
+                break;
+            }
+        }
+        break;
+    }
+    case NetlinkEvent::Action::kChange: {
+        LOG(DEBUG) << "Disk at " << major << ":" << minor << " changed";
+        for (auto disk : mDisks) {
+            if (disk->getDevice() == device) {
+                disk->readMetadata();
+                disk->readPartitions();
+            }
+        }
+        break;
+    }
+    case NetlinkEvent::Action::kRemove: {
+        auto i = mDisks.begin();
+        while (i != mDisks.end()) {
+            if ((*i)->getDevice() == device) {
+                (*i)->destroy();
+                i = mDisks.erase(i);
+            } else {
+                ++i;
+            }
+        }
+        break;
+    }
+    default: {
+        LOG(WARNING) << "Unexpected block event action " << (int) evt->getAction();
+        break;
+    }
     }
 }
 
-int VolumeManager::listVolumes(SocketClient *cli, bool broadcast) {
-    VolumeCollection::iterator i;
-    char msg[256];
+void VolumeManager::addDiskSource(const std::shared_ptr<DiskSource>& diskSource) {
+    mDiskSources.push_back(diskSource);
+}
 
-    for (i = mVolumes->begin(); i != mVolumes->end(); ++i) {
-        char *buffer;
-        asprintf(&buffer, "%s %s %d",
-                 (*i)->getLabel(), (*i)->getFuseMountpoint(),
-                 (*i)->getState());
-        cli->sendMsg(ResponseCode::VolumeListResult, buffer, false);
-        free(buffer);
-        if (broadcast) {
-            if((*i)->getUuid()) {
-                snprintf(msg, sizeof(msg), "%s %s \"%s\"", (*i)->getLabel(),
-                    (*i)->getFuseMountpoint(), (*i)->getUuid());
-                mBroadcaster->sendBroadcast(ResponseCode::VolumeUuidChange,
-                    msg, false);
-            }
-            if((*i)->getUserLabel()) {
-                snprintf(msg, sizeof(msg), "%s %s \"%s\"", (*i)->getLabel(),
-                    (*i)->getFuseMountpoint(), (*i)->getUserLabel());
-                mBroadcaster->sendBroadcast(ResponseCode::VolumeUserLabelChange,
-                    msg, false);
-            }
+std::shared_ptr<android::vold::Disk> VolumeManager::findDisk(const std::string& id) {
+    for (auto disk : mDisks) {
+        if (disk->getId() == id) {
+            return disk;
         }
     }
-    cli->sendMsg(ResponseCode::CommandOkay, "Volumes listed.", false);
+    return nullptr;
+}
+
+std::shared_ptr<android::vold::VolumeBase> VolumeManager::findVolume(const std::string& id) {
+    if (mInternalEmulated->getId() == id) {
+        return mInternalEmulated;
+    }
+    for (auto disk : mDisks) {
+        auto vol = disk->findVolume(id);
+        if (vol != nullptr) {
+            return vol;
+        }
+    }
+    return nullptr;
+}
+
+void VolumeManager::listVolumes(android::vold::VolumeBase::Type type,
+        std::list<std::string>& list) {
+    list.clear();
+    for (auto disk : mDisks) {
+        disk->listVolumes(type, list);
+    }
+}
+
+nsecs_t VolumeManager::benchmarkPrivate(const std::string& id) {
+    std::string path;
+    if (id == "private" || id == "null") {
+        path = "/data";
+    } else {
+        auto vol = findVolume(id);
+        if (vol != nullptr && vol->getState() == android::vold::VolumeBase::State::kMounted) {
+            path = vol->getPath();
+        }
+    }
+
+    if (path.empty()) {
+        LOG(WARNING) << "Failed to find volume for " << id;
+        return -1;
+    }
+
+    return android::vold::BenchmarkPrivate(path);
+}
+
+int VolumeManager::forgetPartition(const std::string& partGuid) {
+    std::string normalizedGuid;
+    if (android::vold::NormalizeHex(partGuid, normalizedGuid)) {
+        LOG(WARNING) << "Invalid GUID " << partGuid;
+        return -1;
+    }
+
+    std::string keyPath = android::vold::BuildKeyPath(normalizedGuid);
+    if (unlink(keyPath.c_str()) != 0) {
+        LOG(ERROR) << "Failed to unlink " << keyPath;
+        return -1;
+    }
+
     return 0;
 }
 
-int VolumeManager::formatVolume(const char *label, bool wipe) {
-    Volume *v = lookupVolume(label);
+int VolumeManager::linkPrimary(userid_t userId) {
+    std::string source(mPrimary->getPath());
+    if (mPrimary->getType() == android::vold::VolumeBase::Type::kEmulated) {
+        source = StringPrintf("%s/%d", source.c_str(), userId);
+        fs_prepare_dir(source.c_str(), 0755, AID_ROOT, AID_ROOT);
+    }
 
-    if (!v) {
-        errno = ENOENT;
+    std::string target(StringPrintf("/mnt/user/%d/primary", userId));
+    if (TEMP_FAILURE_RETRY(unlink(target.c_str()))) {
+        if (errno != ENOENT) {
+            SLOGW("Failed to unlink %s: %s", target.c_str(), strerror(errno));
+        }
+    }
+    LOG(DEBUG) << "Linking " << source << " to " << target;
+    if (TEMP_FAILURE_RETRY(symlink(source.c_str(), target.c_str()))) {
+        SLOGW("Failed to link %s to %s: %s", source.c_str(), target.c_str(),
+                strerror(errno));
+        return -errno;
+    }
+    return 0;
+}
+
+int VolumeManager::onUserAdded(userid_t userId, int userSerialNumber) {
+    mAddedUsers[userId] = userSerialNumber;
+    return 0;
+}
+
+int VolumeManager::onUserRemoved(userid_t userId) {
+    mAddedUsers.erase(userId);
+    return 0;
+}
+
+int VolumeManager::onUserStarted(userid_t userId) {
+    // Note that sometimes the system will spin up processes from Zygote
+    // before actually starting the user, so we're okay if Zygote
+    // already created this directory.
+    std::string path(StringPrintf("%s/%d", kUserMountPath, userId));
+    fs_prepare_dir(path.c_str(), 0755, AID_ROOT, AID_ROOT);
+
+    mStartedUsers.insert(userId);
+    if (mPrimary) {
+        linkPrimary(userId);
+    }
+    return 0;
+}
+
+int VolumeManager::onUserStopped(userid_t userId) {
+    mStartedUsers.erase(userId);
+    return 0;
+}
+
+int VolumeManager::setPrimary(const std::shared_ptr<android::vold::VolumeBase>& vol) {
+    mPrimary = vol;
+    for (userid_t userId : mStartedUsers) {
+        linkPrimary(userId);
+    }
+    return 0;
+}
+
+static int sane_readlinkat(int dirfd, const char* path, char* buf, size_t bufsiz) {
+    ssize_t len = readlinkat(dirfd, path, buf, bufsiz);
+    if (len < 0) {
+        return -1;
+    } else if (len == (ssize_t) bufsiz) {
+        return -1;
+    } else {
+        buf[len] = '\0';
+        return 0;
+    }
+}
+
+static int unmount_tree(const char* path) {
+    size_t path_len = strlen(path);
+
+    FILE* fp = setmntent("/proc/mounts", "r");
+    if (fp == NULL) {
+        ALOGE("Error opening /proc/mounts: %s", strerror(errno));
+        return -errno;
+    }
+
+    // Some volumes can be stacked on each other, so force unmount in
+    // reverse order to give us the best chance of success.
+    std::list<std::string> toUnmount;
+    mntent* mentry;
+    while ((mentry = getmntent(fp)) != NULL) {
+        if (strncmp(mentry->mnt_dir, path, path_len) == 0) {
+            toUnmount.push_front(std::string(mentry->mnt_dir));
+        }
+    }
+    endmntent(fp);
+
+    for (auto path : toUnmount) {
+        if (umount2(path.c_str(), MNT_DETACH)) {
+            ALOGW("Failed to unmount %s: %s", path.c_str(), strerror(errno));
+        }
+    }
+    return 0;
+}
+
+int VolumeManager::remountUid(uid_t uid, const std::string& mode) {
+    LOG(DEBUG) << "Remounting " << uid << " as mode " << mode;
+
+    DIR* dir;
+    struct dirent* de;
+    char rootName[PATH_MAX];
+    char pidName[PATH_MAX];
+    int pidFd;
+    int nsFd;
+    struct stat sb;
+    pid_t child;
+
+    if (!(dir = opendir("/proc"))) {
+        PLOG(ERROR) << "Failed to opendir";
         return -1;
     }
 
-    if (mVolManagerDisabled) {
-        errno = EBUSY;
+    // Figure out root namespace to compare against below
+    if (sane_readlinkat(dirfd(dir), "1/ns/mnt", rootName, PATH_MAX) == -1) {
+        PLOG(ERROR) << "Failed to readlink";
+        closedir(dir);
         return -1;
     }
 
-    return v->formatVol(wipe);
+    // Poke through all running PIDs look for apps running as UID
+    while ((de = readdir(dir))) {
+        pidFd = -1;
+        nsFd = -1;
+
+        pidFd = openat(dirfd(dir), de->d_name, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+        if (pidFd < 0) {
+            goto next;
+        }
+        if (fstat(pidFd, &sb) != 0) {
+            PLOG(WARNING) << "Failed to stat " << de->d_name;
+            goto next;
+        }
+        if (sb.st_uid != uid) {
+            goto next;
+        }
+
+        // Matches so far, but refuse to touch if in root namespace
+        LOG(DEBUG) << "Found matching PID " << de->d_name;
+        if (sane_readlinkat(pidFd, "ns/mnt", pidName, PATH_MAX) == -1) {
+            PLOG(WARNING) << "Failed to read namespace for " << de->d_name;
+            goto next;
+        }
+        if (!strcmp(rootName, pidName)) {
+            LOG(WARNING) << "Skipping due to root namespace";
+            goto next;
+        }
+
+        // We purposefully leave the namespace open across the fork
+        nsFd = openat(pidFd, "ns/mnt", O_RDONLY);
+        if (nsFd < 0) {
+            PLOG(WARNING) << "Failed to open namespace for " << de->d_name;
+            goto next;
+        }
+
+        if (!(child = fork())) {
+            if (setns(nsFd, CLONE_NEWNS) != 0) {
+                PLOG(ERROR) << "Failed to setns for " << de->d_name;
+                _exit(1);
+            }
+
+            unmount_tree("/storage");
+
+            std::string storageSource;
+            if (mode == "default") {
+                storageSource = "/mnt/runtime/default";
+            } else if (mode == "read") {
+                storageSource = "/mnt/runtime/read";
+            } else if (mode == "write") {
+                storageSource = "/mnt/runtime/write";
+            } else {
+                // Sane default of no storage visible
+                _exit(0);
+            }
+            if (TEMP_FAILURE_RETRY(mount(storageSource.c_str(), "/storage",
+                    NULL, MS_BIND | MS_REC | MS_SLAVE, NULL)) == -1) {
+                PLOG(ERROR) << "Failed to mount " << storageSource << " for "
+                        << de->d_name;
+                _exit(1);
+            }
+
+            // Mount user-specific symlink helper into place
+            userid_t user_id = multiuser_get_user_id(uid);
+            std::string userSource(StringPrintf("/mnt/user/%d", user_id));
+            if (TEMP_FAILURE_RETRY(mount(userSource.c_str(), "/storage/self",
+                    NULL, MS_BIND, NULL)) == -1) {
+                PLOG(ERROR) << "Failed to mount " << userSource << " for "
+                        << de->d_name;
+                _exit(1);
+            }
+
+            _exit(0);
+        }
+
+        if (child == -1) {
+            PLOG(ERROR) << "Failed to fork";
+            goto next;
+        } else {
+            TEMP_FAILURE_RETRY(waitpid(child, nullptr, 0));
+        }
+
+next:
+        close(nsFd);
+        close(pidFd);
+    }
+    closedir(dir);
+    return 0;
+}
+
+int VolumeManager::reset() {
+    // Tear down all existing disks/volumes and start from a blank slate so
+    // newly connected framework hears all events.
+    mInternalEmulated->destroy();
+    mInternalEmulated->create();
+    for (auto disk : mDisks) {
+        disk->destroy();
+        disk->create();
+    }
+    mAddedUsers.clear();
+    mStartedUsers.clear();
+    return 0;
+}
+
+int VolumeManager::shutdown() {
+    mInternalEmulated->destroy();
+    for (auto disk : mDisks) {
+        disk->destroy();
+    }
+    mDisks.clear();
+    return 0;
+}
+
+int VolumeManager::unmountAll() {
+    std::lock_guard<std::mutex> lock(mLock);
+
+    // First, try gracefully unmounting all known devices
+    if (mInternalEmulated != nullptr) {
+        mInternalEmulated->unmount();
+    }
+    for (auto disk : mDisks) {
+        disk->unmountAll();
+    }
+
+    // Worst case we might have some stale mounts lurking around, so
+    // force unmount those just to be safe.
+    FILE* fp = setmntent("/proc/mounts", "r");
+    if (fp == NULL) {
+        SLOGE("Error opening /proc/mounts: %s", strerror(errno));
+        return -errno;
+    }
+
+    // Some volumes can be stacked on each other, so force unmount in
+    // reverse order to give us the best chance of success.
+    std::list<std::string> toUnmount;
+    mntent* mentry;
+    while ((mentry = getmntent(fp)) != NULL) {
+        if (strncmp(mentry->mnt_dir, "/mnt/", 5) == 0
+                || strncmp(mentry->mnt_dir, "/storage/", 9) == 0) {
+            toUnmount.push_front(std::string(mentry->mnt_dir));
+        }
+    }
+    endmntent(fp);
+
+    for (auto path : toUnmount) {
+        SLOGW("Tearing down stale mount %s", path.c_str());
+        android::vold::ForceUnmount(path);
+    }
+
+    return 0;
 }
 
 int VolumeManager::getObbMountPath(const char *sourceFile, char *mountPath, int mountPathLen) {
@@ -318,7 +694,7 @@
     }
 
     memset(mountPath, 0, mountPathLen);
-    int written = snprintf(mountPath, mountPathLen, "%s/%s", Volume::LOOPDIR, idHash);
+    int written = snprintf(mountPath, mountPathLen, "%s/%s", VolumeManager::LOOPDIR, idHash);
     if ((written < 0) || (written >= mountPathLen)) {
         errno = EINVAL;
         return -1;
@@ -352,7 +728,7 @@
         return -1;
     }
 
-    int written = snprintf(buffer, maxlen, "%s/%s", Volume::ASECDIR, id);
+    int written = snprintf(buffer, maxlen, "%s/%s", VolumeManager::ASECDIR, id);
     if ((written < 0) || (written >= maxlen)) {
         SLOGE("getAsecMountPath failed for %s: couldn't construct path in buffer", id);
         errno = EINVAL;
@@ -424,12 +800,6 @@
         return -1;
     }
 
-    if (lookupVolume(id)) {
-        SLOGE("ASEC id '%s' currently exists", id);
-        errno = EADDRINUSE;
-        return -1;
-    }
-
     char asecFileName[255];
 
     if (!findAsec(id, asecFileName, sizeof(asecFileName))) {
@@ -439,7 +809,7 @@
         return -1;
     }
 
-    const char *asecDir = isExternal ? Volume::SEC_ASECDIR_EXT : Volume::SEC_ASECDIR_INT;
+    const char *asecDir = isExternal ? VolumeManager::SEC_ASECDIR_EXT : VolumeManager::SEC_ASECDIR_INT;
 
     int written = snprintf(asecFileName, sizeof(asecFileName), "%s/%s.asec", asecDir, id);
     if ((written < 0) || (size_t(written) >= sizeof(asecFileName))) {
@@ -515,7 +885,7 @@
         int formatStatus;
         char mountPoint[255];
 
-        int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id);
+        int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id);
         if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
             SLOGE("ASEC fs format failed: couldn't construct mountPoint");
             if (cleanupDm) {
@@ -527,9 +897,9 @@
         }
 
         if (usingExt4) {
-            formatStatus = Ext4::format(dmDevice, numImgSectors, mountPoint);
+            formatStatus = android::vold::ext4::Format(dmDevice, numImgSectors, mountPoint);
         } else {
-            formatStatus = Fat::format(dmDevice, numImgSectors, 0);
+            formatStatus = android::vold::vfat::Format(dmDevice, numImgSectors);
         }
 
         if (formatStatus < 0) {
@@ -556,10 +926,11 @@
 
         int mountStatus;
         if (usingExt4) {
-            mountStatus = Ext4::doMount(dmDevice, mountPoint, false, false, false);
+            mountStatus = android::vold::ext4::Mount(dmDevice, mountPoint,
+                    false, false, false);
         } else {
-            mountStatus = Fat::doMount(dmDevice, mountPoint, false, false, false, ownerUid, 0, 0000,
-                    false);
+            mountStatus = android::vold::vfat::Mount(dmDevice, mountPoint,
+                    false, false, false, ownerUid, 0, 0000, false);
         }
 
         if (mountStatus) {
@@ -573,7 +944,7 @@
         }
 
         if (usingExt4) {
-            int dirfd = open(mountPoint, O_DIRECTORY);
+            int dirfd = open(mountPoint, O_DIRECTORY | O_CLOEXEC);
             if (dirfd >= 0) {
                 if (fchown(dirfd, ownerUid, AID_SYSTEM)
                         || fchmod(dirfd, S_IRUSR | S_IWUSR | S_IXUSR | S_ISGID | S_IRGRP | S_IXGRP)) {
@@ -606,7 +977,7 @@
         return -1;
     }
 
-    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id);
+    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id);
     if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
        SLOGE("ASEC resize failed for %s: couldn't construct mountpoint", id);
        return -1;
@@ -622,7 +993,7 @@
     int fd;
     unsigned int oldNumSec = 0;
 
-    if ((fd = open(asecFileName, O_RDONLY)) < 0) {
+    if ((fd = open(asecFileName, O_RDONLY | O_CLOEXEC)) < 0) {
         SLOGE("Failed to open ASEC file (%s)", strerror(errno));
         return -1;
     }
@@ -718,7 +1089,7 @@
      */
     waitForDevMapper(dmDevice);
 
-    if (Ext4::resize(dmDevice, numImgSectors)) {
+    if (android::vold::ext4::Resize(dmDevice, numImgSectors)) {
         SLOGE("Unable to resize %s (%s)", id, strerror(errno));
         if (cleanupDm) {
             Devmapper::destroy(idHash);
@@ -767,7 +1138,7 @@
         return -1;
     }
 
-    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id);
+    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id);
     if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
         SLOGE("ASEC finalize failed: couldn't construct mountPoint");
         return -1;
@@ -775,9 +1146,11 @@
 
     int result = 0;
     if (sb.c_opts & ASEC_SB_C_OPTS_EXT4) {
-        result = Ext4::doMount(loopDevice, mountPoint, true, true, true);
+        result = android::vold::ext4::Mount(loopDevice, mountPoint,
+                true, true, true);
     } else {
-        result = Fat::doMount(loopDevice, mountPoint, true, true, true, 0, 0, 0227, false);
+        result = android::vold::vfat::Mount(loopDevice, mountPoint,
+                true, true, true, 0, 0, 0227, false);
     }
 
     if (result) {
@@ -830,7 +1203,7 @@
         return -1;
     }
 
-    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id);
+    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id);
     if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
         SLOGE("Unable remount to fix permissions for %s: couldn't construct mountpoint", id);
         return -1;
@@ -841,7 +1214,7 @@
         return 0;
     }
 
-    int ret = Ext4::doMount(loopDevice, mountPoint,
+    int ret = android::vold::ext4::Mount(loopDevice, mountPoint,
             false /* read-only */,
             true  /* remount */,
             false /* executable */);
@@ -868,7 +1241,7 @@
              */
             const bool privateFile = !strcmp(ftsent->fts_name, filename);
 
-            int fd = open(ftsent->fts_accpath, O_NOFOLLOW);
+            int fd = open(ftsent->fts_accpath, O_NOFOLLOW | O_CLOEXEC);
             if (fd < 0) {
                 SLOGE("Couldn't open file %s: %s", ftsent->fts_accpath, strerror(errno));
                 result = -1;
@@ -893,7 +1266,7 @@
         fts_close(fts);
 
         // Finally make the directory readable by everyone.
-        int dirfd = open(mountPoint, O_DIRECTORY);
+        int dirfd = open(mountPoint, O_DIRECTORY | O_CLOEXEC);
         if (dirfd < 0 || fchmod(dirfd, 0755)) {
             SLOGE("Couldn't change owner of existing directory %s: %s", mountPoint, strerror(errno));
             result |= -1;
@@ -903,7 +1276,7 @@
         result |= -1;
     }
 
-    result |= Ext4::doMount(loopDevice, mountPoint,
+    result |= android::vold::ext4::Mount(loopDevice, mountPoint,
             true /* read-only */,
             true /* remount */,
             true /* execute */);
@@ -945,7 +1318,7 @@
 
     asprintf(&asecFilename2, "%s/%s.asec", dir, id2);
 
-    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id1);
+    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id1);
     if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
         SLOGE("Rename failed: couldn't construct mountpoint");
         goto out_err;
@@ -957,7 +1330,7 @@
         goto out_err;
     }
 
-    written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id2);
+    written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id2);
     if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
         SLOGE("Rename failed: couldn't construct mountpoint2");
         goto out_err;
@@ -1005,7 +1378,7 @@
         return -1;
     }
 
-    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id);
+    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id);
     if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
         SLOGE("ASEC unmount failed for %s: couldn't construct mountpoint", id);
         return -1;
@@ -1029,7 +1402,7 @@
         return -1;
     }
 
-    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::LOOPDIR, idHash);
+    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::LOOPDIR, idHash);
     if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
         SLOGE("OBB unmount failed for %s: couldn't construct mountpoint", fileName);
         return -1;
@@ -1060,16 +1433,16 @@
         SLOGW("%s unmount attempt %d failed (%s)",
               id, i, strerror(errno));
 
-        int action = 0; // default is to just complain
+        int signal = 0; // default is to just complain
 
         if (force) {
             if (i > (UNMOUNT_RETRIES - 2))
-                action = 2; // SIGKILL
+                signal = SIGKILL;
             else if (i > (UNMOUNT_RETRIES - 3))
-                action = 1; // SIGHUP
+                signal = SIGTERM;
         }
 
-        Process::killProcessesWithOpenFiles(mountPoint, action);
+        Process::killProcessesWithOpenFiles(mountPoint, signal);
         usleep(UNMOUNT_SLEEP_BETWEEN_RETRY_MS);
     }
 
@@ -1141,7 +1514,7 @@
         return -1;
     }
 
-    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id);
+    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id);
     if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
         SLOGE("ASEC destroy failed for %s: couldn't construct mountpoint", id);
         return -1;
@@ -1201,7 +1574,7 @@
 }
 
 bool VolumeManager::isAsecInDirectory(const char *dir, const char *asecName) const {
-    int dirfd = open(dir, O_DIRECTORY);
+    int dirfd = open(dir, O_DIRECTORY | O_CLOEXEC);
     if (dirfd < 0) {
         SLOGE("Couldn't open internal ASEC dir (%s)", strerror(errno));
         return false;
@@ -1232,10 +1605,10 @@
     }
 
     const char *dir;
-    if (isAsecInDirectory(Volume::SEC_ASECDIR_INT, asecName)) {
-        dir = Volume::SEC_ASECDIR_INT;
-    } else if (isAsecInDirectory(Volume::SEC_ASECDIR_EXT, asecName)) {
-        dir = Volume::SEC_ASECDIR_EXT;
+    if (isAsecInDirectory(VolumeManager::SEC_ASECDIR_INT, asecName)) {
+        dir = VolumeManager::SEC_ASECDIR_INT;
+    } else if (isAsecInDirectory(VolumeManager::SEC_ASECDIR_EXT, asecName)) {
+        dir = VolumeManager::SEC_ASECDIR_EXT;
     } else {
         free(asecName);
         return -1;
@@ -1273,7 +1646,7 @@
         return -1;
     }
 
-    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::ASECDIR, id);
+    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::ASECDIR, id);
     if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
         SLOGE("ASEC mount failed for %s: couldn't construct mountpoint", id);
         return -1;
@@ -1339,9 +1712,11 @@
 
     int result;
     if (sb.c_opts & ASEC_SB_C_OPTS_EXT4) {
-        result = Ext4::doMount(dmDevice, mountPoint, readOnly, false, readOnly);
+        result = android::vold::ext4::Mount(dmDevice, mountPoint,
+                readOnly, false, readOnly);
     } else {
-        result = Fat::doMount(dmDevice, mountPoint, readOnly, false, readOnly, ownerUid, 0, 0222, false);
+        result = android::vold::vfat::Mount(dmDevice, mountPoint,
+                readOnly, false, readOnly, ownerUid, 0, 0222, false);
     }
 
     if (result) {
@@ -1360,19 +1735,6 @@
     return 0;
 }
 
-Volume* VolumeManager::getVolumeForFile(const char *fileName) {
-    VolumeCollection::iterator i;
-
-    for (i = mVolumes->begin(); i != mVolumes->end(); ++i) {
-        const char* mountPoint = (*i)->getFuseMountpoint();
-        if (!strncmp(fileName, mountPoint, strlen(mountPoint))) {
-            return *i;
-        }
-    }
-
-    return NULL;
-}
-
 /**
  * Mounts an image file <code>img</code>.
  */
@@ -1385,7 +1747,7 @@
         return -1;
     }
 
-    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", Volume::LOOPDIR, idHash);
+    int written = snprintf(mountPoint, sizeof(mountPoint), "%s/%s", VolumeManager::LOOPDIR, idHash);
     if ((written < 0) || (size_t(written) >= sizeof(mountPoint))) {
         SLOGE("OBB mount failed for %s: couldn't construct mountpoint", img);
         return -1;
@@ -1406,7 +1768,7 @@
     int fd;
     unsigned long nr_sec = 0;
 
-    if ((fd = open(loopDevice, O_RDWR)) < 0) {
+    if ((fd = open(loopDevice, O_RDWR | O_CLOEXEC)) < 0) {
         SLOGE("Failed to open loopdevice (%s)", strerror(errno));
         Loop::destroyByDevice(loopDevice);
         return -1;
@@ -1443,8 +1805,8 @@
      */
     waitForDevMapper(dmDevice);
 
-    if (Fat::doMount(dmDevice, mountPoint, true, false, true, 0, ownerGid,
-                     0227, false)) {
+    if (android::vold::vfat::Mount(dmDevice, mountPoint,
+            true, false, true, 0, ownerGid, 0227, false)) {
         SLOGE("Image mount failed (%s)", strerror(errno));
         if (cleanupDm) {
             Devmapper::destroy(idHash);
@@ -1460,17 +1822,6 @@
     return 0;
 }
 
-int VolumeManager::mountVolume(const char *label) {
-    Volume *v = lookupVolume(label);
-
-    if (!v) {
-        errno = ENOENT;
-        return -1;
-    }
-
-    return v->mountVol();
-}
-
 int VolumeManager::listMountedObbs(SocketClient* cli) {
     FILE *fp = setmntent("/proc/mounts", "r");
     if (fp == NULL) {
@@ -1479,16 +1830,16 @@
     }
 
     // Create a string to compare against that has a trailing slash
-    int loopDirLen = strlen(Volume::LOOPDIR);
+    int loopDirLen = strlen(VolumeManager::LOOPDIR);
     char loopDir[loopDirLen + 2];
-    strcpy(loopDir, Volume::LOOPDIR);
+    strcpy(loopDir, VolumeManager::LOOPDIR);
     loopDir[loopDirLen++] = '/';
     loopDir[loopDirLen] = '\0';
 
     mntent* mentry;
     while ((mentry = getmntent(fp)) != NULL) {
         if (!strncmp(mentry->mnt_dir, loopDir, loopDirLen)) {
-            int fd = open(mentry->mnt_fsname, O_RDONLY);
+            int fd = open(mentry->mnt_fsname, O_RDONLY | O_CLOEXEC);
             if (fd >= 0) {
                 struct loop_info64 li;
                 if (ioctl(fd, LOOP_GET_STATUS64, &li) >= 0) {
@@ -1503,299 +1854,9 @@
     return 0;
 }
 
-int VolumeManager::shareEnabled(const char *label, const char *method, bool *enabled) {
-    Volume *v = lookupVolume(label);
-
-    if (!v) {
-        errno = ENOENT;
-        return -1;
-    }
-
-    if (strcmp(method, "ums")) {
-        errno = ENOSYS;
-        return -1;
-    }
-
-    if (v->getState() != Volume::State_Shared) {
-        *enabled = false;
-    } else {
-        *enabled = true;
-    }
-    return 0;
-}
-
-int VolumeManager::shareVolume(const char *label, const char *method) {
-    Volume *v = lookupVolume(label);
-
-    if (!v) {
-        errno = ENOENT;
-        return -1;
-    }
-
-    /*
-     * Eventually, we'll want to support additional share back-ends,
-     * some of which may work while the media is mounted. For now,
-     * we just support UMS
-     */
-    if (strcmp(method, "ums")) {
-        errno = ENOSYS;
-        return -1;
-    }
-
-    if (v->getState() == Volume::State_NoMedia) {
-        errno = ENODEV;
-        return -1;
-    }
-
-    if (v->getState() != Volume::State_Idle) {
-        // You need to unmount manually befoe sharing
-        errno = EBUSY;
-        return -1;
-    }
-
-    if (mVolManagerDisabled) {
-        errno = EBUSY;
-        return -1;
-    }
-
-    dev_t d = v->getShareDevice();
-    if ((MAJOR(d) == 0) && (MINOR(d) == 0)) {
-        // This volume does not support raw disk access
-        errno = EINVAL;
-        return -1;
-    }
-
-    int fd;
-    char nodepath[255];
-    int written = snprintf(nodepath,
-             sizeof(nodepath), "/dev/block/vold/%d:%d",
-             major(d), minor(d));
-
-    if ((written < 0) || (size_t(written) >= sizeof(nodepath))) {
-        SLOGE("shareVolume failed: couldn't construct nodepath");
-        return -1;
-    }
-
-    if ((fd = open(MASS_STORAGE_FILE_PATH, O_WRONLY)) < 0) {
-        SLOGE("Unable to open ums lunfile (%s)", strerror(errno));
-        return -1;
-    }
-
-    if (write(fd, nodepath, strlen(nodepath)) < 0) {
-        SLOGE("Unable to write to ums lunfile (%s)", strerror(errno));
-        close(fd);
-        return -1;
-    }
-
-    close(fd);
-    v->handleVolumeShared();
-    if (mUmsSharingCount++ == 0) {
-        FILE* fp;
-        mSavedDirtyRatio = -1; // in case we fail
-        if ((fp = fopen("/proc/sys/vm/dirty_ratio", "r+"))) {
-            char line[16];
-            if (fgets(line, sizeof(line), fp) && sscanf(line, "%d", &mSavedDirtyRatio)) {
-                fprintf(fp, "%d\n", mUmsDirtyRatio);
-            } else {
-                SLOGE("Failed to read dirty_ratio (%s)", strerror(errno));
-            }
-            fclose(fp);
-        } else {
-            SLOGE("Failed to open /proc/sys/vm/dirty_ratio (%s)", strerror(errno));
-        }
-    }
-    return 0;
-}
-
-int VolumeManager::unshareVolume(const char *label, const char *method) {
-    Volume *v = lookupVolume(label);
-
-    if (!v) {
-        errno = ENOENT;
-        return -1;
-    }
-
-    if (strcmp(method, "ums")) {
-        errno = ENOSYS;
-        return -1;
-    }
-
-    if (v->getState() != Volume::State_Shared) {
-        errno = EINVAL;
-        return -1;
-    }
-
-    int fd;
-    if ((fd = open(MASS_STORAGE_FILE_PATH, O_WRONLY)) < 0) {
-        SLOGE("Unable to open ums lunfile (%s)", strerror(errno));
-        return -1;
-    }
-
-    char ch = 0;
-    if (write(fd, &ch, 1) < 0) {
-        SLOGE("Unable to write to ums lunfile (%s)", strerror(errno));
-        close(fd);
-        return -1;
-    }
-
-    close(fd);
-    v->handleVolumeUnshared();
-    if (--mUmsSharingCount == 0 && mSavedDirtyRatio != -1) {
-        FILE* fp;
-        if ((fp = fopen("/proc/sys/vm/dirty_ratio", "r+"))) {
-            fprintf(fp, "%d\n", mSavedDirtyRatio);
-            fclose(fp);
-        } else {
-            SLOGE("Failed to open /proc/sys/vm/dirty_ratio (%s)", strerror(errno));
-        }
-        mSavedDirtyRatio = -1;
-    }
-    return 0;
-}
-
-extern "C" int vold_disableVol(const char *label) {
+extern "C" int vold_unmountAll(void) {
     VolumeManager *vm = VolumeManager::Instance();
-    vm->disableVolumeManager();
-    vm->unshareVolume(label, "ums");
-    return vm->unmountVolume(label, true, false);
-}
-
-extern "C" int vold_getNumDirectVolumes(void) {
-    VolumeManager *vm = VolumeManager::Instance();
-    return vm->getNumDirectVolumes();
-}
-
-int VolumeManager::getNumDirectVolumes(void) {
-    VolumeCollection::iterator i;
-    int n=0;
-
-    for (i = mVolumes->begin(); i != mVolumes->end(); ++i) {
-        if ((*i)->getShareDevice() != (dev_t)0) {
-            n++;
-        }
-    }
-    return n;
-}
-
-extern "C" int vold_getDirectVolumeList(struct volume_info *vol_list) {
-    VolumeManager *vm = VolumeManager::Instance();
-    return vm->getDirectVolumeList(vol_list);
-}
-
-int VolumeManager::getDirectVolumeList(struct volume_info *vol_list) {
-    VolumeCollection::iterator i;
-    int n=0;
-    dev_t d;
-
-    for (i = mVolumes->begin(); i != mVolumes->end(); ++i) {
-        if ((d=(*i)->getShareDevice()) != (dev_t)0) {
-            (*i)->getVolInfo(&vol_list[n]);
-            snprintf(vol_list[n].blk_dev, sizeof(vol_list[n].blk_dev),
-                     "/dev/block/vold/%d:%d", major(d), minor(d));
-            n++;
-        }
-    }
-
-    return 0;
-}
-
-int VolumeManager::unmountVolume(const char *label, bool force, bool revert) {
-    Volume *v = lookupVolume(label);
-
-    if (!v) {
-        errno = ENOENT;
-        return -1;
-    }
-
-    if (v->getState() == Volume::State_NoMedia) {
-        errno = ENODEV;
-        return -1;
-    }
-
-    if (v->getState() != Volume::State_Mounted) {
-        SLOGW("Attempt to unmount volume which isn't mounted (%d)\n",
-             v->getState());
-        errno = EBUSY;
-        return UNMOUNT_NOT_MOUNTED_ERR;
-    }
-
-    cleanupAsec(v, force);
-
-    return v->unmountVol(force, revert);
-}
-
-extern "C" int vold_unmountAllAsecs(void) {
-    int rc;
-
-    VolumeManager *vm = VolumeManager::Instance();
-    rc = vm->unmountAllAsecsInDir(Volume::SEC_ASECDIR_EXT);
-    if (vm->unmountAllAsecsInDir(Volume::SEC_ASECDIR_INT)) {
-        rc = -1;
-    }
-    return rc;
-}
-
-#define ID_BUF_LEN 256
-#define ASEC_SUFFIX ".asec"
-#define ASEC_SUFFIX_LEN (sizeof(ASEC_SUFFIX) - 1)
-int VolumeManager::unmountAllAsecsInDir(const char *directory) {
-    DIR *d = opendir(directory);
-    int rc = 0;
-
-    if (!d) {
-        SLOGE("Could not open asec dir %s", directory);
-        return -1;
-    }
-
-    size_t dirent_len = offsetof(struct dirent, d_name) +
-            fpathconf(dirfd(d), _PC_NAME_MAX) + 1;
-
-    struct dirent *dent = (struct dirent *) malloc(dirent_len);
-    if (dent == NULL) {
-        SLOGE("Failed to allocate memory for asec dir");
-        return -1;
-    }
-
-    struct dirent *result;
-    while (!readdir_r(d, dent, &result) && result != NULL) {
-        if (dent->d_name[0] == '.')
-            continue;
-        if (dent->d_type != DT_REG)
-            continue;
-        size_t name_len = strlen(dent->d_name);
-        if (name_len > 5 && name_len < (ID_BUF_LEN + ASEC_SUFFIX_LEN - 1) &&
-                !strcmp(&dent->d_name[name_len - 5], ASEC_SUFFIX)) {
-            char id[ID_BUF_LEN];
-            strlcpy(id, dent->d_name, name_len - 4);
-            if (unmountAsec(id, true)) {
-                /* Register the error, but try to unmount more asecs */
-                rc = -1;
-            }
-        }
-    }
-    closedir(d);
-
-    free(dent);
-
-    return rc;
-}
-
-/*
- * Looks up a volume by it's label or mount-point
- */
-Volume *VolumeManager::lookupVolume(const char *label) {
-    VolumeCollection::iterator i;
-
-    for (i = mVolumes->begin(); i != mVolumes->end(); ++i) {
-        if (label[0] == '/') {
-            if (!strcmp(label, (*i)->getFuseMountpoint()))
-                return (*i);
-        } else {
-            if (!strcmp(label, (*i)->getLabel()))
-                return (*i);
-        }
-    }
-    return NULL;
+    return vm->unmountAll();
 }
 
 bool VolumeManager::isMountpointMounted(const char *mp)
@@ -1818,77 +1879,13 @@
     return found_mp;
 }
 
-int VolumeManager::cleanupAsec(Volume *v, bool force) {
-    int rc = 0;
-
-    char asecFileName[255];
-
-    AsecIdCollection removeAsec;
-    AsecIdCollection removeObb;
-
-    for (AsecIdCollection::iterator it = mActiveContainers->begin(); it != mActiveContainers->end();
-            ++it) {
-        ContainerData* cd = *it;
-
-        if (cd->type == ASEC) {
-            if (findAsec(cd->id, asecFileName, sizeof(asecFileName))) {
-                SLOGE("Couldn't find ASEC %s; cleaning up", cd->id);
-                removeAsec.push_back(cd);
-            } else {
-                SLOGD("Found ASEC at path %s", asecFileName);
-                if (!strncmp(asecFileName, Volume::SEC_ASECDIR_EXT,
-                        strlen(Volume::SEC_ASECDIR_EXT))) {
-                    removeAsec.push_back(cd);
-                }
-            }
-        } else if (cd->type == OBB) {
-            if (v == getVolumeForFile(cd->id)) {
-                removeObb.push_back(cd);
-            }
-        } else {
-            SLOGE("Unknown container type %d!", cd->type);
-        }
-    }
-
-    for (AsecIdCollection::iterator it = removeAsec.begin(); it != removeAsec.end(); ++it) {
-        ContainerData *cd = *it;
-        SLOGI("Unmounting ASEC %s (dependent on %s)", cd->id, v->getLabel());
-        if (unmountAsec(cd->id, force)) {
-            SLOGE("Failed to unmount ASEC %s (%s)", cd->id, strerror(errno));
-            rc = -1;
-        }
-    }
-
-    for (AsecIdCollection::iterator it = removeObb.begin(); it != removeObb.end(); ++it) {
-        ContainerData *cd = *it;
-        SLOGI("Unmounting OBB %s (dependent on %s)", cd->id, v->getLabel());
-        if (unmountObb(cd->id, force)) {
-            SLOGE("Failed to unmount OBB %s (%s)", cd->id, strerror(errno));
-            rc = -1;
-        }
-    }
-
-    return rc;
-}
-
 int VolumeManager::mkdirs(char* path) {
-    // Require that path lives under a volume we manage and is mounted
-    const char* emulated_source = getenv("EMULATED_STORAGE_SOURCE");
-    const char* root = NULL;
-    if (emulated_source && !strncmp(path, emulated_source, strlen(emulated_source))) {
-        root = emulated_source;
+    // Only offer to create directories for paths managed by vold
+    if (strncmp(path, "/storage/", 9) == 0) {
+        // fs_mkdirs() does symlink checking and relative path enforcement
+        return fs_mkdirs(path, 0700);
     } else {
-        Volume* vol = getVolumeForFile(path);
-        if (vol && vol->getState() == Volume::State_Mounted) {
-            root = vol->getMountpoint();
-        }
-    }
-
-    if (!root) {
         SLOGE("Failed to find mounted volume for %s", path);
         return -EINVAL;
     }
-
-    /* fs_mkdirs() does symlink checking and relative path enforcement */
-    return fs_mkdirs(path, 0700);
 }
diff --git a/VolumeManager.h b/VolumeManager.h
index 17fa6f7..fa2237f 100644
--- a/VolumeManager.h
+++ b/VolumeManager.h
@@ -14,16 +14,29 @@
  * limitations under the License.
  */
 
-#ifndef _VOLUMEMANAGER_H
-#define _VOLUMEMANAGER_H
+#ifndef ANDROID_VOLD_VOLUME_MANAGER_H
+#define ANDROID_VOLD_VOLUME_MANAGER_H
 
 #include <pthread.h>
+#include <fnmatch.h>
+#include <stdlib.h>
 
 #ifdef __cplusplus
-#include <utils/List.h>
-#include <sysutils/SocketListener.h>
 
-#include "Volume.h"
+#include <list>
+#include <mutex>
+#include <string>
+#include <unordered_map>
+#include <unordered_set>
+
+#include <cutils/multiuser.h>
+#include <utils/List.h>
+#include <utils/Timers.h>
+#include <sysutils/SocketListener.h>
+#include <sysutils/NetlinkEvent.h>
+
+#include "Disk.h"
+#include "VolumeBase.h"
 
 /* The length of an MD5 hash when encoded into ASCII hex characters */
 #define MD5_ASCII_LENGTH_PLUS_NULL ((MD5_DIGEST_LENGTH*2)+1)
@@ -51,13 +64,17 @@
 typedef android::List<ContainerData*> AsecIdCollection;
 
 class VolumeManager {
+public:
+    static const char *SEC_ASECDIR_EXT;
+    static const char *SEC_ASECDIR_INT;
+    static const char *ASECDIR;
+    static const char *LOOPDIR;
+
 private:
     static VolumeManager *sInstance;
 
-private:
     SocketListener        *mBroadcaster;
 
-    VolumeCollection      *mVolumes;
     AsecIdCollection      *mActiveContainers;
     bool                   mDebug;
 
@@ -65,26 +82,63 @@
     int                    mUmsSharingCount;
     int                    mSavedDirtyRatio;
     int                    mUmsDirtyRatio;
-    int                    mVolManagerDisabled;
 
 public:
     virtual ~VolumeManager();
 
+    // TODO: pipe all requests through VM to avoid exposing this lock
+    std::mutex& getLock() { return mLock; }
+
     int start();
     int stop();
 
     void handleBlockEvent(NetlinkEvent *evt);
 
-    int addVolume(Volume *v);
+    class DiskSource {
+    public:
+        DiskSource(const std::string& sysPattern, const std::string& nickname, int flags) :
+                mSysPattern(sysPattern), mNickname(nickname), mFlags(flags) {
+        }
 
-    int listVolumes(SocketClient *cli, bool broadcast);
-    int mountVolume(const char *label);
-    int unmountVolume(const char *label, bool force, bool revert);
-    int shareVolume(const char *label, const char *method);
-    int unshareVolume(const char *label, const char *method);
-    int shareEnabled(const char *path, const char *method, bool *enabled);
-    int formatVolume(const char *label, bool wipe);
-    void disableVolumeManager(void) { mVolManagerDisabled = 1; }
+        bool matches(const std::string& sysPath) {
+            return !fnmatch(mSysPattern.c_str(), sysPath.c_str(), 0);
+        }
+
+        const std::string& getNickname() { return mNickname; }
+        int getFlags() { return mFlags; }
+
+    private:
+        std::string mSysPattern;
+        std::string mNickname;
+        int mFlags;
+    };
+
+    void addDiskSource(const std::shared_ptr<DiskSource>& diskSource);
+
+    std::shared_ptr<android::vold::Disk> findDisk(const std::string& id);
+    std::shared_ptr<android::vold::VolumeBase> findVolume(const std::string& id);
+
+    void listVolumes(android::vold::VolumeBase::Type type, std::list<std::string>& list);
+
+    nsecs_t benchmarkPrivate(const std::string& id);
+
+    int forgetPartition(const std::string& partGuid);
+
+    int onUserAdded(userid_t userId, int userSerialNumber);
+    int onUserRemoved(userid_t userId);
+    int onUserStarted(userid_t userId);
+    int onUserStopped(userid_t userId);
+
+    int setPrimary(const std::shared_ptr<android::vold::VolumeBase>& vol);
+
+    int remountUid(uid_t uid, const std::string& mode);
+
+    /* Reset all internal state, typically during framework boot */
+    int reset();
+    /* Prepare for device shutdown, safely unmounting all devices */
+    int shutdown();
+    /* Unmount all volumes, usually for encryption */
+    int unmountAll();
 
     /* ASEC */
     int findAsec(const char *id, char *asecPath = NULL, size_t asecPathLen = 0,
@@ -118,16 +172,11 @@
     int unmountObb(const char *fileName, bool force);
     int getObbMountPath(const char *id, char *buffer, int maxlen);
 
-    Volume* getVolumeForFile(const char *fileName);
-
     /* Shared between ASEC and Loopback images */
     int unmountLoopImage(const char *containerId, const char *loopId,
             const char *fileName, const char *mountPoint, bool force);
 
-    void setDebug(bool enable);
-
-    // XXX: Post froyo this should be moved and cleaned up
-    int cleanupAsec(Volume *v, bool force);
+    int setDebug(bool enable);
 
     void setBroadcaster(SocketListener *sl) { mBroadcaster = sl; }
     SocketListener *getBroadcaster() { return mBroadcaster; }
@@ -136,11 +185,6 @@
 
     static char *asecHash(const char *id, char *buffer, size_t len);
 
-    Volume *lookupVolume(const char *label);
-    int getNumDirectVolumes(void);
-    int getDirectVolumeList(struct volume_info *vol_list);
-    int unmountAllAsecsInDir(const char *directory);
-
     /*
      * Ensure that all directories along given path exist, creating parent
      * directories as needed.  Validates that given path is absolute and that
@@ -156,15 +200,25 @@
     bool isMountpointMounted(const char *mp);
     bool isAsecInDirectory(const char *dir, const char *asec) const;
     bool isLegalAsecId(const char *id) const;
+
+    int linkPrimary(userid_t userId);
+
+    std::mutex mLock;
+
+    std::list<std::shared_ptr<DiskSource>> mDiskSources;
+    std::list<std::shared_ptr<android::vold::Disk>> mDisks;
+
+    std::unordered_map<userid_t, int> mAddedUsers;
+    std::unordered_set<userid_t> mStartedUsers;
+
+    std::shared_ptr<android::vold::VolumeBase> mInternalEmulated;
+    std::shared_ptr<android::vold::VolumeBase> mPrimary;
 };
 
 extern "C" {
 #endif /* __cplusplus */
 #define UNMOUNT_NOT_MOUNTED_ERR -2
-    int vold_disableVol(const char *label);
-    int vold_getNumDirectVolumes(void);
-    int vold_getDirectVolumeList(struct volume_info *v);
-    int vold_unmountAllAsecs(void);
+    int vold_unmountAll(void);
 #ifdef __cplusplus
 }
 #endif
diff --git a/bench/benchgen.py b/bench/benchgen.py
new file mode 100644
index 0000000..77262c4
--- /dev/null
+++ b/bench/benchgen.py
@@ -0,0 +1,337 @@
+#!/usr/bin/env python
+
+# Copyright (C) 2015 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the 'License');
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an 'AS IS' BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""
+Generates storage benchmark from captured strace output.
+
+Currently assumes that all mmap'ed regions are resource accesses, and emulates as pread().
+
+Usage:
+$ adb shell strace -p `pid zygote` -o /data/local/tmp/trace -f -ff -y -ttt -e trace=file,desc,munmap
+$ adb pull /data/local/tmp/trace*
+$ python benchgen.py trace.*
+
+"""
+
+import re, sys, collections, traceback, argparse
+
+from operator import itemgetter
+from collections import defaultdict
+
+class Event:
+    def __init__(self, thread, time, call, args, ret):
+        self.thread = thread
+        self.time = time
+        self.call = call
+        self.args = args
+        self.ret = ret
+
+    def __repr__(self):
+        return "%s(%s)=%s" % (self.call, repr(self.args), self.ret)
+
+
+class File:
+    def __init__(self, name, ident):
+        self.name = name
+        self.ident = ident
+        self.size = 0
+
+    def __repr__(self):
+        return self.name
+
+
+events = []
+files = {}
+
+def find_file(name):
+    name = name.strip('<>"')
+    if name not in files:
+        files[name] = File(name, len(files))
+    return files[name]
+
+def extract_file(e, arg):
+    if "<" in arg:
+        fd, path = arg.split("<")
+        path = path.strip(">")
+        handle = "t%sf%s" % (e.thread, fd)
+        return (fd, find_file(path), handle)
+    else:
+        return (None, None, None)
+
+def parse_args(s):
+    args = []
+    arg = ""
+    esc = False
+    quot = False
+    for c in s:
+        if esc:
+            esc = False
+            arg += c
+            continue
+
+        if c == '"':
+            if quot:
+                quot = False
+                continue
+            else:
+                quot = True
+                continue
+
+        if c == '\\':
+            esc = True
+            continue
+
+        if c == ',' and not quot:
+            args.append(arg.strip())
+            arg = ""
+        else:
+            arg += c
+
+    args.append(arg.strip())
+    return args
+
+
+bufsize = 1048576
+interesting = ["mmap2","read","write","pread64","pwrite64","fsync","fdatasync","openat","close","lseek","_llseek"]
+
+re_event = re.compile(r"^([\d\.]+) (.+?)\((.+?)\) = (.+?)$")
+re_arg = re.compile(r'''((?:[^,"']|"[^"]*"|'[^']*')+)''')
+for fn in sys.argv[1:]:
+    with open(fn) as f:
+        thread = int(fn.split(".")[-1])
+        for line in f:
+            line = re_event.match(line)
+            if not line: continue
+
+            time, call, args, ret = line.groups()
+            if call not in interesting: continue
+            if "/data/" not in args: continue
+
+            time = float(time)
+            args = parse_args(args)
+            events.append(Event(thread, time, call, args, ret))
+
+
+with open("BenchmarkGen.h", 'w') as bench:
+    print >>bench, """/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+/******************************************************************
+ * THIS CODE WAS GENERATED BY benchgen.py, DO NOT MODIFY DIRECTLY *
+ ******************************************************************/
+
+
+#include <base/logging.h>
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/sendfile.h>
+#include <fcntl.h>
+
+#include <algorithm>
+#include <string>
+
+#include <Utils.h>
+
+namespace android {
+namespace vold {
+
+static status_t BenchmarkRun() {
+"""
+
+    print >>bench, "char* buf = (char*) malloc(%d);" % (bufsize)
+
+    nread = 0
+    nwrite = 0
+    nsync = 0
+    events = sorted(events, key=lambda e: e.time)
+    active = set()
+    defined = set()
+    for e in events:
+        if e.call == "openat":
+            fd, f, handle = extract_file(e, e.ret)
+            if f:
+                active.add(handle)
+                if handle not in defined:
+                    print >>bench, "int ",
+                    defined.add(handle)
+                print >>bench, '%s = TEMP_FAILURE_RETRY(open("file%s", %s));' % (handle, f.ident, e.args[2])
+
+        elif e.call == "close":
+            fd, f, handle = extract_file(e, e.args[0])
+            if handle in active:
+                active.remove(handle)
+                print >>bench, 'close(%s);' % (handle)
+
+        elif e.call == "lseek":
+            fd, f, handle = extract_file(e, e.args[0])
+            if handle in active:
+                print >>bench, 'TEMP_FAILURE_RETRY(lseek(%s, %s, %s));' % (handle, e.args[1], e.args[2])
+
+        elif e.call == "_llseek":
+            fd, f, handle = extract_file(e, e.args[0])
+            if handle in active:
+                print >>bench, 'TEMP_FAILURE_RETRY(lseek(%s, %s, %s));' % (handle, e.args[1], e.args[3])
+
+        elif e.call == "read":
+            fd, f, handle = extract_file(e, e.args[0])
+            if handle in active:
+                # TODO: track actual file size instead of guessing
+                count = min(int(e.args[2]), bufsize)
+                f.size += count
+                print >>bench, 'TEMP_FAILURE_RETRY(read(%s, buf, %d));' % (handle, count)
+                nread += 1
+
+        elif e.call == "write":
+            fd, f, handle = extract_file(e, e.args[0])
+            if handle in active:
+                # TODO: track actual file size instead of guessing
+                count = min(int(e.args[2]), bufsize)
+                f.size += count
+                print >>bench, 'TEMP_FAILURE_RETRY(read(%s, buf, %d));' % (handle, count)
+                nwrite += 1
+
+        elif e.call == "pread64":
+            fd, f, handle = extract_file(e, e.args[0])
+            if handle in active:
+                f.size = max(f.size, int(e.args[2]) + int(e.args[3]))
+                count = min(int(e.args[2]), bufsize)
+                print >>bench, 'TEMP_FAILURE_RETRY(pread(%s, buf, %d, %s));' % (handle, count, e.args[3])
+                nread += 1
+
+        elif e.call == "pwrite64":
+            fd, f, handle = extract_file(e, e.args[0])
+            if handle in active:
+                f.size = max(f.size, int(e.args[2]) + int(e.args[3]))
+                count = min(int(e.args[2]), bufsize)
+                print >>bench, 'TEMP_FAILURE_RETRY(pwrite(%s, buf, %d, %s));' % (handle, count, e.args[3])
+                nwrite += 1
+
+        elif e.call == "fsync":
+            fd, f, handle = extract_file(e, e.args[0])
+            if handle in active:
+                print >>bench, 'TEMP_FAILURE_RETRY(fsync(%s));' % (handle)
+                nsync += 1
+
+        elif e.call == "fdatasync":
+            fd, f, handle = extract_file(e, e.args[0])
+            if handle in active:
+                print >>bench, 'TEMP_FAILURE_RETRY(fdatasync(%s));' % (handle)
+                nsync += 1
+
+        elif e.call == "mmap2":
+            fd, f, handle = extract_file(e, e.args[4])
+            if handle in active:
+                count = min(int(e.args[1]), bufsize)
+                offset = int(e.args[5], 0)
+                f.size = max(f.size, count + offset)
+                print >>bench, 'TEMP_FAILURE_RETRY(pread(%s, buf, %s, %s)); // mmap2' % (handle, count, offset)
+                nread += 1
+
+    for handle in active:
+        print >>bench, 'close(%s);' % (handle)
+
+    print >>bench, """
+free(buf);
+return 0;
+}
+
+static status_t CreateFile(const char* name, int len) {
+    int chunk = std::min(len, 65536);
+    int out = -1;
+    std::string buf;
+
+    if (android::vold::ReadRandomBytes(chunk, buf) != OK) {
+        LOG(ERROR) << "Failed to read random data";
+        return -EIO;
+    }
+    if ((out = TEMP_FAILURE_RETRY(open(name, O_WRONLY|O_CREAT|O_TRUNC))) < 0) {
+        PLOG(ERROR) << "Failed to open " << name;
+        return -errno;
+    }
+
+    while (len > 0) {
+        int n = write(out, buf.c_str(), std::min(len, chunk));
+        if (n < 0) {
+            PLOG(ERROR) << "Failed to write";
+            close(out);
+            return -errno;
+        }
+        len -= n;
+    }
+
+    close(out);
+    return OK;
+}
+
+static status_t BenchmarkCreate() {
+status_t res = 0;
+res |= CreateFile("stub", 0);
+"""
+    for f in files.values():
+        print >>bench, 'res |= CreateFile("file%s", %d);' % (f.ident, f.size)
+
+    print >>bench, """
+return res;
+}
+
+static status_t BenchmarkDestroy() {
+status_t res = 0;
+res |= unlink("stub");
+"""
+    for f in files.values():
+        print >>bench, 'res |= unlink("file%s");' % (f.ident)
+
+    print >>bench, """
+return res;
+}
+
+static std::string BenchmarkIdent() {"""
+    print >>bench, """return "r%d:w%d:s%d";""" % (nread, nwrite, nsync)
+    print >>bench, """}
+
+}  // namespace vold
+}  // namespace android
+"""
+
+
+size = sum([ f.size for f in files.values() ])
+print "Found", len(files), "data files accessed, total size", (size/1024), "kB"
+
+types = defaultdict(int)
+for e in events:
+    types[e.call] += 1
+
+print "Found syscalls:"
+for t, n in types.iteritems():
+    print str(n).rjust(8), t
+
+print
diff --git a/cryptfs.c b/cryptfs.c
index 5422f52..a905ff6 100644
--- a/cryptfs.c
+++ b/cryptfs.c
@@ -61,6 +61,7 @@
 #include "Process.h"
 
 #include <hardware/keymaster0.h>
+#include <hardware/keymaster1.h>
 
 #define UNUSED __attribute__((unused))
 
@@ -78,8 +79,7 @@
 
 #define KEY_IN_FOOTER  "footer"
 
-// "default_password" encoded into hex (d=0x64 etc)
-#define DEFAULT_PASSWORD "64656661756c745f70617373776f7264"
+#define DEFAULT_PASSWORD "default_password"
 
 #define EXT4_FS 1
 #define F2FS_FS 2
@@ -89,6 +89,7 @@
 #define RSA_KEY_SIZE 2048
 #define RSA_KEY_SIZE_BYTES (RSA_KEY_SIZE / 8)
 #define RSA_EXPONENT 0x10001
+#define KEYMASTER_CRYPTFS_RATE_LIMIT 1  // Maximum one try per second
 
 #define RETRY_MOUNT_ATTEMPTS 10
 #define RETRY_MOUNT_DELAY_SECONDS 1
@@ -100,7 +101,8 @@
 static int  master_key_saved = 0;
 static struct crypt_persist_data *persist_data = NULL;
 
-static int keymaster_init(keymaster0_device_t **keymaster_dev)
+static int keymaster_init(keymaster0_device_t **keymaster0_dev,
+                          keymaster1_device_t **keymaster1_dev)
 {
     int rc;
 
@@ -108,50 +110,74 @@
     rc = hw_get_module_by_class(KEYSTORE_HARDWARE_MODULE_ID, NULL, &mod);
     if (rc) {
         ALOGE("could not find any keystore module");
-        goto out;
+        goto err;
     }
 
-    rc = keymaster0_open(mod, keymaster_dev);
+    SLOGI("keymaster module name is %s", mod->name);
+    SLOGI("keymaster version is %d", mod->module_api_version);
+
+    *keymaster0_dev = NULL;
+    *keymaster1_dev = NULL;
+    if (mod->module_api_version == KEYMASTER_MODULE_API_VERSION_1_0) {
+        SLOGI("Found keymaster1 module, using keymaster1 API.");
+        rc = keymaster1_open(mod, keymaster1_dev);
+    } else {
+        SLOGI("Found keymaster0 module, using keymaster0 API.");
+        rc = keymaster0_open(mod, keymaster0_dev);
+    }
+
     if (rc) {
         ALOGE("could not open keymaster device in %s (%s)",
-            KEYSTORE_HARDWARE_MODULE_ID, strerror(-rc));
-        goto out;
+              KEYSTORE_HARDWARE_MODULE_ID, strerror(-rc));
+        goto err;
     }
 
     return 0;
 
-out:
-    *keymaster_dev = NULL;
+err:
+    *keymaster0_dev = NULL;
+    *keymaster1_dev = NULL;
     return rc;
 }
 
 /* Should we use keymaster? */
 static int keymaster_check_compatibility()
 {
-    keymaster0_device_t *keymaster_dev = 0;
+    keymaster0_device_t *keymaster0_dev = 0;
+    keymaster1_device_t *keymaster1_dev = 0;
     int rc = 0;
 
-    if (keymaster_init(&keymaster_dev)) {
+    if (keymaster_init(&keymaster0_dev, &keymaster1_dev)) {
         SLOGE("Failed to init keymaster");
         rc = -1;
         goto out;
     }
 
-    SLOGI("keymaster version is %d", keymaster_dev->common.module->module_api_version);
+    if (keymaster1_dev) {
+        rc = 1;
+        goto out;
+    }
 
-    if (keymaster_dev->common.module->module_api_version
+    // TODO(swillden): Check to see if there's any reason to require v0.3.  I think v0.1 and v0.2
+    // should work.
+    if (keymaster0_dev->common.module->module_api_version
             < KEYMASTER_MODULE_API_VERSION_0_3) {
         rc = 0;
         goto out;
     }
 
-    if (!(keymaster_dev->flags & KEYMASTER_SOFTWARE_ONLY) &&
-        (keymaster_dev->flags & KEYMASTER_BLOBS_ARE_STANDALONE)) {
+    if (!(keymaster0_dev->flags & KEYMASTER_SOFTWARE_ONLY) &&
+        (keymaster0_dev->flags & KEYMASTER_BLOBS_ARE_STANDALONE)) {
         rc = 1;
     }
 
 out:
-    keymaster0_close(keymaster_dev);
+    if (keymaster1_dev) {
+        keymaster1_close(keymaster1_dev);
+    }
+    if (keymaster0_dev) {
+        keymaster0_close(keymaster0_dev);
+    }
     return rc;
 }
 
@@ -159,24 +185,67 @@
 static int keymaster_create_key(struct crypt_mnt_ftr *ftr)
 {
     uint8_t* key = 0;
-    keymaster0_device_t *keymaster_dev = 0;
+    keymaster0_device_t *keymaster0_dev = 0;
+    keymaster1_device_t *keymaster1_dev = 0;
 
-    if (keymaster_init(&keymaster_dev)) {
+    if (keymaster_init(&keymaster0_dev, &keymaster1_dev)) {
         SLOGE("Failed to init keymaster");
         return -1;
     }
 
     int rc = 0;
+    size_t key_size = 0;
+    if (keymaster1_dev) {
+        keymaster_key_param_t params[] = {
+            /* Algorithm & size specifications.  Stick with RSA for now.  Switch to AES later. */
+            keymaster_param_enum(KM_TAG_ALGORITHM, KM_ALGORITHM_RSA),
+            keymaster_param_int(KM_TAG_KEY_SIZE, RSA_KEY_SIZE),
+            keymaster_param_long(KM_TAG_RSA_PUBLIC_EXPONENT, RSA_EXPONENT),
 
-    keymaster_rsa_keygen_params_t params;
-    memset(&params, '\0', sizeof(params));
-    params.public_exponent = RSA_EXPONENT;
-    params.modulus_size = RSA_KEY_SIZE;
+	    /* The only allowed purpose for this key is signing. */
+	    keymaster_param_enum(KM_TAG_PURPOSE, KM_PURPOSE_SIGN),
 
-    size_t key_size;
-    if (keymaster_dev->generate_keypair(keymaster_dev, TYPE_RSA, &params,
-                                        &key, &key_size)) {
-        SLOGE("Failed to generate keypair");
+            /* Padding & digest specifications. */
+            keymaster_param_enum(KM_TAG_PADDING, KM_PAD_NONE),
+            keymaster_param_enum(KM_TAG_DIGEST, KM_DIGEST_NONE),
+
+            /* Require that the key be usable in standalone mode.  File system isn't available. */
+            keymaster_param_enum(KM_TAG_BLOB_USAGE_REQUIREMENTS, KM_BLOB_STANDALONE),
+
+            /* No auth requirements, because cryptfs is not yet integrated with gatekeeper. */
+            keymaster_param_bool(KM_TAG_NO_AUTH_REQUIRED),
+
+            /* Rate-limit key usage attempts, to rate-limit brute force */
+            keymaster_param_int(KM_TAG_MIN_SECONDS_BETWEEN_OPS, KEYMASTER_CRYPTFS_RATE_LIMIT),
+        };
+        keymaster_key_param_set_t param_set = { params, sizeof(params)/sizeof(*params) };
+        keymaster_key_blob_t key_blob;
+        keymaster_error_t error = keymaster1_dev->generate_key(keymaster1_dev, &param_set,
+                                                               &key_blob,
+                                                               NULL /* characteristics */);
+        if (error != KM_ERROR_OK) {
+            SLOGE("Failed to generate keymaster1 key, error %d", error);
+            rc = -1;
+            goto out;
+        }
+
+        key = (uint8_t*)key_blob.key_material;
+        key_size = key_blob.key_material_size;
+    }
+    else if (keymaster0_dev) {
+        keymaster_rsa_keygen_params_t params;
+        memset(&params, '\0', sizeof(params));
+        params.public_exponent = RSA_EXPONENT;
+        params.modulus_size = RSA_KEY_SIZE;
+
+        if (keymaster0_dev->generate_keypair(keymaster0_dev, TYPE_RSA, &params,
+                                             &key, &key_size)) {
+            SLOGE("Failed to generate keypair");
+            rc = -1;
+            goto out;
+        }
+    } else {
+        SLOGE("Cryptfs bug: keymaster_init succeeded but didn't initialize a device");
         rc = -1;
         goto out;
     }
@@ -191,7 +260,10 @@
     ftr->keymaster_blob_size = key_size;
 
 out:
-    keymaster0_close(keymaster_dev);
+    if (keymaster0_dev)
+        keymaster0_close(keymaster0_dev);
+    if (keymaster1_dev)
+        keymaster1_close(keymaster1_dev);
     free(key);
     return rc;
 }
@@ -204,20 +276,14 @@
                                  size_t *signature_size)
 {
     int rc = 0;
-    keymaster0_device_t *keymaster_dev = 0;
-    if (keymaster_init(&keymaster_dev)) {
+    keymaster0_device_t *keymaster0_dev = 0;
+    keymaster1_device_t *keymaster1_dev = 0;
+    if (keymaster_init(&keymaster0_dev, &keymaster1_dev)) {
         SLOGE("Failed to init keymaster");
-        return -1;
+        rc = -1;
+        goto out;
     }
 
-    /* We currently set the digest type to DIGEST_NONE because it's the
-     * only supported value for keymaster. A similar issue exists with
-     * PADDING_NONE. Long term both of these should likely change.
-     */
-    keymaster_rsa_sign_params_t params;
-    params.digest_type = DIGEST_NONE;
-    params.padding_type = PADDING_NONE;
-
     unsigned char to_sign[RSA_KEY_SIZE_BYTES];
     size_t to_sign_size = sizeof(to_sign);
     memset(to_sign, 0, RSA_KEY_SIZE_BYTES);
@@ -237,49 +303,103 @@
     //    necessary, but is necessary to ensure consistency in
     //    implementations.
     switch (ftr->kdf_type) {
-        case KDF_SCRYPT_KEYMASTER_UNPADDED:
-            // This is broken: It produces a message which is shorter than
-            // the public modulus, failing criterion 2.
-            memcpy(to_sign, object, object_size);
-            to_sign_size = object_size;
-            SLOGI("Signing unpadded object");
-            break;
-        case KDF_SCRYPT_KEYMASTER_BADLY_PADDED:
-            // This is broken: Since the value of object is uniformly
-            // distributed, it produces a message that is larger than the
-            // public modulus with probability 0.25.
-            memcpy(to_sign, object, min(RSA_KEY_SIZE_BYTES, object_size));
-            SLOGI("Signing end-padded object");
-            break;
         case KDF_SCRYPT_KEYMASTER:
             // This ensures the most significant byte of the signed message
             // is zero.  We could have zero-padded to the left instead, but
             // this approach is slightly more robust against changes in
             // object size.  However, it's still broken (but not unusably
-            // so) because we really should be using a proper RSA padding
-            // function, such as OAEP.
-            //
-            // TODO(paullawrence): When keymaster 0.4 is available, change
-            // this to use the padding options it provides.
+            // so) because we really should be using a proper deterministic
+            // RSA padding function, such as PKCS1.
             memcpy(to_sign + 1, object, min(RSA_KEY_SIZE_BYTES - 1, object_size));
             SLOGI("Signing safely-padded object");
             break;
         default:
             SLOGE("Unknown KDF type %d", ftr->kdf_type);
-            return -1;
+            rc = -1;
+            goto out;
     }
 
-    rc = keymaster_dev->sign_data(keymaster_dev,
-                                  &params,
-                                  ftr->keymaster_blob,
-                                  ftr->keymaster_blob_size,
-                                  to_sign,
-                                  to_sign_size,
-                                  signature,
-                                  signature_size);
+    if (keymaster0_dev) {
+        keymaster_rsa_sign_params_t params;
+        params.digest_type = DIGEST_NONE;
+        params.padding_type = PADDING_NONE;
 
-    keymaster0_close(keymaster_dev);
-    return rc;
+        rc = keymaster0_dev->sign_data(keymaster0_dev,
+                                      &params,
+                                      ftr->keymaster_blob,
+                                      ftr->keymaster_blob_size,
+                                      to_sign,
+                                      to_sign_size,
+                                      signature,
+                                      signature_size);
+        goto out;
+    } else if (keymaster1_dev) {
+        keymaster_key_blob_t key = { ftr->keymaster_blob, ftr->keymaster_blob_size };
+        keymaster_key_param_t params[] = {
+            keymaster_param_enum(KM_TAG_PADDING, KM_PAD_NONE),
+            keymaster_param_enum(KM_TAG_DIGEST, KM_DIGEST_NONE),
+        };
+        keymaster_key_param_set_t param_set = { params, sizeof(params)/sizeof(*params) };
+        keymaster_operation_handle_t op_handle;
+        keymaster_error_t error = keymaster1_dev->begin(keymaster1_dev, KM_PURPOSE_SIGN, &key,
+                                                        &param_set, NULL /* out_params */,
+                                                        &op_handle);
+        if (error == KM_ERROR_KEY_RATE_LIMIT_EXCEEDED) {
+            // Key usage has been rate-limited.  Wait a bit and try again.
+            sleep(KEYMASTER_CRYPTFS_RATE_LIMIT);
+            error = keymaster1_dev->begin(keymaster1_dev, KM_PURPOSE_SIGN, &key,
+                                          &param_set, NULL /* out_params */,
+                                          &op_handle);
+        }
+        if (error != KM_ERROR_OK) {
+            SLOGE("Error starting keymaster signature transaction: %d", error);
+            rc = -1;
+            goto out;
+        }
+
+        keymaster_blob_t input = { to_sign, to_sign_size };
+        size_t input_consumed;
+        error = keymaster1_dev->update(keymaster1_dev, op_handle, NULL /* in_params */,
+                                       &input, &input_consumed, NULL /* out_params */,
+                                       NULL /* output */);
+        if (error != KM_ERROR_OK) {
+            SLOGE("Error sending data to keymaster signature transaction: %d", error);
+            rc = -1;
+            goto out;
+        }
+        if (input_consumed != to_sign_size) {
+            // This should never happen.  If it does, it's a bug in the keymaster implementation.
+            SLOGE("Keymaster update() did not consume all data.");
+            keymaster1_dev->abort(keymaster1_dev, op_handle);
+            rc = -1;
+            goto out;
+        }
+
+        keymaster_blob_t tmp_sig;
+        error = keymaster1_dev->finish(keymaster1_dev, op_handle, NULL /* in_params */,
+                                       NULL /* verify signature */, NULL /* out_params */,
+                                       &tmp_sig);
+        if (error != KM_ERROR_OK) {
+            SLOGE("Error finishing keymaster signature transaction: %d", error);
+            rc = -1;
+            goto out;
+        }
+
+        *signature = (uint8_t*)tmp_sig.data;
+        *signature_size = tmp_sig.data_length;
+    } else {
+        SLOGE("Cryptfs bug: keymaster_init succeded but didn't initialize a device.");
+        rc = -1;
+        goto out;
+    }
+
+    out:
+        if (keymaster1_dev)
+            keymaster1_close(keymaster1_dev);
+        if (keymaster0_dev)
+            keymaster0_close(keymaster0_dev);
+
+        return rc;
 }
 
 /* Store password when userdata is successfully decrypted and mounted.
@@ -395,7 +515,7 @@
     struct ext4_super_block sb;
     off64_t len;
 
-    if ((fd = open(dev, O_RDONLY)) < 0) {
+    if ((fd = open(dev, O_RDONLY|O_CLOEXEC)) < 0) {
         SLOGE("Cannot open device to get filesystem size ");
         return 0;
     }
@@ -438,7 +558,7 @@
     fs_mgr_get_crypt_info(fstab, key_loc, real_blkdev, sizeof(key_loc));
 
     if (!strcmp(key_loc, KEY_IN_FOOTER)) {
-      if ( (fd = open(real_blkdev, O_RDWR)) < 0) {
+      if ( (fd = open(real_blkdev, O_RDWR|O_CLOEXEC)) < 0) {
         SLOGE("Cannot open real block device %s\n", real_blkdev);
         return -1;
       }
@@ -500,7 +620,7 @@
     SLOGE("Unexpected value for crypto key location\n");
     return -1;
   }
-  if ( (fd = open(fname, O_RDWR | O_CREAT, 0600)) < 0) {
+  if ( (fd = open(fname, O_RDWR | O_CREAT|O_CLOEXEC, 0600)) < 0) {
     SLOGE("Cannot open footer file %s for put\n", fname);
     return -1;
   }
@@ -638,7 +758,7 @@
     SLOGE("Unexpected value for crypto key location\n");
     return -1;
   }
-  if ( (fd = open(fname, O_RDWR)) < 0) {
+  if ( (fd = open(fname, O_RDWR|O_CLOEXEC)) < 0) {
     SLOGE("Cannot open footer file %s for get\n", fname);
     return -1;
   }
@@ -763,7 +883,7 @@
         return -1;
     }
 
-    fd = open(fname, O_RDONLY);
+    fd = open(fname, O_RDONLY|O_CLOEXEC);
     if (fd < 0) {
         SLOGE("Cannot open %s metadata file", fname);
         return -1;
@@ -844,7 +964,7 @@
         return -1;
     }
 
-    fd = open(fname, O_RDWR);
+    fd = open(fname, O_RDWR|O_CLOEXEC);
     if (fd < 0) {
         SLOGE("Cannot open %s metadata file", fname);
         return -1;
@@ -914,76 +1034,31 @@
     return -1;
 }
 
-static int hexdigit (char c)
-{
-    if (c >= '0' && c <= '9') return c - '0';
-    c = tolower(c);
-    if (c >= 'a' && c <= 'f') return c - 'a' + 10;
-    return -1;
-}
-
-static unsigned char* convert_hex_ascii_to_key(const char* master_key_ascii,
-                                               unsigned int* out_keysize)
-{
-    unsigned int i;
-    *out_keysize = 0;
-
-    size_t size = strlen (master_key_ascii);
-    if (size % 2) {
-        SLOGE("Trying to convert ascii string of odd length");
-        return NULL;
-    }
-
-    unsigned char* master_key = (unsigned char*) malloc(size / 2);
-    if (master_key == 0) {
-        SLOGE("Cannot allocate");
-        return NULL;
-    }
-
-    for (i = 0; i < size; i += 2) {
-        int high_nibble = hexdigit (master_key_ascii[i]);
-        int low_nibble = hexdigit (master_key_ascii[i + 1]);
-
-        if(high_nibble < 0 || low_nibble < 0) {
-            SLOGE("Invalid hex string");
-            free (master_key);
-            return NULL;
-        }
-
-        master_key[*out_keysize] = high_nibble * 16 + low_nibble;
-        (*out_keysize)++;
-    }
-
-    return master_key;
-}
-
 /* Convert a binary key of specified length into an ascii hex string equivalent,
  * without the leading 0x and with null termination
  */
-static void convert_key_to_hex_ascii(unsigned char *master_key, unsigned int keysize,
-                              char *master_key_ascii)
-{
-  unsigned int i, a;
-  unsigned char nibble;
+static void convert_key_to_hex_ascii(const unsigned char *master_key,
+                                     unsigned int keysize, char *master_key_ascii) {
+    unsigned int i, a;
+    unsigned char nibble;
 
-  for (i=0, a=0; i<keysize; i++, a+=2) {
-    /* For each byte, write out two ascii hex digits */
-    nibble = (master_key[i] >> 4) & 0xf;
-    master_key_ascii[a] = nibble + (nibble > 9 ? 0x37 : 0x30);
+    for (i=0, a=0; i<keysize; i++, a+=2) {
+        /* For each byte, write out two ascii hex digits */
+        nibble = (master_key[i] >> 4) & 0xf;
+        master_key_ascii[a] = nibble + (nibble > 9 ? 0x37 : 0x30);
 
-    nibble = master_key[i] & 0xf;
-    master_key_ascii[a+1] = nibble + (nibble > 9 ? 0x37 : 0x30);
-  }
+        nibble = master_key[i] & 0xf;
+        master_key_ascii[a+1] = nibble + (nibble > 9 ? 0x37 : 0x30);
+    }
 
-  /* Add the null termination */
-  master_key_ascii[a] = '\0';
+    /* Add the null termination */
+    master_key_ascii[a] = '\0';
 
 }
 
-static int load_crypto_mapping_table(struct crypt_mnt_ftr *crypt_ftr, unsigned char *master_key,
-                                     char *real_blk_name, const char *name, int fd,
-                                     char *extra_params)
-{
+static int load_crypto_mapping_table(struct crypt_mnt_ftr *crypt_ftr,
+        const unsigned char *master_key, const char *real_blk_name,
+        const char *name, int fd, const char *extra_params) {
   _Alignas(struct dm_ioctl) char buffer[DM_CRYPT_BUF_SIZE];
   struct dm_ioctl *io;
   struct dm_target_spec *tgt;
@@ -1072,9 +1147,9 @@
     return -1;
 }
 
-static int create_crypto_blk_dev(struct crypt_mnt_ftr *crypt_ftr, unsigned char *master_key,
-                                    char *real_blk_name, char *crypto_blk_name, const char *name)
-{
+static int create_crypto_blk_dev(struct crypt_mnt_ftr *crypt_ftr,
+        const unsigned char *master_key, const char *real_blk_name,
+        char *crypto_blk_name, const char *name) {
   char buffer[DM_CRYPT_BUF_SIZE];
   struct dm_ioctl *io;
   unsigned int minor;
@@ -1084,7 +1159,7 @@
   char *extra_params;
   int load_count;
 
-  if ((fd = open("/dev/device-mapper", O_RDWR)) < 0 ) {
+  if ((fd = open("/dev/device-mapper", O_RDWR|O_CLOEXEC)) < 0 ) {
     SLOGE("Cannot open device-mapper\n");
     goto errout;
   }
@@ -1149,7 +1224,7 @@
   struct dm_ioctl *io;
   int retval = -1;
 
-  if ((fd = open("/dev/device-mapper", O_RDWR)) < 0 ) {
+  if ((fd = open("/dev/device-mapper", O_RDWR|O_CLOEXEC)) < 0 ) {
     SLOGE("Cannot open device-mapper\n");
     goto errout;
   }
@@ -1178,14 +1253,10 @@
     SLOGI("Using pbkdf2 for cryptfs KDF");
 
     /* Turn the password into a key and IV that can decrypt the master key */
-    unsigned int keysize;
-    char* master_key = (char*)convert_hex_ascii_to_key(passwd, &keysize);
-    if (!master_key) return -1;
-    PKCS5_PBKDF2_HMAC_SHA1(master_key, keysize, salt, SALT_LEN,
+    PKCS5_PBKDF2_HMAC_SHA1(passwd, strlen(passwd),
+                           salt, SALT_LEN,
                            HASH_COUNT, KEY_LEN_BYTES+IV_LEN_BYTES, ikey);
 
-    memset(master_key, 0, keysize);
-    free (master_key);
     return 0;
 }
 
@@ -1202,14 +1273,11 @@
 
     /* Turn the password into a key and IV that can decrypt the master key */
     unsigned int keysize;
-    unsigned char* master_key = convert_hex_ascii_to_key(passwd, &keysize);
-    if (!master_key) return -1;
-    crypto_scrypt(master_key, keysize, salt, SALT_LEN, N, r, p, ikey,
-            KEY_LEN_BYTES + IV_LEN_BYTES);
+    crypto_scrypt((const uint8_t*)passwd, strlen(passwd),
+                  salt, SALT_LEN, N, r, p, ikey,
+                  KEY_LEN_BYTES + IV_LEN_BYTES);
 
-    memset(master_key, 0, keysize);
-    free (master_key);
-    return 0;
+   return 0;
 }
 
 static int scrypt_keymaster(const char *passwd, const unsigned char *salt,
@@ -1218,7 +1286,6 @@
     SLOGI("Using scrypt with keymaster for cryptfs KDF");
 
     int rc;
-    unsigned int key_size;
     size_t signature_size;
     unsigned char* signature;
     struct crypt_mnt_ftr *ftr = (struct crypt_mnt_ftr *) params;
@@ -1227,16 +1294,9 @@
     int r = 1 << ftr->r_factor;
     int p = 1 << ftr->p_factor;
 
-    unsigned char* master_key = convert_hex_ascii_to_key(passwd, &key_size);
-    if (!master_key) {
-        SLOGE("Failed to convert passwd from hex");
-        return -1;
-    }
-
-    rc = crypto_scrypt(master_key, key_size, salt, SALT_LEN,
-                       N, r, p, ikey, KEY_LEN_BYTES + IV_LEN_BYTES);
-    memset(master_key, 0, key_size);
-    free(master_key);
+    rc = crypto_scrypt((const uint8_t*)passwd, strlen(passwd),
+                       salt, SALT_LEN, N, r, p, ikey,
+                       KEY_LEN_BYTES + IV_LEN_BYTES);
 
     if (rc) {
         SLOGE("scrypt failed");
@@ -1275,8 +1335,6 @@
     get_device_scrypt_params(crypt_ftr);
 
     switch (crypt_ftr->kdf_type) {
-    case KDF_SCRYPT_KEYMASTER_UNPADDED:
-    case KDF_SCRYPT_KEYMASTER_BADLY_PADDED:
     case KDF_SCRYPT_KEYMASTER:
         if (keymaster_create_key(crypt_ftr)) {
             SLOGE("keymaster_create_key failed");
@@ -1397,9 +1455,7 @@
 
 static void get_kdf_func(struct crypt_mnt_ftr *ftr, kdf_func *kdf, void** kdf_params)
 {
-    if (ftr->kdf_type == KDF_SCRYPT_KEYMASTER_UNPADDED ||
-        ftr->kdf_type == KDF_SCRYPT_KEYMASTER_BADLY_PADDED ||
-        ftr->kdf_type == KDF_SCRYPT_KEYMASTER) {
+    if (ftr->kdf_type == KDF_SCRYPT_KEYMASTER) {
         *kdf = scrypt_keymaster;
         *kdf_params = ftr;
     } else if (ftr->kdf_type == KDF_SCRYPT) {
@@ -1437,7 +1493,7 @@
     unsigned char key_buf[KEY_LEN_BYTES];
 
     /* Get some random bits for a key */
-    fd = open("/dev/urandom", O_RDONLY);
+    fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC);
     read(fd, key_buf, sizeof(key_buf));
     read(fd, salt, SALT_LEN);
     close(fd);
@@ -1470,10 +1526,10 @@
         if (kill) {
             if (i == (WAIT_UNMOUNT_COUNT - 3)) {
                 SLOGW("sending SIGHUP to processes with open files\n");
-                vold_killProcessesWithOpenFiles(mountpoint, 1);
+                vold_killProcessesWithOpenFiles(mountpoint, SIGTERM);
             } else if (i == (WAIT_UNMOUNT_COUNT - 2)) {
                 SLOGW("sending SIGKILL to processes with open files\n");
-                vold_killProcessesWithOpenFiles(mountpoint, 2);
+                vold_killProcessesWithOpenFiles(mountpoint, SIGKILL);
             }
         }
 
@@ -1492,7 +1548,7 @@
     return rc;
 }
 
-#define DATA_PREP_TIMEOUT 200
+#define DATA_PREP_TIMEOUT 1000
 static int prep_data_fs(void)
 {
     int i;
@@ -1510,7 +1566,7 @@
         if (*p == '1') {
             break;
         } else {
-            usleep(250000);
+            usleep(50000);
         }
     }
     if (i == DATA_PREP_TIMEOUT) {
@@ -1904,36 +1960,18 @@
   return rc;
 }
 
-/* Called by vold when it wants to undo the crypto mapping of a volume it
- * manages.  This is usually in response to a factory reset, when we want
- * to undo the crypto mapping so the volume is formatted in the clear.
- */
-int cryptfs_revert_volume(const char *label)
-{
-    return delete_crypto_blk_dev((char *)label);
-}
-
 /*
- * Called by vold when it's asked to mount an encrypted, nonremovable volume.
- * Setup a dm-crypt mapping, use the saved master key from
- * setting up the /data mapping, and return the new device path.
+ * Called by vold when it's asked to mount an encrypted external
+ * storage volume. The incoming partition has no crypto header/footer,
+ * as any metadata is been stored in a separate, small partition.
+ *
+ * out_crypto_blkdev must be MAXPATHLEN.
  */
-int cryptfs_setup_volume(const char *label, int major, int minor,
-                         char *crypto_sys_path, unsigned int max_path,
-                         int *new_major, int *new_minor)
-{
-    char real_blkdev[MAXPATHLEN], crypto_blkdev[MAXPATHLEN];
-    struct crypt_mnt_ftr sd_crypt_ftr;
-    struct stat statbuf;
-
-    sprintf(real_blkdev, "/dev/block/vold/%d:%d", major, minor);
-
-    get_crypt_ftr_and_key(&sd_crypt_ftr);
-
-    /* Update the fs_size field to be the size of the volume */
-    int fd = open(real_blkdev, O_RDONLY);
+int cryptfs_setup_ext_volume(const char* label, const char* real_blkdev,
+        const unsigned char* key, int keysize, char* out_crypto_blkdev) {
+    int fd = open(real_blkdev, O_RDONLY|O_CLOEXEC);
     if (fd == -1) {
-        SLOGE("Cannot open volume %s\n", real_blkdev);
+        SLOGE("Failed to open %s: %s", real_blkdev, strerror(errno));
         return -1;
     }
 
@@ -1942,25 +1980,26 @@
     close(fd);
 
     if (nr_sec == 0) {
-        SLOGE("Cannot get size of volume %s\n", real_blkdev);
+        SLOGE("Failed to get size of %s: %s", real_blkdev, strerror(errno));
         return -1;
     }
 
-    sd_crypt_ftr.fs_size = nr_sec;
-    create_crypto_blk_dev(&sd_crypt_ftr, saved_master_key, real_blkdev, 
-                          crypto_blkdev, label);
+    struct crypt_mnt_ftr ext_crypt_ftr;
+    memset(&ext_crypt_ftr, 0, sizeof(ext_crypt_ftr));
+    ext_crypt_ftr.fs_size = nr_sec;
+    ext_crypt_ftr.keysize = keysize;
+    strcpy((char*) ext_crypt_ftr.crypto_type_name, "aes-cbc-essiv:sha256");
 
-    if (stat(crypto_blkdev, &statbuf) < 0) {
-        SLOGE("Error get stat for crypto_blkdev %s. err=%d(%s)\n",
-              crypto_blkdev, errno, strerror(errno));
-    }
-    *new_major = MAJOR(statbuf.st_rdev);
-    *new_minor = MINOR(statbuf.st_rdev);
+    return create_crypto_blk_dev(&ext_crypt_ftr, key, real_blkdev,
+            out_crypto_blkdev, label);
+}
 
-    /* Create path to sys entry for this block device */
-    snprintf(crypto_sys_path, max_path, "/devices/virtual/block/%s", strrchr(crypto_blkdev, '/')+1);
-
-    return 0;
+/*
+ * Called by vold when it's asked to unmount an encrypted external
+ * storage volume.
+ */
+int cryptfs_revert_ext_volume(const char* label) {
+    return delete_crypto_blk_dev((char*) label);
 }
 
 int cryptfs_crypto_complete(void)
@@ -1986,68 +2025,6 @@
     return 0;
 }
 
-/*
- * TODO - transition patterns to new format in calling code
- *        and remove this vile hack, and the use of hex in
- *        the password passing code.
- *
- * Patterns are passed in zero based (i.e. the top left dot
- * is represented by zero, the top middle one etc), but we want
- * to store them '1' based.
- * This is to allow us to migrate the calling code to use this
- * convention. It also solves a nasty problem whereby scrypt ignores
- * trailing zeros, so patterns ending at the top left could be
- * truncated, and similarly, you could add the top left to any
- * pattern and still match.
- * adjust_passwd is a hack function that returns the alternate representation
- * if the password appears to be a pattern (hex numbers all less than 09)
- * If it succeeds we need to try both, and in particular try the alternate
- * first. If the original matches, then we need to update the footer
- * with the alternate.
- * All code that accepts passwords must adjust them first. Since
- * cryptfs_check_passwd is always the first function called after a migration
- * (and indeed on any boot) we only need to do the double try in this
- * function.
- */
-char* adjust_passwd(const char* passwd)
-{
-    size_t index, length;
-
-    if (!passwd) {
-        return 0;
-    }
-
-    // Check even length. Hex encoded passwords are always
-    // an even length, since each character encodes to two characters.
-    length = strlen(passwd);
-    if (length % 2) {
-        SLOGW("Password not correctly hex encoded.");
-        return 0;
-    }
-
-    // Check password is old-style pattern - a collection of hex
-    // encoded bytes less than 9 (00 through 08)
-    for (index = 0; index < length; index +=2) {
-        if (passwd[index] != '0'
-            || passwd[index + 1] < '0' || passwd[index + 1] > '8') {
-            return 0;
-        }
-    }
-
-    // Allocate room for adjusted passwd and null terminate
-    char* adjusted = malloc(length + 1);
-    adjusted[length] = 0;
-
-    // Add 0x31 ('1') to each character
-    for (index = 0; index < length; index += 2) {
-        // output is 31 through 39 so set first byte to three, second to src + 1
-        adjusted[index] = '3';
-        adjusted[index + 1] = passwd[index + 1] + 1;
-    }
-
-    return adjusted;
-}
-
 int cryptfs_check_passwd(char *passwd)
 {
     SLOGI("cryptfs_check_passwd");
@@ -2062,31 +2039,8 @@
     if (rc)
         return rc;
 
-    char* adjusted_passwd = adjust_passwd(passwd);
-    if (adjusted_passwd) {
-        int failed_decrypt_count = crypt_ftr.failed_decrypt_count;
-        rc = test_mount_encrypted_fs(&crypt_ftr, adjusted_passwd,
-                                     DATA_MNT_POINT, "userdata");
-
-        // Maybe the original one still works?
-        if (rc) {
-            // Don't double count this failure
-            crypt_ftr.failed_decrypt_count = failed_decrypt_count;
-            rc = test_mount_encrypted_fs(&crypt_ftr, passwd,
-                                         DATA_MNT_POINT, "userdata");
-            if (!rc) {
-                // cryptfs_changepw also adjusts so pass original
-                // Note that adjust_passwd only recognises patterns
-                // so we can safely use CRYPT_TYPE_PATTERN
-                SLOGI("Updating pattern to new format");
-                cryptfs_changepw(CRYPT_TYPE_PATTERN, passwd);
-            }
-        }
-        free(adjusted_passwd);
-    } else {
-        rc = test_mount_encrypted_fs(&crypt_ftr, passwd,
-                                     DATA_MNT_POINT, "userdata");
-    }
+    rc = test_mount_encrypted_fs(&crypt_ftr, passwd,
+                                 DATA_MNT_POINT, "userdata");
 
     if (rc == 0 && crypt_ftr.crypt_type != CRYPT_TYPE_DEFAULT) {
         cryptfs_clear_password();
@@ -2132,11 +2086,6 @@
         /* If the device has no password, then just say the password is valid */
         rc = 0;
     } else {
-        char* adjusted_passwd = adjust_passwd(passwd);
-        if (adjusted_passwd) {
-            passwd = adjusted_passwd;
-        }
-
         decrypt_master_key(passwd, decrypted_master_key, &crypt_ftr, 0, 0);
         if (!memcmp(decrypted_master_key, saved_master_key, crypt_ftr.keysize)) {
             /* They match, the password is correct */
@@ -2146,8 +2095,6 @@
             sleep(1);
             rc = 1;
         }
-
-        free(adjusted_passwd);
     }
 
     return rc;
@@ -2491,14 +2438,14 @@
     data.real_blkdev = real_blkdev;
     data.crypto_blkdev = crypto_blkdev;
 
-    if ( (data.realfd = open(real_blkdev, O_RDWR)) < 0) {
+    if ( (data.realfd = open(real_blkdev, O_RDWR|O_CLOEXEC)) < 0) {
         SLOGE("Error opening real_blkdev %s for inplace encrypt. err=%d(%s)\n",
               real_blkdev, errno, strerror(errno));
         rc = -1;
         goto errout;
     }
 
-    if ( (data.cryptofd = open(crypto_blkdev, O_WRONLY)) < 0) {
+    if ( (data.cryptofd = open(crypto_blkdev, O_WRONLY|O_CLOEXEC)) < 0) {
         SLOGE("Error opening crypto_blkdev %s for ext4 inplace encrypt. err=%d(%s)\n",
               crypto_blkdev, errno, strerror(errno));
         rc = ENABLE_INPLACE_ERR_DEV;
@@ -2622,12 +2569,12 @@
     data.crypto_blkdev = crypto_blkdev;
     data.realfd = -1;
     data.cryptofd = -1;
-    if ( (data.realfd = open64(real_blkdev, O_RDWR)) < 0) {
+    if ( (data.realfd = open64(real_blkdev, O_RDWR|O_CLOEXEC)) < 0) {
         SLOGE("Error opening real_blkdev %s for f2fs inplace encrypt\n",
               real_blkdev);
         goto errout;
     }
-    if ( (data.cryptofd = open64(crypto_blkdev, O_WRONLY)) < 0) {
+    if ( (data.cryptofd = open64(crypto_blkdev, O_WRONLY|O_CLOEXEC)) < 0) {
         SLOGE("Error opening crypto_blkdev %s for f2fs inplace encrypt. err=%d(%s)\n",
               crypto_blkdev, errno, strerror(errno));
         rc = ENABLE_INPLACE_ERR_DEV;
@@ -2694,12 +2641,12 @@
     off64_t one_pct, cur_pct, new_pct;
     off64_t blocks_already_done, tot_numblocks;
 
-    if ( (realfd = open(real_blkdev, O_RDONLY)) < 0) { 
+    if ( (realfd = open(real_blkdev, O_RDONLY|O_CLOEXEC)) < 0) {
         SLOGE("Error opening real_blkdev %s for inplace encrypt\n", real_blkdev);
         return ENABLE_INPLACE_ERR_OTHER;
     }
 
-    if ( (cryptofd = open(crypto_blkdev, O_WRONLY)) < 0) { 
+    if ( (cryptofd = open(crypto_blkdev, O_WRONLY|O_CLOEXEC)) < 0) {
         SLOGE("Error opening crypto_blkdev %s for inplace encrypt. err=%d(%s)\n",
               crypto_blkdev, errno, strerror(errno));
         close(realfd);
@@ -2855,15 +2802,9 @@
 
 #define FRAMEWORK_BOOT_WAIT 60
 
-static inline int should_encrypt(struct volume_info *volume)
-{
-    return (volume->flags & (VOL_ENCRYPTABLE | VOL_NONREMOVABLE)) ==
-            (VOL_ENCRYPTABLE | VOL_NONREMOVABLE);
-}
-
 static int cryptfs_SHA256_fileblock(const char* filename, __le8* buf)
 {
-    int fd = open(filename, O_RDONLY);
+    int fd = open(filename, O_RDONLY|O_CLOEXEC);
     if (fd == -1) {
         SLOGE("Error opening file %s", filename);
         return -1;
@@ -2963,10 +2904,7 @@
     char encrypted_state[PROPERTY_VALUE_MAX];
     char lockid[32] = { 0 };
     char key_loc[PROPERTY_VALUE_MAX];
-    char fuse_sdcard[PROPERTY_VALUE_MAX];
-    char *sd_mnt_point;
     int num_vols;
-    struct volume_info *vol_list = 0;
     off64_t previously_encrypted_upto = 0;
 
     if (!strcmp(howarg, "wipe")) {
@@ -3006,7 +2944,7 @@
     fs_mgr_get_crypt_info(fstab, 0, real_blkdev, sizeof(real_blkdev));
 
     /* Get the size of the real block device */
-    int fd = open(real_blkdev, O_RDONLY);
+    int fd = open(real_blkdev, O_RDONLY|O_CLOEXEC);
     if (fd == -1) {
         SLOGE("Cannot open block device %s\n", real_blkdev);
         goto error_unencrypted;
@@ -3041,55 +2979,15 @@
     snprintf(lockid, sizeof(lockid), "enablecrypto%d", (int) getpid());
     acquire_wake_lock(PARTIAL_WAKE_LOCK, lockid);
 
-    /* Get the sdcard mount point */
-    sd_mnt_point = getenv("EMULATED_STORAGE_SOURCE");
-    if (!sd_mnt_point) {
-       sd_mnt_point = getenv("EXTERNAL_STORAGE");
-    }
-    if (!sd_mnt_point) {
-        sd_mnt_point = "/mnt/sdcard";
-    }
-
-    /* TODO
-     * Currently do not have test devices with multiple encryptable volumes.
-     * When we acquire some, re-add support.
-     */
-    num_vols=vold_getNumDirectVolumes();
-    vol_list = malloc(sizeof(struct volume_info) * num_vols);
-    vold_getDirectVolumeList(vol_list);
-
-    for (i=0; i<num_vols; i++) {
-        if (should_encrypt(&vol_list[i])) {
-            SLOGE("Cannot encrypt if there are multiple encryptable volumes"
-                  "%s\n", vol_list[i].label);
-            goto error_unencrypted;
-        }
-    }
-
     /* The init files are setup to stop the class main and late start when
      * vold sets trigger_shutdown_framework.
      */
     property_set("vold.decrypt", "trigger_shutdown_framework");
     SLOGD("Just asked init to shut down class main\n");
 
-    if (vold_unmountAllAsecs()) {
-        /* Just report the error.  If any are left mounted,
-         * umounting /data below will fail and handle the error.
-         */
-        SLOGE("Error unmounting internal asecs");
-    }
-
-    property_get("ro.crypto.fuse_sdcard", fuse_sdcard, "");
-    if (!strcmp(fuse_sdcard, "true")) {
-        /* This is a device using the fuse layer to emulate the sdcard semantics
-         * on top of the userdata partition.  vold does not manage it, it is managed
-         * by the sdcard service.  The sdcard service was killed by the property trigger
-         * above, so just unmount it now.  We must do this _AFTER_ killing the framework,
-         * unlike the case for vold managed devices above.
-         */
-        if (wait_and_unmount(sd_mnt_point, false)) {
-            goto error_shutting_down;
-        }
+    /* Ask vold to unmount all devices that it manages */
+    if (vold_unmountAll()) {
+        SLOGE("Failed to unmount all vold managed devices");
     }
 
     /* Now unmount the /data partition. */
@@ -3237,8 +3135,6 @@
     /* Undo the dm-crypt mapping whether we succeed or not */
     delete_crypto_blk_dev("userdata");
 
-    free(vol_list);
-
     if (! rc) {
         /* Success */
         crypt_ftr.flags &= ~CRYPT_INCONSISTENT_STATE;
@@ -3279,7 +3175,7 @@
             /* wipe data if encryption failed */
             SLOGE("encryption failed - rebooting into recovery to wipe data\n");
             mkdir("/cache/recovery", 0700);
-            int fd = open("/cache/recovery/command", O_RDWR|O_CREAT|O_TRUNC, 0600);
+            int fd = open("/cache/recovery/command", O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0600);
             if (fd >= 0) {
                 write(fd, "--wipe_data\n", strlen("--wipe_data\n") + 1);
                 write(fd, "--reason=cryptfs_enable_internal\n", strlen("--reason=cryptfs_enable_internal\n") + 1);
@@ -3305,7 +3201,6 @@
     return rc;
 
 error_unencrypted:
-    free(vol_list);
     property_set("vold.encrypt_progress", "error_not_encrypted");
     if (lockid[0]) {
         release_wake_lock(lockid);
@@ -3322,7 +3217,6 @@
 
     /* shouldn't get here */
     property_set("vold.encrypt_progress", "error_shutting_down");
-    free(vol_list);
     if (lockid[0]) {
         release_wake_lock(lockid);
     }
@@ -3331,15 +3225,7 @@
 
 int cryptfs_enable(char *howarg, int type, char *passwd, int allow_reboot)
 {
-    char* adjusted_passwd = adjust_passwd(passwd);
-    if (adjusted_passwd) {
-        passwd = adjusted_passwd;
-    }
-
-    int rc = cryptfs_enable_internal(howarg, type, passwd, allow_reboot);
-
-    free(adjusted_passwd);
-    return rc;
+    return cryptfs_enable_internal(howarg, type, passwd, allow_reboot);
 }
 
 int cryptfs_enable_default(char *howarg, int allow_reboot)
@@ -3355,6 +3241,7 @@
     }
 
     struct crypt_mnt_ftr crypt_ftr;
+    int rc;
 
     /* This is only allowed after we've successfully decrypted the master key */
     if (!master_key_saved) {
@@ -3375,23 +3262,19 @@
 
     crypt_ftr.crypt_type = crypt_type;
 
-    char* adjusted_passwd = adjust_passwd(newpw);
-    if (adjusted_passwd) {
-        newpw = adjusted_passwd;
-    }
-
-    encrypt_master_key(crypt_type == CRYPT_TYPE_DEFAULT ? DEFAULT_PASSWORD
+    rc = encrypt_master_key(crypt_type == CRYPT_TYPE_DEFAULT ? DEFAULT_PASSWORD
                                                         : newpw,
                        crypt_ftr.salt,
                        saved_master_key,
                        crypt_ftr.master_key,
                        &crypt_ftr);
-
+    if (rc) {
+        SLOGE("Encrypt master key failed: %d", rc);
+        return -1;
+    }
     /* save the key */
     put_crypt_ftr_and_key(&crypt_ftr);
 
-    free(adjusted_passwd);
-
 #ifdef CONFIG_HW_DISK_ENCRYPTION
     if (!strcmp((char *)crypt_ftr.crypto_type_name, "aes-xts")) {
         if (crypt_type == CRYPT_TYPE_DEFAULT) {
diff --git a/cryptfs.h b/cryptfs.h
index 7f082cc..94684e2 100644
--- a/cryptfs.h
+++ b/cryptfs.h
@@ -72,10 +72,7 @@
 /* Key Derivation Function algorithms */
 #define KDF_PBKDF2 1
 #define KDF_SCRYPT 2
-/* TODO(paullawrence): Remove KDF_SCRYPT_KEYMASTER_UNPADDED and KDF_SCRYPT_KEYMASTER_BADLY_PADDED
- * when it is safe to do so. */
-#define KDF_SCRYPT_KEYMASTER_UNPADDED 3
-#define KDF_SCRYPT_KEYMASTER_BADLY_PADDED 4
+/* Algorithms 3 & 4 deprecated before shipping outside of google, so removed */
 #define KDF_SCRYPT_KEYMASTER 5
 
 /* Maximum allowed keymaster blob size. */
@@ -176,20 +173,6 @@
   struct crypt_persist_entry persist_entry[0];
 };
 
-struct volume_info {
-   unsigned int size;
-   unsigned int flags;
-   struct crypt_mnt_ftr crypt_ftr;
-   char mnt_point[256];
-   char blk_dev[256];
-   char crypto_blkdev[256];
-   char label[256];
-};
-#define VOL_NONREMOVABLE   0x1
-#define VOL_ENCRYPTABLE    0x2
-#define VOL_PRIMARY        0x4
-#define VOL_PROVIDES_ASEC  0x8
-
 #define DATA_MNT_POINT "/data"
 
 /* Return values for cryptfs_crypto_complete */
@@ -238,11 +221,10 @@
   int cryptfs_enable(char *flag, int type, char *passwd, int allow_reboot);
   int cryptfs_changepw(int type, const char *newpw);
   int cryptfs_enable_default(char *flag, int allow_reboot);
+  int cryptfs_setup_ext_volume(const char* label, const char* real_blkdev,
+          const unsigned char* key, int keysize, char* out_crypto_blkdev);
+  int cryptfs_revert_ext_volume(const char* label);
   int cryptfs_enable_file();
-  int cryptfs_setup_volume(const char *label, int major, int minor,
-                           char *crypto_dev_path, unsigned int max_pathlen,
-                           int *new_major, int *new_minor);
-  int cryptfs_revert_volume(const char *label);
   int cryptfs_getfield(const char *fieldname, char *value, int len);
   int cryptfs_setfield(const char *fieldname, const char *value);
   int cryptfs_mount_default_encrypted(void);
diff --git a/fs/Ext4.cpp b/fs/Ext4.cpp
new file mode 100644
index 0000000..3ae4159
--- /dev/null
+++ b/fs/Ext4.cpp
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <vector>
+#include <string>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/mount.h>
+#include <sys/wait.h>
+
+#include <linux/kdev_t.h>
+
+#define LOG_TAG "Vold"
+
+#include <base/logging.h>
+#include <base/stringprintf.h>
+#include <cutils/log.h>
+#include <cutils/properties.h>
+#include <logwrap/logwrap.h>
+#include <selinux/selinux.h>
+
+#include "Ext4.h"
+#include "Utils.h"
+#include "VoldUtil.h"
+
+using android::base::StringPrintf;
+
+namespace android {
+namespace vold {
+namespace ext4 {
+
+static const char* kResizefsPath = "/system/bin/resize2fs";
+static const char* kMkfsPath = "/system/bin/make_ext4fs";
+static const char* kFsckPath = "/system/bin/e2fsck";
+
+bool IsSupported() {
+    return access(kMkfsPath, X_OK) == 0
+            && access(kFsckPath, X_OK) == 0
+            && IsFilesystemSupported("ext4");
+}
+
+status_t Check(const std::string& source, const std::string& target) {
+    // The following is shamelessly borrowed from fs_mgr.c, so it should be
+    // kept in sync with any changes over there.
+
+    const char* c_source = source.c_str();
+    const char* c_target = target.c_str();
+
+    int status;
+    int ret;
+    long tmpmnt_flags = MS_NOATIME | MS_NOEXEC | MS_NOSUID;
+    char *tmpmnt_opts = (char*) "nomblk_io_submit,errors=remount-ro";
+
+    /*
+     * First try to mount and unmount the filesystem.  We do this because
+     * the kernel is more efficient than e2fsck in running the journal and
+     * processing orphaned inodes, and on at least one device with a
+     * performance issue in the emmc firmware, it can take e2fsck 2.5 minutes
+     * to do what the kernel does in about a second.
+     *
+     * After mounting and unmounting the filesystem, run e2fsck, and if an
+     * error is recorded in the filesystem superblock, e2fsck will do a full
+     * check.  Otherwise, it does nothing.  If the kernel cannot mount the
+     * filesytsem due to an error, e2fsck is still run to do a full check
+     * fix the filesystem.
+     */
+    ret = mount(c_source, c_target, "ext4", tmpmnt_flags, tmpmnt_opts);
+    if (!ret) {
+        int i;
+        for (i = 0; i < 5; i++) {
+            // Try to umount 5 times before continuing on.
+            // Should we try rebooting if all attempts fail?
+            int result = umount(c_target);
+            if (result == 0) {
+                break;
+            }
+            ALOGW("%s(): umount(%s)=%d: %s\n", __func__, c_target, result, strerror(errno));
+            sleep(1);
+        }
+    }
+
+    /*
+     * Some system images do not have e2fsck for licensing reasons
+     * (e.g. recent SDK system images). Detect these and skip the check.
+     */
+    if (access(kFsckPath, X_OK)) {
+        ALOGD("Not running %s on %s (executable not in system image)\n",
+                kFsckPath, c_source);
+    } else {
+        ALOGD("Running %s on %s\n", kFsckPath, c_source);
+
+        std::vector<std::string> cmd;
+        cmd.push_back(kFsckPath);
+        cmd.push_back("-y");
+        cmd.push_back(c_source);
+
+        // ext4 devices are currently always trusted
+        return ForkExecvp(cmd, sFsckContext);
+    }
+
+    return 0;
+}
+
+status_t Mount(const std::string& source, const std::string& target, bool ro,
+        bool remount, bool executable) {
+    int rc;
+    unsigned long flags;
+
+    const char* c_source = source.c_str();
+    const char* c_target = target.c_str();
+
+    flags = MS_NOATIME | MS_NODEV | MS_NOSUID | MS_DIRSYNC;
+
+    flags |= (executable ? 0 : MS_NOEXEC);
+    flags |= (ro ? MS_RDONLY : 0);
+    flags |= (remount ? MS_REMOUNT : 0);
+
+    rc = mount(c_source, c_target, "ext4", flags, NULL);
+
+    if (rc && errno == EROFS) {
+        SLOGE("%s appears to be a read only filesystem - retrying mount RO", c_source);
+        flags |= MS_RDONLY;
+        rc = mount(c_source, c_target, "ext4", flags, NULL);
+    }
+
+    return rc;
+}
+
+status_t Resize(const std::string& source, unsigned int numSectors) {
+    std::vector<std::string> cmd;
+    cmd.push_back(kResizefsPath);
+    cmd.push_back("-f");
+    cmd.push_back(source);
+    cmd.push_back(StringPrintf("%u", numSectors));
+
+    return ForkExecvp(cmd);
+}
+
+status_t Format(const std::string& source, unsigned int numSectors,
+        const std::string& target) {
+    std::vector<std::string> cmd;
+    cmd.push_back(kMkfsPath);
+    cmd.push_back("-J");
+
+    cmd.push_back("-a");
+    cmd.push_back(target);
+
+    if (numSectors) {
+        cmd.push_back("-l");
+        cmd.push_back(StringPrintf("%u", numSectors * 512));
+    }
+
+    // Always generate a real UUID
+    cmd.push_back("-u");
+    cmd.push_back(source);
+
+    return ForkExecvp(cmd);
+}
+
+}  // namespace ext4
+}  // namespace vold
+}  // namespace android
diff --git a/fs/Ext4.h b/fs/Ext4.h
new file mode 100644
index 0000000..a5efa74
--- /dev/null
+++ b/fs/Ext4.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_VOLD_EXT4_H
+#define ANDROID_VOLD_EXT4_H
+
+#include <utils/Errors.h>
+
+#include <string>
+
+namespace android {
+namespace vold {
+namespace ext4 {
+
+bool IsSupported();
+
+status_t Check(const std::string& source, const std::string& target);
+status_t Mount(const std::string& source, const std::string& target, bool ro,
+        bool remount, bool executable);
+status_t Format(const std::string& source, unsigned int numSectors,
+        const std::string& target);
+status_t Resize(const std::string& source, unsigned int numSectors);
+
+}  // namespace ext4
+}  // namespace vold
+}  // namespace android
+
+#endif
diff --git a/fs/F2fs.cpp b/fs/F2fs.cpp
new file mode 100644
index 0000000..b947822
--- /dev/null
+++ b/fs/F2fs.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "F2fs.h"
+#include "Utils.h"
+
+#include <base/logging.h>
+#include <base/stringprintf.h>
+
+#include <vector>
+#include <string>
+
+#include <sys/mount.h>
+
+using android::base::StringPrintf;
+
+namespace android {
+namespace vold {
+namespace f2fs {
+
+static const char* kMkfsPath = "/system/bin/make_f2fs";
+static const char* kFsckPath = "/system/bin/fsck.f2fs";
+
+bool IsSupported() {
+    return access(kMkfsPath, X_OK) == 0
+            && access(kFsckPath, X_OK) == 0
+            && IsFilesystemSupported("f2fs");
+}
+
+status_t Check(const std::string& source) {
+    std::vector<std::string> cmd;
+    cmd.push_back(kFsckPath);
+    cmd.push_back("-f");
+    cmd.push_back(source);
+
+    // f2fs devices are currently always trusted
+    return ForkExecvp(cmd, sFsckContext);
+}
+
+status_t Mount(const std::string& source, const std::string& target) {
+    const char* c_source = source.c_str();
+    const char* c_target = target.c_str();
+    unsigned long flags = MS_NOATIME | MS_NODEV | MS_NOSUID | MS_DIRSYNC;
+
+    int res = mount(c_source, c_target, "f2fs", flags, NULL);
+    if (res != 0) {
+        PLOG(ERROR) << "Failed to mount " << source;
+        if (errno == EROFS) {
+            res = mount(c_source, c_target, "f2fs", flags | MS_RDONLY, NULL);
+            if (res != 0) {
+                PLOG(ERROR) << "Failed to mount read-only " << source;
+            }
+        }
+    }
+
+    return res;
+}
+
+status_t Format(const std::string& source) {
+    std::vector<std::string> cmd;
+    cmd.push_back(kMkfsPath);
+    cmd.push_back(source);
+
+    return ForkExecvp(cmd);
+}
+
+}  // namespace f2fs
+}  // namespace vold
+}  // namespace android
diff --git a/fs/F2fs.h b/fs/F2fs.h
new file mode 100644
index 0000000..f710212
--- /dev/null
+++ b/fs/F2fs.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_VOLD_F2FS_H
+#define ANDROID_VOLD_F2FS_H
+
+#include <utils/Errors.h>
+
+#include <string>
+
+namespace android {
+namespace vold {
+namespace f2fs {
+
+bool IsSupported();
+
+status_t Check(const std::string& source);
+status_t Mount(const std::string& source, const std::string& target);
+status_t Format(const std::string& source);
+
+}  // namespace f2fs
+}  // namespace vold
+}  // namespace android
+
+#endif
diff --git a/fs/Vfat.cpp b/fs/Vfat.cpp
new file mode 100644
index 0000000..7bd05ec
--- /dev/null
+++ b/fs/Vfat.cpp
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/mount.h>
+#include <sys/wait.h>
+#include <linux/fs.h>
+#include <sys/ioctl.h>
+
+#include <linux/kdev_t.h>
+
+#define LOG_TAG "Vold"
+
+#include <base/logging.h>
+#include <base/stringprintf.h>
+#include <cutils/log.h>
+#include <cutils/properties.h>
+#include <selinux/selinux.h>
+
+#include <logwrap/logwrap.h>
+
+#include "Vfat.h"
+#include "Utils.h"
+#include "VoldUtil.h"
+
+using android::base::StringPrintf;
+
+namespace android {
+namespace vold {
+namespace vfat {
+
+static const char* kMkfsPath = "/system/bin/newfs_msdos";
+static const char* kFsckPath = "/system/bin/fsck_msdos";
+
+bool IsSupported() {
+    return access(kMkfsPath, X_OK) == 0
+            && access(kFsckPath, X_OK) == 0
+            && IsFilesystemSupported("vfat");
+}
+
+status_t Check(const std::string& source) {
+    if (access(kFsckPath, X_OK)) {
+        SLOGW("Skipping fs checks\n");
+        return 0;
+    }
+
+    int pass = 1;
+    int rc = 0;
+    do {
+        std::vector<std::string> cmd;
+        cmd.push_back(kFsckPath);
+        cmd.push_back("-p");
+        cmd.push_back("-f");
+        cmd.push_back(source);
+
+        // Fat devices are currently always untrusted
+        rc = ForkExecvp(cmd, sFsckUntrustedContext);
+
+        if (rc < 0) {
+            SLOGE("Filesystem check failed due to logwrap error");
+            errno = EIO;
+            return -1;
+        }
+
+        switch(rc) {
+        case 0:
+            SLOGI("Filesystem check completed OK");
+            return 0;
+
+        case 2:
+            SLOGE("Filesystem check failed (not a FAT filesystem)");
+            errno = ENODATA;
+            return -1;
+
+        case 4:
+            if (pass++ <= 3) {
+                SLOGW("Filesystem modified - rechecking (pass %d)",
+                        pass);
+                continue;
+            }
+            SLOGE("Failing check after too many rechecks");
+            errno = EIO;
+            return -1;
+
+        default:
+            SLOGE("Filesystem check failed (unknown exit code %d)", rc);
+            errno = EIO;
+            return -1;
+        }
+    } while (0);
+
+    return 0;
+}
+
+status_t Mount(const std::string& source, const std::string& target, bool ro,
+        bool remount, bool executable, int ownerUid, int ownerGid, int permMask,
+        bool createLost) {
+    int rc;
+    unsigned long flags;
+    char mountData[255];
+
+    const char* c_source = source.c_str();
+    const char* c_target = target.c_str();
+
+    flags = MS_NODEV | MS_NOSUID | MS_DIRSYNC;
+
+    flags |= (executable ? 0 : MS_NOEXEC);
+    flags |= (ro ? MS_RDONLY : 0);
+    flags |= (remount ? MS_REMOUNT : 0);
+
+    sprintf(mountData,
+            "utf8,uid=%d,gid=%d,fmask=%o,dmask=%o,shortname=mixed",
+            ownerUid, ownerGid, permMask, permMask);
+
+    rc = mount(c_source, c_target, "vfat", flags, mountData);
+
+    if (rc && errno == EROFS) {
+        SLOGE("%s appears to be a read only filesystem - retrying mount RO", c_source);
+        flags |= MS_RDONLY;
+        rc = mount(c_source, c_target, "vfat", flags, mountData);
+    }
+
+    if (rc == 0 && createLost) {
+        char *lost_path;
+        asprintf(&lost_path, "%s/LOST.DIR", c_target);
+        if (access(lost_path, F_OK)) {
+            /*
+             * Create a LOST.DIR in the root so we have somewhere to put
+             * lost cluster chains (fsck_msdos doesn't currently do this)
+             */
+            if (mkdir(lost_path, 0755)) {
+                SLOGE("Unable to create LOST.DIR (%s)", strerror(errno));
+            }
+        }
+        free(lost_path);
+    }
+
+    return rc;
+}
+
+status_t Format(const std::string& source, unsigned int numSectors) {
+    std::vector<std::string> cmd;
+    cmd.push_back(kMkfsPath);
+    cmd.push_back("-F");
+    cmd.push_back("32");
+    cmd.push_back("-O");
+    cmd.push_back("android");
+    cmd.push_back("-c");
+    cmd.push_back("64");
+    cmd.push_back("-A");
+
+    if (numSectors) {
+        cmd.push_back("-s");
+        cmd.push_back(StringPrintf("%u", numSectors));
+    }
+
+    cmd.push_back(source);
+
+    int rc = ForkExecvp(cmd);
+    if (rc < 0) {
+        SLOGE("Filesystem format failed due to logwrap error");
+        errno = EIO;
+        return -1;
+    }
+
+    if (rc == 0) {
+        SLOGI("Filesystem formatted OK");
+        return 0;
+    } else {
+        SLOGE("Format failed (unknown exit code %d)", rc);
+        errno = EIO;
+        return -1;
+    }
+    return 0;
+}
+
+}  // namespace vfat
+}  // namespace vold
+}  // namespace android
diff --git a/fs/Vfat.h b/fs/Vfat.h
new file mode 100644
index 0000000..306c7db
--- /dev/null
+++ b/fs/Vfat.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_VOLD_VFAT_H
+#define ANDROID_VOLD_VFAT_H
+
+#include <utils/Errors.h>
+
+#include <string>
+
+namespace android {
+namespace vold {
+namespace vfat {
+
+bool IsSupported();
+
+status_t Check(const std::string& source);
+status_t Mount(const std::string& source, const std::string& target, bool ro,
+        bool remount, bool executable, int ownerUid, int ownerGid, int permMask,
+        bool createLost);
+status_t Format(const std::string& source, unsigned int numSectors);
+
+}  // namespace vfat
+}  // namespace vold
+}  // namespace android
+
+#endif
diff --git a/fstrim.c b/fstrim.c
deleted file mode 100644
index 2c24fc9..0000000
--- a/fstrim.c
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <string.h>
-#include <limits.h>
-#include <linux/fs.h>
-#include <time.h>
-#include <fs_mgr.h>
-#include <pthread.h>
-#define LOG_TAG "fstrim"
-#include "cutils/log.h"
-#include "hardware_legacy/power.h"
-
-/* These numbers must match what the MountService specified in
- * frameworks/base/services/java/com/android/server/EventLogTags.logtags
- */
-#define LOG_FSTRIM_START  2755
-#define LOG_FSTRIM_FINISH 2756
-
-#define FSTRIM_WAKELOCK "dofstrim"
-
-#define UNUSED __attribute__((unused))
-
-/* From a would-be kernel header */
-#define FIDTRIM         _IOWR('f', 128, struct fstrim_range)    /* Deep discard trim */
-
-static unsigned long long get_boot_time_ms(void)
-{
-    struct timespec t;
-    unsigned long long time_ms;
-
-    t.tv_sec = 0;
-    t.tv_nsec = 0;
-    clock_gettime(CLOCK_BOOTTIME, &t);
-    time_ms = (t.tv_sec * 1000LL) + (t.tv_nsec / 1000000);
-
-    return time_ms;
-}
-
-static void *do_fstrim_filesystems(void *thread_arg)
-{
-    int i;
-    int fd;
-    int ret = 0;
-    struct fstrim_range range = { 0 };
-    extern struct fstab *fstab;
-    int deep_trim = !!thread_arg;
-
-    SLOGI("Starting fstrim work...\n");
-
-    /* Get a wakelock as this may take a while, and we don't want the
-     * device to sleep on us.
-     */
-    acquire_wake_lock(PARTIAL_WAKE_LOCK, FSTRIM_WAKELOCK);
-
-    /* Log the start time in the event log */
-    LOG_EVENT_LONG(LOG_FSTRIM_START, get_boot_time_ms());
-
-    for (i = 0; i < fstab->num_entries; i++) {
-        /* Skip raw partitions */
-        if (!strcmp(fstab->recs[i].fs_type, "emmc") ||
-            !strcmp(fstab->recs[i].fs_type, "mtd")) {
-            continue;
-        }
-        /* Skip read-only filesystems */
-        if (fstab->recs[i].flags & MS_RDONLY) {
-            continue;
-        }
-        if (fs_mgr_is_voldmanaged(&fstab->recs[i])) {
-            continue; /* Should we trim fat32 filesystems? */
-        }
-
-        fd = open(fstab->recs[i].mount_point, O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
-        if (fd < 0) {
-            SLOGE("Cannot open %s for FITRIM\n", fstab->recs[i].mount_point);
-            ret = -1;
-            continue;
-        }
-
-        memset(&range, 0, sizeof(range));
-        range.len = ULLONG_MAX;
-        SLOGI("Invoking %s ioctl on %s", deep_trim ? "FIDTRIM" : "FITRIM", fstab->recs[i].mount_point);
-
-        ret = ioctl(fd, deep_trim ? FIDTRIM : FITRIM, &range);
-        if (ret) {
-            SLOGE("%s ioctl failed on %s (error %d/%s)", deep_trim ? "FIDTRIM" : "FITRIM", fstab->recs[i].mount_point, errno, strerror(errno));
-            ret = -1;
-        } else {
-            SLOGI("Trimmed %llu bytes on %s\n", range.len, fstab->recs[i].mount_point);
-        }
-        close(fd);
-    }
-
-    /* Log the finish time in the event log */
-    LOG_EVENT_LONG(LOG_FSTRIM_FINISH, get_boot_time_ms());
-
-    SLOGI("Finished fstrim work.\n");
-
-    /* Release the wakelock that let us work */
-    release_wake_lock(FSTRIM_WAKELOCK);
-
-    return (void *)(uintptr_t)ret;
-}
-
-int fstrim_filesystems(int deep_trim)
-{
-    pthread_t t;
-    int ret;
-
-    /* Depending on the emmc chip and size, this can take upwards
-     * of a few minutes.  If done in the same thread as the caller
-     * of this function, that would block vold from accepting any
-     * commands until the trim is finished.  So start another thread
-     * to do the work, and return immediately.
-     *
-     * This function should not be called more than once per day, but
-     * even if it is called a second time before the first one finishes,
-     * the kernel will "do the right thing" and split the work between
-     * the two ioctls invoked in separate threads.
-     */
-    ret = pthread_create(&t, NULL, do_fstrim_filesystems, (void *)(intptr_t)deep_trim);
-    if (ret) {
-        SLOGE("Cannot create thread to do fstrim");
-        return ret;
-    }
-
-    ret = pthread_detach(t);
-    if (ret) {
-        SLOGE("Cannot detach thread doing fstrim");
-        return ret;
-    }
-
-    return 0;
-}
diff --git a/fstrim.h b/fstrim.h
deleted file mode 100644
index 185d998..0000000
--- a/fstrim.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-    int fstrim_filesystems(int deep_trim);
-#ifdef __cplusplus
-}
-#endif
-
diff --git a/main.cpp b/main.cpp
index c07f48d..648f36a 100644
--- a/main.cpp
+++ b/main.cpp
@@ -14,49 +14,67 @@
  * limitations under the License.
  */
 
+#include "Disk.h"
+#include "VolumeManager.h"
+#include "CommandListener.h"
+#include "CryptCommandListener.h"
+#include "NetlinkManager.h"
+#include "cryptfs.h"
+#include "sehandle.h"
+
+#include <base/logging.h>
+#include <base/stringprintf.h>
+#include <cutils/klog.h>
+#include <cutils/properties.h>
+#include <cutils/sockets.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-
+#include <getopt.h>
 #include <fcntl.h>
 #include <dirent.h>
 #include <fs_mgr.h>
 
-#define LOG_TAG "Vold"
-
-#include "cutils/klog.h"
-#include "cutils/log.h"
-#include "cutils/properties.h"
-
-#include "VolumeManager.h"
-#include "CommandListener.h"
-#include "NetlinkManager.h"
-#include "DirectVolume.h"
-#include "cryptfs.h"
-#include "sehandle.h"
-
 static int process_config(VolumeManager *vm);
 static void coldboot(const char *path);
+static void parse_args(int argc, char** argv);
 
-#define FSTAB_PREFIX "/fstab."
 struct fstab *fstab;
 
 struct selabel_handle *sehandle;
 
-int main() {
+using android::base::StringPrintf;
+
+int main(int argc, char** argv) {
+    setenv("ANDROID_LOG_TAGS", "*:v", 1);
+    android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM));
+
+    LOG(INFO) << "Vold 3.0 (the awakening) firing up";
+
+    LOG(VERBOSE) << "Detected support for:"
+            << (android::vold::IsFilesystemSupported("ext4") ? " ext4" : "")
+            << (android::vold::IsFilesystemSupported("f2fs") ? " f2fs" : "")
+            << (android::vold::IsFilesystemSupported("vfat") ? " vfat" : "");
 
     VolumeManager *vm;
     CommandListener *cl;
+    CryptCommandListener *ccl;
     NetlinkManager *nm;
 
-    SLOGI("Vold 2.1 (the revenge) firing up");
+    parse_args(argc, argv);
 
     sehandle = selinux_android_file_context_handle();
-    if (sehandle)
+    if (sehandle) {
         selinux_android_set_sehandle(sehandle);
+    }
+
+    // Quickly throw a CLOEXEC on the socket we just inherited from init
+    fcntl(android_get_control_socket("vold"), F_SETFD, FD_CLOEXEC);
+    fcntl(android_get_control_socket("cryptd"), F_SETFD, FD_CLOEXEC);
 
     mkdir("/dev/block/vold", 0755);
 
@@ -65,31 +83,35 @@
 
     /* Create our singleton managers */
     if (!(vm = VolumeManager::Instance())) {
-        SLOGE("Unable to create VolumeManager");
+        LOG(ERROR) << "Unable to create VolumeManager";
         exit(1);
-    };
+    }
 
     if (!(nm = NetlinkManager::Instance())) {
-        SLOGE("Unable to create NetlinkManager");
+        LOG(ERROR) << "Unable to create NetlinkManager";
         exit(1);
-    };
+    }
 
+    if (property_get_bool("vold.debug", false)) {
+        vm->setDebug(true);
+    }
 
     cl = new CommandListener();
+    ccl = new CryptCommandListener();
     vm->setBroadcaster((SocketListener *) cl);
     nm->setBroadcaster((SocketListener *) cl);
 
     if (vm->start()) {
-        SLOGE("Unable to start VolumeManager (%s)", strerror(errno));
+        PLOG(ERROR) << "Unable to start VolumeManager";
         exit(1);
     }
 
     if (process_config(vm)) {
-        SLOGE("Error reading configuration (%s)... continuing anyways", strerror(errno));
+        PLOG(ERROR) << "Error reading configuration... continuing anyways";
     }
 
     if (nm->start()) {
-        SLOGE("Unable to start NetlinkManager (%s)", strerror(errno));
+        PLOG(ERROR) << "Unable to start NetlinkManager";
         exit(1);
     }
 
@@ -100,7 +122,12 @@
      * Now that we're up, we can respond to commands
      */
     if (cl->startListener()) {
-        SLOGE("Unable to start CommandListener (%s)", strerror(errno));
+        PLOG(ERROR) << "Unable to start CommandListener";
+        exit(1);
+    }
+
+    if (ccl->startListener()) {
+        PLOG(ERROR) << "Unable to start CryptCommandListener";
         exit(1);
     }
 
@@ -109,18 +136,41 @@
         sleep(1000);
     }
 
-    SLOGI("Vold exiting");
+    LOG(ERROR) << "Vold exiting";
     exit(0);
 }
 
-static void do_coldboot(DIR *d, int lvl)
-{
+static void parse_args(int argc, char** argv) {
+    static struct option opts[] = {
+        {"blkid_context", required_argument, 0, 'b' },
+        {"blkid_untrusted_context", required_argument, 0, 'B' },
+        {"fsck_context", required_argument, 0, 'f' },
+        {"fsck_untrusted_context", required_argument, 0, 'F' },
+    };
+
+    int c;
+    while ((c = getopt_long(argc, argv, "", opts, nullptr)) != -1) {
+        switch (c) {
+        case 'b': android::vold::sBlkidContext = optarg; break;
+        case 'B': android::vold::sBlkidUntrustedContext = optarg; break;
+        case 'f': android::vold::sFsckContext = optarg; break;
+        case 'F': android::vold::sFsckUntrustedContext = optarg; break;
+        }
+    }
+
+    CHECK(android::vold::sBlkidContext != nullptr);
+    CHECK(android::vold::sBlkidUntrustedContext != nullptr);
+    CHECK(android::vold::sFsckContext != nullptr);
+    CHECK(android::vold::sFsckUntrustedContext != nullptr);
+}
+
+static void do_coldboot(DIR *d, int lvl) {
     struct dirent *de;
     int dfd, fd;
 
     dfd = dirfd(d);
 
-    fd = openat(dfd, "uevent", O_WRONLY);
+    fd = openat(dfd, "uevent", O_WRONLY | O_CLOEXEC);
     if(fd >= 0) {
         write(fd, "add\n", 4);
         close(fd);
@@ -149,8 +199,7 @@
     }
 }
 
-static void coldboot(const char *path)
-{
+static void coldboot(const char *path) {
     DIR *d = opendir(path);
     if(d) {
         do_coldboot(d, 0);
@@ -158,55 +207,40 @@
     }
 }
 
-static int process_config(VolumeManager *vm)
-{
-    char fstab_filename[PROPERTY_VALUE_MAX + sizeof(FSTAB_PREFIX)];
-    char propbuf[PROPERTY_VALUE_MAX];
-    int i;
-    int ret = -1;
-    int flags;
-
-    property_get("ro.hardware", propbuf, "");
-    snprintf(fstab_filename, sizeof(fstab_filename), FSTAB_PREFIX"%s", propbuf);
-
-    fstab = fs_mgr_read_fstab(fstab_filename);
+static int process_config(VolumeManager *vm) {
+    std::string path(android::vold::DefaultFstabPath());
+    fstab = fs_mgr_read_fstab(path.c_str());
     if (!fstab) {
-        SLOGE("failed to open %s\n", fstab_filename);
+        PLOG(ERROR) << "Failed to open default fstab " << path;
         return -1;
     }
 
     /* Loop through entries looking for ones that vold manages */
-    for (i = 0; i < fstab->num_entries; i++) {
+    bool has_adoptable = false;
+    for (int i = 0; i < fstab->num_entries; i++) {
         if (fs_mgr_is_voldmanaged(&fstab->recs[i])) {
-            DirectVolume *dv = NULL;
-            flags = 0;
-
-            /* Set any flags that might be set for this volume */
             if (fs_mgr_is_nonremovable(&fstab->recs[i])) {
-                flags |= VOL_NONREMOVABLE;
+                LOG(WARNING) << "nonremovable no longer supported; ignoring volume";
+                continue;
             }
+
+            std::string sysPattern(fstab->recs[i].blk_device);
+            std::string nickname(fstab->recs[i].label);
+            int flags = 0;
+
             if (fs_mgr_is_encryptable(&fstab->recs[i])) {
-                flags |= VOL_ENCRYPTABLE;
+                flags |= android::vold::Disk::Flags::kAdoptable;
+                has_adoptable = true;
             }
-            /* Only set this flag if there is not an emulated sd card */
-            if (fs_mgr_is_noemulatedsd(&fstab->recs[i]) &&
-                !strcmp(fstab->recs[i].fs_type, "vfat")) {
-                flags |= VOL_PROVIDES_ASEC;
-            }
-            dv = new DirectVolume(vm, &(fstab->recs[i]), flags);
-
-            if (dv->addPath(fstab->recs[i].blk_device)) {
-                SLOGE("Failed to add devpath %s to volume %s",
-                      fstab->recs[i].blk_device, fstab->recs[i].label);
-                goto out_fail;
+            if (fs_mgr_is_noemulatedsd(&fstab->recs[i])
+                    || property_get_bool("vold.debug.default_primary", false)) {
+                flags |= android::vold::Disk::Flags::kDefaultPrimary;
             }
 
-            vm->addVolume(dv);
+            vm->addDiskSource(std::shared_ptr<VolumeManager::DiskSource>(
+                    new VolumeManager::DiskSource(sysPattern, nickname, flags)));
         }
     }
-
-    ret = 0;
-
-out_fail:
-    return ret;
+    property_set("vold.has_adoptable", has_adoptable ? "1" : "0");
+    return 0;
 }
diff --git a/vdc.cpp b/vdc.cpp
index 3e80940..d8476b7 100644
--- a/vdc.cpp
+++ b/vdc.cpp
@@ -54,14 +54,19 @@
         exit(5);
     }
 
-    while ((sock = socket_local_client("vold",
+    const char* sockname = "vold";
+    if (!strcmp(argv[1], "cryptfs")) {
+        sockname = "cryptd";
+    }
+
+    while ((sock = socket_local_client(sockname,
                                  ANDROID_SOCKET_NAMESPACE_RESERVED,
                                  SOCK_STREAM)) < 0) {
         if(!wait_for_socket) {
             fprintf(stderr, "Error connecting (%s)\n", strerror(errno));
             exit(4);
         } else {
-            sleep(1);
+            usleep(10000);
         }
     }
 
@@ -74,6 +79,7 @@
 
 static int do_cmd(int sock, int argc, char **argv) {
     char final_cmd[255] = "0 "; /* 0 is a (now required) sequence number */
+
     int i;
     size_t ret;
 
@@ -166,4 +172,3 @@
     fprintf(stderr,
             "Usage: %s [--wait] <monitor>|<cmd> [arg1] [arg2...]\n", progname);
  }
-