OSDN Git Service

Move mount and unmount functions into separate file.
authorrelan <relan@users.noreply.github.com>
Thu, 22 Oct 2009 18:47:23 +0000 (18:47 +0000)
committerrelan <relan@users.noreply.github.com>
Mon, 24 Aug 2015 05:26:10 +0000 (08:26 +0300)
libexfat/exfat.h
libexfat/mount.c [new file with mode: 0644]
libexfat/utils.c

index 4199191..6bfcea3 100644 (file)
@@ -84,8 +84,6 @@ cluster_t exfat_next_cluster(const struct exfat* ef, cluster_t cluster,
 cluster_t exfat_advance_cluster(const struct exfat* ef, cluster_t cluster,
                int contiguous, uint32_t count);
 
-int exfat_mount(struct exfat* ef, const char* spec);
-void exfat_unmount(struct exfat* ef);
 void exfat_stat(const struct exfat_node* node, struct stat *stbuf);
 time_t exfat_exfat2unix(le16_t date, le16_t time);
 void exfat_unix2exfat(time_t unix_time, le16_t* date, le16_t* time);
@@ -101,4 +99,7 @@ void exfat_put_node(struct exfat_node* node);
 int exfat_cache_directory(struct exfat* ef, struct exfat_node* dir);
 void exfat_reset_cache(struct exfat* ef);
 
+int exfat_mount(struct exfat* ef, const char* spec);
+void exfat_unmount(struct exfat* ef);
+
 #endif /* ifndef EXFAT_H_INCLUDED */
diff --git a/libexfat/mount.c b/libexfat/mount.c
new file mode 100644 (file)
index 0000000..c14f1ec
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ *  mount.c
+ *  exFAT file system implementation library.
+ *
+ *  Created by Andrew Nayenko on 22.10.09.
+ *  This software is distributed under the GNU General Public License 
+ *  version 3 or any later.
+ */
+
+#include "exfat.h"
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#define _XOPEN_SOURCE /* for tzset() in Linux */
+#include <time.h>
+
+static uint64_t rootdir_size(const struct exfat* ef)
+{
+       uint64_t clusters = 0;
+       cluster_t rootdir_cluster = le32_to_cpu(ef->sb->rootdir_cluster);
+
+       while (!CLUSTER_INVALID(rootdir_cluster))
+       {
+               clusters++;
+               /* root directory cannot be contiguous because there is no flag
+                  to indicate this */
+               rootdir_cluster = exfat_next_cluster(ef, rootdir_cluster, 0);
+       }
+       return clusters * CLUSTER_SIZE(*ef->sb);
+}
+
+int exfat_mount(struct exfat* ef, const char* spec)
+{
+       tzset();
+
+       ef->sb = malloc(sizeof(struct exfat_super_block));
+       if (ef->sb == NULL)
+       {
+               exfat_error("memory allocation failed");
+               return -ENOMEM;
+       }
+
+       ef->fd = open(spec, O_RDONLY); /* currently read only */
+       if (ef->fd < 0)
+       {
+               free(ef->sb);
+               exfat_error("failed to open `%s'", spec);
+               return -EIO;
+       }
+
+       exfat_read_raw(ef->sb, sizeof(struct exfat_super_block), 0, ef->fd);
+       if (memcmp(ef->sb->oem_name, "EXFAT   ", 8) != 0)
+       {
+               close(ef->fd);
+               free(ef->sb);
+               exfat_error("exFAT file system is not found");
+               return -EIO;
+       }
+
+       ef->upcase = NULL;
+       ef->upcase_chars = 0;
+       ef->rootdir_size = rootdir_size(ef);
+
+       ef->root = malloc(sizeof(struct exfat_node));
+       if (ef->root == NULL)
+       {
+               close(ef->fd);
+               free(ef->sb);
+               exfat_error("failed to allocate root node");
+               return -ENOMEM;
+       }
+       memset(ef->root, 0, sizeof(struct exfat_node));
+       ef->root->flags = EXFAT_ATTRIB_DIR;
+       ef->root->size = ef->rootdir_size;
+       ef->root->start_cluster = le32_to_cpu(ef->sb->rootdir_cluster);
+       ef->root->name[0] = cpu_to_le16('\0');
+       /* exFAT does not have time attributes for the root directory */
+       ef->root->mtime = 0;
+       ef->root->atime = 0;
+       /* always keep at least 1 reference to the root node */
+       exfat_get_node(ef->root);
+
+       return 0;
+}
+
+void exfat_unmount(struct exfat* ef)
+{
+       exfat_put_node(ef->root);
+       exfat_reset_cache(ef);
+       ef->root = NULL;
+       close(ef->fd);
+       ef->fd = 0;
+       free(ef->sb);
+       ef->sb = NULL;
+       free(ef->upcase);
+       ef->upcase = NULL;
+       ef->upcase_chars = 0;
+}
index 1d6ebd1..ac8ed87 100644 (file)
@@ -8,97 +8,9 @@
  */
 
 #include "exfat.h"
-#include <stdlib.h>
 #include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
 #define _XOPEN_SOURCE /* for timezone in Linux */
 #include <time.h>
-#include <sys/time.h>
-
-static uint64_t rootdir_size(const struct exfat* ef)
-{
-       uint64_t clusters = 0;
-       cluster_t rootdir_cluster = le32_to_cpu(ef->sb->rootdir_cluster);
-
-       while (!CLUSTER_INVALID(rootdir_cluster))
-       {
-               clusters++;
-               /* root directory cannot be contiguous because there is no flag
-                  to indicate this */
-               rootdir_cluster = exfat_next_cluster(ef, rootdir_cluster, 0);
-       }
-       return clusters * CLUSTER_SIZE(*ef->sb);
-}
-
-int exfat_mount(struct exfat* ef, const char* spec)
-{
-       tzset();
-
-       ef->sb = malloc(sizeof(struct exfat_super_block));
-       if (ef->sb == NULL)
-       {
-               exfat_error("memory allocation failed");
-               return -ENOMEM;
-       }
-
-       ef->fd = open(spec, O_RDONLY); /* currently read only */
-       if (ef->fd < 0)
-       {
-               free(ef->sb);
-               exfat_error("failed to open `%s'", spec);
-               return -EIO;
-       }
-
-       exfat_read_raw(ef->sb, sizeof(struct exfat_super_block), 0, ef->fd);
-       if (memcmp(ef->sb->oem_name, "EXFAT   ", 8) != 0)
-       {
-               close(ef->fd);
-               free(ef->sb);
-               exfat_error("exFAT file system is not found");
-               return -EIO;
-       }
-
-       ef->upcase = NULL;
-       ef->upcase_chars = 0;
-       ef->rootdir_size = rootdir_size(ef);
-
-       ef->root = malloc(sizeof(struct exfat_node));
-       if (ef->root == NULL)
-       {
-               close(ef->fd);
-               free(ef->sb);
-               exfat_error("failed to allocate root node");
-               return -ENOMEM;
-       }
-       memset(ef->root, 0, sizeof(struct exfat_node));
-       ef->root->flags = EXFAT_ATTRIB_DIR;
-       ef->root->size = ef->rootdir_size;
-       ef->root->start_cluster = le32_to_cpu(ef->sb->rootdir_cluster);
-       ef->root->name[0] = cpu_to_le16('\0');
-       /* exFAT does not have time attributes for the root directory */
-       ef->root->mtime = 0;
-       ef->root->atime = 0;
-       /* always keep at least 1 reference to the root node */
-       exfat_get_node(ef->root);
-
-       return 0;
-}
-
-void exfat_unmount(struct exfat* ef)
-{
-       exfat_put_node(ef->root);
-       exfat_reset_cache(ef);
-       ef->root = NULL;
-       close(ef->fd);
-       ef->fd = 0;
-       free(ef->sb);
-       ef->sb = NULL;
-       free(ef->upcase);
-       ef->upcase = NULL;
-       ef->upcase_chars = 0;
-}
 
 void exfat_stat(const struct exfat_node* node, struct stat *stbuf)
 {