X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fdrivers%2Fao_fat.h;h=39f4207bb1dc6e418a02769918b4c1c06bf75c2d;hp=5b9b300f51d53ebf402658f1e2ac4bb685e0ac35;hb=1085ec5d57e0ed5d132f2bbdac1a0b6a32c0ab4a;hpb=c7b606e93a4e4fbd2c0e883352ed74619ee24cf7 diff --git a/src/drivers/ao_fat.h b/src/drivers/ao_fat.h index 5b9b300f..39f4207b 100644 --- a/src/drivers/ao_fat.h +++ b/src/drivers/ao_fat.h @@ -3,7 +3,8 @@ * * 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 - * the Free Software Foundation; version 2 of the License. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -32,9 +33,10 @@ ao_fat_init(void); #define AO_FAT_DENT_EMPTY 0xe5 #define AO_FAT_DENT_END 0x00 -#define AO_FAT_IS_FILE(attr) (((attr) & (AO_FAT_FILE_VOLUME_LABEL|AO_FAT_FILE_DIRECTORY|AO_FAT_FILE_ARCHIVE)) == 0) -#define AO_FAT_IS_DIR(attr) (((attr) & (AO_FAT_FILE_DIRECTORY)) == AO_FAT_FILE_DIRECTORY) +#define AO_FAT_IS_FILE(attr) (((attr) & (AO_FAT_FILE_VOLUME_LABEL|AO_FAT_FILE_DIRECTORY)) == 0) +#define AO_FAT_IS_DIR(attr) (((attr) & (AO_FAT_FILE_DIRECTORY|AO_FAT_FILE_VOLUME_LABEL)) == AO_FAT_FILE_DIRECTORY) +/* API error codes */ #define AO_FAT_SUCCESS 0 #define AO_FAT_EPERM 1 #define AO_FAT_ENOENT 2 @@ -47,6 +49,27 @@ ao_fat_init(void); #define AO_FAT_EMFILE 24 #define AO_FAT_EFBIG 27 #define AO_FAT_ENOSPC 28 +#define AO_FAT_EDIREOF 29 + +/* ao_fat_setup return values */ +#define AO_FAT_FILESYSTEM_SUCCESS 0 +#define AO_FAT_FILESYSTEM_MBR_READ_FAILURE 1 +#define AO_FAT_FILESYSTEM_INVALID_MBR_SIGNATURE 2 +#define AO_FAT_FILESYSTEM_INVALID_PARTITION_TYPE 3 +#define AO_FAT_FILESYSTEM_ZERO_SIZED_PARTITION 4 + +#define AO_FAT_FILESYSTEM_BOOT_READ_FAILURE 5 +#define AO_FAT_FILESYSTEM_INVALID_BOOT_SIGNATURE 6 +#define AO_FAT_FILESYSTEM_INVALID_SECTOR_SIZE 7 + +void +ao_fat_sync(void); + +void +ao_fat_unmount(void); + +int8_t +ao_fat_full(void); int8_t ao_fat_open(char name[11], uint8_t mode); @@ -59,20 +82,20 @@ int8_t ao_fat_creat(char name[11]); int8_t -ao_fat_close(void); +ao_fat_close(int8_t fd); int -ao_fat_read(void *dest, int len); +ao_fat_read(int8_t fd, void *dest, int len); int -ao_fat_write(void *src, int len); +ao_fat_write(int8_t fd, void *src, int len); #define AO_FAT_SEEK_SET 0 #define AO_FAT_SEEK_CUR 1 #define AO_FAT_SEEK_END 2 int32_t -ao_fat_seek(int32_t pos, uint8_t whence); +ao_fat_seek(int8_t fd, int32_t pos, uint8_t whence); int8_t ao_fat_unlink(char name[11]); @@ -80,12 +103,37 @@ ao_fat_unlink(char name[11]); int8_t ao_fat_rename(char old[11], char new[11]); +/* + * Byte offset within a file. Supports files up to 2GB in size + */ +typedef int32_t ao_fat_offset_t; + +/* + * Cluster index in partition data space + */ +typedef uint32_t ao_fat_cluster_t; + +/* + * Sector offset within partition + */ +typedef uint32_t ao_fat_sector_t; + +/* + * Index within the root directory + */ +typedef uint16_t ao_fat_dirent_t; + +/* + * Offset within a cluster (or sector) + */ +typedef uint16_t ao_fat_cluster_offset_t; + struct ao_fat_dirent { - char name[11]; - uint8_t attr; - uint32_t size; - uint16_t cluster; - uint16_t entry; + char name[11]; + uint8_t attr; + uint32_t size; + ao_fat_cluster_t cluster; + uint16_t entry; }; int8_t