summaryrefslogtreecommitdiffstats
path: root/src/fat_common.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2013-11-01 13:42:51 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2013-11-01 13:42:51 +0100
commitb58be737f078928b6e1dc3cabc77bec20b059ece (patch)
treefff7ad10fc6993a247d4b9d2cc88d00c466ed8de /src/fat_common.c
parent0bf23249bb4ea2bf930148bfd59a13342cdedd76 (diff)
new functions is_fat_directory() and fat_get_cluster_from_entry()
rename sectors() to fat_sectors()
Diffstat (limited to 'src/fat_common.c')
-rw-r--r--src/fat_common.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/fat_common.c b/src/fat_common.c
index e6a6bee..ab1f181 100644
--- a/src/fat_common.c
+++ b/src/fat_common.c
@@ -23,9 +23,13 @@
#include <config.h>
#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
#include "types.h"
#include "common.h"
#include "fat.h"
+#include "fat_common.h"
unsigned int fat_sector_size(const struct fat_boot_sector *fat_header)
{ return (fat_header->sector_size[1]<<8)+fat_header->sector_size[0]; }
@@ -33,6 +37,19 @@ unsigned int fat_sector_size(const struct fat_boot_sector *fat_header)
unsigned int get_dir_entries(const struct fat_boot_sector *fat_header)
{ return (fat_header->dir_entries[1]<<8)+fat_header->dir_entries[0]; }
-unsigned int sectors(const struct fat_boot_sector *fat_header)
+unsigned int fat_sectors(const struct fat_boot_sector *fat_header)
{ return (fat_header->sectors[1]<<8)+fat_header->sectors[0]; }
+unsigned int fat_get_cluster_from_entry(const struct msdos_dir_entry *entry)
+{
+ return (((unsigned long int)le16(entry->starthi))<<16) | le16(entry->start);
+}
+
+int is_fat_directory(const unsigned char *buffer)
+{
+ return(buffer[0]=='.' &&
+ memcmp(buffer, ". ", 8+3)==0 &&
+ memcmp(&buffer[0x20], ".. ", 8+3)==0 &&
+ buffer[0xB]!=ATTR_EXT && (buffer[0xB]&ATTR_DIR)!=0 &&
+ buffer[1*0x20+0xB]!=ATTR_EXT && (buffer[1*0x20+0xB]&ATTR_DIR)!=0);
+}