Basic File List Example
Display a list of files on the ZentriOS file system
- SDK directory:
apps/basic/file_list
- Zentri App Store:
ZENTRI-BAFILELIST
API Features Demonstrated
- File System API
- zx_file_list - wrapper for the ZentriOS Command API ls
- zn_file_list - ZentriOS Native API
- zn_file_system_get_stats
- zn_file_destroy_list
Platforms
This app works on:
- AMW004 - Zentri Mackerel evaluation board
- AMW106 - Zentri Moray evaluation board
- NXP-SCCK - NXP Secure Cloud Connectivity Kit
Requirements and Prerequisites
Requires ZentriOS-powered hardware with serial flash memory, such as an AMW004 orAMW106 module
Description
This app displays information about files on the filesystem and then exits. Information is formatted and written to the log bus which can be viewed on a ZentriOS terminal.
Information about files is shown in the following sequence:
- File statistics
- Files on extended flash
- Files located in the
webapp/
directory - Files on extended flash are shown by paging
Expected output is similar to:
> File count....... 11
Flash size....... 1048576
Bytes used....... 401408
Bytes available.. 647168
Listing files on extended flash...
# Name Size Checksum
0 .recovery.html 7574 6BD9
1 apps/external_file_list-debug.zap 1888 7ECF
2 command_help.csv 47254 8ED4
3 default_setup.script 135 C90E
4 favicon.ico.gz 721 41C7
5 geotrust_ca.pem 1236 6E5A
6 sys/wifi_fw.bin 210412 5891
7 webapp/index.html 2031 CA05
8 webapp/unauthorized.html 9531 154C
9 webapp/zentrios.css.gz 22722 ABCB
10 webapp/zentrios.js.gz 71570 88F1
Listing webapp files...
# Name Size Checksum
0 webapp/unauthorized.html 9531 154C
1 webapp/index.html 2031 CA05
2 webapp/zentrios.css.gz 22722 ABCB
3 webapp/zentrios.js.gz 71570 88F1
Listing files on extended flash with 'paging' ...
Page: 1
# Name Size Checksum
0 sys/wifi_fw.bin 210412 5891
1 geotrust_ca.pem 1236 6E5A
2 command_help.csv 47254 8ED4
3 webapp/unauthorized.html 9531 154C
4 .recovery.html 7574 6BD9
Page: 2
# Name Size Checksum
0 webapp/index.html 2031 CA05
1 favicon.ico.gz 721 41C7
2 default_setup.script 135 C90E
3 webapp/zentrios.css.gz 22722 ABCB
4 webapp/zentrios.js.gz 71570 88F1
Page: 3
# Name Size Checksum
0 apps/external_file_list-debug.zap 1888 7ECF
Implementation
This app uses zx_file_list, a wrapper for the file list Command API ls. It is passed a pointer to a zos_file_t linked list structure that is then passed to print_file_list
for formatting and display on the ZentriOS terminal.
When you are finished with the linked list structure, you must call zn_file_destroy_list to deallocate memory and clean up.
See the following links for additional information about the ZentriOS features used in this app.
zn_app_init
- Calls the subroutines in sequence:
display_file_stats
list_extended_files_only
list_webapp_files
list_with_paging
display_file_stats
- File statistics are shown using the zn_file_system_get_stats API.
list_extended_files_only
- Files on extended flash are shown by passing the FILE_MEMORY_EXTENDED memory type to the zx_file_list API.
list_webapp_files
- Files located in the
webapp/
directory are shown by passing awebapp/
search string to zx_file_list.
list_with_paging
- Files are paged by passing a parameters structure to zn_file_list.
- The zos_file_parameters_t structure
.offset
parameter corresponds to thels
command-b base sector
option. - The zos_file_parameters_t structure
.limit
parameter corresponds to thels
command-c max file count
option - See the notes about paging in the ls documentation.
- The zos_file_parameters_t structure
print_file_list
- Formats and displays the file list on the ZentriOS terminal.
Source
See: