OSDN Git Service

Repairing: implement unknown entry type fix.
[android-x86/external-exfat.git] / libexfat / exfat.h
index 2a592a0..2342be4 100644 (file)
@@ -4,7 +4,7 @@
        implementation.
 
        Free exFAT implementation.
-       Copyright (C) 2010-2016  Andrew Nayenko
+       Copyright (C) 2010-2018  Andrew Nayenko
 
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
 #ifndef EXFAT_H_INCLUDED
 #define EXFAT_H_INCLUDED
 
+#ifndef ANDROID
+/* Android.bp is used instead of autotools when targeting Android */
 #include "config.h"
+#endif
 #include "compiler.h"
 #include "exfatfs.h"
 #include <stdio.h>
@@ -43,8 +46,8 @@
 
 #define SECTOR_SIZE(sb) (1 << (sb).sector_bits)
 #define CLUSTER_SIZE(sb) (SECTOR_SIZE(sb) << (sb).spc_bits)
-#define CLUSTER_INVALID(c) \
-       ((c) < EXFAT_FIRST_DATA_CLUSTER || (c) > EXFAT_LAST_DATA_CLUSTER)
+#define CLUSTER_INVALID(sb, c) ((c) < EXFAT_FIRST_DATA_CLUSTER || \
+       (c) - EXFAT_FIRST_DATA_CLUSTER >= le32_to_cpu((sb).cluster_count))
 
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
@@ -61,6 +64,9 @@
 #define BMAP_CLR(bitmap, index) \
        ((bitmap)[BMAP_BLOCK(index)] &= ~BMAP_MASK(index))
 
+#define EXFAT_REPAIR(hook, ef, ...) \
+       (exfat_ask_to_fix(ef) && exfat_fix_ ## hook(ef, __VA_ARGS__))
+
 /* The size of off_t type must be 64 bits. File systems larger than 2 GB will
    be corrupted with 32-bit off_t. */
 STATIC_ASSERT(sizeof(off_t) == 8);
@@ -75,10 +81,10 @@ struct exfat_node
        int references;
        uint32_t fptr_index;
        cluster_t fptr_cluster;
-       cluster_t entry_cluster;
        off_t entry_offset;
        cluster_t start_cluster;
        uint16_t attrib;
+       uint8_t continuations;
        bool is_contiguous : 1;
        bool is_cached : 1;
        bool is_dirty : 1;
@@ -119,6 +125,7 @@ struct exfat
        gid_t gid;
        int ro;
        bool noatime;
+       enum { EXFAT_REPAIR_NO, EXFAT_REPAIR_ASK, EXFAT_REPAIR_YES } repair;
 };
 
 /* in-core nodes iterator */
@@ -135,6 +142,7 @@ struct exfat_human_bytes
 };
 
 extern int exfat_errors;
+extern int exfat_errors_fixed;
 
 void exfat_bug(const char* format, ...) PRINTF NORETURN;
 void exfat_error(const char* format, ...) PRINTF;
@@ -161,7 +169,7 @@ ssize_t exfat_generic_pwrite(struct exfat* ef, struct exfat_node* node,
 int exfat_opendir(struct exfat* ef, struct exfat_node* dir,
                struct exfat_iterator* it);
 void exfat_closedir(struct exfat* ef, struct exfat_iterator* it);
-struct exfat_node* exfat_readdir(struct exfat* ef, struct exfat_iterator* it);
+struct exfat_node* exfat_readdir(struct exfat_iterator* it);
 int exfat_lookup(struct exfat* ef, struct exfat_node** node,
                const char* path);
 int exfat_split(struct exfat* ef, struct exfat_node** parent,
@@ -185,8 +193,7 @@ void exfat_get_name(const struct exfat_node* node,
                char buffer[EXFAT_UTF8_NAME_BUFFER_MAX]);
 uint16_t exfat_start_checksum(const struct exfat_entry_meta1* entry);
 uint16_t exfat_add_checksum(const void* entry, uint16_t sum);
-le16_t exfat_calc_checksum(const struct exfat_entry_meta1* meta1,
-               const struct exfat_entry_meta2* meta2, const le16_t* name);
+le16_t exfat_calc_checksum(const struct exfat_entry* entries, int n);
 uint32_t exfat_vbr_start_checksum(const void* sector, size_t size);
 uint32_t exfat_vbr_add_checksum(const void* sector, size_t size, uint32_t sum);
 le16_t exfat_calc_name_hash(const struct exfat* ef, const le16_t* name,
@@ -226,4 +233,12 @@ void exfat_unix2exfat(time_t unix_time, le16_t* date, le16_t* time,
                uint8_t* centisec);
 void exfat_tzset(void);
 
+bool exfat_ask_to_fix(const struct exfat* ef);
+bool exfat_fix_invalid_vbr_checksum(const struct exfat* ef, void* sector,
+               uint32_t vbr_checksum);
+bool exfat_fix_invalid_node_checksum(const struct exfat* ef,
+               struct exfat_node* node);
+bool exfat_fix_unknown_entry(struct exfat* ef, struct exfat_node* dir,
+               const struct exfat_entry* entry, off_t offset);
+
 #endif /* ifndef EXFAT_H_INCLUDED */