Newbie questions about fat32 handling.

Discussion about writing software for VS1005 and the VSOS Operating System. Also posts about VS1005-related hardware design and device drivers should be posted here.
Post Reply
gilvanl
User
Posts: 11
Joined: Wed 2017-11-01 13:26

Newbie questions about fat32 handling.

Post by gilvanl »

Hello, I have some questions about reading fat32 file systems.

I would like to implement a set of functions that selects one file or directory (one entry in fat32) at
a time in a directory from the drive. The primitives are:
GoNext - selects the next file in a list (more or less is the code in PlayDir and PlayFiles example).
GoPrev - selects the prior file in a list (same as above in PlayDir and PlayFiles example).
GoUp - if there is some upper directory it goes up one level, same as "cd ..".
GoDown - if the selected entry is a directory, it enters that directory and lists the files, like "cd selected_dir".
GoRoot - from any place in the file tree of the actual drive, goes to root, and lists the files and directories.

I had looking in the examples "cd" and "dir" but not figured out the exact parts to use.

The variable "char *currentDirectory" in consolestate.h is the selected entry ?

Sorry by the newbie questions but I am stuck in this part and do not see details in the documentation.

Thanks, best regards.
User avatar
Henrik
VLSI Staff
Posts: 1215
Joined: Tue 2010-06-22 14:10

Re: Newbie questions about fat32 handling.

Post by Henrik »

Hello!

This is a short message just to let you know that I am putting together an answer and hope to get it to you later today, latest tomorrow.

Kind regards,
- Henrik
Good signatures never die. They just fade away.
User avatar
Henrik
VLSI Staff
Posts: 1215
Joined: Tue 2010-06-22 14:10

Re: Newbie questions about fat32 handling.

Post by Henrik »

Hello again!

For traversing through directories it may be easiest to just run the "CD" command from your source code, using the system function RunProgram(). It can be used as if you were on the command line:

Code: Select all

#include <apploader.h>

if (RunProgram("cd", path)) {
  SysError("Couldn't change directory to %s", path);
  goto finally;
}

Examples for path:
* "D:"
* "D:SYS/"
* "SYS"
* ".."
Note!
If you have not started your application from the Shell.dl3 command line, but instead from config.txt, there will not be a working shell environment, and RunProgram("cd", ...) will crash! To create the shell environment, add the following line on config.txt before your own application:

Code: Select all

# Add shell environment
shellenv
# Start YourOwnApp
RUN YourOwnApp
Then, to see how to list all directories so that you can select one, have a look at the ListDirs application I have attached to this message. It lists both files and directories under the current directory, and shows which ones are directories with a 'D' character. Example run:

Code: Select all

S:>dir
-    1. CONFIG.TXT         3843 2021-04-16 07:29:40 config.txt
-    3. GFX.DAT           67988 2020-05-05 07:27:46 gfx.dat
-    4. SHELL.AP3          1444 2017-12-14 12:46:02 shell.ap3
D    2. SYS                   0 2021-05-11 07:38:02 SYS
S:>ListDirs
Entries in SPI Flash c814 "S:"
file, attr: 20, short: CONFIG.TXT  , long: config.txt
DIR , attr: 10, short: SYS         , long: SYS
file, attr: 20, short: GFX.DAT     , long: gfx.dat
file, attr: 20, short: SHELL.AP3   , long: shell.ap3
Attachments
ListDirs.zip
Example on how to list files / directories
(5.37 KiB) Downloaded 15 times
Good signatures never die. They just fade away.
gilvanl
User
Posts: 11
Joined: Wed 2017-11-01 13:26

Re: Newbie questions about fat32 handling.

Post by gilvanl »

Thanks a lot !

I will look after the example.

Best regards.
gilvanl
User
Posts: 11
Joined: Wed 2017-11-01 13:26

Re: Newbie questions about fat32 handling.

Post by gilvanl »

I came to thank again, seems that I have find out more or less how to implement my idea.
Very neat and useful example.

Best regards.
User avatar
Henrik
VLSI Staff
Posts: 1215
Joined: Tue 2010-06-22 14:10

Re: Newbie questions about fat32 handling.

Post by Henrik »

You're welcome!

Also note that the canonical whole current path can be printed out by printing currentDirectory, as you can see in the fopen() function call in ListDirs(). There's a catch, though: to save space, the path is stored in short (8 character) form, so it may not be overtly user friendly.

Kind regards,
- Henrik
Good signatures never die. They just fade away.
gilvanl
User
Posts: 11
Joined: Wed 2017-11-01 13:26

Re: Newbie questions about fat32 handling.

Post by gilvanl »

Hello, and thanks again for the help.

See in the topic: " Simple VS1005 Breakout Board Player " the results of my coding and testing.
A simple project just for some fun.
The sound is excelent, and i use it for my default player now.
Hope it be useful for the people here in the board.

Best regards.
Post Reply