mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-23 04:04:15 +08:00
move to components directory
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@634 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
Import('env')
|
||||
Import('rtconfig')
|
||||
Import('RTT_ROOT')
|
||||
|
||||
dfs = Split("""
|
||||
src/dfs_fs.c
|
||||
src/dfs_init.c
|
||||
src/dfs_posix.c
|
||||
src/dfs_raw.c
|
||||
src/dfs_util.c
|
||||
""")
|
||||
|
||||
# DFS-FatFs options
|
||||
fatfs = Split("""
|
||||
filesystems/fatfs/fatfs_cache.c
|
||||
filesystems/fatfs/fatfs_direntry.c
|
||||
filesystems/fatfs/fatfs_fat.c
|
||||
filesystems/fatfs/fatfs_file.c
|
||||
filesystems/fatfs/fatfs_filename.c
|
||||
filesystems/fatfs/fatfs_init.c
|
||||
filesystems/fatfs_misc.c
|
||||
filesystems/fatfs/fatfs_mount.c""")
|
||||
|
||||
# DFS-ELMFAT options
|
||||
elmfat = Split("""
|
||||
filesystems/elmfat/dfs_elm.c
|
||||
filesystems/elmfat/ff.c
|
||||
""")
|
||||
|
||||
# DFS-YAFFS2 options
|
||||
yaffs2_main = Split("""
|
||||
filesystems/yaffs2/direct/yaffscfg.c
|
||||
filesystems/yaffs2/direct/yaffs_fileem.c
|
||||
filesystems/yaffs2/direct/yaffsfs.c
|
||||
filesystems/yaffs2/direct/dfs_yaffs2.c
|
||||
""")
|
||||
|
||||
yaffs2_comm = Split("""
|
||||
filesystems/yaffs2/yaffs_ecc.c
|
||||
filesystems/yaffs2/yaffs_guts.c
|
||||
filesystems/yaffs2/yaffs_packedtags1.c
|
||||
filesystems/yaffs2/yaffs_tagscompat.c
|
||||
filesystems/yaffs2/yaffs_packedtags2.c
|
||||
filesystems/yaffs2/yaffs_tagsvalidity.c
|
||||
filesystems/yaffs2/yaffs_nand.c
|
||||
filesystems/yaffs2/yaffs_checkptrw.c
|
||||
filesystems/yaffs2/yaffs_qsort.c
|
||||
""")
|
||||
|
||||
# The set of source files associated with this SConscript file.
|
||||
src_local = dfs
|
||||
path = [RTT_ROOT + '/filesystem/dfs', RTT_ROOT + '/filesystem/dfs/include']
|
||||
|
||||
if rtconfig.RT_USING_DFS_YAFFS2:
|
||||
src_local = src_local + yaffs2_main + yaffs2_comm
|
||||
path = path + [RTT_ROOT + '/filesystem/dfs/filesystems/yaffs2', RTT_ROOT + '/filesystem/dfs/filesystems/yaffs2/direct']
|
||||
|
||||
if rtconfig.RT_USING_DFS_ELMFAT:
|
||||
src_local = src_local + elmfat
|
||||
path = path + [RTT_ROOT + '/filesystem/dfs/filesystems/elmfat']
|
||||
|
||||
env.Append(CPPPATH = path)
|
||||
|
||||
obj = env.Object(src_local)
|
||||
|
||||
Return('obj')
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Project : Device Filesystem
|
||||
+------------------------------------------------------------------------------
|
||||
| Copyright 2004, 2005 www.fayfayspace.org.
|
||||
| All rights reserved.
|
||||
|------------------------------------------------------------------------------
|
||||
| File : dfs_opts.h, the option definitions of Device FileSystem
|
||||
|------------------------------------------------------------------------------
|
||||
| Chang Logs:
|
||||
| Date Author Notes
|
||||
| 2005-01-22 ffxz The first version.
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef __DFS_CONFIG_H__
|
||||
#define __DFS_CONFIG_H__
|
||||
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Device Manager options
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
/* Device Options parameters */
|
||||
#define DEVICES_MAX 8
|
||||
#define DEVICE_NAME_MAX 8
|
||||
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Device Filesystem options
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
/* the max length of filesystem name */
|
||||
#define DFS_FS_NAME_MAX 4
|
||||
/* the max type of filesystem */
|
||||
#define DFS_FILESYSTEM_TYPES_MAX 2
|
||||
|
||||
/* the max length of path name */
|
||||
#define DFS_PATH_MAX 256
|
||||
/* the max length of file name */
|
||||
#define DFS_FILE_MAX 256
|
||||
|
||||
/* options for server task */
|
||||
#define DFS_MBOX_NUMBER 32
|
||||
#define DFS_SERVER_STACK 1024
|
||||
#define DFS_SERVER_PRI 110
|
||||
#define DFS_SERVER_SLICE 20
|
||||
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| FAT filesystem options
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
/* file name max length */
|
||||
#define FAT_NAME_MAX 256
|
||||
/* max number of FAT filesystem */
|
||||
#define FATFS_MAX 2
|
||||
|
||||
/* the size of sector */
|
||||
#define SECTOR_SIZE 512
|
||||
|
||||
/* FAT table sector cache options */
|
||||
#define FAT_CACHE_SIZE 0x10 /* config parameter */
|
||||
#define FAT_CACHE_MASK (FAT_CACHE_SIZE-1)
|
||||
|
||||
#define GET16(x) (*(x)) | (*((x)+1) << 8)
|
||||
#define GET32(x) (*(x)) | (*((x)+1) << 8) | (*((x)+2) << 16) | (*((x)+3) << 24)
|
||||
|
||||
#define SET16(x, v) \
|
||||
do \
|
||||
{ \
|
||||
*(x) = (v) & 0x00ff; \
|
||||
(*((x)+1)) = (v) >> 8; \
|
||||
} while ( 0 )
|
||||
|
||||
#define SET32(x, v) \
|
||||
do \
|
||||
{ \
|
||||
*(x) = (v) & 0x000000ff; \
|
||||
(*((x)+1)) = ((v) >> 8) & 0x000000ff; \
|
||||
(*((x)+2)) = ((v) >> 16) & 0x000000ff; \
|
||||
(*((x)+3)) = ((v) >> 24); \
|
||||
} while ( 0 )
|
||||
|
||||
#define DFS_DEBUG_INFO 0x01
|
||||
#define DFS_DEBUG_WARNING 0x02
|
||||
#define DFS_DEBUG_ERROR 0x04
|
||||
|
||||
#define DFS_DEBUG_LEVEL (DFS_DEBUG_INFO | DFS_DEBUG_WARNING | DFS_DEBUG_ERROR)
|
||||
|
||||
/* #define DFS_DEBUG */
|
||||
#ifdef DFS_DEBUG
|
||||
#define dfs_log(level, x) do { if (level & DFS_DEBUG_LEVEL) \
|
||||
{rt_kprintf("DFS %s, %d:", __FILE__, __LINE__); rt_kprintf x; \
|
||||
rt_kprintf ("\n");}}while (0)
|
||||
#else
|
||||
#define dfs_log(level, x)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,110 @@
|
||||
FatFs Module Source Files R0.07e (C)ChaN, 2009
|
||||
|
||||
|
||||
FILES
|
||||
|
||||
ffconf.h Configuration file for FatFs module.
|
||||
ff.h Common include file for FatFs and application module.
|
||||
ff.c FatFs module.
|
||||
diskio.h Common include file for FatFs and disk I/O module.
|
||||
diskio.c Skeleton of low level disk I/O module.
|
||||
integer.h Alternative type definitions for integer variables.
|
||||
option Optional external functions.
|
||||
|
||||
Low level disk I/O module is not included in this archive because the FatFs
|
||||
module is only a generic file system layer and not depend on any specific
|
||||
storage device. You have to provide a low level disk I/O module that written
|
||||
to control your storage device.
|
||||
|
||||
|
||||
|
||||
AGREEMENTS
|
||||
|
||||
FatFs module is an open source software to implement FAT file system to
|
||||
small embedded systems. This is a free software and is opened for education,
|
||||
research and commercial developments under license policy of following trems.
|
||||
|
||||
Copyright (C) 2009, ChaN, all right reserved.
|
||||
|
||||
* The FatFs module is a free software and there is NO WARRANTY.
|
||||
* No restriction on use. You can use, modify and redistribute it for
|
||||
personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
|
||||
* Redistributions of source code must retain the above copyright notice.
|
||||
|
||||
|
||||
|
||||
REVISION HISTORY
|
||||
|
||||
Feb 26, 2006 R0.00 Prototype
|
||||
|
||||
Apr 29, 2006 R0.01 First release.
|
||||
|
||||
Jun 01, 2006 R0.02 Added FAT12.
|
||||
Removed unbuffered mode.
|
||||
Fixed a problem on small (<32M) patition.
|
||||
|
||||
Jun 10, 2006 R0.02a Added a configuration option _FS_MINIMUM.
|
||||
|
||||
Sep 22, 2006 R0.03 Added f_rename.
|
||||
Changed option _FS_MINIMUM to _FS_MINIMIZE.
|
||||
|
||||
Dec 11, 2006 R0.03a Improved cluster scan algolithm to write files fast.
|
||||
Fixed f_mkdir creates incorrect directory on FAT32.
|
||||
|
||||
Feb 04, 2007 R0.04 Supported multiple drive system. (FatFs)
|
||||
Changed some APIs for multiple drive system.
|
||||
Added f_mkfs. (FatFs)
|
||||
Added _USE_FAT32 option. (Tiny-FatFs)
|
||||
|
||||
Apr 01, 2007 R0.04a Supported multiple partitions on a plysical drive. (FatFs)
|
||||
Fixed an endian sensitive code in f_mkfs. (FatFs)
|
||||
Added a capability of extending the file size to f_lseek.
|
||||
Added minimization level 3.
|
||||
Fixed a problem that can collapse a sector when recreate an
|
||||
existing file in any sub-directory at non FAT32 cfg. (Tiny-FatFs)
|
||||
|
||||
May 05, 2007 R0.04b Added _USE_NTFLAG option.
|
||||
Added FSInfo support.
|
||||
Fixed some problems corresponds to FAT32. (Tiny-FatFs)
|
||||
Fixed DBCS name can result FR_INVALID_NAME.
|
||||
Fixed short seek (0 < ofs <= csize) collapses the file object.
|
||||
|
||||
Aug 25, 2007 R0.05 Changed arguments of f_read, f_write.
|
||||
Changed arguments of f_mkfs. (FatFs)
|
||||
Fixed f_mkfs on FAT32 creates incorrect FSInfo. (FatFs)
|
||||
Fixed f_mkdir on FAT32 creates incorrect directory. (FatFs)
|
||||
|
||||
Feb 03, 2008 R0.05a Added f_truncate().
|
||||
Added f_utime().
|
||||
Fixed off by one error at FAT sub-type determination.
|
||||
Fixed btr in f_read() can be mistruncated.
|
||||
Fixed cached sector is not flushed when create and close without write.
|
||||
|
||||
Apr 01, 2008 R0.06 Added f_forward(). (Tiny-FatFs)
|
||||
Added string functions: fputc(), fputs(), fprintf() and fgets().
|
||||
Improved performance of f_lseek() on move to the same or following cluster.
|
||||
|
||||
Apr 01, 2009, R0.07 Merged Tiny-FatFs as a buffer configuration option.
|
||||
Added long file name support.
|
||||
Added multiple code page support.
|
||||
Added re-entrancy for multitask operation.
|
||||
Added auto cluster size selection to f_mkfs().
|
||||
Added rewind option to f_readdir().
|
||||
Changed result code of critical errors.
|
||||
Renamed string functions to avoid name collision.
|
||||
|
||||
Apr 14, 2009, R0.07a Separated out OS dependent code on reentrant cfg.
|
||||
Added multiple sector size support.
|
||||
|
||||
Jun 21, 2009, R0.07c Fixed f_unlink() may return FR_OK on error.
|
||||
Fixed wrong cache control in f_lseek().
|
||||
Added relative path feature.
|
||||
Added f_chdir().
|
||||
Added f_chdrive().
|
||||
Added proper case conversion for extended characters.
|
||||
|
||||
Nov 03,'2009 R0.07e Separated out configuration options from ff.h to ffconf.h.
|
||||
Added a configuration option, _LFN_UNICODE.
|
||||
Fixed f_unlink() fails to remove a sub-dir on _FS_RPATH.
|
||||
Fixed name matching error on the 13 char boundary.
|
||||
Changed f_readdir() to return the SFN with always upper case on non-LFN cfg.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,202 @@
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* This is a stub disk I/O module that acts as front end of the existing */
|
||||
/* disk I/O modules and attach it to FatFs module with common interface. */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#include "diskio.h"
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Correspondence between physical drive number and physical drive. */
|
||||
|
||||
#define ATA 0
|
||||
#define MMC 1
|
||||
#define USB 2
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Inidialize a Drive */
|
||||
|
||||
DSTATUS disk_initialize (
|
||||
BYTE drv /* Physical drive nmuber (0..) */
|
||||
)
|
||||
{
|
||||
DSTATUS stat;
|
||||
int result;
|
||||
|
||||
switch (drv) {
|
||||
case ATA :
|
||||
result = ATA_disk_initialize();
|
||||
// translate the reslut code here
|
||||
|
||||
return stat;
|
||||
|
||||
case MMC :
|
||||
result = MMC_disk_initialize();
|
||||
// translate the reslut code here
|
||||
|
||||
return stat;
|
||||
|
||||
case USB :
|
||||
result = USB_disk_initialize();
|
||||
// translate the reslut code here
|
||||
|
||||
return stat;
|
||||
}
|
||||
return STA_NOINIT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Return Disk Status */
|
||||
|
||||
DSTATUS disk_status (
|
||||
BYTE drv /* Physical drive nmuber (0..) */
|
||||
)
|
||||
{
|
||||
DSTATUS stat;
|
||||
int result;
|
||||
|
||||
switch (drv) {
|
||||
case ATA :
|
||||
result = ATA_disk_status();
|
||||
// translate the reslut code here
|
||||
|
||||
return stat;
|
||||
|
||||
case MMC :
|
||||
result = MMC_disk_status();
|
||||
// translate the reslut code here
|
||||
|
||||
return stat;
|
||||
|
||||
case USB :
|
||||
result = USB_disk_status();
|
||||
// translate the reslut code here
|
||||
|
||||
return stat;
|
||||
}
|
||||
return STA_NOINIT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Read Sector(s) */
|
||||
|
||||
DRESULT disk_read (
|
||||
BYTE drv, /* Physical drive nmuber (0..) */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
DWORD sector, /* Sector address (LBA) */
|
||||
BYTE count /* Number of sectors to read (1..255) */
|
||||
)
|
||||
{
|
||||
DRESULT res;
|
||||
int result;
|
||||
|
||||
switch (drv) {
|
||||
case ATA :
|
||||
result = ATA_disk_read(buff, sector, count);
|
||||
// translate the reslut code here
|
||||
|
||||
return res;
|
||||
|
||||
case MMC :
|
||||
result = MMC_disk_read(buff, sector, count);
|
||||
// translate the reslut code here
|
||||
|
||||
return res;
|
||||
|
||||
case USB :
|
||||
result = USB_disk_read(buff, sector, count);
|
||||
// translate the reslut code here
|
||||
|
||||
return res;
|
||||
}
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Write Sector(s) */
|
||||
|
||||
#if _READONLY == 0
|
||||
DRESULT disk_write (
|
||||
BYTE drv, /* Physical drive nmuber (0..) */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
DWORD sector, /* Sector address (LBA) */
|
||||
BYTE count /* Number of sectors to write (1..255) */
|
||||
)
|
||||
{
|
||||
DRESULT res;
|
||||
int result;
|
||||
|
||||
switch (drv) {
|
||||
case ATA :
|
||||
result = ATA_disk_write(buff, sector, count);
|
||||
// translate the reslut code here
|
||||
|
||||
return res;
|
||||
|
||||
case MMC :
|
||||
result = MMC_disk_write(buff, sector, count);
|
||||
// translate the reslut code here
|
||||
|
||||
return res;
|
||||
|
||||
case USB :
|
||||
result = USB_disk_write(buff, sector, count);
|
||||
// translate the reslut code here
|
||||
|
||||
return res;
|
||||
}
|
||||
return RES_PARERR;
|
||||
}
|
||||
#endif /* _READONLY */
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Miscellaneous Functions */
|
||||
|
||||
DRESULT disk_ioctl (
|
||||
BYTE drv, /* Physical drive nmuber (0..) */
|
||||
BYTE ctrl, /* Control code */
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
DRESULT res;
|
||||
int result;
|
||||
|
||||
switch (drv) {
|
||||
case ATA :
|
||||
// pre-process here
|
||||
|
||||
result = ATA_disk_ioctl(ctrl, buff);
|
||||
// post-process here
|
||||
|
||||
return res;
|
||||
|
||||
case MMC :
|
||||
// pre-process here
|
||||
|
||||
result = MMC_disk_ioctl(ctrl, buff);
|
||||
// post-process here
|
||||
|
||||
return res;
|
||||
|
||||
case USB :
|
||||
// pre-process here
|
||||
|
||||
result = USB_disk_ioctl(ctrl, buff);
|
||||
// post-process here
|
||||
|
||||
return res;
|
||||
}
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*-----------------------------------------------------------------------
|
||||
/ Low level disk interface modlue include file R0.07 (C)ChaN, 2009
|
||||
/-----------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _DISKIO
|
||||
|
||||
#define _READONLY 0 /* 1: Read-only mode */
|
||||
#define _USE_IOCTL 1
|
||||
|
||||
#include "integer.h"
|
||||
|
||||
|
||||
/* Status of Disk Functions */
|
||||
typedef BYTE DSTATUS;
|
||||
|
||||
/* Results of Disk Functions */
|
||||
typedef enum {
|
||||
RES_OK = 0, /* 0: Successful */
|
||||
RES_ERROR, /* 1: R/W Error */
|
||||
RES_WRPRT, /* 2: Write Protected */
|
||||
RES_NOTRDY, /* 3: Not Ready */
|
||||
RES_PARERR /* 4: Invalid Parameter */
|
||||
} DRESULT;
|
||||
|
||||
|
||||
/*---------------------------------------*/
|
||||
/* Prototypes for disk control functions */
|
||||
|
||||
BOOL assign_drives (int argc, char *argv[]);
|
||||
DSTATUS disk_initialize (BYTE);
|
||||
DSTATUS disk_status (BYTE);
|
||||
DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE);
|
||||
#if _READONLY == 0
|
||||
DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE);
|
||||
#endif
|
||||
DRESULT disk_ioctl (BYTE, BYTE, void*);
|
||||
|
||||
|
||||
|
||||
/* Disk Status Bits (DSTATUS) */
|
||||
|
||||
#define STA_NOINIT 0x01 /* Drive not initialized */
|
||||
#define STA_NODISK 0x02 /* No medium in the drive */
|
||||
#define STA_PROTECT 0x04 /* Write protected */
|
||||
|
||||
|
||||
/* Command code for disk_ioctrl() */
|
||||
|
||||
/* Generic command */
|
||||
#define CTRL_SYNC 0 /* Mandatory for write functions */
|
||||
#define GET_SECTOR_COUNT 1 /* Mandatory for only f_mkfs() */
|
||||
#define GET_SECTOR_SIZE 2 /* Mandatory for multiple sector size cfg */
|
||||
#define GET_BLOCK_SIZE 3 /* Mandatory for only f_mkfs() */
|
||||
#define CTRL_POWER 4
|
||||
#define CTRL_LOCK 5
|
||||
#define CTRL_EJECT 6
|
||||
/* MMC/SDC command */
|
||||
#define MMC_GET_TYPE 10
|
||||
#define MMC_GET_CSD 11
|
||||
#define MMC_GET_CID 12
|
||||
#define MMC_GET_OCR 13
|
||||
#define MMC_GET_SDSTAT 14
|
||||
/* ATA/CF command */
|
||||
#define ATA_GET_REV 20
|
||||
#define ATA_GET_MODEL 21
|
||||
#define ATA_GET_SN 22
|
||||
|
||||
|
||||
#define _DISKIO
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,172 @@
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ FatFs - FAT file system module configuration file R0.07e (C)ChaN, 2009
|
||||
/----------------------------------------------------------------------------/
|
||||
/
|
||||
/ CAUTION! Do not forget to make clean the project after any changes to
|
||||
/ the configuration options.
|
||||
/
|
||||
/----------------------------------------------------------------------------*/
|
||||
#ifndef _FFCONFIG
|
||||
#define _FFCONFIG 0x007E
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Function and Buffer Configurations
|
||||
/----------------------------------------------------------------------------*/
|
||||
|
||||
#define _FS_TINY 0 /* 0 or 1 */
|
||||
/* When _FS_TINY is set to 1, FatFs uses the sector buffer in the file system
|
||||
/ object instead of the sector buffer in the individual file object for file
|
||||
/ data transfer. This reduces memory consumption 512 bytes each file object. */
|
||||
|
||||
|
||||
#define _FS_READONLY 0 /* 0 or 1 */
|
||||
/* Setting _FS_READONLY to 1 defines read only configuration. This removes
|
||||
/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename,
|
||||
/ f_truncate and useless f_getfree. */
|
||||
|
||||
|
||||
#define _FS_MINIMIZE 0 /* 0, 1, 2 or 3 */
|
||||
/* The _FS_MINIMIZE option defines minimization level to remove some functions.
|
||||
/
|
||||
/ 0: Full function.
|
||||
/ 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod, f_truncate and f_rename
|
||||
/ are removed.
|
||||
/ 2: f_opendir and f_readdir are removed in addition to level 1.
|
||||
/ 3: f_lseek is removed in addition to level 2. */
|
||||
|
||||
|
||||
#define _USE_STRFUNC 0 /* 0, 1 or 2 */
|
||||
/* To enable string functions, set _USE_STRFUNC to 1 or 2. */
|
||||
|
||||
|
||||
#define _USE_MKFS 0 /* 0 or 1 */
|
||||
/* To enable f_mkfs function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */
|
||||
|
||||
|
||||
#define _USE_FORWARD 0 /* 0 or 1 */
|
||||
/* To enable f_forward function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Locale and Namespace Configurations
|
||||
/----------------------------------------------------------------------------*/
|
||||
|
||||
#define _CODE_PAGE 936
|
||||
/* The _CODE_PAGE specifies the OEM code page to be used on the target system.
|
||||
/ Incorrect setting of the code page can cause a file open failure.
|
||||
/
|
||||
/ 932 - Japanese Shift-JIS (DBCS, OEM, Windows)
|
||||
/ 936 - Simplified Chinese GBK (DBCS, OEM, Windows)
|
||||
/ 949 - Korean (DBCS, OEM, Windows)
|
||||
/ 950 - Traditional Chinese Big5 (DBCS, OEM, Windows)
|
||||
/ 1250 - Central Europe (Windows)
|
||||
/ 1251 - Cyrillic (Windows)
|
||||
/ 1252 - Latin 1 (Windows)
|
||||
/ 1253 - Greek (Windows)
|
||||
/ 1254 - Turkish (Windows)
|
||||
/ 1255 - Hebrew (Windows)
|
||||
/ 1256 - Arabic (Windows)
|
||||
/ 1257 - Baltic (Windows)
|
||||
/ 1258 - Vietnam (OEM, Windows)
|
||||
/ 437 - U.S. (OEM)
|
||||
/ 720 - Arabic (OEM)
|
||||
/ 737 - Greek (OEM)
|
||||
/ 775 - Baltic (OEM)
|
||||
/ 850 - Multilingual Latin 1 (OEM)
|
||||
/ 858 - Multilingual Latin 1 + Euro (OEM)
|
||||
/ 852 - Latin 2 (OEM)
|
||||
/ 855 - Cyrillic (OEM)
|
||||
/ 866 - Russian (OEM)
|
||||
/ 857 - Turkish (OEM)
|
||||
/ 862 - Hebrew (OEM)
|
||||
/ 874 - Thai (OEM, Windows)
|
||||
/ 1 - ASCII only (Valid for non LFN cfg.)
|
||||
*/
|
||||
|
||||
|
||||
#define _USE_LFN 0 /* 0, 1 or 2 */
|
||||
#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
|
||||
/* The _USE_LFN option switches the LFN support.
|
||||
/
|
||||
/ 0: Disable LFN. _MAX_LFN and _LFN_UNICODE have no effect.
|
||||
/ 1: Enable LFN with static working buffer on the bss. NOT REENTRANT.
|
||||
/ 2: Enable LFN with dynamic working buffer on the STACK.
|
||||
/
|
||||
/ The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. When enable LFN,
|
||||
/ two Unicode handling functions ff_convert() and ff_wtoupper() must be added
|
||||
/ to the project. */
|
||||
|
||||
|
||||
#define _LFN_UNICODE 0 /* 0 or 1 */
|
||||
/* To switch the character code set on FatFs API to Unicode,
|
||||
/ enable LFN feature and set _LFN_UNICODE to 1.
|
||||
*/
|
||||
|
||||
|
||||
#define _FS_RPATH 0 /* 0 or 1 */
|
||||
/* When _FS_RPATH is set to 1, relative path feature is enabled and f_chdir,
|
||||
/ f_chdrive function are available.
|
||||
/ Note that output of the f_readdir fnction is affected by this option. */
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Physical Drive Configurations
|
||||
/----------------------------------------------------------------------------*/
|
||||
#ifdef RT_DFS_ELM_DRIVES
|
||||
#define _DRIVES RT_DFS_ELM_DRIVES
|
||||
#else
|
||||
#define _DRIVES 1
|
||||
#endif
|
||||
/* Number of volumes (logical drives) to be used. */
|
||||
|
||||
|
||||
#define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */
|
||||
/* Maximum sector size to be handled.
|
||||
/ Always set 512 for memory card and hard disk but a larger value may be
|
||||
/ required for floppy disk (512/1024) and optical disk (512/2048).
|
||||
/ When _MAX_SS is larger than 512, GET_SECTOR_SIZE command must be implememted
|
||||
/ to the disk_ioctl function. */
|
||||
|
||||
|
||||
#define _MULTI_PARTITION 0 /* 0 or 1 */
|
||||
/* When _MULTI_PARTITION is set to 0, each volume is bound to the same physical
|
||||
/ drive number and can mount only first primaly partition. When it is set to 1,
|
||||
/ each volume is tied to the partitions listed in Drives[]. */
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ System Configurations
|
||||
/----------------------------------------------------------------------------*/
|
||||
#ifdef RT_DFS_ELM_WORD_ACCESS
|
||||
#define _WORD_ACCESS 1
|
||||
#else
|
||||
#define _WORD_ACCESS 0
|
||||
#endif
|
||||
|
||||
/* The _WORD_ACCESS option defines which access method is used to the word
|
||||
/ data on the FAT volume.
|
||||
/
|
||||
/ 0: Byte-by-byte access. Always compatible with all platforms.
|
||||
/ 1: Word access. Do not choose this unless following condition is met.
|
||||
/
|
||||
/ When the byte order on the memory is big-endian or address miss-aligned
|
||||
/ word access results incorrect behavior, the _WORD_ACCESS must be set to 0.
|
||||
/ If it is not the case, the value can also be set to 1 to improve the
|
||||
/ performance and code size. */
|
||||
|
||||
|
||||
#define _FS_REENTRANT 0 /* 0 or 1 */
|
||||
#define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */
|
||||
#define _SYNC_t rt_mutex_t /* O/S dependent type of sync object. e.g. HANDLE, OS_EVENT*, ID and etc.. */
|
||||
/* The _FS_REENTRANT option switches the reentrancy of the FatFs module.
|
||||
/
|
||||
/ 0: Disable reentrancy. _SYNC_t and _FS_TIMEOUT have no effect.
|
||||
/ 1: Enable reentrancy. Also user provided synchronization handlers,
|
||||
/ ff_req_grant, ff_rel_grant, ff_del_syncobj and ff_cre_syncobj
|
||||
/ function must be added to the project. */
|
||||
|
||||
|
||||
#endif /* _FFCONFIG */
|
||||
@@ -0,0 +1,37 @@
|
||||
/*-------------------------------------------*/
|
||||
/* Integer type definitions for FatFs module */
|
||||
/*-------------------------------------------*/
|
||||
|
||||
#ifndef _INTEGER
|
||||
|
||||
#if 0
|
||||
#include <windows.h>
|
||||
#else
|
||||
|
||||
/* These types must be 16-bit, 32-bit or larger integer */
|
||||
typedef int INT;
|
||||
typedef unsigned int UINT;
|
||||
|
||||
/* These types must be 8-bit integer */
|
||||
typedef signed char CHAR;
|
||||
typedef unsigned char UCHAR;
|
||||
typedef unsigned char BYTE;
|
||||
|
||||
/* These types must be 16-bit integer */
|
||||
typedef short SHORT;
|
||||
typedef unsigned short USHORT;
|
||||
typedef unsigned short WORD;
|
||||
typedef unsigned short WCHAR;
|
||||
|
||||
/* These types must be 32-bit integer */
|
||||
typedef long LONG;
|
||||
typedef unsigned long ULONG;
|
||||
typedef unsigned long DWORD;
|
||||
|
||||
/* Boolean type */
|
||||
typedef enum { FALSE = 0, TRUE } BOOL;
|
||||
|
||||
#endif
|
||||
|
||||
#define _INTEGER
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,115 @@
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Sample code of OS dependent synchronization object controls */
|
||||
/* for FatFs R0.07d (C)ChaN, 2009 */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
#include <windows.h> // Win32
|
||||
//#include <ucos_ii.h> // uC/OS-II
|
||||
|
||||
#include "../ff.h"
|
||||
|
||||
#if _FS_REENTRANT
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Create a Synchronization Object for a Volume
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called in f_mount function to create a new
|
||||
/ synchronization object, such as semaphore and mutex. When a FALSE is
|
||||
/ returned, the f_mount function fails with FR_INT_ERR.
|
||||
*/
|
||||
|
||||
BOOL ff_cre_syncobj ( /* TRUE:Function succeeded, FALSE:Could not create due to any error */
|
||||
BYTE vol, /* Corresponding logical drive being processed */
|
||||
_SYNC_t *sobj /* Pointer to return the created sync object */
|
||||
)
|
||||
{
|
||||
BOOL ret;
|
||||
|
||||
*sobj = CreateMutex(NULL, FALSE, NULL); // Win32
|
||||
ret = (*sobj != INVALID_HANDLE_VALUE) ? TRUE : FALSE; //
|
||||
|
||||
// *sobj = VolumeSemId[vol]; // uITRON (give a static created sync object)
|
||||
// ret = TRUE; // The initial value of the semaphore must be 1.
|
||||
|
||||
// *sobj = OSMutexCreate(0, &err); // uC/OS-II
|
||||
// ret = (err == OS_NO_ERR) ? TRUE : FALSE; //
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Delete a Synchronization Object */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called in f_mount function to delete a synchronization
|
||||
/ object that created with ff_cre_syncobj function. When a FALSE is
|
||||
/ returned, the f_mount function fails with FR_INT_ERR.
|
||||
*/
|
||||
|
||||
BOOL ff_del_syncobj ( /* TRUE:Function succeeded, FALSE:Could not delete due to any error */
|
||||
_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
|
||||
)
|
||||
{
|
||||
BOOL ret;
|
||||
|
||||
ret = CloseHandle(sobj); // Win32
|
||||
|
||||
// ret = TRUE; // uITRON (nothing to do)
|
||||
|
||||
// OSMutexDel(sobj, OS_DEL_ALWAYS, &err); // uC/OS-II
|
||||
// ret = (err == OS_NO_ERR) ? TRUE : FALSE; //
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Request Grant to Access the Volume */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called on entering file functions to lock the volume.
|
||||
/ When a FALSE is returned, the file function fails with FR_TIMEOUT.
|
||||
*/
|
||||
|
||||
BOOL ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */
|
||||
_SYNC_t sobj /* Sync object to wait */
|
||||
)
|
||||
{
|
||||
BOOL ret;
|
||||
|
||||
ret = (WaitForSingleObject(sobj, _FS_TIMEOUT) == WAIT_OBJECT_0) ? TRUE : FALSE; // Win32
|
||||
|
||||
// ret = (wai_sem(sobj) == E_OK) ? TRUE : FALSE; // uITRON
|
||||
|
||||
// OSMutexPend(sobj, _FS_TIMEOUT, &err)); // uC/OS-II
|
||||
// ret = (err == OS_NO_ERR) ? TRUE : FALSE; //
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Release Grant to Access the Volume */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called on leaving file functions to unlock the volume.
|
||||
*/
|
||||
|
||||
void ff_rel_grant (
|
||||
_SYNC_t sobj /* Sync object to be signaled */
|
||||
)
|
||||
{
|
||||
ReleaseMutex(sobj); // Win32
|
||||
|
||||
// sig_sem(sobj); // uITRON
|
||||
|
||||
// OSMutexPost(sobj); // uC/OS-II
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#error This file is not needed in this configuration.
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Device FileSystem
|
||||
+------------------------------------------------------------------------------
|
||||
| Copyright 2004, 2005 www.fayfayspace.org.
|
||||
| All rights reserved.
|
||||
|------------------------------------------------------------------------------
|
||||
| File : dfs_def.h, the definitions of Device FileSystem
|
||||
|------------------------------------------------------------------------------
|
||||
| Chang Logs:
|
||||
| Date Author notes
|
||||
| 2004-10-01 ffxz The first version.
|
||||
| 2004-10-14 ffxz Clean up the code.
|
||||
| 2005-01-22 ffxz Clean up the code, port to MinGW
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef __DFS_DEF_H__
|
||||
#define __DFS_DEF_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <dfs_config.h>
|
||||
|
||||
#if defined(RT_USING_NEWLIB) || defined (RT_USING_MINILIBC)
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#ifndef __D_FS__
|
||||
#define __D_FS__
|
||||
#endif
|
||||
|
||||
/* Device error codes */
|
||||
#define DFS_STATUS_OK 0 /* no error */
|
||||
#define DFS_STATUS_ENOENT 2 /* No such file or directory */
|
||||
#define DFS_STATUS_EIO 5 /* I/O error */
|
||||
#define DFS_STATUS_ENXIO 6 /* No such device or address */
|
||||
#define DFS_STATUS_EBADF 9 /* Bad file number */
|
||||
#define DFS_STATUS_EAGIAN 11 /* Try again */
|
||||
#define DFS_STATUS_ENOMEM 12 /* no memory */
|
||||
#define DFS_STATUS_EBUSY 16 /* Device or resource busy */
|
||||
#define DFS_STATUS_EEXIST 17 /* File exists */
|
||||
#define DFS_STATUS_EXDEV 18 /* Cross-device link */
|
||||
#define DFS_STATUS_ENODEV 19 /* No such device */
|
||||
#define DFS_STATUS_ENOTDIR 20 /* Not a directory */
|
||||
#define DFS_STATUS_EISDIR 21 /* Is a directory */
|
||||
#define DFS_STATUS_EINVAL 22 /* Invalid argument */
|
||||
#define DFS_STATUS_ENOSPC 28 /* No space left on device */
|
||||
#define DFS_STATUS_EROFS 30 /* Read-only file system */
|
||||
#define DFS_STATUS_ENOSYS 38 /* Function not implemented */
|
||||
#define DFS_STATUS_ENOTEMPTY 39 /* Directory not empty */
|
||||
#define DFS_STATUS_EMMOUNT 128 /* Filesystem table full */
|
||||
|
||||
/* Operation flags */
|
||||
#define DFS_O_RDONLY 0000000
|
||||
#define DFS_O_WRONLY 0000001
|
||||
#define DFS_O_RDWR 0000002
|
||||
#define DFS_O_ACCMODE 0000003
|
||||
#define DFS_O_CREAT 0000100
|
||||
#define DFS_O_EXCL 0000200
|
||||
#define DFS_O_TRUNC 0001000
|
||||
#define DFS_O_APPEND 0002000
|
||||
#define DFS_O_DIRECTORY 0200000
|
||||
|
||||
/* File flags */
|
||||
#define DFS_F_OPEN 0x01000000
|
||||
#define DFS_F_DIRECTORY 0x02000000
|
||||
#define DFS_F_EOF 0x04000000
|
||||
#define DFS_F_ERR 0x08000000
|
||||
|
||||
/* Seek flags */
|
||||
#define DFS_SEEK_SET 0
|
||||
#define DFS_SEEK_CUR 1
|
||||
#define DFS_SEEK_END 2
|
||||
|
||||
/* Stat codes */
|
||||
#define DFS_S_IFMT 00170000
|
||||
#define DFS_S_IFSOCK 0140000
|
||||
#define DFS_S_IFLNK 0120000
|
||||
#define DFS_S_IFREG 0100000
|
||||
#define DFS_S_IFBLK 0060000
|
||||
#define DFS_S_IFDIR 0040000
|
||||
#define DFS_S_IFCHR 0020000
|
||||
#define DFS_S_IFIFO 0010000
|
||||
#define DFS_S_ISUID 0004000
|
||||
#define DFS_S_ISGID 0002000
|
||||
#define DFS_S_ISVTX 0001000
|
||||
|
||||
#define DFS_S_ISLNK(m) (((m) & DFS_S_IFMT) == DFS_S_IFLNK)
|
||||
#define DFS_S_ISREG(m) (((m) & DFS_S_IFMT) == DFS_S_IFREG)
|
||||
#define DFS_S_ISDIR(m) (((m) & DFS_S_IFMT) == DFS_S_IFDIR)
|
||||
#define DFS_S_ISCHR(m) (((m) & DFS_S_IFMT) == DFS_S_IFCHR)
|
||||
#define DFS_S_ISBLK(m) (((m) & DFS_S_IFMT) == DFS_S_IFBLK)
|
||||
#define DFS_S_ISFIFO(m) (((m) & DFS_S_IFMT) == DFS_S_IFIFO)
|
||||
#define DFS_S_ISSOCK(m) (((m) & DFS_S_IFMT) == DFS_S_IFSOCK)
|
||||
|
||||
#define DFS_S_IRWXU 00700
|
||||
#define DFS_S_IRUSR 00400
|
||||
#define DFS_S_IWUSR 00200
|
||||
#define DFS_S_IXUSR 00100
|
||||
|
||||
#define DFS_S_IRWXG 00070
|
||||
#define DFS_S_IRGRP 00040
|
||||
#define DFS_S_IWGRP 00020
|
||||
#define DFS_S_IXGRP 00010
|
||||
|
||||
#define DFS_S_IRWXO 00007
|
||||
#define DFS_S_IROTH 00004
|
||||
#define DFS_S_IWOTH 00002
|
||||
#define DFS_S_IXOTH 00001
|
||||
|
||||
#define DEVICE_GETGEOME 0
|
||||
#define DEVICE_GETINFO 1
|
||||
#define DEVICE_FORMAT 2
|
||||
#define DEVICE_CLEAN_SECTOR 3
|
||||
|
||||
struct device_geometry
|
||||
{
|
||||
rt_uint32_t sector_count; /* count of sectors */
|
||||
rt_uint32_t cylinder_count; /* count of cylinder */
|
||||
rt_uint32_t sectors_per_track; /* number of sectors per track */
|
||||
rt_uint32_t head_count; /* count of head */
|
||||
rt_uint32_t bytes_per_sector; /* number of bytes per sector */
|
||||
};
|
||||
|
||||
struct dfs_stat
|
||||
{
|
||||
rt_device_t st_dev;
|
||||
rt_uint16_t st_mode;
|
||||
rt_uint32_t st_size;
|
||||
rt_time_t st_mtime;
|
||||
rt_uint32_t st_blksize;
|
||||
};
|
||||
#define stat dfs_stat
|
||||
|
||||
/* File types */
|
||||
#define FT_REGULAR 0 /* regular file */
|
||||
#define FT_SOCKET 1 /* socket file */
|
||||
#define FT_DIRECTORY 2 /* directory */
|
||||
#define FT_USER 3 /* user defined */
|
||||
|
||||
/* file descriptor */
|
||||
struct dfs_fd
|
||||
{
|
||||
char path[DFS_PATH_MAX + 1];/* Name (below mount point) */
|
||||
int type; /* Type (regular or socket) */
|
||||
int ref_count; /* Descriptor reference count */
|
||||
|
||||
struct dfs_filesystem* fs; /* Resident file system */
|
||||
|
||||
rt_uint32_t flags; /* Descriptor flags */
|
||||
rt_size_t size; /* Size in bytes */
|
||||
rt_off_t pos; /* Current file position */
|
||||
|
||||
void *data; /* Specific file system data */
|
||||
};
|
||||
|
||||
#define DFS_DT_UNKNOWN 0x00
|
||||
#define DFS_DT_REG 0x01
|
||||
#define DFS_DT_DIR 0x02
|
||||
|
||||
struct dfs_dirent
|
||||
{
|
||||
rt_uint8_t d_type; /* The type of the file */
|
||||
rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */
|
||||
rt_uint16_t d_reclen; /* length of this record */
|
||||
char d_name[256]; /* The null-terminated file name */
|
||||
};
|
||||
#define dirent dfs_dirent
|
||||
|
||||
struct dfs_session
|
||||
{
|
||||
rt_mailbox_t mbox;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Project : Device Filesystem
|
||||
+------------------------------------------------------------------------------
|
||||
| Copyright 2004, 2005 www.fayfayspace.org.
|
||||
| All rights reserved.
|
||||
|------------------------------------------------------------------------------
|
||||
| File : dfs_efs.h
|
||||
|------------------------------------------------------------------------------
|
||||
| Chang Logs:
|
||||
| Date Author Notes
|
||||
| 2010-02-06 Bernard Add elm_init function declaration
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef __DFS_ELM_H__
|
||||
#define __DFS_ELM_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int elm_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Project : Device Filesystem
|
||||
+------------------------------------------------------------------------------
|
||||
| Copyright 2004, 2005 www.fayfayspace.org.
|
||||
| All rights reserved.
|
||||
|------------------------------------------------------------------------------
|
||||
| File : dfs_fat.h, FAT 12/16/32 file system definitions
|
||||
|------------------------------------------------------------------------------
|
||||
| Chang Logs:
|
||||
| Date Author Notes
|
||||
| 2003-03-30 ffxz
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef __DFS_FAT_H__
|
||||
#define __DFS_FAT_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int fatfs_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Project : Device Filesystem
|
||||
+------------------------------------------------------------------------------
|
||||
| Copyright 2004, 2005 www.fayfayspace.org.
|
||||
| All rights reserved.
|
||||
|------------------------------------------------------------------------------
|
||||
| File : dfs_fs.h, the filesystem related defines of Device FileSystem
|
||||
|------------------------------------------------------------------------------
|
||||
| Chang Logs:
|
||||
| Date Author Notes
|
||||
| 2005-02-22 ffxz The first version.
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef __DFS_FS_H__
|
||||
#define __DFS_FS_H__
|
||||
|
||||
#include <dfs_def.h>
|
||||
#include <dfs_config.h>
|
||||
|
||||
/* Pre-declaration */
|
||||
struct dfs_filesystem;
|
||||
struct dfs_fd;
|
||||
struct dfs_dirent;
|
||||
|
||||
/* File system operations struct */
|
||||
struct dfs_filesystem_operation
|
||||
{
|
||||
char name[DFS_FS_NAME_MAX + 1];
|
||||
|
||||
int (*mount) (struct dfs_filesystem* fs);
|
||||
int (*unmount) (struct dfs_filesystem* fs);
|
||||
|
||||
int (*open) (struct dfs_fd* fd);
|
||||
int (*close) (struct dfs_fd* fd);
|
||||
int (*ioctl) (struct dfs_fd* fd, int cmd, void *args);
|
||||
int (*read) (struct dfs_fd* fd, void* buf, rt_size_t count);
|
||||
int (*write) (struct dfs_fd* fd, const void* buf, rt_size_t count);
|
||||
int (*lseek) (struct dfs_fd* fd, rt_off_t offset);
|
||||
int (*getdents) (struct dfs_fd* fd, struct dfs_dirent* dirp, rt_uint32_t count);
|
||||
|
||||
int (*unlink) (struct dfs_filesystem* fs, const char* pathname);
|
||||
int (*stat) (struct dfs_filesystem* fs, const char* filename, struct dfs_stat* buf);
|
||||
int (*rename) (struct dfs_filesystem* fs, const char* oldpath, const char* newpath);
|
||||
};
|
||||
|
||||
/* Mounted file system */
|
||||
struct dfs_filesystem
|
||||
{
|
||||
rt_device_t dev_id; /* Attached device */
|
||||
|
||||
char path[DFS_PATH_MAX + 1]; /* File system mount point */
|
||||
struct dfs_filesystem_operation* ops; /* Operations for file system type */
|
||||
rt_uint32_t block_id; /* Current block_id on attached device */
|
||||
|
||||
void *data; /* Specific file system data */
|
||||
};
|
||||
|
||||
/* file system partition table */
|
||||
struct dfs_partition
|
||||
{
|
||||
rt_uint8_t type; /* file system type */
|
||||
rt_off_t offset; /* partition start offset */
|
||||
rt_size_t size; /* partition size */
|
||||
rt_sem_t lock;
|
||||
};
|
||||
|
||||
int dfs_register(struct dfs_filesystem_operation* ops);
|
||||
struct dfs_filesystem* dfs_filesystem_lookup(const char *path);
|
||||
rt_err_t dfs_filesystem_get_partition(struct dfs_partition* part, rt_uint8_t* buf, rt_uint32_t pindex);
|
||||
|
||||
int dfs_mount(const char* device_name, const char* path,
|
||||
const char* filesystemtype, rt_uint32_t rwflag, const
|
||||
void* data);
|
||||
int dfs_unmount(const char *specialfile);
|
||||
|
||||
/* extern variable */
|
||||
extern struct dfs_filesystem_operation* filesystem_operation_table[];
|
||||
extern struct dfs_filesystem filesystem_table[];
|
||||
|
||||
extern char working_directory[];
|
||||
|
||||
void dfs_lock(void);
|
||||
void dfs_unlock(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
|
||||
+------------------------------------------------------------------------------
|
||||
|
||||
| Project : Device Filesystem
|
||||
|
||||
+------------------------------------------------------------------------------
|
||||
|
||||
| Copyright 2004, 2005 www.fayfayspace.org.
|
||||
|
||||
| All rights reserved.
|
||||
|
||||
|------------------------------------------------------------------------------
|
||||
|
||||
| File : dfs_init.h, the initilization definitions of Device FileSystem
|
||||
|------------------------------------------------------------------------------
|
||||
| Chang Logs:
|
||||
|
||||
| Date Author Notes
|
||||
|
||||
| 2005-02-21 ffxz The first version.
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef __DFS_INIT_H__
|
||||
#define __DFS_INIT_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* initilization of dfs */
|
||||
void dfs_init(void);
|
||||
|
||||
/* initilization of dfs with filesystem server */
|
||||
void dfs_server_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Project : Device Filesystem
|
||||
+------------------------------------------------------------------------------
|
||||
| Copyright 2004, 2005 www.fayfayspace.org.
|
||||
| All rights reserved.
|
||||
|------------------------------------------------------------------------------
|
||||
| File : dfs_posix.h, the filesystem related defines of Device FileSystem
|
||||
|------------------------------------------------------------------------------
|
||||
| Chang Logs:
|
||||
| Date Author Notes
|
||||
| 2009-05-27 Yi.qiu The first version.
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef __DFS_POSIX_H__
|
||||
#define __DFS_POSIX_H__
|
||||
|
||||
#include <dfs_raw.h>
|
||||
|
||||
#define O_RDONLY DFS_O_RDONLY
|
||||
#define O_WRONLY DFS_O_WRONLY
|
||||
#define O_RDWR DFS_O_RDWR
|
||||
#define O_ACCMODE DFS_O_ACCMODE
|
||||
#define O_CREAT DFS_O_CREAT
|
||||
#define O_EXCL DFS_O_EXCL
|
||||
#define O_TRUNC DFS_O_TRUNC
|
||||
#define O_APPEND DFS_O_APPEND
|
||||
#define O_DIRECTORY DFS_O_DIRECTORY
|
||||
|
||||
#define S_IFMT DFS_S_IFMT
|
||||
#define S_IFSOCK DFS_S_IFSOCK
|
||||
#define S_IFLNK DFS_S_IFLNK
|
||||
#define S_IFREG DFS_S_IFREG
|
||||
#define S_IFBLK DFS_S_IFBLK
|
||||
#define S_IFDIR DFS_S_IFDIR
|
||||
#define S_IFCHR DFS_S_IFCHR
|
||||
#define S_IFIFO DFS_S_IFIFO
|
||||
#define S_ISUID DFS_S_ISUID
|
||||
#define S_ISGID DFS_S_ISGID
|
||||
#define S_ISVTX DFS_S_ISVTX
|
||||
|
||||
#define S_ISLNK(m) (((m) & DFS_S_IFMT) == DFS_S_IFLNK)
|
||||
#define S_ISREG(m) (((m) & DFS_S_IFMT) == DFS_S_IFREG)
|
||||
#define S_ISDIR(m) (((m) & DFS_S_IFMT) == DFS_S_IFDIR)
|
||||
#define S_ISCHR(m) (((m) & DFS_S_IFMT) == DFS_S_IFCHR)
|
||||
#define S_ISBLK(m) (((m) & DFS_S_IFMT) == DFS_S_IFBLK)
|
||||
#define S_ISFIFO(m) (((m) & DFS_S_IFMT) == DFS_S_IFIFO)
|
||||
#define S_ISSOCK(m) (((m) & DFS_S_IFMT) == DFS_S_IFSOCK)
|
||||
|
||||
#define S_IRWXU DFS_S_IRWXU
|
||||
#define S_IRUSR DFS_S_IRUSR
|
||||
#define S_IWUSR DFS_S_IWUSR
|
||||
#define S_IXUSR DFS_S_IXUSR
|
||||
|
||||
#define S_IRWXG DFS_S_IRWXG
|
||||
#define S_IRGRP DFS_S_IRGRP
|
||||
#define S_IWGRP DFS_S_IWGRP
|
||||
#define S_IXGRP DFS_S_IXGRP
|
||||
|
||||
#define S_IRWXO DFS_S_IRWXO
|
||||
#define S_IROTH DFS_S_IROTH
|
||||
#define S_IWOTH DFS_S_IWOTH
|
||||
#define S_IXOTH DFS_S_IXOTH
|
||||
|
||||
#define SEEK_SET DFS_SEEK_SET
|
||||
#define SEEK_CUR DFS_SEEK_CUR
|
||||
#define SEEK_END DFS_SEEK_END
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int fd; /* directory file */
|
||||
char buf[512];
|
||||
int num;
|
||||
int cur;
|
||||
} DIR;
|
||||
|
||||
/* file api*/
|
||||
int open(const char *file, int flags, int mode);
|
||||
int close(int d);
|
||||
int read(int fd, char *buf, int len);
|
||||
int write(int fd, char *buf, int len);
|
||||
int lseek(int fd, int offset, int dir);
|
||||
int rename(const char* old, const char* new );
|
||||
int unlink(const char *pathname);
|
||||
int stat(const char *file, struct dfs_stat *buf);
|
||||
|
||||
/* directory api*/
|
||||
int mkdir (const char *path, rt_uint16_t mode);
|
||||
int rmdir(const char *path);
|
||||
DIR* opendir(const char* name);
|
||||
struct dfs_dirent* readdir(DIR *d);
|
||||
rt_off_t telldir(DIR *d);
|
||||
void seekdir(DIR *d, rt_off_t offset);
|
||||
void rewinddir(DIR *d);
|
||||
int closedir(DIR* d);
|
||||
int chdir(const char *path);
|
||||
char* getcwd(char *buf, rt_size_t size);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Project : Device Filesystem
|
||||
+------------------------------------------------------------------------------
|
||||
| Copyright 2004, 2005 www.fayfayspace.org.
|
||||
| All rights reserved.
|
||||
|------------------------------------------------------------------------------
|
||||
| File : dfs_raw.h, the raw APIs of Device FileSystem
|
||||
|------------------------------------------------------------------------------
|
||||
| Chang Logs:
|
||||
| Date Author Notes
|
||||
| 2005-01-26 ffxz The first version
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef __DFS_RAW_H__
|
||||
#define __DFS_RAW_H__
|
||||
|
||||
#include <dfs_def.h>
|
||||
#include <dfs_fs.h>
|
||||
|
||||
int dfile_raw_open(struct dfs_fd* fd, const char *path, int flags);
|
||||
int dfile_raw_close(struct dfs_fd* fd);
|
||||
int dfile_raw_ioctl(struct dfs_fd* fd, int cmd, void *args);
|
||||
int dfile_raw_read(struct dfs_fd* fd, void *buf, rt_size_t len);
|
||||
int dfile_raw_getdents(struct dfs_fd* fd, struct dfs_dirent* dirp, rt_size_t nbytes);
|
||||
int dfile_raw_unlink(const char *path);
|
||||
int dfile_raw_write(struct dfs_fd* fd, const void *buf, rt_size_t len);
|
||||
int dfile_raw_lseek(struct dfs_fd* fd, rt_off_t offset);
|
||||
int dfile_raw_stat(const char *path, struct dfs_stat *buf);
|
||||
int dfile_raw_rename(const char* oldpath, const char* newpath);
|
||||
|
||||
/* FD APIs */
|
||||
int fd_new(void);
|
||||
struct dfs_fd* fd_get(int fd);
|
||||
void fd_put(struct dfs_fd* fd);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Project : Device Filesystem
|
||||
+------------------------------------------------------------------------------
|
||||
| Copyright 2004, 2005 www.fayfayspace.org.
|
||||
| All rights reserved.
|
||||
|------------------------------------------------------------------------------
|
||||
| File : dfs_util.h, some misc definitions of Device FileSystem
|
||||
|------------------------------------------------------------------------------
|
||||
| Chang Logs:
|
||||
| Date Author Notes
|
||||
| 2005-01-26 ffxz The first version
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef __DFS_UTIL_H__
|
||||
#define __DFS_UTIL_H__
|
||||
|
||||
#include <dfs_def.h>
|
||||
|
||||
int dir_name(const char* path, char* dirname, int len);
|
||||
int file_name(const char* path, char* filename, int len);
|
||||
|
||||
int next_dir_name(const char* path, int pos, char* next);
|
||||
void build_fullpath(const char *directory, const char *filename, char *fullpath);
|
||||
int str_is_prefix(const char* prefix, const char* str);
|
||||
|
||||
#if !defined(RT_USING_MINILIBC) && !defined(RT_USING_NEWLIB)
|
||||
char *strrchr(const char *t, int c);
|
||||
#if defined (__ARMCC_VERSION) && (__ARMCC_VERSION / 10000 < 35)
|
||||
#include <stddef.h>
|
||||
int strncasecmp(const char* s1, const char* s2, size_t len);
|
||||
#endif /* end of __ARMCC_VERSION */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,386 @@
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Project : Device Filesystem
|
||||
+------------------------------------------------------------------------------
|
||||
| Copyright 2004, 2005 www.fayfayspace.org.
|
||||
| All rights reserved.
|
||||
|------------------------------------------------------------------------------
|
||||
| File : dfs_fs.c, the filesystem related implementations of Device FileSystem
|
||||
|------------------------------------------------------------------------------
|
||||
| Chang Logs:
|
||||
| Date Author Notes
|
||||
| 2005-02-22 ffxz The first version.
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
#include <dfs_fs.h>
|
||||
#include <dfs_raw.h>
|
||||
#include <dfs_util.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Function : dfs_register
|
||||
+------------------------------------------------------------------------------
|
||||
| Description : registers a filesystem
|
||||
|
|
||||
| Parameters : ops, the implementation of filesystem
|
||||
| Returns : the status of register
|
||||
| 0 , successful
|
||||
| -1, failed
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
int dfs_register(struct dfs_filesystem_operation* ops)
|
||||
{
|
||||
int index, result;
|
||||
|
||||
result = 0;
|
||||
|
||||
/* lock filesystem */
|
||||
dfs_lock();
|
||||
|
||||
/* check if this filesystem was already registered */
|
||||
for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX; index++)
|
||||
{
|
||||
if (filesystem_operation_table[index] != RT_NULL &&
|
||||
strcmp(filesystem_operation_table[index]->name, ops->name) == 0)
|
||||
{
|
||||
result = -1;
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
/* find out an empty filesystem type entry */
|
||||
for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX && filesystem_operation_table[index] != RT_NULL;
|
||||
index++) ;
|
||||
|
||||
/* filesystem type table full */
|
||||
if (index == DFS_FILESYSTEM_TYPES_MAX)
|
||||
{
|
||||
result = -1;
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* save the filesystem's operations */
|
||||
filesystem_operation_table[index] = ops;
|
||||
|
||||
err:
|
||||
dfs_unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Function : dfs_filesystem_lookup
|
||||
+------------------------------------------------------------------------------
|
||||
| Description : lookup the mounted filesystem on the specified path
|
||||
|
|
||||
| Parameters : path, the specified path string
|
||||
| Returns : the found filesystem
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
struct dfs_filesystem* dfs_filesystem_lookup(const char *path)
|
||||
{
|
||||
struct dfs_filesystem* fs;
|
||||
rt_uint32_t index, fspath, prefixlen;
|
||||
|
||||
fs = RT_NULL;
|
||||
prefixlen = 0;
|
||||
|
||||
/* lock filesystem */
|
||||
dfs_lock();
|
||||
|
||||
/* lookup it in the filesystem table */
|
||||
for (index = 0; index < DFS_FILESYSTEMS_MAX + 1; index++)
|
||||
{
|
||||
fspath = strlen(filesystem_table[index].path);
|
||||
if (fspath < prefixlen) continue;
|
||||
|
||||
if ((filesystem_table[index].ops != RT_NULL) &&
|
||||
str_is_prefix(filesystem_table[index].path, path) == 0)
|
||||
{
|
||||
fs = &filesystem_table[index];
|
||||
prefixlen = fspath;
|
||||
}
|
||||
}
|
||||
|
||||
dfs_unlock();
|
||||
|
||||
return fs;
|
||||
}
|
||||
|
||||
rt_err_t dfs_filesystem_get_partition(struct dfs_partition* part, rt_uint8_t* buf, rt_uint32_t pindex)
|
||||
{
|
||||
#define DPT_ADDRESS 0x1be /* device partition offset in Boot Sector */
|
||||
#define DPT_ITEM_SIZE 16 /* partition item size */
|
||||
|
||||
rt_uint8_t* dpt;
|
||||
rt_uint8_t type;
|
||||
rt_err_t result;
|
||||
|
||||
RT_ASSERT(part != RT_NULL);
|
||||
RT_ASSERT(buf != RT_NULL);
|
||||
|
||||
result = RT_EOK;
|
||||
|
||||
dpt = buf + DPT_ADDRESS + pindex * DPT_ITEM_SIZE;
|
||||
|
||||
if ((*dpt != 0x80) && (*dpt != 0x00))
|
||||
{
|
||||
/* which is not a partition table */
|
||||
result = -RT_ERROR;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* get partition type */
|
||||
type = *(dpt+4);
|
||||
|
||||
if (type != 0)
|
||||
{
|
||||
/* set partition type */
|
||||
part->type = type;
|
||||
|
||||
/* get partition offset and size */
|
||||
part->offset = *(dpt+ 8) | *(dpt+ 9) << 8 |
|
||||
*(dpt+10) << 16 | *(dpt+11) << 24;
|
||||
part->size = *(dpt+12) | *(dpt+13) << 8 |
|
||||
*(dpt+14) << 16 | *(dpt+15) << 24;
|
||||
|
||||
#ifdef RT_USING_FINSH
|
||||
rt_kprintf("part[%d], begin: %d, size: ",
|
||||
pindex, part->offset * 512);
|
||||
if ( (part->size>>11) > 0 ) /* MB */
|
||||
{
|
||||
unsigned int part_size;
|
||||
part_size = part->size>>11;/* MB */
|
||||
if ( (part_size>>10) > 0) /* GB */
|
||||
{
|
||||
rt_kprintf("%d.%d%s",part_size>>10,part_size&0x3FF,"GB\r\n");/* GB */
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("%d.%d%s",part_size,(part->size>>1)&0x3FF,"MB\r\n");/* MB */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("%d%s",part->size>>1,"KB\r\n");/* KB */
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
result = -RT_ERROR;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Function : dfs_mount
|
||||
+------------------------------------------------------------------------------
|
||||
| Description : mount a filesystem to specified path
|
||||
|
|
||||
| Parameters : device_name, the implementation of filesystem
|
||||
| path,
|
||||
| filesystemtype,
|
||||
| rwflag,
|
||||
| data,
|
||||
| Returns : the status of register
|
||||
| 0 , successful
|
||||
| -1, failed
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
int dfs_mount(const char* device_name, const char* path,
|
||||
const char* filesystemtype, unsigned long rwflag, const
|
||||
void* data)
|
||||
{
|
||||
struct dfs_filesystem_operation* ops;
|
||||
struct dfs_filesystem* fs;
|
||||
char *fullpath=RT_NULL;
|
||||
#ifdef DFS_USING_WORKDIR
|
||||
char full_path[DFS_PATH_MAX + 1];
|
||||
#endif
|
||||
rt_device_t dev_id;
|
||||
int index;
|
||||
|
||||
/* open specific device */
|
||||
dev_id = rt_device_find(device_name);
|
||||
if (dev_id == RT_NULL)
|
||||
{
|
||||
/* no this device */
|
||||
rt_set_errno(-DFS_STATUS_ENODEV);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* find out specific filesystem */
|
||||
dfs_lock();
|
||||
for ( index = 0; index < DFS_FILESYSTEM_TYPES_MAX; index++ )
|
||||
{
|
||||
if (strcmp(filesystem_operation_table[index]->name, filesystemtype) == 0)break;
|
||||
}
|
||||
|
||||
/* can't find filesystem */
|
||||
if ( index == DFS_FILESYSTEM_TYPES_MAX )
|
||||
{
|
||||
rt_set_errno(-DFS_STATUS_ENODEV);
|
||||
dfs_unlock();
|
||||
return -1;
|
||||
}
|
||||
ops = filesystem_operation_table[index];
|
||||
dfs_unlock();
|
||||
|
||||
/* make full path for special file */
|
||||
fullpath = (char*)path;
|
||||
if ( fullpath[0] != '/') /* not an abstract path */
|
||||
{
|
||||
#ifdef DFS_USING_WORKDIR
|
||||
/* build full path */
|
||||
fullpath = full_path;
|
||||
dfs_lock();
|
||||
build_fullpath(working_directory, path, fullpath);
|
||||
dfs_unlock();
|
||||
#else
|
||||
rt_set_errno(-DFS_STATUS_ENOTDIR);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Check if the path exists or not, raw APIs call, fixme */
|
||||
if ( (strcmp(fullpath, "/") != 0) && (strcmp(fullpath, "/dev") != 0) )
|
||||
{
|
||||
struct dfs_fd fd;
|
||||
|
||||
if ( dfile_raw_open(&fd, fullpath, DFS_O_RDONLY | DFS_O_DIRECTORY) < 0 )
|
||||
{
|
||||
rt_set_errno(-DFS_STATUS_ENOTDIR);
|
||||
return -1;
|
||||
}
|
||||
dfile_raw_close(&fd);
|
||||
}
|
||||
|
||||
/* check whether the file system mounted or not */
|
||||
dfs_lock();
|
||||
for (index =0; index < DFS_FILESYSTEMS_MAX; index++)
|
||||
{
|
||||
if ( filesystem_table[index].ops != RT_NULL &&
|
||||
strcmp(filesystem_table[index].path, path) == 0 )
|
||||
{
|
||||
rt_set_errno(-DFS_STATUS_EINVAL);
|
||||
goto err1;
|
||||
}
|
||||
}
|
||||
|
||||
/* find out en empty filesystem table entry */
|
||||
for (index = 0; index < DFS_FILESYSTEMS_MAX && filesystem_table[index].ops != RT_NULL;
|
||||
index++) ;
|
||||
if ( index == DFS_FILESYSTEMS_MAX ) /* can't find en empty filesystem table entry */
|
||||
{
|
||||
rt_set_errno(-DFS_STATUS_EMMOUNT);
|
||||
goto err1;
|
||||
}
|
||||
|
||||
/* register file system */
|
||||
fs = &(filesystem_table[index]);
|
||||
strncpy(fs->path, fullpath, strlen(fullpath));
|
||||
fs->ops = ops;
|
||||
fs->dev_id = dev_id;
|
||||
/* release filesystem_table lock */
|
||||
dfs_unlock();
|
||||
|
||||
/* open device, but do not check the status of device */
|
||||
rt_device_open(fs->dev_id, RT_DEVICE_OFLAG_RDWR);
|
||||
|
||||
if ( ops->mount == RT_NULL ) /* there is no mount implementation */
|
||||
{
|
||||
dfs_lock();
|
||||
/* clear filesystem table entry */
|
||||
rt_memset(fs, 0, sizeof(struct dfs_filesystem));
|
||||
dfs_unlock();
|
||||
|
||||
rt_set_errno(-DFS_STATUS_ENOSYS);
|
||||
return -1;
|
||||
}
|
||||
/* call mount of this filesystem */
|
||||
else if ( ops->mount(fs) < 0 )
|
||||
{
|
||||
/* mount failed */
|
||||
dfs_lock();
|
||||
|
||||
/* close device */
|
||||
rt_device_close(fs->dev_id);
|
||||
|
||||
/* clear filesystem table entry */
|
||||
rt_memset(fs, 0, sizeof(struct dfs_filesystem));
|
||||
|
||||
dfs_unlock();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err1:
|
||||
dfs_unlock();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Function : dfs_unmount
|
||||
+------------------------------------------------------------------------------
|
||||
| Description : unmount a filesystem
|
||||
|
|
||||
| Parameters :
|
||||
| Returns : the status of register
|
||||
| 0 , successful
|
||||
| -1, failed
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
int dfs_unmount(const char *specialfile)
|
||||
{
|
||||
char *fullpath;
|
||||
#ifdef DFS_USING_WORKDIR
|
||||
char full_path[DFS_PATH_MAX + 1];
|
||||
#endif
|
||||
struct dfs_filesystem* fs = RT_NULL;
|
||||
|
||||
fullpath = (char*)specialfile;
|
||||
if ( fullpath[0] != '/')
|
||||
{
|
||||
#ifdef DFS_USING_WORKDIR
|
||||
/* build full path */
|
||||
fullpath = full_path;
|
||||
dfs_lock();
|
||||
build_fullpath(working_directory, specialfile, fullpath);
|
||||
dfs_unlock();
|
||||
#else
|
||||
rt_set_errno(-DFS_STATUS_ENOTDIR);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* lock filesystem */
|
||||
dfs_lock();
|
||||
|
||||
fs = dfs_filesystem_lookup(fullpath);
|
||||
if (fs != RT_NULL && fs->ops->unmount != RT_NULL && fs->ops->unmount(fs) < 0)
|
||||
{
|
||||
goto err1;
|
||||
}
|
||||
|
||||
/* close device, but do not check the status of device */
|
||||
rt_device_close(fs->dev_id);
|
||||
|
||||
/* clear this filesystem table entry */
|
||||
rt_memset(fs, 0, sizeof(struct dfs_filesystem));
|
||||
|
||||
dfs_unlock();
|
||||
|
||||
return 0;
|
||||
|
||||
err1:
|
||||
dfs_unlock();
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Project : Device Filesystem
|
||||
+------------------------------------------------------------------------------
|
||||
| Copyright 2004, 2005 www.fayfayspace.org.
|
||||
| All rights reserved.
|
||||
|------------------------------------------------------------------------------
|
||||
| File : dfs.c, the implementation of Device FileSystem
|
||||
|------------------------------------------------------------------------------
|
||||
| Chang Logs:
|
||||
| Date Author Notes
|
||||
| 2002-12-31 ffxz The first version.
|
||||
| 2005-01-22 ffxz Clean up the code.
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
#include <dfs_def.h>
|
||||
#include <dfs_config.h>
|
||||
|
||||
#include <dfs_fs.h>
|
||||
#include <dfs_raw.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* Global variables */
|
||||
struct dfs_filesystem_operation* filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX + 1];
|
||||
struct dfs_filesystem filesystem_table[DFS_FILESYSTEMS_MAX + 1];
|
||||
|
||||
/* device filesystem lock */
|
||||
struct rt_mutex dlock;
|
||||
|
||||
#ifdef DFS_USING_WORKDIR
|
||||
char working_directory[DFS_PATH_MAX + 1];
|
||||
#endif
|
||||
|
||||
#ifdef DFS_USING_STDIO
|
||||
struct dfs_fd fd_table[3 + DFS_FD_MAX];
|
||||
#else
|
||||
struct dfs_fd fd_table[DFS_FD_MAX];
|
||||
#endif
|
||||
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Function : dfs_init
|
||||
+------------------------------------------------------------------------------
|
||||
| Description : Inits the Device Filesystem
|
||||
| Parameters : null
|
||||
| Returns : null
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
void dfs_init()
|
||||
{
|
||||
int index;
|
||||
|
||||
/* clear filesystem operations table */
|
||||
for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX + 1; index++)
|
||||
filesystem_operation_table[index] = RT_NULL;
|
||||
|
||||
/* create device filesystem lock */
|
||||
rt_mutex_init(&dlock, "dlock", RT_IPC_FLAG_FIFO);
|
||||
|
||||
/* clear filesystem table */
|
||||
rt_memset(filesystem_table, 0, sizeof(filesystem_table));
|
||||
|
||||
#ifdef DFS_USING_WORKDIR
|
||||
/* set current working directory */
|
||||
strcpy(working_directory, "/");
|
||||
#endif
|
||||
|
||||
/* clean fd table */
|
||||
rt_memset(fd_table, 0, sizeof(fd_table));
|
||||
}
|
||||
|
||||
void dfs_lock()
|
||||
{
|
||||
rt_err_t result;
|
||||
|
||||
result = rt_mutex_take(&dlock, RT_WAITING_FOREVER);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
}
|
||||
|
||||
void dfs_unlock()
|
||||
{
|
||||
rt_mutex_release(&dlock);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Project : Device Filesystem
|
||||
+------------------------------------------------------------------------------
|
||||
| Copyright 2004, 2005 www.fayfayspace.org.
|
||||
| All rights reserved.
|
||||
|------------------------------------------------------------------------------
|
||||
| File : dfs_utl.c, some misc functions of Device FileSystem
|
||||
|------------------------------------------------------------------------------
|
||||
| Chang Logs:
|
||||
| Date Author Notes
|
||||
| 2005-01-26 ffxz The first version
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <dfs_fs.h>
|
||||
#include <dfs_util.h>
|
||||
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Function : dir_name
|
||||
+------------------------------------------------------------------------------
|
||||
| Description : Gets the directory name in specified path string
|
||||
|
|
||||
| Parameters : path, the specified path string
|
||||
| path_name, return the path name in this parameter
|
||||
| len, the length of path name
|
||||
| Returns : the status of path_name:
|
||||
| 0 , successful
|
||||
| -1, failed
|
||||
| For Example :
|
||||
| path, dir_name
|
||||
| /, /
|
||||
| /usr, /
|
||||
| /usr/lib, /usr
|
||||
| /usr/lib/, /usr
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
int dir_name(const char* path, char* dirname, int len)
|
||||
{
|
||||
int pos;
|
||||
|
||||
if ( path[0] == '/' && path[1] == '\0' )
|
||||
{
|
||||
*dirname++ = '/';
|
||||
*dirname = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
pos = strlen(path);
|
||||
while ( *(path + pos - 1) =='/' ) pos --;
|
||||
while ( pos > 0 && *(path + pos - 1) != '/' ) pos --;
|
||||
while ( pos > 0 && *(path + pos - 1) == '/' ) pos --;
|
||||
|
||||
if ( pos > len ) return -1;
|
||||
|
||||
if ( pos != 0)
|
||||
{
|
||||
memcpy(dirname, path, pos);
|
||||
*(dirname+pos) = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
*dirname++ = '/';
|
||||
*dirname = '\0';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Function : file_name
|
||||
+------------------------------------------------------------------------------
|
||||
| Description : Gets the file name in specified path string
|
||||
|
|
||||
| Parameters : path, the specified path string
|
||||
| filename, return the path name in this parameter
|
||||
| len, the length of file name
|
||||
| Returns : the status of file_name:
|
||||
| 0 , successful
|
||||
| -1, failed
|
||||
| For Example :
|
||||
| path, filename
|
||||
| /, RT_NULL
|
||||
| /usr, usr
|
||||
| /usr/lib, lib
|
||||
| /usr/lib/, lib
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
int file_name(const char* path, char* filename, int len)
|
||||
{
|
||||
int pos, size;
|
||||
|
||||
if ( path[0] == '/' && path[1] == '\0' )
|
||||
{
|
||||
*filename = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
pos = strlen(path);
|
||||
while ( *(path + pos -1)=='/' ) pos --;
|
||||
size = pos;
|
||||
|
||||
while ( *(path + pos -1) != '/' && pos > 0 ) pos --;
|
||||
|
||||
if ( size - pos > len ) return -1;
|
||||
else size = size - pos ;
|
||||
|
||||
memcpy(filename, path + pos, size);
|
||||
*(filename+size) = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Function : next_path_name
|
||||
+------------------------------------------------------------------------------
|
||||
| Description : Gets the next directory name from specified path string
|
||||
|
|
||||
| Parameters : path, the specified path string
|
||||
| pos, the specified position of path string
|
||||
| next, return the next path in this parameter
|
||||
| Returns : the position of next directory item,
|
||||
| -1, if pos reach in the end of the specified path string
|
||||
| For Example :
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
int next_dir_name(const char* path, int pos, char* next)
|
||||
{
|
||||
const char* q;
|
||||
|
||||
if ( pos > strlen(path) || pos < 0|| path == RT_NULL ) return -1;
|
||||
|
||||
q = path + pos;
|
||||
|
||||
/* check for firt '/' */
|
||||
while ( *q == '/' ) q++;
|
||||
if ( *q == '\0' )
|
||||
{
|
||||
*next = '\0';
|
||||
return -1;
|
||||
}
|
||||
|
||||
while ( *q != '/' && *q != '\0' )
|
||||
{
|
||||
*next++ = *q++;
|
||||
}
|
||||
*next = '\0';
|
||||
|
||||
return q - path + 1;
|
||||
}
|
||||
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Function : build_fullpath
|
||||
+------------------------------------------------------------------------------
|
||||
| Description : make up the full path from directory and filename
|
||||
|
|
||||
| Parameters : path, the specified path string
|
||||
| filename, return the path name in this parameter
|
||||
| fullpath, the returned full path name
|
||||
| Returns : null
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
void build_fullpath(const char *directory, const char *filename, char *fullpath)
|
||||
{
|
||||
char elem[DFS_PATH_MAX + 1];
|
||||
int pos, start, len;
|
||||
|
||||
len = 0;
|
||||
/* check parameters */
|
||||
RT_ASSERT(directory != RT_NULL);
|
||||
RT_ASSERT(filename != RT_NULL);
|
||||
RT_ASSERT(fullpath != RT_NULL);
|
||||
|
||||
/* copy full of directory */
|
||||
strncpy(fullpath, directory, DFS_PATH_MAX + 1);
|
||||
|
||||
for (pos = 0; filename[pos] != '\0'; )
|
||||
{
|
||||
/* strip '//' */
|
||||
while (filename[pos] == '/') pos++;
|
||||
|
||||
/* get the filename element, save to elem array */
|
||||
for (start = pos; filename[pos] != '/' && filename[pos] != '\0'; pos++)
|
||||
len = pos - start + 1;
|
||||
|
||||
strncpy(elem, filename + start, DFS_PATH_MAX + 1);
|
||||
/* clear the end of elem */
|
||||
elem[(len < DFS_PATH_MAX + 1? len : DFS_PATH_MAX + 1)] = '\0';
|
||||
|
||||
/* strip '..' */
|
||||
if (elem[0] == '.' && elem[1] == '.')
|
||||
{
|
||||
if (strlen(fullpath) == 0) strcpy(fullpath, ""); /* empty filename */
|
||||
else if (fullpath[0] == '/' && fullpath[1] !='\0')
|
||||
{
|
||||
int i = strlen(fullpath);
|
||||
|
||||
while (fullpath[i - 1] == '/') i--;
|
||||
while (i > 0 && fullpath[i - 1] != '/') i--;
|
||||
|
||||
fullpath[i] = '\0';
|
||||
}
|
||||
}
|
||||
/* not '.', copy as normally */
|
||||
else if (elem[0] != '.')
|
||||
{
|
||||
len = strlen(fullpath);
|
||||
|
||||
if (len == 0) strncpy(fullpath, elem, DFS_PATH_MAX + 1);
|
||||
else if (fullpath[len - 1] == '/')
|
||||
{
|
||||
if (elem[0] == '/') strncat(fullpath, elem + 1, DFS_PATH_MAX + 1);
|
||||
else strncat(fullpath, elem, DFS_PATH_MAX + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (elem[0] == '/') strcat(fullpath, elem);
|
||||
else
|
||||
{
|
||||
strncat(fullpath, "/", DFS_PATH_MAX + 1);
|
||||
strncat(fullpath + 1, elem, DFS_PATH_MAX + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( fullpath[0] != '/' && fullpath[(len = strlen(fullpath)) - 1] == '/')
|
||||
{
|
||||
fullpath[len - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
int str_is_prefix(const char* prefix, const char* str)
|
||||
{
|
||||
while ((*prefix) && (*str) && (*prefix == *str))
|
||||
{
|
||||
prefix ++;
|
||||
str ++;
|
||||
}
|
||||
|
||||
if (*prefix == 0) return 0;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if !defined(RT_USING_MINILIBC) && !defined(RT_USING_NEWLIB)
|
||||
#if !defined(__ICCARM__)
|
||||
char *strrchr(const char *t, int c)
|
||||
{
|
||||
register char ch;
|
||||
register const char *l=0;
|
||||
|
||||
ch = c;
|
||||
for (;;)
|
||||
{
|
||||
if ((*t == ch)) l=t;
|
||||
if ((!*t)) return (char*)l; ++t;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined (__ARMCC_VERSION) && (__ARMCC_VERSION / 10000 < 35)
|
||||
int strncasecmp ( const char* s1, const char* s2, size_t len )
|
||||
{
|
||||
register unsigned int x2;
|
||||
register unsigned int x1;
|
||||
register const char* end = s1 + len;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if ((s1 >= end) )
|
||||
return 0;
|
||||
|
||||
x2 = *s2 - 'A'; if ((x2 < 26u)) x2 += 32;
|
||||
x1 = *s1 - 'A'; if ((x1 < 26u)) x1 += 32;
|
||||
s1++; s2++;
|
||||
|
||||
if ((x2 != x1))
|
||||
break;
|
||||
|
||||
if ((x1 == (unsigned int)-'A'))
|
||||
break;
|
||||
}
|
||||
|
||||
return x1 - x2;
|
||||
}
|
||||
#endif /* end of __ARMCC_VERSION */
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user