Error ENOENT (-2) when file name in fs_open() is longer than 8 characters

I'm developing in VS Code (nRF Connect, SDK 2.3.0 and nRF82840) my own mass storage device on my custom board with a MT25QU512 NOR flash memory. To test the write to the file I wrote a little code starting from the mass template of the nRF Connect in VS Code, but I noticed that if I try to create a file which a length name longer than 8 characters, the fs_open() returns error ENOENT (-2) meaning "when the file path is not possible (bad mount point)" as indicated in the Zephyr API documentation. To know the length limit I wrote a simple test code inside the main function of mass template:

char filePath[ 128 ];
char fileName[ 32 ] = "";

while ( 1 )
{
	strncpy( filePath, RECORDS_DIRECTORY_PATH, sizeof( filePath ) );
	strcat( fileName, "a" );
	strcat( filePath, fileName );
	fs_file_t_init( &file );

	if ( fs_open( &file, filePath, FS_O_CREATE | FS_O_WRITE | FS_O_APPEND ) < 0 )
	{
		LOG_ERR( "Failed to open %s, length %d", filePath, strlen( filePath ) );
		break;
	}
	else
	{
		LOG_INF( "Open %s, length %d", filePath, strlen( filePath ) );
	}

	fs_close( &file );
	k_msleep( 1000 );
}

The output for RECORDS_DIRECTORY_PATH = "/NAND:/Records/" is

*** Booting Zephyr OS build v3.2.99-ncs2 ***
[00:00:00.000,183] <inf> flashdisk: Initialize device NAND
[00:00:00.000,183] <inf> flashdisk: offset 0, sector size 512, page size 4096, volume size 67108864
[00:00:00.033,874] <inf> flashdisk: Initialize device NAND
[00:00:00.033,905] <inf> flashdisk: offset 0, sector size 512, page size 4096, volume size 67108864
[00:00:00.117,980] <err> fs: failed to create directory (-17)
[00:00:00.118,011] <inf> main: Directory /NAND:/Records/ exists
[00:00:00.118,560] <inf> main: Open /NAND:/Records/a, length 16
[00:00:02.175,842] <inf> main: Open /NAND:/Records/aa, length 17
[00:00:04.231,964] <inf> main: Open /NAND:/Records/aaa, length 18
[00:00:06.288,146] <inf> main: Open /NAND:/Records/aaaa, length 19
[00:00:08.344,329] <inf> main: Open /NAND:/Records/aaaaa, length 20
[00:00:10.400,543] <inf> main: Open /NAND:/Records/aaaaaa, length 21
[00:00:12.456,726] <inf> main: Open /NAND:/Records/aaaaaaa, length 22
[00:00:14.512,908] <inf> main: Open /NAND:/Records/aaaaaaaa, length 23
[00:00:16.569,000] <err> fs: file open error (-2)
[00:00:16.569,061] <err> main: Failed to open /NAND:/Records/aaaaaaaaa, length 24
[00:00:16.569,061] <inf> main: The device is put in USB mass storage mode.

and the output for RECORDS_DIRECTORY_PATH = "/NAND:/" is

*** Booting Zephyr OS build v3.2.99-ncs2 ***
[00:00:00.000,183] <inf> flashdisk: Initialize device NAND
[00:00:00.000,183] <inf> flashdisk: offset 0, sector size 512, page size 4096, volume size 67108864
[00:00:00.034,362] <inf> flashdisk: Initialize device NAND
[00:00:00.034,362] <inf> flashdisk: offset 0, sector size 512, page size 4096, volume size 67108864
[00:00:00.118,988] <err> fs: failed to create directory (-17)
[00:00:00.119,018] <inf> main: Directory /NAND:/Records/ exists
[00:00:00.119,323] <inf> main: Open /NAND:/a, length 8
[00:00:02.176,330] <inf> main: Open /NAND:/aa, length 9
[00:00:04.176,544] <inf> main: Open /NAND:/aaa, length 10
[00:00:06.176,757] <inf> main: Open /NAND:/aaaa, length 11
[00:00:08.176,940] <inf> main: Open /NAND:/aaaaa, length 12
[00:00:10.177,185] <inf> main: Open /NAND:/aaaaaa, length 13
[00:00:12.177,398] <inf> main: Open /NAND:/aaaaaaa, length 14
[00:00:14.177,612] <inf> main: Open /NAND:/aaaaaaaa, length 15
[00:00:16.177,825] <err> fs: file open error (-2)
[00:00:16.177,886] <err> main: Failed to open /NAND:/aaaaaaaaa, length 16
[00:00:16.177,886] <inf> main: The device is put in USB mass storage mode.

Changing the while file path with directory doesn't impact on the generation of the error: it seems to get out only when the file name exceed the 8 characters. Is this normal? What's goin' on?

Parents Reply Children
No Data
Related