Tuxera exFAT vold patch for Android 11.

Issue: FP3-A11#46
Change-Id: Ifbe147f8f8273d617c9fe447539d69e83607730e
diff --git a/fs/HfsPlus.cpp b/fs/HfsPlus.cpp
new file mode 100644
index 0000000..979d17f
--- /dev/null
+++ b/fs/HfsPlus.cpp
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2010-2021 Tuxera Inc.
+ *
+ * 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 <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <linux/fs.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <linux/kdev_t.h>
+
+#define LOG_TAG "Vold::HfsPlus"
+
+#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
+#include <selinux/selinux.h>
+
+#include <logwrap/logwrap.h>
+
+#include "HfsPlus.h"
+#include "Utils.h"
+#include "VoldUtil.h"
+
+using android::base::StringPrintf;
+
+namespace android {
+namespace vold {
+namespace hfsplus {
+
+status_t Detect(const std::string& source, bool *outResult) {
+    const char *const fsPath = source.c_str();
+
+    int retval = -1;
+
+    int fd = open(fsPath, O_RDONLY | O_CLOEXEC);
+    if (fd != -1) {
+        loff_t seek_res = lseek64(fd, 0, SEEK_SET);
+        if (seek_res == 0) {
+            char sb_region[4096];
+            ssize_t read_res = read(fd, sb_region, 4096);
+            if (read_res >= (1024 + 512)) {
+                if (!memcmp(&sb_region[1024], "H+\x00\x04", 4)) {
+                    LOG(INFO) << "HFS+ filesystem detected.";
+                    *outResult = true;
+                }
+                else if (!memcmp(&sb_region[1024], "HX\x00\x05", 4)) {
+                    LOG(INFO) << "HFSX filesystem detected.";
+                    *outResult = true;
+                }
+                else {
+                    LOG(VERBOSE) << "Filesystem detection failed (not an "
+                                 << "HFS+/HFSX filesystem).";
+                    *outResult = false;
+                }
+
+                retval = 0;
+            }
+            else if (read_res != -1) {
+                int err = errno ? errno : EIO;
+                LOG(ERROR) << "Error while reading 4096 bytes from device "
+                           << "offset 0: " << strerror(errno) << " (" << errno
+                           << ")";
+                errno = err;
+            }
+        }
+        else if (seek_res != -1) {
+            int err = errno ? errno : EIO;
+            LOG(ERROR) << "Error while seeking to device offset 0: "
+                       << strerror(errno) << " (" << errno << ")";
+            errno = err;
+        }
+
+        close(fd);
+    }
+
+    return retval;
+}
+
+}  // namespace hfsplus
+}  // namespace vold
+}  // namespace android