This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

problems with file system in httpserver example

Other Parts Discussed in Thread: SYSBIOS

Hi everyone,

I'm trying to open a file in the httpserver example,

as in the topic

I'm having trouble to open file in read mode.

I wrote a function that try to open a file, but if the file doesn't exists it will be created.

Unfortunately, if I call the function after netappstart then the program crash and the console give me:

ti.sysbios.knl.Task: line 370: E_stackOverflow: Task 0x200231c8 stack overflow.
xdc.runtime.Error.raise: terminating execution

My function is:

int file_handler(unsigned long *ulToken, long *lFileHandle){

	long lRetVal = -1;
	int loopcount=0;
	int controllo=0;
	unsigned char gaucOldMacDonald[]="100";
	unsigned char gaucOldMacDonald2[]="100";
	char subbuff[5]; //vale per pushlight, dimdom, heatdom, pushutter per lo stato
	char subbuff2[5];
	int stato_lampada;
	unsigned char gaucCmpBuf[BUF_SIZE];
	unsigned char gaucCmpBuf2[BUF_SIZE];
	bzero(gaucCmpBuf,BUF_SIZE);

UART_PRINT("I try\n\r");
	lRetVal = sl_FsOpen((unsigned char *)USER_FILE_NAME,
			    	                        FS_MODE_OPEN_READ,
			    	                        ulToken,
			    	                        lFileHandle);


	UART_PRINT("Here\n\r");

		if(lRetVal<0){
			UART_PRINT("Il file doesn't exists\n\r");

		lRetVal = sl_FsOpen((unsigned char *)USER_FILE_NAME,
		                FS_MODE_OPEN_CREATE(65536,
		                          _FS_FILE_OPEN_FLAG_COMMIT|_FS_FILE_PUBLIC_WRITE),
		                        ulToken,
		                        lFileHandle);

		controllo=1;
		UART_PRINT("FILE_CREATED\n\r");

		}else{
			UART_PRINT("File esistente\n\r");
			//il file esiste già
			lRetVal = sl_FsRead(*lFileHandle,
			(unsigned int)(loopcount * sizeof(gaucOldMacDonald)),
			 gaucCmpBuf, sizeof(gaucOldMacDonald));

			controllo=0;
		}
		lRetVal=sl_FsClose(*lFileHandle,0,0,0);


		if(controllo==0){
		memcpy(subbuff, &gaucCmpBuf[0],1);
		subbuff[1]='\0';
		duty_cycle=atoi(subbuff);
		

		}
		bzero(gaucCmpBuf2,BUF_SIZE);
		lRetVal = sl_FsOpen((unsigned char *)USER_FILE_NAME2,
					    	                        FS_MODE_OPEN_READ,
					    	                        ulToken,
					    	                        lFileHandle);

return 0;
}

  • I tried to make a task that do pend on a semaphore, initialized on 0, and block himself while the semaphore counter is lower than 1, but the program crash anyway.
  • Hi,

    The major issue is not related to file system but to the fact you get to a stack overflow. Please check why you get it. If the BUF_SIZE too large (try to reduce it)? you allocated twice this size on stack.

    The other issue is related to file system where you open the file again at the end of the function without doing anything (and closing it). In this case, you would loose the file handle and would be able to close it outside the function so any future interaction with the file system would end up with the SL_FS_FILE_HAS_NOT_BEEN_CLOSE_CORRECTLY error.

    Shlomi

  • Hi,

    thanks for reply.

    It works *_* my BUF_SIZE was too large as you have suggested.

    Thanks a lot :)