Author Topic: utFat and uFile  (Read 10377 times)

Offline cmalan

  • Newbie
  • *
  • Posts: 14
    • View Profile
utFat and uFile
« on: February 03, 2012, 07:55:49 AM »
Hi

Can the sd card and internal flash be accessible from ftp and http at the same time.
I want to store config data on internal flash and write logs to the sd card.

Christo

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: utFat and uFile
« Reply #1 on: February 03, 2012, 10:02:29 AM »
Hi Christo

Essentially both are possible at the same time.

1) When FTP_UTFAT is enabled the FTP server will use the SD card if it is present and formatted and otherwise 'fall-back' to using the internal Flash (without FTP_UTFAT always internal Flash)
2) When HTTP_UTFAT is enabled the WEB server will use the SD card if it is present and formatted and otherwise 'fall-back' to using the internal Flash (without HTTP_UTFAT always internal Flash)
3) General application code can access both types as they wish and so one part could be using internal Flash and another using the SD card.

Regards

Mark


Offline cmalan

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: utFat and uFile
« Reply #2 on: February 03, 2012, 10:58:28 AM »
Hi Mark

Ok I see, what will it take to have both accessible from ftp and http.
The config data is created on the pc and send to uTasker with ftp. The sd card log function is an optional and if the sd card is removed or inserted the config file will change with the sd-card. I want the config file to stay on the internal flash even if the sd-card is available.

Christo

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: utFat and uFile
« Reply #3 on: February 04, 2012, 10:31:47 PM »
Hi Christo

There are several things that I could envisage:
1) FTP requires a file system for it basic operation and can choose which one (if more than one are present), as it does when the FTP_UTFAT option is enabled. If there were more than one FTP server (operating on different ports for example) one could specifically work with the desired file system (althoug I am not sure whether FTP clinets can work with non-standard port numbers (?)).
2) Both SD card and internal files could always be displayed (uFileSystem files visible in every directory). If an operation on a non-existing FAT file is specified it could default to the equivalent uFileSystem file. Writing new files could be tricky since it wouldn't know where to write to.
3) A specific, virtual directory could be used when uFileSystem operations are to be performed. Moving to this virtual directory (not actually on the card) would exclusively result in uFileSystem operation. Moving out would then return to SD card operations.
4) The Web server simply serves the file that is specified in the GET commands. It could "fall back" to uFileSystem files if the defined file is not found on the SD card.
5) The web server could also use the virtual directory as suggested in 3) so that any files served from it would be taken from the uFileSystem and any others from the SD card.

Although these capabilities don't exist in the present solution they shouldn't be difficult to add. I think that most important part would however be to identify the strategy that could be used as standard optional mode so that it doesn't later have to be modified again because it doesn't allows similar things to be performed that haven't been envisaged yet - therefore it needs have a certain amount of flexibility but be of generic nature.

Regards

Mark

Offline cmalan

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: utFat and uFile
« Reply #4 on: February 06, 2012, 08:49:41 AM »
Hi Mark

I think the best solution would be 3, and give the virtual directory a obscure name that user is not likely to create on the card.
My short term solution will be a bit simpler. The config data is crated and uploaded with pc application. The pc can stop the sd card and then do the ftp to internal flash.

How do I stop the sd card? It can be started with a system reset.

Christo

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: utFat and uFile
« Reply #5 on: February 07, 2012, 12:05:47 PM »
Hi Christo

How to stop the SD card ?

Once the SD card has been detected and mounted it can be used. If the SD card is then removed from the system this is not noticed (unless a card detect switch is present and used) until some action is performed that needs to read the card (sometimes even performing a DIR will not notice that the card has been removed because the root directory is still in cache).

But I think that you would like a method of not necessarily removing the card but disabling it so that the uFileSystem is used by FTP (for example).

FTP bases its file system use on the flag UTDIR_VALID which is set when the FTP connection is established by calling utOpenDirectory(FTP_ROOT, ptr_utDirectory);. Since this will always be sucessful if the SD card is still present I think that it would be simplest to control FTP directly to either try to use the FTP card or not rather than controlling whether the card is detected or not. Fpr example a global variable that indicates which modules can use the card and which should not.

That means that if you want to switch FTP from SD card based to uFileSystem based with an active SD card it woudl be necessary to be able to control that variable.

Generally it may be useful to add an unmount command which can be used to disable the SD card entirely, including powering it down if it has its own power supply. Later a mount could be commanded that will then try to mount the card or regularly poll it in case it is not inserted at the time but may be inserted later.

As summary I could imaging three commands to the utFAT module:
- one to disable or enable access from certain system modules (eg. FTP, HTTP and maybe some optional flags for the application parts too)
- one to unmount a card
- one to remount the card (although restarting the mass storage task may be adequate)

Regards

Mark

Offline cmalan

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: utFat and uFile
« Reply #6 on: February 07, 2012, 01:40:31 PM »
Hi Mark

I will use a global variable to ensure that ptr_utDirectory in ftp.c is not valid when I want to use the internal flash.
The global variable can be switched on an off via the web pages.
This will be sufficient for now. I will revisit the virtual dir when I have time later in the development.

Thanks
Christo