Web 51 Filesystem

Simple http server  software.html  Web 51 - Web51 SMTP
Filesystem can span over 3 "medias": external I2C EEPROM, FlashROM in the CPU, EEPROM in the CPU. (Filesystem is searched in this order; therefore, external EEPROM can "overwrite" files in the CPU).

FlashROM/internal EEPROM filesystem

Individual filesystem items are usually generated by html2db. For correct filesystem operation, linking order must be observed to ensure proper data structure in the resulting linked file, as shown below. Correct linking is ensured by the www8051.sc script; in practice, it is necessary to use proper segment names as declared there. That is,
cpu_dir - for a directory item in CPU Flash
ee_dir - for a directory item in the CP EEPROM
Location of constructed html pages in segments cpu_files and ee_files is only recommended; system does not require it for operation. Only requirement is that data must be in the same type of memory (Flash/EEPROM/I2C) as the corresponding directory item.

Example of the filesystem in the FlashROM of the CPU:


;FlashROM filesystem begins
;File filecpu.asm
        .section cpu_dir_begin, #alloc
.global	filedir
filedir:	

;Directory item in FlashROM filesystem
;File config.html
        .section cpu_dir, #alloc
        .word   'c'+'o'+'n'+'f'+'i'+'g'+'.'+'h'+'t'+'m'+'l'
        .byte   1       ;text/html
        .byte   0       ;reserved
        .word   begin0
        .word   end0

        .word   0       ;value specified with -index option
        .byte   1       ;text/html
        .byte   0       ;reserved
        .word   begin0
        .word   end0
....
....

;Directory item in FlashROM filesystem
;File setup.html
        .section cpu_dir, #alloc
        .word   's'+'e'+'t'+'u'+'p'+'.'+'h'+'t'+'m'+'l'
        .byte   1       ;text/html
        .byte   0       ;reserved
        .word   begin1
        .word   end1

;Directory item in FlashROM filesystem
;CGI scripts - file bdc.asm
        .section cpu_dir, #alloc
        .word   'b'+'d'+'c'+'.'+'c'+'g'+'i'
        .byte   0x10            ;cgi
        .byte   0               ;reserved
        .word   cgi8begin
        .word   cgi8end

;Directory item in FlashROM filesystem
;CGI scripts - file fl.asm
        .section cpu_dir, #alloc
        .word   'f'+'l'+'.'+'c'+'g'+'i'
        .byte   0x10            ;cgi
        .byte   0               ;reserved
        .word   cgi9begin
        .word   cgi9end
;
;End of FlashROM filesystem directory
;File filecpu.asm
	.section cpu_dir_end, #alloc
;
	.word	-1
	.byte	0		;none
	.byte	0		;reserved
	.word	0
	.word	0

;FlashROM filesystem item
;File config.html
        .section      cpu_files, #alloc
begin0:
       .ascii	"...
end0:

;FlashROM filesystem item
;File setup.html
        .section      cpu_files, #alloc
begin1:
       .ascii	"...
end1:

Of course, the above filenames are for illustration purposes only. They were taken from the 'serial' example.

CPU EEPROM filesystem uses exactly the same structure. Only the default segment name used by html2db is ee_dir for directory items and ee_files for contents of "files".

I2C EEPROM filesystem

I2C EEPROM filesystem structure is the same as FlashROM filesystem structure, with one exception - directory items start at a fixed adress. A signature precedes the I2C EEPROM directory structure and indicates an external memory with WWW data.

Example of an I2C EEPROM filesystem:


	;;cseg  at      0000h
        .text
        .ascii  "@BCL"  ;Signature

        .word   'i'+'n'+'d'+'e'+'x'+'.'+'h'+'t'+'m'+'l'
        .byte   1       ;text/html
        .byte   0       ;reserved
        .word   begin0
        .word   end0

        .word   0
        .byte   1       ;text/html
        .byte   0       ;reserved
        .word   begin0
        .word   end0
....
....

begin0:
        .ascii  "...
end0:

Directory item

Web51 uses 8-byte directory items.
First two bytes contain a hash value of the filename. Hash is calculated as a 16-bit sum of ASCII codes of all filename characters. The sum includes the dot between the name and the extension, as well as the extension itself. Hash does not include the path (last slash character and everything before it). Therefore, hash of img0.gif is equal to hash of image/img0.gif. Hash of / (server root) is equal to 0. html2db allows to add another hash to any page, besides the one calculated from its name, using -index hash_value. For example, a page can be specified as the server root with the mentioned hash of 0.
Filesystem ends with a directory item with hash value 0FFFFh, called EOD (End Of Directory).
Third byte specifies file type. According to file type, appropriate header is sent and a correct file handling mode is selected. Files of type 1 and 2 are searched for cgi calls. Files of type 10h (CGI) are processed by the P-Code interpreter.

typehandling method / header
0sent without a header
1sent with header 'HTTP/1.1 200 OK',LF,'Content-type: text/html',LF,LF
2sent with header 'HTTP/1.1 200 OK',LF,'Content-type: text/plain',LF,LF
3sent with header 'HTTP/1.1 200 OK',LF,'Content-type: image/jpeg',LF,LF
4sent with header 'HTTP/1.1 200 OK',LF,'Content-type: image/gif',LF,LF
5sent with header 'HTTP/1.1 200 OK',LF,'Content-type: image/png',LF,LF
6sent with header 'HTTP/1.1 200 OK',LF,'Content-type: application/octet-stream',LF,LF
10hinterpreted as a P-Code CGI script

Fourth byte is reserved and has to be zero, for compatibility with future versions.

Fifth and sixth byte contain point to the beginning of the file in memory.

Seventh and eighth byte point behind the end of the file in memory.





Sponzored by LPhard Ltd. Graphics by GIMP Created by EasyPad

(c)Copyright 2000 - 2002, HW server & Radek Benedikt
Web51@HW.cz, Web51.HW.cz
Simple http server  Obsah  Web 51 - Web51 SMTP