diff --git a/apps/debug_menu.c b/apps/debug_menu.c index d761b9f868..08fc6e0da4 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -63,7 +63,7 @@ #include "usb.h" #include "rtc.h" #include "storage.h" -#include "fat.h" +#include "fs_defines.h" #include "eeprom_24cxx.h" #if (CONFIG_STORAGE & STORAGE_MMC) || (CONFIG_STORAGE & STORAGE_SD) #include "sdmmc.h" diff --git a/bootloader/gigabeat.c b/bootloader/gigabeat.c index a79454b81d..005d33630f 100644 --- a/bootloader/gigabeat.c +++ b/bootloader/gigabeat.c @@ -29,7 +29,6 @@ #include "lcd.h" #include "../kernel-internal.h" #include "storage.h" -#include "fat.h" #include "file_internal.h" #include "disk.h" #include "font.h" diff --git a/bootloader/ipod.c b/bootloader/ipod.c index 8580886ce4..8e5bd08a42 100644 --- a/bootloader/ipod.c +++ b/bootloader/ipod.c @@ -32,7 +32,6 @@ #include "lcd.h" #include "../kernel-internal.h" #include "ata.h" -#include "fat.h" #include "file_internal.h" #include "disk.h" #include "font.h" diff --git a/bootloader/ipod6g.c b/bootloader/ipod6g.c index 0ab9444578..0d0a4c53d1 100644 --- a/bootloader/ipod6g.c +++ b/bootloader/ipod6g.c @@ -32,7 +32,6 @@ #include "../kernel-internal.h" #include "file_internal.h" #include "storage.h" -#include "fat.h" #include "disk.h" #include "font.h" #include "backlight.h" diff --git a/bootloader/ipodnano2g.c b/bootloader/ipodnano2g.c index d0a8e0206c..85bb2df86d 100644 --- a/bootloader/ipodnano2g.c +++ b/bootloader/ipodnano2g.c @@ -34,7 +34,6 @@ #include "../kernel-internal.h" #include "file_internal.h" #include "storage.h" -#include "fat.h" #include "disk.h" #include "font.h" #include "backlight.h" diff --git a/bootloader/meizu_m3.c b/bootloader/meizu_m3.c index cefb186ef4..61308349f6 100644 --- a/bootloader/meizu_m3.c +++ b/bootloader/meizu_m3.c @@ -32,7 +32,6 @@ #include "lcd.h" #include "../kernel-internal.h" #include "storage.h" -#include "fat.h" #include "disk.h" #include "font.h" #include "backlight.h" diff --git a/bootloader/meizu_m6sl.c b/bootloader/meizu_m6sl.c index c230ec3c08..073c57cb0d 100644 --- a/bootloader/meizu_m6sl.c +++ b/bootloader/meizu_m6sl.c @@ -30,7 +30,6 @@ #include "kernel.h" #include "thread.h" #include "storage.h" -#include "fat.h" #include "disk.h" #include "font.h" #include "adc.h" diff --git a/bootloader/meizu_m6sp.c b/bootloader/meizu_m6sp.c index c57fe91b22..0a6dc274d9 100644 --- a/bootloader/meizu_m6sp.c +++ b/bootloader/meizu_m6sp.c @@ -30,7 +30,6 @@ #include "kernel.h" #include "thread.h" #include "storage.h" -#include "fat.h" #include "disk.h" #include "font.h" #include "button.h" diff --git a/bootloader/mini2440.c b/bootloader/mini2440.c index 4088065550..2bdd1a0f41 100644 --- a/bootloader/mini2440.c +++ b/bootloader/mini2440.c @@ -30,7 +30,6 @@ #include "../kernel-internal.h" #include "storage.h" #include "file_internal.h" -#include "fat.h" #include "disk.h" #include "font.h" #include "backlight.h" diff --git a/bootloader/mrobe500.c b/bootloader/mrobe500.c index 08ba6f2acd..e3d59051a1 100644 --- a/bootloader/mrobe500.c +++ b/bootloader/mrobe500.c @@ -27,7 +27,6 @@ #include "../kernel-internal.h" #include "storage.h" #include "file_internal.h" -#include "fat.h" #include "disk.h" #include "font.h" #include "adc.h" diff --git a/bootloader/sansaview.c b/bootloader/sansaview.c index 7ea4b59250..31716d4b25 100644 --- a/bootloader/sansaview.c +++ b/bootloader/sansaview.c @@ -35,7 +35,6 @@ SANSA VIEW: TESTING CODE #include "lcd.h" #include "../kernel-internal.h" #include "storage.h" -#include "fat.h" #include "disk.h" #include "font.h" #include "backlight.h" diff --git a/bootloader/telechips.c b/bootloader/telechips.c index 879e72ad65..c69a6da42c 100644 --- a/bootloader/telechips.c +++ b/bootloader/telechips.c @@ -31,7 +31,6 @@ #include "../kernel-internal.h" #include "storage.h" #include "file_internal.h" -#include "fat.h" #include "disk.h" #include "font.h" #include "button.h" diff --git a/bootloader/tpj1022.c b/bootloader/tpj1022.c index 30adb6ba4e..3590c7882d 100644 --- a/bootloader/tpj1022.c +++ b/bootloader/tpj1022.c @@ -32,7 +32,6 @@ #include "thread.h" #include "storage.h" #include "file_internal.h" -#include "fat.h" #include "disk.h" #include "font.h" #include "panic.h" diff --git a/firmware/common/disk_cache.c b/firmware/common/disk_cache.c index 0e842e7796..9e4dee6a91 100644 --- a/firmware/common/disk_cache.c +++ b/firmware/common/disk_cache.c @@ -23,7 +23,7 @@ #include "system.h" #include "linked_list.h" #include "disk_cache.h" -#include "fat.h" /* for SECTOR_SIZE */ +#include "fs_defines.h" #include "bitarray.h" /* Cache: LRU cache with separately-chained hashtable diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index b98567e8bf..b574117620 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c @@ -34,10 +34,9 @@ #include "ata_idle_notify.h" #include "ata-driver.h" #include "ata-defines.h" +#include "fs_defines.h" #include "storage.h" -#define SECTOR_SIZE 512 - #define SELECT_DEVICE1 0x10 #define SELECT_LBA 0x40 diff --git a/firmware/export/fat.h b/firmware/export/fat.h index 963c1fe767..b8092290e6 100644 --- a/firmware/export/fat.h +++ b/firmware/export/fat.h @@ -48,14 +48,6 @@ #define FAT_MAX_TRANSFER_SIZE 256 #endif -/* still experimental? */ -/* increasing this will increase the total memory used by the cache; the - cache, as noted in disk_cache.h, has other minimum requirements that may - prevent reducing its number of entries in order to compensate */ -#ifndef SECTOR_SIZE -#define SECTOR_SIZE 512 -#endif - /** ****************************************************************************/ diff --git a/firmware/include/disk_cache.h b/firmware/include/disk_cache.h index 725b3778cc..79b2ccf2c6 100644 --- a/firmware/include/disk_cache.h +++ b/firmware/include/disk_cache.h @@ -21,29 +21,6 @@ #ifndef DISK_CACHE_H #define DISK_CACHE_H -/* This needs enough for all file handles to have a buffer in the worst case - * plus at least one reserved exclusively for the cache client and a couple - * for other file system code. The buffers are put to use by the cache if not - * taken for another purpose (meaning nothing is wasted sitting fallow). - * - * One map per volume is maintained in order to avoid collisions between - * volumes that would slow cache probing. DC_MAP_NUM_ENTRIES is the number - * for each map per volume. The buffers themselves are shared. - */ -#if MEMORYSIZE < 8 -#define DC_NUM_ENTRIES 32 -#define DC_MAP_NUM_ENTRIES 128 -#elif MEMORYSIZE <= 32 -#define DC_NUM_ENTRIES 48 -#define DC_MAP_NUM_ENTRIES 128 -#else /* MEMORYSIZE > 32 */ -#define DC_NUM_ENTRIES 64 -#define DC_MAP_NUM_ENTRIES 256 -#endif /* MEMORYSIZE */ - -/* this _could_ be larger than a sector if that would ever be useful */ -#define DC_CACHE_BUFSIZE SECTOR_SIZE - #include "mutex.h" #include "mv.h" diff --git a/firmware/include/file_internal.h b/firmware/include/file_internal.h index 5893737833..d62b5a8541 100644 --- a/firmware/include/file_internal.h +++ b/firmware/include/file_internal.h @@ -28,55 +28,14 @@ #include "mutex.h" #include "mrsw_lock.h" #include "fs_attr.h" +#include "fs_defines.h" #include "fat.h" #ifdef HAVE_DIRCACHE #include "dircache.h" #endif -/** Tuneable parameters **/ - -/* limits for number of open descriptors - if you increase these values, make - certain that the disk cache has enough available buffers */ -#define MAX_OPEN_FILES 11 -#define MAX_OPEN_DIRS 12 #define MAX_OPEN_HANDLES (MAX_OPEN_FILES+MAX_OPEN_DIRS) -/* internal functions open streams as well; make sure they don't fail if all - user descs are busy; this needs to be at least the greatest quantity needed - at once by all internal functions */ -#ifdef HAVE_DIRCACHE -#define AUX_FILEOBJS 3 -#else -#define AUX_FILEOBJS 2 -#endif - -/* number of components statically allocated to handle the vast majority - of path depths; should maybe be tuned for >= 90th percentile but for now, - imma just guessing based on something like: - root + 'Music' + 'Artist' + 'Album' + 'Disc N' + filename */ -#define STATIC_PATHCOMP_NUM 6 - -#define MAX_COMPNAME 260 - -/* unsigned value that will also hold the off_t range we need without - overflow */ -#define file_size_t uint32_t - -#ifdef __USE_FILE_OFFSET64 -/* if we want, we can deal with files up to 2^32-1 bytes-- the full FAT16/32 - range */ -#define FILE_SIZE_MAX (0xffffffffu) -#else -/* file contents and size will be preserved by the APIs so long as ftruncate() - isn't used; bytes passed 2^31-1 will not accessible nor will writes succeed - that would extend the file beyond the max for a 32-bit off_t */ -#define FILE_SIZE_MAX (0x7fffffffu) -#endif - -/* if file is "large(ish)", then get rid of the contents now rather than - lazily when the file is synced or closed in order to free-up space */ -#define O_TRUNC_THRESH 65536 - /* default attributes when creating new files and directories */ #define ATTR_NEW_FILE (ATTR_ARCHIVE) #define ATTR_NEW_DIRECTORY (ATTR_DIRECTORY) diff --git a/firmware/include/fs_defines.h b/firmware/include/fs_defines.h new file mode 100644 index 0000000000..538c4b36cd --- /dev/null +++ b/firmware/include/fs_defines.h @@ -0,0 +1,108 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2017 by Michael Sevakis + * + * 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; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef FS_DEFINES_H +#define FS_DEFINES_H + +/** Tuneable parameters **/ + +#if 0 +/* Define this just in case you're doing something that may crash a lot and + want less write caching */ +#define FS_MIN_WRITECACHING +#endif + +#ifndef MAX_PATH +#define MAX_PATH 260 +#endif + +#define MAX_COMPNAME 260 + +/* still experimental? */ +/* increasing this will increase the total memory used by the cache; the + cache, as noted in disk_cache.h, has other minimum requirements that may + prevent reducing its number of entries in order to compensate */ +#ifndef SECTOR_SIZE +#define SECTOR_SIZE 512 +#endif + +/* limits for number of open descriptors - if you increase these values, make + certain that the disk cache has enough available buffers */ +#define MAX_OPEN_FILES 11 +#define MAX_OPEN_DIRS 12 + +/* internal functions open streams as well; make sure they don't fail if all + user descs are busy; this needs to be at least the greatest quantity needed + at once by all internal functions */ +#ifdef HAVE_DIRCACHE +#define AUX_FILEOBJS 3 +#else +#define AUX_FILEOBJS 2 +#endif + +/* number of components statically allocated to handle the vast majority + of path depths; should maybe be tuned for >= 90th percentile but for now, + imma just guessing based on something like: + root + 'Music' + 'Artist' + 'Album' + 'Disc N' + filename */ +#define STATIC_PATHCOMP_NUM 6 + +/* unsigned value that will also hold the off_t range we need without + overflow */ +#define file_size_t uint32_t + +#ifdef __USE_FILE_OFFSET64 +/* if we want, we can deal with files up to 2^32-1 bytes-- the full FAT16/32 + range */ +#define FILE_SIZE_MAX (0xffffffffu) +#else +/* file contents and size will be preserved by the APIs so long as ftruncate() + isn't used; bytes passed 2^31-1 will not accessible nor will writes succeed + that would extend the file beyond the max for a 32-bit off_t */ +#define FILE_SIZE_MAX (0x7fffffffu) +#endif + +/* if file is "large(ish)", then get rid of the contents now rather than + lazily when the file is synced or closed in order to free-up space */ +#define O_TRUNC_THRESH 65536 + +/* This needs enough for all file handles to have a buffer in the worst case + * plus at least one reserved exclusively for the cache client and a couple + * for other file system code. The buffers are put to use by the cache if not + * taken for another purpose (meaning nothing is wasted sitting fallow). + * + * One map per volume is maintained in order to avoid collisions between + * volumes that would slow cache probing. IOC_MAP_NUM_ENTRIES is the number + * for each map per volume. The buffers themselves are shared. + */ +#if MEMORYSIZE < 8 +#define DC_NUM_ENTRIES 32 +#define DC_MAP_NUM_ENTRIES 128 +#elif MEMORYSIZE <= 32 +#define DC_NUM_ENTRIES 48 +#define DC_MAP_NUM_ENTRIES 128 +#else /* MEMORYSIZE > 32 */ +#define DC_NUM_ENTRIES 64 +#define DC_MAP_NUM_ENTRIES 256 +#endif /* MEMORYSIZE */ + +/* this _could_ be larger than a sector if that would ever be useful */ +#define DC_CACHE_BUFSIZE SECTOR_SIZE + +#endif /* FS_DEFINES_H */ diff --git a/firmware/target/arm/as3525/sd-as3525.c b/firmware/target/arm/as3525/sd-as3525.c index 4530d5d763..e65a7525b6 100644 --- a/firmware/target/arm/as3525/sd-as3525.c +++ b/firmware/target/arm/as3525/sd-as3525.c @@ -23,7 +23,7 @@ /* Driver for the ARM PL180 SD/MMC controller inside AS3525 SoC */ #include "config.h" /* for HAVE_MULTIDRIVE & AMS_OF_SIZE */ -#include "fat.h" +#include "fs_defines.h" #include "thread.h" #include "led.h" #include "sdmmc.h" diff --git a/firmware/target/arm/as3525/sd-as3525v2.c b/firmware/target/arm/as3525/sd-as3525v2.c index dec36a520d..3f39629e0b 100644 --- a/firmware/target/arm/as3525/sd-as3525v2.c +++ b/firmware/target/arm/as3525/sd-as3525v2.c @@ -21,7 +21,7 @@ ****************************************************************************/ #include "config.h" /* for HAVE_MULTIVOLUME */ -#include "fat.h" +#include "fs_defines.h" #include "thread.h" #include "gcc_extensions.h" #include "led.h" diff --git a/firmware/target/arm/ata-nand-telechips.c b/firmware/target/arm/ata-nand-telechips.c index b8e572068c..869a53c1ef 100644 --- a/firmware/target/arm/ata-nand-telechips.c +++ b/firmware/target/arm/ata-nand-telechips.c @@ -28,8 +28,7 @@ #include "panic.h" #include "nand_id.h" #include "storage.h" - -#define SECTOR_SIZE 512 +#include "fs_defines.h" /* ECC on read is implemented on the assumption that MLC-style 4-bit correction is always used regardless of NAND chip type. This assumption is true for at diff --git a/firmware/target/arm/imx233/nand-imx233.c b/firmware/target/arm/imx233/nand-imx233.c index 22c4fc2748..a7afba7d43 100644 --- a/firmware/target/arm/imx233/nand-imx233.c +++ b/firmware/target/arm/imx233/nand-imx233.c @@ -23,7 +23,7 @@ #include "gpmi-imx233.h" #include "pinctrl-imx233.h" #include "button-target.h" -#include "fat.h" +#include "fs_defines.h" #include "disk.h" #include "usb.h" #include "debug.h" diff --git a/firmware/target/arm/imx233/sdmmc-imx233.c b/firmware/target/arm/imx233/sdmmc-imx233.c index 28310fbfd1..d3dabafecb 100644 --- a/firmware/target/arm/imx233/sdmmc-imx233.c +++ b/firmware/target/arm/imx233/sdmmc-imx233.c @@ -27,7 +27,6 @@ #include "pinctrl-imx233.h" #include "partitions-imx233.h" #include "button-target.h" -#include "fat.h" #include "disk.h" #include "usb.h" #include "debug.h" diff --git a/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c b/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c index 2f3c4189e5..0bfcdf3b1a 100644 --- a/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c +++ b/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c @@ -25,7 +25,6 @@ #include "system.h" #include "debug.h" #include "ata.h" -#include "fat.h" #include "disk.h" #include "panic.h" #include "lcd.h" diff --git a/firmware/target/arm/pp/ata-sd-pp.c b/firmware/target/arm/pp/ata-sd-pp.c index 2a11b40fee..edb806ab96 100644 --- a/firmware/target/arm/pp/ata-sd-pp.c +++ b/firmware/target/arm/pp/ata-sd-pp.c @@ -35,8 +35,8 @@ #include "usb.h" #include "sd.h" #include "storage.h" +#include "fs_defines.h" -#define SECTOR_SIZE 512 #define BLOCKS_PER_BANK 0x7a7800 /* Comparing documentations of various MMC/SD controllers revealed, */ diff --git a/firmware/target/arm/tms320dm320/sdmmc-dm320.c b/firmware/target/arm/tms320dm320/sdmmc-dm320.c index d46dbf5e40..a6e261bcfa 100644 --- a/firmware/target/arm/tms320dm320/sdmmc-dm320.c +++ b/firmware/target/arm/tms320dm320/sdmmc-dm320.c @@ -43,7 +43,6 @@ #endif #include "sdmmc.h" #include "disk.h" -#include "fat.h" #include "system-target.h" /* The configuration method is not very flexible. */ @@ -72,7 +71,6 @@ #define UNALIGNED_NUM_SECTORS 10 #define MAX_TRANSFER_ERRORS 10 -#define SECTOR_SIZE 512 #define BLOCKS_PER_BANK 0x7A7800 /* command flags for send_cmd */ diff --git a/firmware/usb.c b/firmware/usb.c index ee6ed2c12c..5e3795dd48 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -30,7 +30,6 @@ #include "system.h" #include "debug.h" #include "storage.h" -#include "fat.h" #include "disk.h" #include "panic.h" #include "lcd.h" diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c index 59ec191b4b..70587dfed4 100644 --- a/firmware/usbstack/usb_storage.c +++ b/firmware/usbstack/usb_storage.c @@ -27,7 +27,7 @@ #include "logf.h" #include "storage.h" #include "disk.h" -#include "fat.h" +#include "fs_defines.h" /* Needed to get at the audio buffer */ #include "audio.h" #include "usb_storage.h" @@ -41,10 +41,6 @@ #define RAMDISK_SIZE 2048 #endif -#ifndef SECTOR_SIZE -#define SECTOR_SIZE 512 -#endif - /* These defaults allow the operation */ #ifndef USBSTOR_READ_SECTORS_FILTER #define USBSTOR_READ_SECTORS_FILTER() ({ 0; })