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