'pwd' command emits garbage at 2nd subdirectory level #133

dlkeng opened this Issue Jan 25, 2013 · 1 comment

2 participants


OpenLog v3.13

The "pwd" command emits garbage at 2nd subdirectory level.
For example, with the following directory structure:

Volume is FAT32

For example:

 0) board reset
 1) 'pwd' shows ".\"
 2) 'cd ZZ1'
 3) 'pwd' shows ".\ZZ1"
 4) 'cd ZZ2'
 5) 'pwd' shows ".\ %@#$.!($*&!@(#$*&(!@*&$!@($*&."  (and lots more!)

This appears to be caused by the following lines in the code:

1575      tmp_var = getNextFolderTreeIndex();
1576      for (byte i = 0; i < tmp_var; i++)

In that code, ' tmp_var ' and ' i ' are both unsigned, but getNextFolderTreeIndex() returns -1 when limited by FOLDER_TRACK_DEPTH. So, in essence, the for() loop runs from 0 to 254 when a -1 is returned by getNextFolderTreeIndex() when the folderTree[] array is full.This results in trying to print file/directory names from data well off the end of the folderTree[] array.

Additionally, the whole operations traversing the directory tree and showing its current location behaves strangely.

The following is an example directory tree transversal operations and results

 1) 'pwd' shows ".\"
 2) 'cd ZZ1'
 3) 'pwd' shows ".\ZZ1"
 4) 'cd ..'
 5) 'pwd' shows ".\"
 6) 'cd ZZ1'
 7) 'pwd' shows ".\ZZ1"
 8) 'cd ZZ2'                 <-------- folderTree[] is now full
 9) 'pwd' shows ".\" %@#$..  <-------- is incorrect since is actually at ".\ZZ1\ZZ2"
10) 'cd ..'                  <-------- actually goes to root
11) 'pwd' shows ".\"
12) 'cd ZZ1'
13) 'pwd' shows ".\"         <-------- is incorrect since is actually at ".\ZZ1"

In summary, once folderTree[] has been filled, all subsequent 'pwd' commands show
is at root directory and all 'cd ..' commands always go to root directory! It appears the intent originally was to somehow limit the depth of the directory structure, but the 'cd' command is not limited on its tranversal down the directory structure, only the upward transversal.

SparkFun Electronics member

I can definitely recreate the issue. My OpenLog borks when you try pwd on a directory with more than 2 levels. This is however kind of expected.

#define FOLDER_TRACK_DEPTH 2 //Decreased for more RAM access

We reduced the number of folders to track to save RAM. pwd works correctly when I increase this depth to 5 but, because we tie up more RAM, we sacrifice the RX buffer size. I think I'm going to leave support at two subfolders. If you think we need more, please re-open issue.

@nseidle nseidle closed this Apr 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment