This commit is contained in:
bernard
2013-12-29 22:31:05 +08:00
49 changed files with 2557 additions and 2273 deletions
+6 -9
View File
@@ -108,12 +108,8 @@
#if _MAX_SS != 512 && _MAX_SS != 1024 && _MAX_SS != 2048 && _MAX_SS != 4096
#error Wrong sector size.
#endif
#if _MAX_SS != 512
#define SS(fs) ((fs)->ssize) /* Multiple sector size */
#else
#define SS(fs) 512U /* Fixed sector size */
#endif
#define SS(fs) ((fs)->ssize) /* sector size */
/* Reentrancy related */
#if _FS_REENTRANT
@@ -2058,10 +2054,11 @@ FRESULT chk_mounted ( /* FR_OK(0): successful, !=0: any error occurred */
stat = disk_initialize(fs->drv); /* Initialize low level disk I/O layer */
if (stat & STA_NOINIT) /* Check if the initialization succeeded */
return FR_NOT_READY; /* Failed to initialize due to no media or hard error */
#if _MAX_SS != 512 /* Get disk sector size (variable sector size cfg only) */
/* Get disk sector size (variable sector size cfg only) */
if (disk_ioctl(fs->drv, GET_SECTOR_SIZE, &fs->ssize) != RES_OK)
return FR_DISK_ERR;
#endif
#if !_FS_READONLY
if (chk_wp && (stat & STA_PROTECT)) /* Check disk write protection if needed */
return FR_WRITE_PROTECTED;
@@ -3601,10 +3598,10 @@ FRESULT f_mkfs (
stat = disk_initialize(drv);
if (stat & STA_NOINIT) return FR_NOT_READY;
if (stat & STA_PROTECT) return FR_WRITE_PROTECTED;
#if _MAX_SS != 512 /* Get disk sector size */
/* Get disk sector size */
if (disk_ioctl(drv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK)
return FR_DISK_ERR;
#endif
if (disk_ioctl(drv, GET_SECTOR_COUNT, &n_vol) != RES_OK || n_vol < 128)
return FR_DISK_ERR;
b_vol = (sfd) ? 0 : 63; /* Volume start sector */
-2
View File
@@ -84,9 +84,7 @@ typedef struct {
BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */
WORD id; /* File system mount ID */
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
#if _MAX_SS != 512
WORD ssize; /* Bytes per sector (512,1024,2048,4096) */
#endif
#if _FS_REENTRANT
_SYNC_t sobj; /* Identifier of sync object */
#endif
+136 -181
View File
@@ -37,48 +37,36 @@
*
* @param ops the file system instance to be registered.
*
* @return 0 on successful, -1 on failed.
* @return RT_EOK on successful, -RT_ERROR on failed.
*/
int dfs_register(const struct dfs_filesystem_operation *ops)
{
int index, result;
int free_index;
result = 0;
free_index = DFS_FILESYSTEM_TYPES_MAX;
int ret = RT_EOK;
const struct dfs_filesystem_operation **empty = RT_NULL;
const struct dfs_filesystem_operation **iter;
/* lock filesystem */
dfs_lock();
/* check if this filesystem was already registered */
for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX; index++)
for (iter = &filesystem_operation_table[0];
iter < &filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX]; iter ++)
{
if (filesystem_operation_table[index] == RT_NULL)
/* find out an empty filesystem type entry */
if (*iter == RT_NULL)
(empty == RT_NULL) ? (empty = iter) : 0;
else if (strcmp((*iter)->name, ops->name) == 0)
{
/* find out an empty filesystem type entry */
if (free_index == DFS_FILESYSTEM_TYPES_MAX)
free_index = index;
ret = -1;
break;
}
else if (strcmp(filesystem_operation_table[index]->name, ops->name) == 0)
{
result = -1;
goto err;
}
}
/* filesystem type table full */
if (free_index == DFS_FILESYSTEM_TYPES_MAX)
{
result = -1;
goto err;
}
/* save the filesystem's operations */
filesystem_operation_table[free_index] = ops;
if ((ret == RT_EOK) && (empty != RT_NULL))
*empty = ops;
err:
dfs_unlock();
return result;
return ret;
}
/**
@@ -91,37 +79,33 @@ err:
*/
struct dfs_filesystem *dfs_filesystem_lookup(const char *path)
{
struct dfs_filesystem *fs;
rt_uint32_t index, fspath, prefixlen;
struct dfs_filesystem *iter;
struct dfs_filesystem *fs = RT_NULL;
rt_uint32_t fspath, prefixlen;
fs = RT_NULL;
prefixlen = 0;
/* lock filesystem */
dfs_lock();
/* lookup it in the filesystem table */
for (index = 0; index < DFS_FILESYSTEMS_MAX; index++)
for (iter = &filesystem_table[0];
iter < &filesystem_table[DFS_FILESYSTEMS_MAX]; iter++)
{
if (filesystem_table[index].path == RT_NULL)
if ((iter->path == RT_NULL) || (iter->ops == RT_NULL))
continue;
else
{
fspath = strlen(filesystem_table[index].path);
if (fspath < prefixlen)
continue;
}
if ((filesystem_table[index].ops != RT_NULL) &&
(strncmp(filesystem_table[index].path, path, fspath) == 0))
{
/* check next path separator */
if (fspath > 1 && (strlen(path) > fspath) && (path[fspath] != '/'))
continue;
fspath = strlen(iter->path);
if ((fspath < prefixlen)
|| (strncmp(iter->path, path, fspath) != 0))
continue;
fs = &filesystem_table[index];
prefixlen = fspath;
}
/* check next path separator */
if (fspath > 1 && (strlen(path) > fspath) && (path[fspath] != '/'))
continue;
fs = iter;
prefixlen = fspath;
}
dfs_unlock();
@@ -147,64 +131,42 @@ rt_err_t dfs_filesystem_get_partition(struct dfs_partition *part,
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;
/* check if it is a valid partition table */
if ((*dpt != 0x80) && (*dpt != 0x00))
{
/* which is not a partition table */
result = -RT_ERROR;
return result;
}
return -RT_ERROR;
/* get partition type */
type = *(dpt+4);
if (type == 0)
return -RT_ERROR;
if (type != 0)
{
/* set partition type */
part->type = type;
/* set partition information
* size is the number of 512-Byte */
part->type = type;
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;
/* 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;
rt_kprintf("found 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 */
{
/* GB */
rt_kprintf("%d.%d%s",part_size>>10,part_size&0x3FF,"GB\r\n");
}
else
{
/* MB */
rt_kprintf("%d.%d%s",part_size,(part->size>>1)&0x3FF,"MB\r\n");
}
}
else
{
/* KB */
rt_kprintf("%d%s",part->size>>1,"KB\r\n");
}
}
rt_kprintf("found part[%d], begin: %d, size: ",
pindex, part->offset*512);
if ((part->size>>11) == 0)
rt_kprintf("%d%s",part->size>>1,"KB\n"); /* KB */
else
{
result = -RT_ERROR;
unsigned int part_size;
part_size = part->size >> 11; /* MB */
if ((part_size>>10) == 0)
rt_kprintf("%d.%d%s",part_size,(part->size>>1)&0x3FF,"MB\n");
else
rt_kprintf("%d.%d%s",part_size>>10,part_size&0x3FF,"GB\n");
}
return result;
return RT_EOK;
}
/**
@@ -224,57 +186,54 @@ int dfs_mount(const char *device_name,
unsigned long rwflag,
const void *data)
{
const struct dfs_filesystem_operation *ops;
struct dfs_filesystem *fs;
char *fullpath=RT_NULL;
const struct dfs_filesystem_operation **ops;
struct dfs_filesystem *iter;
struct dfs_filesystem *fs = RT_NULL;
char *fullpath = RT_NULL;
rt_device_t dev_id;
int index, free_index;
/* open specific device */
if (device_name != RT_NULL)
{
dev_id = rt_device_find(device_name);
if (dev_id == RT_NULL)
{
/* no this device */
rt_set_errno(-DFS_STATUS_ENODEV);
return -1;
}
}
else
if (device_name == RT_NULL)
{
/* which is a non-device filesystem mount */
dev_id = RT_NULL;
dev_id = NULL;
}
/* find out specific filesystem */
dfs_lock();
for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX; index++)
{
if (filesystem_operation_table[index] == RT_NULL)
continue;
if (strcmp(filesystem_operation_table[index]->name, filesystemtype) == 0)
break;
}
dfs_unlock();
/* can't find filesystem */
if (index == DFS_FILESYSTEM_TYPES_MAX)
else if ((dev_id = rt_device_find(device_name)) == RT_NULL)
{
/* no this device */
rt_set_errno(-DFS_STATUS_ENODEV);
return -1;
}
ops = filesystem_operation_table[index];
/* find out the specific filesystem */
dfs_lock();
for (ops = &filesystem_operation_table[0];
ops < &filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX]; ops++)
if ((ops != RT_NULL) && (strcmp((*ops)->name, filesystemtype) == 0))
break;
dfs_unlock();
if (ops == &filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX])
{
/* can't find filesystem */
rt_set_errno(-DFS_STATUS_ENODEV);
return -1;
}
/* check if there is mount implementation */
if ((*ops == NULL) || ((*ops)->mount == NULL))
{
rt_set_errno(-DFS_STATUS_ENOSYS);
return -1;
}
/* make full path for special file */
fullpath = dfs_normalize_path(RT_NULL, path);
if (fullpath == RT_NULL) /* not an abstract path */
{
rt_set_errno(-DFS_STATUS_ENOTDIR);
return -1;
}
@@ -293,60 +252,52 @@ int dfs_mount(const char *device_name,
dfs_file_close(&fd);
}
free_index = DFS_FILESYSTEMS_MAX;
/* check whether the file system mounted or not */
/* check whether the file system mounted or not in the filesystem table
* if it is unmounted yet, find out an empty entry */
dfs_lock();
for (index = 0; index < DFS_FILESYSTEMS_MAX; index ++)
for (iter = &filesystem_table[0];
iter < &filesystem_table[DFS_FILESYSTEMS_MAX]; iter++)
{
if (filesystem_table[index].ops == RT_NULL)
{
/* find out an empty filesystem table entry */
if (free_index == DFS_FILESYSTEMS_MAX)
free_index = index;
}
else if (strcmp(filesystem_table[index].path, path) == 0)
/* check if it is an empty filesystem table entry? if it is, save fs */
if (iter->ops == RT_NULL)
(fs == RT_NULL) ? (fs = iter) : 0;
/* check if the PATH is mounted */
else if (strcmp(iter->path, path) == 0)
{
rt_set_errno(-DFS_STATUS_EINVAL);
goto err1;
}
}
/* can't find en empty filesystem table entry */
if (free_index == DFS_FILESYSTEMS_MAX)
if ((fs == RT_NULL) && (iter == &filesystem_table[DFS_FILESYSTEMS_MAX]))
{
rt_set_errno(-DFS_STATUS_ENOSPC);
goto err1;
}
/* register file system */
fs = &(filesystem_table[free_index]);
fs->path = fullpath;
fs->ops = ops;
fs->ops = *ops;
fs->dev_id = dev_id;
/* release filesystem_table lock */
dfs_unlock();
/* open device, but do not check the status of device */
if (dev_id != RT_NULL)
rt_device_open(fs->dev_id, RT_DEVICE_OFLAG_RDWR);
/* there is no mount implementation */
if (ops->mount == RT_NULL)
{
if (dev_id != RT_NULL)
rt_device_close(dev_id);
dfs_lock();
/* clear filesystem table entry */
rt_memset(fs, 0, sizeof(struct dfs_filesystem));
dfs_unlock();
rt_free(fullpath);
rt_set_errno(-DFS_STATUS_ENOSYS);
return -1;
if (rt_device_open(fs->dev_id,
RT_DEVICE_OFLAG_RDWR) != RT_EOK)
{
/* The underlaying device has error, clear the entry. */
dfs_lock();
rt_memset(fs, 0, sizeof(struct dfs_filesystem));
goto err1;
}
}
/* call mount of this filesystem */
else if (ops->mount(fs, rwflag, data) < 0)
if ((*ops)->mount(fs, rwflag, data) < 0)
{
/* close device */
if (dev_id != RT_NULL)
@@ -356,19 +307,14 @@ int dfs_mount(const char *device_name,
dfs_lock();
/* clear filesystem table entry */
rt_memset(fs, 0, sizeof(struct dfs_filesystem));
dfs_unlock();
rt_free(fullpath);
return -1;
goto err1;
}
return 0;
err1:
dfs_unlock();
if (fullpath != RT_NULL)
rt_free(fullpath);
rt_free(fullpath);
return -1;
}
@@ -383,6 +329,7 @@ err1:
int dfs_unmount(const char *specialfile)
{
char *fullpath;
struct dfs_filesystem *iter;
struct dfs_filesystem *fs = RT_NULL;
fullpath = dfs_normalize_path(RT_NULL, specialfile);
@@ -396,7 +343,17 @@ int dfs_unmount(const char *specialfile)
/* lock filesystem */
dfs_lock();
fs = dfs_filesystem_lookup(fullpath);
for (iter = &filesystem_table[0];
iter < &filesystem_table[DFS_FILESYSTEMS_MAX]; iter++)
{
/* check if the PATH is mounted */
if ((iter->path != NULL) && (strcmp(iter->path, fullpath) == 0))
{
fs = iter;
break;
}
}
if (fs == RT_NULL ||
fs->ops->unmount == RT_NULL ||
fs->ops->unmount(fs) < 0)
@@ -437,12 +394,10 @@ err1:
int dfs_mkfs(const char *fs_name, const char *device_name)
{
int index;
rt_device_t dev_id;
rt_device_t dev_id = RT_NULL;
/* check device name, and it should not be NULL */
if (device_name == RT_NULL)
dev_id = RT_NULL;
else
if (device_name != RT_NULL)
dev_id = rt_device_find(device_name);
if (dev_id == RT_NULL)
@@ -458,19 +413,23 @@ int dfs_mkfs(const char *fs_name, const char *device_name)
{
if (filesystem_operation_table[index] != RT_NULL &&
strcmp(filesystem_operation_table[index]->name, fs_name) == 0)
{
/* find file system operation */
const struct dfs_filesystem_operation *ops = filesystem_operation_table[index];
dfs_unlock();
if (ops->mkfs != RT_NULL)
return ops->mkfs(dev_id);
break;
}
}
dfs_unlock();
if (index < DFS_FILESYSTEM_TYPES_MAX)
{
/* find file system operation */
const struct dfs_filesystem_operation *ops = filesystem_operation_table[index];
if (ops->mkfs == RT_NULL)
{
rt_set_errno(-DFS_STATUS_ENOSYS);
return -1;
}
return ops->mkfs(dev_id);
}
rt_kprintf("Can not find the file system which named as %s.\n", fs_name);
return -1;
}
@@ -512,7 +471,7 @@ int dfs_mount_table(void)
mount_table[index].rwflag,
mount_table[index].data) != 0)
{
rt_kprintf("mount fs[%s] on %s failed.\n", mount_table[index].filesystemtype,
rt_kprintf("mount fs[%s] on %s failed.\n", mount_table[index].filesystemtype,
mount_table[index].path);
return -RT_ERROR;
}
@@ -538,11 +497,7 @@ int df(const char *path)
long long cap;
struct statfs buffer;
if (path == RT_NULL)
result = dfs_statfs("/", &buffer);
else
result = dfs_statfs(path, &buffer);
result = dfs_statfs(path ? path : RT_NULL, &buffer);
if (result != 0)
{
rt_kprintf("dfs_statfs failed.\n");
+6 -4
View File
@@ -10,6 +10,8 @@
* SQLite compile macro
*/
#define RT_USING_SQLITE
2.
关注SQLite目录下的src/sqlite_config_rtthread.h
#define SQLITE_MINIMUM_FILE_DESCRIPTOR 0
#define SQLITE_OMIT_LOAD_EXTENSION 1
#define SQLITE_OMIT_WAL
@@ -20,11 +22,11 @@
#define SQLITE_THREADSAFE 1
#define HAVE_READLINE 0
#define NDEBUG
#define _HAVE_SQLITE_CONFIG_H
#define _HAVE_SQLITE_CONFIG_H
#define BUILD_sqlite
#define SQLITE_OS_OTHER 1
#define SQLITE_OS_RTT 1
2.
#define SQLITE_OS_OTHER 1
#define SQLITE_OS_RTTHREAD 1
3.
用test目录下的test10.c来进行测试.
推荐用mini2440bsp,因为板子的ram较大。
+143 -18
View File
@@ -25,6 +25,71 @@
#ifndef SQLITE_API
# define SQLITE_API
#endif
/************** Begin file sqlite_config_rtthread.h **************************/
#ifndef _SQLITE_CONFIG_RTTHREAD_H_
#define _SQLITE_CONFIG_RTTHREAD_H_
/*
* SQLite compile macro
*/
#ifndef SQLITE_MINIMUM_FILE_DESCRIPTOR
#define SQLITE_MINIMUM_FILE_DESCRIPTOR 0
#endif
#ifndef SQLITE_OMIT_LOAD_EXTENSION
#define SQLITE_OMIT_LOAD_EXTENSION 1
#endif
//#ifndef #define SQLITE_OMIT_WAL
#define SQLITE_OMIT_WAL
//#endif
#ifndef SQLITE_RTTHREAD_NO_WIDE
#define SQLITE_RTTHREAD_NO_WIDE 1
#endif
#ifndef SQLITE_ENABLE_LOCKING_STYLE
#define SQLITE_ENABLE_LOCKING_STYLE 0
#endif
#ifndef SQLITE_DISABLE_LOCKING_STYLE
#define SQLITE_DISABLE_LOCKING_STYLE 1
#endif
#ifndef SQLITE_TEMP_STORE
#define SQLITE_TEMP_STORE 1
#endif
#ifndef SQLITE_THREADSAFE
#define SQLITE_THREADSAFE 1
#endif
#ifndef HAVE_READLINE
#define HAVE_READLINE 0
#endif
#ifndef NDEBUG
#define NDEBUG
#endif
#ifndef _HAVE_SQLITE_CONFIG_H
#define _HAVE_SQLITE_CONFIG_H
#endif
#ifndef BUILD_sqlite
#define BUILD_sqlite
#endif
#ifndef SQLITE_OS_OTHER
#define SQLITE_OS_OTHER 1
#endif
#ifndef SQLITE_OS_RTTHREAD
#define SQLITE_OS_RTTHREAD 1
#endif
#endif
/************** End of sqlite_config_rtthread.h ******************************/
/************** Begin file sqlite3.h *****************************************/
/*
** 2001 September 15
@@ -22649,6 +22714,7 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
#if SQLITE_OS_RTTHREAD /* This file is used for rt-thread only */
/* #include <rtthread.h> */
#include <dfs_posix.h>
/*
** Include code that is common to all os_*.c files
@@ -22863,6 +22929,51 @@ SQLITE_API int sqlite3_open_file_count = 0;
/************** End of os_common.h *******************************************/
/************** Continuing where we left off in os_rtthread.c ****************/
#ifndef RT_USING_NEWLIB
#ifndef EINTR
#define EINTR 4 /* Interrupted system call */
#endif
#ifndef ENOLCK
#define ENOLCK 46 /* No record locks available */
#endif
#ifndef EACCES
#define EACCES 13 /* Permission denied */
#endif
#ifndef EPERM
#define EPERM 1 /* Operation not permitted */
#endif
#ifndef ETIMEDOUT
#define ETIMEDOUT 145 /* Connection timed out */
#endif
#ifndef ENOTCONN
#define ENOTCONN 134 /* Transport endpoint is not connected */
#endif
#if defined(__GNUC__) || defined(__ADSPBLACKFIN__)
int _gettimeofday(struct timeval *tp, void *ignore) __attribute__((weak));
int _gettimeofday(struct timeval *tp, void *ignore)
#elif defined(__CC_ARM)
__weak int _gettimeofday(struct timeval *tp, void *ignore)
#elif defined(__IAR_SYSTEMS_ICC__)
#if __VER__ > 540
__weak
#endif
int _gettimeofday(struct timeval *tp, void *ignore)
#else
int _gettimeofday(struct timeval *tp, void *ignore)
#endif
{
return 0;
}
#endif /* RT_USING_NEWLIB */
/*
** Compiling and using WAL mode requires several APIs that are not
** available in rt-thread.
@@ -23019,7 +23130,7 @@ static int sqlite3_os_type = 0;
# define SYSCALL sqlite3_syscall_ptr
#endif
#include <dfs_posix.h>
/* #include <dfs_posix.h> */
static int _Access(const char *pathname, int mode)
{
@@ -23110,10 +23221,10 @@ static struct rtthread_syscall {
#define osFstat ((int(*)(int,struct stat*))aSyscall[5].pCurrent)
{ "read", (sqlite3_syscall_ptr)read, 0 },
#define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[6].pCurrent)
#define osRead ((int(*)(int,void*,size_t))aSyscall[6].pCurrent)
{ "write", (sqlite3_syscall_ptr)write, 0 },
#define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[7].pCurrent)
#define osWrite ((int(*)(int,const void*,size_t))aSyscall[7].pCurrent)
{ "unlink", (sqlite3_syscall_ptr)unlink, 0 },
#define osUnlink ((int(*)(const char*))aSyscall[8].pCurrent)
@@ -23465,9 +23576,9 @@ static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) {
return SQLITE_OK;
#endif
case EAGAIN:
case DFS_STATUS_EAGAIN:
case ETIMEDOUT:
case EBUSY:
case DFS_STATUS_EBUSY:
case EINTR:
case ENOLCK:
/* random NFS retry error, unless during file system support
@@ -23506,17 +23617,17 @@ static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) {
/* invalid fd, unless during file system support introspection, in which
* it actually means what it says */
#endif
case EIO:
case EBADF:
case EINVAL:
case DFS_STATUS_EIO:
case DFS_STATUS_EBADF:
case DFS_STATUS_EINVAL:
case ENOTCONN:
case ENODEV:
case ENXIO:
case ENOENT:
case DFS_STATUS_ENODEV:
case DFS_STATUS_ENXIO:
case DFS_STATUS_ENOENT:
#ifdef ESTALE /* ESTALE is not defined on Interix systems */
case ESTALE:
#endif
case ENOSYS:
case DFS_STATUS_ENOSYS:
/* these should force the client to close the file and reconnect */
default:
@@ -23573,11 +23684,14 @@ static void verifyDbFile(rtthreadFile *pFile){
pFile->ctrlFlags |= UNIXFILE_WARNED;
return;
}
#warning " struct \"stat\" has no field \"st_nlink\""
#ifndef RT_USING_SQLITE
if( buf.st_nlink==0 && (pFile->ctrlFlags & UNIXFILE_DELETE)==0 ){
sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath);
pFile->ctrlFlags |= UNIXFILE_WARNED;
return;
}
#endif
}
/*
@@ -23760,7 +23874,7 @@ static int dotlockLock(sqlite3_file *id, int eFileLock) {
if( rc<0 ){
/* failed to open/create the lock directory */
int tErrno = errno;
if( EEXIST == tErrno ){
if( DFS_STATUS_EEXIST == tErrno ){
rc = SQLITE_BUSY;
} else {
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
@@ -23811,11 +23925,11 @@ static int dotlockUnlock(sqlite3_file *id, int eFileLock) {
/* To fully unlock the database, delete the lock file */
assert( eFileLock==NO_LOCK );
rc = osRmdir(zLockFile);
if( rc<0 && errno==ENOTDIR ) rc = osUnlink(zLockFile);
if( rc<0 && errno==DFS_STATUS_ENOTDIR ) rc = osUnlink(zLockFile);
if( rc<0 ){
int tErrno = errno;
rc = 0;
if( ENOENT != tErrno ){
if( DFS_STATUS_ENOENT != tErrno ){
rc = SQLITE_IOERR_UNLOCK;
}
if( IS_LOCK_ERROR(rc) ){
@@ -24258,7 +24372,7 @@ static int rtthreadWrite(
SimulateDiskfullError(( wrote=0, amt=1 ));
if( amt>0 ){
if( wrote<0 && pFile->lastErrno!=ENOSPC ){
if( wrote<0 && pFile->lastErrno!=DFS_STATUS_ENOSPC ){
/* lastErrno set by seekAndWrite */
return SQLITE_IOERR_WRITE;
}else{
@@ -25090,7 +25204,7 @@ static int rtthreadOpen(
fd = robust_open(zName, openFlags, openMode);
OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
if( fd<0 && errno!=EISDIR && isReadWrite && !isExclusive ){
if( fd<0 && errno!=DFS_STATUS_EISDIR && isReadWrite && !isExclusive ){
/* Failed to open the file for read/write access. Try read-only. */
flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
openFlags &= ~(O_RDWR|O_CREAT);
@@ -25148,7 +25262,7 @@ static int rtthreadDelete(
UNUSED_PARAMETER(NotUsed);
SimulateIOError(return SQLITE_IOERR_DELETE);
if( osUnlink(zPath)==(-1) ){
if( errno==ENOENT ){
if( errno==DFS_STATUS_ENOENT ){
rc = SQLITE_IOERR_DELETE_NOENT;
}else{
rc = rtthreadLogError(SQLITE_IOERR_DELETE, "unlink", zPath);
@@ -25179,6 +25293,17 @@ static int rtthreadDelete(
**
** Otherwise return 0.
*/
#ifndef F_OK
# define F_OK 0
#endif
#ifndef R_OK
# define R_OK 4
#endif
#ifndef W_OK
# define W_OK 2
#endif
static int rtthreadAccess(
sqlite3_vfs *NotUsed, /* The VFS containing this xAccess method */
const char *zPath, /* Path of the file to examine */
+2
View File
@@ -346,6 +346,8 @@ SRC += \
parse.h \
config.h \
sqlite3.h
SRC += $(TOP)/src/sqlite_config_rtthread.h
# Source code to the test files.
#
+77 -17
View File
@@ -16,12 +16,58 @@
#if SQLITE_OS_RTTHREAD /* This file is used for rt-thread only */
#include <rtthread.h>
#include <dfs_posix.h>
/*
** Include code that is common to all os_*.c files
*/
#include "os_common.h"
#ifndef RT_USING_NEWLIB
#ifndef EINTR
#define EINTR 4 /* Interrupted system call */
#endif
#ifndef ENOLCK
#define ENOLCK 46 /* No record locks available */
#endif
#ifndef EACCES
#define EACCES 13 /* Permission denied */
#endif
#ifndef EPERM
#define EPERM 1 /* Operation not permitted */
#endif
#ifndef ETIMEDOUT
#define ETIMEDOUT 145 /* Connection timed out */
#endif
#ifndef ENOTCONN
#define ENOTCONN 134 /* Transport endpoint is not connected */
#endif
#if defined(__GNUC__) || defined(__ADSPBLACKFIN__)
int _gettimeofday(struct timeval *tp, void *ignore) __attribute__((weak));
int _gettimeofday(struct timeval *tp, void *ignore)
#elif defined(__CC_ARM)
__weak int _gettimeofday(struct timeval *tp, void *ignore)
#elif defined(__IAR_SYSTEMS_ICC__)
#if __VER__ > 540
__weak
#endif
int _gettimeofday(struct timeval *tp, void *ignore)
#else
int _gettimeofday(struct timeval *tp, void *ignore)
#endif
{
return 0;
}
#endif /* RT_USING_NEWLIB */
/*
** Compiling and using WAL mode requires several APIs that are not
** available in rt-thread.
@@ -269,10 +315,10 @@ static struct rtthread_syscall {
#define osFstat ((int(*)(int,struct stat*))aSyscall[5].pCurrent)
{ "read", (sqlite3_syscall_ptr)read, 0 },
#define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[6].pCurrent)
#define osRead ((int(*)(int,void*,size_t))aSyscall[6].pCurrent)
{ "write", (sqlite3_syscall_ptr)write, 0 },
#define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[7].pCurrent)
#define osWrite ((int(*)(int,const void*,size_t))aSyscall[7].pCurrent)
{ "unlink", (sqlite3_syscall_ptr)unlink, 0 },
#define osUnlink ((int(*)(const char*))aSyscall[8].pCurrent)
@@ -624,9 +670,9 @@ static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) {
return SQLITE_OK;
#endif
case EAGAIN:
case DFS_STATUS_EAGAIN:
case ETIMEDOUT:
case EBUSY:
case DFS_STATUS_EBUSY:
case EINTR:
case ENOLCK:
/* random NFS retry error, unless during file system support
@@ -665,17 +711,17 @@ static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) {
/* invalid fd, unless during file system support introspection, in which
* it actually means what it says */
#endif
case EIO:
case EBADF:
case EINVAL:
case DFS_STATUS_EIO:
case DFS_STATUS_EBADF:
case DFS_STATUS_EINVAL:
case ENOTCONN:
case ENODEV:
case ENXIO:
case ENOENT:
case DFS_STATUS_ENODEV:
case DFS_STATUS_ENXIO:
case DFS_STATUS_ENOENT:
#ifdef ESTALE /* ESTALE is not defined on Interix systems */
case ESTALE:
#endif
case ENOSYS:
case DFS_STATUS_ENOSYS:
/* these should force the client to close the file and reconnect */
default:
@@ -732,11 +778,14 @@ static void verifyDbFile(rtthreadFile *pFile){
pFile->ctrlFlags |= UNIXFILE_WARNED;
return;
}
#warning " struct \"stat\" has no field \"st_nlink\""
#ifndef RT_USING_SQLITE
if( buf.st_nlink==0 && (pFile->ctrlFlags & UNIXFILE_DELETE)==0 ){
sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath);
pFile->ctrlFlags |= UNIXFILE_WARNED;
return;
}
#endif
}
/*
@@ -919,7 +968,7 @@ static int dotlockLock(sqlite3_file *id, int eFileLock) {
if( rc<0 ){
/* failed to open/create the lock directory */
int tErrno = errno;
if( EEXIST == tErrno ){
if( DFS_STATUS_EEXIST == tErrno ){
rc = SQLITE_BUSY;
} else {
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
@@ -970,11 +1019,11 @@ static int dotlockUnlock(sqlite3_file *id, int eFileLock) {
/* To fully unlock the database, delete the lock file */
assert( eFileLock==NO_LOCK );
rc = osRmdir(zLockFile);
if( rc<0 && errno==ENOTDIR ) rc = osUnlink(zLockFile);
if( rc<0 && errno==DFS_STATUS_ENOTDIR ) rc = osUnlink(zLockFile);
if( rc<0 ){
int tErrno = errno;
rc = 0;
if( ENOENT != tErrno ){
if( DFS_STATUS_ENOENT != tErrno ){
rc = SQLITE_IOERR_UNLOCK;
}
if( IS_LOCK_ERROR(rc) ){
@@ -1417,7 +1466,7 @@ static int rtthreadWrite(
SimulateDiskfullError(( wrote=0, amt=1 ));
if( amt>0 ){
if( wrote<0 && pFile->lastErrno!=ENOSPC ){
if( wrote<0 && pFile->lastErrno!=DFS_STATUS_ENOSPC ){
/* lastErrno set by seekAndWrite */
return SQLITE_IOERR_WRITE;
}else{
@@ -2249,7 +2298,7 @@ static int rtthreadOpen(
fd = robust_open(zName, openFlags, openMode);
OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
if( fd<0 && errno!=EISDIR && isReadWrite && !isExclusive ){
if( fd<0 && errno!=DFS_STATUS_EISDIR && isReadWrite && !isExclusive ){
/* Failed to open the file for read/write access. Try read-only. */
flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
openFlags &= ~(O_RDWR|O_CREAT);
@@ -2307,7 +2356,7 @@ static int rtthreadDelete(
UNUSED_PARAMETER(NotUsed);
SimulateIOError(return SQLITE_IOERR_DELETE);
if( osUnlink(zPath)==(-1) ){
if( errno==ENOENT ){
if( errno==DFS_STATUS_ENOENT ){
rc = SQLITE_IOERR_DELETE_NOENT;
}else{
rc = rtthreadLogError(SQLITE_IOERR_DELETE, "unlink", zPath);
@@ -2338,6 +2387,17 @@ static int rtthreadDelete(
**
** Otherwise return 0.
*/
#ifndef F_OK
# define F_OK 0
#endif
#ifndef R_OK
# define R_OK 4
#endif
#ifndef W_OK
# define W_OK 2
#endif
static int rtthreadAccess(
sqlite3_vfs *NotUsed, /* The VFS containing this xAccess method */
const char *zPath, /* Path of the file to examine */
@@ -0,0 +1,62 @@
#ifndef _SQLITE_CONFIG_RTTHREAD_H_
#define _SQLITE_CONFIG_RTTHREAD_H_
/*
* SQLite compile macro
*/
#ifndef SQLITE_MINIMUM_FILE_DESCRIPTOR
#define SQLITE_MINIMUM_FILE_DESCRIPTOR 0
#endif
#ifndef SQLITE_OMIT_LOAD_EXTENSION
#define SQLITE_OMIT_LOAD_EXTENSION 1
#endif
//#ifndef #define SQLITE_OMIT_WAL
#define SQLITE_OMIT_WAL
//#endif
#ifndef SQLITE_RTTHREAD_NO_WIDE
#define SQLITE_RTTHREAD_NO_WIDE 1
#endif
#ifndef SQLITE_ENABLE_LOCKING_STYLE
#define SQLITE_ENABLE_LOCKING_STYLE 0
#endif
#ifndef SQLITE_DISABLE_LOCKING_STYLE
#define SQLITE_DISABLE_LOCKING_STYLE 1
#endif
#ifndef SQLITE_TEMP_STORE
#define SQLITE_TEMP_STORE 1
#endif
#ifndef SQLITE_THREADSAFE
#define SQLITE_THREADSAFE 1
#endif
#ifndef HAVE_READLINE
#define HAVE_READLINE 0
#endif
#ifndef NDEBUG
#define NDEBUG
#endif
#ifndef _HAVE_SQLITE_CONFIG_H
#define _HAVE_SQLITE_CONFIG_H
#endif
#ifndef BUILD_sqlite
#define BUILD_sqlite
#endif
#ifndef SQLITE_OS_OTHER
#define SQLITE_OS_OTHER 1
#endif
#ifndef SQLITE_OS_RTTHREAD
#define SQLITE_OS_RTTHREAD 1
#endif
#endif
+1
View File
@@ -228,6 +228,7 @@ proc copy_file {filename} {
# inlining opportunities.
#
foreach file {
sqlite_config_rtthread.h
sqlite3.h
sqliteInt.h
+3
View File
@@ -19,6 +19,7 @@
*
* Change Logs:
* Date Author Notes
* 2013-12-23 Bernard Add the checking for ESHUTDOWN
*/
#ifndef __POSIX_TYPES_H__
@@ -37,7 +38,9 @@
#include <errno.h>
#include <stdarg.h>
#ifndef ESHUTDOWN
#define ESHUTDOWN 180
#endif
#else