fixed bug: no release uffs_object_handler in dfs_uffs.c

function:dfs_uffs_open()

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1363 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
iamyhw@gmail.com
2011-04-03 10:13:21 +00:00
parent ccf7d67918
commit 8d77fe70dc
8 changed files with 814 additions and 792 deletions
+34 -29
View File
@@ -10,6 +10,7 @@
* \file nand flash interface example
* \brief example for using nand flash driver and multiple partitions, with system memory allocator.
* \author Ricky Zheng, created at 27 Nov, 2007
* \modify amsl, at 17 Jan, 2010 iamyhw@gmail.com
*/
#include <rtthread.h>
@@ -88,40 +89,42 @@ static int nand_is_badblock(uffs_Device *dev,u32 block)
return K9F2G08_Check_badblk(block);
}
/* The only uffs v1.3.2-4 can used. */
static uffs_FlashOps nand_driver_ops =
{
nand_read_page_data, //ReadPageData
nand_read_page_spare, //ReadPageSpare
NULL, //ReadPageSpareWithLayout
nand_write_page_data, //WritePageData
nand_write_page_spare, //WritePageSpare
NULL, //WriteFullPage
nand_is_badblock, //IsBadBlock
nand_mark_badblock, //MarkBadBlock
nand_erase_block, //EraseBlock
nand_read_page_data, /* ReadPageData */
nand_read_page_spare, /* ReadPageSpare */
NULL, /* ReadPageSpareWithLayout */
nand_write_page_data, /* WritePageData */
nand_write_page_spare, /* WritePageSpare */
NULL, /* WriteFullPage */
nand_is_badblock, /* IsBadBlock */
nand_mark_badblock, /* MarkBadBlock */
nand_erase_block, /* EraseBlock */
};
//change these parameters to fit your nand flash specification
//#define MAN_ID MAN_ID_SAMSUNG // simulate Samsung's NAND flash
static struct uffs_StorageAttrSt flash_storage = {0};
static int initDevice(uffs_Device *dev)
{
dev->ops = &nand_driver_ops;
return RT_EOK;
return U_SUCC;
}
static int releaseDevice(uffs_Device *dev)
{
return RT_EOK;
return U_SUCC;
}
#include <dfs_uffs.h>
static uffs_Device uffs_device = {0};
/* define mount table,UFFS FS private data */
/* it is absolute accessing for uffs.*/
/*
* define mount table,UFFS FS private data
* it is absolute accessing for uffs.
* set struct data on the RT-Thread device
*/
static uffs_MountTable uffs_mount_table =
{
&uffs_device,
@@ -175,40 +178,42 @@ struct nand_flash_dev* nand_init(u8* buf)
return RT_NULL;
}
/* RT-Thread Device Driver Interface */
/* UFFS FileSystem NandFlash InterFace */
/* we don't use entity, let uffs autarky */
/*
* RT-Thread Device Driver Interface
* UFFS FileSystem NandFlash InterFace
* we don't use entity, let uffs autarky
*/
struct rt_device nand_device;
static rt_err_t rt_nand_init(rt_device_t dev)
{
return 0;
return RT_EOK;
}
static rt_err_t rt_nand_open(rt_device_t dev, u16 oflag)
{
return 0;
return RT_EOK;
}
static rt_err_t rt_nand_close(rt_device_t dev)
{
return 0;
return RT_EOK;
}
static rt_err_t rt_nand_control(rt_device_t dev, u8 cmd, void *args)
{
return 0;
return RT_EOK;
}
static rt_size_t rt_nand_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
{
return 0;
return RT_EOK;
}
static rt_size_t rt_nand_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size)
{
return 0;
return RT_EOK;
}
void rt_hw_nand_init(void)
@@ -236,7 +241,7 @@ void rt_hw_nand_init(void)
/* about uffs codes */
entry = &uffs_mount_table;
//entry->lock = rt_sem_create("sem_nand0", 1, RT_IPC_FLAG_FIFO);//??it's lonely!how to do?
/* entry->lock = rt_sem_create("sem_nand0", 1, RT_IPC_FLAG_FIFO); */ /* it's lonely!how to do? */
uffs_MemSetupSystemAllocator(&(entry->dev->mem));
entry->dev->Init = initDevice;
@@ -261,7 +266,7 @@ void rt_hw_nand_init(void)
extid >>= 2;
/* Calc blocksize. Blocksize is multiples of 64KiB */
chip->pages_per_block = ((64*1024)<<(extid & 0x03))/(chip->page_data_size);
/* The 5th id byte */
/* The 5th id byte,it is no use */
chip->total_blocks = (type->chipsize*1024*1024) /
chip->page_data_size / chip->pages_per_block;
@@ -279,7 +284,7 @@ void rt_hw_nand_init(void)
chip->block_status_offs = NAND_SMALL_BADBLOCK_POS;
chip->ecc_opt = UFFS_ECC_SOFT; /* ecc option, do not use ECC,debug */
chip->layout_opt = UFFS_LAYOUT_UFFS; /* let UFFS do the spare layout */
#if (0) //DEBUG trace facility
#if (0) /* DEBUG trace facility */
rt_kprintf("page_data_size = %d\n",chip->page_data_size);
rt_kprintf("pages_per_block = %d\n",chip->pages_per_block);
rt_kprintf("spare_size = %d\n",chip->spare_size);
@@ -289,5 +294,5 @@ void rt_hw_nand_init(void)
}
}
//end of file
/* end of file */
+58 -41
View File
@@ -37,36 +37,46 @@ int dfs_uffs_statfs(struct dfs_filesystem* fs, struct statfs *buf)
}
int dfs_uffs_open(struct dfs_fd* fd)
{
int ret=U_SUCC;
{
if (fd->flags & DFS_O_DIRECTORY)
{//Îļþ¼Ð
uffs_DIR *dirp;
/* open directory */
{ /* directory */
uffs_DIR* dirp;
int oflag = UO_DIR;
if (fd->flags & DFS_O_CREAT) oflag |= UO_CREATE;
if (fd->flags & DFS_O_RDONLY) oflag |= UO_RDONLY;
if (fd->flags & DFS_O_WRONLY) oflag |= UO_WRONLY;
if (fd->flags & DFS_O_CREAT)
{//´´½¨
ret = uffs_open(fd->path,UO_CREATE|UO_DIR);
if(ret != U_SUCC)
if (oflag & UO_CREATE)
{ /* create directory right now */
uffs_Object* fp = uffs_GetObject();
if(fp == NULL)
{
uffs_set_error(-UEMFILE);
return U_FAIL;
}
if(uffs_OpenObject(fp, fd->path, oflag) != U_SUCC)
{
return U_FAIL;
}
/* release object hander */
uffs_PutObject(fp);
}
/* use directory handler */
dirp = uffs_opendir(fd->path);
if(dirp == NULL)
{
uffs_set_error(-UEMFILE);
ret = U_FAIL;
return U_FAIL;
}
fd->data = dirp;
return U_SUCC;
}
else
{//Îļþ
{/* file */
uffs_Object *fp;
int mode = UO_RDONLY;
@@ -80,17 +90,15 @@ int dfs_uffs_open(struct dfs_fd* fd)
/* Creates a new file. The function fails if the file is already existing. */
if (fd->flags & DFS_O_EXCL) mode |= UO_EXCL;
/* allocate a fd */
/* open directory */
/* get an object hander */
fp = uffs_GetObject();
if(fp == NULL)
{
uffs_set_error(-UEMFILE);
ret = U_FAIL;
return U_FAIL;
}
if(uffs_OpenObject(fp, fd->path, mode) == RT_EOK)
if(uffs_OpenObject(fp, fd->path, mode) == U_SUCC)
{
struct uffs_stat stat_buf;
@@ -104,20 +112,20 @@ int dfs_uffs_open(struct dfs_fd* fd)
{
fd->pos = uffs_SeekObject(fp, 0, USEEK_END);
}
ret = U_SUCC;
return U_SUCC;
}
else
{
/* open failed, return */
uffs_set_error(-uffs_GetObjectErr(fp));
/* release object hander */
uffs_PutObject(fp);
return U_FAIL;
}
}
return ret;
}
}
int dfs_uffs_close(struct dfs_fd* fd)
{
int ret=U_SUCC;
@@ -125,21 +133,18 @@ int dfs_uffs_close(struct dfs_fd* fd)
if (fd->type == FT_DIRECTORY)
{
uffs_DIR* dirp;
dirp = (uffs_DIR*)(fd->data);
RT_ASSERT(dirp != RT_NULL);
uffs_closedir(dirp);
ret = uffs_closedir(dirp);
}
else if (fd->type == FT_REGULAR)
{
uffs_Object* fp;
fp = (uffs_Object*)(fd->data);
uffs_Object* fp = (uffs_Object*)(fd->data);
RT_ASSERT(fd != RT_NULL);
ret = uffs_CloseObject(fp);
/* release object hander */
uffs_PutObject(fp);
}
@@ -169,7 +174,7 @@ int dfs_uffs_read(struct dfs_fd* fd, void* buf, rt_size_t count)
RT_ASSERT(fd != RT_NULL);
/* update position */
fd->pos = fp->pos;
fp->pos = fd->pos;
return uffs_ReadObject(fp, buf, count);
}
@@ -179,7 +184,7 @@ int dfs_uffs_write(struct dfs_fd* fd, const void* buf, rt_size_t count)
uffs_Object* fp;
u32 byte_write;
struct uffs_stat stat_buf;
rt_kprintf("count=%d\n",count);
if(fd->type == FT_DIRECTORY)
{
return -DFS_STATUS_EISDIR;
@@ -226,6 +231,11 @@ int dfs_uffs_getdents(struct dfs_fd* fd, struct dirent* dir, rt_uint32_t count)
rt_uint32_t index;
struct dirent* d;
if(fd->type != FT_DIRECTORY)
{
return -DFS_STATUS_EISDIR;
}
dirp = (uffs_DIR*)(fd->data);
RT_ASSERT(dirp != RT_NULL);
@@ -276,18 +286,25 @@ int dfs_uffs_stat(struct dfs_filesystem* fs, const char* path, struct stat* st)
if (ret == U_SUCC)
{
st->st_dev = 0;
//st->st_mode = stat_buf.st_mode;
rt_uint32_t mode=0;
st->st_dev = 0;
st->st_mode = DFS_S_IFREG | DFS_S_IRUSR | DFS_S_IRGRP | DFS_S_IROTH |
DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH;
if (stat_buf.st_mode & US_IFDIR)
{
st->st_mode &= ~DFS_S_IFREG;
st->st_mode |= DFS_S_IFDIR | DFS_S_IXUSR | DFS_S_IXGRP | DFS_S_IXOTH;
}
if (stat_buf.st_mode & US_IREAD)
st->st_mode &= ~(DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH);
if(stat_buf.st_mode & US_IFREG) mode |= DFS_S_IFREG;
if(stat_buf.st_mode & US_IFDIR) mode |= DFS_S_IFDIR;
if(stat_buf.st_mode & US_IRWXU) mode |= DFS_S_IRWXU;
if(stat_buf.st_mode & US_IRUSR) mode |= DFS_S_IRUSR;
if(stat_buf.st_mode & US_IWUSR) mode |= DFS_S_IWUSR;
if(stat_buf.st_mode & US_IXUSR) mode |= DFS_S_IXUSR;
if(stat_buf.st_mode & US_IRWXG) mode |= DFS_S_IRWXG;
if(stat_buf.st_mode & US_IRGRP) mode |= DFS_S_IRGRP;
if(stat_buf.st_mode & US_IWGRP) mode |= DFS_S_IWGRP;
if(stat_buf.st_mode & US_IXGRP) mode |= DFS_S_IXGRP;
if(stat_buf.st_mode & US_IRWXO) mode |= DFS_S_IRWXO;
if(stat_buf.st_mode & US_IROTH) mode |= DFS_S_IROTH;
if(stat_buf.st_mode & US_IWOTH) mode |= DFS_S_IWOTH;
if(stat_buf.st_mode & US_IXOTH) mode |= DFS_S_IXOTH;
st->st_mode = mode;
st->st_size = stat_buf.st_size;
st->st_mtime= stat_buf.st_mtime;
st->st_blksize= stat_buf.st_blksize;
@@ -2,6 +2,7 @@
#define __K9F2G08_H__
#include <rtdef.h>
#include <s3c24x0.h>
#include <nand.h>
void K9F2G08_Program(u32 blockIndex, u32 srcAddress, u32 fileSize);
File diff suppressed because it is too large Load Diff
+47 -33
View File
@@ -1,24 +1,40 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
--*/
#ifndef __NAND_H__
#define __NAND_H__
/*
* 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__
#include <s3c24x0.h>
#include <uffs/uffs_types.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 */
@@ -28,9 +44,9 @@ PARTICULAR PURPOSE.
#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
/* 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
@@ -56,16 +72,14 @@ PARTICULAR PURPOSE.
#define NAND_SAMSUNG_LP_OPTIONS \
(NAND_NO_PADDING | NAND_CACHEPRG | NAND_COPYBACK)
struct nand_flash_dev
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
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
@@ -74,4 +88,4 @@ struct nand_manufacturers
char * name;
};
#endif /*__NAND_H__*/
#endif /*__RTT_DFS_NAND_H__*/
@@ -37,25 +37,25 @@
#ifndef _UFFS_H_
#define _UFFS_H_
#include <dfs_def.h>
#include <rtthread.h>
#include "uffs/uffs_types.h"
#ifdef __cplusplus
extern "C"{
#endif
#define UO_RDONLY DFS_O_RDONLY /** read only */
#define UO_WRONLY DFS_O_WRONLY /** write only */
#define UO_RDWR DFS_O_RDWR /** read and write */
#define UO_APPEND DFS_O_APPEND /** append */
#define UO_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 DFS_O_CREAT
#define UO_TRUNC DFS_O_TRUNC
#define UO_EXCL DFS_O_EXCL
#define UO_DIR DFS_O_DIRECTORY /** open a directory */
#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 */
@@ -85,9 +85,9 @@ extern "C"{
#define _SEEK_SET 1 /** seek from beginning of file */
#define _SEEK_END 2 /** seek from end of file */
#define USEEK_SET DFS_SEEK_SET /*0* 从当前点寻找 */
#define USEEK_CUR DFS_SEEK_CUR /*1* 从文件的开始寻找 */
#define USEEK_END DFS_SEEK_END /*2* 从文件的结尾寻找 */
#define USEEK_CUR _SEEK_CUR
#define USEEK_SET _SEEK_SET
#define USEEK_END _SEEK_END
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -19,7 +19,7 @@
#include "uffs_ext.h"
#include <dfs_posix.h>
#include <filerw.h>
#include <rtgui/filerw.h>
#ifdef RT_USING_FINSH
#include <finsh.h>