Add timeout for mount on untrusted media

Under some circumstances it seems mounting a device can take a long
time. We already abort fsck if it runs for too long, so this is the last
remaining spot this could happen.

Bug: 339740354
Test: Mount a very slow device, observe no Android restart
Change-Id: I3607be269d3aeb4c2391d1d8e2372e3a6795e7c4
diff --git a/fs/Vfat.cpp b/fs/Vfat.cpp
index d9e2713..3bab02f 100644
--- a/fs/Vfat.cpp
+++ b/fs/Vfat.cpp
@@ -129,8 +129,8 @@
     return (int16_t)(utcOffsetSeconds / 60);
 }
 
-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 DoMount(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;
 
@@ -198,6 +198,32 @@
     return rc;
 }
 
+struct mount_args {
+    const std::string& source;
+    const std::string& target;
+    bool ro;
+    bool remount;
+    bool executable;
+    int ownerUid;
+    int ownerGid;
+    int permMask;
+    bool createLost;
+};
+
+int DoMountWrapper(void* args) {
+    struct mount_args* m_args = (struct mount_args*)args;
+
+    return DoMount(m_args->source, m_args->target, m_args->ro, m_args->remount, m_args->executable,
+                   m_args->ownerUid, m_args->ownerGid, m_args->permMask, m_args->createLost);
+}
+
+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) {
+    struct mount_args args = {source,   target,   ro,       remount,   executable,
+                              ownerUid, ownerGid, permMask, createLost};
+    return ForkTimeout(DoMountWrapper, &args, kUntrustedMountSleepTime);
+}
+
 status_t Format(const std::string& source, unsigned long numSectors) {
     std::vector<std::string> cmd;
     cmd.push_back(kMkfsPath);