git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2014 bbd45198-f89e-11dd-88c7-29a3b14d5316

This commit is contained in:
goprife@gmail.com
2012-04-02 15:53:34 +00:00
parent f525373465
commit 34678294fe
82 changed files with 0 additions and 18604 deletions
-1
View File
@@ -1 +0,0 @@
Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
@@ -1,3 +0,0 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.6 )
PROJECT( uffs )
ADD_SUBDIRECTORY( src )
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
-5
View File
@@ -1,5 +0,0 @@
TODO list for v1.3:
* New API: int uffs_SkipObject(uffs_Object *obj, int size);
* Introduce buffer group
* Interface to Linux MTD
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,31 +0,0 @@
/*
+------------------------------------------------------------------------------
| Project : Device Filesystem
+------------------------------------------------------------------------------
| Copyright 2010
| All rights reserved.
|------------------------------------------------------------------------------
| File : dfs_uffs.h
|------------------------------------------------------------------------------
| Chang Logs:
| Date Author Notes
| 2010-09-02 Bernard The first version.
| 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
Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

@@ -1,28 +0,0 @@
#ifndef __K9F2G08_H__
#define __K9F2G08_H__
#include <rtdef.h>
#include <s3c24x0.h>
#include <nand.h>
void K9F2G08_Program(u32 blockIndex, u32 srcAddress, u32 fileSize);
//*************** H/W dependent functions ***************
void K9F2G08_ReadChipID(u8* buf, UBOOL all);
int K9F2G08_Check_badblk(u32 block);
int K9F2G08_EraseBlock (u32 block);
int K9F2G08_Mark_badblk (u32 block);
int K9F2G08_ReadPage (u32 block, u32 page, u8 *buffer, int len, u8 *ecc);
int K9F2G08_WritePage (u32 block, u32 page, const u8 *buffer, int len, const u8 *ecc);
int K9F2G08_ReadTags (u32 block, u32 page, u8 *spare, int ofs, int len);
int K9F2G08_WriteTags (u32 block, u32 page, const u8 *spare, int ofs, int len);
void K9F2G08_Reset(void);
void K9F2G08_Init(void);
#endif
File diff suppressed because it is too large Load Diff
@@ -1,91 +0,0 @@
/*
* uffs/flash/nand.h
*
* COPYRIGHT (C) 2006 - 2011, 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
*
* Info:
* Contains standard defines and IDs for NAND flash devices
*/
#ifndef __RTT_DFS_NAND_H__
#define __RTT_DFS_NAND_H__
/*
* Standard NAND flash commands
*/
#define NAND_CMD_READ0 0 /* Read0 */
#define NAND_CMD_READ1 1 /* Read1 */
#define NAND_CMD_RNDOUT 5 /* Random data output */
#define NAND_CMD_PAGEPROG 0x10 /* Write phase 2 */
#define NAND_CMD_READOOB 0x50 /* Read oob */
#define NAND_CMD_ERASE1 0x60 /* Erase phase 1 */
#define NAND_CMD_STATUS 0x70 /* Status read */
#define NAND_CMD_STATUS_MULTI 0x71
#define NAND_CMD_SEQIN 0x80 /* Write phase 1 */
#define NAND_CMD_RNDIN 0x85 /* Random data input */
#define NAND_CMD_READID 0x90 /* ReadID,all-purpose command */
#define NAND_CMD_ERASE2 0xd0 /* Erase phase 2 */
#define NAND_CMD_RESET 0xff /* Reset */
/* Extended commands for large page devices */
#define NAND_CMD_READSTART 0x30
#define NAND_CMD_RNDOUTSTART 0xE0
#define NAND_CMD_CACHEDPROG 0x15
#define NAND_CMD_READ_EDC 0x7b
/* define low accessing value */
#define TOTAL_BLOCKS 2048 /* total block of whole chip */
#define PAGE_DATA_SIZE 2048 /* max size of page data */
#define PAGE_SPARE_SIZE 64 /* max size of extended partition */
#define PAGES_PER_BLOCK 64 /* max pages per block' */
#define PAGE_SIZE (PAGE_DATA_SIZE+PAGE_SPARE_SIZE)/* max size per whole page */
#define BLOCK_DATA_SIZE (PAGE_DATA_SIZE*PAGES_PER_BLOCK)/* max size per block' */
/* bad flags offset in the oob area. */
#define NAND_SMALL_BADBLOCK_POS 5 /* small page FLASH */
#define NAND_LARGE_BADBLOCK_POS 0 /* large page FLASH */
/* Option constants for bizarre disfunctionality and real
* features
*/
/* Chip can not auto increment pages */
#define NAND_NO_AUTOINCR 0x00000001
/* Buswitdh is 16 bit */
#define NAND_BUSWIDTH_16 0x00000002
/* Device supports partial programming without padding */
#define NAND_NO_PADDING 0x00000004
/* Chip has cache program function */
#define NAND_CACHEPRG 0x00000008
/* Chip has copy back function */
#define NAND_COPYBACK 0x00000010
/* AND Chip which has 4 banks and a confusing page / block
* assignment. See Renesas datasheet for further information */
#define NAND_IS_AND 0x00000020
/* Chip has a array of 4 pages which can be read without
* additional ready /busy waits */
#define NAND_4PAGE_ARRAY 0x00000040
/* Options valid for Samsung large page devices */
#define NAND_SAMSUNG_LP_OPTIONS \
(NAND_NO_PADDING | NAND_CACHEPRG | NAND_COPYBACK)
struct nand_flash_dev
{
char *name; /* chip name */
int id; /* chip ID */
unsigned long pagesize; /* max pages */
unsigned long chipsize; /* size of whole chip iMB */
unsigned long blocksize;/* size of block */
unsigned long options; /* option */
};
struct nand_manufacturers
{
int id;
char * name;
};
#endif /*__RTT_DFS_NAND_H__*/
@@ -1,135 +0,0 @@
/*
* drivers/mtd/nandids.c
*
* Copyright (C) 2002 Thomas Gleixner (tglx@linutronix.de)
*
* $Id: nand_ids.c,v 1.10 2004/05/26 13:40:12 gleixner Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#include <rtdef.h>
#include "flash/nand.h"
/*
* Chip ID list
*
* name, ID, pagesize, chipsize in MegaByte, eraseblock size,options
*
* if 0, get this information from the extended chip ID
*/
struct nand_flash_dev nand_flash_ids[] =
{
{"NAND 1MiB 5V 8-bit", 0x6e, 256, 1, 0x1000, 0},
{"NAND 2MiB 5V 8-bit", 0x64, 256, 2, 0x1000, 0},
{"NAND 4MiB 5V 8-bit", 0x6b, 512, 4, 0x2000, 0},
{"NAND 1MiB 3,3V 8-bit", 0xe8, 256, 1, 0x1000, 0},
{"NAND 1MiB 3,3V 8-bit", 0xec, 256, 1, 0x1000, 0},
{"NAND 2MiB 3,3V 8-bit", 0xea, 256, 2, 0x1000, 0},
{"NAND 4MiB 3,3V 8-bit", 0xd5, 512, 4, 0x2000, 0},
{"NAND 4MiB 3,3V 8-bit", 0xe3, 512, 4, 0x2000, 0},
{"NAND 4MiB 3,3V 8-bit", 0xe5, 512, 4, 0x2000, 0},
{"NAND 8MiB 3,3V 8-bit", 0xd6, 512, 8, 0x2000, 0},
{"NAND 8MiB 1,8V 8-bit", 0x39, 512, 8, 0x2000, 0},
{"NAND 8MiB 3,3V 8-bit", 0xe6, 512, 8, 0x2000, 0},
{"NAND 8MiB 1,8V 16-bit", 0x49, 512, 8, 0x2000, NAND_BUSWIDTH_16},
{"NAND 8MiB 3,3V 16-bit", 0x59, 512, 8, 0x2000, NAND_BUSWIDTH_16},
{"NAND 16MiB 1,8V 8-bit", 0x33, 512, 16, 0x4000, 0},
{"NAND 16MiB 3,3V 8-bit", 0x73, 512, 16, 0x4000, 0},
{"NAND 16MiB 1,8V 16-bit", 0x43, 512, 16, 0x4000, NAND_BUSWIDTH_16},
{"NAND 16MiB 3,3V 16-bit", 0x53, 512, 16, 0x4000, NAND_BUSWIDTH_16},
{"NAND 32MiB 1,8V 8-bit", 0x35, 512, 32, 0x4000, 0},
{"NAND 32MiB 3,3V 8-bit", 0x75, 512, 32, 0x4000, 0},
{"NAND 32MiB 1,8V 16-bit", 0x45, 512, 32, 0x4000, NAND_BUSWIDTH_16},
{"NAND 32MiB 3,3V 16-bit", 0x55, 512, 32, 0x4000, NAND_BUSWIDTH_16},
{"NAND 64MiB 1,8V 8-bit", 0x36, 512, 64, 0x4000, 0},
{"NAND 64MiB 3,3V 8-bit", 0x76, 512, 64, 0x4000, 0},
{"NAND 64MiB 1,8V 16-bit", 0x46, 512, 64, 0x4000, NAND_BUSWIDTH_16},
{"NAND 64MiB 3,3V 16-bit", 0x56, 512, 64, 0x4000, NAND_BUSWIDTH_16},
{"NAND 128MiB 1,8V 8-bit", 0x78, 512, 128, 0x4000, 0},
{"NAND 128MiB 3,3V 8-bit", 0x79, 512, 128, 0x4000, 0},
{"NAND 128MiB 1,8V 16-bit", 0x72, 512, 128, 0x4000, NAND_BUSWIDTH_16},
{"NAND 128MiB 3,3V 16-bit", 0x74, 512, 128, 0x4000, NAND_BUSWIDTH_16},
{"NAND 256MiB 3,3V 8-bit", 0x71, 512, 256, 0x4000, 0},
/* {"NAND 512MiB 3,3V 8-bit", 0xDC, 512, 512, 0x4000, 0}, */
{"NAND 512MiB 3,3V 8-bit", 0xDC, 0, 512, 0, 0},
/* These are the new chips with large page size. The pagesize
* and the erasesize is determined from the extended id bytes
*/
/* 1 Gigabit */
{"NAND 128MiB 1,8V 8-bit", 0xA1, 0, 128, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
{"NAND 128MiB 3,3V 8-bit", 0xF1, 0, 128, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
{"NAND 128MiB 1,8V 16-bit", 0xB1, 0, 128, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
{"NAND 128MiB 3,3V 16-bit", 0xC1, 0, 128, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
/* 2 Gigabit */
{"NAND 256MiB 1,8V 8-bit", 0xAA, 0, 256, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
{"NAND 256MiB 3,3V 8-bit", 0xDA, 0, 256, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
{"NAND 256MiB 1,8V 16-bit", 0xBA, 0, 256, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
{"NAND 256MiB 3,3V 16-bit", 0xCA, 0, 256, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
/* 4 Gigabit */
{"NAND 512MiB 1,8V 8-bit", 0xAC, 0, 512, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
{"NAND 512MiB 3,3V 8-bit", 0xDC, 0, 512, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
{"NAND 512MiB 1,8V 16-bit", 0xBC, 0, 512, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
{"NAND 512MiB 3,3V 16-bit", 0xCC, 0, 512, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
/* 8 Gigabit */
{"NAND 1GiB 1,8V 8-bit", 0xA3, 0, 1024, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
{"NAND 1GiB 3,3V 8-bit", 0xD3, 0, 1024, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
{"NAND 1GiB 1,8V 16-bit", 0xB3, 0, 1024, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
{"NAND 1GiB 3,3V 16-bit", 0xC3, 0, 1024, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
/* 16 Gigabit */
{"NAND 2GiB 1,8V 8-bit", 0xA5, 0, 2048, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
{"NAND 2GiB 3,3V 8-bit", 0xD5, 0, 2048, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR},
{"NAND 2GiB 1,8V 16-bit", 0xB5, 0, 2048, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
{"NAND 2GiB 3,3V 16-bit", 0xC5, 0, 2048, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR},
/* Renesas AND 1 Gigabit. Those chips do not support extended id and have a strange page/block layout !
* The chosen minimum erasesize is 4 * 2 * 2048 = 16384 Byte, as those chips have an array of 4 page planes
* 1 block = 2 pages, but due to plane arrangement the blocks 0-3 consists of page 0 + 4,1 + 5, 2 + 6, 3 + 7
* Anyway JFFS2 would increase the eraseblock size so we chose a combined one which can be erased in one go
* There are more speed improvements for reads and writes possible, but not implemented now
*/
{"AND 128MiB 3,3V 8-bit", 0x01, 2048, 128, 0x4000, NAND_IS_AND | NAND_NO_AUTOINCR | NAND_4PAGE_ARRAY},
{RT_NULL,}
};
/*
* NAND Flash 生产厂家代码
*/
#define NAND_MFR_TOSHIBA 0x98
#define NAND_MFR_SAMSUNG 0xec
#define NAND_MFR_FUJITSU 0x04
#define NAND_MFR_NATIONAL 0x8f
#define NAND_MFR_RENESAS 0x07
#define NAND_MFR_STMICRO 0x20
/* 制造商ID列表 */
struct nand_manufacturers nand_manuf_ids[] =
{
{NAND_MFR_TOSHIBA, "Toshiba"},
{NAND_MFR_SAMSUNG, "Samsung"},
{NAND_MFR_FUJITSU, "Fujitsu"},
{NAND_MFR_NATIONAL,"National"},
{NAND_MFR_RENESAS, "Renesas"},
{NAND_MFR_STMICRO, "ST Micro"},
{0x0, "Unknown"}
};
@@ -1,4 +0,0 @@
ADD_SUBDIRECTORY(emu)
ADD_SUBDIRECTORY(uffs)
ADD_SUBDIRECTORY(utils)
ADD_SUBDIRECTORY(example)
@@ -1,5 +0,0 @@
SET(libemu_SRCS cmdline.c cmdline.h helper_cmds.c uffs_fileem.c uffs_fileem.h uffs_os_posix.c test_cmds.c)
INCLUDE_DIRECTORIES(${uffs_SOURCE_DIR}/src/inc)
ADD_LIBRARY(emu STATIC ${libemu_SRCS} )
File diff suppressed because it is too large Load Diff
@@ -1,64 +0,0 @@
/*
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_CLI_H_
#define _UFFS_CLI_H_
#ifndef BOOL
#define BOOL int
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
typedef BOOL command_t(const char *tail);
struct cli_commandset {
command_t *handler;
const char *cmd;
const char *args;
const char *descr;
};
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);
#endif
File diff suppressed because it is too large Load Diff
@@ -1,172 +0,0 @@
/*
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 test_cmds.c
* \brief commands for test uffs
* \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 "uffs/uffs_find.h"
#include "uffs/uffs_badblock.h"
#include "cmdline.h"
#define PFX "test:"
static BOOL cmdTestPageReadWrite(const char *tail)
{
TreeNode *node;
uffs_Device *dev;
uffs_Tags local_tag;
uffs_Tags *tag = &local_tag;
int ret;
u16 block;
u16 page;
uffs_Buf *buf;
u32 i;
dev = uffs_GetDeviceFromMountPoint("/");
if (!dev)
goto ext;
buf = uffs_BufClone(dev, NULL);
if (!buf)
goto ext;
node = uffs_TreeGetErasedNode(dev);
if (!node) {
uffs_Perror(UFFS_ERR_SERIOUS, "no free block ?");
goto ext;
}
for (i = 0; i < dev->com.pg_data_size; i++) {
buf->data[i] = i & 0xFF;
}
block = node->u.list.block;
page = 1;
TAG_DATA_LEN(tag) = dev->com.pg_data_size;
TAG_TYPE(tag) = UFFS_TYPE_DATA;
TAG_PAGE_ID(tag) = 3;
TAG_PARENT(tag) = 100;
TAG_SERIAL(tag) = 10;
TAG_BLOCK_TS(tag) = 1;
ret = uffs_FlashWritePageCombine(dev, block, page, buf, tag);
if (UFFS_FLASH_HAVE_ERR(ret)) {
uffs_Perror(UFFS_ERR_SERIOUS, "Write page error: %d", ret);
goto ext;
}
ret = uffs_FlashReadPage(dev, block, page, buf);
if (UFFS_FLASH_HAVE_ERR(ret)) {
uffs_Perror(UFFS_ERR_SERIOUS, "Read page error: %d", ret);
goto ext;
}
for (i = 0; i < dev->com.pg_data_size; i++) {
if (buf->data[i] != (i & 0xFF)) {
uffs_Perror(UFFS_ERR_SERIOUS, "Data verify fail at: %d", i);
goto ext;
}
}
ret = uffs_FlashReadPageSpare(dev, block, page, tag, NULL);
if (UFFS_FLASH_HAVE_ERR(ret)) {
uffs_Perror(UFFS_ERR_SERIOUS, "Read tag (page spare) error: %d", ret);
goto ext;
}
// verify tag:
if (!TAG_IS_DIRTY(tag)) {
uffs_Perror(UFFS_ERR_SERIOUS, "not dirty ? Tag verify fail!");
goto ext;
}
if (!TAG_IS_VALID(tag)) {
uffs_Perror(UFFS_ERR_SERIOUS, "not valid ? Tag verify fail!");
goto ext;
}
if (TAG_DATA_LEN(tag) != dev->com.pg_data_size ||
TAG_TYPE(tag) != UFFS_TYPE_DATA ||
TAG_PAGE_ID(tag) != 3 ||
TAG_PARENT(tag) != 100 ||
TAG_SERIAL(tag) != 10 ||
TAG_BLOCK_TS(tag) != 1) {
uffs_Perror(UFFS_ERR_SERIOUS, "Tag verify fail!");
goto ext;
}
uffs_Perror(UFFS_ERR_SERIOUS, "Page read/write test succ.");
ext:
if (node) {
uffs_FlashEraseBlock(dev, node->u.list.block);
if (HAVE_BADBLOCK(dev))
uffs_BadBlockProcess(dev, node);
else
uffs_InsertToErasedListHead(dev, node);
}
if (dev)
uffs_PutDevice(dev);
if (buf)
uffs_BufFreeClone(dev, buf);
return TRUE;
}
static struct cli_commandset cmdset[] =
{
{ cmdTestPageReadWrite, "t_pgrw", NULL, "test page read/write" },
{ NULL, NULL, NULL, NULL }
};
struct cli_commandset * get_test_cmds()
{
return cmdset;
};
File diff suppressed because it is too large Load Diff
@@ -1,55 +0,0 @@
/*
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_fileem.h
* \brief Emulate NAND flash with host file.
* \author Ricky Zheng
*/
#ifndef _UFFS_FILEEM_H_
#define _UFFS_FILEEM_H_
#include "uffs/uffs_device.h"
typedef struct uffs_FileEmuSt {
int initCount;
FILE *fp;
u8 *em_monitor_page;
u8 * em_monitor_spare;
const char *emu_filename;
} uffs_FileEmu;
void uffs_fileem_setup_device(uffs_Device *dev);
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,104 +0,0 @@
/*
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_os_linux.c
* \brief emulation on linux host
* \author Ricky Zheng
*/
#include "uffs/uffs_os.h"
#include "uffs/uffs_public.h"
//#include <memory.h>
#include <stdlib.h>
#include <time.h>
#define PFX "linuxemu:"
int uffs_SemCreate(int n)
{
//TODO: ... create semaphore, return semaphore handler (rather then return n) ...
return n;
}
int uffs_SemWait(int sem)
{
if (sem) {
//TODO: ... wait semaphore available ...
}
return 0;
}
int uffs_SemSignal(int sem)
{
if (sem) {
//TODO: ... release semaphore ...
}
return 0;
}
int uffs_SemDelete(int sem)
{
if (sem) {
//TODO: ... delete semaphore ...
}
return 0;
}
int uffs_OSGetTaskId(void)
{
//TODO: ... return current task ID ...
return 0;
}
void uffs_CriticalEnter(void)
{
//TODO: enter critical section (for example, disable IRQ?)
return;
}
void uffs_CriticalExit(void)
{
//TODO: exit from critical section (for example, enable IRQ?)
return;
}
unsigned int uffs_GetCurDateTime(void)
{
// FIXME: return system time, please modify this for your platform !
// or just return 0 if you don't care about file time.
time_t tvalue;
tvalue = 0;//time(NULL);
return (unsigned int)tvalue;
}
@@ -1,12 +0,0 @@
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,155 +0,0 @@
/*
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,139 +0,0 @@
/*
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
* \brief uffs basic defines
* \author Ricky Zheng
*/
#ifndef _UFFS_H_
#define _UFFS_H_
#include <rtthread.h>
#include "uffs/uffs_types.h"
#ifdef __cplusplus
extern "C"{
#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_BINARY 0x0000 /** no used in uffs */
#define UO_CREATE 0x0100
#define UO_TRUNC 0x0200
#define UO_EXCL 0x0400
#define UO_DIR 0x1000 /** 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 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 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_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;
#ifdef __cplusplus
}
#endif
#endif
@@ -1,70 +0,0 @@
/*
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 +0,0 @@
/*
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 +0,0 @@
/*
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 +0,0 @@
/*
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 +0,0 @@
/*
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 +0,0 @@
/*
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,152 +0,0 @@
/*
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,55 +0,0 @@
/*
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_fileem.h
* \brief Emulate NAND flash with host file.
* \author Ricky Zheng
*/
#ifndef _UFFS_FILEEM_H_
#define _UFFS_FILEEM_H_
#include "uffs_device.h"
typedef struct uffs_FileEmuSt {
int initCount;
FILE *fp;
u8 *em_monitor_page;
u8 * em_monitor_spare;
const char *emu_filename;
} uffs_FileEmu;
void uffs_fileem_setup_device(uffs_Device *dev);
#endif
@@ -1,74 +0,0 @@
/*
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 +0,0 @@
/*
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 +0,0 @@
/*
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 +0,0 @@
/*
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 +0,0 @@
/*
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 +0,0 @@
/*
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_
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,158 +0,0 @@
/*
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
#endif
@@ -1,85 +0,0 @@
/*
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 +0,0 @@
/*
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 +0,0 @@
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} )
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 +0,0 @@
/*
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 +0,0 @@
/*
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 +0,0 @@
/*
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;
}
@@ -1,46 +0,0 @@
/*
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>
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_mem.c
* \brief uffs native memory allocator
* \author Ricky Zheng, created 23th Feb, 2007
*/
#include <rtthread.h>
#include "uffs/uffs_types.h"
#include "uffs/uffs_public.h"
#include "uffs/uffs_os.h"
#include "uffs/uffs_mem.h"
#define PFX "mem: "
#if CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR > 0
#include <rtthread.h>
void* rt_malloc_link(struct uffs_DeviceSt *dev, unsigned int size)
{
return rt_malloc(size);
}
URET rt_free_link(struct uffs_DeviceSt *dev, void *p)
{
rt_free(p);
return 0;
}
void uffs_MemSetupSystemAllocator(uffs_MemAllocator *allocator)
{
allocator->malloc = rt_malloc_link;
allocator->free = rt_free_link;
}
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,195 +0,0 @@
/*
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 +0,0 @@
/*
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;
}
@@ -1,10 +0,0 @@
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(mkuffs_SRCS mkuffs.c)
ADD_EXECUTABLE(mkuffs ${mkuffs_SRCS})
TARGET_LINK_LIBRARIES(mkuffs emu uffs emu)
File diff suppressed because it is too large Load Diff
@@ -1,25 +0,0 @@
#usage:
# find . -name "*.c" | xargs /usr/bin/ruby path/to/chomp_uffs_perror.rb
#
ARGV.each do |file|
lines = []
count = 0
File.open(file).each_line do |line|
if line =~ /^(.*uffs_Perror.+)PFX(\s*".+)$/
lines << ($1 + $2)
count += 1
#puts ($1 + $2)
else
lines << line
end
end
if count > 0
f = File.open(file, "w")
lines.each do |s|
f.puts s
end
f.close
puts "Fix file #{file}, modified lines: #{count}"
end
end
@@ -1,24 +0,0 @@
#usage:
# find . -name "*.c" | xargs /usr/bin/ruby path/to/format_code.rb
#
ARGV.each do |file|
lines = []
count = 0
File.open(file).each_line do |line|
if line =~ /^(.*)\s$/
lines << $1.dup
count += 1
else
lines << line
end
end
if count > 0
f = File.open(file, "w")
lines.each do |s|
f.puts s
end
f.close
puts "Fix file #{file}, modified lines: #{count}"
end
end
File diff suppressed because it is too large Load Diff
@@ -1,11 +0,0 @@
#ifndef __UFFS_EXT_H__
#define __UFFS_EXT_H__
int CountFileUnder(const char *dir);
int uffs_ls(const char *name);
int uffs_format(const char *name);
int uffs_mkfile(const char *name);
#endif