Björn Stenberg | d9eb5c7 | 2002-03-28 15:09:10 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2002 by Linus Nielsen Feltzing |
| 11 | * |
| 12 | * All files in this archive are subject to the GNU General Public License. |
| 13 | * See the file COPYING in the source tree root for full license agreement. |
| 14 | * |
| 15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 16 | * KIND, either express or implied. |
| 17 | * |
| 18 | ****************************************************************************/ |
| 19 | |
| 20 | #ifndef FAT_H |
| 21 | #define FAT_H |
| 22 | |
Björn Stenberg | b7b48fe | 2002-10-20 22:50:58 +0000 | [diff] [blame] | 23 | #include <stdbool.h> |
Jörg Hohensohn | da84857 | 2004-12-28 22:16:07 +0000 | [diff] [blame] | 24 | #include "ata.h" /* for volume definitions */ |
Miika Pekkarinen | ae66c2b | 2006-12-03 18:12:19 +0000 | [diff] [blame] | 25 | #include "config.h" |
Björn Stenberg | b7b48fe | 2002-10-20 22:50:58 +0000 | [diff] [blame] | 26 | |
Jens Arnold | ef3e129 | 2006-12-04 21:37:22 +0000 | [diff] [blame^] | 27 | #define SECTOR_SIZE 512 |
Björn Stenberg | 1dff4b6 | 2002-04-26 16:44:58 +0000 | [diff] [blame] | 28 | |
Rani Hod | 8630f07 | 2006-07-31 22:59:45 +0000 | [diff] [blame] | 29 | /* Number of bytes reserved for a file name (including the trailing \0). |
| 30 | Since names are stored in the entry as UTF-8, we won't be able to |
| 31 | store all names allowed by FAT. In FAT, a name can have max 255 |
| 32 | characters (not bytes!). Since the UTF-8 encoding of a char may take |
| 33 | up to 4 bytes, there will be names that we won't be able to store |
| 34 | completely. For such names, the short DOS name is used. */ |
| 35 | #define FAT_FILENAME_BYTES 256 |
| 36 | |
Björn Stenberg | 5661b23 | 2002-04-27 01:25:22 +0000 | [diff] [blame] | 37 | struct fat_direntry |
| 38 | { |
Rani Hod | 8630f07 | 2006-07-31 22:59:45 +0000 | [diff] [blame] | 39 | unsigned char name[FAT_FILENAME_BYTES]; /* UTF-8 encoded name plus \0 */ |
Björn Stenberg | 5661b23 | 2002-04-27 01:25:22 +0000 | [diff] [blame] | 40 | unsigned short attr; /* Attributes */ |
| 41 | unsigned char crttimetenth; /* Millisecond creation |
| 42 | time stamp (0-199) */ |
| 43 | unsigned short crttime; /* Creation time */ |
| 44 | unsigned short crtdate; /* Creation date */ |
| 45 | unsigned short lstaccdate; /* Last access date */ |
Björn Stenberg | 5661b23 | 2002-04-27 01:25:22 +0000 | [diff] [blame] | 46 | unsigned short wrttime; /* Last write time */ |
| 47 | unsigned short wrtdate; /* Last write date */ |
Jean-Philippe Bernardy | 36b8e13 | 2005-01-23 23:20:40 +0000 | [diff] [blame] | 48 | unsigned long filesize; /* File size in bytes */ |
| 49 | long firstcluster; /* fstclusterhi<<16 + fstcluslo */ |
Björn Stenberg | d9eb5c7 | 2002-03-28 15:09:10 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | #define FAT_ATTR_READ_ONLY 0x01 |
| 53 | #define FAT_ATTR_HIDDEN 0x02 |
| 54 | #define FAT_ATTR_SYSTEM 0x04 |
| 55 | #define FAT_ATTR_VOLUME_ID 0x08 |
| 56 | #define FAT_ATTR_DIRECTORY 0x10 |
| 57 | #define FAT_ATTR_ARCHIVE 0x20 |
Jörg Hohensohn | da84857 | 2004-12-28 22:16:07 +0000 | [diff] [blame] | 58 | #define FAT_ATTR_VOLUME 0x40 /* this is a volume, not a real directory */ |
Björn Stenberg | d9eb5c7 | 2002-03-28 15:09:10 +0000 | [diff] [blame] | 59 | |
Björn Stenberg | 924164e | 2002-05-03 15:35:51 +0000 | [diff] [blame] | 60 | struct fat_file |
Björn Stenberg | e8bcc01 | 2002-04-27 19:37:41 +0000 | [diff] [blame] | 61 | { |
Jean-Philippe Bernardy | 36b8e13 | 2005-01-23 23:20:40 +0000 | [diff] [blame] | 62 | long firstcluster; /* first cluster in file */ |
| 63 | long lastcluster; /* cluster of last access */ |
| 64 | long lastsector; /* sector of last access */ |
| 65 | long clusternum; /* current clusternum */ |
| 66 | long sectornum; /* sector number in this cluster */ |
Björn Stenberg | eee2c01 | 2002-11-18 11:58:43 +0000 | [diff] [blame] | 67 | unsigned int direntry; /* short dir entry index from start of dir */ |
| 68 | unsigned int direntries; /* number of dir entries used by this file */ |
Jean-Philippe Bernardy | 36b8e13 | 2005-01-23 23:20:40 +0000 | [diff] [blame] | 69 | long dircluster; /* first cluster of dir */ |
Björn Stenberg | 1f214f2 | 2002-11-13 23:16:32 +0000 | [diff] [blame] | 70 | bool eof; |
Jörg Hohensohn | da84857 | 2004-12-28 22:16:07 +0000 | [diff] [blame] | 71 | #ifdef HAVE_MULTIVOLUME |
Jens Arnold | 316ae18 | 2005-01-03 07:59:49 +0000 | [diff] [blame] | 72 | int volume; /* file resides on which volume */ |
Jörg Hohensohn | da84857 | 2004-12-28 22:16:07 +0000 | [diff] [blame] | 73 | #endif |
Björn Stenberg | d9eb5c7 | 2002-03-28 15:09:10 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
Björn Stenberg | a5e77d8 | 2002-10-31 16:09:28 +0000 | [diff] [blame] | 76 | struct fat_dir |
| 77 | { |
Björn Stenberg | c442a68 | 2002-11-15 11:20:33 +0000 | [diff] [blame] | 78 | unsigned int entry; |
Björn Stenberg | eee2c01 | 2002-11-18 11:58:43 +0000 | [diff] [blame] | 79 | unsigned int entrycount; |
Jean-Philippe Bernardy | fc19445 | 2005-02-25 18:50:16 +0000 | [diff] [blame] | 80 | long sector; |
Björn Stenberg | 1f214f2 | 2002-11-13 23:16:32 +0000 | [diff] [blame] | 81 | struct fat_file file; |
Jens Arnold | ef3e129 | 2006-12-04 21:37:22 +0000 | [diff] [blame^] | 82 | unsigned char sectorcache[3][SECTOR_SIZE]; |
Björn Stenberg | a5e77d8 | 2002-10-31 16:09:28 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | |
Jörg Hohensohn | da84857 | 2004-12-28 22:16:07 +0000 | [diff] [blame] | 86 | extern void fat_init(void); |
Jean-Philippe Bernardy | 36b8e13 | 2005-01-23 23:20:40 +0000 | [diff] [blame] | 87 | extern int fat_mount(IF_MV2(int volume,) IF_MV2(int drive,) long startsector); |
Jörg Hohensohn | 7414687 | 2005-01-05 00:09:04 +0000 | [diff] [blame] | 88 | extern int fat_unmount(int volume, bool flush); |
Jean-Philippe Bernardy | 36b8e13 | 2005-01-23 23:20:40 +0000 | [diff] [blame] | 89 | extern void fat_size(IF_MV2(int volume,) unsigned long* size, unsigned long* free); // public for info |
Jörg Hohensohn | da84857 | 2004-12-28 22:16:07 +0000 | [diff] [blame] | 90 | extern void fat_recalc_free(IF_MV_NONVOID(int volume)); // public for debug info screen |
Jens Arnold | 0ceaa5e | 2004-08-17 01:45:48 +0000 | [diff] [blame] | 91 | extern int fat_create_dir(const char* name, |
Linus Nielsen Feltzing | 60b1c4b | 2004-01-15 14:30:59 +0000 | [diff] [blame] | 92 | struct fat_dir* newdir, |
| 93 | struct fat_dir* dir); |
Jean-Philippe Bernardy | 36b8e13 | 2005-01-23 23:20:40 +0000 | [diff] [blame] | 94 | extern long fat_startsector(IF_MV_NONVOID(int volume)); // public for config sector |
Jörg Hohensohn | da84857 | 2004-12-28 22:16:07 +0000 | [diff] [blame] | 95 | extern int fat_open(IF_MV2(int volume,) |
Jean-Philippe Bernardy | 36b8e13 | 2005-01-23 23:20:40 +0000 | [diff] [blame] | 96 | long cluster, |
Björn Stenberg | b7b48fe | 2002-10-20 22:50:58 +0000 | [diff] [blame] | 97 | struct fat_file* ent, |
Jens Arnold | 0ceaa5e | 2004-08-17 01:45:48 +0000 | [diff] [blame] | 98 | const struct fat_dir* dir); |
| 99 | extern int fat_create_file(const char* name, |
Björn Stenberg | b7b48fe | 2002-10-20 22:50:58 +0000 | [diff] [blame] | 100 | struct fat_file* ent, |
| 101 | struct fat_dir* dir); |
Jean-Philippe Bernardy | 5da99ed | 2005-02-26 21:18:05 +0000 | [diff] [blame] | 102 | extern long fat_readwrite(struct fat_file *ent, long sectorcount, |
Björn Stenberg | b7b48fe | 2002-10-20 22:50:58 +0000 | [diff] [blame] | 103 | void* buf, bool write ); |
Jean-Philippe Bernardy | 36b8e13 | 2005-01-23 23:20:40 +0000 | [diff] [blame] | 104 | extern int fat_closewrite(struct fat_file *ent, long size, int attr); |
| 105 | extern int fat_seek(struct fat_file *ent, unsigned long sector ); |
Björn Stenberg | 46ddacf | 2002-10-22 15:06:08 +0000 | [diff] [blame] | 106 | extern int fat_remove(struct fat_file *ent); |
Jens Arnold | 0ceaa5e | 2004-08-17 01:45:48 +0000 | [diff] [blame] | 107 | extern int fat_truncate(const struct fat_file *ent); |
Björn Stenberg | c5f5be5 | 2002-11-19 12:48:50 +0000 | [diff] [blame] | 108 | extern int fat_rename(struct fat_file* file, |
Jens Arnold | 316ae18 | 2005-01-03 07:59:49 +0000 | [diff] [blame] | 109 | struct fat_dir* dir, |
Jens Arnold | 0ceaa5e | 2004-08-17 01:45:48 +0000 | [diff] [blame] | 110 | const unsigned char* newname, |
Jean-Philippe Bernardy | 36b8e13 | 2005-01-23 23:20:40 +0000 | [diff] [blame] | 111 | long size, int attr); |
Björn Stenberg | e8bcc01 | 2002-04-27 19:37:41 +0000 | [diff] [blame] | 112 | |
Jörg Hohensohn | da84857 | 2004-12-28 22:16:07 +0000 | [diff] [blame] | 113 | extern int fat_opendir(IF_MV2(int volume,) |
Jean-Philippe Bernardy | 36b8e13 | 2005-01-23 23:20:40 +0000 | [diff] [blame] | 114 | struct fat_dir *ent, unsigned long currdir, |
Jens Arnold | 0ceaa5e | 2004-08-17 01:45:48 +0000 | [diff] [blame] | 115 | const struct fat_dir *parent_dir); |
Björn Stenberg | 924164e | 2002-05-03 15:35:51 +0000 | [diff] [blame] | 116 | extern int fat_getnext(struct fat_dir *ent, struct fat_direntry *entry); |
Jean-Philippe Bernardy | 5da99ed | 2005-02-26 21:18:05 +0000 | [diff] [blame] | 117 | extern unsigned int fat_get_cluster_size(IF_MV_NONVOID(int volume)); |
Jörg Hohensohn | da84857 | 2004-12-28 22:16:07 +0000 | [diff] [blame] | 118 | extern bool fat_ismounted(int volume); |
Björn Stenberg | d9eb5c7 | 2002-03-28 15:09:10 +0000 | [diff] [blame] | 119 | |
| 120 | #endif |