Can't write larger files to Flash

I am having trouble with flash file system. Whether I write to the flash using FTP or from an application thread, I get the same symptom. I am attempting to write 2 files that are 125,004 bytes. The first is written just fine. The second file gets truncated to 31,232. When using FTP, the error return is “critical error” as interpreted by the FTP program. When using fwrite() from an application program, fwrite() simply returns "0x00. " Flash #defines are as follows:

#define FS_VOLUME3_SIZE (4096 * 1024)
#define FS_VOLUME3 “FLASH0”
#define FS_VOLUME3_DIR FS_VOLUME3 “/”
#define FS_VOLUME3_SUB_DIR0 FS_VOLUME3 “/DIR0”
#define FS_VOLUME3_SUB_DIR0_1 FS_VOLUME3_SUB_DIR0 “/DIR00”
#define FS_VOLUME3_SUB_DIR1 FS_VOLUME3 “/DIR1”
#define MEDIA2_BLOCK_SIZE NAFS_BLOCK_SIZE_512 /* set flash up with 2K blocks /
#define FLASH0_STACK_SIZE 8 * 1024 /
8k /
#define FLASH0_QUEUE_SIZE 128
#define FLASH0_BUFFERS_IN_POOL 20
#define FLASH0_VOLUME_NAME “FLASH0”
#define FLASH0_INODE_BLOCK_LIMIT 25
#define FLASH0_OPEN_DIRS 10
#define FLASH0_OPEN_FILES_PER_DIR 10
#define FLASH0_START_SECTOR 10 /
for NS7520 only */
#define FLASH0_END_SECTOR 16
#define FLASH0_OPTIONS NAFS_MOST_DIRTY_SECTOR | NAFS_TRACK_SECTOR_ERASES
#define FLASH0_COMPACTING_THRESHOLD 40

In attempting to use the RAM volume, I have no problems writing the same files. I get the same problem if I first write the files to RAM, and then copy them to FLASH.

Any advice would be very much appreciated.

It sounds like you don’t have enough flash allocated to the file system, although the define statements that you posted don’t appear in my project at all, are you using the ConnectME? For the ConnectME, at least for V7.0 and up, the flash is allocated in the customize.ldr file with the FILE_SYSTEM_SIZE constant. Be careful though, because when you add to the file system size, you’re taking away from the application image size. Make sure there’s enough allocated for your application image.

Also note that your BLOCK_SIZE and INODE_BLOCK_LIMIT parameters affect how much of your file system flash is used for internal file and directory tables. Read the NET+OS API reference for NAFSinit_volume_cb() for detailed info on that.