?? wosfs.c
字號:
//
// file: wosfs.c
//
// "Way Oversimplified File System"
// A flat memory-based file system
// which supports reading of files only,
// but not writing. (It could be easily
// extended to support appending, perhaps.)
//
// dvb@altera.com 2001 April 25
//
#include "wosfs.h"
// +-----------------------------
// | Local Prototypes
static void r_read_from_flash(long offset,long length,void *data_out);
// +----------------------------
// | Routines
static void r_read_from_flash(long offset,long length,void *data_out)
{
int i;
for (i = 0; i < length; ++i)
{
((unsigned char*)data_out)[i] = ((unsigned char*)nk_wosfs_flash_begin)[i + offset];
}
}
long nr_wosfs_get_file_count(void)
{
ns_wosfs_volume_header vh;
r_read_from_flash(0,sizeof(ns_wosfs_volume_header),&vh);
if (nk_wosfs_signature != vh.signature)
{
return 0;
}
return vh.file_count;
}
void nr_wosfs_get_directory_entry(long file_index,ns_wosfs_directory_entry *de_out)
{
r_read_from_flash(sizeof(ns_wosfs_volume_header) + file_index * sizeof(ns_wosfs_directory_entry),
sizeof(ns_wosfs_directory_entry),de_out);
}
int nr_wosfs_string_match(char *a, char *b) // return 1 if match
{
char *x = a;
while(*a || *b)
{
if(*a++ != *b++)
return 0;
}
return 1;
}
long nr_wosfs_get_directory_entry_by_name(char *file_name,ns_wosfs_directory_entry *de_out)
{
ns_wosfs_directory_entry de;
int file_index;
int file_count;
file_count = nr_wosfs_get_file_count();
for(file_index = 0; file_index < file_count; file_index++)
{
nr_wosfs_get_directory_entry(file_index,&de);
if(nr_wosfs_string_match(file_name,de.name))
{
if(de_out)
*de_out = de;
return file_index;
}
}
return -1;
}
void nr_wosfs_read(long file_index,long offset,long length,void *data_out)
{
ns_wosfs_directory_entry de;
r_read_from_flash(sizeof(ns_wosfs_volume_header) + file_index * sizeof(ns_wosfs_directory_entry),
sizeof(ns_wosfs_directory_entry),&de);
r_read_from_flash(de.location + offset,length,data_out);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -