diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2013-08-05 22:02:45 -0400 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2014-08-30 03:48:23 +0200 |
commit | 7d1a47cf13726c95ac46027156cc12dd9da5b855 (patch) | |
tree | eb20d07656806479a8e1fea25887a490ea30d1d8 /firmware/export | |
parent | 95a4c3afcd53a1f8b835dec33de51f9c304de4d9 (diff) | |
download | rockbox-7d1a47cf13726c95ac46027156cc12dd9da5b855.tar.gz rockbox-7d1a47cf13726c95ac46027156cc12dd9da5b855.zip |
Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.
Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.
Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.
Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.
2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.
3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.
4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.
Key core changes:
1) Files and directories share core code and data structures.
2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).
3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.
4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".
5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.
6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).
Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:
1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).
2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.
3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.
4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.
5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.
Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.
2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.
3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).
4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).
5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).
Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.
To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.
2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.
Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
Diffstat (limited to 'firmware/export')
-rw-r--r-- | firmware/export/config.h | 29 | ||||
-rw-r--r-- | firmware/export/config/gigabeats.h | 3 | ||||
-rw-r--r-- | firmware/export/disk.h | 13 | ||||
-rw-r--r-- | firmware/export/fat.h | 225 | ||||
-rw-r--r-- | firmware/export/filefuncs.h | 39 | ||||
-rw-r--r-- | firmware/export/hostfs.h | 25 | ||||
-rw-r--r-- | firmware/export/load_code.h | 10 | ||||
-rw-r--r-- | firmware/export/mv.h | 77 | ||||
-rw-r--r-- | firmware/export/pathfuncs.h | 100 | ||||
-rw-r--r-- | firmware/export/rbpaths.h | 21 | ||||
-rw-r--r-- | firmware/export/storage.h | 7 | ||||
-rw-r--r-- | firmware/export/system.h | 10 |
12 files changed, 379 insertions, 180 deletions
diff --git a/firmware/export/config.h b/firmware/export/config.h index 5e4178cd4c..2a1cdb3416 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h | |||
@@ -27,12 +27,21 @@ | |||
27 | /* symbolic names for multiple choice configurations: */ | 27 | /* symbolic names for multiple choice configurations: */ |
28 | 28 | ||
29 | /* CONFIG_STORAGE (note these are combineable bit-flags) */ | 29 | /* CONFIG_STORAGE (note these are combineable bit-flags) */ |
30 | #define STORAGE_ATA 0x01 | 30 | #define STORAGE_ATA_NUM 0 |
31 | #define STORAGE_MMC 0x02 | 31 | #define STORAGE_MMC_NUM 1 |
32 | #define STORAGE_SD 0x04 | 32 | #define STORAGE_SD_NUM 2 |
33 | #define STORAGE_NAND 0x08 | 33 | #define STORAGE_NAND_NUM 3 |
34 | #define STORAGE_RAMDISK 0x10 | 34 | #define STORAGE_RAMDISK_NUM 4 |
35 | #define STORAGE_HOSTFS 0x20 /* meant for APPLICATION targets (implicit for SIMULATOR) */ | 35 | #define STORAGE_HOSTFS_NUM 5 |
36 | #define STORAGE_NUM_TYPES 6 | ||
37 | |||
38 | #define STORAGE_ATA (1 << STORAGE_ATA_NUM) | ||
39 | #define STORAGE_MMC (1 << STORAGE_MMC_NUM) | ||
40 | #define STORAGE_SD (1 << STORAGE_SD_NUM) | ||
41 | #define STORAGE_NAND (1 << STORAGE_NAND_NUM) | ||
42 | #define STORAGE_RAMDISK (1 << STORAGE_RAMDISK_NUM) | ||
43 | /* meant for APPLICATION targets (implicit for SIMULATOR) */ | ||
44 | #define STORAGE_HOSTFS (1 << STORAGE_HOSTFS_NUM) | ||
36 | 45 | ||
37 | /* CONFIG_TUNER (note these are combineable bit-flags) */ | 46 | /* CONFIG_TUNER (note these are combineable bit-flags) */ |
38 | #define S1A0903X01 0x01 /* Samsung */ | 47 | #define S1A0903X01 0x01 /* Samsung */ |
@@ -573,6 +582,8 @@ Lyre prototype 1 */ | |||
573 | #ifdef __PCTOOL__ | 582 | #ifdef __PCTOOL__ |
574 | #undef CONFIG_CPU | 583 | #undef CONFIG_CPU |
575 | #define CONFIG_CPU 0 | 584 | #define CONFIG_CPU 0 |
585 | #undef HAVE_MULTIVOLUME | ||
586 | #undef HAVE_MULTIDRIVE | ||
576 | #endif | 587 | #endif |
577 | 588 | ||
578 | #ifdef APPLICATION | 589 | #ifdef APPLICATION |
@@ -831,9 +842,11 @@ Lyre prototype 1 */ | |||
831 | * plenty of RAM. Both features can be enabled independently. */ | 842 | * plenty of RAM. Both features can be enabled independently. */ |
832 | #if (MEMORYSIZE >= 8) && !defined(BOOTLOADER) && !defined(__PCTOOL__) \ | 843 | #if (MEMORYSIZE >= 8) && !defined(BOOTLOADER) && !defined(__PCTOOL__) \ |
833 | && !defined(APPLICATION) | 844 | && !defined(APPLICATION) |
845 | #ifndef SIMULATOR | ||
834 | #define HAVE_DIRCACHE | 846 | #define HAVE_DIRCACHE |
847 | #endif | ||
835 | #ifdef HAVE_TAGCACHE | 848 | #ifdef HAVE_TAGCACHE |
836 | #define HAVE_TC_RAMCACHE | 849 | //#define HAVE_TC_RAMCACHE |
837 | #endif | 850 | #endif |
838 | #endif | 851 | #endif |
839 | 852 | ||
@@ -1178,7 +1191,7 @@ Lyre prototype 1 */ | |||
1178 | /* This attribute can be used to enable to detection of plugin file handles leaks. | 1191 | /* This attribute can be used to enable to detection of plugin file handles leaks. |
1179 | * When enabled, the plugin core will monitor open/close/creat and when the plugin exits | 1192 | * When enabled, the plugin core will monitor open/close/creat and when the plugin exits |
1180 | * will display an error message if the plugin leaked some file handles */ | 1193 | * will display an error message if the plugin leaked some file handles */ |
1181 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) | 1194 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) || defined (SIMULATOR) |
1182 | #define HAVE_PLUGIN_CHECK_OPEN_CLOSE | 1195 | #define HAVE_PLUGIN_CHECK_OPEN_CLOSE |
1183 | #endif | 1196 | #endif |
1184 | 1197 | ||
diff --git a/firmware/export/config/gigabeats.h b/firmware/export/config/gigabeats.h index 11fc02be3d..6657134f9d 100644 --- a/firmware/export/config/gigabeats.h +++ b/firmware/export/config/gigabeats.h | |||
@@ -16,6 +16,9 @@ | |||
16 | /* define this if you use an ATA controller */ | 16 | /* define this if you use an ATA controller */ |
17 | #define CONFIG_STORAGE STORAGE_ATA | 17 | #define CONFIG_STORAGE STORAGE_ATA |
18 | 18 | ||
19 | /* For the Gigabeat S, we mount the second partition */ | ||
20 | #define CONFIG_DEFAULT_PARTNUM 1 | ||
21 | |||
19 | /*define this if the ATA controller and method of USB access support LBA48 */ | 22 | /*define this if the ATA controller and method of USB access support LBA48 */ |
20 | #define HAVE_LBA48 | 23 | #define HAVE_LBA48 |
21 | 24 | ||
diff --git a/firmware/export/disk.h b/firmware/export/disk.h index 8d6b41b5bd..c66028fe45 100644 --- a/firmware/export/disk.h +++ b/firmware/export/disk.h | |||
@@ -24,7 +24,8 @@ | |||
24 | #include "config.h" | 24 | #include "config.h" |
25 | #include "mv.h" /* for volume definitions */ | 25 | #include "mv.h" /* for volume definitions */ |
26 | 26 | ||
27 | struct partinfo { | 27 | struct partinfo |
28 | { | ||
28 | unsigned long start; /* first sector (LBA) */ | 29 | unsigned long start; /* first sector (LBA) */ |
29 | unsigned long size; /* number of sectors */ | 30 | unsigned long size; /* number of sectors */ |
30 | unsigned char type; | 31 | unsigned char type; |
@@ -35,11 +36,9 @@ struct partinfo { | |||
35 | #define PARTITION_TYPE_FAT16 0x06 | 36 | #define PARTITION_TYPE_FAT16 0x06 |
36 | #define PARTITION_TYPE_OS2_HIDDEN_C_DRIVE 0x84 | 37 | #define PARTITION_TYPE_OS2_HIDDEN_C_DRIVE 0x84 |
37 | 38 | ||
38 | /* returns a pointer to an array of 8 partinfo structs */ | 39 | bool disk_init(IF_MD_NONVOID(int drive)); |
39 | struct partinfo* disk_init(IF_MD_NONVOID(int drive)); | 40 | bool disk_partinfo(int partition, struct partinfo *info); |
40 | struct partinfo* disk_partinfo(int partition); | ||
41 | 41 | ||
42 | void disk_init_subsystem(void) INIT_ATTR; /* Initialises mutexes */ | ||
43 | int disk_mount_all(void); /* returns the # of successful mounts */ | 42 | int disk_mount_all(void); /* returns the # of successful mounts */ |
44 | int disk_mount(int drive); | 43 | int disk_mount(int drive); |
45 | int disk_unmount_all(void); | 44 | int disk_unmount_all(void); |
@@ -50,4 +49,6 @@ int disk_unmount(int drive); | |||
50 | int disk_get_sector_multiplier(IF_MD_NONVOID(int drive)); | 49 | int disk_get_sector_multiplier(IF_MD_NONVOID(int drive)); |
51 | #endif | 50 | #endif |
52 | 51 | ||
53 | #endif | 52 | bool disk_present(IF_MD_NONVOID(int drive)); |
53 | |||
54 | #endif /* _DISK_H_ */ | ||
diff --git a/firmware/export/fat.h b/firmware/export/fat.h index a0d52acc35..3aa1e254dc 100644 --- a/firmware/export/fat.h +++ b/firmware/export/fat.h | |||
@@ -18,123 +18,168 @@ | |||
18 | * KIND, either express or implied. | 18 | * KIND, either express or implied. |
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | |||
22 | #ifndef FAT_H | 21 | #ifndef FAT_H |
23 | #define FAT_H | 22 | #define FAT_H |
24 | 23 | ||
25 | #include <stdbool.h> | 24 | #include <stdbool.h> |
26 | #include "mv.h" /* for volume definitions */ | 25 | #include <sys/types.h> |
26 | #include <time.h> | ||
27 | #include "config.h" | 27 | #include "config.h" |
28 | #include "system.h" | 28 | #include "system.h" |
29 | #include "mv.h" /* for volume definitions */ | ||
30 | |||
31 | /******** | ||
32 | **** DO NOT use these functions directly unless otherwise noted. Required | ||
33 | **** synchronization is done by higher-level interfaces to minimize locking | ||
34 | **** overhead. | ||
35 | **** | ||
36 | **** Volume, drive, string, etc. parameters should also be checked by | ||
37 | **** callers for gross violations-- NULL strings, out-of-bounds values, | ||
38 | **** etc. | ||
39 | ****/ | ||
40 | |||
41 | /**************************************************************************** | ||
42 | ** Values that can be overridden by a target in config-[target].h | ||
43 | **/ | ||
44 | |||
45 | /* if your ATA implementation can do better, go right ahead and increase this | ||
46 | * value */ | ||
47 | #ifndef FAT_MAX_TRANSFER_SIZE | ||
48 | #define FAT_MAX_TRANSFER_SIZE 256 | ||
49 | #endif | ||
29 | 50 | ||
30 | /* This value can be overwritten by a target in config-[target].h, but | 51 | /* still experimental? */ |
31 | that behaviour is still experimental */ | 52 | /* increasing this will increase the total memory used by the cache; the |
53 | cache, as noted in disk_cache.h, has other minimum requirements that may | ||
54 | prevent reducing its number of entries in order to compensate */ | ||
32 | #ifndef SECTOR_SIZE | 55 | #ifndef SECTOR_SIZE |
33 | #define SECTOR_SIZE 512 | 56 | #define SECTOR_SIZE 512 |
34 | #endif | 57 | #endif |
35 | 58 | ||
59 | /** | ||
60 | ****************************************************************************/ | ||
61 | |||
62 | #define INVALID_SECNUM (0xfffffffeul) /* sequential, not FAT */ | ||
63 | #define FAT_MAX_FILE_SIZE (0xfffffffful) /* 2^32-1 bytes */ | ||
64 | #define MAX_DIRENTRIES 65536 | ||
65 | #define MAX_DIRECTORY_SIZE (MAX_DIRENTRIES*32) /* 2MB max size */ | ||
66 | |||
67 | /* these aren't I/O error conditions, so define specially; failure rc's | ||
68 | * shouldn't return the last digit as "0", therefore this is unambiguous */ | ||
69 | #define FAT_RC_ENOSPC (-10) | ||
70 | #define FAT_SEEK_EOF (-20) | ||
71 | |||
36 | /* Number of bytes reserved for a file name (including the trailing \0). | 72 | /* Number of bytes reserved for a file name (including the trailing \0). |
37 | Since names are stored in the entry as UTF-8, we won't be able to | 73 | Since names are stored in the entry as UTF-8, we won't be ble to |
38 | store all names allowed by FAT. In FAT, a name can have max 255 | 74 | store all names allowed by FAT. In FAT, a name can have max 255 |
39 | characters (not bytes!). Since the UTF-8 encoding of a char may take | 75 | characters (not bytes!). Since the UTF-8 encoding of a char may take |
40 | up to 4 bytes, there will be names that we won't be able to store | 76 | up to 4 bytes, there will be names that we won't be able to store |
41 | completely. For such names, the short DOS name is used. */ | 77 | completely. For such names, the short DOS name is used. */ |
42 | #define FAT_FILENAME_BYTES 256 | 78 | #define FAT_DIRENTRY_NAME_MAX 255 |
43 | |||
44 | struct fat_direntry | 79 | struct fat_direntry |
45 | { | 80 | { |
46 | unsigned char name[FAT_FILENAME_BYTES]; /* UTF-8 encoded name plus \0 */ | 81 | union { |
47 | unsigned short attr; /* Attributes */ | 82 | uint8_t name[255+1+4]; /* UTF-8 name plus \0 plus parse slop */ |
48 | unsigned char crttimetenth; /* Millisecond creation | 83 | uint16_t ucssegs[5+20][13]; /* UTF-16 segment buffer - layout saves... */ |
49 | time stamp (0-199) */ | 84 | }; /* ...130 bytes (important if stacked) */ |
50 | unsigned short crttime; /* Creation time */ | 85 | uint16_t ucsterm; /* allow one NULL-term after ucssegs */ |
51 | unsigned short crtdate; /* Creation date */ | 86 | uint8_t shortname[13]; /* DOS filename (OEM charset) */ |
52 | unsigned short lstaccdate; /* Last access date */ | 87 | uint8_t attr; /* file attributes */ |
53 | unsigned short wrttime; /* Last write time */ | 88 | uint8_t crttimetenth; /* millisecond creation time stamp (0-199) */ |
54 | unsigned short wrtdate; /* Last write date */ | 89 | uint16_t crttime; /* creation time */ |
55 | unsigned long filesize; /* File size in bytes */ | 90 | uint16_t crtdate; /* creation date */ |
56 | long firstcluster; /* fstclusterhi<<16 + fstcluslo */ | 91 | uint16_t lstaccdate; /* last access date */ |
92 | uint16_t wrttime; /* last write time */ | ||
93 | uint16_t wrtdate; /* last write date */ | ||
94 | uint32_t filesize; /* file size in bytes */ | ||
95 | int32_t firstcluster; /* first FAT cluster of file, 0 if empty */ | ||
57 | }; | 96 | }; |
58 | 97 | ||
59 | #define FAT_ATTR_READ_ONLY 0x01 | 98 | /* cursor structure used for scanning directories; holds the last-returned |
60 | #define FAT_ATTR_HIDDEN 0x02 | 99 | entry information */ |
61 | #define FAT_ATTR_SYSTEM 0x04 | 100 | struct fat_dirscan_info |
62 | #define FAT_ATTR_VOLUME_ID 0x08 | 101 | { |
63 | #define FAT_ATTR_DIRECTORY 0x10 | 102 | unsigned int entry; /* short dir entry index in parent */ |
64 | #define FAT_ATTR_ARCHIVE 0x20 | 103 | unsigned int entries; /* number of dir entries used */ |
65 | #define FAT_ATTR_VOLUME 0x40 /* this is a volume, not a real directory */ | 104 | }; |
105 | |||
106 | #define FAT_RW_VAL (0u - 1) | ||
66 | 107 | ||
108 | /* basic FAT file information about where to find a file and who houses it */ | ||
67 | struct fat_file | 109 | struct fat_file |
68 | { | 110 | { |
69 | long firstcluster; /* first cluster in file */ | ||
70 | long lastcluster; /* cluster of last access */ | ||
71 | long lastsector; /* sector of last access */ | ||
72 | long clusternum; /* current clusternum */ | ||
73 | long sectornum; /* sector number in this cluster */ | ||
74 | unsigned int direntry; /* short dir entry index from start of dir */ | ||
75 | unsigned int direntries; /* number of dir entries used by this file */ | ||
76 | long dircluster; /* first cluster of dir */ | ||
77 | bool eof; | ||
78 | #ifdef HAVE_MULTIVOLUME | 111 | #ifdef HAVE_MULTIVOLUME |
79 | int volume; /* file resides on which volume */ | 112 | int volume; /* file resides on which volume (first!) */ |
80 | #endif | 113 | #endif |
114 | long firstcluster; /* first cluster in file */ | ||
115 | long dircluster; /* first cluster of parent directory */ | ||
116 | struct fat_dirscan_info e; /* entry information */ | ||
81 | }; | 117 | }; |
82 | 118 | ||
83 | struct fat_dir | 119 | /* this stores what was last accessed when read or writing a file's data */ |
120 | struct fat_filestr | ||
84 | { | 121 | { |
85 | unsigned char sectorcache[SECTOR_SIZE] CACHEALIGN_ATTR; | 122 | struct fat_file *fatfilep; /* common file information */ |
86 | unsigned int entry; | 123 | long lastcluster; /* cluster of last access */ |
87 | unsigned int entrycount; | 124 | unsigned long lastsector; /* sector of last access */ |
88 | long sector; | 125 | long clusternum; /* cluster number of last access */ |
89 | struct fat_file file; | 126 | unsigned long sectornum; /* sector number within current cluster */ |
90 | /* There are 2-bytes per characters. We don't want to bother too much, as LFN entries are | 127 | bool eof; /* end-of-file reached */ |
91 | * at much 255 characters longs, that's at most 20 LFN entries. Each entry hold at most | 128 | }; |
92 | * 13 characters, that a total of 260 characters. So we keep a buffer of that size. | 129 | |
93 | * Keep coherent with fat.c code. */ | 130 | /** File entity functions **/ |
94 | unsigned char longname[260 * 2]; | 131 | int fat_create_file(struct fat_file *parent, const char *name, |
95 | } CACHEALIGN_ATTR; | 132 | uint8_t attr, struct fat_file *file, |
96 | 133 | struct fat_direntry *fatent); | |
97 | #ifdef HAVE_HOTSWAP | 134 | bool fat_dir_is_parent(const struct fat_file *dir, const struct fat_file *file); |
98 | extern void fat_lock(void); | 135 | bool fat_file_is_same(const struct fat_file *file1, const struct fat_file *file2); |
99 | extern void fat_unlock(void); | 136 | int fat_fstat(struct fat_file *file, struct fat_direntry *entry); |
100 | #endif | 137 | int fat_open(const struct fat_file *parent, long startcluster, |
138 | struct fat_file *file); | ||
139 | int fat_open_rootdir(IF_MV(int volume,) struct fat_file *dir); | ||
140 | enum fat_remove_op /* what should fat_remove(), remove? */ | ||
141 | { | ||
142 | FAT_RM_DIRENTRIES = 0x1, /* remove only directory entries */ | ||
143 | FAT_RM_DATA = 0x2, /* remove only file data */ | ||
144 | FAT_RM_ALL = 0x3, /* remove all of above */ | ||
145 | }; | ||
146 | int fat_remove(struct fat_file *file, enum fat_remove_op what); | ||
147 | int fat_rename(struct fat_file *parent, struct fat_file *file, | ||
148 | const unsigned char *newname); | ||
101 | 149 | ||
102 | extern void fat_init(void); | 150 | /** File stream functions **/ |
103 | extern int fat_get_bytes_per_sector(IF_MV_NONVOID(int volume)); | 151 | int fat_closewrite(struct fat_filestr *filestr, uint32_t size, |
104 | extern int fat_mount(IF_MV(int volume,) IF_MD(int drive,) long startsector); | 152 | struct fat_direntry *fatentp); |
105 | extern int fat_unmount(int volume, bool flush); | 153 | void fat_filestr_init(struct fat_filestr *filestr, struct fat_file *file); |
106 | extern void fat_size(IF_MV(int volume,) /* public for info */ | 154 | unsigned long fat_query_sectornum(const struct fat_filestr *filestr); |
107 | unsigned long* size, | 155 | long fat_readwrite(struct fat_filestr *filestr, unsigned long sectorcount, |
108 | unsigned long* free); | 156 | void *buf, bool write); |
109 | extern void fat_recalc_free(IF_MV_NONVOID(int volume)); /* public for debug info screen */ | 157 | void fat_rewind(struct fat_filestr *filestr); |
110 | extern int fat_create_dir(const char* name, | 158 | int fat_seek(struct fat_filestr *filestr, unsigned long sector); |
111 | struct fat_dir* newdir, | 159 | int fat_truncate(const struct fat_filestr *filestr); |
112 | struct fat_dir* dir); | ||
113 | extern int fat_open(IF_MV(int volume,) | ||
114 | long cluster, | ||
115 | struct fat_file* ent, | ||
116 | const struct fat_dir* dir); | ||
117 | extern int fat_create_file(const char* name, | ||
118 | struct fat_file* ent, | ||
119 | struct fat_dir* dir); | ||
120 | extern long fat_readwrite(struct fat_file *ent, long sectorcount, | ||
121 | void* buf, bool write ); | ||
122 | extern int fat_closewrite(struct fat_file *ent, long size, int attr); | ||
123 | extern int fat_seek(struct fat_file *ent, unsigned long sector ); | ||
124 | extern int fat_remove(struct fat_file *ent); | ||
125 | extern int fat_truncate(const struct fat_file *ent); | ||
126 | extern int fat_rename(struct fat_file* file, | ||
127 | struct fat_dir* dir, | ||
128 | const unsigned char* newname, | ||
129 | long size, int attr); | ||
130 | |||
131 | extern int fat_opendir(IF_MV(int volume,) | ||
132 | struct fat_dir *ent, unsigned long startcluster, | ||
133 | const struct fat_dir *parent_dir); | ||
134 | extern int fat_getnext(struct fat_dir *ent, struct fat_direntry *entry); | ||
135 | extern unsigned int fat_get_cluster_size(IF_MV_NONVOID(int volume)); /* public for debug info screen */ | ||
136 | extern bool fat_ismounted(int volume); | ||
137 | extern void* fat_get_sector_buffer(void); | ||
138 | extern void fat_release_sector_buffer(void); | ||
139 | 160 | ||
140 | #endif | 161 | /** Directory stream functions **/ |
162 | struct filestr_cache; | ||
163 | int fat_readdir(struct fat_filestr *dirstr, struct fat_dirscan_info *scan, | ||
164 | struct filestr_cache *cachep, struct fat_direntry *entry); | ||
165 | void fat_rewinddir(struct fat_dirscan_info *scan); | ||
166 | |||
167 | /** Mounting and unmounting functions **/ | ||
168 | bool fat_ismounted(IF_MV_NONVOID(int volume)); | ||
169 | int fat_mount(IF_MV(int volume,) IF_MD(int drive,) unsigned long startsector); | ||
170 | int fat_unmount(IF_MV_NONVOID(int volume)); | ||
171 | |||
172 | /** Debug screen stuff **/ | ||
173 | #ifdef MAX_LOG_SECTOR_SIZE | ||
174 | int fat_get_bytes_per_sector(IF_MV_NONVOID(int volume)); | ||
175 | #endif /* MAX_LOG_SECTOR_SIZE */ | ||
176 | unsigned int fat_get_cluster_size(IF_MV_NONVOID(int volume)); | ||
177 | void fat_recalc_free(IF_MV_NONVOID(int volume)); | ||
178 | bool fat_size(IF_MV(int volume,) unsigned long *size, unsigned long *free); | ||
179 | |||
180 | /** Misc. **/ | ||
181 | time_t fattime_mktime(uint16_t fatdate, uint16_t fattime); | ||
182 | void fat_empty_fat_direntry(struct fat_direntry *entry); | ||
183 | void fat_init(void); | ||
184 | |||
185 | #endif /* FAT_H */ | ||
diff --git a/firmware/export/filefuncs.h b/firmware/export/filefuncs.h deleted file mode 100644 index 92e97f65b0..0000000000 --- a/firmware/export/filefuncs.h +++ /dev/null | |||
@@ -1,39 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2009 by Maurus Cuelenaere | ||
11 | * | ||
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. | ||
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 __INCLUDE_FILEFUNCS_H_ | ||
23 | #define __INCLUDE_FILEFUNCS_H_ | ||
24 | |||
25 | #include <stdbool.h> | ||
26 | #include "config.h" | ||
27 | #include "file.h" | ||
28 | #include "dir.h" | ||
29 | |||
30 | #ifdef HAVE_MULTIVOLUME | ||
31 | int strip_volume(const char* name, char* namecopy); | ||
32 | #endif | ||
33 | |||
34 | bool file_exists(const char *file); | ||
35 | bool dir_exists(const char *path); | ||
36 | |||
37 | extern struct dirinfo dir_get_info(DIR* parent, struct dirent *entry); | ||
38 | |||
39 | #endif /* __INCLUDE_FILEFUNCS_H_ */ | ||
diff --git a/firmware/export/hostfs.h b/firmware/export/hostfs.h index bbadecec31..a24d009ca9 100644 --- a/firmware/export/hostfs.h +++ b/firmware/export/hostfs.h | |||
@@ -41,4 +41,29 @@ extern bool hostfs_removable(int drive); | |||
41 | extern bool hostfs_present(int drive); | 41 | extern bool hostfs_present(int drive); |
42 | #endif | 42 | #endif |
43 | 43 | ||
44 | /* This has to be repeated here for now for sim's sake since HAVE_HOSTFS | ||
45 | eats all the other stuff in storage.h. The sim probably shouldn't use | ||
46 | this. */ | ||
47 | #ifdef CONFIG_STORAGE_MULTI | ||
48 | extern int hostfs_driver_type(int drive); | ||
49 | #else | ||
50 | # ifdef APPLICATION | ||
51 | # define hostfs_driver_type(drive) (STORAGE_HOSTFS_NUM) | ||
52 | # else /* !APPLICATION */ | ||
53 | # if (CONFIG_STORAGE & STORAGE_ATA) | ||
54 | # define hostfs_driver_type(drive) (STORAGE_ATA_NUM) | ||
55 | # elif (CONFIG_STORAGE & STORAGE_SD) | ||
56 | # define hostfs_driver_type(drive) (STORAGE_SD_NUM) | ||
57 | # elif (CONFIG_STORAGE & STORAGE_MMC) | ||
58 | # define hostfs_driver_type(drive) (STORAGE_MMC_NUM) | ||
59 | # elif (CONFIG_STORAGE & STORAGE_NAND) | ||
60 | # define hostfs_driver_type(drive) (STORAGE_NAND_NUM) | ||
61 | # elif (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
62 | # define hostfs_driver_type(drive) (STORAGE_RAMDISK_NUM) | ||
63 | # else | ||
64 | # error Unknown storage driver | ||
65 | # endif /* CONFIG_STORAGE */ | ||
66 | # endif /* APPLICATION */ | ||
67 | #endif /* CONFIG_STORAGE_MULTI */ | ||
68 | |||
44 | #endif /* HOSTFS_H */ | 69 | #endif /* HOSTFS_H */ |
diff --git a/firmware/export/load_code.h b/firmware/export/load_code.h index cca577044e..df85a81f82 100644 --- a/firmware/export/load_code.h +++ b/firmware/export/load_code.h | |||
@@ -45,7 +45,17 @@ static inline void lc_close(void *handle) { (void)handle; } | |||
45 | 45 | ||
46 | #elif (CONFIG_PLATFORM & PLATFORM_HOSTED) | 46 | #elif (CONFIG_PLATFORM & PLATFORM_HOSTED) |
47 | 47 | ||
48 | #ifdef APPLICATION | ||
49 | /* App doesn't simulate code loading from a buffer */ | ||
50 | static inline void * lc_open_from_mem(void *addr, size_t blob_size) | ||
51 | { | ||
52 | return NULL; | ||
53 | (void)addr; (void)blob_size; | ||
54 | } | ||
55 | #else | ||
48 | extern void *lc_open_from_mem(void* addr, size_t blob_size); | 56 | extern void *lc_open_from_mem(void* addr, size_t blob_size); |
57 | #endif | ||
58 | |||
49 | extern void *lc_get_header(void *handle); | 59 | extern void *lc_get_header(void *handle); |
50 | extern void lc_close(void *handle); | 60 | extern void lc_close(void *handle); |
51 | 61 | ||
diff --git a/firmware/export/mv.h b/firmware/export/mv.h index 1d0a536663..620d77d30d 100644 --- a/firmware/export/mv.h +++ b/firmware/export/mv.h | |||
@@ -45,23 +45,44 @@ | |||
45 | #define IF_MV(x...) x /* valist contents or empty */ | 45 | #define IF_MV(x...) x /* valist contents or empty */ |
46 | #define IF_MV_NONVOID(x...) x /* valist contents or 'void' */ | 46 | #define IF_MV_NONVOID(x...) x /* valist contents or 'void' */ |
47 | #define IF_MV_VOL(v) v /* volume argument or '0' */ | 47 | #define IF_MV_VOL(v) v /* volume argument or '0' */ |
48 | /* how to name volumes, first char must be outside of legal file names, | ||
49 | a number gets appended to enumerate, if applicable */ | ||
50 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
51 | #define VOL_NAMES "<MMC%d>" | ||
52 | #define VOL_ENUM_POS 4 /* position of %d, to avoid runtime calculation */ | ||
53 | #elif (CONFIG_STORAGE & STORAGE_SD) | ||
54 | #define VOL_NAMES "<microSD%d>" | ||
55 | #define VOL_ENUM_POS 8 /* position of %d, to avoid runtime calculation */ | ||
56 | #else | ||
57 | #define VOL_NAMES "<HD%d>" | ||
58 | #define VOL_ENUM_POS 3 | ||
59 | #endif /* CONFIG_STORAGE */ | ||
60 | 48 | ||
61 | #ifdef HAVE_HOTSWAP | 49 | /* Format: "/<DEC###>/foo/bar" |
62 | bool volume_removable(int volume); | 50 | * The "DEC" is pure decoration and treated as a comment. Only an unbroken |
63 | bool volume_present(int volume); | 51 | * trailing string of digits within the brackets is parsed as the volume |
52 | * number. | ||
53 | * | ||
54 | * IMPORTANT!: Adjust VOL_DEC_MAX_LEN if needed to the longest of these | ||
55 | */ | ||
56 | #define DEFAULT_VOL_DEC "Volume" | ||
57 | |||
58 | #if (CONFIG_STORAGE & STORAGE_ATA) | ||
59 | #define ATA_VOL_DEC "HDD" | ||
60 | #endif | ||
61 | #if (CONFIG_STORAGE & STORAGE_MMC) | ||
62 | #define MMC_VOL_DEC "MMC" | ||
63 | #endif | ||
64 | #if (CONFIG_STORAGE & STORAGE_SD) | ||
65 | #define SD_VOL_DEC "microSD" | ||
66 | #endif | ||
67 | #if (CONFIG_STORAGE & STORAGE_NAND) | ||
68 | #define NAND_VOL_DEC "NAND" | ||
69 | #endif | ||
70 | #if (CONFIG_STORAGE & STORAGE_RAMDISK) | ||
71 | #define RAMDISK_VOL_DEC "RAMDisk" | ||
72 | #endif | ||
73 | #if (CONFIG_STORAGE & STORAGE_HOSTFS) | ||
74 | #ifndef HOSTFS_VOL_DEC /* overridable */ | ||
75 | #define HOSTFS_VOL_DEC DEFAULT_VOL_DEC | ||
64 | #endif | 76 | #endif |
77 | #endif | ||
78 | |||
79 | /* Characters that delimit a volume specifier at any root point in the path. | ||
80 | The tokens must be outside of legal filename characters */ | ||
81 | #define VOL_START_TOK '<' | ||
82 | #define VOL_END_TOK '>' | ||
83 | #define VOL_DEC_MAX_LEN 7 /* biggest of all xxx_VOL_DEC defines */ | ||
84 | #define VOL_MAX_LEN (1 + VOL_DEC_MAX_LEN + 2 + 1) | ||
85 | #define VOL_NUM_MAX 100 | ||
65 | 86 | ||
66 | #else /* empty definitions if no multi-volume */ | 87 | #else /* empty definitions if no multi-volume */ |
67 | #define IF_MV(x...) | 88 | #define IF_MV(x...) |
@@ -69,4 +90,30 @@ bool volume_present(int volume); | |||
69 | #define IF_MV_VOL(v) 0 | 90 | #define IF_MV_VOL(v) 0 |
70 | #endif /* HAVE_MULTIVOLUME */ | 91 | #endif /* HAVE_MULTIVOLUME */ |
71 | 92 | ||
93 | #define CHECK_VOL(volume) \ | ||
94 | ((unsigned int)IF_MV_VOL(volume) < NUM_VOLUMES) | ||
95 | |||
96 | #define CHECK_DRV(drive) \ | ||
97 | ((unsigned int)IF_MD_DRV(drive) < NUM_DRIVES) | ||
98 | |||
99 | /* Volume-centric functions (in disk.c) */ | ||
100 | void volume_recalc_free(IF_MV_NONVOID(int volume)); | ||
101 | unsigned int volume_get_cluster_size(IF_MV_NONVOID(int volume)); | ||
102 | void volume_size(IF_MV(int volume,) unsigned long *size, unsigned long *free); | ||
103 | bool volume_ismounted(IF_MV_NONVOID(int volume)); | ||
104 | #ifdef HAVE_HOTSWAP | ||
105 | bool volume_removable(int volume); | ||
106 | bool volume_present(int volume); | ||
107 | #endif /* HAVE_HOTSWAP */ | ||
108 | |||
109 | #ifdef HAVE_MULTIDRIVE | ||
110 | int volume_drive(int volume); | ||
111 | #else /* !HAVE_MULTIDRIVE */ | ||
112 | static inline int volume_drive(int volume) | ||
113 | { | ||
114 | return 0; | ||
115 | (void)volume; | ||
116 | } | ||
117 | #endif /* HAVE_MULTIDRIVE */ | ||
118 | |||
72 | #endif /* __MV_H__ */ | 119 | #endif /* __MV_H__ */ |
diff --git a/firmware/export/pathfuncs.h b/firmware/export/pathfuncs.h new file mode 100644 index 0000000000..26eb4a1067 --- /dev/null +++ b/firmware/export/pathfuncs.h | |||
@@ -0,0 +1,100 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2014 by Michael Sevakis | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #ifndef _PATHFUNCS_H_ | ||
22 | #define _PATHFUNCS_H_ | ||
23 | |||
24 | #include <sys/types.h> | ||
25 | #define __need_size_t | ||
26 | #include <stddef.h> | ||
27 | #include <stdbool.h> | ||
28 | #include "config.h" | ||
29 | |||
30 | /* useful char constants that could be reconfigured if desired */ | ||
31 | #define PATH_SEPCH '/' | ||
32 | #define PATH_SEPSTR "/" | ||
33 | #define PATH_ROOTSTR "/" | ||
34 | #define PATH_BADSEPCH '\\' | ||
35 | #define PATH_DRVSEPCH ':' | ||
36 | |||
37 | /* a nicer way to check for "." and ".." than two strcmp() calls */ | ||
38 | static inline bool is_dotdir_name(const char *name) | ||
39 | { | ||
40 | return name[0] == '.' && (!name[1] || (name[1] == '.' && !name[2])); | ||
41 | } | ||
42 | |||
43 | static inline bool name_is_dot(const char *name) | ||
44 | { | ||
45 | return name[0] == '.' && !name[1]; | ||
46 | } | ||
47 | |||
48 | static inline bool name_is_dot_dot(const char *name) | ||
49 | { | ||
50 | return name[0] == '.' && name[1] == '.' && !name[2]; | ||
51 | } | ||
52 | |||
53 | /* return a pointer to the character following path separators */ | ||
54 | #define GOBBLE_PATH_SEPCH(p) \ | ||
55 | ({ int _c; \ | ||
56 | const char *_p = (p); \ | ||
57 | while ((_c = *_p) == PATH_SEPCH) \ | ||
58 | ++_p; \ | ||
59 | _p; }) | ||
60 | |||
61 | /* return a pointer to the character following a path component which may | ||
62 | be a separator or the terminating nul */ | ||
63 | #define GOBBLE_PATH_COMP(p) \ | ||
64 | ({ int _c; \ | ||
65 | const char *_p = (p); \ | ||
66 | while ((_c = *_p) && _c != PATH_SEPCH) \ | ||
67 | ++_p; \ | ||
68 | _p; }) | ||
69 | |||
70 | /* does the character terminate a path component? */ | ||
71 | #define IS_COMP_TERMINATOR(c) \ | ||
72 | ({ int _c = (c); \ | ||
73 | !_c || _c == PATH_SEPCH; }) | ||
74 | |||
75 | #ifdef HAVE_MULTIVOLUME | ||
76 | int path_strip_volume(const char *name, const char **nameptr, bool greedy); | ||
77 | int get_volume_name(int volume, char *name); | ||
78 | #endif | ||
79 | |||
80 | int path_strip_drive(const char *name, const char **nameptr, bool greedy); | ||
81 | size_t path_trim_whitespace(const char *name, const char **nameptr); | ||
82 | size_t path_basename(const char *name, const char **nameptr); | ||
83 | size_t path_dirname(const char *name, const char **nameptr); | ||
84 | size_t path_strip_trailing_separators(const char *name, const char **nameptr); | ||
85 | void path_correct_separators(char *dstpath, const char *path); | ||
86 | |||
87 | /* constants useable in basepath and component */ | ||
88 | #define PA_SEP_HARD NULL /* separate even if base is empty */ | ||
89 | #define PA_SEP_SOFT "" /* separate only if base is nonempty */ | ||
90 | size_t path_append(char *buffer, const char *basepath, const char *component, | ||
91 | size_t bufsize); | ||
92 | ssize_t parse_path_component(const char **pathp, const char **namep); | ||
93 | |||
94 | /* return true if path begins with a root '/' component and is not NULL */ | ||
95 | static inline bool path_is_absolute(const char *path) | ||
96 | { | ||
97 | return path && path[0] == PATH_SEPCH; | ||
98 | } | ||
99 | |||
100 | #endif /* _PATHFUNCS_H_ */ | ||
diff --git a/firmware/export/rbpaths.h b/firmware/export/rbpaths.h index 3600709482..b04d669716 100644 --- a/firmware/export/rbpaths.h +++ b/firmware/export/rbpaths.h | |||
@@ -70,27 +70,6 @@ | |||
70 | 70 | ||
71 | #define HOME_DIR_LEN (sizeof(HOME_DIR)-1) | 71 | #define HOME_DIR_LEN (sizeof(HOME_DIR)-1) |
72 | 72 | ||
73 | #ifdef APPLICATION | ||
74 | |||
75 | #include <dirent.h> | ||
76 | #include <fcntl.h> | ||
77 | #include <unistd.h> | ||
78 | |||
79 | int app_open(const char *name, int o, ...); | ||
80 | int app_creat(const char* name, mode_t mode); | ||
81 | int app_remove(const char *name); | ||
82 | int app_rename(const char *old, const char *new); | ||
83 | DIR* app_opendir(const char *_name); | ||
84 | int app_closedir(DIR *dir); | ||
85 | struct dirent* app_readdir(DIR* dir); | ||
86 | int app_mkdir(const char* name); | ||
87 | int app_rmdir(const char* name); | ||
88 | ssize_t app_readlink(const char *path, char *buf, size_t bufsiz); | ||
89 | |||
90 | extern void paths_init(void); | ||
91 | |||
92 | #endif | ||
93 | |||
94 | #define REC_BASE_DIR HOME_DIR | 73 | #define REC_BASE_DIR HOME_DIR |
95 | #define PLAYLIST_CATALOG_DEFAULT_DIR HOME_DIR "/Playlists" | 74 | #define PLAYLIST_CATALOG_DEFAULT_DIR HOME_DIR "/Playlists" |
96 | 75 | ||
diff --git a/firmware/export/storage.h b/firmware/export/storage.h index 8e7281d523..14cba09b35 100644 --- a/firmware/export/storage.h +++ b/firmware/export/storage.h | |||
@@ -93,6 +93,7 @@ static inline void stub_storage_spindown(int timeout) { (void)timeout; } | |||
93 | #define storage_removable(drive) hostfs_removable(IF_MD(drive)) | 93 | #define storage_removable(drive) hostfs_removable(IF_MD(drive)) |
94 | #define storage_present(drive) hostfs_present(IF_MD(drive)) | 94 | #define storage_present(drive) hostfs_present(IF_MD(drive)) |
95 | #endif | 95 | #endif |
96 | #define storage_driver_type(drive) hostfs_driver_type(IF_MV(drive)) | ||
96 | #elif (CONFIG_STORAGE & STORAGE_ATA) | 97 | #elif (CONFIG_STORAGE & STORAGE_ATA) |
97 | #define STORAGE_FUNCTION(NAME) (ata_## NAME) | 98 | #define STORAGE_FUNCTION(NAME) (ata_## NAME) |
98 | #define storage_spindown ata_spindown | 99 | #define storage_spindown ata_spindown |
@@ -119,6 +120,7 @@ static inline void stub_storage_spindown(int timeout) { (void)timeout; } | |||
119 | #define storage_removable(drive) ata_removable(IF_MD(drive)) | 120 | #define storage_removable(drive) ata_removable(IF_MD(drive)) |
120 | #define storage_present(drive) ata_present(IF_MD(drive)) | 121 | #define storage_present(drive) ata_present(IF_MD(drive)) |
121 | #endif | 122 | #endif |
123 | #define storage_driver_type(drive) (STORAGE_ATA_NUM) | ||
122 | #elif (CONFIG_STORAGE & STORAGE_SD) | 124 | #elif (CONFIG_STORAGE & STORAGE_SD) |
123 | #define STORAGE_FUNCTION(NAME) (sd_## NAME) | 125 | #define STORAGE_FUNCTION(NAME) (sd_## NAME) |
124 | #define storage_spindown sd_spindown | 126 | #define storage_spindown sd_spindown |
@@ -145,6 +147,7 @@ static inline void stub_storage_spindown(int timeout) { (void)timeout; } | |||
145 | #define storage_removable(drive) sd_removable(IF_MD(drive)) | 147 | #define storage_removable(drive) sd_removable(IF_MD(drive)) |
146 | #define storage_present(drive) sd_present(IF_MD(drive)) | 148 | #define storage_present(drive) sd_present(IF_MD(drive)) |
147 | #endif | 149 | #endif |
150 | #define storage_driver_type(drive) (STORAGE_SD_NUM) | ||
148 | #elif (CONFIG_STORAGE & STORAGE_MMC) | 151 | #elif (CONFIG_STORAGE & STORAGE_MMC) |
149 | #define STORAGE_FUNCTION(NAME) (mmc_## NAME) | 152 | #define STORAGE_FUNCTION(NAME) (mmc_## NAME) |
150 | #define storage_spindown mmc_spindown | 153 | #define storage_spindown mmc_spindown |
@@ -170,6 +173,7 @@ static inline void stub_storage_spindown(int timeout) { (void)timeout; } | |||
170 | #define storage_removable(drive) mmc_removable(IF_MD(drive)) | 173 | #define storage_removable(drive) mmc_removable(IF_MD(drive)) |
171 | #define storage_present(drive) mmc_present(IF_MD(drive)) | 174 | #define storage_present(drive) mmc_present(IF_MD(drive)) |
172 | #endif | 175 | #endif |
176 | #define storage_driver_type(drive) (STORAGE_MMC_NUM) | ||
173 | #elif (CONFIG_STORAGE & STORAGE_NAND) | 177 | #elif (CONFIG_STORAGE & STORAGE_NAND) |
174 | #define STORAGE_FUNCTION(NAME) (nand_## NAME) | 178 | #define STORAGE_FUNCTION(NAME) (nand_## NAME) |
175 | #define storage_spindown nand_spindown | 179 | #define storage_spindown nand_spindown |
@@ -195,6 +199,7 @@ static inline void stub_storage_spindown(int timeout) { (void)timeout; } | |||
195 | #define storage_removable(drive) nand_removable(IF_MD(drive)) | 199 | #define storage_removable(drive) nand_removable(IF_MD(drive)) |
196 | #define storage_present(drive) nand_present(IF_MD(drive)) | 200 | #define storage_present(drive) nand_present(IF_MD(drive)) |
197 | #endif | 201 | #endif |
202 | #define storage_driver_type(drive) (STORAGE_NAND_NUM) | ||
198 | #elif (CONFIG_STORAGE & STORAGE_RAMDISK) | 203 | #elif (CONFIG_STORAGE & STORAGE_RAMDISK) |
199 | #define STORAGE_FUNCTION(NAME) (ramdisk_## NAME) | 204 | #define STORAGE_FUNCTION(NAME) (ramdisk_## NAME) |
200 | #define storage_spindown ramdisk_spindown | 205 | #define storage_spindown ramdisk_spindown |
@@ -220,6 +225,7 @@ static inline void stub_storage_spindown(int timeout) { (void)timeout; } | |||
220 | #define storage_removable(drive) ramdisk_removable(IF_MD(drive)) | 225 | #define storage_removable(drive) ramdisk_removable(IF_MD(drive)) |
221 | #define storage_present(drive) ramdisk_present(IF_MD(drive)) | 226 | #define storage_present(drive) ramdisk_present(IF_MD(drive)) |
222 | #endif | 227 | #endif |
228 | #define storage_driver_type(drive) (STORAGE_RAMDISK_NUM) | ||
223 | #else | 229 | #else |
224 | //#error No storage driver! | 230 | //#error No storage driver! |
225 | #endif | 231 | #endif |
@@ -246,6 +252,7 @@ void storage_get_info(int drive, struct storage_info *info); | |||
246 | bool storage_removable(int drive); | 252 | bool storage_removable(int drive); |
247 | bool storage_present(int drive); | 253 | bool storage_present(int drive); |
248 | #endif | 254 | #endif |
255 | int storage_driver_type(int drive); | ||
249 | 256 | ||
250 | #endif /* NOT CONFIG_STORAGE_MULTI and NOT SIMULATOR*/ | 257 | #endif /* NOT CONFIG_STORAGE_MULTI and NOT SIMULATOR*/ |
251 | 258 | ||
diff --git a/firmware/export/system.h b/firmware/export/system.h index 4442eb96d7..47dd858d81 100644 --- a/firmware/export/system.h +++ b/firmware/export/system.h | |||
@@ -104,6 +104,10 @@ int get_cpu_boost_counter(void); | |||
104 | /* return number of elements in array a */ | 104 | /* return number of elements in array a */ |
105 | #define ARRAYLEN(a) (sizeof(a)/sizeof((a)[0])) | 105 | #define ARRAYLEN(a) (sizeof(a)/sizeof((a)[0])) |
106 | 106 | ||
107 | /* is the given pointer "p" inside the said bounds of array "a"? */ | ||
108 | #define PTR_IN_ARRAY(a, p, numelem) \ | ||
109 | ((uintptr_t)(p) - (uintptr_t)(a) < (uintptr_t)(numelem)*sizeof ((a)[0])) | ||
110 | |||
107 | /* return p incremented by specified number of bytes */ | 111 | /* return p incremented by specified number of bytes */ |
108 | #define SKIPBYTES(p, count) ((typeof (p))((char *)(p) + (count))) | 112 | #define SKIPBYTES(p, count) ((typeof (p))((char *)(p) + (count))) |
109 | 113 | ||
@@ -188,9 +192,13 @@ enum { | |||
188 | #include "system-target.h" | 192 | #include "system-target.h" |
189 | #elif defined(HAVE_SDL) /* SDL build */ | 193 | #elif defined(HAVE_SDL) /* SDL build */ |
190 | #include "system-sdl.h" | 194 | #include "system-sdl.h" |
195 | #ifdef SIMULATOR | ||
196 | #include "system-sim.h" | ||
197 | #endif | ||
191 | #elif defined(__PCTOOL__) | 198 | #elif defined(__PCTOOL__) |
192 | #include "system-sdl.h" | 199 | #include "system-hosted.h" |
193 | #endif | 200 | #endif |
201 | |||
194 | #include "bitswap.h" | 202 | #include "bitswap.h" |
195 | #include "rbendian.h" | 203 | #include "rbendian.h" |
196 | 204 | ||