update jffs2 to use MTD device.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1938 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong@gmail.com 2012-02-07 03:53:11 +00:00
parent eedd490bd6
commit a5e0a4526a
17 changed files with 152 additions and 475 deletions

View File

@ -438,7 +438,7 @@ __externC void cyg_selwakeup( struct CYG_SELINFO_TAG *sip );
// Provides the current time as a time_t timestamp for use in filesystem
// data strucures.
__externC time_t cyg_timestamp(void);
__externC time_t jffs2_get_timestamp(void);
//=============================================================================
// Miscellaneous functions.

View File

@ -12,6 +12,7 @@
* 2012-1-7 prife the first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "cyg/infra/cyg_type.h"
#include "cyg/fileio/fileio.h"
@ -22,13 +23,10 @@
#include <dfs_def.h>
#include "dfs_jffs2.h"
#include "jffs2_config.h"
#include "porting.h"
#include <string.h>
#define FILE_PATH_MAX 256 /* the longest file path */
#define DEVICE_PART_MAX 1 /* the max partions on a nand deivce*/
#if DEVICE_PART_MAX > 1
#error "support only one jffs2 partition on a flash device!"
#endif
@ -36,7 +34,7 @@
/* make sure the following struct var had been initilased to 0! */ //fixme
struct device_part
{
rt_device_t dev;
struct rt_mtd_device *dev;
struct cyg_mtab_entry * mte;
};
static struct device_part device_partition[DEVICE_PART_MAX] = {0};
@ -132,7 +130,6 @@ static int jffs2_result_to_dfs(int result)
/*
* RT-Thread DFS Interface for jffs2
*/
static int dfs_jffs2_mount(struct dfs_filesystem* fs,
unsigned long rwflag,
const void* data)
@ -164,7 +161,7 @@ static int dfs_jffs2_mount(struct dfs_filesystem* fs,
*/
mte->data = (CYG_ADDRWORD)fs->dev_id;
device_partition[index].dev = fs->dev_id;
device_partition[index].dev = RT_MTD_DEVICE(fs->dev_id);
/* after jffs2_mount, mte->data will not be dev_id any more */
result = jffs2_mount(NULL, mte);
if (result != 0)
@ -182,7 +179,7 @@ static int _find_fs(struct cyg_mtab_entry ** mte, rt_device_t dev_id)
/* find device index */
for (index = 0; index < DEVICE_PART_MAX; index++)
{
if (device_partition[index].dev == dev_id)
if (device_partition[index].dev == RT_MTD_DEVICE(dev_id))
{
*mte = device_partition[index].mte;
return 0;
@ -199,7 +196,7 @@ static int dfs_jffs2_unmount(struct dfs_filesystem* fs)
/* find device index, then umount it */
for (index = 0; index < DEVICE_PART_MAX; index++)
{
if (device_partition[index].dev == fs->dev_id)
if (device_partition[index].dev == RT_MTD_DEVICE(fs->dev_id))
{
result = jffs2_umount(device_partition[index].mte);
if (result)

View File

@ -3,6 +3,10 @@
#define __ECOS /* must be defined */
#define FILE_PATH_MAX 256 /* the longest file path */
#define DEVICE_PART_MAX 1 /* the max partions on a nand deivce*/
#define CYGPKG_FS_JFFS2_RET_DIRENT_DTYPE /* should be enabled */
#if defined(CYGPKG_FS_JFFS2_RET_DIRENT_DTYPE)
#define CYGPKG_FILEIO_DIRENT_DTYPE
@ -11,7 +15,7 @@
#define CYGOPT_FS_JFFS2_WRITE /* if not defined, jffs2 is read only*/
/* jffs2 debug output opion */
#define CONFIG_JFFS2_FS_DEBUG 0 /* 1 or 2 */
#define CONFIG_JFFS2_FS_DEBUG 0 /* 1 or 2 */
/* jffs2 gc thread section */
#define CYGOPT_FS_JFFS2_GCTHREAD

View File

@ -10,7 +10,7 @@
#define PTR_ERR(err) ((unsigned long)(err))
#define IS_ERR(err) ((unsigned long)err > (unsigned long)-1000L)
#define CURRENT_TIME cyg_timestamp()
#define CURRENT_TIME jffs2_get_timestamp()
#define KERN_EMERG "<0>" // system is unusable
#define KERN_ALERT "<1>" // action must be taken immediately

View File

@ -5,10 +5,10 @@
#include <asm/page.h> /* Don't ask. Linux headers are a mess. */
#define kmalloc(x, y) malloc(x)
#define kfree(x) free(x)
#define vmalloc(x) malloc(x)
#define vfree(x) free(x)
#define kmalloc(x, y) rt_malloc(x)
#define kfree(x) rt_free(x)
#define vmalloc(x) rt_malloc(x)
#define vfree(x) rt_free(x)
#endif /* __LINUX_SLAB_H__ */

View File

@ -1,113 +0,0 @@
#ifndef CYGONCE_PKGCONF_INFRA_H
# define CYGONCE_PKGCONF_INFRA_H
//======================================================================
//
// infra.h
//
// Host side implementation of the infrastructure configuration
// header.
//
//======================================================================
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of the eCos host tools.
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 or (at your option) any
// later version.
//
// This program 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 for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the
// Free Software Foundation, Inc., 51 Franklin Street,
// Fifth Floor, Boston, MA 02110-1301, USA.
// -------------------------------------------
// ####ECOSHOSTGPLCOPYRIGHTEND####
//======================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): bartv
// Contact(s): bartv
// Date: 1998/07/13
// Version: 0.01
//
//####DESCRIPTIONEND####
//======================================================================
// The purpose of this header file is to replicate appropriate
// functionality from the target-side header file <pkgconf/infra.h>.
// This header file is intended to contain configuration options
// related to the implementation of the infrastructure, as opposed
// to how that infrastructure gets used by other packages. A good
// example would be a configuration option to control the size
// of the circular trace buffer.
//
// On the host side these things are handled by autoconf, and in
// particular the configure.in script will offer command-line
// arguments allowing the relevant options to be controlled.
// The relevant information will end up in <cyg/pkgconf/hostinfra.h>
# include <pkgconf/hostinfra.h>
// Some options should always be enabled in this header file.
#define CYGDBG_INFRA_DIAG_PRINTF_USE_VARARG
#define CYGDBG_INFRA_DEBUG_ASSERT_MESSAGE
#define CYGDBG_INFRA_DEBUG_TRACE_MESSAGE
// Other options should be decided on a package by package basis,
// e.g. whether or not assertions are used. On the host side it is
// not appropriate to control these globally, instead the infrastructure
// always provides the necessary functionality and it is up to the
// other parts of the system to decide whether or not the facilities
// get used.
// A third set of options deal with the environment, e.g. the sizes
// of various data types. autoconf macros take care of most of the
// work, but some translation is needed into eCos-style names to
// avoid namespace pollution.
// Process the definitions of SIZEOF_INT_P and SIZEOF_LONG to work
// out a sensible data type for CYG_ADDRESS and CYG_ADDRWORD.
#if (!defined(SIZEOF_INT_P) || !defined(SIZEOF_LONG))
# error "Configure problem: data type sizes not set"
#endif
#if (SIZEOF_INT_P == 4)
// The default, nothing needs to be done
#elif (SIZEOF_INT_P == 8)
# define cyg_haladdress cyg_halint64
#else
# error "Only 32 and 64 bit pointers are supported"
#endif
#if ((SIZEOF_INT_P == 4) && (SIZEOF_LONG == 4))
// The default, nothing needs to be done
#elif ((SIZEOF_INT_P <= 8) && (SIZEOF_LONG <= 8))
// cyg_halint64 will have been defined appropriately.
# define cyg_haladdrword cyg_halint64
#else
# error "Only 32 and 64 bit machine word sizes are supported"
#endif
// Any symbols defined in <pkgconf/hostconf.h> which have been processed
// here should no longer be of any interest, and in the interests of
// reducing name space pollution they get undef'ed here.
// In addition there are two #define's in the config.h header file
// which are always present and which have names that are rather too
// generic. These get removed here as well. The version is worth
// preserving under a different name.
#undef SIZEOF_INT_P
#undef SIZEOF_LONG
#undef PACKAGE
#undef VERSION
#endif // CYGONCE_PKGCONF_INFRA_H
// End of infra.h

View File

@ -3,7 +3,7 @@
#include "porting.h"
time_t cyg_timestamp(void)
time_t jffs2_get_timestamp(void)
{
return 0;
}

View File

@ -42,8 +42,9 @@ extern cyg_fileops jffs2_fileops;
extern cyg_fileops jffs2_dirops;
extern struct cyg_fstab_entry jffs2_fste;
extern void jffs2_get_info_from_sb(void * data, struct jffs2_fs_info * info);
extern int jffs2_porting_stat(cyg_mtab_entry * mte, cyg_dir dir, const char *name,
time_t jffs2_get_timestamp(void);
void jffs2_get_info_from_sb(void * data, struct jffs2_fs_info * info);
int jffs2_porting_stat(cyg_mtab_entry * mte, cyg_dir dir, const char *name,
void * stat_buf);
#endif

View File

@ -1,20 +0,0 @@
#include <stdio.h>
//#include <io.h>
//#include <fcntl.h>
//#include <sys/stat.h>
#include "flash.h"
int file_handle;
int FLASH_SIZE;
int flash_file_init(void)
{
// file_handle = open(FILE_NAME, O_RDWR |O_BINARY| O_CREAT, S_IREAD | S_IWRITE);
// if(file_handle >= 0) {
// printf("read file ok\n");
// } else {
// printf("read file error\n");
// return -1;
// }
// FLASH_SIZE = lseek(file_handle, 0, SEEK_END) ;// / BLOCK_SIZE * BLOCK_SIZE; /*È¡ÕûÊý*/
// printf("the size of jffs bin file is %d", FLASH_SIZE);
return 0;
}

View File

@ -1,89 +0,0 @@
#include <linux/kernel.h>
#include "nodelist.h"
#include <linux/pagemap.h>
#include <linux/crc32.h>
#include "compr.h"
//#include <errno.h>
#include <string.h>
extern struct cyg_fstab_entry jffs2_fste;
MTAB_ENTRY(jffs2_mte,
"/",
"jffs2",
NULL,
0);
#include "flash.h"
extern int file_handle;
extern int FLASH_SIZE;
extern int flash_file_init(void);
extern int jffs2_mount(cyg_fstab_entry * fste, cyg_mtab_entry * mte);
extern int jffs2_open(cyg_mtab_entry * mte, cyg_dir dir, const char *name,
int mode, cyg_file * file);
extern int jffs2_fo_read(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
char buffer[1024];
int jffs2_main()
{
int res;
cyg_file file;
struct CYG_UIO_TAG uio_s;
struct CYG_IOVEC_TAG iovec;
// res = flash_file_init();
if (res != 0)
goto out;
//mount file system
res = jffs2_mount(&jffs2_fste, &jffs2_mte);
if (res < 0)
{
printf("jffs2_mount error!\n");
goto out;
}
printf("jffs2 mount ok!\n");
//read a file or dirs "src/dfs.c"
//res = jffs2_open(&jffs2_mte, 0, "dfs_uffs.c", O_RDWR, &file);
//res = jffs2_open(&jffs2_mte, 0, "SConscript", O_RDWR, &file);
// res = jffs2_open(&jffs2_mte, 0, "filesystems/devfs/console.c" , O_RDWR, &file);
if (res != 0)
{
printf("jffs2_open file error: %d", res);
goto out;
}
memset(buffer, 0, sizeof(buffer));
uio_s.uio_iov = &iovec;
uio_s.uio_iov->iov_base = buffer;
uio_s.uio_iov->iov_len = 1024;
uio_s.uio_iovcnt = 1; //must be 1
//uio_s.uio_offset //not used...
uio_s.uio_resid = uio_s.uio_iov->iov_len; //seem no use in ecos;
//uio_s.uio_segflg = UIO_USERSPACE;
//uio_s.uio_rw = ;
res = jffs2_fo_read(&file, &uio_s);
if (res != 0)
{
printf("jffs2_fo_read file error: %d", res);
goto out;
}
printf("\n\n=====================================================================\n");
printf("the uffs/dfs_uffs.c file content is:\n\n");
printf("%s", buffer);
out:
#if defined (MSVC)
printf("\n\npress any key to colose this console...\n");
getch();
#endif
return 0;
}

View File

@ -21,7 +21,6 @@
struct _inode *jffs2_lookup(struct _inode *dir_i, const unsigned char *d_name, int namelen)
{
struct jffs2_inode_info *dir_f;
struct jffs2_sb_info *c;
struct jffs2_full_dirent *fd = NULL, *fd_list;
uint32_t ino = 0;
uint32_t hash = full_name_hash(d_name, namelen);
@ -30,7 +29,6 @@ struct _inode *jffs2_lookup(struct _inode *dir_i, const unsigned char *d_name, i
D1(printk("jffs2_lookup()\n"));
dir_f = JFFS2_INODE_INFO(dir_i);
c = JFFS2_SB_INFO(dir_i->i_sb);
down(&dir_f->sem);
@ -242,7 +240,7 @@ int jffs2_mkdir (struct _inode *dir_i, const unsigned char *d_name, int mode)
rd->pino = cpu_to_je32(dir_i->i_ino);
rd->version = cpu_to_je32(++dir_f->highest_version);
rd->ino = cpu_to_je32(inode->i_ino);
rd->mctime = cpu_to_je32(cyg_timestamp());
rd->mctime = cpu_to_je32(jffs2_get_timestamp());
rd->nsize = namelen;
rd->type = DT_DIR;
rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));

View File

@ -14,95 +14,75 @@
#include <linux/kernel.h>
#include "nodelist.h"
#include <rtdevice.h>
//#include <cyg/io/io.h> mod by prife
//#include <cyg/io/config_keys.h>
//#include <cyg/io/flash.h>
#define PAGE_SIZE 1024
// #include <stdio.h>
// #include <stdlib.h>
//#include <io.h>
//#include <fcntl.h>
// #include <string.h>
//#include <sys/stat.h>
#include <rtthread.h>
cyg_bool jffs2_flash_read(struct jffs2_sb_info * c,
cyg_uint32 read_buffer_offset, const size_t size,
size_t * return_size, unsigned char *write_buffer)
int jffs2_flash_read(struct jffs2_sb_info * c, cyg_uint32 offset,
const size_t size,
size_t * return_size,
unsigned char *buffer)
{
cyg_uint32 len;
struct super_block *sb = OFNI_BS_2SFFJ(c);
D2(printf("FLASH READ\n"));
D2(printf("read address = %x\n", CYGNUM_FS_JFFS2_BASE_ADDRESS + read_buffer_offset));
D2(printf("write address = %x\n", write_buffer));
D2(printf("size = %x\n", size));
// err = cyg_io_bread(sb->s_dev, write_buffer, &len, read_buffer_offset);
len = rt_device_read(sb->s_dev, read_buffer_offset, write_buffer, size);
*return_size = rt_mtd_read(RT_MTD_DEVICE(sb->s_dev), offset, buffer, size);
// lseek(file_handle, read_buffer_offset, SEEK_SET);
// len = read(file_handle, write_buffer, size);
if (len != size)
return -EIO;
//rt_kprintf("fread: offset %d, size %d, ret size %d\n",
// offset, size, *return_size);
*return_size = (size_t) len;
return ENOERR;
}
cyg_bool jffs2_flash_write(struct jffs2_sb_info * c,
cyg_uint32 write_buffer_offset, const size_t size,
size_t * return_size, unsigned char *read_buffer)
int jffs2_flash_write(struct jffs2_sb_info * c,
cyg_uint32 offset, const size_t size,
size_t * return_size, unsigned char *buffer)
{
cyg_uint32 len;
struct super_block *sb = OFNI_BS_2SFFJ(c);
D2(printf("FLASH WRITE ENABLED!!!\n"));
D2(printf("write address = %x\n", CYGNUM_FS_JFFS2_BASE_ADDRESS + write_buffer_offset));
D2(printf("read address = %x\n", read_buffer));
D2(printf("size = %x\n", size));
*return_size = rt_mtd_write(RT_MTD_DEVICE(sb->s_dev), offset, buffer, size);
len = rt_device_write(sb->s_dev, write_buffer_offset, read_buffer, size);
*return_size = (size_t) len;
if (len != size)
rt_kprintf("fwrite: offset %d, size %d, ret size %d\n",
offset, size, *return_size);
return ENOERR;
}
int jffs2_flash_erase(struct jffs2_sb_info * c,
struct jffs2_eraseblock * jeb)
{
rt_err_t result;
struct super_block *sb = OFNI_BS_2SFFJ(c);
rt_kprintf("erase: offset %d\n", jeb->offset);
result = rt_mtd_erase_block(RT_MTD_DEVICE(sb->s_dev), jeb->offset);
if (result != RT_EOK)
return -EIO;
return ENOERR;
//return ((err == ENOERR) ? ENOERR : -EIO);
// Cyg_ErrNo err;
// cyg_uint32 len;
// struct super_block *sb = OFNI_BS_2SFFJ(c);
// lseek(file_handle, write_buffer_offset, SEEK_SET);
// len = write(file_handle, read_buffer, size);
// if (len < 0)
// return -EIO;
// *return_size = (size_t) len;
// return ENOERR;
}
int
jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct iovec *vecs,
unsigned long count, loff_t to, size_t * retlen)
int jffs2_flash_direct_writev(struct jffs2_sb_info *c,
const struct iovec *vecs, unsigned long count, loff_t to,
size_t * retlen)
{
unsigned long i;
size_t totlen = 0, thislen;
int ret = 0;
for (i = 0; i < count; i++) {
for (i = 0; i < count; i++)
{
// writes need to be aligned but the data we're passed may not be
// Observation suggests most unaligned writes are small, so we
// optimize for that case.
if (((vecs[i].iov_len & (sizeof (int) - 1))) ||
(((unsigned long) vecs[i].
iov_base & (sizeof (unsigned long) - 1)))) {
if (((vecs[i].iov_len & (sizeof(int) - 1))) ||
(((unsigned long) vecs[i].iov_base & (sizeof(unsigned long) - 1))))
{
// are there iov's after this one? Or is it so much we'd need
// to do multiple writes anyway?
if ((i + 1) < count || vecs[i].iov_len > 256) {
if ((i + 1) < count || vecs[i].iov_len > 256)
{
// cop out and malloc
unsigned long j;
ssize_t sizetomalloc = 0, totvecsize = 0;
@ -112,91 +92,62 @@ jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct iovec *vecs,
totvecsize += vecs[j].iov_len;
// pad up in case unaligned
sizetomalloc = totvecsize + sizeof (int) - 1;
sizetomalloc &= ~(sizeof (int) - 1);
cbuf = (char *) malloc(sizetomalloc);
sizetomalloc = totvecsize + sizeof(int) - 1;
sizetomalloc &= ~(sizeof(int) - 1);
cbuf = (char *) rt_malloc(sizetomalloc);
// malloc returns aligned memory
if (!cbuf) {
if (!cbuf)
{
ret = -ENOMEM;
goto writev_out;
}
cbufptr = cbuf;
for (j = i; j < count; j++) {
memcpy(cbufptr, vecs[j].iov_base,
vecs[j].iov_len);
for (j = i; j < count; j++)
{
memcpy(cbufptr, vecs[j].iov_base, vecs[j].iov_len);
cbufptr += vecs[j].iov_len;
}
ret =
jffs2_flash_write(c, to, sizetomalloc,
&thislen, (unsigned char *)cbuf);
if (thislen > totvecsize) // in case it was aligned up
rt_kprintf("direct_write: offset %d, size %d\n", to, sizetomalloc);
ret = jffs2_flash_write(c, to, sizetomalloc, &thislen,
(unsigned char *) cbuf);
if (thislen > totvecsize) // in case it was aligned up
thislen = totvecsize;
totlen += thislen;
free(cbuf);
rt_free(cbuf);
goto writev_out;
} else {
}
else
{
// otherwise optimize for the common case
int buf[256 / sizeof (int)]; // int, so int aligned
int buf[256/sizeof(int)]; // int, so int aligned
size_t lentowrite;
lentowrite = vecs[i].iov_len;
// pad up in case its unaligned
lentowrite += sizeof (int) - 1;
lentowrite &= ~(sizeof (int) - 1);
lentowrite += sizeof(int) - 1;
lentowrite &= ~(sizeof(int) - 1);
memcpy(buf, vecs[i].iov_base, lentowrite);
ret =
jffs2_flash_write(c, to, lentowrite,
&thislen, (unsigned char *) &buf);
rt_kprintf("direct_write: offset %d, size %d\n", to, lentowrite);
ret = jffs2_flash_write(c, to, lentowrite, &thislen,
(unsigned char *) &buf);
if (thislen > vecs[i].iov_len)
thislen = vecs[i].iov_len;
} // else
} else
ret =
jffs2_flash_write(c, to, vecs[i].iov_len, &thislen,
vecs[i].iov_base);
}
}
else
{
rt_kprintf("direct_writev: offset %d, size %d\n", to, vecs[i].iov_len);
ret = jffs2_flash_write(c, to, vecs[i].iov_len, &thislen,
vecs[i].iov_base);
}
totlen += thislen;
if (ret || thislen != vecs[i].iov_len)
break;
if (ret || thislen != vecs[i].iov_len) break;
to += vecs[i].iov_len;
}
writev_out:
if (retlen)
*retlen = totlen;
writev_out:
if (retlen) *retlen = totlen;
return ret;
}
cyg_bool jffs2_flash_erase(struct jffs2_sb_info * c,
struct jffs2_eraseblock * jeb)
{
int res;
struct super_block *sb = OFNI_BS_2SFFJ(c);
D2(printf("FLASH ERASE ENABLED!!!\n"));
D2(printf("erase address = %x\n", CYGNUM_FS_JFFS2_BASE_ADDRESS + jeb->offset));
D2(printf("size = %x\n", c->sector_size));
// err = cyg_io_get_config(sb->s_dev, CYG_IO_GET_CONFIG_FLASH_ERASE,
// &e, &len);
res = rt_device_control(sb->s_dev, RT_DEVICE_CTRL_BLK_ERASE, (void *)(jeb->offset));
return ((res == RT_EOK) ? ENOERR : -EIO);
//这里 jeb数据结构
// int i;
// char block_buf[4096];
// cyg_uint32 len;
// struct super_block *sb = OFNI_BS_2SFFJ(c);
// lseek(file_handle, jeb->offset, SEEK_SET);
// c->sector_size 是sector大小还是block大小呢 //fixme
// 这里的jeb->offset 是字节为偏移地址吗??? //fixme
// memset(&block_buf, 0xff, sizeof(block_buf) );
// for(i=0; i<(BLOCK_SIZE/4096); i++)
// write(file_handle, &block_buf, sizeof(block_buf));
// return ENOERR;
}

View File

@ -18,18 +18,12 @@
#include <linux/pagemap.h>
#include <linux/crc32.h>
#include "compr.h"
//#include <errno.h> //prife
#include <string.h>
//#include <cyg/io/config_keys.h> //prife
#if (__GNUC__ == 3) && (__GNUC_MINOR__ == 2) && \
(defined (__arm__) || defined (_mips))
#error This compiler is known to be broken. Please see:
#error "http://ecos.sourceware.org/ml/ecos-patches/2003-08/msg00006.html"
#endif
#include <rtdevice.h>
//--------------------------------------------
cyg_mtab_entry *cyg_cdir_mtab_entry = NULL; // prife add
cyg_mtab_entry *cyg_cdir_mtab_entry = NULL;
cyg_dir cyg_cdir_dir = CYG_DIR_NULL;
//==========================================================================
// Default functions
@ -219,7 +213,7 @@ static void icache_evict(struct _inode *root_i, struct _inode *i)
this->i_cache_prev->i_cache_next = this->i_cache_next;
jffs2_clear_inode(this);
memset(this, 0x5a, sizeof(*this));
free(this);
rt_free(this);
if (parent && parent != this) {
parent->i_count--;
this = root_i;
@ -453,59 +447,24 @@ static int jffs2_pathconf(struct _inode *node, struct cyg_pathconf_info *info)
// filesystem.
static int jffs2_read_super(struct super_block *sb)
{
// struct jffs2_sb_info *c;
// Cyg_ErrNo err;
// cyg_uint32 len;
// cyg_io_flash_getconfig_devsize_t ds;
// cyg_io_flash_getconfig_blocksize_t bs;
//
// D1(printk(KERN_DEBUG "jffs2: read_super\n"));
//
// c = JFFS2_SB_INFO(sb);
//
// len = sizeof (ds);
// err = cyg_io_get_config(sb->s_dev,
// CYG_IO_GET_CONFIG_FLASH_DEVSIZE, &ds, &len);
// if (err != ENOERR) {
// D1(printf
// ("jffs2: cyg_io_get_config failed to get dev size: %d\n",
// err));
// return err;
// }
// len = sizeof (bs);
// bs.offset = 0;
// err = cyg_io_get_config(sb->s_dev,
// CYG_IO_GET_CONFIG_FLASH_BLOCKSIZE, &bs, &len);
// if (err != ENOERR) {
// D1(printf
// ("jffs2: cyg_io_get_config failed to get block size: %d\n",
// err));
// return err;
// }
//
// c->sector_size = bs.block_size;
// c->flash_size = ds.dev_size;
// c->cleanmarker_size = sizeof(struct jffs2_unknown_node);
Cyg_ErrNo err;
struct jffs2_sb_info *c;
struct rt_device_blk_geometry geometry; //fixme need a new struct type!
struct rt_mtd_device *device;
c = JFFS2_SB_INFO(sb);
device = RT_MTD_DEVICE(sb->s_dev);
//init some block
/* initialize mutex lock */
init_MUTEX(&c->alloc_sem);
init_MUTEX(&c->erase_free_sem);
rt_memset(&geometry, 0, sizeof(geometry));
rt_device_control(sb->s_dev, RT_DEVICE_CTRL_BLK_GETGEOME, &geometry);
c->sector_size = geometry.block_size;
c->flash_size = (geometry.sector_count) * (geometry.bytes_per_sector);
/* sector size is the erase block size */
c->sector_size = device->block_size;
c->flash_size = (device->block_end - device->block_start) * device->block_size;
c->cleanmarker_size = sizeof(struct jffs2_unknown_node);
err = jffs2_do_mount_fs(c);
if (err)
return -err;
if (err) return -err;
D1(printk(KERN_DEBUG "jffs2_read_super(): Getting root inode\n"));
sb->s_root = jffs2_iget(sb, 1);
@ -520,7 +479,7 @@ static int jffs2_read_super(struct super_block *sb)
out_nodes:
jffs2_free_ino_caches(c);
jffs2_free_raw_node_refs(c);
free(c->blocks);
rt_free(c->blocks);
return err;
}
@ -558,7 +517,7 @@ int jffs2_mount(cyg_fstab_entry * fste, cyg_mtab_entry * mte)
jffs2_sb = NULL;
t = (cyg_io_handle_t)mte->data; //get from dfs_jffs2;
if (jffs2_sb == NULL) {
jffs2_sb = malloc(sizeof (struct super_block));
jffs2_sb = rt_malloc(sizeof (struct super_block));
if (jffs2_sb == NULL)
return ENOMEM;
@ -567,9 +526,9 @@ int jffs2_mount(cyg_fstab_entry * fste, cyg_mtab_entry * mte)
memset(jffs2_sb, 0, sizeof (struct super_block));
jffs2_sb->s_dev = t;
c->inocache_list = malloc(sizeof(struct jffs2_inode_cache *) * INOCACHE_HASHSIZE);
c->inocache_list = rt_malloc(sizeof(struct jffs2_inode_cache *) * INOCACHE_HASHSIZE);
if (!c->inocache_list) {
free(jffs2_sb);
rt_free(jffs2_sb);
return ENOMEM;
}
memset(c->inocache_list, 0, sizeof(struct jffs2_inode_cache *) * INOCACHE_HASHSIZE);
@ -586,8 +545,8 @@ int jffs2_mount(cyg_fstab_entry * fste, cyg_mtab_entry * mte)
jffs2_compressors_exit();
}
free(jffs2_sb);
free(c->inocache_list);
rt_free(jffs2_sb);
rt_free(c->inocache_list);
return err;
}
@ -677,16 +636,16 @@ static int jffs2_umount(cyg_mtab_entry * mte)
jffs2_free_full_dirent(fd);
}
free(root);
rt_free(root);
//Clear root inode
//root_i = NULL;
// Clean up the super block and root inode
jffs2_free_ino_caches(c);
jffs2_free_raw_node_refs(c);
free(c->blocks);
free(c->inocache_list);
free(jffs2_sb);
rt_free(c->blocks);
rt_free(c->inocache_list);
rt_free(jffs2_sb);
// Clear superblock & root pointer
mte->root = CYG_DIR_NULL;
mte->data = 0;
@ -986,7 +945,7 @@ static int jffs2_ops_rename(cyg_mtab_entry * mte, cyg_dir dir1,
if (!err)
ds1.dir->i_ctime =
ds1.dir->i_mtime =
ds2.dir->i_ctime = ds2.dir->i_mtime = cyg_timestamp();
ds2.dir->i_ctime = ds2.dir->i_mtime = jffs2_get_timestamp();
out:
jffs2_iput(ds1.dir);
if (S_ISDIR(ds1.node->i_mode)) {
@ -1066,7 +1025,7 @@ static int jffs2_ops_link(cyg_mtab_entry * mte, cyg_dir dir1, const char *name1,
if (err == 0)
ds1.node->i_ctime =
ds2.dir->i_ctime = ds2.dir->i_mtime = cyg_timestamp();
ds2.dir->i_ctime = ds2.dir->i_mtime = jffs2_get_timestamp();
jffs2_iput(ds1.dir);
jffs2_iput(ds1.node);
@ -1294,7 +1253,7 @@ int jffs2_fo_read(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio)
// We successfully read some data, update the node's access time
// and update the file offset and transfer residue.
inode->i_atime = cyg_timestamp();
inode->i_atime = jffs2_get_timestamp();
uio->uio_resid = resid;
fp->f_offset = pos;
@ -1403,7 +1362,7 @@ static int jffs2_truncate_file (struct _inode *inode)
ri->mode = cpu_to_jemode(inode->i_mode);
ri->isize = cpu_to_je32(0);
ri->atime = cpu_to_je32(inode->i_atime);
ri->mtime = cpu_to_je32(cyg_timestamp());
ri->mtime = cpu_to_je32(jffs2_get_timestamp());
ri->offset = cpu_to_je32(0);
ri->csize = ri->dsize = cpu_to_je32(0);
ri->compr = JFFS2_COMPR_NONE;
@ -1419,7 +1378,7 @@ static int jffs2_truncate_file (struct _inode *inode)
}
/* It worked. Update the inode */
inode->i_mtime = cyg_timestamp();
inode->i_mtime = jffs2_get_timestamp();
inode->i_size = 0;
old_metadata = f->metadata;
jffs2_truncate_fragtree (c, &f->fragtree, 0);
@ -1460,7 +1419,7 @@ static int jffs2_fo_write(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio)
ri.mode = cpu_to_jemode(inode->i_mode);
ri.uid = cpu_to_je16(inode->i_uid);
ri.gid = cpu_to_je16(inode->i_gid);
ri.atime = ri.ctime = ri.mtime = cpu_to_je32(cyg_timestamp());
ri.atime = ri.ctime = ri.mtime = cpu_to_je32(jffs2_get_timestamp());
if (pos > inode->i_size) {
int err;
@ -1682,7 +1641,6 @@ static int jffs2_fo_dirread(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio)
int nlen = sizeof (ent->d_name) - 1;
off_t len = uio->uio_iov[0].iov_len;
struct jffs2_inode_info *f;
struct jffs2_sb_info *c;
struct _inode *inode = d_inode;
struct jffs2_full_dirent *fd;
unsigned long offset, curofs;
@ -1695,7 +1653,6 @@ static int jffs2_fo_dirread(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio)
(KERN_DEBUG "jffs2_readdir() for dir_i #%lu\n", d_inode->i_ino));
f = JFFS2_INODE_INFO(inode);
c = JFFS2_SB_INFO(inode->i_sb);
offset = fp->f_offset;
@ -1823,19 +1780,14 @@ void jffs2_gc_release_page(struct jffs2_sb_info *c,
static struct _inode *new_inode(struct super_block *sb)
{
// Only called in write.c jffs2_new_inode
// Always adds itself to inode cache
struct _inode *inode;
struct _inode *cached_inode;
inode = malloc(sizeof (struct _inode));
inode = rt_malloc(sizeof (struct _inode));
if (inode == NULL)
return 0;
D2(printf
("malloc new_inode %x ####################################\n",
D2(printf("malloc new_inode %x ####################################\n",
inode));
memset(inode, 0, sizeof (struct _inode));
@ -1945,7 +1897,7 @@ void jffs2_iput(struct _inode *i)
parent = i->i_parent;
jffs2_clear_inode(i);
memset(i, 0x5a, sizeof(*i));
free(i);
rt_free(i);
if (parent && parent != i) {
i = parent;
@ -2021,7 +1973,7 @@ struct _inode *jffs2_new_inode (struct _inode *dir_i, int mode, struct jffs2_raw
up(&(f->sem));
jffs2_clear_inode(inode);
memset(inode, 0x6a, sizeof(*inode));
free(inode);
rt_free(inode);
return ERR_PTR(ret);
}
inode->i_nlink = 1;
@ -2029,7 +1981,7 @@ struct _inode *jffs2_new_inode (struct _inode *dir_i, int mode, struct jffs2_raw
inode->i_mode = jemode_to_cpu(ri->mode);
inode->i_gid = je16_to_cpu(ri->gid);
inode->i_uid = je16_to_cpu(ri->uid);
inode->i_atime = inode->i_ctime = inode->i_mtime = cyg_timestamp();
inode->i_atime = inode->i_ctime = inode->i_mtime = jffs2_get_timestamp();
ri->atime = ri->mtime = ri->ctime = cpu_to_je32(inode->i_mtime);
inode->i_size = 0;

View File

@ -21,62 +21,62 @@
struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize)
{
return malloc(sizeof(struct jffs2_full_dirent) + namesize);
return rt_malloc(sizeof(struct jffs2_full_dirent) + namesize);
}
void jffs2_free_full_dirent(struct jffs2_full_dirent *x)
{
free(x);
rt_free(x);
}
struct jffs2_full_dnode *jffs2_alloc_full_dnode(void)
{
return malloc(sizeof(struct jffs2_full_dnode));
return rt_malloc(sizeof(struct jffs2_full_dnode));
}
void jffs2_free_full_dnode(struct jffs2_full_dnode *x)
{
free(x);
rt_free(x);
}
struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void)
{
return malloc(sizeof(struct jffs2_raw_dirent));
return rt_malloc(sizeof(struct jffs2_raw_dirent));
}
void jffs2_free_raw_dirent(struct jffs2_raw_dirent *x)
{
free(x);
rt_free(x);
}
struct jffs2_raw_inode *jffs2_alloc_raw_inode(void)
{
return malloc(sizeof(struct jffs2_raw_inode));
return rt_malloc(sizeof(struct jffs2_raw_inode));
}
void jffs2_free_raw_inode(struct jffs2_raw_inode *x)
{
free(x);
rt_free(x);
}
struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void)
{
return malloc(sizeof(struct jffs2_tmp_dnode_info));
return rt_malloc(sizeof(struct jffs2_tmp_dnode_info));
}
void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x)
{
free(x);
rt_free(x);
}
struct jffs2_node_frag *jffs2_alloc_node_frag(void)
{
return malloc(sizeof(struct jffs2_node_frag));
return rt_malloc(sizeof(struct jffs2_node_frag));
}
void jffs2_free_node_frag(struct jffs2_node_frag *x)
{
free(x);
rt_free(x);
}
#if CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0
@ -92,12 +92,12 @@ void jffs2_destroy_slab_caches(void)
struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void)
{
return malloc(sizeof(struct jffs2_raw_node_ref));
return rt_malloc(sizeof(struct jffs2_raw_node_ref));
}
void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x)
{
free(x);
rt_free(x);
}
#else // CYGNUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE == 0
@ -150,7 +150,7 @@ void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x)
struct jffs2_inode_cache *jffs2_alloc_inode_cache(void)
{
struct jffs2_inode_cache *ret = malloc(sizeof(struct jffs2_inode_cache));
struct jffs2_inode_cache *ret = rt_malloc(sizeof(struct jffs2_inode_cache));
D1(printk(KERN_DEBUG "Allocated inocache at %p\n", ret));
return ret;
}
@ -158,6 +158,6 @@ struct jffs2_inode_cache *jffs2_alloc_inode_cache(void)
void jffs2_free_inode_cache(struct jffs2_inode_cache *x)
{
D1(printk(KERN_DEBUG "Freeing inocache at %p\n", x));
free(x);
rt_free(x);
}

View File

@ -15,8 +15,6 @@
#define __JFFS2_OS_ECOS_H__
#include "jffs2_config.h"
#include <rtthread.h>
#define malloc rt_malloc
#define free rt_free
#define printf rt_kprintf
//#include <pkgconf/fs_jffs2.h>
@ -117,7 +115,7 @@ static inline unsigned int full_name_hash(const unsigned char * name, unsigned i
#define JFFS2_F_I_RDEV_MIN(f) ((OFNI_EDONI_2SFFJ(f)->i_rdev)&0xff)
#define JFFS2_F_I_RDEV_MAJ(f) ((OFNI_EDONI_2SFFJ(f)->i_rdev)>>8)
#define get_seconds cyg_timestamp
#define get_seconds jffs2_get_timestamp
struct _inode {
cyg_uint32 i_ino;
@ -215,13 +213,13 @@ uint32_t jffs2_to_os_mode (uint32_t jmode);
/* flashio.c */
cyg_bool jffs2_flash_read(struct jffs2_sb_info *c, cyg_uint32 read_buffer_offset,
int jffs2_flash_read(struct jffs2_sb_info *c, cyg_uint32 read_buffer_offset,
const size_t size, size_t * return_size, unsigned char * write_buffer);
cyg_bool jffs2_flash_write(struct jffs2_sb_info *c, cyg_uint32 write_buffer_offset,
int jffs2_flash_write(struct jffs2_sb_info *c, cyg_uint32 write_buffer_offset,
const size_t size, size_t * return_size, unsigned char * read_buffer);
int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct iovec *vecs,
unsigned long count, loff_t to, size_t *retlen);
cyg_bool jffs2_flash_erase(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
int jffs2_flash_erase(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
// dir-ecos.c
struct _inode *jffs2_lookup(struct _inode *dir_i, const unsigned char *name, int namelen);

View File

@ -15,8 +15,6 @@
#define __JFFS2_OS_RTTHREAD_H__
#include "jffs2_config.h"
#include <rtthread.h>
#define free rt_free
#define printf rt_kprintf
#define printf rt_kprintf
//#include <pkgconf/fs_jffs2.h>
@ -115,7 +113,7 @@ static inline unsigned int full_name_hash(const unsigned char * name, unsigned i
#define JFFS2_F_I_RDEV_MIN(f) ((OFNI_EDONI_2SFFJ(f)->i_rdev)&0xff)
#define JFFS2_F_I_RDEV_MAJ(f) ((OFNI_EDONI_2SFFJ(f)->i_rdev)>>8)
#define get_seconds cyg_timestamp
#define get_seconds jffs2_get_timestamp
struct _inode {
cyg_uint32 i_ino;
@ -213,13 +211,13 @@ uint32_t jffs2_to_os_mode (uint32_t jmode);
/* flashio.c */
cyg_bool jffs2_flash_read(struct jffs2_sb_info *c, cyg_uint32 read_buffer_offset,
int jffs2_flash_read(struct jffs2_sb_info *c, cyg_uint32 read_buffer_offset,
const size_t size, size_t * return_size, unsigned char * write_buffer);
cyg_bool jffs2_flash_write(struct jffs2_sb_info *c, cyg_uint32 write_buffer_offset,
int jffs2_flash_write(struct jffs2_sb_info *c, cyg_uint32 write_buffer_offset,
const size_t size, size_t * return_size, unsigned char * read_buffer);
int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct iovec *vecs,
unsigned long count, loff_t to, size_t *retlen);
cyg_bool jffs2_flash_erase(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
int jffs2_flash_erase(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
// dir-ecos.c
struct _inode *jffs2_lookup(struct _inode *dir_i, const unsigned char *name, int namelen);