VxWorks有dosFs和hrFs,都可以用作Nor Flash或者SPI Flash文件系统,需要定义如下宏:

#define INCLUDE_TFFS
#ifdef INCLUDE_TFFS
#define INCLUDE_TFFS_SHOW
#define INCLUDE_TFFS_MOUNT
#define INCLUDE_ERF
#define INCLUDE_DEVICE_MANAGER
#define INCLUDE_FS_EVENT_UTIL
#define INCLUDE_FS_MONITOR
#define INCLUDE_XBD
#define INCLUDE_XBD_BLK_DEV
#define INCLUDE_XBD_TRANS
#define INCLUDE_DISK_UTIL
#define INCLUDE_DISK_PART      
#define INCLUDE_RAWFS          
#endif

#undef INCLUDE_HRFS  -- 用的话打开就行
#ifdef INCLUDE_HRFS
#   define INCLUDE_HRFS_FORMAT    
#   define INCLUDE_HRFS_CHKDSK    
#endif

#undef INCLUDE_DOSFS -- 用的话打开就行
#ifdef INCLUDE_DOSFS
#   define INCLUDE_DOSFS_DIR_FIXED
#   define INCLUDE_DOSFS_DIR_VFAT
#   define INCLUDE_DOSFS_FAT
#   define INCLUDE_DOSFS_FMT
#   define INCLUDE_DOSFS_CHKDSK
#   define INCLUDE_DOSFS_MAIN
#   define INCLUDE_DOSFS_SHOW
#endif  

建立文件系统过程如下:

-> tffsShowAll 
TFFS Version 6.6
0: socket=RFA0: type=0x0, unitSize=0x20000, mediaSize=0x400000
1: socket=RFA1: type=0x0, unitSize=0x10000, mediaSize=0x100000
value = 47 = 0x2f = '/'
-> sysTffsFormat 0
Formatted 32 of 32 units = 100.0 %
value = 0 = 0x0
-> sysTffsFormat 1
Formatted 16 of 16 units = 100.0 %
value = 0 = 0x0
-> usrTffsConfig 0,0,"/tffs0"
Instantiating /tffs0 as rawFs,  device = 0x50001
value = 0 = 0x0
-> usrTffsConfig 1,0,"/tffs1"
Instantiating /tffs1 as rawFs,  device = 0x70001
value = 0 = 0x0
-> hrfsFormat "/tffs0"
Formatting /tffs0 for HRFS v1.2
Instantiating /tffs0 as rawFs, device = 0x50001
Formatting...OK.
value = 0 = 0x0
-> hrfsFormat "/tffs1"
Formatting /tffs1 for HRFS v1.2
Instantiating /tffs1 as rawFs, device = 0x70001
Formatting...OK.
value = 0 = 0x0
-> ll "/tffs0"

Listing Directory /tffs0:
drwxrwxrwx  2 0       0                 4096 Jan  1 00:01 ./
drwxrwxrwx  2 0       0                 4096 Jan  1 00:01 ../
value = 0 = 0x0
-> ll "/tffs1"

Listing Directory /tffs1:
drwxrwxrwx  2 0       0                 2048 Jan  1 00:01 ./
drwxrwxrwx  2 0       0                 2048 Jan  1 00:01 ../
value = 0 = 0x0
-> 

如何建立dosfs with TFFS

For a TFFS device, you'd first "low level" format the TFFS disk (sysTffsFormat), then the transaction layer(usrFormatTrans) and then the above DosFS device (dosFsVolFormat).

-> usrFormatTrans "/tffs1",100,0
Instantiating /tffs1 as rawFs, device = 0x30001
Instantiating /tffs1 as rawFs,  device = 0x60001
value = 0 = 0x0
-> dosFsVolFormat "/tffs1"
Formatting /tffs1 for DOSFS
Instantiating /tffs1 as rawFs, device = 0x60001
Formatting...Retrieved old volume params with 8 confidence:
Volume Parameters: FAT type: FAT32, sectors per cluster 0
  0 FAT copies, 0 clusters, 0 sectors per FAT
  Sectors reserved 0, hidden 0, FAT sectors 0
  Root dir entries 0, sysId (null)  , serial number a8f40000
  Label:"           " ...
Disk with 1669 sectors of 512 bytes will be formatted with:
Volume Parameters: FAT type: FAT12, sectors per cluster 1
  2 FAT copies, 1644 clusters, 5 sectors per FAT
  Sectors reserved 1, hidden 63, FAT sectors 10
  Root dir entries 224, sysId VXDOS12 , serial number a8f40000
  Label:"           " ...
OK.
value = 0 = 0x0

几个小tips

1)如何判断是什么文件系统?

chkdsk() & hrfsChkDsk() 和 dosFsShow()
STATUS dosFsShow
    (
    void *  pDevName,  
    u_int   level      
    )

STATUS chkdsk
    (
    const char *    pDevName,    
    u_int    repairLevel,    
    u_int    verbose    
    )

STATUS hrfsChkDsk
    (
    char *      path,          
    int         verbLevel,      
    int         flags          
    )似乎这个不支持命令行编译,要用workbench编。

2)注意全局变量flFileSysSectorStart可能在某些版本下有用:

In 5.5.1 and 6.4 the variable flFileSysSectorStart is 0, but it is 1 in 6.4.2.

int flFileSysSectorStart = 1;

风河的注释:
Starting sector of File System: protects overwriting TFFS at sector 0, dosFS shares TFFS sector 0, other file systems may not. Since dosfs, hrfs and other file systems now use the new discard interface, fat monitoring is not on and therefore it is better to always protect TFFS info sector.

我的理解,dosfs和tffs可以共享sector 0,tffs知道dosfs的boot sector的结构。其它FS不行,会冲掉tffs的boot sector 信息。

3)如果有时候sysTffsformat不好使了试试这个:

STATUS tffsRawio 
    (
    int tffsDriveNo,
    int functionNo,
    int arg0,
    int arg1,
    int arg2
    )
tffsRawio(0, 3, 0, 8)
The first argument in the tffsRawio() command shown above is the TrueFFS drive number, 0. The second argument, 3, is the function number (also known as TFFS_PHYSICAL_ERASE). The third argument, 0, specifies the unit number of the first erase unit you want to erase. The fourth argument, 8,specifies how many erase units you want to erase

这个函数可以直接调用底层擦除函数,因为一旦你定义了FORMAT_IF_NEED的话,tffs是不会帮你擦底层的。

4)tffs下的裸读裸写操作:按照块设备来操作即可

-> cd "/tffs1"
value = 0 = 0x0
-> open "hjj",0x202
value = 5 = 0x5
-> write 5,0x4200,256
value = 256 = 0x100
-> ll "/tffs1"
Listing Directory /tffs1:
-rwxrwxrwx  1 0       0                  256 Jan  1  1980 hjj 
value = 0 = 0x0
->