mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-02-08 11:54:50 +08:00
add support uffs interface
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1243 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
@@ -1,92 +1,337 @@
|
||||
#include <rtthread.h>
|
||||
#include <dfs.h>
|
||||
#include <rtthread.h>
|
||||
#include <dfs_def.h>
|
||||
#include <dfs_fs.h>
|
||||
#include "uffs/uffs_fs.h"
|
||||
#include "uffs/uffs_mtb.h"
|
||||
#include "uffs/uffs_fd.h"
|
||||
#include "uffs_ext.h"
|
||||
|
||||
/* mount and unmount file system */
|
||||
static int dfs_uffs_mount(struct dfs_filesystem* fs, unsigned long rwflag, const void* data)
|
||||
/* mount and unmount file system */
|
||||
int dfs_uffs_mount(struct dfs_filesystem* fs, unsigned long rwflag, const void* data)
|
||||
{
|
||||
}
|
||||
return ((uffs_InitMountTable() == U_SUCC) ? 0 : -1);
|
||||
}
|
||||
|
||||
static int dfs_uffs_unmount(struct dfs_filesystem* fs)
|
||||
int dfs_uffs_unmount(struct dfs_filesystem* fs)
|
||||
{
|
||||
}
|
||||
uffs_ReleaseObjectBuf();
|
||||
return uffs_ReleaseMountTable();
|
||||
}
|
||||
|
||||
static int dfs_uffs_mkfs(const char* device_name)
|
||||
int dfs_uffs_mkfs(const char* device_name)
|
||||
{
|
||||
return uffs_format(NULL);
|
||||
}
|
||||
|
||||
int dfs_uffs_statfs(struct dfs_filesystem* fs, struct statfs *buf)
|
||||
{
|
||||
return -DFS_STATUS_EIO;
|
||||
}
|
||||
int ret = U_SUCC;
|
||||
uffs_MountTable *entry = (uffs_MountTable*)(fs->dev_id->user_data);
|
||||
struct uffs_StorageAttrSt *attr = entry->dev->attr;
|
||||
|
||||
static int dfs_uffs_statfs(struct dfs_filesystem* fs, struct _statfs *buf)
|
||||
buf->f_bsize = attr->page_data_size * attr->pages_per_block;
|
||||
buf->f_blocks = attr->total_blocks;
|
||||
buf->f_bfree = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int dfs_uffs_open(struct dfs_fd* fd)
|
||||
{
|
||||
int ret=U_SUCC;
|
||||
|
||||
if (fd->flags & DFS_O_DIRECTORY)
|
||||
{//Îļþ¼Ð
|
||||
uffs_DIR *dirp;
|
||||
/* open directory */
|
||||
|
||||
if (fd->flags & DFS_O_CREAT)
|
||||
{//´´½¨
|
||||
ret = uffs_open(fd->path,UO_CREATE|UO_DIR);
|
||||
if(ret != U_SUCC)
|
||||
{
|
||||
return U_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
dirp = uffs_opendir(fd->path);
|
||||
if(dirp == NULL)
|
||||
{
|
||||
uffs_set_error(-UEMFILE);
|
||||
ret = U_FAIL;
|
||||
}
|
||||
|
||||
fd->data = dirp;
|
||||
|
||||
return U_SUCC;
|
||||
}
|
||||
else
|
||||
{//Îļþ
|
||||
uffs_Object *fp;
|
||||
|
||||
int mode = UO_RDONLY;
|
||||
|
||||
if (fd->flags & DFS_O_WRONLY) mode |= UO_WRONLY;
|
||||
if ((fd->flags & DFS_O_ACCMODE) & DFS_O_RDWR) mode |= UO_WRONLY;
|
||||
/* Opens the file, if it is existing. If not, a new file is created. */
|
||||
if (fd->flags & DFS_O_CREAT) mode |= UO_CREATE;
|
||||
/* Creates a new file. If the file is existing, it is truncated and overwritten. */
|
||||
if (fd->flags & DFS_O_TRUNC) mode |= UO_TRUNC;
|
||||
/* Creates a new file. The function fails if the file is already existing. */
|
||||
if (fd->flags & DFS_O_EXCL) mode |= UO_EXCL;
|
||||
|
||||
/* allocate a fd */
|
||||
|
||||
/* open directory */
|
||||
fp = uffs_GetObject();
|
||||
if(fp == NULL)
|
||||
{
|
||||
uffs_set_error(-UEMFILE);
|
||||
ret = U_FAIL;
|
||||
}
|
||||
|
||||
if(uffs_OpenObject(fp, fd->path, mode) == RT_EOK)
|
||||
{
|
||||
struct uffs_stat stat_buf;
|
||||
|
||||
uffs_stat(fd->path, &stat_buf);
|
||||
|
||||
fd->pos = fp->pos;
|
||||
fd->size = stat_buf.st_size;
|
||||
fd->data = fp;
|
||||
|
||||
if(fd->flags & DFS_O_APPEND)
|
||||
{
|
||||
fd->pos = uffs_SeekObject(fp, 0, USEEK_END);
|
||||
}
|
||||
ret = U_SUCC;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* open failed, return */
|
||||
uffs_set_error(-uffs_GetObjectErr(fp));
|
||||
uffs_PutObject(fp);
|
||||
return U_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int dfs_uffs_close(struct dfs_fd* fd)
|
||||
{
|
||||
}
|
||||
int ret=U_SUCC;
|
||||
|
||||
static int dfs_uffs_open(struct dfs_fd* fd)
|
||||
if (fd->type == FT_DIRECTORY)
|
||||
{
|
||||
uffs_DIR* dirp;
|
||||
|
||||
dirp = (uffs_DIR*)(fd->data);
|
||||
RT_ASSERT(dirp != RT_NULL);
|
||||
|
||||
uffs_closedir(dirp);
|
||||
}
|
||||
else if (fd->type == FT_REGULAR)
|
||||
{
|
||||
uffs_Object* fp;
|
||||
|
||||
fp = (uffs_Object*)(fd->data);
|
||||
|
||||
RT_ASSERT(fd != RT_NULL);
|
||||
|
||||
ret = uffs_CloseObject(fp);
|
||||
uffs_PutObject(fp);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int dfs_uffs_ioctl(struct dfs_fd* fd, int cmd, void *args)
|
||||
{
|
||||
}
|
||||
return -DFS_STATUS_ENOSYS;
|
||||
}
|
||||
|
||||
static int dfs_uffs_close(struct dfs_fd* fd)
|
||||
int dfs_uffs_read(struct dfs_fd* fd, void* buf, rt_size_t count)
|
||||
{
|
||||
}
|
||||
uffs_Object* fp;
|
||||
uffs_DIR* dirp;
|
||||
|
||||
static int dfs_uffs_ioctl(struct dfs_fd* fd, int cmd, void *args)
|
||||
if (fd->type == FT_DIRECTORY)
|
||||
{
|
||||
dirp = (uffs_DIR*)(fd->data);
|
||||
fp = dirp->obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
fp = (uffs_Object*)(fd->data);
|
||||
}
|
||||
|
||||
RT_ASSERT(fd != RT_NULL);
|
||||
|
||||
/* update position */
|
||||
fd->pos = fp->pos;
|
||||
|
||||
return uffs_ReadObject(fp, buf, count);
|
||||
}
|
||||
|
||||
int dfs_uffs_write(struct dfs_fd* fd, const void* buf, rt_size_t count)
|
||||
{
|
||||
}
|
||||
uffs_Object* fp;
|
||||
u32 byte_write;
|
||||
struct uffs_stat stat_buf;
|
||||
|
||||
static int dfs_uffs_read(struct dfs_fd* fd, void* buf, rt_size_t count)
|
||||
if(fd->type == FT_DIRECTORY)
|
||||
{
|
||||
return -DFS_STATUS_EISDIR;
|
||||
}
|
||||
|
||||
fp = (uffs_Object*)(fd->data);
|
||||
RT_ASSERT(fp != RT_NULL);
|
||||
|
||||
byte_write = uffs_WriteObject(fp, buf, count);
|
||||
|
||||
/* update position and file size */
|
||||
fd->pos = fp->pos;
|
||||
|
||||
uffs_stat(fp->name, &stat_buf);
|
||||
fd->size = stat_buf.st_size;
|
||||
|
||||
return byte_write;
|
||||
}
|
||||
|
||||
int dfs_uffs_flush(struct dfs_fd* fd)
|
||||
{
|
||||
}
|
||||
uffs_Object* fp;
|
||||
|
||||
static int dfs_uffs_write(struct dfs_fd* fd, const void* buf, rt_size_t count)
|
||||
fp = (uffs_Object*)(fd->data);
|
||||
RT_ASSERT(fp != RT_NULL);
|
||||
|
||||
return uffs_FlushObject(fp);
|
||||
}
|
||||
|
||||
int dfs_uffs_lseek(struct dfs_fd* fd, rt_off_t offset)
|
||||
{
|
||||
}
|
||||
uffs_Object* fp;
|
||||
|
||||
static int dfs_uffs_flush(struct dfs_fd* fd)
|
||||
fp = (uffs_Object*)(fd->data);
|
||||
RT_ASSERT(fp != RT_NULL);
|
||||
|
||||
return uffs_SeekObject(fp, USEEK_SET, offset);
|
||||
}
|
||||
|
||||
int dfs_uffs_getdents(struct dfs_fd* fd, struct dirent* dir, rt_uint32_t count)
|
||||
{
|
||||
}
|
||||
uffs_DIR* dirp;
|
||||
struct uffs_dirent *ent;
|
||||
rt_uint32_t index;
|
||||
struct dirent* d;
|
||||
|
||||
static int dfs_uffs_lseek(struct dfs_fd* fd, rt_off_t offset)
|
||||
dirp = (uffs_DIR*)(fd->data);
|
||||
RT_ASSERT(dirp != RT_NULL);
|
||||
|
||||
/* make integer count */
|
||||
count = (count / sizeof(struct dirent)) * sizeof(struct dirent);
|
||||
if ( count == 0 ) return -DFS_STATUS_EINVAL;
|
||||
|
||||
index = 0;
|
||||
while (1)
|
||||
{
|
||||
d = dir + index;
|
||||
|
||||
ent = uffs_readdir(dirp);
|
||||
if(ent == RT_NULL)break;
|
||||
|
||||
|
||||
d->d_type = DFS_DT_DIR;
|
||||
|
||||
d->d_namlen = ent->d_namelen;
|
||||
d->d_reclen = (rt_uint16_t)sizeof(struct dirent);
|
||||
rt_strncpy(d->d_name, ent->d_name, rt_strlen(ent->d_name) + 1);
|
||||
|
||||
index ++;
|
||||
if ( index * sizeof(struct dirent) >= count )
|
||||
break;
|
||||
}
|
||||
return index * sizeof(struct dirent);
|
||||
}
|
||||
|
||||
//Delete a File or Directory
|
||||
int dfs_uffs_unlink(struct dfs_filesystem* fs, const char* path)
|
||||
{
|
||||
}
|
||||
int ret;
|
||||
int err = 0;
|
||||
|
||||
static int dfs_uffs_getdents(struct dfs_fd* fd, struct _dirent* dirp, rt_uint32_t count)
|
||||
ret = uffs_DeleteObject(path, &err);
|
||||
uffs_set_error(-err);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int dfs_uffs_stat(struct dfs_filesystem* fs, const char* path, struct stat* st)
|
||||
{
|
||||
}
|
||||
int ret=U_SUCC;
|
||||
struct uffs_stat stat_buf;
|
||||
|
||||
static int dfs_uffs_unlink(struct dfs_filesystem* fs, const char* pathname)
|
||||
ret = uffs_stat(path, &stat_buf);
|
||||
|
||||
if (ret == U_SUCC)
|
||||
{
|
||||
st->st_dev = 0;
|
||||
//st->st_mode = stat_buf.st_mode;
|
||||
|
||||
st->st_mode = DFS_S_IFREG | DFS_S_IRUSR | DFS_S_IRGRP | DFS_S_IROTH |
|
||||
DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH;
|
||||
if (stat_buf.st_mode & US_IFDIR)
|
||||
{
|
||||
st->st_mode &= ~DFS_S_IFREG;
|
||||
st->st_mode |= DFS_S_IFDIR | DFS_S_IXUSR | DFS_S_IXGRP | DFS_S_IXOTH;
|
||||
}
|
||||
if (stat_buf.st_mode & US_IREAD)
|
||||
st->st_mode &= ~(DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH);
|
||||
st->st_size = stat_buf.st_size;
|
||||
st->st_mtime= stat_buf.st_mtime;
|
||||
st->st_blksize= stat_buf.st_blksize;
|
||||
|
||||
return U_SUCC;
|
||||
}
|
||||
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
int dfs_uffs_rename(struct dfs_filesystem* fs, const char* oldpath, const char* newpath)
|
||||
{
|
||||
}
|
||||
int ret;
|
||||
int err = 0;
|
||||
|
||||
static int dfs_uffs_stat(struct dfs_filesystem* fs, const char* filename, struct _stat* buf)
|
||||
{
|
||||
}
|
||||
ret = uffs_RenameObject(oldpath, newpath, &err);
|
||||
uffs_set_error(-err);
|
||||
|
||||
static int dfs_uffs_rename(struct dfs_filesystem* fs, const char* oldpath, const char* newpath)
|
||||
{
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct dfs_filesystem_operation _uffs =
|
||||
{
|
||||
"uffs",
|
||||
dfs_uffs_mount,
|
||||
dfs_uffs_unmount,
|
||||
dfs_uffs_mkfs,
|
||||
dfs_uffs_statfs,
|
||||
struct dfs_filesystem_operation _uffs =
|
||||
{
|
||||
"uffs",
|
||||
dfs_uffs_mount,
|
||||
dfs_uffs_unmount,
|
||||
dfs_uffs_mkfs,
|
||||
dfs_uffs_statfs,
|
||||
dfs_uffs_open,
|
||||
dfs_uffs_close,
|
||||
dfs_uffs_ioctl,
|
||||
dfs_uffs_read,
|
||||
dfs_uffs_write,
|
||||
dfs_uffs_flush,
|
||||
dfs_uffs_lseek,
|
||||
dfs_uffs_getdents,
|
||||
dfs_uffs_unlink,
|
||||
dfs_uffs_stat,
|
||||
dfs_uffs_rename,
|
||||
};
|
||||
|
||||
dfs_uffs_open,
|
||||
dfs_uffs_close,
|
||||
dfs_uffs_ioctl,
|
||||
dfs_uffs_read,
|
||||
dfs_uffs_write,
|
||||
dfs_uffs_flush,
|
||||
dfs_uffs_lseek,
|
||||
dfs_uffs_getdents,
|
||||
dfs_uffs_unlink,
|
||||
dfs_uffs_stat,
|
||||
dfs_uffs_rename,
|
||||
};
|
||||
int dfs_uffs_init(void)
|
||||
{
|
||||
/* register UFFS file system */
|
||||
return dfs_register(&_uffs);
|
||||
}
|
||||
|
||||
int dfs_uffs_init(void)
|
||||
{
|
||||
/* register UFFS file system */
|
||||
return dfs_register(&_uffs);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,30 @@
|
||||
/*
|
||||
* File : dfs_uffs.h
|
||||
* This file is part of Device File System in RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2004-2010, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2010-09-02 Bernard The first version.
|
||||
*/
|
||||
+------------------------------------------------------------------------------
|
||||
| Project : Device Filesystem
|
||||
+------------------------------------------------------------------------------
|
||||
| Copyright 2010
|
||||
| All rights reserved.
|
||||
|------------------------------------------------------------------------------
|
||||
| File : dfs_uffs.h
|
||||
|------------------------------------------------------------------------------
|
||||
| Chang Logs:
|
||||
| Date Author Notes
|
||||
| 2010-12-24 amsl Add dfs_uffs_init function declaration
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef __DFS_UFFS_H__
|
||||
#define __DFS_UFFS_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int dfs_uffs_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ struct cli_commandset {
|
||||
const char * cli_getparam(const char *tail, const char **next);
|
||||
void cli_add_commandset(struct cli_commandset *cmds);
|
||||
void cliInterpret(const char *line);
|
||||
void cliMain();
|
||||
void cliMain(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
*/
|
||||
#include "uffs/uffs_os.h"
|
||||
#include "uffs/uffs_public.h"
|
||||
#include <memory.h>
|
||||
//#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
@@ -98,7 +98,7 @@ unsigned int uffs_GetCurDateTime(void)
|
||||
// or just return 0 if you don't care about file time.
|
||||
time_t tvalue;
|
||||
|
||||
tvalue = time(NULL);
|
||||
tvalue = 0;//time(NULL);
|
||||
|
||||
return (unsigned int)tvalue;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
INCLUDE_DIRECTORIES(${uffs_SOURCE_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${uffs_SOURCE_DIR}/src/emu)
|
||||
|
||||
LINK_DIRECTORIES(${uffs_BINARY_DIR}/src/emu)
|
||||
LINK_DIRECTORIES(${uffs_BINARY_DIR}/src/uffs)
|
||||
|
||||
SET(static_mem_SRCS static-mem-allocate.c)
|
||||
SET(flash_if_SRCS flash-interface-example.c)
|
||||
ADD_EXECUTABLE(static-mem-example ${static_mem_SRCS})
|
||||
ADD_EXECUTABLE(flash-if-example ${flash_if_SRCS})
|
||||
TARGET_LINK_LIBRARIES(static-mem-example emu uffs emu)
|
||||
TARGET_LINK_LIBRARIES(flash-if-example emu uffs emu)
|
||||
INCLUDE_DIRECTORIES(${uffs_SOURCE_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${uffs_SOURCE_DIR}/src/emu)
|
||||
|
||||
LINK_DIRECTORIES(${uffs_BINARY_DIR}/src/emu)
|
||||
LINK_DIRECTORIES(${uffs_BINARY_DIR}/src/uffs)
|
||||
|
||||
SET(static_mem_SRCS static-mem-allocate.c)
|
||||
SET(flash_if_SRCS flash-interface-example.c)
|
||||
ADD_EXECUTABLE(static-mem-example ${static_mem_SRCS})
|
||||
ADD_EXECUTABLE(flash-if-example ${flash_if_SRCS})
|
||||
TARGET_LINK_LIBRARIES(static-mem-example emu uffs emu)
|
||||
TARGET_LINK_LIBRARIES(flash-if-example emu uffs emu)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,161 +1,155 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file static-mem-allocate.c
|
||||
* \brief demostrate how to use static memory allocation. This example use
|
||||
* file emulated NAND flash.
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_public.h"
|
||||
#include "uffs/uffs_fs.h"
|
||||
#include "uffs/uffs_utils.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
#include "uffs/uffs_mtb.h"
|
||||
#include "cmdline.h"
|
||||
#include "uffs_fileem.h"
|
||||
|
||||
#define PFX "static-example: "
|
||||
|
||||
#if CONFIG_USE_STATIC_MEMORY_ALLOCATOR == 0
|
||||
int main()
|
||||
{
|
||||
uffs_Perror(UFFS_ERR_NORMAL, "This example need CONFIG_USE_STATIC_MEMORY_ALLOCATOR = 1");
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
extern struct cli_commandset * get_helper_cmds(void);
|
||||
|
||||
#define DEFAULT_EMU_FILENAME "uffsemfile.bin"
|
||||
|
||||
#define PAGE_DATA_SIZE 512
|
||||
#define PAGE_SPARE_SIZE 16
|
||||
#define PAGES_PER_BLOCK 32
|
||||
#define TOTAL_BLOCKS 128
|
||||
|
||||
#define PAGE_SIZE (PAGE_DATA_SIZE + PAGE_SPARE_SIZE)
|
||||
#define BLOCK_DATA_SIZE (PAGES_PER_BLOCK * PAGE_DATA_SIZE)
|
||||
#define TOTAL_DATA_SIZE (TOTAL_BLOCKS * BLOCK_DATA_SIZE)
|
||||
#define BLOCK_SIZE (PAGES_PER_BLOCK * PAGE_SIZE)
|
||||
#define TOTAL_SIZE (BLOCK_SIZE * TOTAL_BLOCKS)
|
||||
|
||||
#define MAX_MOUNT_TABLES 10
|
||||
#define MAX_MOUNT_POINT_NAME 32
|
||||
|
||||
static uffs_Device demo_device = {0};
|
||||
static struct uffs_MountTableEntrySt demo_mount = {
|
||||
&demo_device,
|
||||
0, /* start from block 0 */
|
||||
-1, /* use whole chip */
|
||||
"/", /* mount point */
|
||||
NULL
|
||||
};
|
||||
|
||||
static struct uffs_StorageAttrSt emu_storage = {0};
|
||||
static struct uffs_FileEmuSt emu_private = {0};
|
||||
|
||||
/* static alloc the memory */
|
||||
static int static_buffer_pool[UFFS_STATIC_BUFF_SIZE(PAGES_PER_BLOCK, PAGE_SIZE, TOTAL_BLOCKS) / sizeof(int)];
|
||||
|
||||
|
||||
static void setup_emu_storage(struct uffs_StorageAttrSt *attr)
|
||||
{
|
||||
attr->total_blocks = TOTAL_BLOCKS; /* total blocks */
|
||||
attr->page_data_size = PAGE_DATA_SIZE; /* page data size */
|
||||
attr->spare_size = PAGE_SPARE_SIZE; /* page spare size */
|
||||
attr->pages_per_block = PAGES_PER_BLOCK; /* pages per block */
|
||||
attr->block_status_offs = 4; /* block status offset is 5th byte in spare */
|
||||
attr->ecc_opt = UFFS_ECC_SOFT; /* ecc option */
|
||||
attr->layout_opt = UFFS_LAYOUT_UFFS; /* let UFFS do the spare layout */
|
||||
|
||||
}
|
||||
|
||||
static void setup_emu_private(uffs_FileEmu *emu)
|
||||
{
|
||||
memset(emu, 0, sizeof(uffs_FileEmu));
|
||||
emu->emu_filename = DEFAULT_EMU_FILENAME;
|
||||
}
|
||||
|
||||
static int init_uffs_fs(void)
|
||||
{
|
||||
struct uffs_MountTableEntrySt *mtbl = &demo_mount;
|
||||
|
||||
/* setup emu storage */
|
||||
setup_emu_storage(&emu_storage);
|
||||
setup_emu_private(&emu_private);
|
||||
emu_storage._private = &emu_private;
|
||||
mtbl->dev->attr = &emu_storage;
|
||||
|
||||
/* setup memory allocator */
|
||||
uffs_MemSetupStaticAllocator(&mtbl->dev->mem, static_buffer_pool, sizeof(static_buffer_pool));
|
||||
|
||||
/* setup device */
|
||||
uffs_fileem_setup_device(mtbl->dev);
|
||||
|
||||
/* register mount table */
|
||||
uffs_RegisterMountTable(mtbl);
|
||||
|
||||
return uffs_InitMountTable() == U_SUCC ? 0 : -1;
|
||||
}
|
||||
|
||||
static int release_uffs_fs(void)
|
||||
{
|
||||
return uffs_ReleaseMountTable();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = init_uffs_fs();
|
||||
|
||||
if (ret != 0) {
|
||||
printf ("Init file system fail: %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
cli_add_commandset(get_helper_cmds());
|
||||
cliMain();
|
||||
|
||||
release_uffs_fs();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file static-mem-allocate.c
|
||||
* \brief demostrate how to use static memory allocation. This example use
|
||||
* file emulated NAND flash, one partition only.
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_public.h"
|
||||
#include "uffs/uffs_fs.h"
|
||||
#include "uffs/uffs_utils.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
#include "uffs/uffs_mtb.h"
|
||||
#include "cmdline.h"
|
||||
#include "uffs_fileem.h"
|
||||
|
||||
#define PFX "static-example: "
|
||||
|
||||
#if CONFIG_USE_STATIC_MEMORY_ALLOCATOR == 0
|
||||
int main()
|
||||
{
|
||||
uffs_Perror(UFFS_ERR_NORMAL, "This example need CONFIG_USE_STATIC_MEMORY_ALLOCATOR = 1");
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
extern struct cli_commandset * get_helper_cmds(void);
|
||||
|
||||
#define PAGE_DATA_SIZE 512
|
||||
#define PAGE_SPARE_SIZE 16
|
||||
#define PAGES_PER_BLOCK 32
|
||||
#define TOTAL_BLOCKS 128
|
||||
|
||||
#define PAGE_SIZE (PAGE_DATA_SIZE + PAGE_SPARE_SIZE)
|
||||
#define BLOCK_DATA_SIZE (PAGES_PER_BLOCK * PAGE_DATA_SIZE)
|
||||
#define TOTAL_DATA_SIZE (TOTAL_BLOCKS * BLOCK_DATA_SIZE)
|
||||
#define BLOCK_SIZE (PAGES_PER_BLOCK * PAGE_SIZE)
|
||||
#define TOTAL_SIZE (BLOCK_SIZE * TOTAL_BLOCKS)
|
||||
|
||||
#define MAX_MOUNT_TABLES 10
|
||||
#define MAX_MOUNT_POINT_NAME 32
|
||||
|
||||
static uffs_Device demo_device = {0};
|
||||
static struct uffs_MountTableEntrySt demo_mount = {
|
||||
&demo_device,
|
||||
0, /* start from block 0 */
|
||||
-1, /* use whole chip */
|
||||
"/", /* mount point */
|
||||
NULL
|
||||
};
|
||||
|
||||
/* static alloc the memory */
|
||||
static int static_buffer_pool[UFFS_STATIC_BUFF_SIZE(PAGES_PER_BLOCK, PAGE_SIZE, TOTAL_BLOCKS) / sizeof(int)];
|
||||
|
||||
|
||||
static void setup_storage(struct uffs_StorageAttrSt *attr)
|
||||
{
|
||||
attr->total_blocks = TOTAL_BLOCKS; /* total blocks */
|
||||
attr->page_data_size = PAGE_DATA_SIZE; /* page data size */
|
||||
attr->spare_size = PAGE_SPARE_SIZE; /* page spare size */
|
||||
attr->pages_per_block = PAGES_PER_BLOCK; /* pages per block */
|
||||
attr->block_status_offs = 4; /* block status offset is 5th byte in spare */
|
||||
attr->ecc_opt = UFFS_ECC_SOFT; /* use UFFS software ecc */
|
||||
attr->layout_opt = UFFS_LAYOUT_UFFS; /* let UFFS do the spare layout */
|
||||
}
|
||||
|
||||
static void setup_device(uffs_Device *dev)
|
||||
{
|
||||
// using file emulator device
|
||||
dev->Init = femu_InitDevice;
|
||||
dev->Release = femu_ReleaseDevice;
|
||||
dev->attr = femu_GetStorage();
|
||||
}
|
||||
|
||||
static int init_uffs_fs(void)
|
||||
{
|
||||
struct uffs_MountTableEntrySt *mtbl = &demo_mount;
|
||||
|
||||
/* setup flash storage attributes */
|
||||
setup_storage(femu_GetStorage());
|
||||
|
||||
/* setup memory allocator */
|
||||
uffs_MemSetupStaticAllocator(&mtbl->dev->mem, static_buffer_pool, sizeof(static_buffer_pool));
|
||||
|
||||
/* setup device: init, release, attr */
|
||||
setup_device(mtbl->dev);
|
||||
|
||||
/* register mount table */
|
||||
uffs_RegisterMountTable(mtbl);
|
||||
|
||||
return uffs_InitMountTable() == U_SUCC ? 0 : -1;
|
||||
}
|
||||
|
||||
static int release_uffs_fs(void)
|
||||
{
|
||||
return uffs_ReleaseMountTable();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = init_uffs_fs();
|
||||
|
||||
if (ret != 0) {
|
||||
printf ("Init file system fail: %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
cli_add_commandset(get_helper_cmds());
|
||||
cli_add_commandset(get_test_cmds());
|
||||
cliMain();
|
||||
|
||||
release_uffs_fs();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
/**
|
||||
* \file uffs.h
|
||||
@@ -37,98 +37,98 @@
|
||||
|
||||
#ifndef _UFFS_H_
|
||||
#define _UFFS_H_
|
||||
|
||||
#include <dfs_def.h>
|
||||
#include "uffs/uffs_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define UO_RDONLY 0x0000 /** read only */
|
||||
#define UO_WRONLY 0x0001 /** write only */
|
||||
#define UO_RDWR 0x0002 /** read and write */
|
||||
#define UO_APPEND 0x0008 /** append */
|
||||
#define UO_RDONLY DFS_O_RDONLY /** read only */
|
||||
#define UO_WRONLY DFS_O_WRONLY /** write only */
|
||||
#define UO_RDWR DFS_O_RDWR /** read and write */
|
||||
#define UO_APPEND DFS_O_APPEND /** append */
|
||||
|
||||
#define UO_BINARY 0x0000 /** no used in uffs */
|
||||
|
||||
#define UO_BINARY 0x0000 /** no used in uffs */
|
||||
#define UO_CREATE DFS_O_CREAT
|
||||
#define UO_TRUNC DFS_O_TRUNC
|
||||
#define UO_EXCL DFS_O_EXCL
|
||||
|
||||
#define UO_CREATE 0x0100
|
||||
#define UO_TRUNC 0x0200
|
||||
#define UO_EXCL 0x0400
|
||||
|
||||
#define UO_DIR 0x1000 /** open a directory */
|
||||
#define UO_DIR DFS_O_DIRECTORY /** open a directory */
|
||||
|
||||
|
||||
|
||||
#define UENOERR 0 /** no error */
|
||||
#define UEACCES 1 /** Tried to open read-only file
|
||||
for writing, or files sharing mode
|
||||
does not allow specified operations,
|
||||
or given path is directory */
|
||||
#define UENOERR 0 /** no error */
|
||||
#define UEACCES 1 /** Tried to open read-only file
|
||||
for writing, or files sharing mode
|
||||
does not allow specified operations,
|
||||
or given path is directory */
|
||||
|
||||
#define UEEXIST 2 /** _O_CREAT and _O_EXCL flags specified,
|
||||
#define UEEXIST 2 /** _O_CREAT and _O_EXCL flags specified,
|
||||
but filename already exists */
|
||||
#define UEINVAL 3 /** Invalid oflag or pmode argument */
|
||||
#define UEMFILE 4 /** No more file handles available
|
||||
(too many open files) */
|
||||
#define UENOENT 5 /** file or path not found */
|
||||
#define UETIME 6 /** can't set file time */
|
||||
#define UEBADF 9 /** invalid file handle */
|
||||
#define UENOMEM 10 /** no enough memory */
|
||||
#define UEIOERR 11 /** I/O error from lower level flash operation */
|
||||
#define UENOTDIR 12 /** Not a directory */
|
||||
#define UEISDIR 13 /** Is a directory */
|
||||
#define UEINVAL 3 /** Invalid oflag or pmode argument */
|
||||
#define UEMFILE 4 /** No more file handles available
|
||||
(too many open files) */
|
||||
#define UENOENT 5 /** file or path not found */
|
||||
#define UETIME 6 /** can't set file time */
|
||||
#define UEBADF 9 /** invalid file handle */
|
||||
#define UENOMEM 10 /** no enough memory */
|
||||
#define UEIOERR 11 /** I/O error from lower level flash operation */
|
||||
#define UENOTDIR 12 /** Not a directory */
|
||||
#define UEISDIR 13 /** Is a directory */
|
||||
|
||||
#define UEUNKNOWN 100 /** unknown error */
|
||||
#define UEUNKNOWN 100 /** unknown error */
|
||||
|
||||
|
||||
#define _SEEK_CUR 0 /** seek from current position */
|
||||
#define _SEEK_SET 1 /** seek from beginning of file */
|
||||
#define _SEEK_END 2 /** seek from end of file */
|
||||
|
||||
#define USEEK_SET DFS_SEEK_SET /*0* 从当前点寻找 */
|
||||
#define USEEK_CUR DFS_SEEK_CUR /*1* 从文件的开始寻找 */
|
||||
#define USEEK_END DFS_SEEK_END /*2* 从文件的结尾寻找 */
|
||||
|
||||
|
||||
|
||||
#define _SEEK_CUR 0 /** seek from current position */
|
||||
#define _SEEK_SET 1 /** seek from beginning of file */
|
||||
#define _SEEK_END 2 /** seek from end of file */
|
||||
|
||||
#define USEEK_CUR _SEEK_CUR
|
||||
#define USEEK_SET _SEEK_SET
|
||||
#define USEEK_END _SEEK_END
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \def MAX_FILENAME_LENGTH
|
||||
* \note Be careful: it's part of the physical format (see: uffs_FileInfoSt.name)
|
||||
* !!DO NOT CHANGE IT AFTER FILE SYSTEM IS FORMATED!!
|
||||
*/
|
||||
#define MAX_FILENAME_LENGTH 32
|
||||
|
||||
/** \note 8-bits attr goes to uffs_dirent::d_type */
|
||||
#define FILE_ATTR_DIR (1 << 7) //!< attribute for directory
|
||||
#define FILE_ATTR_WRITE (1 << 0) //!< writable
|
||||
|
||||
|
||||
/**
|
||||
* \structure uffs_FileInfoSt
|
||||
* \brief file/dir entry info in physical storage format
|
||||
*/
|
||||
struct uffs_FileInfoSt {
|
||||
u32 attr; //!< file/dir attribute
|
||||
u32 create_time;
|
||||
u32 last_modify;
|
||||
u32 access;
|
||||
u32 reserved;
|
||||
u32 name_len; //!< length of file/dir name
|
||||
char name[MAX_FILENAME_LENGTH];
|
||||
};
|
||||
typedef struct uffs_FileInfoSt uffs_FileInfo;
|
||||
|
||||
/**
|
||||
* \struct uffs_ObjectInfoSt
|
||||
* \brief object info
|
||||
*/
|
||||
typedef struct uffs_ObjectInfoSt {
|
||||
uffs_FileInfo info;
|
||||
u32 len; //!< length of file
|
||||
u16 serial; //!< object serial num
|
||||
} uffs_ObjectInfo;
|
||||
/**
|
||||
* \def MAX_FILENAME_LENGTH
|
||||
* \note Be careful: it's part of the physical format (see: uffs_FileInfoSt.name)
|
||||
* !!DO NOT CHANGE IT AFTER FILE SYSTEM IS FORMATED!!
|
||||
*/
|
||||
#define MAX_FILENAME_LENGTH 32
|
||||
|
||||
/** \note 8-bits attr goes to uffs_dirent::d_type */
|
||||
#define FILE_ATTR_DIR (1 << 7) //!< attribute for directory
|
||||
#define FILE_ATTR_WRITE (1 << 0) //!< writable
|
||||
|
||||
|
||||
/*
|
||||
* \structure uffs_FileInfoSt
|
||||
* \brief file/dir entry info in physical storage format
|
||||
*/
|
||||
struct uffs_FileInfoSt {
|
||||
u32 attr; //!< file/dir attribute
|
||||
u32 create_time;
|
||||
u32 last_modify;
|
||||
u32 access;
|
||||
u32 reserved;
|
||||
u32 name_len; //!< length of file/dir name
|
||||
char name[MAX_FILENAME_LENGTH];
|
||||
};
|
||||
typedef struct uffs_FileInfoSt uffs_FileInfo;
|
||||
|
||||
/**
|
||||
* \struct uffs_ObjectInfoSt
|
||||
* \brief object info
|
||||
*/
|
||||
typedef struct uffs_ObjectInfoSt {
|
||||
uffs_FileInfo info;
|
||||
u32 len; //!< length of file
|
||||
u16 serial; //!< object serial num
|
||||
} uffs_ObjectInfo;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
/**
|
||||
* \file uffs_badblock.h
|
||||
* \brief bad block management
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_BADBLOCK_H_
|
||||
#define _UFFS_BADBLOCK_H_
|
||||
|
||||
#include "uffs/uffs_public.h"
|
||||
#include "uffs/uffs_device.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
#define HAVE_BADBLOCK(dev) (dev->bad.block != UFFS_INVALID_BLOCK)
|
||||
|
||||
/** initialize bad block management data structures for uffs device */
|
||||
void uffs_BadBlockInit(uffs_Device *dev);
|
||||
|
||||
/** processing bad block: erase bad block, mark it as 'bad' and put it to bad block list */
|
||||
void uffs_BadBlockProcess(uffs_Device *dev, TreeNode *node);
|
||||
|
||||
/** try to recover data from a new discovered bad block */
|
||||
void uffs_BadBlockRecover(uffs_Device *dev);
|
||||
|
||||
/** put a new block to the bad block waiting list */
|
||||
void uffs_BadBlockAdd(uffs_Device *dev, int block);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
/**
|
||||
* \file uffs_badblock.h
|
||||
* \brief bad block management
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_BADBLOCK_H_
|
||||
#define _UFFS_BADBLOCK_H_
|
||||
|
||||
#include "uffs/uffs_public.h"
|
||||
#include "uffs/uffs_device.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
#define HAVE_BADBLOCK(dev) (dev->bad.block != UFFS_INVALID_BLOCK)
|
||||
|
||||
/** initialize bad block management data structures for uffs device */
|
||||
void uffs_BadBlockInit(uffs_Device *dev);
|
||||
|
||||
/** processing bad block: erase bad block, mark it as 'bad' and put it to bad block list */
|
||||
void uffs_BadBlockProcess(uffs_Device *dev, TreeNode *node);
|
||||
|
||||
/** try to recover data from a new discovered bad block */
|
||||
void uffs_BadBlockRecover(uffs_Device *dev);
|
||||
|
||||
/** put a new block to the bad block waiting list */
|
||||
void uffs_BadBlockAdd(uffs_Device *dev, int block);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,107 +1,107 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
/**
|
||||
* \file uffs_blockinfo.h
|
||||
* \brief data structure for operating block information
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_BLOCKINFO_H_
|
||||
#define _UFFS_BLOCKINFO_H_
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_public.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
/**
|
||||
* \struct uffs_PageSpareSt
|
||||
* \brief this structure is for storing uffs tag and more.
|
||||
*/
|
||||
struct uffs_PageSpareSt {
|
||||
uffs_Tags tag; //!< page tag
|
||||
u8 expired:1;
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_BlockInfoSt
|
||||
* \brief block information data. Block info is frequently accessed,
|
||||
UFFS use a cache system to speed up block info access.
|
||||
*/
|
||||
struct uffs_BlockInfoSt {
|
||||
struct uffs_BlockInfoSt *next;
|
||||
struct uffs_BlockInfoSt *prev;
|
||||
u16 block; //!< block number
|
||||
struct uffs_PageSpareSt *spares; //!< page spare info array
|
||||
int expired_count; //!< how many pages expired in this block ?
|
||||
int ref_count; //!< reference counter, it's safe to reuse this block memory when the counter is 0.
|
||||
};
|
||||
|
||||
/** get tag from block info */
|
||||
#define GET_TAG(bc, page) (&(bc)->spares[page].tag)
|
||||
|
||||
|
||||
/** initialize block info caches */
|
||||
URET uffs_BlockInfoInitCache(uffs_Device *dev, int maxCachedBlocks);
|
||||
|
||||
/** release block info caches */
|
||||
URET uffs_BlockInfoReleaseCache(uffs_Device *dev);
|
||||
|
||||
/** load page spare to block info cache */
|
||||
URET uffs_BlockInfoLoad(uffs_Device *dev, uffs_BlockInfo *work, int page);
|
||||
|
||||
/** find block info cache */
|
||||
uffs_BlockInfo * uffs_BlockInfoFindInCache(uffs_Device *dev, int block);
|
||||
|
||||
/** get block info cache, load it on demand */
|
||||
uffs_BlockInfo * uffs_BlockInfoGet(uffs_Device *dev, int block);
|
||||
|
||||
/** put info cache back to pool, should be called with #uffs_BlockInfoGet in pairs. */
|
||||
void uffs_BlockInfoPut(uffs_Device *dev, uffs_BlockInfo *p);
|
||||
|
||||
/** explicitly expire a block info cache */
|
||||
void uffs_BlockInfoExpire(uffs_Device *dev, uffs_BlockInfo *p, int page);
|
||||
|
||||
/** no one hold any block info cache ? safe to release block info caches */
|
||||
UBOOL uffs_BlockInfoIsAllFree(uffs_Device *dev);
|
||||
|
||||
/** explicitly expire all block info caches */
|
||||
void uffs_BlockInfoExpireAll(uffs_Device *dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
/**
|
||||
* \file uffs_blockinfo.h
|
||||
* \brief data structure for operating block information
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_BLOCKINFO_H_
|
||||
#define _UFFS_BLOCKINFO_H_
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_public.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
/**
|
||||
* \struct uffs_PageSpareSt
|
||||
* \brief this structure is for storing uffs tag and more.
|
||||
*/
|
||||
struct uffs_PageSpareSt {
|
||||
uffs_Tags tag; //!< page tag
|
||||
u8 expired:1;
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_BlockInfoSt
|
||||
* \brief block information data. Block info is frequently accessed,
|
||||
UFFS use a cache system to speed up block info access.
|
||||
*/
|
||||
struct uffs_BlockInfoSt {
|
||||
struct uffs_BlockInfoSt *next;
|
||||
struct uffs_BlockInfoSt *prev;
|
||||
u16 block; //!< block number
|
||||
struct uffs_PageSpareSt *spares; //!< page spare info array
|
||||
int expired_count; //!< how many pages expired in this block ?
|
||||
int ref_count; //!< reference counter, it's safe to reuse this block memory when the counter is 0.
|
||||
};
|
||||
|
||||
/** get tag from block info */
|
||||
#define GET_TAG(bc, page) (&(bc)->spares[page].tag)
|
||||
|
||||
|
||||
/** initialize block info caches */
|
||||
URET uffs_BlockInfoInitCache(uffs_Device *dev, int maxCachedBlocks);
|
||||
|
||||
/** release block info caches */
|
||||
URET uffs_BlockInfoReleaseCache(uffs_Device *dev);
|
||||
|
||||
/** load page spare to block info cache */
|
||||
URET uffs_BlockInfoLoad(uffs_Device *dev, uffs_BlockInfo *work, int page);
|
||||
|
||||
/** find block info cache */
|
||||
uffs_BlockInfo * uffs_BlockInfoFindInCache(uffs_Device *dev, int block);
|
||||
|
||||
/** get block info cache, load it on demand */
|
||||
uffs_BlockInfo * uffs_BlockInfoGet(uffs_Device *dev, int block);
|
||||
|
||||
/** put info cache back to pool, should be called with #uffs_BlockInfoGet in pairs. */
|
||||
void uffs_BlockInfoPut(uffs_Device *dev, uffs_BlockInfo *p);
|
||||
|
||||
/** explicitly expire a block info cache */
|
||||
void uffs_BlockInfoExpire(uffs_Device *dev, uffs_BlockInfo *p, int page);
|
||||
|
||||
/** no one hold any block info cache ? safe to release block info caches */
|
||||
UBOOL uffs_BlockInfoIsAllFree(uffs_Device *dev);
|
||||
|
||||
/** explicitly expire all block info caches */
|
||||
void uffs_BlockInfoExpireAll(uffs_Device *dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,174 +1,174 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_buf.h
|
||||
* \brief page buffers
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#ifndef UFFS_BUF_H
|
||||
#define UFFS_BUF_H
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_device.h"
|
||||
#include "uffs/uffs_tree.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
#define CLONE_BUF_MARK 0xffff //!< set uffs_BufSt::ref_count to this for a 'cloned' buffer
|
||||
|
||||
/** for uffs_BufSt::mark */
|
||||
#define UFFS_BUF_EMPTY 0 //!< buffer is empty
|
||||
#define UFFS_BUF_VALID 1 //!< buffer is holding valid data
|
||||
#define UFFS_BUF_DIRTY 2 //!< buffer data is modified
|
||||
|
||||
/** for uffs_BufSt::ext_mark */
|
||||
#define UFFS_BUF_EXT_MARK_TRUNC_TAIL 1 //!<
|
||||
|
||||
/** uffs page buffer */
|
||||
struct uffs_BufSt{
|
||||
struct uffs_BufSt *next; //!< link to next buffer
|
||||
struct uffs_BufSt *prev; //!< link to previous buffer
|
||||
struct uffs_BufSt *next_dirty; //!< link to next dirty buffer
|
||||
struct uffs_BufSt *prev_dirty; //!< link to previous dirty buffer
|
||||
u8 type; //!< #UFFS_TYPE_DIR or #UFFS_TYPE_FILE or #UFFS_TYPE_DATA
|
||||
u16 parent; //!< parent serial
|
||||
u16 serial; //!< serial
|
||||
u16 page_id; //!< page id
|
||||
u16 mark; //!< #UFFS_BUF_EMPTY or #UFFS_BUF_VALID, or #UFFS_BUF_DIRTY ?
|
||||
u16 ref_count; //!< reference counter, or #CLONE_BUF_MARK for a cloned buffer
|
||||
u16 data_len; //!< length of data
|
||||
u16 check_sum; //!< checksum field
|
||||
u8 * data; //!< data buffer
|
||||
u8 * header; //!< header
|
||||
int ext_mark; //!< extension mark.
|
||||
};
|
||||
|
||||
#define uffs_BufIsFree(buf) (buf->ref_count == 0 ? U_TRUE : U_FALSE)
|
||||
|
||||
/** initialize page buffers */
|
||||
URET uffs_BufInit(struct uffs_DeviceSt *dev, int buf_max, int dirty_buf_max);
|
||||
|
||||
/** release page buffers */
|
||||
URET uffs_BufReleaseAll(struct uffs_DeviceSt *dev);
|
||||
|
||||
/** find the page buffer, move to link list head if found */
|
||||
uffs_Buf * uffs_BufGet(struct uffs_DeviceSt *dev, u16 parent, u16 serial, u16 page_id);
|
||||
uffs_Buf *uffs_BufGetEx(struct uffs_DeviceSt *dev, u8 type, TreeNode *node, u16 page_id);
|
||||
|
||||
/** alloc a new page buffer */
|
||||
uffs_Buf *uffs_BufNew(struct uffs_DeviceSt *dev, u8 type, u16 parent, u16 serial, u16 page_id);
|
||||
|
||||
/** find the page buffer (not affect the reference counter) */
|
||||
uffs_Buf * uffs_BufFind(uffs_Device *dev, u16 parent, u16 serial, u16 page_id);
|
||||
|
||||
/** put page buffer back to pool, called in pair with #uffs_Get,#uffs_GetEx or #uffs_BufNew */
|
||||
URET uffs_BufPut(uffs_Device *dev, uffs_Buf *buf);
|
||||
|
||||
/** increase buffer references */
|
||||
void uffs_BufIncRef(uffs_Buf *buf);
|
||||
|
||||
/** decrease buffer references */
|
||||
void uffs_BufDecRef(uffs_Buf *buf);
|
||||
|
||||
/** write data to a page buffer */
|
||||
URET uffs_BufWrite(struct uffs_DeviceSt *dev, uffs_Buf *buf, void *data, u32 ofs, u32 len);
|
||||
|
||||
/** read data from a page buffer */
|
||||
URET uffs_BufRead(struct uffs_DeviceSt *dev, uffs_Buf *buf, void *data, u32 ofs, u32 len);
|
||||
|
||||
/** mark buffer as #UFFS_BUF_EMPTY if ref_count == 0, and discard all data it holds */
|
||||
void uffs_BufMarkEmpty(uffs_Device *dev, uffs_Buf *buf);
|
||||
|
||||
/** if there is no free dirty group slot, flush the most dirty group */
|
||||
URET uffs_BufFlush(struct uffs_DeviceSt *dev);
|
||||
URET uffs_BufFlushEx(struct uffs_DeviceSt *dev, UBOOL force_block_recover);
|
||||
|
||||
/** flush dirty group */
|
||||
URET uffs_BufFlushGroup(struct uffs_DeviceSt *dev, u16 parent, u16 serial);
|
||||
URET uffs_BufFlushGroupEx(struct uffs_DeviceSt *dev, u16 parent, u16 serial, UBOOL force_block_recover);
|
||||
|
||||
/** find free dirty group slot */
|
||||
int uffs_BufFindFreeGroupSlot(struct uffs_DeviceSt *dev);
|
||||
|
||||
/** find the dirty group slot */
|
||||
int uffs_BufFindGroupSlot(struct uffs_DeviceSt *dev, u16 parent, u16 serial);
|
||||
|
||||
/** lock dirty group */
|
||||
URET uffs_BufLockGroup(struct uffs_DeviceSt *dev, int slot);
|
||||
|
||||
/** unlock dirty group */
|
||||
URET uffs_BufUnLockGroup(struct uffs_DeviceSt *dev, int slot);
|
||||
|
||||
/** flush most dirty group */
|
||||
URET uffs_BufFlushMostDirtyGroup(struct uffs_DeviceSt *dev);
|
||||
|
||||
/** flush all groups under the same parent number */
|
||||
URET uffs_BufFlushGroupMatchParent(struct uffs_DeviceSt *dev, u16 parent);
|
||||
|
||||
/** flush all page buffers */
|
||||
URET uffs_BufFlushAll(struct uffs_DeviceSt *dev);
|
||||
|
||||
/** no one holding any page buffer ? safe to release page buffers */
|
||||
UBOOL uffs_BufIsAllFree(struct uffs_DeviceSt *dev);
|
||||
|
||||
/** are all page buffer marked with #UFFS_BUF_EMPTY ? */
|
||||
UBOOL uffs_BufIsAllEmpty(struct uffs_DeviceSt *dev);
|
||||
|
||||
/** mark all page buffer as #UFFS_BUF_EMPTY */
|
||||
URET uffs_BufSetAllEmpty(struct uffs_DeviceSt *dev);
|
||||
|
||||
/** clone a page buffer */
|
||||
uffs_Buf * uffs_BufClone(struct uffs_DeviceSt *dev, uffs_Buf *buf);
|
||||
|
||||
/** release a cloned page buffer, call in pair with #uffs_BufClone */
|
||||
URET uffs_BufFreeClone(uffs_Device *dev, uffs_Buf *buf);
|
||||
|
||||
/** load physical storage data to page buffer */
|
||||
URET uffs_BufLoadPhyData(uffs_Device *dev, uffs_Buf *buf, u32 block, u32 page);
|
||||
|
||||
/** load physical storage data to page buffer withouth checking ECC */
|
||||
URET uffs_LoadPhyDataToBufEccUnCare(uffs_Device *dev, uffs_Buf *buf, u32 block, u32 page);
|
||||
|
||||
/** showing page buffers info, for debug only */
|
||||
void uffs_BufInspect(uffs_Device *dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_buf.h
|
||||
* \brief page buffers
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#ifndef UFFS_BUF_H
|
||||
#define UFFS_BUF_H
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_device.h"
|
||||
#include "uffs/uffs_tree.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
#define CLONE_BUF_MARK 0xffff //!< set uffs_BufSt::ref_count to this for a 'cloned' buffer
|
||||
|
||||
/** for uffs_BufSt::mark */
|
||||
#define UFFS_BUF_EMPTY 0 //!< buffer is empty
|
||||
#define UFFS_BUF_VALID 1 //!< buffer is holding valid data
|
||||
#define UFFS_BUF_DIRTY 2 //!< buffer data is modified
|
||||
|
||||
/** for uffs_BufSt::ext_mark */
|
||||
#define UFFS_BUF_EXT_MARK_TRUNC_TAIL 1 //!<
|
||||
|
||||
/** uffs page buffer */
|
||||
struct uffs_BufSt{
|
||||
struct uffs_BufSt *next; //!< link to next buffer
|
||||
struct uffs_BufSt *prev; //!< link to previous buffer
|
||||
struct uffs_BufSt *next_dirty; //!< link to next dirty buffer
|
||||
struct uffs_BufSt *prev_dirty; //!< link to previous dirty buffer
|
||||
u8 type; //!< #UFFS_TYPE_DIR or #UFFS_TYPE_FILE or #UFFS_TYPE_DATA
|
||||
u16 parent; //!< parent serial
|
||||
u16 serial; //!< serial
|
||||
u16 page_id; //!< page id
|
||||
u16 mark; //!< #UFFS_BUF_EMPTY or #UFFS_BUF_VALID, or #UFFS_BUF_DIRTY ?
|
||||
u16 ref_count; //!< reference counter, or #CLONE_BUF_MARK for a cloned buffer
|
||||
u16 data_len; //!< length of data
|
||||
u16 check_sum; //!< checksum field
|
||||
u8 * data; //!< data buffer
|
||||
u8 * header; //!< header
|
||||
int ext_mark; //!< extension mark.
|
||||
};
|
||||
|
||||
#define uffs_BufIsFree(buf) (buf->ref_count == 0 ? U_TRUE : U_FALSE)
|
||||
|
||||
/** initialize page buffers */
|
||||
URET uffs_BufInit(struct uffs_DeviceSt *dev, int buf_max, int dirty_buf_max);
|
||||
|
||||
/** release page buffers */
|
||||
URET uffs_BufReleaseAll(struct uffs_DeviceSt *dev);
|
||||
|
||||
/** find the page buffer, move to link list head if found */
|
||||
uffs_Buf * uffs_BufGet(struct uffs_DeviceSt *dev, u16 parent, u16 serial, u16 page_id);
|
||||
uffs_Buf *uffs_BufGetEx(struct uffs_DeviceSt *dev, u8 type, TreeNode *node, u16 page_id);
|
||||
|
||||
/** alloc a new page buffer */
|
||||
uffs_Buf *uffs_BufNew(struct uffs_DeviceSt *dev, u8 type, u16 parent, u16 serial, u16 page_id);
|
||||
|
||||
/** find the page buffer (not affect the reference counter) */
|
||||
uffs_Buf * uffs_BufFind(uffs_Device *dev, u16 parent, u16 serial, u16 page_id);
|
||||
|
||||
/** put page buffer back to pool, called in pair with #uffs_Get,#uffs_GetEx or #uffs_BufNew */
|
||||
URET uffs_BufPut(uffs_Device *dev, uffs_Buf *buf);
|
||||
|
||||
/** increase buffer references */
|
||||
void uffs_BufIncRef(uffs_Buf *buf);
|
||||
|
||||
/** decrease buffer references */
|
||||
void uffs_BufDecRef(uffs_Buf *buf);
|
||||
|
||||
/** write data to a page buffer */
|
||||
URET uffs_BufWrite(struct uffs_DeviceSt *dev, uffs_Buf *buf, void *data, u32 ofs, u32 len);
|
||||
|
||||
/** read data from a page buffer */
|
||||
URET uffs_BufRead(struct uffs_DeviceSt *dev, uffs_Buf *buf, void *data, u32 ofs, u32 len);
|
||||
|
||||
/** mark buffer as #UFFS_BUF_EMPTY if ref_count == 0, and discard all data it holds */
|
||||
void uffs_BufMarkEmpty(uffs_Device *dev, uffs_Buf *buf);
|
||||
|
||||
/** if there is no free dirty group slot, flush the most dirty group */
|
||||
URET uffs_BufFlush(struct uffs_DeviceSt *dev);
|
||||
URET uffs_BufFlushEx(struct uffs_DeviceSt *dev, UBOOL force_block_recover);
|
||||
|
||||
/** flush dirty group */
|
||||
URET uffs_BufFlushGroup(struct uffs_DeviceSt *dev, u16 parent, u16 serial);
|
||||
URET uffs_BufFlushGroupEx(struct uffs_DeviceSt *dev, u16 parent, u16 serial, UBOOL force_block_recover);
|
||||
|
||||
/** find free dirty group slot */
|
||||
int uffs_BufFindFreeGroupSlot(struct uffs_DeviceSt *dev);
|
||||
|
||||
/** find the dirty group slot */
|
||||
int uffs_BufFindGroupSlot(struct uffs_DeviceSt *dev, u16 parent, u16 serial);
|
||||
|
||||
/** lock dirty group */
|
||||
URET uffs_BufLockGroup(struct uffs_DeviceSt *dev, int slot);
|
||||
|
||||
/** unlock dirty group */
|
||||
URET uffs_BufUnLockGroup(struct uffs_DeviceSt *dev, int slot);
|
||||
|
||||
/** flush most dirty group */
|
||||
URET uffs_BufFlushMostDirtyGroup(struct uffs_DeviceSt *dev);
|
||||
|
||||
/** flush all groups under the same parent number */
|
||||
URET uffs_BufFlushGroupMatchParent(struct uffs_DeviceSt *dev, u16 parent);
|
||||
|
||||
/** flush all page buffers */
|
||||
URET uffs_BufFlushAll(struct uffs_DeviceSt *dev);
|
||||
|
||||
/** no one holding any page buffer ? safe to release page buffers */
|
||||
UBOOL uffs_BufIsAllFree(struct uffs_DeviceSt *dev);
|
||||
|
||||
/** are all page buffer marked with #UFFS_BUF_EMPTY ? */
|
||||
UBOOL uffs_BufIsAllEmpty(struct uffs_DeviceSt *dev);
|
||||
|
||||
/** mark all page buffer as #UFFS_BUF_EMPTY */
|
||||
URET uffs_BufSetAllEmpty(struct uffs_DeviceSt *dev);
|
||||
|
||||
/** clone a page buffer */
|
||||
uffs_Buf * uffs_BufClone(struct uffs_DeviceSt *dev, uffs_Buf *buf);
|
||||
|
||||
/** release a cloned page buffer, call in pair with #uffs_BufClone */
|
||||
URET uffs_BufFreeClone(uffs_Device *dev, uffs_Buf *buf);
|
||||
|
||||
/** load physical storage data to page buffer */
|
||||
URET uffs_BufLoadPhyData(uffs_Device *dev, uffs_Buf *buf, u32 block, u32 page);
|
||||
|
||||
/** load physical storage data to page buffer withouth checking ECC */
|
||||
URET uffs_LoadPhyDataToBufEccUnCare(uffs_Device *dev, uffs_Buf *buf, u32 block, u32 page);
|
||||
|
||||
/** showing page buffers info, for debug only */
|
||||
void uffs_BufInspect(uffs_Device *dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,59 +1,59 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_CORE_H_
|
||||
#define _UFFS_CORE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
/** \typedef uffs_Device */
|
||||
typedef struct uffs_DeviceSt uffs_Device;
|
||||
/** \typedef uffs_FlashOps */
|
||||
typedef struct uffs_FlashOpsSt uffs_FlashOps;
|
||||
|
||||
typedef struct uffs_BlockInfoSt uffs_BlockInfo;
|
||||
typedef struct uffs_PageSpareSt uffs_PageSpare;
|
||||
typedef struct uffs_TagsSt uffs_Tags; //!< UFFS page tags
|
||||
typedef struct uffs_TagStoreSt uffs_TagStore; //!< UFFS page tags physical store structure
|
||||
|
||||
typedef struct uffs_BufSt uffs_Buf;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_CORE_H_
|
||||
#define _UFFS_CORE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
/** \typedef uffs_Device */
|
||||
typedef struct uffs_DeviceSt uffs_Device;
|
||||
/** \typedef uffs_FlashOps */
|
||||
typedef struct uffs_FlashOpsSt uffs_FlashOps;
|
||||
|
||||
typedef struct uffs_BlockInfoSt uffs_BlockInfo;
|
||||
typedef struct uffs_PageSpareSt uffs_PageSpare;
|
||||
typedef struct uffs_TagsSt uffs_Tags; //!< UFFS page tags
|
||||
typedef struct uffs_TagStoreSt uffs_TagStore; //!< UFFS page tags physical store structure
|
||||
|
||||
typedef struct uffs_BufSt uffs_Buf;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,191 +1,191 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_device.h
|
||||
* \brief uffs device structures definition
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#ifndef UFFS_DEVICE_H
|
||||
#define UFFS_DEVICE_H
|
||||
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_buf.h"
|
||||
#include "uffs/uffs_blockinfo.h"
|
||||
#include "uffs/uffs_pool.h"
|
||||
#include "uffs/uffs_tree.h"
|
||||
#include "uffs/uffs_mem.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
#include "uffs/uffs_flash.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \struct uffs_BlockInfoCacheSt
|
||||
* \brief block information structure, used to manager block information caches
|
||||
*/
|
||||
struct uffs_BlockInfoCacheSt {
|
||||
uffs_BlockInfo *head; //!< buffer head of block info(spares)
|
||||
uffs_BlockInfo *tail; //!< buffer tail
|
||||
void *mem_pool; //!< internal memory pool, used for release whole buffer
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_PartitionSt
|
||||
* \brief partition basic information
|
||||
*/
|
||||
struct uffs_PartitionSt {
|
||||
u16 start; //!< start block number of partition
|
||||
u16 end; //!< end block number of partiton
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_LockSt
|
||||
* \brief lock stuffs
|
||||
*/
|
||||
struct uffs_LockSt {
|
||||
int sem;
|
||||
int task_id;
|
||||
int counter;
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_DirtyGroupSt
|
||||
* \brief manager dirty page buffers
|
||||
*/
|
||||
struct uffs_DirtyGroupSt {
|
||||
int count; //!< dirty buffers count
|
||||
int lock; //!< dirty group lock (0: unlocked, >0: locked)
|
||||
uffs_Buf *dirty; //!< dirty buffer list
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_PageBufDescSt
|
||||
* \brief uffs page buffers descriptor
|
||||
*/
|
||||
struct uffs_PageBufDescSt {
|
||||
uffs_Buf *head; //!< head of buffers
|
||||
uffs_Buf *tail; //!< tail of buffers
|
||||
struct uffs_DirtyGroupSt dirtyGroup[MAX_DIRTY_BUF_GROUPS]; //!< dirty buffer groups
|
||||
int buf_max; //!< maximum buffers
|
||||
int dirty_buf_max; //!< maximum dirty buffer allowed
|
||||
void *pool; //!< memory pool for buffers
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \struct uffs_PageCommInfoSt
|
||||
* \brief common data for device, should be initialized at early
|
||||
* \note it is possible that pg_size is smaller than physical page size, but normally they are the same.
|
||||
* \note page data layout: [HEADER] + [DATA]
|
||||
*/
|
||||
struct uffs_PageCommInfoSt {
|
||||
u16 pg_data_size; //!< page data size
|
||||
u16 header_size; //!< header size
|
||||
u16 pg_size; //!< page size
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_NewBadBlockSt
|
||||
* \brief holding new discovered bad block
|
||||
*/
|
||||
struct uffs_NewBadBlockSt {
|
||||
u16 block; //!< bad block, FIX ME to process more than one bad block
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_FlashStatSt
|
||||
* \typedef uffs_FlashStat
|
||||
* \brief statistic data of flash read/write/erase activities
|
||||
*/
|
||||
typedef struct uffs_FlashStatSt {
|
||||
int block_erase_count;
|
||||
int page_write_count;
|
||||
int page_read_count;
|
||||
int page_header_read_count;
|
||||
int spare_write_count;
|
||||
int spare_read_count;
|
||||
} uffs_FlashStat;
|
||||
|
||||
|
||||
/**
|
||||
* \struct uffs_DeviceSt
|
||||
* \brief The core data structure of UFFS, all information needed by manipulate UFFS object
|
||||
* \note one partition corresponding one uffs device.
|
||||
*/
|
||||
struct uffs_DeviceSt {
|
||||
URET (*Init)(uffs_Device *dev); //!< low level initialization
|
||||
URET (*Release)(uffs_Device *dev); //!< low level release
|
||||
void *_private; //!< private data for device
|
||||
|
||||
struct uffs_StorageAttrSt *attr; //!< storage attribute
|
||||
struct uffs_PartitionSt par; //!< partition information
|
||||
struct uffs_FlashOpsSt *ops; //!< flash operations
|
||||
struct uffs_BlockInfoCacheSt bc; //!< block info cache
|
||||
struct uffs_LockSt lock; //!< lock data structure
|
||||
struct uffs_PageBufDescSt buf; //!< page buffers
|
||||
struct uffs_PageCommInfoSt com; //!< common information
|
||||
struct uffs_TreeSt tree; //!< tree list of block
|
||||
struct uffs_NewBadBlockSt bad; //!< new discovered bad block
|
||||
struct uffs_FlashStatSt st; //!< statistic (counters)
|
||||
struct uffs_memAllocatorSt mem; //!< uffs native memory allocator
|
||||
u32 ref_count; //!< device reference count
|
||||
int dev_num; //!< device number (partition number)
|
||||
};
|
||||
|
||||
/** create the lock for uffs device */
|
||||
URET uffs_DeviceInitLock(uffs_Device *dev);
|
||||
|
||||
/** delete the lock of uffs device */
|
||||
URET uffs_DeviceReleaseLock(uffs_Device *dev);
|
||||
|
||||
/** lock uffs device */
|
||||
URET uffs_DeviceLock(uffs_Device *dev);
|
||||
|
||||
/** unlock uffs device */
|
||||
URET uffs_DeviceUnLock(uffs_Device *dev);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_device.h
|
||||
* \brief uffs device structures definition
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#ifndef UFFS_DEVICE_H
|
||||
#define UFFS_DEVICE_H
|
||||
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_buf.h"
|
||||
#include "uffs/uffs_blockinfo.h"
|
||||
#include "uffs/uffs_pool.h"
|
||||
#include "uffs/uffs_tree.h"
|
||||
#include "uffs/uffs_mem.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
#include "uffs/uffs_flash.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \struct uffs_BlockInfoCacheSt
|
||||
* \brief block information structure, used to manager block information caches
|
||||
*/
|
||||
struct uffs_BlockInfoCacheSt {
|
||||
uffs_BlockInfo *head; //!< buffer head of block info(spares)
|
||||
uffs_BlockInfo *tail; //!< buffer tail
|
||||
void *mem_pool; //!< internal memory pool, used for release whole buffer
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_PartitionSt
|
||||
* \brief partition basic information
|
||||
*/
|
||||
struct uffs_PartitionSt {
|
||||
u16 start; //!< start block number of partition
|
||||
u16 end; //!< end block number of partiton
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_LockSt
|
||||
* \brief lock stuffs
|
||||
*/
|
||||
struct uffs_LockSt {
|
||||
int sem;
|
||||
int task_id;
|
||||
int counter;
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_DirtyGroupSt
|
||||
* \brief manager dirty page buffers
|
||||
*/
|
||||
struct uffs_DirtyGroupSt {
|
||||
int count; //!< dirty buffers count
|
||||
int lock; //!< dirty group lock (0: unlocked, >0: locked)
|
||||
uffs_Buf *dirty; //!< dirty buffer list
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_PageBufDescSt
|
||||
* \brief uffs page buffers descriptor
|
||||
*/
|
||||
struct uffs_PageBufDescSt {
|
||||
uffs_Buf *head; //!< head of buffers
|
||||
uffs_Buf *tail; //!< tail of buffers
|
||||
struct uffs_DirtyGroupSt dirtyGroup[MAX_DIRTY_BUF_GROUPS]; //!< dirty buffer groups
|
||||
int buf_max; //!< maximum buffers
|
||||
int dirty_buf_max; //!< maximum dirty buffer allowed
|
||||
void *pool; //!< memory pool for buffers
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \struct uffs_PageCommInfoSt
|
||||
* \brief common data for device, should be initialized at early
|
||||
* \note it is possible that pg_size is smaller than physical page size, but normally they are the same.
|
||||
* \note page data layout: [HEADER] + [DATA]
|
||||
*/
|
||||
struct uffs_PageCommInfoSt {
|
||||
u16 pg_data_size; //!< page data size
|
||||
u16 header_size; //!< header size
|
||||
u16 pg_size; //!< page size
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_NewBadBlockSt
|
||||
* \brief holding new discovered bad block
|
||||
*/
|
||||
struct uffs_NewBadBlockSt {
|
||||
u16 block; //!< bad block, FIX ME to process more than one bad block
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_FlashStatSt
|
||||
* \typedef uffs_FlashStat
|
||||
* \brief statistic data of flash read/write/erase activities
|
||||
*/
|
||||
typedef struct uffs_FlashStatSt {
|
||||
int block_erase_count;
|
||||
int page_write_count;
|
||||
int page_read_count;
|
||||
int page_header_read_count;
|
||||
int spare_write_count;
|
||||
int spare_read_count;
|
||||
} uffs_FlashStat;
|
||||
|
||||
|
||||
/**
|
||||
* \struct uffs_DeviceSt
|
||||
* \brief The core data structure of UFFS, all information needed by manipulate UFFS object
|
||||
* \note one partition corresponding one uffs device.
|
||||
*/
|
||||
struct uffs_DeviceSt {
|
||||
URET (*Init)(uffs_Device *dev); //!< low level initialization
|
||||
URET (*Release)(uffs_Device *dev); //!< low level release
|
||||
void *_private; //!< private data for device
|
||||
|
||||
struct uffs_StorageAttrSt *attr; //!< storage attribute
|
||||
struct uffs_PartitionSt par; //!< partition information
|
||||
struct uffs_FlashOpsSt *ops; //!< flash operations
|
||||
struct uffs_BlockInfoCacheSt bc; //!< block info cache
|
||||
struct uffs_LockSt lock; //!< lock data structure
|
||||
struct uffs_PageBufDescSt buf; //!< page buffers
|
||||
struct uffs_PageCommInfoSt com; //!< common information
|
||||
struct uffs_TreeSt tree; //!< tree list of block
|
||||
struct uffs_NewBadBlockSt bad; //!< new discovered bad block
|
||||
struct uffs_FlashStatSt st; //!< statistic (counters)
|
||||
struct uffs_memAllocatorSt mem; //!< uffs native memory allocator
|
||||
u32 ref_count; //!< device reference count
|
||||
int dev_num; //!< device number (partition number)
|
||||
};
|
||||
|
||||
/** create the lock for uffs device */
|
||||
URET uffs_DeviceInitLock(uffs_Device *dev);
|
||||
|
||||
/** delete the lock of uffs device */
|
||||
URET uffs_DeviceReleaseLock(uffs_Device *dev);
|
||||
|
||||
/** lock uffs device */
|
||||
URET uffs_DeviceLock(uffs_Device *dev);
|
||||
|
||||
/** unlock uffs device */
|
||||
URET uffs_DeviceUnLock(uffs_Device *dev);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,90 +1,90 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_ecc.h
|
||||
* \brief file handle operations
|
||||
* \author Ricky Zheng, created 8th Jun, 2005
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_ECC_H_
|
||||
#define _UFFS_ECC_H_
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "uffs/uffs_fs.h"
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define MAX_ECC_LENGTH 24 //!< 2K page ecc length is 24 bytes.
|
||||
|
||||
/**
|
||||
* calculate ECC
|
||||
* \return length of generated ECC. (3 bytes ECC per 256 data)
|
||||
*/
|
||||
int uffs_EccMake(void *data, int data_len, void *ecc);
|
||||
|
||||
/**
|
||||
* correct data by ECC.
|
||||
*
|
||||
* return: 0 -- no error
|
||||
* -1 -- can not be corrected
|
||||
* >0 -- how many bits are corrected
|
||||
*/
|
||||
int uffs_EccCorrect(void *data, int data_len, void *read_ecc, const void *test_ecc);
|
||||
|
||||
|
||||
/**
|
||||
* generate 12 bit ecc for maximum 8 bytes data
|
||||
*/
|
||||
u16 uffs_EccMake8(void *data, int data_len);
|
||||
|
||||
/**
|
||||
* correct maximum 8 bytes data from 12 bits ECC
|
||||
*
|
||||
* return: 0 -- no error
|
||||
* -1 -- can not be corrected
|
||||
* >0 -- how many bits are corrected
|
||||
*/
|
||||
int uffs_EccCorrect8(void *data, u16 read_ecc, u16 test_ecc, int errtop);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_ecc.h
|
||||
* \brief file handle operations
|
||||
* \author Ricky Zheng, created 8th Jun, 2005
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_ECC_H_
|
||||
#define _UFFS_ECC_H_
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "uffs/uffs_fs.h"
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define MAX_ECC_LENGTH 24 //!< 2K page ecc length is 24 bytes.
|
||||
|
||||
/**
|
||||
* calculate ECC
|
||||
* \return length of generated ECC. (3 bytes ECC per 256 data)
|
||||
*/
|
||||
int uffs_EccMake(void *data, int data_len, void *ecc);
|
||||
|
||||
/**
|
||||
* correct data by ECC.
|
||||
*
|
||||
* return: 0 -- no error
|
||||
* -1 -- can not be corrected
|
||||
* >0 -- how many bits are corrected
|
||||
*/
|
||||
int uffs_EccCorrect(void *data, int data_len, void *read_ecc, const void *test_ecc);
|
||||
|
||||
|
||||
/**
|
||||
* generate 12 bit ecc for maximum 8 bytes data
|
||||
*/
|
||||
u16 uffs_EccMake8(void *data, int data_len);
|
||||
|
||||
/**
|
||||
* correct maximum 8 bytes data from 12 bits ECC
|
||||
*
|
||||
* return: 0 -- no error
|
||||
* -1 -- can not be corrected
|
||||
* >0 -- how many bits are corrected
|
||||
*/
|
||||
int uffs_EccCorrect8(void *data, u16 read_ecc, u16 test_ecc, int errtop);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,150 +1,152 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_fd.h
|
||||
* \brief PISIX like file operations
|
||||
* \author Ricky Zheng, created 8th Jun, 2005
|
||||
*/
|
||||
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
#include "uffs/uffs_fs.h"
|
||||
#include "uffs/uffs.h"
|
||||
#include "uffs/uffs_find.h"
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* \brief definitions for uffs_stat::st_mode
|
||||
*/
|
||||
#define US_IFMT 0xF000 /* file type make */
|
||||
#define US_IFREG 0x8000 /* regular */
|
||||
#define US_IFLNK 0xA000 /* symbolic link */
|
||||
#define US_IFDIR 0x4000 /* directory */
|
||||
#define US_IREAD 00400 /* read permission */
|
||||
#define US_IWRITE 00200 /* write permission */
|
||||
|
||||
#define US_IRWXU 00700 /* RWX owner */
|
||||
#define US_IRUSR 00400 /* R owner */
|
||||
#define US_IWUSR 00200 /* W owner */
|
||||
#define US_IXUSR 00100 /* X owner */
|
||||
#define US_IRWXG 00070 /* RWX group */
|
||||
#define US_IRGRP 00040 /* R group */
|
||||
#define US_IWGRP 00020 /* W group */
|
||||
#define US_IXGRP 00010 /* X group */
|
||||
#define US_IRWXO 00007 /* RWX other */
|
||||
#define US_IROTH 00004 /* R other */
|
||||
#define US_IWOTH 00002 /* W other */
|
||||
#define US_IXOTH 00001 /* X other */
|
||||
|
||||
/**
|
||||
* \brief POSIX dirent
|
||||
*/
|
||||
struct uffs_dirent {
|
||||
int d_ino; /* inode number (serial number or this record) */
|
||||
char d_name[MAX_FILENAME_LENGTH]; /* name of this record */
|
||||
|
||||
int d_off; /* offset to this dirent */
|
||||
unsigned short int d_reclen; /* length of this uffs_dirent */
|
||||
unsigned short int d_namelen; /* length of this d_name */
|
||||
unsigned char d_type; /* type of this record */
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief POSIX DIR
|
||||
*/
|
||||
typedef struct uffs_dirSt {
|
||||
struct uffs_ObjectSt *obj; /* dir object */
|
||||
struct uffs_FindInfoSt f; /* find info */
|
||||
struct uffs_ObjectInfoSt info; /* object info */
|
||||
struct uffs_dirent dirent; /* dir entry */
|
||||
} uffs_DIR;
|
||||
|
||||
/**
|
||||
* \brief POSIX stat
|
||||
*/
|
||||
struct uffs_stat {
|
||||
int st_dev; /* ID of device containing file */
|
||||
int st_ino; /* inode number */
|
||||
int st_mode; /* protection */
|
||||
int st_nlink; /* number of hard links */
|
||||
int st_uid; /* user ID of owner */
|
||||
int st_gid; /* group ID of owner */
|
||||
int st_rdev; /* device ID (if special file) */
|
||||
long st_size; /* total size, in bytes */
|
||||
int st_blksize; /* blocksize for filesystem I/O */
|
||||
int st_blocks; /* number of blocks allocated */
|
||||
u32 st_atime; /* time of last access */
|
||||
u32 st_mtime; /* time of last modification */
|
||||
u32 st_ctime; /* time of last status change */
|
||||
};
|
||||
|
||||
|
||||
URET uffs_InitDirEntryBuf(void);
|
||||
URET uffs_ReleaseDirEntryBuf(void);
|
||||
uffs_Pool * uffs_GetDirEntryBufPool(void);
|
||||
|
||||
/* POSIX compliant file system APIs */
|
||||
|
||||
int uffs_open(const char *name, int oflag, ...);
|
||||
int uffs_close(int fd);
|
||||
int uffs_read(int fd, void *data, int len);
|
||||
int uffs_write(int fd, void *data, int len);
|
||||
long uffs_seek(int fd, long offset, int origin);
|
||||
long uffs_tell(int fd);
|
||||
int uffs_eof(int fd);
|
||||
int uffs_flush(int fd);
|
||||
int uffs_rename(const char *old_name, const char *new_name);
|
||||
int uffs_remove(const char *name);
|
||||
int uffs_truncate(int fd, long remain);
|
||||
|
||||
int uffs_mkdir(const char *name, ...);
|
||||
int uffs_rmdir(const char *name);
|
||||
|
||||
int uffs_stat(const char *name, struct uffs_stat *buf);
|
||||
int uffs_lstat(const char *name, struct uffs_stat *buf);
|
||||
int uffs_fstat(int fd, struct uffs_stat *buf);
|
||||
|
||||
int uffs_closedir(uffs_DIR *dirp);
|
||||
uffs_DIR * uffs_opendir(const char *path);
|
||||
struct uffs_dirent * uffs_readdir(uffs_DIR *dirp);
|
||||
|
||||
void uffs_rewinddir(uffs_DIR *dirp);
|
||||
|
||||
#if 0
|
||||
void uffs_seekdir(uffs_DIR *dirp, long loc);
|
||||
long uffs_telldir(uffs_DIR *dirp);
|
||||
#endif
|
||||
|
||||
int uffs_get_error(void);
|
||||
int uffs_set_error(int err);
|
||||
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_fd.h
|
||||
* \brief PISIX like file operations
|
||||
* \author Ricky Zheng, created 8th Jun, 2005
|
||||
*/
|
||||
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
#include "uffs/uffs_fs.h"
|
||||
#include "uffs/uffs.h"
|
||||
#include "uffs/uffs_find.h"
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* \brief definitions for uffs_stat::st_mode
|
||||
*/
|
||||
#define US_IFMT 0xF000 /* file type make */
|
||||
#define US_IFREG 0x8000 /* regular */
|
||||
#define US_IFLNK 0xA000 /* symbolic link */
|
||||
#define US_IFDIR 0x4000 /* directory */
|
||||
#define US_IREAD 00400 /* read permission */
|
||||
#define US_IWRITE 00200 /* write permission */
|
||||
|
||||
#define US_IRWXU 00700 /* RWX owner */
|
||||
#define US_IRUSR 00400 /* R owner */
|
||||
#define US_IWUSR 00200 /* W owner */
|
||||
#define US_IXUSR 00100 /* X owner */
|
||||
#define US_IRWXG 00070 /* RWX group */
|
||||
#define US_IRGRP 00040 /* R group */
|
||||
#define US_IWGRP 00020 /* W group */
|
||||
#define US_IXGRP 00010 /* X group */
|
||||
#define US_IRWXO 00007 /* RWX other */
|
||||
#define US_IROTH 00004 /* R other */
|
||||
#define US_IWOTH 00002 /* W other */
|
||||
#define US_IXOTH 00001 /* X other */
|
||||
|
||||
/**
|
||||
* \brief POSIX dirent
|
||||
*/
|
||||
struct uffs_dirent
|
||||
{
|
||||
int d_ino; /* inode number (serial number or this record) */
|
||||
char d_name[MAX_FILENAME_LENGTH]; /* name of this record */
|
||||
int d_off; /* offset to this dirent */
|
||||
u16 d_reclen; /* length of this uffs_dirent */
|
||||
u16 d_namelen; /* length of this d_name */
|
||||
u32 d_type; /* type of this record ,ÒªÓëinfo.attrµÄÀàÐͱ£³ÖÒ»ÖÂ*/
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief POSIX DIR
|
||||
*/
|
||||
typedef struct uffs_dirSt
|
||||
{
|
||||
struct uffs_ObjectSt *obj; /* dir object */
|
||||
struct uffs_FindInfoSt f; /* find info */
|
||||
struct uffs_ObjectInfoSt info; /* object info */
|
||||
struct uffs_dirent dirent; /* dir entry */
|
||||
}uffs_DIR;
|
||||
|
||||
/**
|
||||
* \brief POSIX stat
|
||||
*/
|
||||
struct uffs_stat
|
||||
{
|
||||
int st_dev; /* ID of device containing file */
|
||||
int st_ino; /* inode number */
|
||||
int st_mode; /* protection */
|
||||
int st_nlink; /* number of hard links */
|
||||
int st_uid; /* user ID of owner */
|
||||
int st_gid; /* group ID of owner */
|
||||
int st_rdev; /* device ID (if special file) */
|
||||
long st_size; /* total size, in bytes */
|
||||
int st_blksize; /* blocksize for filesystem I/O */
|
||||
int st_blocks; /* number of blocks allocated */
|
||||
u32 st_atime; /* time of last access */
|
||||
u32 st_mtime; /* time of last modification */
|
||||
u32 st_ctime; /* time of last status change */
|
||||
};
|
||||
|
||||
|
||||
int uffs_InitDirEntryBuf(void);
|
||||
int uffs_ReleaseDirEntryBuf(void);
|
||||
uffs_Pool * uffs_GetDirEntryBufPool(void);
|
||||
|
||||
/* POSIX compliant file system APIs */
|
||||
|
||||
int uffs_open(const char *name, int oflag, ...);
|
||||
int uffs_close(int fd);
|
||||
int uffs_read(int fd, void *data, int len);
|
||||
int uffs_write(int fd, void *data, int len);
|
||||
long uffs_seek(int fd, long offset, int origin);
|
||||
long uffs_tell(int fd);
|
||||
int uffs_eof(int fd);
|
||||
int uffs_flush(int fd);
|
||||
int uffs_rename(const char *old_name, const char *new_name);
|
||||
int uffs_remove(const char *name);
|
||||
int uffs_truncate(int fd, long remain);
|
||||
|
||||
int uffs_mkdir(const char *name, ...);
|
||||
int uffs_rmdir(const char *name);
|
||||
|
||||
int uffs_stat(const char *name, struct uffs_stat *buf);
|
||||
int uffs_lstat(const char *name, struct uffs_stat *buf);
|
||||
int uffs_fstat(int fd, struct uffs_stat *buf);
|
||||
|
||||
int uffs_closedir(uffs_DIR *dirp);
|
||||
uffs_DIR * uffs_opendir(const char *path);
|
||||
struct uffs_dirent * uffs_readdir(uffs_DIR *dirp);
|
||||
|
||||
void uffs_rewinddir(uffs_DIR *dirp);
|
||||
|
||||
#if 0
|
||||
void uffs_seekdir(uffs_DIR *dirp, long loc);
|
||||
long uffs_telldir(uffs_DIR *dirp);
|
||||
#endif
|
||||
|
||||
int uffs_get_error(void);
|
||||
int uffs_set_error(int err);
|
||||
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_find.h
|
||||
* \brief find objects under dir
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_FIND_H_
|
||||
#define _UFFS_FIND_H_
|
||||
|
||||
#include "uffs/uffs_fs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
typedef struct uffs_FindInfoSt {
|
||||
uffs_Device *dev; //!< the device to be searched
|
||||
u16 serial; //!< the dir serial number
|
||||
int step; //!< step: 0 - working on dir entries, 1 - working on file entries, 2 - stoped.
|
||||
int hash; //!< hash entry, internal used
|
||||
TreeNode *work; //!< working node, internal used.
|
||||
int pos; //!< current position
|
||||
} uffs_FindInfo;
|
||||
|
||||
|
||||
URET uffs_GetObjectInfo(uffs_Object *obj, uffs_ObjectInfo *info, int *err);
|
||||
URET uffs_FindObjectOpen(uffs_FindInfo *find_handle, uffs_Object *dir);
|
||||
URET uffs_FindObjectOpenEx(uffs_FindInfo *f, uffs_Device *dev, int dir);
|
||||
URET uffs_FindObjectFirst(uffs_ObjectInfo *info, uffs_FindInfo *find_handle);
|
||||
URET uffs_FindObjectNext(uffs_ObjectInfo *info, uffs_FindInfo *find_handle);
|
||||
URET uffs_FindObjectRewind(uffs_FindInfo *find_handle);
|
||||
URET uffs_FindObjectClose(uffs_FindInfo * find_handle);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_find.h
|
||||
* \brief find objects under dir
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_FIND_H_
|
||||
#define _UFFS_FIND_H_
|
||||
|
||||
#include "uffs/uffs_fs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
typedef struct uffs_FindInfoSt {
|
||||
uffs_Device *dev; //!< the device to be searched
|
||||
u16 serial; //!< the dir serial number
|
||||
int step; //!< step: 0 - working on dir entries, 1 - working on file entries, 2 - stoped.
|
||||
int hash; //!< hash entry, internal used
|
||||
TreeNode *work; //!< working node, internal used.
|
||||
int pos; //!< current position
|
||||
} uffs_FindInfo;
|
||||
|
||||
|
||||
URET uffs_GetObjectInfo(uffs_Object *obj, uffs_ObjectInfo *info, int *err);
|
||||
URET uffs_FindObjectOpen(uffs_FindInfo *find_handle, uffs_Object *dir);
|
||||
URET uffs_FindObjectOpenEx(uffs_FindInfo *f, uffs_Device *dev, int dir);
|
||||
URET uffs_FindObjectFirst(uffs_ObjectInfo *info, uffs_FindInfo *find_handle);
|
||||
URET uffs_FindObjectNext(uffs_ObjectInfo *info, uffs_FindInfo *find_handle);
|
||||
URET uffs_FindObjectRewind(uffs_FindInfo *find_handle);
|
||||
URET uffs_FindObjectClose(uffs_FindInfo * find_handle);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,137 +1,137 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_fs.h
|
||||
* \brief uffs basic file operations
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_FS_H_
|
||||
#define _UFFS_FS_H_
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs.h"
|
||||
#include "uffs/uffs_public.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
/** file object */
|
||||
struct uffs_ObjectSt {
|
||||
/******* objects manager ********/
|
||||
int dev_lock_count;
|
||||
int dev_get_count;
|
||||
|
||||
/******** init level 0 ********/
|
||||
const char * name; //!< pointer to the start of name, for open or create
|
||||
u32 name_len; //!< name length
|
||||
u16 sum; //!< sum of name
|
||||
uffs_Device *dev; //!< uffs device
|
||||
u32 oflag;
|
||||
u8 type;
|
||||
u16 head_pages; //!< data pages on file head block
|
||||
u16 parent;
|
||||
|
||||
/******* init level 1 ********/
|
||||
TreeNode *node; //!< file entry node in tree
|
||||
u16 serial;
|
||||
|
||||
/******* output ******/
|
||||
int err; //!< error number
|
||||
|
||||
/******* current *******/
|
||||
u32 pos; //!< current position in file
|
||||
|
||||
/***** others *******/
|
||||
UBOOL attr_loaded; //!< attributes loaded ?
|
||||
UBOOL open_succ; //!< U_TRUE or U_FALSE
|
||||
|
||||
};
|
||||
|
||||
typedef struct uffs_ObjectSt uffs_Object;
|
||||
|
||||
|
||||
|
||||
#define uffs_GetObjectErr(obj) ((obj)->err)
|
||||
#define uffs_ClearObjectErr(obj) do { (obj)->err = UENOERR; } while (0)
|
||||
|
||||
uffs_Pool * uffs_GetObjectPool(void);
|
||||
|
||||
URET uffs_InitObjectBuf(void);
|
||||
URET uffs_ReleaseObjectBuf(void);
|
||||
uffs_Object * uffs_GetObject(void);
|
||||
void uffs_PutObject(uffs_Object *obj);
|
||||
int uffs_GetObjectIndex(uffs_Object *obj);
|
||||
uffs_Object * uffs_GetObjectByIndex(int idx);
|
||||
|
||||
|
||||
/**
|
||||
* Re-initialize an object.
|
||||
* should call this function if you want to re-use an object.
|
||||
*/
|
||||
URET uffs_ReInitObject(uffs_Object *obj);
|
||||
|
||||
URET uffs_ParseObject(uffs_Object *obj, const char *name);
|
||||
|
||||
URET uffs_CreateObjectEx(uffs_Object *obj, uffs_Device *dev,
|
||||
int dir, const char *name, int name_len, int oflag);
|
||||
URET uffs_OpenObjectEx(uffs_Object *obj, uffs_Device *dev,
|
||||
int dir, const char *name, int name_len, int oflag);
|
||||
|
||||
URET uffs_OpenObject(uffs_Object *obj, const char *fullname, int oflag);
|
||||
URET uffs_TruncateObject(uffs_Object *obj, u32 remain);
|
||||
URET uffs_CreateObject(uffs_Object *obj, const char *fullname, int oflag);
|
||||
|
||||
URET uffs_CloseObject(uffs_Object *obj);
|
||||
int uffs_WriteObject(uffs_Object *obj, const void *data, int len);
|
||||
int uffs_ReadObject(uffs_Object *obj, void *data, int len);
|
||||
long uffs_SeekObject(uffs_Object *obj, long offset, int origin);
|
||||
int uffs_GetCurOffset(uffs_Object *obj);
|
||||
int uffs_EndOfFile(uffs_Object *obj);
|
||||
URET uffs_FlushObject(uffs_Object *obj);
|
||||
|
||||
URET uffs_RenameObject(const char *old_name, const char *new_name, int *err);
|
||||
URET uffs_DeleteObject(const char * name, int *err);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_fs.h
|
||||
* \brief uffs basic file operations
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_FS_H_
|
||||
#define _UFFS_FS_H_
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs.h"
|
||||
#include "uffs/uffs_public.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
/** file object */
|
||||
struct uffs_ObjectSt {
|
||||
/******* objects manager ********/
|
||||
int dev_lock_count;
|
||||
int dev_get_count;
|
||||
|
||||
/******** init level 0 ********/
|
||||
const char * name; //!< pointer to the start of name, for open or create
|
||||
u32 name_len; //!< name length
|
||||
u16 sum; //!< sum of name
|
||||
uffs_Device *dev; //!< uffs device
|
||||
u32 oflag;
|
||||
u8 type;
|
||||
u16 head_pages; //!< data pages on file head block
|
||||
u16 parent;
|
||||
|
||||
/******* init level 1 ********/
|
||||
TreeNode *node; //!< file entry node in tree
|
||||
u16 serial;
|
||||
|
||||
/******* output ******/
|
||||
int err; //!< error number
|
||||
|
||||
/******* current *******/
|
||||
u32 pos; //!< current position in file
|
||||
|
||||
/***** others *******/
|
||||
UBOOL attr_loaded; //!< attributes loaded ?
|
||||
UBOOL open_succ; //!< U_TRUE or U_FALSE
|
||||
|
||||
};
|
||||
|
||||
typedef struct uffs_ObjectSt uffs_Object;
|
||||
|
||||
|
||||
|
||||
#define uffs_GetObjectErr(obj) ((obj)->err)
|
||||
#define uffs_ClearObjectErr(obj) do { (obj)->err = UENOERR; } while (0)
|
||||
|
||||
uffs_Pool * uffs_GetObjectPool(void);
|
||||
|
||||
URET uffs_InitObjectBuf(void);
|
||||
URET uffs_ReleaseObjectBuf(void);
|
||||
uffs_Object * uffs_GetObject(void);
|
||||
void uffs_PutObject(uffs_Object *obj);
|
||||
int uffs_GetObjectIndex(uffs_Object *obj);
|
||||
uffs_Object * uffs_GetObjectByIndex(int idx);
|
||||
|
||||
|
||||
/**
|
||||
* Re-initialize an object.
|
||||
* should call this function if you want to re-use an object.
|
||||
*/
|
||||
URET uffs_ReInitObject(uffs_Object *obj);
|
||||
|
||||
URET uffs_ParseObject(uffs_Object *obj, const char *name);
|
||||
|
||||
URET uffs_CreateObjectEx(uffs_Object *obj, uffs_Device *dev,
|
||||
int dir, const char *name, int name_len, int oflag);
|
||||
URET uffs_OpenObjectEx(uffs_Object *obj, uffs_Device *dev,
|
||||
int dir, const char *name, int name_len, int oflag);
|
||||
|
||||
URET uffs_OpenObject(uffs_Object *obj, const char *fullname, int oflag);
|
||||
URET uffs_TruncateObject(uffs_Object *obj, u32 remain);
|
||||
URET uffs_CreateObject(uffs_Object *obj, const char *fullname, int oflag);
|
||||
|
||||
URET uffs_CloseObject(uffs_Object *obj);
|
||||
int uffs_WriteObject(uffs_Object *obj, const void *data, int len);
|
||||
int uffs_ReadObject(uffs_Object *obj, void *data, int len);
|
||||
long uffs_SeekObject(uffs_Object *obj, long offset, int origin);
|
||||
int uffs_GetCurOffset(uffs_Object *obj);
|
||||
int uffs_EndOfFile(uffs_Object *obj);
|
||||
URET uffs_FlushObject(uffs_Object *obj);
|
||||
|
||||
URET uffs_RenameObject(const char *old_name, const char *new_name, int *err);
|
||||
URET uffs_DeleteObject(const char * name, int *err);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,130 +1,130 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
#ifndef UFFS_MEM_H
|
||||
#define UFFS_MEM_H
|
||||
|
||||
#include "uffs/uffs_device.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
#define MAX_ECC_SIZE (3 * UFFS_MAX_PAGE_SIZE / 256)
|
||||
#define MAX_SPARE_SIZE (8 * UFFS_MAX_PAGE_SIZE / 256)
|
||||
#define MAX_SPARE_BUF 10
|
||||
|
||||
|
||||
#if CONFIG_USE_NATIVE_MEMORY_ALLOCATOR > 0
|
||||
|
||||
#define HEAP_HASH_BIT 6 /* hash table bit */
|
||||
#define HEAP_HASH_SIZE (1 << (HEAP_HASH_BIT - 1)) /* hash table size */
|
||||
#define HEAP_HASH_MASK (HEAP_HASH_SIZE - 1) /* hash table mask */
|
||||
#define GET_HASH_INDEX(p) ((((unsigned long)(p)) >> 2) & HEAP_HASH_MASK)
|
||||
|
||||
/* memory alloc node */
|
||||
typedef struct HeapManagementNodeSt{
|
||||
int task_id; /* who alloc this block? it's the caller's task id */
|
||||
struct HeapManagementNodeSt * next; /* point to next node */
|
||||
void *p; /* point to allocated block */
|
||||
int size; /* block size */
|
||||
} HeapMm;
|
||||
|
||||
typedef HeapMm* HeapHashTable;
|
||||
|
||||
/** \note: uffs_MemInitHeap should be called before using native memory allocator on each device */
|
||||
void uffs_MemInitHeap(void *addr, int size);
|
||||
|
||||
URET uffs_MemInitNativeAllocator(uffs_Device *dev);
|
||||
int uffs_MemReleaseNativeAllocator(uffs_Device *dev);
|
||||
|
||||
#endif //CONFIG_USE_NATIVE_MEMORY_ALLOCATOR
|
||||
|
||||
|
||||
/** uffs native memory allocator */
|
||||
typedef struct uffs_memAllocatorSt {
|
||||
URET (*init)(struct uffs_DeviceSt *dev); /* init memory allocator, setup buffer sizes */
|
||||
URET (*release)(struct uffs_DeviceSt *dev); /* release memory allocator (for dynamic memory allocation) */
|
||||
|
||||
void * (*malloc)(struct uffs_DeviceSt *dev, unsigned int size); /* allocate memory (for dynamic memory allocation) */
|
||||
URET (*free)(struct uffs_DeviceSt *dev, void *p); /* free memory (for dynamic memory allocation) */
|
||||
|
||||
void * blockinfo_pool_buf; //!< block info cache buffers
|
||||
void * pagebuf_pool_buf; //!< page buffers
|
||||
void * tree_nodes_pool_buf; //!< tree nodes buffer
|
||||
void * spare_pool_buf; //!< spare buffers
|
||||
|
||||
int blockinfo_pool_size; //!< block info cache buffers size
|
||||
int pagebuf_pool_size; //!< page buffers size
|
||||
int tree_nodes_pool_size; //!< tree nodes buffer size
|
||||
int spare_pool_size; //!< spare buffer pool size
|
||||
|
||||
uffs_Pool tree_pool;
|
||||
uffs_Pool spare_pool;
|
||||
|
||||
int spare_data_size; //!< spare data size, calculated by UFFS.
|
||||
|
||||
|
||||
#if CONFIG_USE_NATIVE_MEMORY_ALLOCATOR > 0
|
||||
HeapHashTable tbl[HEAP_HASH_SIZE];
|
||||
int count;
|
||||
int maxused;
|
||||
#endif
|
||||
|
||||
#if CONFIG_USE_STATIC_MEMORY_ALLOCATOR > 0
|
||||
char *buf_start;
|
||||
int buf_size;
|
||||
int pos;
|
||||
#endif
|
||||
|
||||
} uffs_MemAllocator;
|
||||
|
||||
|
||||
#if CONFIG_USE_NATIVE_MEMORY_ALLOCATOR > 0
|
||||
void uffs_MemSetupNativeAllocator(uffs_MemAllocator *allocator);
|
||||
#endif
|
||||
|
||||
#if CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR > 0
|
||||
void uffs_MemSetupSystemAllocator(uffs_MemAllocator *allocator);
|
||||
#endif
|
||||
|
||||
#if CONFIG_USE_STATIC_MEMORY_ALLOCATOR > 0
|
||||
void uffs_MemSetupStaticAllocator(uffs_MemAllocator *allocator, void *pool, int size);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
#ifndef UFFS_MEM_H
|
||||
#define UFFS_MEM_H
|
||||
|
||||
#include "uffs/uffs_device.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
#define MAX_ECC_SIZE (3 * UFFS_MAX_PAGE_SIZE / 256)
|
||||
#define MAX_SPARE_SIZE (8 * UFFS_MAX_PAGE_SIZE / 256)
|
||||
#define MAX_SPARE_BUF 10
|
||||
|
||||
|
||||
#if CONFIG_USE_NATIVE_MEMORY_ALLOCATOR > 0
|
||||
|
||||
#define HEAP_HASH_BIT 6 /* hash table bit */
|
||||
#define HEAP_HASH_SIZE (1 << (HEAP_HASH_BIT - 1)) /* hash table size */
|
||||
#define HEAP_HASH_MASK (HEAP_HASH_SIZE - 1) /* hash table mask */
|
||||
#define GET_HASH_INDEX(p) ((((unsigned long)(p)) >> 2) & HEAP_HASH_MASK)
|
||||
|
||||
/* memory alloc node */
|
||||
typedef struct HeapManagementNodeSt{
|
||||
int task_id; /* who alloc this block? it's the caller's task id */
|
||||
struct HeapManagementNodeSt * next; /* point to next node */
|
||||
void *p; /* point to allocated block */
|
||||
int size; /* block size */
|
||||
} HeapMm;
|
||||
|
||||
typedef HeapMm* HeapHashTable;
|
||||
|
||||
/** \note: uffs_MemInitHeap should be called before using native memory allocator on each device */
|
||||
void uffs_MemInitHeap(void *addr, int size);
|
||||
|
||||
URET uffs_MemInitNativeAllocator(uffs_Device *dev);
|
||||
int uffs_MemReleaseNativeAllocator(uffs_Device *dev);
|
||||
|
||||
#endif //CONFIG_USE_NATIVE_MEMORY_ALLOCATOR
|
||||
|
||||
|
||||
/** uffs native memory allocator */
|
||||
typedef struct uffs_memAllocatorSt {
|
||||
URET (*init)(struct uffs_DeviceSt *dev); /* init memory allocator, setup buffer sizes */
|
||||
URET (*release)(struct uffs_DeviceSt *dev); /* release memory allocator (for dynamic memory allocation) */
|
||||
|
||||
void * (*malloc)(struct uffs_DeviceSt *dev, unsigned int size); /* allocate memory (for dynamic memory allocation) */
|
||||
URET (*free)(struct uffs_DeviceSt *dev, void *p); /* free memory (for dynamic memory allocation) */
|
||||
|
||||
void * blockinfo_pool_buf; //!< block info cache buffers
|
||||
void * pagebuf_pool_buf; //!< page buffers
|
||||
void * tree_nodes_pool_buf; //!< tree nodes buffer
|
||||
void * spare_pool_buf; //!< spare buffers
|
||||
|
||||
int blockinfo_pool_size; //!< block info cache buffers size
|
||||
int pagebuf_pool_size; //!< page buffers size
|
||||
int tree_nodes_pool_size; //!< tree nodes buffer size
|
||||
int spare_pool_size; //!< spare buffer pool size
|
||||
|
||||
uffs_Pool tree_pool;
|
||||
uffs_Pool spare_pool;
|
||||
|
||||
int spare_data_size; //!< spare data size, calculated by UFFS.
|
||||
|
||||
|
||||
#if CONFIG_USE_NATIVE_MEMORY_ALLOCATOR > 0
|
||||
HeapHashTable tbl[HEAP_HASH_SIZE];
|
||||
int count;
|
||||
int maxused;
|
||||
#endif
|
||||
|
||||
#if CONFIG_USE_STATIC_MEMORY_ALLOCATOR > 0
|
||||
char *buf_start;
|
||||
int buf_size;
|
||||
int pos;
|
||||
#endif
|
||||
|
||||
} uffs_MemAllocator;
|
||||
|
||||
|
||||
#if CONFIG_USE_NATIVE_MEMORY_ALLOCATOR > 0
|
||||
void uffs_MemSetupNativeAllocator(uffs_MemAllocator *allocator);
|
||||
#endif
|
||||
|
||||
#if CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR > 0
|
||||
void uffs_MemSetupSystemAllocator(uffs_MemAllocator *allocator);
|
||||
#endif
|
||||
|
||||
#if CONFIG_USE_STATIC_MEMORY_ALLOCATOR > 0
|
||||
void uffs_MemSetupStaticAllocator(uffs_MemAllocator *allocator, void *pool, int size);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,90 +1,90 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_mtb.h
|
||||
* \brief mount table related stuff
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#ifndef UFFS_MTB_H
|
||||
#define UFFS_MTB_H
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
#include "uffs/uffs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct uffs_MountTableEntrySt {
|
||||
uffs_Device *dev;
|
||||
int start_block;
|
||||
int end_block;
|
||||
const char *mount;
|
||||
struct uffs_MountTableEntrySt *next;
|
||||
} uffs_MountTable;
|
||||
|
||||
/** initialize registered mount table */
|
||||
URET uffs_InitMountTable(void);
|
||||
|
||||
/** release registered mount table */
|
||||
URET uffs_ReleaseMountTable(void);
|
||||
|
||||
/** get registered mount table */
|
||||
uffs_MountTable * uffs_GetMountTable(void);
|
||||
|
||||
/** register mount table */
|
||||
int uffs_RegisterMountTable(uffs_MountTable *mtab);
|
||||
|
||||
/** get matched mount point from absolute path */
|
||||
int uffs_GetMatchedMountPointSize(const char *path);
|
||||
|
||||
/** get uffs device from mount point */
|
||||
uffs_Device * uffs_GetDeviceFromMountPoint(const char *mount);
|
||||
|
||||
/** get uffs device from mount point */
|
||||
uffs_Device * uffs_GetDeviceFromMountPointEx(const char *mount, int len);
|
||||
|
||||
/** get mount point name from uffs device */
|
||||
const char * uffs_GetDeviceMountPoint(uffs_Device *dev);
|
||||
|
||||
/** down crease uffs device references by uffs_GetDeviceXXX() */
|
||||
void uffs_PutDevice(uffs_Device *dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_mtb.h
|
||||
* \brief mount table related stuff
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#ifndef UFFS_MTB_H
|
||||
#define UFFS_MTB_H
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
#include "uffs/uffs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct uffs_MountTableEntrySt {
|
||||
uffs_Device *dev;
|
||||
int start_block;
|
||||
int end_block;
|
||||
const char *mount;
|
||||
struct uffs_MountTableEntrySt *next;
|
||||
} uffs_MountTable;
|
||||
|
||||
/** initialize registered mount table */
|
||||
URET uffs_InitMountTable(void);
|
||||
|
||||
/** release registered mount table */
|
||||
URET uffs_ReleaseMountTable(void);
|
||||
|
||||
/** get registered mount table */
|
||||
uffs_MountTable * uffs_GetMountTable(void);
|
||||
|
||||
/** register mount table */
|
||||
int uffs_RegisterMountTable(uffs_MountTable *mtab);
|
||||
|
||||
/** get matched mount point from absolute path */
|
||||
int uffs_GetMatchedMountPointSize(const char *path);
|
||||
|
||||
/** get uffs device from mount point */
|
||||
uffs_Device * uffs_GetDeviceFromMountPoint(const char *mount);
|
||||
|
||||
/** get uffs device from mount point */
|
||||
uffs_Device * uffs_GetDeviceFromMountPointEx(const char *mount, int len);
|
||||
|
||||
/** get mount point name from uffs device */
|
||||
const char * uffs_GetDeviceMountPoint(uffs_Device *dev);
|
||||
|
||||
/** down crease uffs device references by uffs_GetDeviceXXX() */
|
||||
void uffs_PutDevice(uffs_Device *dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,65 +1,65 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
#ifndef UFFS_OS_H
|
||||
#define UFFS_OS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
#include "uffs/uffs_device.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
|
||||
#define UFFS_TASK_ID_NOT_EXIST -1
|
||||
|
||||
typedef int OSSEM;
|
||||
|
||||
/* OS specific functions */
|
||||
int uffs_SemCreate(int n);
|
||||
int uffs_SemWait(int sem);
|
||||
int uffs_SemSignal(int sem);
|
||||
int uffs_SemDelete(int sem);
|
||||
|
||||
void uffs_CriticalEnter(void);
|
||||
void uffs_CriticalExit(void);
|
||||
|
||||
int uffs_OSGetTaskId(void); //get current task id
|
||||
unsigned int uffs_GetCurDateTime(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
#ifndef UFFS_OS_H
|
||||
#define UFFS_OS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
#include "uffs/uffs_device.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
|
||||
#define UFFS_TASK_ID_NOT_EXIST -1
|
||||
|
||||
typedef int OSSEM;
|
||||
|
||||
/* OS specific functions */
|
||||
int uffs_SemCreate(int n);
|
||||
int uffs_SemWait(int sem);
|
||||
int uffs_SemSignal(int sem);
|
||||
int uffs_SemDelete(int sem);
|
||||
|
||||
void uffs_CriticalEnter(void);
|
||||
void uffs_CriticalExit(void);
|
||||
|
||||
int uffs_OSGetTaskId(void); //get current task id
|
||||
unsigned int uffs_GetCurDateTime(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,92 +1,92 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_pool.h
|
||||
* \brief Fast fixed size memory pool management.
|
||||
* \author Ricky Zheng, Simon Kallweit
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_POOL_H_
|
||||
#define _UFFS_POOL_H_
|
||||
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \struct uffs_PoolEntrySt
|
||||
* \brief Helper type for free buffer entries.
|
||||
*/
|
||||
typedef struct uffs_PoolEntrySt {
|
||||
struct uffs_PoolEntrySt *next;
|
||||
} uffs_PoolEntry;
|
||||
|
||||
/**
|
||||
* \struct uffs_PoolSt
|
||||
* \brief Memory pool.
|
||||
*/
|
||||
typedef struct uffs_PoolSt {
|
||||
u8 *mem; //!< memory pool
|
||||
u32 buf_size; //!< size of a buffer
|
||||
u32 num_bufs; //!< number of buffers in the pool
|
||||
uffs_PoolEntry *free_list; //!< linked list of free buffers
|
||||
int sem; //!< buffer lock
|
||||
} uffs_Pool;
|
||||
|
||||
URET uffs_PoolInit(uffs_Pool *pool, void *mem, u32 mem_size, u32 buf_size, u32 num_bufs);
|
||||
URET uffs_PoolRelease(uffs_Pool *pool);
|
||||
|
||||
UBOOL uffs_PoolVerify(uffs_Pool *pool, void *p);
|
||||
|
||||
void *uffs_PoolGet(uffs_Pool *pool);
|
||||
void *uffs_PoolGetLocked(uffs_Pool *pool);
|
||||
|
||||
int uffs_PoolPut(uffs_Pool *pool, void *p);
|
||||
int uffs_PoolPutLocked(uffs_Pool *pool, void *p);
|
||||
|
||||
void *uffs_PoolGetBufByIndex(uffs_Pool *pool, u32 index);
|
||||
u32 uffs_PoolGetIndex(uffs_Pool *pool, void *p);
|
||||
UBOOL uffs_PoolCheckFreeList(uffs_Pool *pool, void *p);
|
||||
|
||||
void * uffs_PoolFindNextAllocated(uffs_Pool *pool, void *from);
|
||||
|
||||
int uffs_PoolGetFreeCount(uffs_Pool *pool);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _UFFS_POOL_H_
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_pool.h
|
||||
* \brief Fast fixed size memory pool management.
|
||||
* \author Ricky Zheng, Simon Kallweit
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_POOL_H_
|
||||
#define _UFFS_POOL_H_
|
||||
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \struct uffs_PoolEntrySt
|
||||
* \brief Helper type for free buffer entries.
|
||||
*/
|
||||
typedef struct uffs_PoolEntrySt {
|
||||
struct uffs_PoolEntrySt *next;
|
||||
} uffs_PoolEntry;
|
||||
|
||||
/**
|
||||
* \struct uffs_PoolSt
|
||||
* \brief Memory pool.
|
||||
*/
|
||||
typedef struct uffs_PoolSt {
|
||||
u8 *mem; //!< memory pool
|
||||
u32 buf_size; //!< size of a buffer
|
||||
u32 num_bufs; //!< number of buffers in the pool
|
||||
uffs_PoolEntry *free_list; //!< linked list of free buffers
|
||||
int sem; //!< buffer lock
|
||||
} uffs_Pool;
|
||||
|
||||
URET uffs_PoolInit(uffs_Pool *pool, void *mem, u32 mem_size, u32 buf_size, u32 num_bufs);
|
||||
URET uffs_PoolRelease(uffs_Pool *pool);
|
||||
|
||||
UBOOL uffs_PoolVerify(uffs_Pool *pool, void *p);
|
||||
|
||||
void *uffs_PoolGet(uffs_Pool *pool);
|
||||
void *uffs_PoolGetLocked(uffs_Pool *pool);
|
||||
|
||||
int uffs_PoolPut(uffs_Pool *pool, void *p);
|
||||
int uffs_PoolPutLocked(uffs_Pool *pool, void *p);
|
||||
|
||||
void *uffs_PoolGetBufByIndex(uffs_Pool *pool, u32 index);
|
||||
u32 uffs_PoolGetIndex(uffs_Pool *pool, void *p);
|
||||
UBOOL uffs_PoolCheckFreeList(uffs_Pool *pool, void *p);
|
||||
|
||||
void * uffs_PoolFindNextAllocated(uffs_Pool *pool, void *from);
|
||||
|
||||
int uffs_PoolGetFreeCount(uffs_Pool *pool);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _UFFS_POOL_H_
|
||||
|
||||
@@ -1,243 +1,243 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_public.h
|
||||
* \brief public data structures for uffs
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_PUBLIC_H_
|
||||
#define _UFFS_PUBLIC_H_
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
#include "uffs/uffs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \struct uffs_TagStoreSt
|
||||
* \brief uffs tag, 8 bytes, will be store in page spare area.
|
||||
*/
|
||||
struct uffs_TagStoreSt {
|
||||
u32 dirty:1; //!< 0: dirty, 1: clear
|
||||
u32 valid:1; //!< 0: valid, 1: invalid
|
||||
u32 type:2; //!< block type: #UFFS_TYPE_DIR, #UFFS_TYPE_FILE, #UFFS_TYPE_DATA
|
||||
u32 block_ts:2; //!< time stamp of block;
|
||||
u32 data_len:12; //!< length of page data
|
||||
u32 serial:14; //!< serial number
|
||||
|
||||
u32 parent:10; //!< parent's serial number
|
||||
u32 page_id:6; //!< page id
|
||||
u32 reserved:4; //!< reserved, for UFFS2
|
||||
u32 tag_ecc:12; //!< tag ECC
|
||||
};
|
||||
|
||||
#define TAG_ECC_DEFAULT (0xFFF) //!< 12-bit '1'
|
||||
|
||||
/**
|
||||
* \struct uffs_TagStoreSt_8
|
||||
* \brief this data structure describes the page status, for 8 bytes page spare.
|
||||
* \note there is no tag ecc for this !
|
||||
*/
|
||||
struct uffs_TagStoreSt_8 {
|
||||
u32 dirty:1; //!< 0: dirty, 1: clear
|
||||
u32 valid:1; //!< 0: valid, 1: invalid
|
||||
u32 type:2; //!< block type: #UFFS_TYPE_DIR, #UFFS_TYPE_FILE, #UFFS_TYPE_DATA
|
||||
u32 block_ts:2; //!< time stamp of block;
|
||||
u32 page_id:5; //!< page id
|
||||
u32 parent:7; //!< parent's serial number
|
||||
u32 serial:8; //!< serial number
|
||||
u32 data_len:8; //!< length of page data
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_TagsSt
|
||||
*/
|
||||
struct uffs_TagsSt {
|
||||
struct uffs_TagStoreSt s; /* store must be the first member */
|
||||
|
||||
/** data_sum for file or dir name */
|
||||
u16 data_sum;
|
||||
|
||||
/**
|
||||
* block_status is not covered by tag_ecc.
|
||||
* it's loaded from flash but not directly write to flash.
|
||||
*/
|
||||
u8 block_status;
|
||||
|
||||
/** internal used */
|
||||
u8 _dirty:1; //!< raw data, before doing ecc correction
|
||||
u8 _valid:1; //!< raw data, before doing ecc correction
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_MiniHeaderSt
|
||||
* \brief the mini header resides on the head of page data
|
||||
*/
|
||||
struct uffs_MiniHeaderSt {
|
||||
u8 status;
|
||||
u8 reserved;
|
||||
u16 crc;
|
||||
};
|
||||
|
||||
|
||||
/** uffs_TagsSt.dirty */
|
||||
#define TAG_VALID 0
|
||||
#define TAG_INVALID 1
|
||||
|
||||
/** uffs_TagsSt.valid */
|
||||
#define TAG_DIRTY 0
|
||||
#define TAG_CLEAR 1
|
||||
|
||||
#define TAG_IS_DIRTY(tag) ((tag)->s.dirty == TAG_DIRTY)
|
||||
#define TAG_IS_VALID(tag) ((tag)->s.valid == TAG_VALID)
|
||||
#define TAG_SERIAL(tag) (tag)->s.serial
|
||||
#define TAG_PARENT(tag) (tag)->s.parent
|
||||
#define TAG_PAGE_ID(tag) (tag)->s.page_id
|
||||
#define TAG_DATA_LEN(tag) (tag)->s.data_len
|
||||
#define TAG_TYPE(tag) (tag)->s.type
|
||||
#define TAG_BLOCK_TS(tag) (tag)->s.block_ts
|
||||
|
||||
|
||||
int uffs_GetFirstBlockTimeStamp(void);
|
||||
int uffs_GetNextBlockTimeStamp(int prev);
|
||||
UBOOL uffs_IsSrcNewerThanObj(int src, int obj);
|
||||
|
||||
|
||||
#include "uffs_device.h"
|
||||
|
||||
|
||||
|
||||
/********************************** debug & error *************************************/
|
||||
#define UFFS_ERR_NOISY -1
|
||||
#define UFFS_ERR_NORMAL 0
|
||||
#define UFFS_ERR_SERIOUS 1
|
||||
#define UFFS_ERR_DEAD 2
|
||||
|
||||
#define TENDSTR "\n"
|
||||
|
||||
//#define UFFS_DBG_LEVEL UFFS_ERR_NORMAL
|
||||
#define UFFS_DBG_LEVEL UFFS_ERR_NOISY
|
||||
|
||||
void uffs_DebugMessage(int level, const char *prefix, const char *suffix, const char *errFmt, ...);
|
||||
|
||||
#define uffs_Perror(level, fmt, ... ) \
|
||||
uffs_DebugMessage(level, PFX, TENDSTR, fmt, ## __VA_ARGS__)
|
||||
|
||||
#define uffs_PerrorRaw(level, fmt, ... ) \
|
||||
uffs_DebugMessage(level, NULL, NULL, fmt, ## __VA_ARGS__)
|
||||
|
||||
|
||||
|
||||
void uffs_AssertCall(const char *file, int line, const char *msg);
|
||||
|
||||
#define uffs_Assert(expr, msg) \
|
||||
do { \
|
||||
if (!(expr)) \
|
||||
uffs_AssertCall(__FILE__, __LINE__, msg); \
|
||||
} while(0)
|
||||
|
||||
/********************************** NAND **********************************************/
|
||||
//NAND flash specific file must implement these interface
|
||||
URET uffs_LoadPageSpare(uffs_Device *dev, int block, int page, uffs_Tags *tag);
|
||||
URET uffs_WritePageSpare(uffs_Device *dev, int block, int page, uffs_Tags *tag);
|
||||
URET uffs_MakePageValid(uffs_Device *dev, int block, int page, uffs_Tags *tag);
|
||||
UBOOL uffs_IsBlockBad(uffs_Device *dev, uffs_BlockInfo *bc);
|
||||
|
||||
/********************************** Public defines *****************************/
|
||||
/**
|
||||
* \def UFFS_ALL_PAGES
|
||||
* \brief UFFS_ALL_PAGES if this value presented, that means the objects are all pages in the block
|
||||
*/
|
||||
#define UFFS_ALL_PAGES (0xffff)
|
||||
|
||||
/**
|
||||
* \def UFFS_INVALID_PAGE
|
||||
* \brief macro for invalid page number
|
||||
*/
|
||||
#define UFFS_INVALID_PAGE (0xfffe)
|
||||
#define UFFS_INVALID_BLOCK (0xfffe)
|
||||
|
||||
|
||||
URET uffs_NewBlock(uffs_Device *dev, u16 block, uffs_Tags *tag, uffs_Buf *buf);
|
||||
URET uffs_BlockRecover(uffs_Device *dev, uffs_BlockInfo *old, u16 newBlock);
|
||||
URET uffs_PageRecover(uffs_Device *dev,
|
||||
uffs_BlockInfo *bc,
|
||||
u16 oldPage,
|
||||
u16 newPage,
|
||||
uffs_Buf *buf);
|
||||
int uffs_FindFreePageInBlock(uffs_Device *dev, uffs_BlockInfo *bc);
|
||||
u16 uffs_FindBestPageInBlock(uffs_Device *dev, uffs_BlockInfo *bc, u16 page);
|
||||
u16 uffs_FindFirstValidPage(uffs_Device *dev, uffs_BlockInfo *bc);
|
||||
u16 uffs_FindFirstFreePage(uffs_Device *dev, uffs_BlockInfo *bc, u16 pageFrom);
|
||||
u16 uffs_FindPageInBlockWithPageId(uffs_Device *dev, uffs_BlockInfo *bc, u16 page_id);
|
||||
|
||||
u8 uffs_MakeSum8(const void *p, int len);
|
||||
u16 uffs_MakeSum16(const void *p, int len);
|
||||
URET uffs_CreateNewFile(uffs_Device *dev, u16 parent, u16 serial, uffs_BlockInfo *bc, uffs_FileInfo *fi);
|
||||
|
||||
int uffs_GetBlockFileDataLength(uffs_Device *dev, uffs_BlockInfo *bc, u8 type);
|
||||
UBOOL uffs_IsPageErased(uffs_Device *dev, uffs_BlockInfo *bc, u16 page);
|
||||
int uffs_GetFreePagesCount(uffs_Device *dev, uffs_BlockInfo *bc);
|
||||
UBOOL uffs_IsDataBlockReguFull(uffs_Device *dev, uffs_BlockInfo *bc);
|
||||
|
||||
int uffs_GetBlockTimeStamp(uffs_Device *dev, uffs_BlockInfo *bc);
|
||||
|
||||
|
||||
int uffs_GetDeviceUsed(uffs_Device *dev);
|
||||
int uffs_GetDeviceFree(uffs_Device *dev);
|
||||
int uffs_GetDeviceTotal(uffs_Device *dev);
|
||||
|
||||
URET uffs_LoadMiniHeader(uffs_Device *dev, int block, u16 page, struct uffs_MiniHeaderSt *header);
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* init functions */
|
||||
/************************************************************************/
|
||||
URET uffs_InitDevice(uffs_Device *dev);
|
||||
URET uffs_ReleaseDevice(uffs_Device *dev);
|
||||
|
||||
|
||||
URET uffs_InitFlashClass(uffs_Device *dev);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // _UFFS_PUBLIC_H_
|
||||
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_public.h
|
||||
* \brief public data structures for uffs
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_PUBLIC_H_
|
||||
#define _UFFS_PUBLIC_H_
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
#include "uffs/uffs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \struct uffs_TagStoreSt
|
||||
* \brief uffs tag, 8 bytes, will be store in page spare area.
|
||||
*/
|
||||
struct uffs_TagStoreSt {
|
||||
u32 dirty:1; //!< 0: dirty, 1: clear
|
||||
u32 valid:1; //!< 0: valid, 1: invalid
|
||||
u32 type:2; //!< block type: #UFFS_TYPE_DIR, #UFFS_TYPE_FILE, #UFFS_TYPE_DATA
|
||||
u32 block_ts:2; //!< time stamp of block;
|
||||
u32 data_len:12; //!< length of page data
|
||||
u32 serial:14; //!< serial number
|
||||
|
||||
u32 parent:10; //!< parent's serial number
|
||||
u32 page_id:6; //!< page id
|
||||
u32 reserved:4; //!< reserved, for UFFS2
|
||||
u32 tag_ecc:12; //!< tag ECC
|
||||
};
|
||||
|
||||
#define TAG_ECC_DEFAULT (0xFFF) //!< 12-bit '1'
|
||||
|
||||
/**
|
||||
* \struct uffs_TagStoreSt_8
|
||||
* \brief this data structure describes the page status, for 8 bytes page spare.
|
||||
* \note there is no tag ecc for this !
|
||||
*/
|
||||
struct uffs_TagStoreSt_8 {
|
||||
u32 dirty:1; //!< 0: dirty, 1: clear
|
||||
u32 valid:1; //!< 0: valid, 1: invalid
|
||||
u32 type:2; //!< block type: #UFFS_TYPE_DIR, #UFFS_TYPE_FILE, #UFFS_TYPE_DATA
|
||||
u32 block_ts:2; //!< time stamp of block;
|
||||
u32 page_id:5; //!< page id
|
||||
u32 parent:7; //!< parent's serial number
|
||||
u32 serial:8; //!< serial number
|
||||
u32 data_len:8; //!< length of page data
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_TagsSt
|
||||
*/
|
||||
struct uffs_TagsSt {
|
||||
struct uffs_TagStoreSt s; /* store must be the first member */
|
||||
|
||||
/** data_sum for file or dir name */
|
||||
u16 data_sum;
|
||||
|
||||
/**
|
||||
* block_status is not covered by tag_ecc.
|
||||
* it's loaded from flash but not directly write to flash.
|
||||
*/
|
||||
u8 block_status;
|
||||
|
||||
/** internal used */
|
||||
u8 _dirty:1; //!< raw data, before doing ecc correction
|
||||
u8 _valid:1; //!< raw data, before doing ecc correction
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct uffs_MiniHeaderSt
|
||||
* \brief the mini header resides on the head of page data
|
||||
*/
|
||||
struct uffs_MiniHeaderSt {
|
||||
u8 status;
|
||||
u8 reserved;
|
||||
u16 crc;
|
||||
};
|
||||
|
||||
|
||||
/** uffs_TagsSt.dirty */
|
||||
#define TAG_VALID 0
|
||||
#define TAG_INVALID 1
|
||||
|
||||
/** uffs_TagsSt.valid */
|
||||
#define TAG_DIRTY 0
|
||||
#define TAG_CLEAR 1
|
||||
|
||||
#define TAG_IS_DIRTY(tag) ((tag)->s.dirty == TAG_DIRTY)
|
||||
#define TAG_IS_VALID(tag) ((tag)->s.valid == TAG_VALID)
|
||||
#define TAG_SERIAL(tag) (tag)->s.serial
|
||||
#define TAG_PARENT(tag) (tag)->s.parent
|
||||
#define TAG_PAGE_ID(tag) (tag)->s.page_id
|
||||
#define TAG_DATA_LEN(tag) (tag)->s.data_len
|
||||
#define TAG_TYPE(tag) (tag)->s.type
|
||||
#define TAG_BLOCK_TS(tag) (tag)->s.block_ts
|
||||
|
||||
|
||||
int uffs_GetFirstBlockTimeStamp(void);
|
||||
int uffs_GetNextBlockTimeStamp(int prev);
|
||||
UBOOL uffs_IsSrcNewerThanObj(int src, int obj);
|
||||
|
||||
|
||||
#include "uffs_device.h"
|
||||
|
||||
|
||||
|
||||
/********************************** debug & error *************************************/
|
||||
#define UFFS_ERR_NOISY -1
|
||||
#define UFFS_ERR_NORMAL 0
|
||||
#define UFFS_ERR_SERIOUS 1
|
||||
#define UFFS_ERR_DEAD 2
|
||||
|
||||
#define TENDSTR "\n"
|
||||
|
||||
//#define UFFS_DBG_LEVEL UFFS_ERR_NORMAL
|
||||
#define UFFS_DBG_LEVEL UFFS_ERR_DEAD
|
||||
|
||||
void uffs_DebugMessage(int level, const char *prefix, const char *suffix, const char *errFmt, ...);
|
||||
|
||||
#define uffs_Perror(level, fmt, ... ) \
|
||||
uffs_DebugMessage(level, PFX, TENDSTR, fmt, ## __VA_ARGS__)
|
||||
|
||||
#define uffs_PerrorRaw(level, fmt, ... ) \
|
||||
uffs_DebugMessage(level, NULL, NULL, fmt, ## __VA_ARGS__)
|
||||
|
||||
|
||||
|
||||
void uffs_AssertCall(const char *file, int line, const char *msg);
|
||||
|
||||
#define uffs_Assert(expr, msg) \
|
||||
do { \
|
||||
if (!(expr)) \
|
||||
uffs_AssertCall(__FILE__, __LINE__, msg); \
|
||||
} while(0)
|
||||
|
||||
/********************************** NAND **********************************************/
|
||||
//NAND flash specific file must implement these interface
|
||||
URET uffs_LoadPageSpare(uffs_Device *dev, int block, int page, uffs_Tags *tag);
|
||||
URET uffs_WritePageSpare(uffs_Device *dev, int block, int page, uffs_Tags *tag);
|
||||
URET uffs_MakePageValid(uffs_Device *dev, int block, int page, uffs_Tags *tag);
|
||||
UBOOL uffs_IsBlockBad(uffs_Device *dev, uffs_BlockInfo *bc);
|
||||
|
||||
/********************************** Public defines *****************************/
|
||||
/**
|
||||
* \def UFFS_ALL_PAGES
|
||||
* \brief UFFS_ALL_PAGES if this value presented, that means the objects are all pages in the block
|
||||
*/
|
||||
#define UFFS_ALL_PAGES (0xffff)
|
||||
|
||||
/**
|
||||
* \def UFFS_INVALID_PAGE
|
||||
* \brief macro for invalid page number
|
||||
*/
|
||||
#define UFFS_INVALID_PAGE (0xfffe)
|
||||
#define UFFS_INVALID_BLOCK (0xfffe)
|
||||
|
||||
|
||||
URET uffs_NewBlock(uffs_Device *dev, u16 block, uffs_Tags *tag, uffs_Buf *buf);
|
||||
URET uffs_BlockRecover(uffs_Device *dev, uffs_BlockInfo *old, u16 newBlock);
|
||||
URET uffs_PageRecover(uffs_Device *dev,
|
||||
uffs_BlockInfo *bc,
|
||||
u16 oldPage,
|
||||
u16 newPage,
|
||||
uffs_Buf *buf);
|
||||
int uffs_FindFreePageInBlock(uffs_Device *dev, uffs_BlockInfo *bc);
|
||||
u16 uffs_FindBestPageInBlock(uffs_Device *dev, uffs_BlockInfo *bc, u16 page);
|
||||
u16 uffs_FindFirstValidPage(uffs_Device *dev, uffs_BlockInfo *bc);
|
||||
u16 uffs_FindFirstFreePage(uffs_Device *dev, uffs_BlockInfo *bc, u16 pageFrom);
|
||||
u16 uffs_FindPageInBlockWithPageId(uffs_Device *dev, uffs_BlockInfo *bc, u16 page_id);
|
||||
|
||||
u8 uffs_MakeSum8(const void *p, int len);
|
||||
u16 uffs_MakeSum16(const void *p, int len);
|
||||
URET uffs_CreateNewFile(uffs_Device *dev, u16 parent, u16 serial, uffs_BlockInfo *bc, uffs_FileInfo *fi);
|
||||
|
||||
int uffs_GetBlockFileDataLength(uffs_Device *dev, uffs_BlockInfo *bc, u8 type);
|
||||
UBOOL uffs_IsPageErased(uffs_Device *dev, uffs_BlockInfo *bc, u16 page);
|
||||
int uffs_GetFreePagesCount(uffs_Device *dev, uffs_BlockInfo *bc);
|
||||
UBOOL uffs_IsDataBlockReguFull(uffs_Device *dev, uffs_BlockInfo *bc);
|
||||
|
||||
int uffs_GetBlockTimeStamp(uffs_Device *dev, uffs_BlockInfo *bc);
|
||||
|
||||
|
||||
int uffs_GetDeviceUsed(uffs_Device *dev);
|
||||
int uffs_GetDeviceFree(uffs_Device *dev);
|
||||
int uffs_GetDeviceTotal(uffs_Device *dev);
|
||||
|
||||
URET uffs_LoadMiniHeader(uffs_Device *dev, int block, u16 page, struct uffs_MiniHeaderSt *header);
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* init functions */
|
||||
/************************************************************************/
|
||||
URET uffs_InitDevice(uffs_Device *dev);
|
||||
URET uffs_ReleaseDevice(uffs_Device *dev);
|
||||
|
||||
|
||||
URET uffs_InitFlashClass(uffs_Device *dev);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // _UFFS_PUBLIC_H_
|
||||
|
||||
|
||||
@@ -1,221 +1,221 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_TREE_H_
|
||||
#define _UFFS_TREE_H_
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_pool.h"
|
||||
#include "uffs/uffs_device.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
#define UFFS_TYPE_DIR 0
|
||||
#define UFFS_TYPE_FILE 1
|
||||
#define UFFS_TYPE_DATA 2
|
||||
#define UFFS_TYPE_RESV 3
|
||||
#define UFFS_TYPE_INVALID 0xFF
|
||||
|
||||
struct BlockListSt { /* 10 bytes */
|
||||
struct uffs_TreeNodeSt * next;
|
||||
struct uffs_TreeNodeSt * prev;
|
||||
u16 block;
|
||||
};
|
||||
|
||||
struct DirhSt { /* 8 bytes */
|
||||
u16 checksum; /* check sum of dir name */
|
||||
u16 block;
|
||||
u16 parent;
|
||||
u16 serial;
|
||||
};
|
||||
|
||||
|
||||
struct FilehSt { /* 12 bytes */
|
||||
u16 block;
|
||||
u16 checksum; /* check sum of file name */
|
||||
u16 parent;
|
||||
u16 serial;
|
||||
u32 len; /* file length total */
|
||||
};
|
||||
|
||||
struct FdataSt { /* 10 bytes */
|
||||
u16 block;
|
||||
u16 parent;
|
||||
u32 len; /* file data length on this block */
|
||||
u16 serial;
|
||||
};
|
||||
|
||||
//UFFS TreeNode (14 or 16 bytes)
|
||||
typedef struct uffs_TreeNodeSt {
|
||||
union {
|
||||
struct BlockListSt list;
|
||||
struct DirhSt dir;
|
||||
struct FilehSt file;
|
||||
struct FdataSt data;
|
||||
} u;
|
||||
u16 hash_next;
|
||||
#ifdef CONFIG_TREE_NODE_USE_DOUBLE_LINK
|
||||
u16 hash_prev;
|
||||
#endif
|
||||
} TreeNode;
|
||||
|
||||
|
||||
//TODO: UFFS2 Tree structures
|
||||
/*
|
||||
struct FdataSt {
|
||||
u32 len;
|
||||
};
|
||||
|
||||
struct filebSt {
|
||||
u16 bls; //how many blocks this file contents ...
|
||||
u8 offs; //the offset of this file header on FILE block
|
||||
u8 sum; //short sum of file name
|
||||
};
|
||||
|
||||
//Extra data structure for storing file length information
|
||||
struct FilehSt {
|
||||
u32 len;
|
||||
};
|
||||
|
||||
//UFFS2 TreeNode (12 bytes)
|
||||
typedef struct uffs_TreeNodeSt {
|
||||
u16 nextIdx;
|
||||
u16 block;
|
||||
u16 parent;
|
||||
u16 serial;
|
||||
union {
|
||||
struct FilehSt h;
|
||||
struct filedSt file;
|
||||
struct data;
|
||||
} u;
|
||||
} TreeNode;
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#define EMPTY_NODE 0xffff //!< special index num of empty node.
|
||||
|
||||
#define ROOT_DIR_SERIAL 0 //!< serial num of root dir
|
||||
#define MAX_UFFS_FSN 0x3ff //!< maximum dir|file serial number (uffs_TagStore#parent: 10 bits)
|
||||
#define MAX_UFFS_FDN 0x3fff //!< maximum file data block serial numbers (uffs_TagStore#serial: 14 bits)
|
||||
#define PARENT_OF_ROOT 0xfffd //!< parent of ROOT ? kidding me ...
|
||||
#define INVALID_UFFS_SERIAL 0xffff //!< invalid serial num
|
||||
|
||||
#define DIR_NODE_HASH_MASK 0x1f
|
||||
#define DIR_NODE_ENTRY_LEN (DIR_NODE_HASH_MASK + 1)
|
||||
|
||||
#define FILE_NODE_HASH_MASK 0x3f
|
||||
#define FILE_NODE_ENTRY_LEN (FILE_NODE_HASH_MASK + 1)
|
||||
|
||||
#define DATA_NODE_HASH_MASK 0x1ff
|
||||
#define DATA_NODE_ENTRY_LEN (DATA_NODE_HASH_MASK + 1)
|
||||
#define FROM_IDX(idx, pool) ((TreeNode *)uffs_PoolGetBufByIndex(pool, idx))
|
||||
#define TO_IDX(p, pool) ((u16)uffs_PoolGetIndex(pool, (void *) p))
|
||||
|
||||
|
||||
#define GET_FILE_HASH(serial) (serial & FILE_NODE_HASH_MASK)
|
||||
#define GET_DIR_HASH(serial) (serial & DIR_NODE_HASH_MASK)
|
||||
#define GET_DATA_HASH(parent, serial) ((parent + serial) & DATA_NODE_HASH_MASK)
|
||||
|
||||
|
||||
struct uffs_TreeSt {
|
||||
TreeNode *erased; //!< erased block list head
|
||||
TreeNode *erased_tail; //!< erased block list tail
|
||||
int erased_count; //!< erased block counter
|
||||
TreeNode *bad; //!< bad block list
|
||||
int bad_count; //!< bad block count
|
||||
u16 dir_entry[DIR_NODE_ENTRY_LEN];
|
||||
u16 file_entry[FILE_NODE_ENTRY_LEN];
|
||||
u16 data_entry[DATA_NODE_ENTRY_LEN];
|
||||
u16 max_serial;
|
||||
};
|
||||
|
||||
|
||||
URET uffs_TreeInit(uffs_Device *dev);
|
||||
URET uffs_TreeRelease(uffs_Device *dev);
|
||||
URET uffs_BuildTree(uffs_Device *dev);
|
||||
u16 uffs_FindFreeFsnSerial(uffs_Device *dev);
|
||||
TreeNode * uffs_TreeFindFileNode(uffs_Device *dev, u16 serial);
|
||||
TreeNode * uffs_TreeFindFileNodeWithParent(uffs_Device *dev, u16 parent);
|
||||
TreeNode * uffs_TreeFindDirNode(uffs_Device *dev, u16 serial);
|
||||
TreeNode * uffs_TreeFindDirNodeWithParent(uffs_Device *dev, u16 parent);
|
||||
TreeNode * uffs_TreeFindFileNodeByName(uffs_Device *dev, const char *name, u32 len, u16 sum, u16 parent);
|
||||
TreeNode * uffs_TreeFindDirNodeByName(uffs_Device *dev, const char *name, u32 len, u16 sum, u16 parent);
|
||||
TreeNode * uffs_TreeFindDataNode(uffs_Device *dev, u16 parent, u16 serial);
|
||||
|
||||
|
||||
TreeNode * uffs_TreeFindDirNodeByBlock(uffs_Device *dev, u16 block);
|
||||
TreeNode * uffs_TreeFindFileNodeByBlock(uffs_Device *dev, u16 block);
|
||||
TreeNode * uffs_TreeFindDataNodeByBlock(uffs_Device *dev, u16 block);
|
||||
TreeNode * uffs_TreeFindErasedNodeByBlock(uffs_Device *dev, u16 block);
|
||||
TreeNode * uffs_TreeFindBadNodeByBlock(uffs_Device *dev, u16 block);
|
||||
|
||||
#define SEARCH_REGION_DIR 1
|
||||
#define SEARCH_REGION_FILE 2
|
||||
#define SEARCH_REGION_DATA 4
|
||||
#define SEARCH_REGION_BAD 8
|
||||
#define SEARCH_REGION_ERASED 16
|
||||
TreeNode * uffs_TreeFindNodeByBlock(uffs_Device *dev, u16 block, int *region);
|
||||
|
||||
|
||||
|
||||
UBOOL uffs_TreeCompareFileName(uffs_Device *dev, const char *name, u32 len, u16 sum, TreeNode *node, int type);
|
||||
|
||||
TreeNode * uffs_TreeGetErasedNode(uffs_Device *dev);
|
||||
|
||||
void uffs_InsertNodeToTree(uffs_Device *dev, u8 type, TreeNode *node);
|
||||
void uffs_InsertToErasedListHead(uffs_Device *dev, TreeNode *node);
|
||||
void uffs_TreeInsertToErasedListTail(uffs_Device *dev, TreeNode *node);
|
||||
void uffs_TreeInsertToBadBlockList(uffs_Device *dev, TreeNode *node);
|
||||
|
||||
void uffs_BreakFromEntry(uffs_Device *dev, u8 type, TreeNode *node);
|
||||
|
||||
void uffs_TreeSetNodeBlock(u8 type, TreeNode *node, u16 block);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
#ifndef _UFFS_TREE_H_
|
||||
#define _UFFS_TREE_H_
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_pool.h"
|
||||
#include "uffs/uffs_device.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
#define UFFS_TYPE_DIR 0
|
||||
#define UFFS_TYPE_FILE 1
|
||||
#define UFFS_TYPE_DATA 2
|
||||
#define UFFS_TYPE_RESV 3
|
||||
#define UFFS_TYPE_INVALID 0xFF
|
||||
|
||||
struct BlockListSt { /* 10 bytes */
|
||||
struct uffs_TreeNodeSt * next;
|
||||
struct uffs_TreeNodeSt * prev;
|
||||
u16 block;
|
||||
};
|
||||
|
||||
struct DirhSt { /* 8 bytes */
|
||||
u16 checksum; /* check sum of dir name */
|
||||
u16 block;
|
||||
u16 parent;
|
||||
u16 serial;
|
||||
};
|
||||
|
||||
|
||||
struct FilehSt { /* 12 bytes */
|
||||
u16 block;
|
||||
u16 checksum; /* check sum of file name */
|
||||
u16 parent;
|
||||
u16 serial;
|
||||
u32 len; /* file length total */
|
||||
};
|
||||
|
||||
struct FdataSt { /* 10 bytes */
|
||||
u16 block;
|
||||
u16 parent;
|
||||
u32 len; /* file data length on this block */
|
||||
u16 serial;
|
||||
};
|
||||
|
||||
//UFFS TreeNode (14 or 16 bytes)
|
||||
typedef struct uffs_TreeNodeSt {
|
||||
union {
|
||||
struct BlockListSt list;
|
||||
struct DirhSt dir;
|
||||
struct FilehSt file;
|
||||
struct FdataSt data;
|
||||
} u;
|
||||
u16 hash_next;
|
||||
#ifdef CONFIG_TREE_NODE_USE_DOUBLE_LINK
|
||||
u16 hash_prev;
|
||||
#endif
|
||||
} TreeNode;
|
||||
|
||||
|
||||
//TODO: UFFS2 Tree structures
|
||||
/*
|
||||
struct FdataSt {
|
||||
u32 len;
|
||||
};
|
||||
|
||||
struct filebSt {
|
||||
u16 bls; //how many blocks this file contents ...
|
||||
u8 offs; //the offset of this file header on FILE block
|
||||
u8 sum; //short sum of file name
|
||||
};
|
||||
|
||||
//Extra data structure for storing file length information
|
||||
struct FilehSt {
|
||||
u32 len;
|
||||
};
|
||||
|
||||
//UFFS2 TreeNode (12 bytes)
|
||||
typedef struct uffs_TreeNodeSt {
|
||||
u16 nextIdx;
|
||||
u16 block;
|
||||
u16 parent;
|
||||
u16 serial;
|
||||
union {
|
||||
struct FilehSt h;
|
||||
struct filedSt file;
|
||||
struct data;
|
||||
} u;
|
||||
} TreeNode;
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#define EMPTY_NODE 0xffff //!< special index num of empty node.
|
||||
|
||||
#define ROOT_DIR_SERIAL 0 //!< serial num of root dir
|
||||
#define MAX_UFFS_FSN 0x3ff //!< maximum dir|file serial number (uffs_TagStore#parent: 10 bits)
|
||||
#define MAX_UFFS_FDN 0x3fff //!< maximum file data block serial numbers (uffs_TagStore#serial: 14 bits)
|
||||
#define PARENT_OF_ROOT 0xfffd //!< parent of ROOT ? kidding me ...
|
||||
#define INVALID_UFFS_SERIAL 0xffff //!< invalid serial num
|
||||
|
||||
#define DIR_NODE_HASH_MASK 0x1f
|
||||
#define DIR_NODE_ENTRY_LEN (DIR_NODE_HASH_MASK + 1)
|
||||
|
||||
#define FILE_NODE_HASH_MASK 0x3f
|
||||
#define FILE_NODE_ENTRY_LEN (FILE_NODE_HASH_MASK + 1)
|
||||
|
||||
#define DATA_NODE_HASH_MASK 0x1ff
|
||||
#define DATA_NODE_ENTRY_LEN (DATA_NODE_HASH_MASK + 1)
|
||||
#define FROM_IDX(idx, pool) ((TreeNode *)uffs_PoolGetBufByIndex(pool, idx))
|
||||
#define TO_IDX(p, pool) ((u16)uffs_PoolGetIndex(pool, (void *) p))
|
||||
|
||||
|
||||
#define GET_FILE_HASH(serial) (serial & FILE_NODE_HASH_MASK)
|
||||
#define GET_DIR_HASH(serial) (serial & DIR_NODE_HASH_MASK)
|
||||
#define GET_DATA_HASH(parent, serial) ((parent + serial) & DATA_NODE_HASH_MASK)
|
||||
|
||||
|
||||
struct uffs_TreeSt {
|
||||
TreeNode *erased; //!< erased block list head
|
||||
TreeNode *erased_tail; //!< erased block list tail
|
||||
int erased_count; //!< erased block counter
|
||||
TreeNode *bad; //!< bad block list
|
||||
int bad_count; //!< bad block count
|
||||
u16 dir_entry[DIR_NODE_ENTRY_LEN];
|
||||
u16 file_entry[FILE_NODE_ENTRY_LEN];
|
||||
u16 data_entry[DATA_NODE_ENTRY_LEN];
|
||||
u16 max_serial;
|
||||
};
|
||||
|
||||
|
||||
URET uffs_TreeInit(uffs_Device *dev);
|
||||
URET uffs_TreeRelease(uffs_Device *dev);
|
||||
URET uffs_BuildTree(uffs_Device *dev);
|
||||
u16 uffs_FindFreeFsnSerial(uffs_Device *dev);
|
||||
TreeNode * uffs_TreeFindFileNode(uffs_Device *dev, u16 serial);
|
||||
TreeNode * uffs_TreeFindFileNodeWithParent(uffs_Device *dev, u16 parent);
|
||||
TreeNode * uffs_TreeFindDirNode(uffs_Device *dev, u16 serial);
|
||||
TreeNode * uffs_TreeFindDirNodeWithParent(uffs_Device *dev, u16 parent);
|
||||
TreeNode * uffs_TreeFindFileNodeByName(uffs_Device *dev, const char *name, u32 len, u16 sum, u16 parent);
|
||||
TreeNode * uffs_TreeFindDirNodeByName(uffs_Device *dev, const char *name, u32 len, u16 sum, u16 parent);
|
||||
TreeNode * uffs_TreeFindDataNode(uffs_Device *dev, u16 parent, u16 serial);
|
||||
|
||||
|
||||
TreeNode * uffs_TreeFindDirNodeByBlock(uffs_Device *dev, u16 block);
|
||||
TreeNode * uffs_TreeFindFileNodeByBlock(uffs_Device *dev, u16 block);
|
||||
TreeNode * uffs_TreeFindDataNodeByBlock(uffs_Device *dev, u16 block);
|
||||
TreeNode * uffs_TreeFindErasedNodeByBlock(uffs_Device *dev, u16 block);
|
||||
TreeNode * uffs_TreeFindBadNodeByBlock(uffs_Device *dev, u16 block);
|
||||
|
||||
#define SEARCH_REGION_DIR 1
|
||||
#define SEARCH_REGION_FILE 2
|
||||
#define SEARCH_REGION_DATA 4
|
||||
#define SEARCH_REGION_BAD 8
|
||||
#define SEARCH_REGION_ERASED 16
|
||||
TreeNode * uffs_TreeFindNodeByBlock(uffs_Device *dev, u16 block, int *region);
|
||||
|
||||
|
||||
|
||||
UBOOL uffs_TreeCompareFileName(uffs_Device *dev, const char *name, u32 len, u16 sum, TreeNode *node, int type);
|
||||
|
||||
TreeNode * uffs_TreeGetErasedNode(uffs_Device *dev);
|
||||
|
||||
void uffs_InsertNodeToTree(uffs_Device *dev, u8 type, TreeNode *node);
|
||||
void uffs_InsertToErasedListHead(uffs_Device *dev, TreeNode *node);
|
||||
void uffs_TreeInsertToErasedListTail(uffs_Device *dev, TreeNode *node);
|
||||
void uffs_TreeInsertToBadBlockList(uffs_Device *dev, TreeNode *node);
|
||||
|
||||
void uffs_BreakFromEntry(uffs_Device *dev, u8 type, TreeNode *node);
|
||||
|
||||
void uffs_TreeSetNodeBlock(u8 type, TreeNode *node, u16 block);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,156 +1,158 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
#ifndef UFFS_TYPES_H
|
||||
#define UFFS_TYPES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
#ifdef _UBASE_
|
||||
#include <sys/utypes.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \file uffs_types.h
|
||||
* \brief basic types used on uffs
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
/* basic types */
|
||||
|
||||
/** \typedef i8
|
||||
* \brief 8 bit integer
|
||||
*/
|
||||
typedef char i8;
|
||||
|
||||
/** \typedef u8
|
||||
* \brief 8 bit unsigned integer
|
||||
*/
|
||||
typedef unsigned char u8;
|
||||
|
||||
/** \typedef i16
|
||||
* \brief 16 bit integer
|
||||
*/
|
||||
typedef short int i16;
|
||||
|
||||
|
||||
/** \typedef u16
|
||||
* \brief 16 bit unsigned integer
|
||||
*/
|
||||
typedef unsigned short int u16;
|
||||
|
||||
|
||||
/** \typedef i32
|
||||
* \brief 32 bit integer
|
||||
*/
|
||||
typedef int i32;
|
||||
|
||||
/** \typedef u32
|
||||
* \brief 32 bit unsigned integer
|
||||
*/
|
||||
typedef unsigned int u32;
|
||||
|
||||
|
||||
#ifndef _UBASE_
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
/* boolean type */
|
||||
|
||||
/** \typedef UBOOL
|
||||
* \brief boolean type for uffs, the value would be: #U_TRUE or #U_FALSE
|
||||
*/
|
||||
typedef int UBOOL;
|
||||
|
||||
/** \def U_TRUE
|
||||
* \brief boolean true for uffs
|
||||
*/
|
||||
#define U_TRUE (TRUE)
|
||||
|
||||
|
||||
/** \def U_FALSE
|
||||
* \brief boolean false for uffs
|
||||
*/
|
||||
#define U_FALSE (FALSE)
|
||||
|
||||
|
||||
/** \typedef URET
|
||||
* \brief return type for uffs, should be #U_FAIL or #U_SUCC
|
||||
*/
|
||||
typedef int URET;
|
||||
|
||||
/** \def U_FAIL
|
||||
* \brief indicator of fail
|
||||
*/
|
||||
#define U_FAIL -1
|
||||
|
||||
/** \def U_SUCC
|
||||
* \brief indicator of successful
|
||||
*/
|
||||
#define U_SUCC 0
|
||||
|
||||
/** \def IS_SUCC(ret)
|
||||
* \brief is it successful ?
|
||||
*/
|
||||
#define IS_SUCC(ret) (ret >= 0 ? U_TRUE : U_FALSE)
|
||||
|
||||
|
||||
/** \def IS_FAIL(ret)
|
||||
* \brief is it fail ?
|
||||
*/
|
||||
#define IS_FAIL(ret) (ret < 0 ? U_TRUE : U_FALSE)
|
||||
|
||||
#ifndef NULL
|
||||
/** \def NULL
|
||||
* \brief zero for pointer
|
||||
*/
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#endif // _UBASE_
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
#ifndef UFFS_TYPES_H
|
||||
#define UFFS_TYPES_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
#ifdef _UBASE_
|
||||
#include <sys/utypes.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \file uffs_types.h
|
||||
* \brief basic types used on uffs
|
||||
* \author Ricky Zheng
|
||||
*/
|
||||
|
||||
/* basic types */
|
||||
|
||||
/** \typedef i8
|
||||
* \brief 8 bit integer
|
||||
*/
|
||||
typedef char i8;
|
||||
|
||||
/** \typedef u8
|
||||
* \brief 8 bit unsigned integer
|
||||
*/
|
||||
typedef unsigned char u8;
|
||||
|
||||
/** \typedef i16
|
||||
* \brief 16 bit integer
|
||||
*/
|
||||
typedef short int i16;
|
||||
|
||||
|
||||
/** \typedef u16
|
||||
* \brief 16 bit unsigned integer
|
||||
*/
|
||||
typedef unsigned short int u16;
|
||||
|
||||
|
||||
/** \typedef i32
|
||||
* \brief 32 bit integer
|
||||
*/
|
||||
typedef int i32;
|
||||
|
||||
/** \typedef u32
|
||||
* \brief 32 bit unsigned integer
|
||||
*/
|
||||
typedef unsigned int u32;
|
||||
|
||||
|
||||
#ifndef _UBASE_
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
/* boolean type */
|
||||
|
||||
/** \typedef UBOOL
|
||||
* \brief boolean type for uffs, the value would be: #U_TRUE or #U_FALSE
|
||||
*/
|
||||
typedef int UBOOL;
|
||||
|
||||
/** \def U_TRUE
|
||||
* \brief boolean true for uffs
|
||||
*/
|
||||
#define U_TRUE (TRUE)
|
||||
|
||||
|
||||
/** \def U_FALSE
|
||||
* \brief boolean false for uffs
|
||||
*/
|
||||
#define U_FALSE (FALSE)
|
||||
|
||||
|
||||
/** \typedef URET
|
||||
* \brief return type for uffs, should be #U_FAIL or #U_SUCC
|
||||
*/
|
||||
typedef int URET;
|
||||
|
||||
/** \def U_FAIL
|
||||
* \brief indicator of fail
|
||||
*/
|
||||
#define U_FAIL -1
|
||||
|
||||
/** \def U_SUCC
|
||||
* \brief indicator of successful
|
||||
*/
|
||||
#define U_SUCC 0
|
||||
|
||||
/** \def IS_SUCC(ret)
|
||||
* \brief is it successful ?
|
||||
*/
|
||||
#define IS_SUCC(ret) (ret >= 0 ? U_TRUE : U_FALSE)
|
||||
|
||||
|
||||
/** \def IS_FAIL(ret)
|
||||
* \brief is it fail ?
|
||||
*/
|
||||
#define IS_FAIL(ret) (ret < 0 ? U_TRUE : U_FALSE)
|
||||
|
||||
#ifndef NULL
|
||||
/** \def NULL
|
||||
* \brief zero for pointer
|
||||
*/
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#endif // _UBASE_
|
||||
|
||||
|
||||
/* RT-Thread info */
|
||||
|
||||
#define memset rt_memset
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,85 +1,85 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
#ifndef UFFS_UTILS_H
|
||||
#define UFFS_UTILS_H
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_device.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
//begin method
|
||||
#define PARTITION_FOLLOW_PRIVATE 0
|
||||
#define PARTITION_BEGIN_ABSOLUTE 1
|
||||
|
||||
//alloc method
|
||||
#define ALLOC_BY_SIZE 0
|
||||
#define ALLOC_BY_ABSOLUTE 1
|
||||
#define ALLOC_USE_FREE 2
|
||||
|
||||
//struct uffs_PartitionMakeInfoSt {
|
||||
// u32 begin_method;
|
||||
// u32 alloc_method;
|
||||
// union{
|
||||
// u32 begin_block;
|
||||
// u32 begin_offset;
|
||||
// };
|
||||
// union{
|
||||
// u32 end_block;
|
||||
// u32 size;
|
||||
// u32 remain_size;
|
||||
// };
|
||||
// u32 access;
|
||||
//};
|
||||
//
|
||||
//
|
||||
//URET uffs_MakePartition(struct uffs_DeviceSt *dev, struct uffs_PartitionMakeInfoSt *pi, int nums);
|
||||
//
|
||||
//void uffs_ListPartition(struct uffs_DeviceSt *dev);
|
||||
|
||||
//get UFFS disk version, if fail, return 0
|
||||
int uffs_GetUFFSVersion(struct uffs_DeviceSt *dev);
|
||||
|
||||
URET uffs_FormatDevice(uffs_Device *dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
#ifndef UFFS_UTILS_H
|
||||
#define UFFS_UTILS_H
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_device.h"
|
||||
#include "uffs/uffs_core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
//begin method
|
||||
#define PARTITION_FOLLOW_PRIVATE 0
|
||||
#define PARTITION_BEGIN_ABSOLUTE 1
|
||||
|
||||
//alloc method
|
||||
#define ALLOC_BY_SIZE 0
|
||||
#define ALLOC_BY_ABSOLUTE 1
|
||||
#define ALLOC_USE_FREE 2
|
||||
|
||||
//struct uffs_PartitionMakeInfoSt {
|
||||
// u32 begin_method;
|
||||
// u32 alloc_method;
|
||||
// union{
|
||||
// u32 begin_block;
|
||||
// u32 begin_offset;
|
||||
// };
|
||||
// union{
|
||||
// u32 end_block;
|
||||
// u32 size;
|
||||
// u32 remain_size;
|
||||
// };
|
||||
// u32 access;
|
||||
//};
|
||||
//
|
||||
//
|
||||
//URET uffs_MakePartition(struct uffs_DeviceSt *dev, struct uffs_PartitionMakeInfoSt *pi, int nums);
|
||||
//
|
||||
//void uffs_ListPartition(struct uffs_DeviceSt *dev);
|
||||
|
||||
//get UFFS disk version, if fail, return 0
|
||||
int uffs_GetUFFSVersion(struct uffs_DeviceSt *dev);
|
||||
|
||||
URET uffs_FormatDevice(uffs_Device *dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,54 +1,54 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
#ifndef UFFS_VERSION_H
|
||||
#define UFFS_VERSION_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
#define UFFS_VERSION 0x01030000 //"01.03.0000"
|
||||
|
||||
const char * uffs_Version2Str(int ver);
|
||||
int uffs_GetVersion(void);
|
||||
int uffs_GetMainVersion(int ver);
|
||||
int uffs_GetMinorVersion(int ver);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
#ifndef UFFS_VERSION_H
|
||||
#define UFFS_VERSION_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
#define UFFS_VERSION 0x01030000 //"01.03.0000"
|
||||
|
||||
const char * uffs_Version2Str(int ver);
|
||||
int uffs_GetVersion(void);
|
||||
int uffs_GetMainVersion(int ver);
|
||||
int uffs_GetMinorVersion(int ver);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
SET (libuffs_SRCS
|
||||
uffs_badblock.c
|
||||
uffs_blockinfo.c
|
||||
uffs_buf.c
|
||||
uffs_debug.c
|
||||
uffs_device.c
|
||||
uffs_ecc.c
|
||||
uffs_fd.c
|
||||
uffs_fs.c
|
||||
uffs_init.c
|
||||
uffs_mem.c
|
||||
uffs_pool.c
|
||||
uffs_public.c
|
||||
uffs_tree.c
|
||||
uffs_utils.c
|
||||
uffs_mtb.c
|
||||
uffs_find.c
|
||||
uffs_flash.c
|
||||
uffs_version.c
|
||||
)
|
||||
|
||||
SET (HDR ${uffs_SOURCE_DIR}/src/inc/uffs)
|
||||
|
||||
SET (libuffs_HEADS
|
||||
${HDR}/uffs.h
|
||||
${HDR}/uffs_badblock.h
|
||||
${HDR}/uffs_blockinfo.h
|
||||
${HDR}/uffs_buf.h
|
||||
${HDR}/uffs_config.h
|
||||
${HDR}/uffs_core.h
|
||||
${HDR}/uffs_device.h
|
||||
${HDR}/uffs_ecc.h
|
||||
${HDR}/uffs_fd.h
|
||||
${HDR}/uffs_fs.h
|
||||
${HDR}/uffs_mem.h
|
||||
${HDR}/uffs_os.h
|
||||
${HDR}/uffs_pool.h
|
||||
${HDR}/uffs_public.h
|
||||
${HDR}/uffs_tree.h
|
||||
${HDR}/uffs_types.h
|
||||
${HDR}/uffs_utils.h
|
||||
${HDR}/uffs_mtb.h
|
||||
${HDR}/uffs_find.h
|
||||
${HDR}/uffs_flash.h
|
||||
${HDR}/uffs_version.h
|
||||
)
|
||||
|
||||
INCLUDE_DIRECTORIES(${uffs_SOURCE_DIR}/src/inc)
|
||||
ADD_LIBRARY( uffs STATIC ${libuffs_SRCS} ${libuffs_HEADS} )
|
||||
SET (libuffs_SRCS
|
||||
uffs_badblock.c
|
||||
uffs_blockinfo.c
|
||||
uffs_buf.c
|
||||
uffs_debug.c
|
||||
uffs_device.c
|
||||
uffs_ecc.c
|
||||
uffs_fd.c
|
||||
uffs_fs.c
|
||||
uffs_init.c
|
||||
uffs_mem.c
|
||||
uffs_pool.c
|
||||
uffs_public.c
|
||||
uffs_tree.c
|
||||
uffs_utils.c
|
||||
uffs_mtb.c
|
||||
uffs_find.c
|
||||
uffs_flash.c
|
||||
uffs_version.c
|
||||
)
|
||||
|
||||
SET (HDR ${uffs_SOURCE_DIR}/src/inc/uffs)
|
||||
|
||||
SET (libuffs_HEADS
|
||||
${HDR}/uffs.h
|
||||
${HDR}/uffs_badblock.h
|
||||
${HDR}/uffs_blockinfo.h
|
||||
${HDR}/uffs_buf.h
|
||||
${HDR}/uffs_config.h
|
||||
${HDR}/uffs_core.h
|
||||
${HDR}/uffs_device.h
|
||||
${HDR}/uffs_ecc.h
|
||||
${HDR}/uffs_fd.h
|
||||
${HDR}/uffs_fs.h
|
||||
${HDR}/uffs_mem.h
|
||||
${HDR}/uffs_os.h
|
||||
${HDR}/uffs_pool.h
|
||||
${HDR}/uffs_public.h
|
||||
${HDR}/uffs_tree.h
|
||||
${HDR}/uffs_types.h
|
||||
${HDR}/uffs_utils.h
|
||||
${HDR}/uffs_mtb.h
|
||||
${HDR}/uffs_find.h
|
||||
${HDR}/uffs_flash.h
|
||||
${HDR}/uffs_version.h
|
||||
)
|
||||
|
||||
INCLUDE_DIRECTORIES(${uffs_SOURCE_DIR}/src/inc)
|
||||
ADD_LIBRARY( uffs STATIC ${libuffs_SRCS} ${libuffs_HEADS} )
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -39,178 +39,178 @@
|
||||
#include "uffs/uffs_fs.h"
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_ecc.h"
|
||||
#include "uffs/uffs_badblock.h"
|
||||
#include <string.h>
|
||||
#include "uffs/uffs_badblock.h"
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#define PFX "bbl: "
|
||||
|
||||
void uffs_BadBlockInit(uffs_Device *dev)
|
||||
{
|
||||
{
|
||||
dev->bad.block = UFFS_INVALID_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief process bad block: erase bad block, mark it as 'bad' and put the node to bad block list.
|
||||
* \param[in] dev uffs device
|
||||
* \param[in] node bad block tree node (before the block turn 'bad', it must belong to something ...)
|
||||
*/
|
||||
void uffs_BadBlockProcess(uffs_Device *dev, TreeNode *node)
|
||||
{
|
||||
if (HAVE_BADBLOCK(dev)) {
|
||||
// mark the bad block
|
||||
uffs_FlashMarkBadBlock(dev, dev->bad.block);
|
||||
|
||||
// and put it into bad block list
|
||||
if (node != NULL)
|
||||
uffs_TreeInsertToBadBlockList(dev, node);
|
||||
|
||||
//clear bad block mark.
|
||||
dev->bad.block = UFFS_INVALID_BLOCK;
|
||||
|
||||
}
|
||||
void uffs_BadBlockProcess(uffs_Device *dev, TreeNode *node)
|
||||
{
|
||||
if (HAVE_BADBLOCK(dev)) {
|
||||
// mark the bad block
|
||||
uffs_FlashMarkBadBlock(dev, dev->bad.block);
|
||||
|
||||
// and put it into bad block list
|
||||
if (node != NULL)
|
||||
uffs_TreeInsertToBadBlockList(dev, node);
|
||||
|
||||
//clear bad block mark.
|
||||
dev->bad.block = UFFS_INVALID_BLOCK;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief recover bad block
|
||||
* \param[in] dev uffs device
|
||||
*/
|
||||
void uffs_BadBlockRecover(uffs_Device *dev)
|
||||
{
|
||||
TreeNode *good, *bad;
|
||||
uffs_Buf *buf;
|
||||
u16 i;
|
||||
u16 page;
|
||||
uffs_BlockInfo *bc = NULL;
|
||||
uffs_Tags *tag;
|
||||
uffs_Tags newTag;
|
||||
UBOOL succRecov;
|
||||
UBOOL goodBlockIsDirty = U_FALSE;
|
||||
int ret;
|
||||
int region;
|
||||
u8 type;
|
||||
|
||||
if (dev->bad.block == UFFS_INVALID_BLOCK)
|
||||
return;
|
||||
|
||||
// pick up an erased good block
|
||||
good = uffs_TreeGetErasedNode(dev);
|
||||
if (good == NULL) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "no free block to replace bad block!");
|
||||
return;
|
||||
}
|
||||
|
||||
//recover block
|
||||
bc = uffs_BlockInfoGet(dev, dev->bad.block);
|
||||
|
||||
if (bc == NULL) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "can't get bad block info");
|
||||
return;
|
||||
}
|
||||
|
||||
succRecov = U_TRUE;
|
||||
for (i = 0; i < dev->attr->pages_per_block; i++) {
|
||||
page = uffs_FindPageInBlockWithPageId(dev, bc, i);
|
||||
if(page == UFFS_INVALID_PAGE) {
|
||||
break; //end of last valid page, normal break
|
||||
}
|
||||
page = uffs_FindBestPageInBlock(dev, bc, page);
|
||||
tag = GET_TAG(bc, page);
|
||||
buf = uffs_BufClone(dev, NULL);
|
||||
if (buf == NULL) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "Can't clone a new buf!");
|
||||
succRecov = U_FALSE;
|
||||
break;
|
||||
}
|
||||
//NOTE: since this is a bad block, we can't guarantee the data is ECC ok, so just load data even ECC is not OK.
|
||||
ret = uffs_LoadPhyDataToBufEccUnCare(dev, buf, bc->block, page);
|
||||
if (ret == U_FAIL) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "I/O error ?");
|
||||
uffs_BufFreeClone(dev, buf);
|
||||
succRecov = U_FALSE;
|
||||
break;
|
||||
}
|
||||
buf->data_len = TAG_DATA_LEN(tag);
|
||||
if (buf->data_len > dev->com.pg_data_size) {
|
||||
uffs_Perror(UFFS_ERR_NOISY, "data length over flow!!!");
|
||||
buf->data_len = dev->com.pg_data_size;
|
||||
}
|
||||
|
||||
buf->parent = TAG_PARENT(tag);
|
||||
buf->serial = TAG_SERIAL(tag);
|
||||
buf->type = TAG_TYPE(tag);
|
||||
buf->page_id = TAG_PAGE_ID(tag);
|
||||
|
||||
newTag = *tag;
|
||||
TAG_BLOCK_TS(&newTag) = uffs_GetNextBlockTimeStamp(TAG_BLOCK_TS(tag));
|
||||
|
||||
ret = uffs_FlashWritePageCombine(dev, good->u.list.block, i, buf, &newTag);
|
||||
|
||||
goodBlockIsDirty = U_TRUE;
|
||||
uffs_BufFreeClone(dev, buf);
|
||||
|
||||
if (ret == UFFS_FLASH_IO_ERR) {
|
||||
uffs_Perror(UFFS_ERR_NORMAL, "I/O error ?");
|
||||
succRecov = U_FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (succRecov == U_TRUE) {
|
||||
//successful recover bad block, so need to mark bad block, and replace with good one
|
||||
|
||||
region = SEARCH_REGION_DIR|SEARCH_REGION_FILE|SEARCH_REGION_DATA;
|
||||
bad = uffs_TreeFindNodeByBlock(dev, dev->bad.block, ®ion);
|
||||
if (bad != NULL) {
|
||||
switch (region) {
|
||||
case SEARCH_REGION_DIR:
|
||||
bad->u.dir.block = good->u.list.block;
|
||||
type = UFFS_TYPE_DIR;
|
||||
break;
|
||||
case SEARCH_REGION_FILE:
|
||||
bad->u.file.block = good->u.list.block;
|
||||
type = UFFS_TYPE_FILE;
|
||||
break;
|
||||
case SEARCH_REGION_DATA:
|
||||
bad->u.data.block = good->u.list.block;
|
||||
type = UFFS_TYPE_DATA;
|
||||
}
|
||||
|
||||
//from now, the 'bad' is actually good block :)))
|
||||
uffs_Perror(UFFS_ERR_NOISY, "new bad block %d found, and replaced by %d!", dev->bad.block, good->u.list.block);
|
||||
uffs_BlockInfoExpire(dev, bc, UFFS_ALL_PAGES);
|
||||
//we reuse the 'good' node as bad block node, and process the bad block.
|
||||
good->u.list.block = dev->bad.block;
|
||||
uffs_BadBlockProcess(dev, good);
|
||||
}
|
||||
else {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "can't find the reported bad block(%d) in the tree???", dev->bad.block);
|
||||
if (goodBlockIsDirty == U_TRUE)
|
||||
dev->ops->EraseBlock(dev, good->u.list.block);
|
||||
uffs_TreeInsertToErasedListTail(dev, good);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (goodBlockIsDirty == U_TRUE)
|
||||
dev->ops->EraseBlock(dev, good->u.list.block);
|
||||
uffs_TreeInsertToErasedListTail(dev, good); //put back to erased list
|
||||
}
|
||||
|
||||
uffs_BlockInfoPut(dev, bc);
|
||||
|
||||
/**
|
||||
* \brief recover bad block
|
||||
* \param[in] dev uffs device
|
||||
*/
|
||||
void uffs_BadBlockRecover(uffs_Device *dev)
|
||||
{
|
||||
TreeNode *good, *bad;
|
||||
uffs_Buf *buf;
|
||||
u16 i;
|
||||
u16 page;
|
||||
uffs_BlockInfo *bc = NULL;
|
||||
uffs_Tags *tag;
|
||||
uffs_Tags newTag;
|
||||
UBOOL succRecov;
|
||||
UBOOL goodBlockIsDirty = U_FALSE;
|
||||
int ret;
|
||||
int region;
|
||||
u8 type;
|
||||
|
||||
if (dev->bad.block == UFFS_INVALID_BLOCK)
|
||||
return;
|
||||
|
||||
// pick up an erased good block
|
||||
good = uffs_TreeGetErasedNode(dev);
|
||||
if (good == NULL) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "no free block to replace bad block!");
|
||||
return;
|
||||
}
|
||||
|
||||
//recover block
|
||||
bc = uffs_BlockInfoGet(dev, dev->bad.block);
|
||||
|
||||
if (bc == NULL) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "can't get bad block info");
|
||||
return;
|
||||
}
|
||||
|
||||
succRecov = U_TRUE;
|
||||
for (i = 0; i < dev->attr->pages_per_block; i++) {
|
||||
page = uffs_FindPageInBlockWithPageId(dev, bc, i);
|
||||
if(page == UFFS_INVALID_PAGE) {
|
||||
break; //end of last valid page, normal break
|
||||
}
|
||||
page = uffs_FindBestPageInBlock(dev, bc, page);
|
||||
tag = GET_TAG(bc, page);
|
||||
buf = uffs_BufClone(dev, NULL);
|
||||
if (buf == NULL) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "Can't clone a new buf!");
|
||||
succRecov = U_FALSE;
|
||||
break;
|
||||
}
|
||||
//NOTE: since this is a bad block, we can't guarantee the data is ECC ok, so just load data even ECC is not OK.
|
||||
ret = uffs_LoadPhyDataToBufEccUnCare(dev, buf, bc->block, page);
|
||||
if (ret == U_FAIL) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "I/O error ?");
|
||||
uffs_BufFreeClone(dev, buf);
|
||||
succRecov = U_FALSE;
|
||||
break;
|
||||
}
|
||||
buf->data_len = TAG_DATA_LEN(tag);
|
||||
if (buf->data_len > dev->com.pg_data_size) {
|
||||
uffs_Perror(UFFS_ERR_NOISY, "data length over flow!!!");
|
||||
buf->data_len = dev->com.pg_data_size;
|
||||
}
|
||||
|
||||
buf->parent = TAG_PARENT(tag);
|
||||
buf->serial = TAG_SERIAL(tag);
|
||||
buf->type = TAG_TYPE(tag);
|
||||
buf->page_id = TAG_PAGE_ID(tag);
|
||||
|
||||
newTag = *tag;
|
||||
TAG_BLOCK_TS(&newTag) = uffs_GetNextBlockTimeStamp(TAG_BLOCK_TS(tag));
|
||||
|
||||
ret = uffs_FlashWritePageCombine(dev, good->u.list.block, i, buf, &newTag);
|
||||
|
||||
goodBlockIsDirty = U_TRUE;
|
||||
uffs_BufFreeClone(dev, buf);
|
||||
|
||||
if (ret == UFFS_FLASH_IO_ERR) {
|
||||
uffs_Perror(UFFS_ERR_NORMAL, "I/O error ?");
|
||||
succRecov = U_FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (succRecov == U_TRUE) {
|
||||
//successful recover bad block, so need to mark bad block, and replace with good one
|
||||
|
||||
region = SEARCH_REGION_DIR|SEARCH_REGION_FILE|SEARCH_REGION_DATA;
|
||||
bad = uffs_TreeFindNodeByBlock(dev, dev->bad.block, ®ion);
|
||||
if (bad != NULL) {
|
||||
switch (region) {
|
||||
case SEARCH_REGION_DIR:
|
||||
bad->u.dir.block = good->u.list.block;
|
||||
type = UFFS_TYPE_DIR;
|
||||
break;
|
||||
case SEARCH_REGION_FILE:
|
||||
bad->u.file.block = good->u.list.block;
|
||||
type = UFFS_TYPE_FILE;
|
||||
break;
|
||||
case SEARCH_REGION_DATA:
|
||||
bad->u.data.block = good->u.list.block;
|
||||
type = UFFS_TYPE_DATA;
|
||||
}
|
||||
|
||||
//from now, the 'bad' is actually good block :)))
|
||||
uffs_Perror(UFFS_ERR_NOISY, "new bad block %d found, and replaced by %d!", dev->bad.block, good->u.list.block);
|
||||
uffs_BlockInfoExpire(dev, bc, UFFS_ALL_PAGES);
|
||||
//we reuse the 'good' node as bad block node, and process the bad block.
|
||||
good->u.list.block = dev->bad.block;
|
||||
uffs_BadBlockProcess(dev, good);
|
||||
}
|
||||
else {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "can't find the reported bad block(%d) in the tree???", dev->bad.block);
|
||||
if (goodBlockIsDirty == U_TRUE)
|
||||
dev->ops->EraseBlock(dev, good->u.list.block);
|
||||
uffs_TreeInsertToErasedListTail(dev, good);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (goodBlockIsDirty == U_TRUE)
|
||||
dev->ops->EraseBlock(dev, good->u.list.block);
|
||||
uffs_TreeInsertToErasedListTail(dev, good); //put back to erased list
|
||||
}
|
||||
type = type;
|
||||
uffs_BlockInfoPut(dev, bc);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** put a new block to the bad block waiting list */
|
||||
void uffs_BadBlockAdd(uffs_Device *dev, int block)
|
||||
{
|
||||
if (dev->bad.block == block)
|
||||
return;
|
||||
|
||||
if (dev->bad.block != UFFS_INVALID_BLOCK)
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "Can't add more then one bad block !");
|
||||
else
|
||||
dev->bad.block = block;
|
||||
}
|
||||
|
||||
/** put a new block to the bad block waiting list */
|
||||
void uffs_BadBlockAdd(uffs_Device *dev, int block)
|
||||
{
|
||||
if (dev->bad.block == block)
|
||||
return;
|
||||
|
||||
if (dev->bad.block != UFFS_INVALID_BLOCK)
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "Can't add more then one bad block !");
|
||||
else
|
||||
dev->bad.block = block;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,144 +1,144 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_debug.c
|
||||
* \brief output debug messages
|
||||
* \author Ricky Zheng, created 10th May, 2005
|
||||
*/
|
||||
#include "uffs/uffs_public.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#if !defined(_UBASE_)
|
||||
#define ENABLE_DEBUG
|
||||
//#define OUTPUT_TOFILE
|
||||
#endif
|
||||
|
||||
#if !defined(_UBASE_)
|
||||
|
||||
|
||||
#ifdef OUTPUT_TOFILE
|
||||
#define DEBUG_LOGFILE "log.txt"
|
||||
#endif
|
||||
|
||||
void uffs_DebugMessage(int level, const char *prefix, const char *suffix, const char *errFmt, ...)
|
||||
{
|
||||
|
||||
#ifdef ENABLE_DEBUG
|
||||
if (level >= UFFS_DBG_LEVEL) {
|
||||
|
||||
char buf[1024] = {0};
|
||||
char *p;
|
||||
|
||||
|
||||
#ifdef OUTPUT_TOFILE
|
||||
FILE *fp = NULL;
|
||||
#endif
|
||||
|
||||
va_list arg;
|
||||
|
||||
if (strlen(errFmt) > 800) {
|
||||
// dangerous!!
|
||||
printf("uffs_Perror buffer is not enough !");
|
||||
return;
|
||||
}
|
||||
|
||||
p = buf;
|
||||
|
||||
if (prefix) {
|
||||
strcpy(p, prefix);
|
||||
p += strlen(prefix);
|
||||
}
|
||||
|
||||
va_start(arg, errFmt);
|
||||
vsprintf(p, errFmt, arg);
|
||||
va_end(arg);
|
||||
|
||||
if (suffix)
|
||||
strcat(p, suffix);
|
||||
|
||||
#ifdef OUTPUT_TOFILE
|
||||
fp = fopen(DEBUG_LOGFILE, "a+b");
|
||||
if (fp) {
|
||||
fwrite(buf, 1, strlen(buf), fp);
|
||||
fclose(fp);
|
||||
}
|
||||
#else
|
||||
printf("%s", buf);
|
||||
#endif
|
||||
}
|
||||
#endif //ENABLE_DEBUG
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define ENABLE_DEBUG
|
||||
|
||||
#include <uBase.h>
|
||||
#include <sys/debug.h>
|
||||
|
||||
|
||||
void uffs_Perror( int level, const char *errFmt, ...)
|
||||
{
|
||||
#ifdef ENABLE_DEBUG
|
||||
va_list args;
|
||||
if (level >= UFFS_DBG_LEVEL) {
|
||||
va_start(args, errFmt);
|
||||
//uffs_vTrace(errFmt, args);
|
||||
dbg_simple_vprintf(errFmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
dbg_simple_raw(TENDSTR);
|
||||
#else
|
||||
level = level;
|
||||
errFmt = errFmt;
|
||||
#endif //ENABLE_DEBUG
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Called when an assert occurred.
|
||||
* This method is called when an assert occurred and should stop the
|
||||
* application from running, as this there is a severe error condition.
|
||||
* \param[in] file Source filename
|
||||
* \param[in] line Source line of code
|
||||
* \param[in] msg Assert message
|
||||
*/
|
||||
void uffs_AssertCall(const char *file, int line, const char *msg)
|
||||
{
|
||||
printf("ASSERT %s:%d - msg:%s\n", file, line, msg);
|
||||
while (1);
|
||||
}
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_debug.c
|
||||
* \brief output debug messages
|
||||
* \author Ricky Zheng, created 10th May, 2005
|
||||
*/
|
||||
#include "uffs/uffs_public.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#if !defined(_UBASE_)
|
||||
#define ENABLE_DEBUG
|
||||
//#define OUTPUT_TOFILE
|
||||
#endif
|
||||
|
||||
#if !defined(_UBASE_)
|
||||
|
||||
|
||||
#ifdef OUTPUT_TOFILE
|
||||
#define DEBUG_LOGFILE "log.txt"
|
||||
#endif
|
||||
|
||||
void uffs_DebugMessage(int level, const char *prefix, const char *suffix, const char *errFmt, ...)
|
||||
{
|
||||
|
||||
#ifdef ENABLE_DEBUG
|
||||
if (level >= UFFS_DBG_LEVEL) {
|
||||
|
||||
char buf[1024] = {0};
|
||||
char *p;
|
||||
|
||||
|
||||
#ifdef OUTPUT_TOFILE
|
||||
FILE *fp = NULL;
|
||||
#endif
|
||||
|
||||
va_list arg;
|
||||
|
||||
if (strlen(errFmt) > 800) {
|
||||
// dangerous!!
|
||||
rt_kprintf("uffs_Perror buffer is not enough !");
|
||||
return;
|
||||
}
|
||||
|
||||
p = buf;
|
||||
|
||||
if (prefix) {
|
||||
strcpy(p, prefix);
|
||||
p += strlen(prefix);
|
||||
}
|
||||
|
||||
va_start(arg, errFmt);
|
||||
vsprintf(p, errFmt, arg);
|
||||
va_end(arg);
|
||||
|
||||
if (suffix)
|
||||
strcat(p, suffix);
|
||||
|
||||
#ifdef OUTPUT_TOFILE
|
||||
fp = fopen(DEBUG_LOGFILE, "a+b");
|
||||
if (fp) {
|
||||
fwrite(buf, 1, strlen(buf), fp);
|
||||
fclose(fp);
|
||||
}
|
||||
#else
|
||||
rt_kprintf("%s", buf);
|
||||
#endif
|
||||
}
|
||||
#endif //ENABLE_DEBUG
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define ENABLE_DEBUG
|
||||
|
||||
#include <uBase.h>
|
||||
#include <sys/debug.h>
|
||||
|
||||
|
||||
void uffs_Perror( int level, const char *errFmt, ...)
|
||||
{
|
||||
#ifdef ENABLE_DEBUG
|
||||
va_list args;
|
||||
if (level >= UFFS_DBG_LEVEL) {
|
||||
va_start(args, errFmt);
|
||||
//uffs_vTrace(errFmt, args);
|
||||
dbg_simple_vprintf(errFmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
dbg_simple_raw(TENDSTR);
|
||||
#else
|
||||
level = level;
|
||||
errFmt = errFmt;
|
||||
#endif //ENABLE_DEBUG
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Called when an assert occurred.
|
||||
* This method is called when an assert occurred and should stop the
|
||||
* application from running, as this there is a severe error condition.
|
||||
* \param[in] file Source filename
|
||||
* \param[in] line Source line of code
|
||||
* \param[in] msg Assert message
|
||||
*/
|
||||
void uffs_AssertCall(const char *file, int line, const char *msg)
|
||||
{
|
||||
rt_kprintf("ASSERT %s:%d - msg:%s\n", file, line, msg);
|
||||
while (1);
|
||||
}
|
||||
|
||||
@@ -1,94 +1,94 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_device.c
|
||||
* \brief uffs device operation
|
||||
* \author Ricky Zheng, created 10th May, 2005
|
||||
*/
|
||||
#include "uffs/uffs_device.h"
|
||||
#include "uffs/uffs_os.h"
|
||||
#include "uffs/uffs_public.h"
|
||||
#include "uffs/uffs_mtb.h"
|
||||
#include <string.h>
|
||||
|
||||
#define PFX "dev: "
|
||||
|
||||
|
||||
|
||||
URET uffs_DeviceInitLock(uffs_Device *dev)
|
||||
{
|
||||
dev->lock.sem = uffs_SemCreate(1);
|
||||
dev->lock.task_id = UFFS_TASK_ID_NOT_EXIST;
|
||||
dev->lock.counter = 0;
|
||||
|
||||
return U_SUCC;
|
||||
}
|
||||
|
||||
URET uffs_DeviceReleaseLock(uffs_Device *dev)
|
||||
{
|
||||
if (dev->lock.sem) {
|
||||
uffs_SemDelete(dev->lock.sem);
|
||||
dev->lock.sem = 0;
|
||||
}
|
||||
|
||||
return U_SUCC;
|
||||
}
|
||||
|
||||
URET uffs_DeviceLock(uffs_Device *dev)
|
||||
{
|
||||
|
||||
uffs_SemWait(dev->lock.sem);
|
||||
|
||||
if (dev->lock.counter != 0) {
|
||||
uffs_Perror(UFFS_ERR_NORMAL, "Lock device, counter %d NOT zero?!", dev->lock.counter);
|
||||
}
|
||||
|
||||
dev->lock.counter++;
|
||||
|
||||
return U_SUCC;
|
||||
}
|
||||
|
||||
URET uffs_DeviceUnLock(uffs_Device *dev)
|
||||
{
|
||||
|
||||
dev->lock.counter--;
|
||||
|
||||
if (dev->lock.counter != 0) {
|
||||
uffs_Perror(UFFS_ERR_NORMAL, "Unlock device, counter %d NOT zero?!", dev->lock.counter);
|
||||
}
|
||||
|
||||
uffs_SemSignal(dev->lock.sem);
|
||||
|
||||
return U_SUCC;
|
||||
}
|
||||
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_device.c
|
||||
* \brief uffs device operation
|
||||
* \author Ricky Zheng, created 10th May, 2005
|
||||
*/
|
||||
#include "uffs/uffs_device.h"
|
||||
#include "uffs/uffs_os.h"
|
||||
#include "uffs/uffs_public.h"
|
||||
#include "uffs/uffs_mtb.h"
|
||||
#include <string.h>
|
||||
|
||||
#define PFX "dev: "
|
||||
|
||||
|
||||
|
||||
URET uffs_DeviceInitLock(uffs_Device *dev)
|
||||
{
|
||||
dev->lock.sem = uffs_SemCreate(1);
|
||||
dev->lock.task_id = UFFS_TASK_ID_NOT_EXIST;
|
||||
dev->lock.counter = 0;
|
||||
|
||||
return U_SUCC;
|
||||
}
|
||||
|
||||
URET uffs_DeviceReleaseLock(uffs_Device *dev)
|
||||
{
|
||||
if (dev->lock.sem) {
|
||||
uffs_SemDelete(dev->lock.sem);
|
||||
dev->lock.sem = 0;
|
||||
}
|
||||
|
||||
return U_SUCC;
|
||||
}
|
||||
|
||||
URET uffs_DeviceLock(uffs_Device *dev)
|
||||
{
|
||||
|
||||
uffs_SemWait(dev->lock.sem);
|
||||
|
||||
if (dev->lock.counter != 0) {
|
||||
uffs_Perror(UFFS_ERR_NORMAL, "Lock device, counter %d NOT zero?!", dev->lock.counter);
|
||||
}
|
||||
|
||||
dev->lock.counter++;
|
||||
|
||||
return U_SUCC;
|
||||
}
|
||||
|
||||
URET uffs_DeviceUnLock(uffs_Device *dev)
|
||||
{
|
||||
|
||||
dev->lock.counter--;
|
||||
|
||||
if (dev->lock.counter != 0) {
|
||||
uffs_Perror(UFFS_ERR_NORMAL, "Unlock device, counter %d NOT zero?!", dev->lock.counter);
|
||||
}
|
||||
|
||||
uffs_SemSignal(dev->lock.sem);
|
||||
|
||||
return U_SUCC;
|
||||
}
|
||||
|
||||
|
||||
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
@@ -1,144 +1,144 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_init.c
|
||||
* \brief initialize uffs file system device
|
||||
* \author Ricky Zheng, created 12th May, 2005
|
||||
*/
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_public.h"
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_tree.h"
|
||||
#include "uffs/uffs_fs.h"
|
||||
#include "uffs/uffs_badblock.h"
|
||||
#include <string.h>
|
||||
|
||||
#define PFX "init: "
|
||||
|
||||
URET uffs_InitDevice(uffs_Device *dev)
|
||||
{
|
||||
URET ret;
|
||||
|
||||
if (dev->mem.init) {
|
||||
if (dev->mem.init(dev) != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "Init memory allocator fail.");
|
||||
return U_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
memset(&(dev->st), 0, sizeof(uffs_FlashStat));
|
||||
|
||||
uffs_DeviceInitLock(dev);
|
||||
uffs_BadBlockInit(dev);
|
||||
|
||||
if (uffs_FlashInterfaceInit(dev) != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "Can't initialize flash interface !");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
uffs_Perror(UFFS_ERR_NOISY, "init page buf");
|
||||
ret = uffs_BufInit(dev, MAX_PAGE_BUFFERS, MAX_DIRTY_PAGES_IN_A_BLOCK);
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_DEAD, "Initialize page buffers fail");
|
||||
goto fail;
|
||||
}
|
||||
uffs_Perror(UFFS_ERR_NOISY, "init block info cache");
|
||||
ret = uffs_BlockInfoInitCache(dev, MAX_CACHED_BLOCK_INFO);
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_DEAD, "Initialize block info fail");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = uffs_TreeInit(dev);
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "fail to init tree buffers");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = uffs_BuildTree(dev);
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "fail to build tree");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return U_SUCC;
|
||||
|
||||
fail:
|
||||
uffs_DeviceReleaseLock(dev);
|
||||
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
URET uffs_ReleaseDevice(uffs_Device *dev)
|
||||
{
|
||||
URET ret;
|
||||
|
||||
ret = uffs_BlockInfoReleaseCache(dev);
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "fail to release block info.");
|
||||
goto ext;
|
||||
}
|
||||
|
||||
ret = uffs_BufReleaseAll(dev);
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "fail to release page buffers");
|
||||
goto ext;
|
||||
}
|
||||
|
||||
ret = uffs_TreeRelease(dev);
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "fail to release tree buffers!");
|
||||
goto ext;
|
||||
}
|
||||
|
||||
ret = uffs_FlashInterfaceRelease(dev);
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "fail to release tree buffers!");
|
||||
goto ext;
|
||||
}
|
||||
|
||||
if (dev->mem.release)
|
||||
ret = dev->mem.release(dev);
|
||||
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "fail to release memory allocator!");
|
||||
}
|
||||
|
||||
uffs_DeviceReleaseLock(dev);
|
||||
|
||||
ext:
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_init.c
|
||||
* \brief initialize uffs file system device
|
||||
* \author Ricky Zheng, created 12th May, 2005
|
||||
*/
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_public.h"
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_tree.h"
|
||||
#include "uffs/uffs_fs.h"
|
||||
#include "uffs/uffs_badblock.h"
|
||||
#include <string.h>
|
||||
|
||||
#define PFX "init: "
|
||||
|
||||
URET uffs_InitDevice(uffs_Device *dev)
|
||||
{
|
||||
URET ret;
|
||||
|
||||
if (dev->mem.init) {
|
||||
if (dev->mem.init(dev) != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "Init memory allocator fail.");
|
||||
return U_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
memset(&(dev->st), 0, sizeof(uffs_FlashStat));
|
||||
|
||||
uffs_DeviceInitLock(dev);
|
||||
uffs_BadBlockInit(dev);
|
||||
|
||||
if (uffs_FlashInterfaceInit(dev) != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "Can't initialize flash interface !");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
uffs_Perror(UFFS_ERR_NOISY, "init page buf");
|
||||
ret = uffs_BufInit(dev, MAX_PAGE_BUFFERS, MAX_DIRTY_PAGES_IN_A_BLOCK);
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_DEAD, "Initialize page buffers fail");
|
||||
goto fail;
|
||||
}
|
||||
uffs_Perror(UFFS_ERR_NOISY, "init block info cache");
|
||||
ret = uffs_BlockInfoInitCache(dev, MAX_CACHED_BLOCK_INFO);
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_DEAD, "Initialize block info fail");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = uffs_TreeInit(dev);
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "fail to init tree buffers");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = uffs_BuildTree(dev);
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "fail to build tree");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return U_SUCC;
|
||||
|
||||
fail:
|
||||
uffs_DeviceReleaseLock(dev);
|
||||
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
URET uffs_ReleaseDevice(uffs_Device *dev)
|
||||
{
|
||||
URET ret;
|
||||
|
||||
ret = uffs_BlockInfoReleaseCache(dev);
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "fail to release block info.");
|
||||
goto ext;
|
||||
}
|
||||
|
||||
ret = uffs_BufReleaseAll(dev);
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "fail to release page buffers");
|
||||
goto ext;
|
||||
}
|
||||
|
||||
ret = uffs_TreeRelease(dev);
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "fail to release tree buffers!");
|
||||
goto ext;
|
||||
}
|
||||
|
||||
ret = uffs_FlashInterfaceRelease(dev);
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "fail to release tree buffers!");
|
||||
goto ext;
|
||||
}
|
||||
|
||||
if (dev->mem.release)
|
||||
ret = dev->mem.release(dev);
|
||||
|
||||
if (ret != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "fail to release memory allocator!");
|
||||
}
|
||||
|
||||
uffs_DeviceReleaseLock(dev);
|
||||
|
||||
ext:
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,247 +1,250 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_mtb.c
|
||||
* \brief mount table operations
|
||||
* \author Ricky Zheng, created 11th July, 2009
|
||||
*/
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_public.h"
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_tree.h"
|
||||
#include "uffs/uffs_mtb.h"
|
||||
#include "uffs/uffs_fd.h"
|
||||
#include <string.h>
|
||||
|
||||
#define PFX "mtb: "
|
||||
|
||||
static struct uffs_MountTableEntrySt *g_mtb_head = NULL;
|
||||
|
||||
uffs_MountTable * uffs_GetMountTable(void)
|
||||
{
|
||||
return g_mtb_head;
|
||||
}
|
||||
|
||||
int uffs_RegisterMountTable(uffs_MountTable *mtab)
|
||||
{
|
||||
uffs_MountTable *work = g_mtb_head;
|
||||
|
||||
if (mtab == NULL)
|
||||
return -1;
|
||||
|
||||
if (work == NULL) {
|
||||
g_mtb_head = mtab;
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (work) {
|
||||
if (mtab == work) {
|
||||
/* already registered */
|
||||
return 0;
|
||||
}
|
||||
if (work->next == NULL) {
|
||||
work->next = mtab;
|
||||
mtab->next = NULL;
|
||||
return 0;
|
||||
}
|
||||
work = work->next;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
URET uffs_InitMountTable(void)
|
||||
{
|
||||
struct uffs_MountTableEntrySt *tbl = uffs_GetMountTable();
|
||||
struct uffs_MountTableEntrySt *work;
|
||||
int dev_num = 0;
|
||||
|
||||
for (work = tbl; work; work = work->next) {
|
||||
uffs_Perror(UFFS_ERR_NOISY, "init device for mount point %s ...", work->mount);
|
||||
if (work->dev->Init(work->dev) == U_FAIL) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "init device for mount point %s fail", work->mount);
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
work->dev->par.start = work->start_block;
|
||||
if (work->end_block < 0) {
|
||||
work->dev->par.end = work->dev->attr->total_blocks + work->end_block;
|
||||
}
|
||||
else {
|
||||
work->dev->par.end = work->end_block;
|
||||
}
|
||||
uffs_Perror(UFFS_ERR_NOISY, "mount partiton: %d,%d",
|
||||
work->dev->par.start, work->dev->par.end);
|
||||
|
||||
if (uffs_InitDevice(work->dev) != U_SUCC) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "init device fail !");
|
||||
return U_FAIL;
|
||||
}
|
||||
work->dev->dev_num = dev_num++;
|
||||
}
|
||||
|
||||
if (uffs_InitObjectBuf() == U_SUCC) {
|
||||
if (uffs_InitDirEntryBuf() == U_SUCC) {
|
||||
return U_SUCC;
|
||||
}
|
||||
}
|
||||
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
URET uffs_ReleaseMountTable(void)
|
||||
{
|
||||
struct uffs_MountTableEntrySt *tbl = uffs_GetMountTable();
|
||||
struct uffs_MountTableEntrySt *work;
|
||||
|
||||
for (work = tbl; work; work = work->next) {
|
||||
uffs_ReleaseDevice(work->dev);
|
||||
work->dev->Release(work->dev);
|
||||
}
|
||||
|
||||
if (uffs_ReleaseObjectBuf() == U_SUCC) {
|
||||
if (uffs_ReleaseDirEntryBuf() == U_SUCC) {
|
||||
return U_SUCC;
|
||||
}
|
||||
}
|
||||
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* find the matched mount point from a given full absolute path.
|
||||
*
|
||||
* \param[in] path full path
|
||||
* \return the length of mount point.
|
||||
*/
|
||||
int uffs_GetMatchedMountPointSize(const char *path)
|
||||
{
|
||||
int pos;
|
||||
uffs_Device *dev;
|
||||
|
||||
if (path[0] != '/')
|
||||
return 0;
|
||||
|
||||
pos = strlen(path);
|
||||
|
||||
while (pos > 0) {
|
||||
if ((dev = uffs_GetDeviceFromMountPointEx(path, pos)) != NULL ) {
|
||||
uffs_PutDevice(dev);
|
||||
return pos;
|
||||
}
|
||||
else {
|
||||
if (path[pos-1] == '/')
|
||||
pos--;
|
||||
//back forward search the next '/'
|
||||
for (; pos > 0 && path[pos-1] != '/'; pos--)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* get device from mount point.
|
||||
*
|
||||
* \param[in] mount mount point name.
|
||||
* \return NULL if mount point is not found.
|
||||
*/
|
||||
uffs_Device * uffs_GetDeviceFromMountPoint(const char *mount)
|
||||
{
|
||||
struct uffs_MountTableEntrySt *devTab = uffs_GetMountTable();
|
||||
|
||||
while (devTab) {
|
||||
if (strcmp(mount, devTab->mount) == 0) {
|
||||
devTab->dev->ref_count++;
|
||||
return devTab->dev;
|
||||
}
|
||||
devTab = devTab->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* get device from mount point.
|
||||
*
|
||||
* \param[in] mount mount point name.
|
||||
* \param[in] len mount point name length.
|
||||
* \return NULL if mount point is not found.
|
||||
*/
|
||||
uffs_Device * uffs_GetDeviceFromMountPointEx(const char *mount, int len)
|
||||
{
|
||||
struct uffs_MountTableEntrySt *devTab = uffs_GetMountTable();
|
||||
|
||||
while (devTab) {
|
||||
if (strlen(devTab->mount) == len && strncmp(mount, devTab->mount, len) == 0) {
|
||||
devTab->dev->ref_count++;
|
||||
return devTab->dev;
|
||||
}
|
||||
devTab = devTab->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return mount point from device
|
||||
*
|
||||
* \param[in] dev uffs device
|
||||
* \return NULL if mount point is not found, otherwise return mount point name in mount table.
|
||||
*/
|
||||
const char * uffs_GetDeviceMountPoint(uffs_Device *dev)
|
||||
{
|
||||
struct uffs_MountTableEntrySt * devTab = uffs_GetMountTable();
|
||||
|
||||
while (devTab) {
|
||||
if (devTab->dev == dev) {
|
||||
return devTab->mount;
|
||||
}
|
||||
devTab = devTab->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void uffs_PutDevice(uffs_Device *dev)
|
||||
{
|
||||
dev->ref_count--;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_mtb.c
|
||||
* \brief mount table operations
|
||||
* \author Ricky Zheng, created 11th July, 2009
|
||||
*/
|
||||
|
||||
#include "uffs/uffs_types.h"
|
||||
#include "uffs/uffs_public.h"
|
||||
#include "uffs/uffs_config.h"
|
||||
#include "uffs/uffs_tree.h"
|
||||
#include "uffs/uffs_mtb.h"
|
||||
#include "uffs/uffs_fd.h"
|
||||
#include <string.h>
|
||||
|
||||
#define PFX "mtb: "
|
||||
|
||||
static struct uffs_MountTableEntrySt *g_mtb_head = NULL;
|
||||
|
||||
uffs_MountTable * uffs_GetMountTable(void)
|
||||
{
|
||||
return g_mtb_head;
|
||||
}
|
||||
|
||||
int uffs_RegisterMountTable(uffs_MountTable *mtab)
|
||||
{
|
||||
uffs_MountTable *work = g_mtb_head;
|
||||
|
||||
if (mtab == NULL)
|
||||
return -1;
|
||||
|
||||
if (work == NULL) {
|
||||
g_mtb_head = mtab;
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (work) {
|
||||
if (mtab == work) {
|
||||
/* already registered */
|
||||
return 0;
|
||||
}
|
||||
if (work->next == NULL) {
|
||||
work->next = mtab;
|
||||
mtab->next = NULL;
|
||||
return 0;
|
||||
}
|
||||
work = work->next;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
URET uffs_InitMountTable(void)
|
||||
{
|
||||
struct uffs_MountTableEntrySt *tbl = uffs_GetMountTable();
|
||||
struct uffs_MountTableEntrySt *work;
|
||||
int dev_num = 0;
|
||||
|
||||
for (work = tbl; work; work = work->next) {
|
||||
uffs_Perror(UFFS_ERR_NOISY, "init device for mount point %s ...", work->mount);
|
||||
if (work->dev->Init(work->dev) == U_FAIL) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "init device for mount point %s fail", work->mount);
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
work->dev->par.start = work->start_block;
|
||||
if (work->end_block < 0)
|
||||
{
|
||||
work->dev->par.end = work->dev->attr->total_blocks + work->end_block;
|
||||
}
|
||||
else
|
||||
{
|
||||
work->dev->par.end = work->end_block;
|
||||
}
|
||||
uffs_Perror(UFFS_ERR_NOISY, "mount partiton: %d,%d",
|
||||
work->dev->par.start, work->dev->par.end);
|
||||
|
||||
if (uffs_InitDevice(work->dev) != U_SUCC)
|
||||
{
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "init device fail !");
|
||||
return U_FAIL;
|
||||
}
|
||||
work->dev->dev_num = dev_num++;
|
||||
}
|
||||
|
||||
if (uffs_InitObjectBuf() == U_SUCC) {
|
||||
if (uffs_InitDirEntryBuf() == U_SUCC) {
|
||||
return U_SUCC;
|
||||
}
|
||||
}
|
||||
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
URET uffs_ReleaseMountTable(void)
|
||||
{
|
||||
struct uffs_MountTableEntrySt *tbl = uffs_GetMountTable();
|
||||
struct uffs_MountTableEntrySt *work;
|
||||
|
||||
for (work = tbl; work; work = work->next) {
|
||||
uffs_ReleaseDevice(work->dev);
|
||||
work->dev->Release(work->dev);
|
||||
}
|
||||
|
||||
if (uffs_ReleaseObjectBuf() == U_SUCC) {
|
||||
if (uffs_ReleaseDirEntryBuf() == U_SUCC) {
|
||||
return U_SUCC;
|
||||
}
|
||||
}
|
||||
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* find the matched mount point from a given full absolute path.
|
||||
*
|
||||
* \param[in] path full path
|
||||
* \return the length of mount point.
|
||||
*/
|
||||
int uffs_GetMatchedMountPointSize(const char *path)
|
||||
{
|
||||
int pos;
|
||||
uffs_Device *dev;
|
||||
|
||||
if (path[0] != '/')
|
||||
return 0;
|
||||
|
||||
pos = strlen(path);
|
||||
|
||||
while (pos > 0) {
|
||||
if ((dev = uffs_GetDeviceFromMountPointEx(path, pos)) != NULL ) {
|
||||
uffs_PutDevice(dev);
|
||||
return pos;
|
||||
}
|
||||
else {
|
||||
if (path[pos-1] == '/')
|
||||
pos--;
|
||||
//back forward search the next '/'
|
||||
for (; pos > 0 && path[pos-1] != '/'; pos--)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* get device from mount point.
|
||||
*
|
||||
* \param[in] mount mount point name.
|
||||
* \return NULL if mount point is not found.
|
||||
*/
|
||||
uffs_Device * uffs_GetDeviceFromMountPoint(const char *mount)
|
||||
{
|
||||
struct uffs_MountTableEntrySt *devTab = uffs_GetMountTable();
|
||||
|
||||
while (devTab) {
|
||||
if (strcmp(mount, devTab->mount) == 0) {
|
||||
devTab->dev->ref_count++;
|
||||
return devTab->dev;
|
||||
}
|
||||
devTab = devTab->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* get device from mount point.
|
||||
*
|
||||
* \param[in] mount mount point name.
|
||||
* \param[in] len mount point name length.
|
||||
* \return NULL if mount point is not found.
|
||||
*/
|
||||
uffs_Device * uffs_GetDeviceFromMountPointEx(const char *mount, int len)
|
||||
{
|
||||
struct uffs_MountTableEntrySt *devTab = uffs_GetMountTable();
|
||||
|
||||
while (devTab) {
|
||||
if (strlen(devTab->mount) == len && strncmp(mount, devTab->mount, len) == 0) {
|
||||
devTab->dev->ref_count++;
|
||||
return devTab->dev;
|
||||
}
|
||||
devTab = devTab->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return mount point from device
|
||||
*
|
||||
* \param[in] dev uffs device
|
||||
* \return NULL if mount point is not found, otherwise return mount point name in mount table.
|
||||
*/
|
||||
const char * uffs_GetDeviceMountPoint(uffs_Device *dev)
|
||||
{
|
||||
struct uffs_MountTableEntrySt * devTab = uffs_GetMountTable();
|
||||
|
||||
while (devTab) {
|
||||
if (devTab->dev == dev) {
|
||||
return devTab->mount;
|
||||
}
|
||||
devTab = devTab->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void uffs_PutDevice(uffs_Device *dev)
|
||||
{
|
||||
dev->ref_count--;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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
@@ -1,195 +1,195 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_utils.c
|
||||
* \brief utilities of uffs
|
||||
* \author Ricky Zheng, created 12th May, 2005
|
||||
*/
|
||||
#include "uffs/uffs_device.h"
|
||||
#include "uffs/uffs_utils.h"
|
||||
#include "uffs/uffs_os.h"
|
||||
#include "uffs/uffs_public.h"
|
||||
#include "uffs/uffs_version.h"
|
||||
#include "uffs/uffs_badblock.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define PFX "util: "
|
||||
|
||||
#ifdef CONFIG_ENABLE_BAD_BLOCK_VERIFY
|
||||
static void _ForceFormatAndCheckBlock(uffs_Device *dev, int block)
|
||||
{
|
||||
u8 *pageBuf;
|
||||
int pageSize;
|
||||
int i, j;
|
||||
uffs_Buf *buf;
|
||||
UBOOL bad = U_TRUE;
|
||||
int ret;
|
||||
|
||||
buf = uffs_BufClone(dev, NULL);
|
||||
if (buf == NULL) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "Alloc page buffer fail ! Format stoped.");
|
||||
goto ext;
|
||||
}
|
||||
|
||||
pageSize = dev->com.pg_data_size;
|
||||
pageBuf = buf->data;
|
||||
|
||||
|
||||
//step 1: Erase, fully fill with 0x0, and check
|
||||
ret = dev->ops->EraseBlock(dev, block);
|
||||
if (UFFS_FLASH_IS_BAD_BLOCK(ret))
|
||||
goto bad_out;
|
||||
|
||||
memset(pageBuf, 0, pageSize);
|
||||
for (i = 0; i < dev->attr->pages_per_block; i++) {
|
||||
ret = dev->ops->WritePageData(dev, block, i, pageBuf, pageSize, NULL);
|
||||
if (UFFS_FLASH_IS_BAD_BLOCK(ret))
|
||||
goto bad_out;
|
||||
ret = dev->ops->WritePageSpare(dev, block, i, pageBuf, 0, dev->attr->spare_size, U_TRUE);
|
||||
if (UFFS_FLASH_IS_BAD_BLOCK(ret))
|
||||
goto bad_out;
|
||||
}
|
||||
for (i = 0; i < dev->attr->pages_per_block; i++) {
|
||||
memset(pageBuf, 0xFF, pageSize);
|
||||
dev->ops->ReadPageData(dev, block, i, pageBuf, pageSize, NULL);
|
||||
for (j = 0; j < pageSize; j++) {
|
||||
if(pageBuf[j] != 0)
|
||||
goto bad_out;
|
||||
}
|
||||
memset(pageBuf, 0xFF, dev->attr->spare_size);
|
||||
dev->ops->ReadPageSpare(dev, block, i, pageBuf, 0, dev->attr->spare_size);
|
||||
for (j = 0; j < dev->attr->spare_size; j++) {
|
||||
if(pageBuf[j] != 0)
|
||||
goto bad_out;
|
||||
}
|
||||
}
|
||||
|
||||
//step 2: Erase, and check
|
||||
ret = dev->ops->EraseBlock(dev, block);
|
||||
if (UFFS_FLASH_IS_BAD_BLOCK(ret))
|
||||
goto bad_out;
|
||||
|
||||
for (i = 0; i < dev->attr->pages_per_block; i++) {
|
||||
memset(pageBuf, 0, pageSize);
|
||||
dev->ops->ReadPageData(dev, block, i, pageBuf, pageSize, NULL);
|
||||
for (j = 0; j < pageSize; j++) {
|
||||
if(pageBuf[j] != 0xFF)
|
||||
goto bad_out;
|
||||
}
|
||||
memset(pageBuf, 0, dev->attr->spare_size);
|
||||
dev->ops->ReadPageSpare(dev, block, i, pageBuf, 0, dev->attr->spare_size);
|
||||
for (j = 0; j < dev->attr->spare_size; j++) {
|
||||
if(pageBuf[j] != 0xFF)
|
||||
goto bad_out;
|
||||
}
|
||||
}
|
||||
|
||||
// format succ
|
||||
bad = U_FALSE;
|
||||
|
||||
bad_out:
|
||||
if (bad == U_TRUE)
|
||||
uffs_FlashMarkBadBlock(dev, block);
|
||||
ext:
|
||||
if (buf)
|
||||
uffs_BufFreeClone(dev, buf);
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
URET uffs_FormatDevice(uffs_Device *dev)
|
||||
{
|
||||
u16 i, slot;
|
||||
|
||||
if (dev == NULL)
|
||||
return U_FAIL;
|
||||
|
||||
if (dev->ops == NULL)
|
||||
return U_FAIL;
|
||||
|
||||
|
||||
if (uffs_BufIsAllFree(dev) == U_FALSE) {
|
||||
uffs_Perror(UFFS_ERR_NORMAL, "some page still in used!");
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
for (slot = 0; slot < MAX_DIRTY_BUF_GROUPS; slot++) {
|
||||
if (dev->buf.dirtyGroup[slot].count > 0) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "there still have dirty pages!");
|
||||
return U_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
uffs_BufSetAllEmpty(dev);
|
||||
|
||||
|
||||
if (uffs_BlockInfoIsAllFree(dev) == U_FALSE) {
|
||||
uffs_Perror(UFFS_ERR_NORMAL, "there still have block info cache ? fail to format");
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
uffs_BlockInfoExpireAll(dev);
|
||||
|
||||
for (i = dev->par.start; i <= dev->par.end; i++) {
|
||||
if (uffs_FlashIsBadBlock(dev, i) == U_FALSE) {
|
||||
uffs_FlashEraseBlock(dev, i);
|
||||
if (HAVE_BADBLOCK(dev))
|
||||
uffs_BadBlockProcess(dev, NULL);
|
||||
}
|
||||
else {
|
||||
#ifdef CONFIG_ENABLE_BAD_BLOCK_VERIFY
|
||||
_ForceFormatAndCheckBlock(dev, i);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (uffs_TreeRelease(dev) == U_FAIL) {
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
if (uffs_TreeInit(dev) == U_FAIL) {
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
if (uffs_BuildTree(dev) == U_FAIL) {
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
return U_SUCC;
|
||||
}
|
||||
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_utils.c
|
||||
* \brief utilities of uffs
|
||||
* \author Ricky Zheng, created 12th May, 2005
|
||||
*/
|
||||
#include "uffs/uffs_device.h"
|
||||
#include "uffs/uffs_utils.h"
|
||||
#include "uffs/uffs_os.h"
|
||||
#include "uffs/uffs_public.h"
|
||||
#include "uffs/uffs_version.h"
|
||||
#include "uffs/uffs_badblock.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define PFX "util: "
|
||||
|
||||
#ifdef CONFIG_ENABLE_BAD_BLOCK_VERIFY
|
||||
static void _ForceFormatAndCheckBlock(uffs_Device *dev, int block)
|
||||
{
|
||||
u8 *pageBuf;
|
||||
int pageSize;
|
||||
int i, j;
|
||||
uffs_Buf *buf;
|
||||
UBOOL bad = U_TRUE;
|
||||
int ret;
|
||||
|
||||
buf = uffs_BufClone(dev, NULL);
|
||||
if (buf == NULL) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "Alloc page buffer fail ! Format stoped.");
|
||||
goto ext;
|
||||
}
|
||||
|
||||
pageSize = dev->com.pg_data_size;
|
||||
pageBuf = buf->data;
|
||||
|
||||
|
||||
//step 1: Erase, fully fill with 0x0, and check
|
||||
ret = dev->ops->EraseBlock(dev, block);
|
||||
if (UFFS_FLASH_IS_BAD_BLOCK(ret))
|
||||
goto bad_out;
|
||||
|
||||
memset(pageBuf, 0, pageSize);
|
||||
for (i = 0; i < dev->attr->pages_per_block; i++) {
|
||||
ret = dev->ops->WritePageData(dev, block, i, pageBuf, pageSize, NULL);
|
||||
if (UFFS_FLASH_IS_BAD_BLOCK(ret))
|
||||
goto bad_out;
|
||||
ret = dev->ops->WritePageSpare(dev, block, i, pageBuf, 0, dev->attr->spare_size, U_TRUE);
|
||||
if (UFFS_FLASH_IS_BAD_BLOCK(ret))
|
||||
goto bad_out;
|
||||
}
|
||||
for (i = 0; i < dev->attr->pages_per_block; i++) {
|
||||
memset(pageBuf, 0xFF, pageSize);
|
||||
dev->ops->ReadPageData(dev, block, i, pageBuf, pageSize, NULL);
|
||||
for (j = 0; j < pageSize; j++) {
|
||||
if(pageBuf[j] != 0)
|
||||
goto bad_out;
|
||||
}
|
||||
memset(pageBuf, 0xFF, dev->attr->spare_size);
|
||||
dev->ops->ReadPageSpare(dev, block, i, pageBuf, 0, dev->attr->spare_size);
|
||||
for (j = 0; j < dev->attr->spare_size; j++) {
|
||||
if(pageBuf[j] != 0)
|
||||
goto bad_out;
|
||||
}
|
||||
}
|
||||
|
||||
//step 2: Erase, and check
|
||||
ret = dev->ops->EraseBlock(dev, block);
|
||||
if (UFFS_FLASH_IS_BAD_BLOCK(ret))
|
||||
goto bad_out;
|
||||
|
||||
for (i = 0; i < dev->attr->pages_per_block; i++) {
|
||||
memset(pageBuf, 0, pageSize);
|
||||
dev->ops->ReadPageData(dev, block, i, pageBuf, pageSize, NULL);
|
||||
for (j = 0; j < pageSize; j++) {
|
||||
if(pageBuf[j] != 0xFF)
|
||||
goto bad_out;
|
||||
}
|
||||
memset(pageBuf, 0, dev->attr->spare_size);
|
||||
dev->ops->ReadPageSpare(dev, block, i, pageBuf, 0, dev->attr->spare_size);
|
||||
for (j = 0; j < dev->attr->spare_size; j++) {
|
||||
if(pageBuf[j] != 0xFF)
|
||||
goto bad_out;
|
||||
}
|
||||
}
|
||||
|
||||
// format succ
|
||||
bad = U_FALSE;
|
||||
|
||||
bad_out:
|
||||
if (bad == U_TRUE)
|
||||
uffs_FlashMarkBadBlock(dev, block);
|
||||
ext:
|
||||
if (buf)
|
||||
uffs_BufFreeClone(dev, buf);
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
URET uffs_FormatDevice(uffs_Device *dev)
|
||||
{
|
||||
u16 i, slot;
|
||||
|
||||
if (dev == NULL)
|
||||
return U_FAIL;
|
||||
|
||||
if (dev->ops == NULL)
|
||||
return U_FAIL;
|
||||
|
||||
|
||||
if (uffs_BufIsAllFree(dev) == U_FALSE) {
|
||||
uffs_Perror(UFFS_ERR_NORMAL, "some page still in used!");
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
for (slot = 0; slot < MAX_DIRTY_BUF_GROUPS; slot++) {
|
||||
if (dev->buf.dirtyGroup[slot].count > 0) {
|
||||
uffs_Perror(UFFS_ERR_SERIOUS, "there still have dirty pages!");
|
||||
return U_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
uffs_BufSetAllEmpty(dev);
|
||||
|
||||
|
||||
if (uffs_BlockInfoIsAllFree(dev) == U_FALSE) {
|
||||
uffs_Perror(UFFS_ERR_NORMAL, "there still have block info cache ? fail to format");
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
uffs_BlockInfoExpireAll(dev);
|
||||
|
||||
for (i = dev->par.start; i <= dev->par.end; i++) {
|
||||
if (uffs_FlashIsBadBlock(dev, i) == U_FALSE) {
|
||||
uffs_FlashEraseBlock(dev, i);
|
||||
if (HAVE_BADBLOCK(dev))
|
||||
uffs_BadBlockProcess(dev, NULL);
|
||||
}
|
||||
else {
|
||||
#ifdef CONFIG_ENABLE_BAD_BLOCK_VERIFY
|
||||
_ForceFormatAndCheckBlock(dev, i);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (uffs_TreeRelease(dev) == U_FAIL) {
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
if (uffs_TreeInit(dev) == U_FAIL) {
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
if (uffs_BuildTree(dev) == U_FAIL) {
|
||||
return U_FAIL;
|
||||
}
|
||||
|
||||
return U_SUCC;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_version.c
|
||||
* \brief uffs version information
|
||||
* \author Ricky Zheng, created 8th May, 2005
|
||||
*/
|
||||
|
||||
#include "uffs/uffs_version.h"
|
||||
#include "uffs/uffs_config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#define PFX "ver: "
|
||||
|
||||
|
||||
static char version_buf[8];
|
||||
|
||||
const char * uffs_Version2Str(int ver)
|
||||
{
|
||||
sprintf(version_buf, "%1d.%02d.%04d", (ver&0xff000000) >> 24, (ver&0xff0000) >> 16, (ver&0xffff));
|
||||
return version_buf;
|
||||
}
|
||||
|
||||
int uffs_GetVersion(void)
|
||||
{
|
||||
return UFFS_VERSION;
|
||||
}
|
||||
|
||||
int uffs_GetMainVersion(int ver)
|
||||
{
|
||||
return (ver&0xff000000) >> 24;
|
||||
}
|
||||
|
||||
int uffs_GetMinorVersion(int ver)
|
||||
{
|
||||
return (ver&0xff0000) >> 16;
|
||||
}
|
||||
/*
|
||||
This file is part of UFFS, the Ultra-low-cost Flash File System.
|
||||
|
||||
Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
|
||||
|
||||
UFFS is free software; you can redistribute it and/or modify it under
|
||||
the GNU Library General Public License as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
UFFS is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
or GNU Library General Public License, as applicable, for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
and GNU Library General Public License along with UFFS; if not, write
|
||||
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or use
|
||||
macros or inline functions from this file, or you compile this file
|
||||
and link it with other works to produce a work based on this file,
|
||||
this file does not by itself cause the resulting work to be covered
|
||||
by the GNU General Public License. However the source code for this
|
||||
file must still be made available in accordance with section (3) of
|
||||
the GNU General Public License v2.
|
||||
|
||||
This exception does not invalidate any other reasons why a work based
|
||||
on this file might be covered by the GNU General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file uffs_version.c
|
||||
* \brief uffs version information
|
||||
* \author Ricky Zheng, created 8th May, 2005
|
||||
*/
|
||||
|
||||
#include "uffs/uffs_version.h"
|
||||
#include "uffs/uffs_config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#define PFX "ver: "
|
||||
|
||||
|
||||
static char version_buf[8];
|
||||
|
||||
const char * uffs_Version2Str(int ver)
|
||||
{
|
||||
sprintf(version_buf, "%1d.%02d.%04d", (ver&0xff000000) >> 24, (ver&0xff0000) >> 16, (ver&0xffff));
|
||||
return version_buf;
|
||||
}
|
||||
|
||||
int uffs_GetVersion(void)
|
||||
{
|
||||
return UFFS_VERSION;
|
||||
}
|
||||
|
||||
int uffs_GetMainVersion(int ver)
|
||||
{
|
||||
return (ver&0xff000000) >> 24;
|
||||
}
|
||||
|
||||
int uffs_GetMinorVersion(int ver)
|
||||
{
|
||||
return (ver&0xff0000) >> 16;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user