mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-21 02:06:14 +08:00
remove efsl from device file system.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@506 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
@@ -3,7 +3,6 @@ Import('rtconfig')
|
||||
Import('RTT_ROOT')
|
||||
|
||||
dfs = Split("""
|
||||
src/dfs_cache.c
|
||||
src/dfs_fs.c
|
||||
src/dfs_init.c
|
||||
src/dfs_posix.c
|
||||
@@ -22,21 +21,6 @@ filesystems/fatfs/fatfs_init.c
|
||||
filesystems/fatfs_misc.c
|
||||
filesystems/fatfs/fatfs_mount.c""")
|
||||
|
||||
# DFS-EFSL options
|
||||
efsl = Split("""
|
||||
filesystems/efsl/src/base/efs.c
|
||||
filesystems/efsl/src/base/extract.c
|
||||
filesystems/efsl/src/base/partition.c
|
||||
filesystems/efsl/src/base/plibc.c
|
||||
filesystems/efsl/src/fs/vfat/dir.c
|
||||
filesystems/efsl/src/fs/vfat/fat.c
|
||||
filesystems/efsl/src/fs/vfat/file.c
|
||||
filesystems/efsl/src/fs/vfat/fs.c
|
||||
filesystems/efsl/src/fs/vfat/ls.c
|
||||
filesystems/efsl/src/fs/vfat/time.c
|
||||
filesystems/efsl/src/fs/vfat/ui.c
|
||||
""")
|
||||
|
||||
# DFS-ELMFAT options
|
||||
elmfat = Split("""
|
||||
filesystems/elmfat/dfs_elm.c
|
||||
@@ -72,10 +56,6 @@ if rtconfig.RT_USING_DFS_YAFFS2:
|
||||
src_local = src_local + yaffs2_main + yaffs2_comm
|
||||
path = path + [RTT_ROOT + '/filesystem/dfs/filesystems/yaffs2', RTT_ROOT + '/filesystem/dfs/filesystems/yaffs2/direct']
|
||||
|
||||
if rtconfig.RT_USING_DFS_EFSL:
|
||||
src_local = src_local + efsl
|
||||
path = path + [RTT_ROOT + '/filesystem/dfs/filesystems/efsl/src/include', RTT_ROOT + '/filesystem/dfs/filesystems/efsl/src/base/include', RTT_ROOT + '/filesystem/dfs/filesystems/efsl/src/fs/vfat/include']
|
||||
|
||||
if rtconfig.RT_USING_DFS_ELMFAT:
|
||||
src_local = src_local + elmfat
|
||||
path = path + [RTT_ROOT + '/filesystem/dfs/filesystems/elmfat']
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#+------------------------------------------------------------------------------
|
||||
#| Device FileSystem
|
||||
#+------------------------------------------------------------------------------
|
||||
#| Copyright 2004, 2005 www.fayfayspace.org.
|
||||
#| All rights reserved.
|
||||
#+------------------------------------------------------------------------------
|
||||
#| File : config.mk, the configuration of makefile
|
||||
#+------------------------------------------------------------------------------
|
||||
#| Chang Logs:
|
||||
#| Date Author notes
|
||||
#| 2005-01-22 ffxz The first version.
|
||||
#+------------------------------------------------------------------------------
|
||||
|
||||
KERNEL_ROOT=$(DFS_ROOT_DIR)/../..
|
||||
include $(KERNEL_ROOT)/config.mk
|
||||
|
||||
CFLAGS +=-I$(KERNEL_ROOT)/include -I$(DFS_ROOT_DIR)/include -I.
|
||||
|
||||
# Source and objects
|
||||
DFS_SRC = $(DFS_ROOT_DIR)/src/dfs_fs.c $(DFS_ROOT_DIR)/src/dfs_init.c \
|
||||
$(DFS_ROOT_DIR)/src/dfs_util.c $(DFS_ROOT_DIR)/src/dfs_raw.c \
|
||||
$(DFS_ROOT_DIR)/src/dfs_api.c $(DFS_ROOT_DIR)/src/dfs_task.c \
|
||||
$(DFS_ROOT_DIR)/src/dfs_cache.c
|
||||
|
||||
ifneq ($(RT_USING_NEWLIB), 1)
|
||||
DFS_SRC += $(DFS_ROOT_DIR)/src/dfs_posix.c
|
||||
endif
|
||||
|
||||
DFS_OBJS= $(DFS_SRC:.c=.o)
|
||||
|
||||
FAT_SRC = $(DFS_ROOT_DIR)/filesystems/fatfs/fatfs_init.c \
|
||||
$(DFS_ROOT_DIR)/filesystems/fatfs/fatfs_mount.c \
|
||||
$(DFS_ROOT_DIR)/filesystems/fatfs/fatfs_fat.c \
|
||||
$(DFS_ROOT_DIR)/filesystems/fatfs/fatfs_misc.c \
|
||||
$(DFS_ROOT_DIR)/filesystems/fatfs/fatfs_file.c \
|
||||
$(DFS_ROOT_DIR)/filesystems/fatfs/fatfs_cache.c \
|
||||
$(DFS_ROOT_DIR)/filesystems/fatfs/fatfs_filename.c \
|
||||
$(DFS_ROOT_DIR)/filesystems/fatfs/fatfs_direntry.c \
|
||||
$(DFS_ROOT_DIR)/filesystems/fatfs/fatfs_mkfs.c
|
||||
FAT_OBJS = $(FAT_SRC:.c=.o)
|
||||
@@ -1,39 +0,0 @@
|
||||
CHANGEFILE
|
||||
----------
|
||||
|
||||
This is the Changefile for the development 0.3 branch of EFSL.
|
||||
Recording began with EFSL-0.3.3
|
||||
|
||||
0.3.5
|
||||
-----
|
||||
* Added warning in documentation that it is outdated
|
||||
* Changed structure definitions
|
||||
* Implemnted full-feature cp
|
||||
* Renamed some efsl-functions (all starting with EFSL_)
|
||||
* Added another example for AVR.
|
||||
* Updated docs on getting started on AVR.
|
||||
|
||||
0.3.4
|
||||
-----
|
||||
* Fixed avr support
|
||||
* Created new avr example + makefile
|
||||
* Some more work on new fsutils
|
||||
|
||||
0.3.3
|
||||
-----
|
||||
|
||||
* Renamed src/core to src/base
|
||||
* Implemented new hwInterface structure
|
||||
Support for multiple hwEndpoints in one project
|
||||
* Modified SD_SPI to work as a general protocol
|
||||
* Modified Linuxfile to the new hwInterface model
|
||||
* Created a new efs_configger, now supports every
|
||||
combination of partitions/disc
|
||||
* Implemented full support for little and big endian
|
||||
machines, as well as for little and big endian
|
||||
filesystems
|
||||
* Created new build system, for multiple platforms,
|
||||
configurable from one file
|
||||
* Changes cpo to use the new library functions
|
||||
* Broke both dsp & atmega support
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
efsl-0.3.6
|
||||
|
||||
[Embedded Filesystems Library]
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,57 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : extract.c *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : This file contains functions to copy structures that get *
|
||||
* corrupted when using direct memory copy *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "extract.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
#if !(defined(BYTE_ALIGNMENT))
|
||||
#warning "Compiling f_setbxx"
|
||||
void ex_setb16(euint8* buf,euint16 data)
|
||||
{
|
||||
buf[1] = data>>8;
|
||||
buf[0] = data>>0;
|
||||
}
|
||||
|
||||
void ex_setb32(euint8* buf,euint32 data)
|
||||
{
|
||||
buf[3] = data>>24;
|
||||
buf[2] = data>>16;
|
||||
buf[1] = data>>8;
|
||||
buf[0] = data>>0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : efs.c *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : This should become the wrapper around efs. It will contain *
|
||||
* functions like efs_init etc. *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
#ifndef __EFS_H__
|
||||
#define __EFS_H__
|
||||
|
||||
/*****************************************************************************/
|
||||
#include <dfs_fs.h>
|
||||
|
||||
#include "etypes.h"
|
||||
#include "config.h"
|
||||
#include "extract.h"
|
||||
#include "partition.h"
|
||||
|
||||
/* WARNING !!!!
|
||||
* These includes DO NOT BELONG HERE,
|
||||
* remove them when the VFS layer is implemented !!!!
|
||||
*/
|
||||
#include "fs.h"
|
||||
#include "file.h"
|
||||
#include "tm.h"
|
||||
#include "ui.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
#define LINUX_FILE_CONFIG 0x00
|
||||
#define AVR_SD_CONFIG 0x01
|
||||
/*****************************************************************************/
|
||||
|
||||
#define efs_read_sectors(device, start, count, buf) rt_device_read(device, \
|
||||
(start) * SECTOR_SIZE, (buf), (count) * SECTOR_SIZE) / SECTOR_SIZE
|
||||
#define efs_write_sectors(device, start, count, buf) rt_device_write(device, \
|
||||
(start) * SECTOR_SIZE, (buf), (count) * SECTOR_SIZE) / SECTOR_SIZE
|
||||
|
||||
struct _efsl_fs {
|
||||
Partition partition;
|
||||
FileSystem filesystem;
|
||||
};
|
||||
typedef struct _efsl_fs efsl_fs;
|
||||
|
||||
/* EFS filesystem file operations */
|
||||
int efs_mount(struct dfs_filesystem* fs);
|
||||
int efs_unmount(struct dfs_filesystem* fs);
|
||||
int efs_open(struct dfs_fd* file);
|
||||
int efs_close(struct dfs_fd* file);
|
||||
int efs_ioctl(struct dfs_fd* file, int cmd, void* args);
|
||||
int efs_read(struct dfs_fd* file, void* buf, rt_size_t len);
|
||||
int efs_write(struct dfs_fd* file, const void* buf, rt_size_t len);
|
||||
int efs_lseek(struct dfs_fd* file, rt_off_t offset);
|
||||
int efs_getdents(struct dfs_fd* file, struct dfs_dirent* dirp, rt_uint32_t count);
|
||||
int efs_unlink(struct dfs_filesystem* fs, const char* path);
|
||||
int efs_stat(struct dfs_filesystem* fs, const char *path, struct dfs_stat *st);
|
||||
int efs_rename(struct dfs_filesystem* fs, const char* oldpath, const char* newpath);
|
||||
|
||||
/*****************************************************************************/
|
||||
int efsl_init(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : extract.h *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : This file contains functions to copy structures that get *
|
||||
* corrupted when using direct memory copy *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
#ifndef __EXTRACT_H_
|
||||
#define __EXTRACT_H_
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "config.h"
|
||||
#include "etypes.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
#if !(defined(HOST_LITTLE_ENDIAN)) && !(defined(HOST_BIG_ENDIAN))
|
||||
#error Endianess undefined, see config.h
|
||||
#elif defined(HOST_LITTLE_ENDIAN) && (defined(HOST_BIG_ENDIAN))
|
||||
#error Endianess defined as little and big, see config.h
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define end_conv16(x) ((((euint16)(x) & 0xff00) >> 8) | \
|
||||
(((euint16)(x) & 0x00ff) << 8))
|
||||
#define end_conv32(x) ((((euint32)(x) & 0xff000000) >> 24) | \
|
||||
(((euint32)(x) & 0x00ff0000) >> 8) | \
|
||||
(((euint32)(x) & 0x0000ff00) << 8) | \
|
||||
(((euint32)(x) & 0x000000ff) << 24))
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if defined(BYTE_ALIGNMENT)
|
||||
#define ex_getb16(buf) (*((euint16*)(buf)))
|
||||
#define ex_setb16(buf,data) *((euint16*)(buf))=(data)
|
||||
#define ex_getb32(buf) (*((euint32*)(buf)))
|
||||
#define ex_setb32(buf,data) *((euint32*)(buf))=(data)
|
||||
#else
|
||||
#define ex_getb16(buf) \
|
||||
((euint16)(*((euint8*)(buf)+1)<<8) + \
|
||||
(euint16)(*((euint8*)(buf)+0)<<0))
|
||||
void ex_setb16(euint8* buf,euint16 data);
|
||||
#define ex_getb32(buf) \
|
||||
((euint32)(*((euint8*)(buf)+3)<<24) + \
|
||||
(euint32)(*((euint8*)(buf)+2)<<16) + \
|
||||
(euint32)(*((euint8*)(buf)+1)<<8) + \
|
||||
(euint32)(*((euint8*)(buf)+0)<<0))
|
||||
void ex_setb32(euint8* buf,euint32 data);
|
||||
#endif
|
||||
|
||||
#if defined(HOST_LITTLE_ENDIAN)
|
||||
#define ex_lth16(buf) ex_getb16(buf)
|
||||
#define ex_lth32(buf) ex_getb32(buf)
|
||||
#define ex_bth16(buf) end_conv16(ex_getb16(buf))
|
||||
#define ex_bth32(buf) end_conv32(ex_getb32(buf))
|
||||
|
||||
#define ex_htl16(buf) ex_setb16(buf)
|
||||
#define ex_htl32(buf) ex_setb32(buf)
|
||||
#define ex_htb16(buf) ex_setb16(end_conv16(buf))
|
||||
#define ex_htb32(buf) ex_setb32(end_conv32(buf))
|
||||
#elif defined(HOST_BIG_ENDIAN)
|
||||
#define ex_lth16(buf) end_conv16(ex_getb16(buf))
|
||||
#define ex_lth32(buf) end_conv32(ex_getb32(buf))
|
||||
#define ex_bth16(buf) ex_getb16(buf)
|
||||
#define ex_bth32(buf) ex_getb32(buf)
|
||||
|
||||
#define ex_htl16(buf) ex_setb16(end_conv16(buf))
|
||||
#define ex_htl32(buf) ex_setb32(end_conv32(buf))
|
||||
#define ex_htb16(buf) ex_setb16(buf)
|
||||
#define ex_htb32(buf) ex_setb32(buf)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : partition.c *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : These functions are partition specific. Searching FAT type *
|
||||
* partitions and read/write functions to partitions. *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
#ifndef __PARTITION_H__
|
||||
#define __PARTITION_H__
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "config.h"
|
||||
#include "error.h"
|
||||
#include "etypes.h"
|
||||
// #include "ioman.h"
|
||||
#include <dfs_cache.h>
|
||||
/*****************************************************************************/
|
||||
|
||||
#define PT_FAT12 0x01
|
||||
#define PT_FAT16A 0x04
|
||||
#define PT_FAT16 0x06
|
||||
#define PT_FAT32 0x0B
|
||||
#define PT_FAT32A 0x5C
|
||||
#define PT_FAT16B 0x5E
|
||||
|
||||
struct _Partition{
|
||||
IOManager *ioman;
|
||||
};
|
||||
typedef struct _Partition Partition;
|
||||
|
||||
void part_initPartition(Partition *part);
|
||||
eint16 part_isFatPart(euint8 type);
|
||||
esint8 part_readBuf(Partition *part, euint32 address, euint8* buf);
|
||||
esint8 part_readPartBuf(Partition *part, euint32 address, euint8* buf, euint32 offset, euint16 len);
|
||||
eint16 part_writeBuf(Partition *part,euint32 address,euint8* buf);
|
||||
euint8* part_getSect(Partition *part, euint32 address,euint8 mode);
|
||||
esint8 part_relSect(Partition *part, euint8* buf);
|
||||
|
||||
esint8 part_flushPart(Partition *part,euint32 addr_l, euint32 addr_h);
|
||||
|
||||
esint8 part_directSectorRead(Partition *part, euint32 address, euint8* buf, euint32 numsector);
|
||||
esint8 part_directSectorWrite(Partition *part, euint32 address, euint8* buf, euint32 numsector);
|
||||
|
||||
#include "extract.h"
|
||||
|
||||
#endif
|
||||
@@ -1,48 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : plibc.c *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : This file contains replacements of common c library functions *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
#ifndef __PLIBC_H__
|
||||
#define __PLIBC_H__
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "etypes.h"
|
||||
#include "config.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
euint16 strMatch(eint8* bufa, eint8*bufb,euint32 n);
|
||||
void memCpy(void* psrc, void* pdest, euint32 size);
|
||||
void memClr(void *pdest,euint32 size);
|
||||
void memSet(void *pdest,euint32 size,euint8 data);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,125 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : partition.c *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : These functions are partition specific. Searching FAT type *
|
||||
* partitions and read/write functions to partitions. *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "partition.h"
|
||||
#include "efs.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* void part_initPartition(Partition *part,Disc* refDisc)
|
||||
* Description: This function searches the 4 partitions for a FAT class partition
|
||||
* and marks the first one found as the active to be used partition.
|
||||
*/
|
||||
void part_initPartition(Partition *part)
|
||||
{
|
||||
part_setError(part,PART_NOERROR);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
/* ****************************************************************************
|
||||
* eint16 part_isFatPart(euint8 type)
|
||||
* Description: This functions checks if a partitiontype (eint8) is of the FAT
|
||||
* type in the broadest sense. I
|
||||
* Return value: If it is FAT, returns 1, otherwise 0.
|
||||
*/
|
||||
eint16 part_isFatPart(euint8 type)
|
||||
{
|
||||
if(type == PT_FAT12 ||
|
||||
type == PT_FAT16A ||
|
||||
type == PT_FAT16 ||
|
||||
type == PT_FAT32 ||
|
||||
type == PT_FAT32A ||
|
||||
type == PT_FAT16B )
|
||||
{
|
||||
return(1);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
esint8 part_readBuf(Partition *part, euint32 address, euint8* buf)
|
||||
{
|
||||
return efs_read_sectors(part->ioman->device, address, 1, buf);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
* eint16 part_writeBuf(Partition *part,euint32 address,euint8* buf)
|
||||
* Description: This function writes 512 bytes, from buf. It's offset is address
|
||||
* sectors from the beginning of the partition.
|
||||
* Return value: It returns whatever the hardware function returns. (-1=error)
|
||||
*/
|
||||
eint16 part_writeBuf(Partition *part,euint32 address,euint8* buf)
|
||||
{
|
||||
/*DBG((TXT("part_writeBuf :: %li\n"),address));*/
|
||||
return efs_write_sectors(part->ioman->device, address, 1, buf);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* euint8* part_getSect(Partition *part, euint32 address, euint8 mode)
|
||||
* Description: This function calls ioman_getSector, but recalculates the sector
|
||||
* address to be partition relative.
|
||||
* Return value: Whatever getSector returns. (pointer or 0)
|
||||
*/
|
||||
euint8* part_getSect(Partition *part, euint32 address, euint8 mode)
|
||||
{
|
||||
return(ioman_getSector(part->ioman,address,mode));
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
* esint8 part_relSect(Partition *part, euint8* buf)
|
||||
* Description: This function calls ioman_releaseSector.
|
||||
* Return value: Whatever releaseSector returns.
|
||||
*/
|
||||
esint8 part_relSect(Partition *part, euint8* buf)
|
||||
{
|
||||
return(ioman_releaseSector(part->ioman,buf));
|
||||
}
|
||||
|
||||
esint8 part_flushPart(Partition *part,euint32 addr_l, euint32 addr_h)
|
||||
{
|
||||
return ioman_flushRange(part->ioman,addr_l,addr_h);
|
||||
}
|
||||
|
||||
esint8 part_directSectorRead(Partition *part, euint32 address, euint8* buf, euint32 numsector)
|
||||
{
|
||||
return ioman_directSectorRead(part->ioman, address, buf, numsector);
|
||||
}
|
||||
|
||||
esint8 part_directSectorWrite(Partition *part,euint32 address, euint8* buf, euint32 numsector)
|
||||
{
|
||||
return ioman_directSectorWrite(part->ioman, address, buf, numsector);
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : plibc.c *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : This file contains replacements of common c library functions *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "plibc.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* unsigned short strMatch(char* bufa, char*bufb, unsigned long n)
|
||||
* Description: Compares bufa and bufb for a length of n bytes.
|
||||
* Return value: Returns the number of character NOT matching.
|
||||
*/
|
||||
euint16 strMatch(eint8* bufa, eint8*bufb,euint32 n)
|
||||
{
|
||||
euint32 c;
|
||||
euint16 res=0;
|
||||
for(c=0;c<n;c++)if(bufa[c]!=bufb[c])res++;
|
||||
return(res);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
/* ****************************************************************************
|
||||
* void memCpy(void* psrc, void* pdest, unsigned long size)
|
||||
* Description: Copies the contents of psrc into pdest on a byte per byte basis.
|
||||
* The total number of bytes copies is size.
|
||||
*/
|
||||
void memCpy(void* psrc, void* pdest, euint32 size)
|
||||
{
|
||||
while(size>0){
|
||||
*((eint8*)pdest+size-1)=*((eint8*)psrc+size-1);
|
||||
size--;
|
||||
}
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
void memClr(void *pdest,euint32 size)
|
||||
{
|
||||
while(size>0){
|
||||
*(((eint8*)pdest)+size-1)=0x00;
|
||||
size--;
|
||||
}
|
||||
}
|
||||
|
||||
void memSet(void *pdest,euint32 size,euint8 data)
|
||||
{
|
||||
while(size>0){
|
||||
*(((eint8*)pdest)+size-1)=data;
|
||||
size--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,363 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : dir.c *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : The functions of dir.c are part of fs.c, they deal with all *
|
||||
* the directory specific stuff. *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "dir.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* void dir_getFileStructure(FileSystem *fs,FileRecord *filerec,FileLocation *loc)
|
||||
* Description: This function stores the filerecord located at loc in filerec.
|
||||
* It fetches the required sector for this.
|
||||
* Return value: void
|
||||
*/
|
||||
void dir_getFileStructure(FileSystem *fs,FileRecord *filerec,FileLocation *loc)
|
||||
{
|
||||
euint8 *buf;
|
||||
|
||||
buf=part_getSect(fs->part,loc->Sector,IOM_MODE_READONLY);
|
||||
*filerec=*(((FileRecord*)buf)+loc->Offset);
|
||||
part_relSect(fs->part,buf);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* void dir_createDirectoryEntry(FileSystem *fs,FileRecord *filerec,FileLocation *loc)
|
||||
* Description: This function writes the filerecord stored in filerec to disc at
|
||||
* location loc.
|
||||
* Return value: void
|
||||
*/
|
||||
void dir_createDirectoryEntry(FileSystem *fs,FileRecord *filerec,FileLocation *loc)
|
||||
{
|
||||
euint8 *buf;
|
||||
|
||||
buf = part_getSect(fs->part,loc->Sector,IOM_MODE_READWRITE);
|
||||
memCpy(filerec,buf+(loc->Offset*sizeof(*filerec)),sizeof(*filerec));
|
||||
part_relSect(fs->part,buf);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* void dir_createDefaultEntry(FileSystem *fs,FileRecord *filerec,eint8* fatfilename)
|
||||
* Description: This function fills in a filerecord with safe default values, and
|
||||
* a given fatfilename. If your system has a means of knowing time, here is an
|
||||
* excellent place to apply it to the filerecord.
|
||||
* Return value: void
|
||||
*/
|
||||
void dir_createDefaultEntry(FileSystem *fs,FileRecord *filerec,eint8* fatfilename)
|
||||
{
|
||||
memCpy(fatfilename,filerec->FileName,11);
|
||||
filerec->Attribute=0x00;
|
||||
filerec->NTReserved=0x00;
|
||||
filerec->MilliSecTimeStamp=0x00;
|
||||
filerec->CreatedTime=time_getTime();
|
||||
filerec->CreatedDate=time_getDate();
|
||||
filerec->AccessDate=filerec->CreatedDate;
|
||||
filerec->FirstClusterHigh=0x0000;
|
||||
filerec->WriteTime=filerec->CreatedTime;
|
||||
filerec->WriteDate=filerec->CreatedDate;
|
||||
filerec->FirstClusterLow=0x0000;
|
||||
filerec->FileSize=0x00000000;
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* void dir_setFirstCluster(File *file,euint32 cluster_addr)
|
||||
* Description: This function requires modification to release it from
|
||||
* depending on the file object.
|
||||
* Return value:
|
||||
*/
|
||||
void dir_setFirstCluster(FileSystem *fs,FileLocation *loc,euint32 cluster_addr)
|
||||
{
|
||||
euint8 *buf;
|
||||
|
||||
buf = part_getSect(fs->part,loc->Sector,IOM_MODE_READWRITE);
|
||||
(((FileRecord*)buf)+loc->Offset)->FirstClusterHigh=cluster_addr>>16;
|
||||
(((FileRecord*)buf)+loc->Offset)->FirstClusterLow=cluster_addr&0xFFFF;
|
||||
part_relSect(fs->part,buf);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* void dir_setFileSize(FileSystem *fs, FileLocation *loc,euint32 numbytes)
|
||||
* Description: This function changes the filesize recorded at loc->Sector
|
||||
* to 'numbytes'.
|
||||
* Return value: void
|
||||
*/
|
||||
void dir_setFileSize(FileSystem *fs, FileLocation *loc,euint32 numbytes)
|
||||
{
|
||||
euint8 *buf;
|
||||
|
||||
buf = part_getSect(fs->part,loc->Sector,IOM_MODE_READWRITE);
|
||||
(((FileRecord*)buf)+loc->Offset)->FileSize=numbytes;
|
||||
part_relSect(fs->part,buf);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* esint8 dir_updateDirectoryEntry(FileSystem *fs,FileRecord *entry,FileLocation *loc))
|
||||
* This function changes the entire entity stores at loc to the data recorded
|
||||
* in entry. This is for custom updates to the directoryentry.
|
||||
* Return value: 0 on success, -1 on failure
|
||||
*/
|
||||
esint8 dir_updateDirectoryEntry(FileSystem *fs,FileRecord *entry,FileLocation *loc)
|
||||
{
|
||||
euint8 *buf;
|
||||
|
||||
buf = part_getSect(fs->part,loc->Sector,IOM_MODE_READWRITE);
|
||||
memCpy(entry,buf+(loc->Offset*sizeof(*entry)),sizeof(*entry));
|
||||
part_relSect(fs->part,buf);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
* euint32 dir_findFileinBuf(euint8 *buf, eint8 *fatname, FileLocation *loc)
|
||||
* This function searches for a given fatfilename in the buffer provided.
|
||||
* It will iterate through the 16 direntry's in the buffer and searches
|
||||
* for the fatfilename. If found, it will store the offset and attribute
|
||||
* entry of the directoryrecord in the loc structure.
|
||||
* If loc is 0, then it's members are not touched.
|
||||
* Return value: This function returns 0 when it cannot find the file,
|
||||
* if it can find the file it will return the first cluster number.
|
||||
*/
|
||||
euint32 dir_findFileinBuf(euint8 *buf, eint8 *fatname, FileLocation *loc)
|
||||
{
|
||||
FileRecord fileEntry;
|
||||
euint8 c;
|
||||
|
||||
for(c=0; c<16; c++)
|
||||
{
|
||||
fileEntry = *(((FileRecord*)buf) + c);
|
||||
/* Check if the entry is for short filenames */
|
||||
if( !( (fileEntry.Attribute & 0x0F) == 0x0F ) )
|
||||
{
|
||||
if( strMatch((eint8*)fileEntry.FileName,fatname,11) == 0 )
|
||||
{
|
||||
/* The entry has been found, return the location in the dir */
|
||||
if(loc)loc->Offset = c;
|
||||
if(loc)loc->attrib = fileEntry.Attribute;
|
||||
if((((euint32 )fileEntry.FirstClusterHigh)<<16)+ fileEntry.FirstClusterLow==0){
|
||||
return(1); /* Lie about cluster, 0 means not found! */
|
||||
}else{
|
||||
return
|
||||
(
|
||||
(((euint32 )fileEntry.FirstClusterHigh)<<16)
|
||||
+ fileEntry.FirstClusterLow
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
* euint32 dir_findFreeEntryinBuf(euint8* buf, FileLocation *loc)
|
||||
* This function searches for a free entry in a given sector 'buf'.
|
||||
* It will put the offset into the loc->Offset field, given that loc is not 0.
|
||||
* Return value: 1 when it found a free spot, 0 if it hasn't.
|
||||
*/
|
||||
euint32 dir_findFreeEntryinBuf(euint8* buf, FileLocation *loc)
|
||||
{
|
||||
FileRecord fileEntry;
|
||||
euint8 c;
|
||||
|
||||
for(c=0;c<16;c++){
|
||||
fileEntry = *(((FileRecord*)buf) + c);
|
||||
if( !( (fileEntry.Attribute & 0x0F) == 0x0F ) ){
|
||||
if(fileEntry.FileName[0] == 0x00 ||
|
||||
fileEntry.FileName[0] == 0xE5 ){
|
||||
if(loc)loc->Offset=c;
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
* euint32 dir_findinBuf(euint8 *buf, eint8 *fatname, FileLocation *loc)
|
||||
* Description: This function searches for a given fatfilename in a buffer.
|
||||
* Return value: Returns 0 on not found, and the firstcluster when the name is found.
|
||||
*/
|
||||
euint32 dir_findinBuf(euint8 *buf, eint8 *fatname, FileLocation *loc, euint8 mode)
|
||||
{
|
||||
switch(mode){
|
||||
case DIRFIND_FILE:
|
||||
return(dir_findFileinBuf(buf,fatname,loc));
|
||||
case DIRFIND_FREE:
|
||||
return(dir_findFreeEntryinBuf(buf,loc));
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* euint32 dir_findinCluster(FileSystem *fs,euint32 cluster,eint8 *fatname, FileLocation *loc, euint8 mode)
|
||||
* This function will search for an existing (fatname) or free directory entry
|
||||
* in a full cluster.
|
||||
* Return value: 0 on failure, firstcluster on finding file, and 1 on finding free spot.
|
||||
*/
|
||||
euint32 dir_findinCluster(FileSystem *fs,euint32 cluster,eint8 *fatname, FileLocation *loc, euint8 mode)
|
||||
{
|
||||
euint8 c,*buf=0;
|
||||
euint32 fclus;
|
||||
|
||||
for(c=0;c<fs->volumeId.SectorsPerCluster;c++){
|
||||
buf = part_getSect(fs->part,fs_clusterToSector(fs,cluster)+c,IOM_MODE_READONLY);
|
||||
fclus=dir_findinBuf(buf,fatname,loc,mode);
|
||||
|
||||
if(fclus)
|
||||
{
|
||||
if(loc)loc->Sector=fs_clusterToSector(fs,cluster)+c;
|
||||
part_relSect(fs->part,buf);
|
||||
return(fclus);
|
||||
}
|
||||
part_relSect(fs->part,buf);
|
||||
}
|
||||
part_relSect(fs->part,buf);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
* euint32 dir_findinDir(FileSystem *fs, eint8* fatname,euint32 firstcluster, FileLocation *loc, euint8 mode)
|
||||
* This function will search for an existing (fatname) or free directory entry
|
||||
* in a directory, following the clusterchains.
|
||||
* Return value: 0 on failure, firstcluster on finding file, and 1 on finding free spot.
|
||||
*/
|
||||
euint32 dir_findinDir(FileSystem *fs, eint8* fatname,euint32 firstcluster, FileLocation *loc, euint8 mode)
|
||||
{
|
||||
euint32 c=0,cluster;
|
||||
ClusterChain Cache;
|
||||
|
||||
Cache.DiscCluster = Cache.FirstCluster = firstcluster;
|
||||
Cache.LogicCluster = Cache.LastCluster = Cache.Linear = 0;
|
||||
|
||||
if(firstcluster <= 1){
|
||||
return(dir_findinRootArea(fs,fatname,loc,mode));
|
||||
}
|
||||
|
||||
while(!fat_LogicToDiscCluster(fs,&Cache,c++)){
|
||||
cluster=dir_findinCluster(fs,Cache.DiscCluster,fatname,loc,mode);
|
||||
if(cluster) return(cluster);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
* euint32 dir_findinDir(FileSystem *fs, eint8* fatname,euint32 firstcluster, FileLocation *loc, euint8 mode)
|
||||
* This function will search for an existing (fatname) or free directory entry
|
||||
* in the rootdirectory-area of a FAT12/FAT16 filesystem.
|
||||
* Return value: 0 on failure, firstcluster on finding file, and 1 on finding free spot.
|
||||
*/
|
||||
euint32 dir_findinRootArea(FileSystem *fs,eint8* fatname, FileLocation *loc, euint8 mode)
|
||||
{
|
||||
euint32 c,fclus;
|
||||
euint8 *buf=0;
|
||||
|
||||
if((fs->type != FAT12) && (fs->type != FAT16))return(0);
|
||||
|
||||
for(c=fs->FirstSectorRootDir;c<(fs->FirstSectorRootDir+fs->volumeId.RootEntryCount/32);c++){
|
||||
buf = part_getSect(fs->part,c,IOM_MODE_READONLY);
|
||||
fclus=dir_findinBuf(buf,fatname,loc,mode);
|
||||
if(fclus){
|
||||
if(loc)loc->Sector=c;
|
||||
part_relSect(fs->part,buf);
|
||||
return(fclus);
|
||||
}
|
||||
part_relSect(fs->part,buf);
|
||||
}
|
||||
part_relSect(fs->part,buf);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
* esint8 dir_getFatFileName(eint8* filename, eint8* fatfilename)
|
||||
* This function will take a full directory path, and strip off all leading
|
||||
* dirs and characters, leaving you with the MS-DOS notation of the actual filename.
|
||||
* Return value: 1 on success, 0 on not being able to produca a filename
|
||||
*/
|
||||
esint8 dir_getFatFileName(eint8* filename, eint8* fatfilename)
|
||||
{
|
||||
eint8 ffnamec[11],*next,nn=0;
|
||||
|
||||
memClr(ffnamec,11); memClr(fatfilename,11);
|
||||
next = filename;
|
||||
|
||||
if(*filename=='/')next++;
|
||||
|
||||
next=file_normalToFatName(next,ffnamec);
|
||||
while(next){
|
||||
memCpy(ffnamec,fatfilename,11);
|
||||
nn++;
|
||||
|
||||
next=file_normalToFatName(next,ffnamec);
|
||||
}
|
||||
if(nn)return(1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
* esint8 dir_addCluster(FileSystem *fs,euint32 firstCluster)
|
||||
* This function extends a directory by 1 cluster + optional the number of
|
||||
* clusters you want pre-allocated. It will also delete the contents of that
|
||||
* cluster. (or clusters)
|
||||
* Return value: 0 on success, -1 on fail
|
||||
*/
|
||||
esint8 dir_addCluster(FileSystem *fs,euint32 firstCluster)
|
||||
{
|
||||
euint32 lastc,logicalc;
|
||||
ClusterChain cache;
|
||||
|
||||
fs_initClusterChain(fs,&cache,firstCluster);
|
||||
if(fat_allocClusterChain(fs,&cache,1)){
|
||||
return(-1);
|
||||
}
|
||||
lastc = fs_getLastCluster(fs,&cache);
|
||||
if(CLUSTER_PREALLOC_DIRECTORY){
|
||||
if(fat_allocClusterChain(fs,&cache,CLUSTER_PREALLOC_DIRECTORY)){
|
||||
return(-1);
|
||||
}
|
||||
logicalc = fat_DiscToLogicCluster(fs,firstCluster,lastc);
|
||||
while(!fat_LogicToDiscCluster(fs,&cache,++logicalc)){
|
||||
fs_clearCluster(fs,cache.DiscCluster);
|
||||
}
|
||||
}else{
|
||||
fs_clearCluster(fs,lastc);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
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,86 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : dir.h *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : The functions of dir.c are part of fs.c, they deal with all *
|
||||
* the directory specific stuff. *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
#ifndef __DDIR_H__
|
||||
#define __DDIR_H__
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "config.h"
|
||||
#include "error.h"
|
||||
#include "fat.h"
|
||||
#include "plibc.h"
|
||||
#include "etypes.h"
|
||||
// #include "ioman.h"
|
||||
#include "tm.h"
|
||||
#include "fs.h"
|
||||
#include <dfs_cache.h>
|
||||
/*****************************************************************************/
|
||||
|
||||
#define ATTR_READ_ONLY 0x01
|
||||
#define ATTR_HIDDEN 0x02
|
||||
#define ATTR_SYSTEM 0x04
|
||||
#define ATTR_VOLUME_ID 0x08
|
||||
#define ATTR_DIRECTORY 0x10
|
||||
#define ATTR_ARCHIVE 0x20
|
||||
|
||||
#define OFFSET_DE_FILENAME 0
|
||||
#define OFFSET_DE_ATTRIBUTE 11
|
||||
#define OFFSET_DE_NTRESERVED 12
|
||||
#define OFFSET_DE_CRTIMETNT 13
|
||||
#define OFFSET_DE_CREATETIME 14
|
||||
#define OFFSET_DE_CREATEDATE 16
|
||||
#define OFFSET_DE_LASTACCESSDATE 18
|
||||
#define OFFSET_DE_FIRSTCLUSTERHIGH 20
|
||||
#define OFFSET_DE_WRITETIME 22
|
||||
#define OFFSET_DE_WRITEDATE 24
|
||||
#define OFFSET_DE_FIRSTCLUSTERLOW 26
|
||||
#define OFFSET_DE_FILESIZE 28
|
||||
|
||||
#define DIRFIND_FILE 0
|
||||
#define DIRFIND_FREE 1
|
||||
|
||||
void dir_getFileStructure(FileSystem *fs,FileRecord *filerec,FileLocation *loc);
|
||||
void dir_createDirectoryEntry(FileSystem *fs,FileRecord *filerec,FileLocation *loc);
|
||||
void dir_createDefaultEntry(FileSystem *fs,FileRecord *filerec,eint8* fatfilename);
|
||||
void dir_setFirstCluster(FileSystem *fs,FileLocation *loc,euint32 cluster_addr);
|
||||
void dir_setFileSize(FileSystem *fs,FileLocation *loc,euint32 numbytes);
|
||||
euint32 dir_findinRoot(FileSystem *fs,eint8 * fatname, FileLocation *loc);
|
||||
euint32 dir_findinDir(FileSystem *fs, eint8 * fatname, euint32 startCluster, FileLocation *loc, euint8 mode);
|
||||
euint32 dir_findinBuf(euint8 *buf,eint8 *fatname, FileLocation *loc, euint8 mode);
|
||||
euint32 dir_findinCluster(FileSystem *fs,euint32 cluster,eint8 *fatname, FileLocation *loc, euint8 mode);
|
||||
euint32 dir_findinRootArea(FileSystem *fs,eint8* fatname, FileLocation *loc, euint8 mode);
|
||||
esint8 dir_getFatFileName(eint8* filename, eint8* fatfilename);
|
||||
esint8 dir_updateDirectoryEntry(FileSystem *fs,FileRecord *entry,FileLocation *loc);
|
||||
esint8 dir_addCluster(FileSystem *fs,euint32 firstCluster);
|
||||
#endif
|
||||
@@ -1,63 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : fat.h *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : This file contains all the functions dealing with the FAT *
|
||||
* in a Microsoft FAT filesystem. It belongs under fs.c *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
#ifndef __FAT_H_
|
||||
#define __FAT_H_
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "config.h"
|
||||
#include "error.h"
|
||||
#include "file.h"
|
||||
#include "etypes.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
euint32 fat_getSectorAddressFatEntry(FileSystem *fs,euint32 cluster_addr);
|
||||
euint32 fat_getNextClusterAddress(FileSystem *fs, euint32 cluster_addr, euint16 *linear);
|
||||
void fat_setNextClusterAddress(FileSystem *fs,euint32 cluster_addr,euint32 next_cluster_addr);
|
||||
eint16 fat_isEocMarker(FileSystem *fs,euint32 fat_entry);
|
||||
euint32 fat_giveEocMarker(FileSystem *fs);
|
||||
euint32 fat_findClusterAddress(FileSystem *fs,euint32 cluster,euint32 offset, euint8 *linear);
|
||||
euint32 fat_getNextClusterAddressWBuf(FileSystem *fs,euint32 cluster_addr, euint8 * buf);
|
||||
void fat_setNextClusterAddressWBuf(FileSystem *fs,euint32 cluster_addr,euint32 next_cluster_addr,euint8 * buf);
|
||||
esint16 fat_getNextClusterChain(FileSystem *fs, ClusterChain *Cache);
|
||||
void fat_bogus(void);
|
||||
esint16 fat_LogicToDiscCluster(FileSystem *fs, ClusterChain *Cache,euint32 logiccluster);
|
||||
eint16 fat_allocClusterChain(FileSystem *fs,ClusterChain *Cache,euint32 num_clusters);
|
||||
eint16 fat_unlinkClusterChain(FileSystem *fs,ClusterChain *Cache);
|
||||
euint32 fat_countClustersInChain(FileSystem *fs,euint32 firstcluster);
|
||||
euint32 fat_DiscToLogicCluster(FileSystem *fs,euint32 firstcluster,euint32 disccluster);
|
||||
void fat_ShortnameToString(const euint8* src, eint8* nm);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,99 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : file.h *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : This file contains functions dealing with files such as: *
|
||||
* fopen, fread and fwrite. *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
#ifndef __FILE_H_
|
||||
#define __FILE_H_
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "config.h"
|
||||
#include "error.h"
|
||||
#include "tm.h"
|
||||
#include "fs.h"
|
||||
#include "dir.h"
|
||||
#include "plibc.h"
|
||||
#include "etypes.h"
|
||||
#include "fat.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
/* Operation flags */
|
||||
#define EFSL_O_RDONLY 0
|
||||
#define EFSL_O_WRONLY 1
|
||||
#define EFSL_O_RDWR 2
|
||||
#define EFSL_O_APPEND 8
|
||||
|
||||
#define FILE_STATUS_OPEN 0
|
||||
#define FILE_STATUS_WRITE 1
|
||||
|
||||
/*****************************************************************************\
|
||||
* File
|
||||
* ------
|
||||
* FileRecord DirEntry Copy of the FileRecord for this file
|
||||
* FileLocation Location Location of the direntry
|
||||
* FileSystem *fs Pointer to the filesystem this file is on
|
||||
* FileCache Cache Pointer to the cache object of the file
|
||||
* euint8 FileStatus Contains bitfield regarding filestatus
|
||||
* euint32 FilePtr Offsetpointer for fread/fwrite functions
|
||||
* euint32 FileSize Working copy of the filesize, always use this,
|
||||
it is more up to date than DirEntry->FileSize,
|
||||
which is only updated when flushing to disc.
|
||||
\*****************************************************************************/
|
||||
struct _File{
|
||||
FileRecord DirEntry;
|
||||
FileLocation Location; /* Location in directory!! */
|
||||
FileSystem *fs;
|
||||
ClusterChain Cache;
|
||||
euint8 FileStatus;
|
||||
euint32 FilePtr;
|
||||
euint32 FileSize;
|
||||
euint32 ref_count; /* Descriptor reference count */
|
||||
};
|
||||
typedef struct _File File;
|
||||
|
||||
|
||||
esint8 file_fopen(File *file, FileSystem *fs,eint8 *filename, eint32 mode);
|
||||
esint8 file_fclose(File *file);
|
||||
esint32 file_setpos(File *file,euint32 pos);
|
||||
euint32 file_fread(File *file,euint32 offset, euint32 size,euint8 *buf);
|
||||
euint32 file_read (File *file,euint32 size,euint8 *buf);
|
||||
euint32 file_fwrite(File* file,euint32 offset,euint32 size,euint8* buf);
|
||||
euint32 file_write (File* file,euint32 size,euint8* buf);
|
||||
eint8* file_normalToFatName(eint8* filename,eint8* fatfilename);
|
||||
euint8 file_validateChar(euint8 c);
|
||||
void file_initFile(File *file, FileSystem *fs, FileLocation *loc);
|
||||
eint16 file_allocClusterChain(File *file,euint32 num_clusters);
|
||||
void file_setAttr(File* file,euint8 attribute,euint8 val);
|
||||
euint8 file_getAttr(File* file,euint8 attribute);
|
||||
euint32 file_requiredCluster(File *file,euint32 offset, euint32 size);
|
||||
|
||||
#endif
|
||||
@@ -1,200 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : fs.h *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : These are general filesystem functions, supported by the *
|
||||
* functions of dir.c and fat.c file.c uses these functions *
|
||||
* heavily, but is not used by fs.c (not true anymore) *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
#ifndef __FS_H_
|
||||
#define __FS_H_
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "config.h"
|
||||
#include "etypes.h"
|
||||
#include "error.h"
|
||||
#include "partition.h"
|
||||
#include "tm.h"
|
||||
#include "extract.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
#define FAT12 1
|
||||
#define FAT16 2
|
||||
#define FAT32 3
|
||||
|
||||
#define FS_INFO_SECTOR 1
|
||||
#define FSINFO_MAGIC_BEGIN 0x41615252
|
||||
#define FSINFO_MAGIC_END 0xAA550000
|
||||
|
||||
/*****************************************************************************************\
|
||||
VolumeId
|
||||
------
|
||||
* ushort BytesPerSector Must be 512 or shit happens.
|
||||
* uchar SectorsPerCluster Must be multiple of 2 (1,2,4,8,16 or 32)
|
||||
* ushort ReservedSectorCount Number of sectors after which the first FAT begins.
|
||||
* uchar NumberOfFats Should be 2
|
||||
* ushort RootEntryCount Number of filerecords the Rootdir can contain. NOT for FAT32
|
||||
* ushort SectorCount16 Number of Sectors for 12/16 bit FAT
|
||||
* ushort FatSectorCount16 Number of Sectors for 1 FAT on FAT12/16 bit FAT's
|
||||
* ulong SectorCount32 Number of Sectors for 32 bit FAT
|
||||
* ulong FatSectorCount32 Number of Sectors for 1 FAT on FAT32
|
||||
* ulong RootCluster Clusternumber of the first cluster of the RootDir on FAT 32
|
||||
This is NOT a complete volumeId copy, no direct I/O is possible.
|
||||
\*****************************************************************************************/
|
||||
struct _VolumeId{
|
||||
euint16 BytesPerSector;
|
||||
euint8 SectorsPerCluster;
|
||||
euint16 ReservedSectorCount;
|
||||
euint8 NumberOfFats;
|
||||
euint16 RootEntryCount;
|
||||
euint16 SectorCount16;
|
||||
euint16 FatSectorCount16;
|
||||
euint32 SectorCount32;
|
||||
euint32 FatSectorCount32;
|
||||
euint32 RootCluster;
|
||||
};
|
||||
typedef struct _VolumeId VolumeId;
|
||||
|
||||
/**************************************************************************************************\
|
||||
FileSystem
|
||||
--------
|
||||
* Partition* part Pointer to partition on which this FS resides.
|
||||
* VolumeId volumeId Contains important FS info.
|
||||
* ulong DataClusterCount Number of dataclusters. This number determines the FATType.
|
||||
* ulong FatSectorCount Number of sectors for 1 FAT, regardless of FATType
|
||||
* ulong SectorCount Number of sectors, regardless of FATType
|
||||
* ulong FirstSectorRootDir First sector of the RootDir.
|
||||
* uchar type Determines FATType (FAT12 FAT16 or FAT32 are defined)
|
||||
|
||||
\**************************************************************************************************/
|
||||
struct _FileSystem{
|
||||
Partition *part;
|
||||
VolumeId volumeId;
|
||||
euint32 DataClusterCount;
|
||||
euint32 FatSectorCount;
|
||||
euint32 SectorCount;
|
||||
euint32 FirstSectorRootDir;
|
||||
euint32 FirstClusterCurrentDir;
|
||||
euint32 FreeClusterCount;
|
||||
euint32 NextFreeCluster;
|
||||
euint8 type;
|
||||
};
|
||||
typedef struct _FileSystem FileSystem;
|
||||
|
||||
/**************************************************************************************************\
|
||||
FileLocation
|
||||
----------
|
||||
* euint32 Sector Sector where the directoryentry of the file/directory can be found.
|
||||
* euint8 Offset Offset (in 32byte segments) where in the sector the entry is.
|
||||
|
||||
\**************************************************************************************************/
|
||||
struct _FileLocation{
|
||||
euint32 Sector;
|
||||
euint8 Offset;
|
||||
euint8 attrib;
|
||||
};
|
||||
typedef struct _FileLocation FileLocation;
|
||||
|
||||
/*****************************************************************************\
|
||||
* FileCache
|
||||
* -----------
|
||||
* This struct acts as cache for the current file. It contains the current
|
||||
* FATPointer (next location in the FAT table), LogicCluster
|
||||
* (the last part of the file that was read) and DataCluster
|
||||
* (the last cluster that was read).
|
||||
* euint8 Linear For how many more clusters the file is nonfragmented
|
||||
* euint32 LogicCluster This field determines the n'th cluster of the file as current
|
||||
* euint32 DiscCluster If this field is 0, it means the cache is invalid. Otherwise
|
||||
it is the clusternumber corresponding with
|
||||
logic(FirstCluster+LogicCluster).
|
||||
* euint32 FirstCluster First cluster of the chain. Zero or one are invalid.
|
||||
* euint32 LastCluster Last cluster of the chain (is not always filled in)
|
||||
\*****************************************************************************/
|
||||
struct _ClusterChain{
|
||||
euint8 Linear;
|
||||
esint32 LogicCluster;
|
||||
euint32 DiscCluster;
|
||||
euint32 FirstCluster;
|
||||
euint32 LastCluster;
|
||||
};
|
||||
typedef struct _ClusterChain ClusterChain;
|
||||
|
||||
/*****************************************************************************\
|
||||
* FileRecord *
|
||||
* ------------ *
|
||||
* This struct represents a 32 byte file entry as it occurs in the data area *
|
||||
* of the filesystem. Direct I/O is possible. *
|
||||
\*****************************************************************************/
|
||||
struct _FileRecord{
|
||||
euint8 FileName[11];
|
||||
euint8 Attribute;
|
||||
euint8 NTReserved;
|
||||
euint8 MilliSecTimeStamp;
|
||||
euint16 CreatedTime;
|
||||
euint16 CreatedDate;
|
||||
euint16 AccessDate;
|
||||
euint16 FirstClusterHigh;
|
||||
euint16 WriteTime;
|
||||
euint16 WriteDate;
|
||||
euint16 FirstClusterLow;
|
||||
euint32 FileSize;
|
||||
};
|
||||
typedef struct _FileRecord FileRecord;
|
||||
|
||||
|
||||
eint16 fs_initFs(FileSystem *fs,Partition *part);
|
||||
eint16 fs_isValidFat(Partition *part);
|
||||
void fs_loadVolumeId(FileSystem *fs, Partition *part);
|
||||
esint16 fs_verifySanity(FileSystem *fs);
|
||||
void fs_countDataSectors(FileSystem *fs);
|
||||
void fs_determineFatType(FileSystem *fs);
|
||||
void fs_findFirstSectorRootDir(FileSystem *fs);
|
||||
void fs_initCurrentDir(FileSystem *fs);
|
||||
euint32 fs_getSectorAddressRootDir(FileSystem *fs,euint32 secref);
|
||||
euint32 fs_clusterToSector(FileSystem *fs,euint32 cluster);
|
||||
euint32 fs_sectorToCluster(FileSystem *fs,euint32 sector);
|
||||
euint32 fs_getNextFreeCluster(FileSystem *fs,euint32 startingcluster);
|
||||
euint32 fs_giveFreeClusterHint(FileSystem *fs);
|
||||
esint16 fs_findFreeFile(FileSystem *fs,eint8* filename,FileLocation *loc,euint8 mode);
|
||||
esint8 fs_findFile(FileSystem *fs,eint8* filename,FileLocation *loc,euint32 *lastDir);
|
||||
esint8 fs_findFile_broken(FileSystem *fs,eint8* filename,FileLocation *loc);
|
||||
euint32 fs_getLastCluster(FileSystem *fs,ClusterChain *Cache);
|
||||
euint32 fs_getFirstClusterRootDir(FileSystem *fs);
|
||||
euint16 fs_makeDate(void);
|
||||
euint16 fs_makeTime(void);
|
||||
void fs_setFirstClusterInDirEntry(FileRecord *rec,euint32 cluster_addr);
|
||||
void fs_initClusterChain(FileSystem *fs,ClusterChain *cache,euint32 cluster_addr);
|
||||
esint8 fs_flushFs(FileSystem *fs);
|
||||
esint8 fs_umount(FileSystem *fs);
|
||||
esint8 fs_clearCluster(FileSystem *fs,euint32 cluster);
|
||||
esint8 fs_getFsInfo(FileSystem *fs);
|
||||
esint8 fs_setFsInfo(FileSystem *fs);
|
||||
|
||||
#endif
|
||||
@@ -1,69 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : ls.h *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : This file contains functions to list the files in a directory *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
#ifndef __LS_H__
|
||||
#define __LS_H__
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "config.h"
|
||||
#include "fs.h"
|
||||
#include "dir.h"
|
||||
#include "fat.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
struct _ListDirEntry{
|
||||
euint8 FileName[LIST_MAXLENFILENAME];
|
||||
euint32 FileSize;
|
||||
euint8 Attribute;
|
||||
};
|
||||
typedef struct _ListDirEntry ListDirEntry;
|
||||
|
||||
struct _DirList{
|
||||
FileSystem *fs;
|
||||
euint16 cEntry,rEntry;
|
||||
/*FileRecord currentEntry;*/
|
||||
ListDirEntry currentEntry;
|
||||
ClusterChain Cache;
|
||||
};
|
||||
typedef struct _DirList DirList;
|
||||
|
||||
esint8 ls_openDir(DirList *dlist,FileSystem *fs,eint8* dirname);
|
||||
esint8 ls_getNext(DirList *dlist);
|
||||
|
||||
esint8 ls_getDirEntry(DirList *dlist);
|
||||
esint8 ls_getRealDirEntry(DirList *dlist);
|
||||
esint8 ls_getRootAreaEntry(DirList *dlist);
|
||||
esint8 ls_isValidFileEntry(ListDirEntry *entry);
|
||||
void ls_fileEntryToDirListEntry(DirList *dlist, euint8* buf, euint16 offset);
|
||||
|
||||
#endif
|
||||
@@ -1,50 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : mkfs.h *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : These functions are used for creating an empty filesystem. *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
#ifndef __MKFS_H_
|
||||
#define __MKFS_H_
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "partition.h"
|
||||
#include "plibc.h"
|
||||
#include "debug.h"
|
||||
#include "etypes.h"
|
||||
#include "extract.h"
|
||||
#include "config.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
#define MKFS_ERR_TOOLITTLESECTORS 1
|
||||
|
||||
esint16 mkfs_makevfat(Partition *part);
|
||||
|
||||
#endif
|
||||
@@ -1,74 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : time.h *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : This file contains functions for time support *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
#ifndef __TIME_H_
|
||||
#define __TIME_H_
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "etypes.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifdef DATE_TIME_SUPPORT
|
||||
#define time_getYear(void) efsl_getYear()
|
||||
#define time_getMonth(void) efsl_getMonth()
|
||||
#define time_getDay(void) efsl_getDay()
|
||||
#define time_getHour(void) efsl_getHour()
|
||||
#define time_getMinute(void) efsl_getMinute()
|
||||
#define time_getSecond(void) efsl_getSecond()
|
||||
#define time_getDate(void) fs_makeDate()
|
||||
#define time_getTime(void) fs_makeTime()
|
||||
#else
|
||||
#define time_getYear(void) 0x0;
|
||||
#define time_getMonth(void) 0x0;
|
||||
#define time_getDay(void) 0x0;
|
||||
#define time_getHour(void) 0x0;
|
||||
#define time_getMinute(void) 0x0;
|
||||
#define time_getSecond(void) 0x0;
|
||||
#define time_getDate(void) 0x0;
|
||||
#define time_getTime(void) 0x0;
|
||||
#endif
|
||||
|
||||
#ifdef DATE_TIME_SUPPORT
|
||||
euint16 efsl_getYear(void);
|
||||
euint8 efsl_getMonth(void);
|
||||
euint8 efsl_getDay(void);
|
||||
euint8 efsl_getHour(void);
|
||||
euint8 efsl_getMinute(void);
|
||||
euint8 efsl_getSecond(void);
|
||||
euint16 fs_makeDate(void);
|
||||
euint16 fs_makeTime(void);
|
||||
#endif
|
||||
|
||||
euint8 fs_hasTimeSupport(void);
|
||||
|
||||
#endif
|
||||
@@ -1,50 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : ui.h *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : This file contains functions which will be presented to the *
|
||||
* user of this library. *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
#ifndef __UI_H__
|
||||
#define __UI_H__
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "fs.h"
|
||||
#include "etypes.h"
|
||||
#include "fat.h"
|
||||
#include "dir.h"
|
||||
#include "config.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
esint8 mk_dir(FileSystem *fs,eint8* dirname);
|
||||
esint16 un_link(FileSystem *fs,euint8* filename);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,150 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : ls.c *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : This file contains functions to list the files in a directory *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
#include <dfs_fs.h>
|
||||
|
||||
#include "ls.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
esint8 ls_openDir(DirList *dlist,FileSystem *fs,eint8* dirname)
|
||||
{
|
||||
FileLocation loc;
|
||||
euint32 fc;
|
||||
esint8 result;
|
||||
|
||||
dlist->fs=fs;
|
||||
|
||||
result = fs_findFile(dlist->fs,dirname,&loc,&fc);
|
||||
|
||||
if(result == 2)
|
||||
{
|
||||
fs_initClusterChain(dlist->fs,&(dlist->Cache),fc);
|
||||
memClr(&(dlist->currentEntry),sizeof(dlist->currentEntry));
|
||||
dlist->rEntry=0;
|
||||
dlist->cEntry=0xFFFF;
|
||||
|
||||
return(0);
|
||||
}
|
||||
else if(result == 1)
|
||||
dfs_log(DFS_DEBUG_INFO, ("%s is not a directory", dirname));
|
||||
else
|
||||
dfs_log(DFS_DEBUG_INFO, ("can't find %s", dirname));
|
||||
|
||||
return (-1);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
esint8 ls_getDirEntry(DirList *dlist)
|
||||
{
|
||||
if(dlist->Cache.FirstCluster == 1){
|
||||
return(ls_getRootAreaEntry(dlist));
|
||||
}else if(dlist->Cache.FirstCluster){
|
||||
return(ls_getRealDirEntry(dlist));
|
||||
}
|
||||
return(-1);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
esint8 ls_getNext(DirList *dlist)
|
||||
{
|
||||
do{
|
||||
if(ls_getDirEntry(dlist))return(-1);
|
||||
dlist->rEntry++;
|
||||
}while(!ls_isValidFileEntry(&(dlist->currentEntry)));
|
||||
dlist->cEntry++;
|
||||
return(0);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
esint8 ls_getRealDirEntry(DirList *dlist)
|
||||
{
|
||||
euint8* buf;
|
||||
|
||||
if(dlist->Cache.FirstCluster<=1)return(-1);
|
||||
|
||||
if(fat_LogicToDiscCluster(dlist->fs,
|
||||
&(dlist->Cache),
|
||||
(dlist->rEntry)/(16 * dlist->fs->volumeId.SectorsPerCluster))){
|
||||
return(-1);
|
||||
}
|
||||
|
||||
buf = part_getSect(dlist->fs->part,
|
||||
fs_clusterToSector(dlist->fs,dlist->Cache.DiscCluster) + (dlist->rEntry/16)%dlist->fs->volumeId.SectorsPerCluster,
|
||||
IOM_MODE_READONLY);
|
||||
|
||||
/*memCpy(buf+(dlist->rEntry%16)*32,&(dlist->currentEntry),32);*/
|
||||
ls_fileEntryToDirListEntry(dlist,buf,32*(dlist->rEntry%16));
|
||||
|
||||
part_relSect(dlist->fs->part,buf);
|
||||
|
||||
return(0);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
esint8 ls_getRootAreaEntry(DirList *dlist)
|
||||
{
|
||||
euint8 *buf=0;
|
||||
|
||||
if((dlist->fs->type != FAT12) && (dlist->fs->type != FAT16))return(-1);
|
||||
if(dlist->rEntry>=dlist->fs->volumeId.RootEntryCount)return(-1);
|
||||
|
||||
buf = part_getSect(dlist->fs->part,
|
||||
dlist->fs->FirstSectorRootDir+dlist->rEntry/16,
|
||||
IOM_MODE_READONLY);
|
||||
/*memCpy(buf+32*(dlist->rEntry%16),&(dlist->currentEntry),32);*/
|
||||
ls_fileEntryToDirListEntry(dlist,buf,32*(dlist->rEntry%16));
|
||||
part_relSect(dlist->fs->part,buf);
|
||||
return(0);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
esint8 ls_isValidFileEntry(ListDirEntry *entry)
|
||||
{
|
||||
if(entry->FileName[0] == 0 || entry->FileName[0] == 0xE5 || entry->FileName[0] == '.')return(0);
|
||||
if((entry->Attribute&0x0F)==0x0F)return(0);
|
||||
return(1);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
void ls_fileEntryToDirListEntry(DirList *dlist, euint8* buf, euint16 offset)
|
||||
{
|
||||
if(offset>480 || offset%32)return;
|
||||
|
||||
buf+=offset;
|
||||
memCpy(buf+OFFSET_DE_FILENAME,dlist->currentEntry.FileName,LIST_MAXLENFILENAME);
|
||||
dlist->currentEntry.Attribute = *(buf+OFFSET_DE_ATTRIBUTE);
|
||||
dlist->currentEntry.FileSize = ex_getb32(buf+OFFSET_DE_FILESIZE);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -1,166 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : mkfs.c *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : These functions are used for creating an empty filesystem. *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "mkfs.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
esint16 mkfs_makevfat(Partition *part)
|
||||
{
|
||||
unsigned long c,cc,ret;
|
||||
unsigned long ns,fs,ds,dc;
|
||||
unsigned char buf[512];
|
||||
|
||||
ns=part->disc->partitions[part->activePartition].numSectors;
|
||||
|
||||
if( ns < 66581 ){
|
||||
DBG((TXT("This is not possible due to insufficient sectors. Sorry\n")));
|
||||
return(MKFS_ERR_TOOLITTLESECTORS);
|
||||
}
|
||||
|
||||
ret=0;
|
||||
|
||||
for(c=1<<6;c>=1;c>>=1){
|
||||
|
||||
/* First guess */
|
||||
ds = ns - 32;
|
||||
fs = ((ds/c)+127)/128;
|
||||
/* ds was guess too large, so fs is too large now too. */
|
||||
|
||||
for(cc=0;cc<2;cc++){
|
||||
|
||||
/* Round 2, error round */
|
||||
ds = ns - 32 - 2*fs;
|
||||
fs = ((ds/c)+127)/128;
|
||||
/* Since fs was too large, ds became too small. So the fs for this small ds is too small as well. */
|
||||
|
||||
/* Round 3, correction round */
|
||||
ds = ns - 32 - 2*fs;
|
||||
fs = ((ds/c)+127)/128;
|
||||
/* The fs was too small, so ds was too large. The calculated fs should be slightly too large. */
|
||||
|
||||
}
|
||||
|
||||
/* Round 4, finalise */
|
||||
ds = ns - 32 - 2*fs;
|
||||
|
||||
dc = ds / c;
|
||||
if(ret<(fs*128-dc)/128)ret=(fs*128-dc)/128;
|
||||
|
||||
/* Check if with current setting we have a valid fat ? */
|
||||
|
||||
if(dc >= 65525 + 16){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Generate BPB */
|
||||
memClr(buf,512);
|
||||
|
||||
/* Boot code */
|
||||
*(buf+0)=0xE9; *(buf+1)=0x00; *(buf+2)=0x00; /* RESET */
|
||||
|
||||
/* OEM name */
|
||||
memCpy("DSCOSMSH",buf+3,8);
|
||||
|
||||
/* Bytes/Sector */
|
||||
/* *((unsigned short*)(buf+11)) = 512; */
|
||||
ex_setb16(buf+11,512);
|
||||
|
||||
/* Sectors/Cluster */
|
||||
*(buf+13) = c;
|
||||
|
||||
/* Reserved Sectors */
|
||||
/* *((unsigned short*)(buf+14)) = 32; */
|
||||
ex_setb16(buf+14,32);
|
||||
|
||||
/* Number of FAT Tables */
|
||||
*(buf+16) = 2;
|
||||
|
||||
/* RootEntryCount */
|
||||
/* *((unsigned short*)(buf+17)) = 0; */
|
||||
ex_setb16(buf+17,0);
|
||||
|
||||
/* Total Sector Count __16 */
|
||||
/* *((unsigned short*)(buf+19)) = 0; */
|
||||
ex_setb16(buf+19,0);
|
||||
|
||||
/* Media (crap) */
|
||||
*(buf+21) = 0xF8;
|
||||
|
||||
/* FAT size 16 */
|
||||
/* *((unsigned short*)(buf+22)) = 0; */
|
||||
ex_setb16(buf+22,0);
|
||||
|
||||
/* Total Sector Count __32 */
|
||||
/* *((unsigned long*)(buf+32)) = ns; */
|
||||
ex_setb32(buf+32,ns);
|
||||
|
||||
/* Fat Size 32 */
|
||||
/* *((unsigned long*)(buf+36)) = fs; */
|
||||
ex_setb32(buf+36,fs);
|
||||
|
||||
/* First Cluster Root Dir */
|
||||
/* *((unsigned long*)(buf+44)) = 2; */
|
||||
ex_setb32(buf+44,2);
|
||||
|
||||
/* VolumeID */
|
||||
/* *((unsigned long*)(buf+67)) = 0x13371337; */
|
||||
ex_setb32(buf+67,0);
|
||||
|
||||
/* Volume Label */
|
||||
memCpy("EFSL-0.3.3 ",buf+71,11);
|
||||
|
||||
/* Filesystemtype */
|
||||
memCpy("FAT32 ",buf+82,8);
|
||||
|
||||
/* Magic */
|
||||
*(buf+510) = 0x55; *(buf+511) = 0xAA;
|
||||
|
||||
part_writeBuf(part,0,buf);
|
||||
|
||||
memClr(buf,512);
|
||||
for(c=32;c<(32+2*fs);c++){
|
||||
part_writeBuf(part,c,buf);
|
||||
}
|
||||
/* *(((unsigned long*)buf) )=0x0FFFFFF8;
|
||||
*(((unsigned long*)buf)+1)=0x0FFFFFFF;
|
||||
*(((unsigned long*)buf)+2)=0x0FFFFFF8; */
|
||||
ex_setb32(buf+0,(euint32)0x0FFFFFF8);
|
||||
ex_setb32(buf+4,(euint32)0x0FFFFFFF);
|
||||
ex_setb32(buf+8,(euint32)0x0FFFFFF8);
|
||||
part_writeBuf(part,32,buf);
|
||||
part_writeBuf(part,32+fs,buf);
|
||||
|
||||
return(0);
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : time.c *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : This file contains functions for time support *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "tm.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
euint16 fs_makeDate(void)
|
||||
{
|
||||
#ifndef DATE_TIME_SUPPORT
|
||||
return(0);
|
||||
#else
|
||||
euint8 m,d;
|
||||
euint16 y;
|
||||
|
||||
y = time_getYear()-1980;
|
||||
m = time_getMonth();
|
||||
d = time_getDay();
|
||||
|
||||
return(
|
||||
(y>127?127<<9:(y&0x3F)<<9) |
|
||||
((m==0||m>12)?1:(m&0xF)<<5) |
|
||||
((d==0||d>31)?1:(d&0x1F))
|
||||
);
|
||||
#endif
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
euint16 fs_makeTime(void)
|
||||
{
|
||||
#ifndef DATE_TIME_SUPPORT
|
||||
return(0);
|
||||
#else
|
||||
euint8 s,m,h;
|
||||
|
||||
s = time_getSecond();
|
||||
m = time_getMinute();
|
||||
h = time_getHour();
|
||||
|
||||
return(
|
||||
(h>23?0:(h&0x1F)<<11) |
|
||||
(m>59?0:(m&0x3F)<<5) |
|
||||
(s>59?0:(s-s%2)/2)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
euint8 fs_hasTimeSupport(void)
|
||||
{
|
||||
#ifdef DATE_TIME_SUPPORT
|
||||
return(1);
|
||||
#else
|
||||
return(0);
|
||||
#endif
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@@ -1,200 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : ui.c *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : This file contains functions which will be presented to the *
|
||||
* user of this library. *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "ui.h"
|
||||
#include "ls.h"
|
||||
#include "efs.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* unlink dir or file@yi.qiu,2008-08-19
|
||||
*/
|
||||
esint16 un_link(FileSystem *fs,euint8* filename)
|
||||
{
|
||||
FileLocation loc;
|
||||
ClusterChain cache;
|
||||
DirList *dlist;
|
||||
euint8* buf;
|
||||
euint8 attr;
|
||||
euint32 firstCluster=0;
|
||||
euint32 fc;
|
||||
|
||||
if ( filename[0] == '/' && filename[1] == '\0')
|
||||
{
|
||||
/* it's the root directory */
|
||||
dfs_log(DFS_DEBUG_INFO, ("Can't delete root directory"));
|
||||
return -DFS_STATUS_EISDIR;
|
||||
}
|
||||
|
||||
if((fs_findFile(fs,(eint8*)filename,&loc,&fc)) > 0)
|
||||
{
|
||||
buf = part_getSect(fs->part,loc.Sector,IOM_MODE_READWRITE);
|
||||
firstCluster = ex_getb16(buf+loc.Offset*32+20);
|
||||
firstCluster <<= 16;
|
||||
firstCluster += ex_getb16(buf+loc.Offset*32+26);
|
||||
attr = ex_getb16(buf+loc.Offset*32+11);
|
||||
part_relSect(fs->part,buf);
|
||||
|
||||
if(attr == ATTR_DIRECTORY)
|
||||
{
|
||||
dlist = (DirList *)rt_malloc(sizeof(DirList));
|
||||
if(dlist == RT_NULL)
|
||||
{
|
||||
|
||||
dfs_log(DFS_DEBUG_INFO, ("Memory alloc failed"));
|
||||
return -DFS_STATUS_ENOMEM;
|
||||
}
|
||||
|
||||
if(firstCluster != 0)
|
||||
{
|
||||
dlist->fs = fs;
|
||||
fs_initClusterChain(fs,&(dlist->Cache),fc);
|
||||
memClr(&(dlist->currentEntry),sizeof(dlist->currentEntry));
|
||||
dlist->rEntry = 0;
|
||||
dlist->cEntry = 0xFFFF;
|
||||
|
||||
while(1)
|
||||
{
|
||||
/* it's the end of file */
|
||||
if(ls_getNext(dlist) == 0)
|
||||
{
|
||||
/* '.' and '..' */
|
||||
if(dlist->currentEntry.FileName[0] == '.') continue;
|
||||
|
||||
dfs_log(DFS_DEBUG_INFO, ("Directory not empty"));
|
||||
return -DFS_STATUS_ENOTEMPTY;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buf = part_getSect(fs->part,loc.Sector,IOM_MODE_READWRITE);
|
||||
memClr(buf+(loc.Offset*32),32);
|
||||
part_relSect(fs->part,buf);
|
||||
cache.DiscCluster = cache.LastCluster = cache.Linear = cache.LogicCluster = 0;
|
||||
cache.FirstCluster = firstCluster;
|
||||
fat_unlinkClusterChain(fs,&cache);
|
||||
|
||||
return 0;
|
||||
}
|
||||
return -DFS_STATUS_ENOENT;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
esint8 mk_dir(FileSystem *fs,eint8* dirname)
|
||||
{
|
||||
FileLocation loc;
|
||||
FileRecord direntry;
|
||||
euint32 nc,parentdir;
|
||||
euint8* buf;
|
||||
eint8 ffname[11];
|
||||
|
||||
if( fs_findFile(fs,dirname,&loc,&parentdir) )
|
||||
{
|
||||
dfs_log(DFS_DEBUG_INFO, ("directory %s has existed", dirname));
|
||||
return(-1);
|
||||
}
|
||||
if(parentdir==0)
|
||||
{
|
||||
dfs_log(DFS_DEBUG_INFO, ("parent directory doesn't existe"));
|
||||
return(-2);
|
||||
}
|
||||
|
||||
if(!fs_findFreeFile(fs,dirname,&loc,0))
|
||||
{
|
||||
dfs_log(DFS_DEBUG_INFO, ("can't find free entry"));
|
||||
return(-3);
|
||||
}
|
||||
|
||||
/* You may never search for a free cluster, and the call
|
||||
* functions that may cause changes to the FAT table, that
|
||||
* is why getNextFreeCluster has to be called AFTER calling
|
||||
* fs_findFreeFile, which may have to expand a directory in
|
||||
* order to store the new filerecord !!
|
||||
*/
|
||||
|
||||
nc = fs_getNextFreeCluster(fs,fs_giveFreeClusterHint(fs));
|
||||
if(nc==0)
|
||||
{
|
||||
dfs_log(DFS_DEBUG_INFO, ("no free cluster"));
|
||||
return(0);
|
||||
}
|
||||
|
||||
fs_clearCluster(fs,nc);
|
||||
|
||||
buf = part_getSect(fs->part,loc.Sector,IOM_MODE_READWRITE);
|
||||
|
||||
dir_getFatFileName(dirname,ffname);
|
||||
memClr(&direntry,sizeof(direntry));
|
||||
memCpy(ffname,&direntry,11);
|
||||
direntry.FileSize = 0;
|
||||
direntry.FirstClusterHigh=nc>>16;
|
||||
direntry.FirstClusterLow=nc&0xFFFF;
|
||||
direntry.Attribute = ATTR_DIRECTORY;
|
||||
memCpy(&direntry,buf+(32*loc.Offset),32);
|
||||
|
||||
part_relSect(fs->part,buf);
|
||||
|
||||
buf = part_getSect(fs->part,fs_clusterToSector(fs,nc),IOM_MODE_READWRITE);
|
||||
|
||||
memClr(&direntry,sizeof(direntry));
|
||||
memCpy(". ",&direntry,11);
|
||||
direntry.Attribute = ATTR_DIRECTORY;
|
||||
direntry.FileSize = 0;
|
||||
direntry.FirstClusterHigh=nc>>16;
|
||||
direntry.FirstClusterLow=nc&0xFFFF;
|
||||
memCpy(&direntry,buf,32);
|
||||
|
||||
if(fs->type == FAT32 && parentdir == fs->volumeId.RootCluster)
|
||||
parentdir = 0;
|
||||
|
||||
if(fs->type != FAT32 && parentdir<=1)
|
||||
parentdir = 0;
|
||||
|
||||
memClr(&direntry,sizeof(direntry));
|
||||
memCpy(".. ",&direntry,11);
|
||||
direntry.Attribute = ATTR_DIRECTORY;
|
||||
direntry.FileSize = 0;
|
||||
direntry.FirstClusterHigh=parentdir>>16;
|
||||
direntry.FirstClusterLow=parentdir&0xFFFF;
|
||||
memCpy(&direntry,buf+32,32);
|
||||
|
||||
part_relSect(fs->part,buf);
|
||||
|
||||
fat_setNextClusterAddress(fs,nc,fat_giveEocMarker(fs));
|
||||
|
||||
return(0);
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
#ifndef __EFSL_CONFIG_H__
|
||||
#define __EFSL_CONFIG_H__
|
||||
|
||||
/* include RT-Thread to import configuration */
|
||||
#include <rtthread.h>
|
||||
|
||||
/* Hardware target
|
||||
---------------
|
||||
|
||||
* Here you will define for what hardware-endpoint EFSL should be compiled.
|
||||
* Look in interfaces.h to see what systems are supported, and add your own
|
||||
* there if you need to write your own driver. Then, define the name you
|
||||
* selected for your hardware there here. Make sure that you only select one
|
||||
* device!
|
||||
*/
|
||||
|
||||
/*#define HW_ENDPOINT_LINUX*/
|
||||
/*#define HW_ENDPOINT_ATMEGA128_SD*/
|
||||
/*#define HW_ENDPOINT_DSP_TI6713_SD*/
|
||||
|
||||
#define MULTIPLE_INTERFACE_SUPPORT
|
||||
/*#define HWIFUNC_INIT(x) lf_init(x)
|
||||
#define HWIFUNC_READ(x,y,z) lf_readBuf(x,y,z)
|
||||
#define HWIFUNC_WRITE(x,y,z) lf_writeBuf(x,y,z)
|
||||
#define HWIFUNC_HEADER interfaces/linuxfile.h */
|
||||
|
||||
/* Architecture
|
||||
------------
|
||||
|
||||
* In this section you should configure how large the default variable
|
||||
* types in your system are. This is controlled in types.h in the general
|
||||
* include directory. The selection you make here defines to what the various
|
||||
* e(s|u)int(8,16,32) types will map.
|
||||
* For 32 bit Linux : VARSIZE_LINUX32
|
||||
* For 64 bit Linux : VARSIZE_LINUX64
|
||||
* For AVR's : VARSIZE_ATMEGA
|
||||
* For TMS67XX : VARSIZE_TMS67XX
|
||||
*/
|
||||
|
||||
#define VARSIZE_LINUX32
|
||||
|
||||
/* Memory configuration
|
||||
--------------------
|
||||
|
||||
* Here you must configure wheter your processor can access memory byte
|
||||
* oriented. All x86 processors can do it, AVR's can do it to. Some DSP
|
||||
* or other microcontrollers can't. If you have an 8 bit system you're safe.
|
||||
* If you are really unsure, leave the setting commented out, it will be slower
|
||||
* but it will work for sure.
|
||||
*/
|
||||
|
||||
/* #define BYTE_ALIGNMENT */
|
||||
|
||||
/* Cache configuration
|
||||
-------------------
|
||||
|
||||
* Here you must configure how much memory of cache you can/want to use.
|
||||
* The number you put at IOMAN_NUMBUFFER is multiplied by 512. So 1 means
|
||||
* 512 bytes cache, 4 means 2048 bytes cache. More is better.
|
||||
* The number after IOMAN_NUMITERATIONS should be untouched.
|
||||
* The last field (IOMAN_DO_MEMALLOC) is to tell ioman to allocate it's
|
||||
* own memory in it's structure, or not. If you choose to do it yourself
|
||||
* you will have to pass a pointer to the memory as the last argument of
|
||||
* ioman_init.
|
||||
*/
|
||||
#define IOMAN_NUMBUFFER 10
|
||||
#define IOMAN_NUMITERATIONS 3
|
||||
#define IOMAN_DO_MEMALLOC
|
||||
|
||||
/* Cluster pre-allocation
|
||||
----------------------
|
||||
|
||||
* When writing files, the function that performs the actual write has to
|
||||
* calculate how many clusters it will need for that request. It then allocates
|
||||
* that number of new clusters to the file. Since this involves some
|
||||
* calculations and writing of the FAT, you might find it beneficial to limit
|
||||
* the number of allocations, and allow fwrite to pre-allocate a number of
|
||||
* clusters extra. This setting determines how many clusters will be extra
|
||||
* allocated whenever this is required.
|
||||
* Take in carefull consideration how large your clustersize is, putting 10 here
|
||||
* with a clustersize of 32kb means you might waste 320 kb.
|
||||
* The first option is for preallocating files, the other is used when enlarging
|
||||
* a directory to accomodate more files
|
||||
*/
|
||||
#define CLUSTER_PREALLOC_FILE 5
|
||||
#define CLUSTER_PREALLOC_DIRECTORY 2
|
||||
|
||||
/* Endianess configuration
|
||||
-----------------------
|
||||
|
||||
* Here you can configure wheter your architecture is little or big endian. This
|
||||
* is important since all FAT structures are stored in intel little endian
|
||||
* order. So if you have a big endian system the library has to convert all
|
||||
* figures to big endian in order to work.
|
||||
*/
|
||||
/*#define HOST_BIG_ENDIAN*/
|
||||
#define HOST_LITTLE_ENDIAN
|
||||
|
||||
/* Date and Time support
|
||||
---------------------
|
||||
|
||||
* Here you can enable or disable date and time support. If you enable
|
||||
* it you will have to create 6 functions, that are described in the
|
||||
* EFSL manual. If the functions are not present when linking your
|
||||
* program with the library you will get unresolved dependencies.
|
||||
*/
|
||||
/* #define DATE_TIME_SUPPORT */
|
||||
|
||||
/* Error reporting support
|
||||
-----------------------
|
||||
|
||||
* When you receive an error in userland, it usually only gives limited
|
||||
* information (most likely, fail or success). If error detection and
|
||||
* reporting is important for you, you can enable more detailed error
|
||||
* reporting here. This is optional, the costs are 1 byte per object,
|
||||
* and a small increase in code size.
|
||||
* You can enable error recording for all object, or you can select the
|
||||
* object manually.
|
||||
* For full error reporting use FULL_ERROR_SUPPORT
|
||||
* For only the base-core of the library use BASE_ERROR_SUPPORT
|
||||
* For IO/Man use ERRSUP_IOMAN
|
||||
* For Disc use ERRSUP_IOMAN
|
||||
* For Part use ERRSUP_PARTITION
|
||||
* For Fs use ERRSUP_FILESYSTEM
|
||||
* For File use ERRSUP_FILE
|
||||
*/
|
||||
|
||||
#define FULL_ERROR_SUPPORT
|
||||
/*#define BASE_ERROR_SUPPORT*/
|
||||
|
||||
|
||||
/* Debugging configuration
|
||||
-----------------------
|
||||
|
||||
* Here you can configure the debugging behaviour. Debugging is different
|
||||
* on every platform (see debug.h for more information).
|
||||
* If your hardware has no means of output (printf) dont define any anything,
|
||||
* and nothing will happen. For real world use debugging should be turned off.
|
||||
*/
|
||||
|
||||
/*#define DEBUG*/
|
||||
/*#define DO_FUNC_DEBUG*/
|
||||
|
||||
/* List options
|
||||
------------
|
||||
|
||||
* In this section you can configure what kind of data you will get from
|
||||
* directory listing requests. Please refer to the documentation for
|
||||
* more information
|
||||
*/
|
||||
|
||||
#define LIST_MAXLENFILENAME 12
|
||||
|
||||
#endif
|
||||
@@ -1,124 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : error.h *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : Header file containing error-defines. *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
#ifndef __ERROR_H_
|
||||
#define __ERROR_H_
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "config.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
#if defined (FULL_ERROR_SUPPORT)
|
||||
#define ERRSUP_IOMAN
|
||||
#define ERRSUP_DISC
|
||||
#define ERRSUP_PARTITION
|
||||
#define ERRSUP_FAT_FILESYSTEM
|
||||
#define ERRSUP_FAT_FILESYSTEM
|
||||
#elif defined (BASE_ERROR_SUPPORT)
|
||||
#define ERRSUP_IOMAN
|
||||
#define ERRSUP_DISC
|
||||
#define ERRSUP_PARTITION
|
||||
#endif
|
||||
|
||||
#if defined (HWINT_HAS_ERROR_SUPPORT) && defined (INTERFACE_ERROR_SUPPORT)
|
||||
#define ERRSUP_HWINTERFACE
|
||||
#endif
|
||||
|
||||
#ifdef ERRSUP_IOMAN
|
||||
#define IOMAN_ERR_EUINT8 euint8 error;
|
||||
#define ioman_setError(ioman,errval) ioman->error = errval
|
||||
#define ioman_getError(ioman) ioman->error
|
||||
#else
|
||||
#define IOMAN_ERR_EUINT8
|
||||
#define ioman_setError(ioman,errval)
|
||||
#define ioman_getError(ioman) 0
|
||||
#endif
|
||||
|
||||
#ifdef ERRSUP_DISC
|
||||
#define DISC_ERR_EUINT8 euint8 error;
|
||||
#define disc_setError(disc,errval) disc->error = errval
|
||||
#define disc_getError(disc) disc->error
|
||||
#else
|
||||
#define DISC_ERR_EUINT8
|
||||
#define disc_setError(disc,errval)
|
||||
#define disc_getError(disc) 0
|
||||
#endif
|
||||
|
||||
#ifdef ERRSUP_PART
|
||||
#define PART_ERR_EUINT8 euint8 error;
|
||||
#define part_setError(part,errval) part->error = errval
|
||||
#define part_getError(part) part->error
|
||||
#else
|
||||
#define PART_ERR_EUINT8
|
||||
#define part_setError(part,errval)
|
||||
#define part_getError(part) 0
|
||||
#endif
|
||||
|
||||
#ifdef ERRSUP_FAT_FILESYSTEM
|
||||
#define FILESYSTEM_ERR_EUINT8 euint8 error;
|
||||
#define fs_setError(fs,errval) fs->error = errval
|
||||
#define fs_getError(fs) fs->error
|
||||
#else
|
||||
#define FILESYSTEM_ERR_EUINT8
|
||||
#define fs_setError(fs,errval)
|
||||
#define fs_getError(fs) 0
|
||||
#endif
|
||||
|
||||
#ifdef ERRSUP_FILE
|
||||
#define FILE_ERR_EUINT8 euint8 error;
|
||||
#define file_setError(file,errval) file->error = errval
|
||||
#define file_getError(file) file->error
|
||||
#else
|
||||
#define FILE_ERR_EUINT8
|
||||
#define file_setError(file,errval)
|
||||
#define file_getError(file) 0
|
||||
#endif
|
||||
|
||||
#define IOMAN_NOERROR 0
|
||||
#define IOMAN_ERR_SETATTROUTOFBOUNDS 1
|
||||
#define IOMAN_ERR_GETATTROUTOFBOUNDS 2
|
||||
#define IOMAN_ERR_READFAIL 3
|
||||
#define IOMAN_ERR_WRITEFAIL 4
|
||||
#define IOMAN_ERR_OPOUTOFBOUNDS 5
|
||||
#define IOMAN_ERR_PUSHBEYONDSTACK 6
|
||||
#define IOMAN_ERR_POPEMPTYSTACK 7
|
||||
#define IOMAN_ERR_CACHEPTROUTOFRANGE 8
|
||||
#define IOMAN_ERR_WRITEREADONLYSECTOR 9
|
||||
#define IOMAN_ERR_NOMEMORY 10
|
||||
|
||||
#define DISC_NOERROR 0
|
||||
|
||||
#define PART_NOERROR 0
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,110 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : types.h *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : This file contains the crossplatform data types *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
#ifndef __EFS_TYPES_H__
|
||||
#define __EFS_TYPES_H__
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "config.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
/* VARIABLE SIZES
|
||||
==============
|
||||
|
||||
* eint8 -> 1 byte
|
||||
* eint16 -> 2 bytes
|
||||
* eint32 -> 4 bytes
|
||||
*
|
||||
* VARSIZE_LINUX32 is suitable for 32bit Linux
|
||||
* VARSIZE_LINUX64 is suitable for 64bit Linux
|
||||
* VARSIZE_ATMEGA is suitable for AVR's
|
||||
* VARSIZE_TMS67XX is suitable for the TI TMS67XX
|
||||
*
|
||||
* If nothing is selected a default is used, that should work on
|
||||
* 32 bit systems
|
||||
*/
|
||||
|
||||
#if defined(VARSIZE_LINUX32)
|
||||
typedef char eint8;
|
||||
typedef signed char esint8;
|
||||
typedef unsigned char euint8;
|
||||
typedef short eint16;
|
||||
typedef signed short esint16;
|
||||
typedef unsigned short euint16;
|
||||
typedef long eint32;
|
||||
typedef signed long esint32;
|
||||
typedef unsigned long euint32;
|
||||
#elif defined(VARSIZE_LINUX64)
|
||||
typedef char eint8;
|
||||
typedef signed char esint8;
|
||||
typedef unsigned char euint8;
|
||||
typedef short eint16;
|
||||
typedef signed short esint16;
|
||||
typedef unsigned short euint16;
|
||||
typedef int eint32;
|
||||
typedef signed int esint32;
|
||||
typedef unsigned int euint32;
|
||||
#elif defined (VARSIZE_ATMEGA)
|
||||
typedef char eint8;
|
||||
typedef signed char esint8;
|
||||
typedef unsigned char euint8;
|
||||
typedef short eint16;
|
||||
typedef signed short esint16;
|
||||
typedef unsigned short euint16;
|
||||
typedef long eint32;
|
||||
typedef signed long esint32;
|
||||
typedef unsigned long euint32;
|
||||
#elif defined(VARSIZE_TMS67XX)
|
||||
typedef char eint8;
|
||||
typedef signed char esint8;
|
||||
typedef unsigned char euint8;
|
||||
typedef short eint16;
|
||||
typedef signed short esint16;
|
||||
typedef unsigned short euint16;
|
||||
typedef int eint32;
|
||||
typedef signed int esint32;
|
||||
typedef unsigned int euint32;
|
||||
#else
|
||||
#warning "No VARSIZE selection has been made, beware!"
|
||||
typedef char eint8;
|
||||
typedef signed char esint8;
|
||||
typedef unsigned char euint8;
|
||||
typedef short eint16;
|
||||
typedef signed short esint16;
|
||||
typedef unsigned short euint16;
|
||||
typedef long eint32;
|
||||
typedef signed long esint32;
|
||||
typedef unsigned long euint32;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,44 +0,0 @@
|
||||
/*****************************************************************************\
|
||||
* EFSL - Embedded Filesystems Library *
|
||||
* ----------------------------------- *
|
||||
* *
|
||||
* Filename : ioctl.h *
|
||||
* Release : 0.3 - devel *
|
||||
* Description : This file contains the ioctl command numbers *
|
||||
* *
|
||||
* 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; version 2 *
|
||||
* of the License. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
* This exception does not invalidate any other reasons why a work based *
|
||||
* on this file might be covered by the GNU General Public License. *
|
||||
* *
|
||||
* (c)2006 Lennart Yseboodt *
|
||||
* (c)2006 Michael De Nil *
|
||||
\*****************************************************************************/
|
||||
|
||||
#ifndef __EFS_IOCTL_H__
|
||||
#define __EFS_IOCTL_H__
|
||||
|
||||
/*****************************************************************************/
|
||||
#include "config.h"
|
||||
/*****************************************************************************/
|
||||
|
||||
#define IOCTL_NOP 0
|
||||
#define IOCTL_SECTORCOUNT 1
|
||||
|
||||
#endif
|
||||
@@ -1,41 +0,0 @@
|
||||
#ifndef __DFS_CACHE_H__
|
||||
#define __DFS_CACHE_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#define IOMAN_STATUS_ATTR_VALIDDATA 0
|
||||
#define IOMAN_STATUS_ATTR_USERBUFFER 1
|
||||
#define IOMAN_STATUS_ATTR_WRITE 2
|
||||
|
||||
#define IOM_MODE_READONLY 1
|
||||
#define IOM_MODE_READWRITE 2
|
||||
#define IOM_MODE_EXP_REQ 4
|
||||
|
||||
#define DFS_SECTOR_SIZE 512
|
||||
|
||||
struct _IOManager
|
||||
{
|
||||
rt_device_t device;
|
||||
rt_uint8_t numbuf;
|
||||
|
||||
rt_uint32_t sector[DFS_CACHE_MAX_NUM];
|
||||
rt_uint8_t status[DFS_CACHE_MAX_NUM];
|
||||
rt_uint8_t usage [DFS_CACHE_MAX_NUM];
|
||||
|
||||
/* cache FIFO */
|
||||
rt_uint8_t ring_fifo[DFS_CACHE_MAX_NUM];
|
||||
|
||||
/* cache buffer */
|
||||
rt_uint8_t cache[DFS_CACHE_MAX_NUM][DFS_SECTOR_SIZE];
|
||||
};
|
||||
typedef struct _IOManager IOManager;
|
||||
|
||||
rt_err_t ioman_init(IOManager* ioman);
|
||||
rt_uint8_t* ioman_getSector(IOManager *ioman, rt_uint32_t address, rt_uint8_t mode);
|
||||
rt_err_t ioman_releaseSector(IOManager *ioman, rt_uint8_t* buf);
|
||||
rt_err_t ioman_flushRange(IOManager *ioman, rt_uint32_t address_low, rt_uint32_t address_high);
|
||||
|
||||
rt_err_t ioman_directSectorRead(IOManager *ioman, rt_uint32_t address, rt_uint8_t* buf, rt_uint32_t numsector);
|
||||
rt_err_t ioman_directSectorWrite(IOManager *ioman, rt_uint32_t address, rt_uint8_t* buf, rt_uint32_t numsector);
|
||||
|
||||
#endif
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Project : Device Filesystem
|
||||
+------------------------------------------------------------------------------
|
||||
| Copyright 2004, 2005 www.fayfayspace.org.
|
||||
| All rights reserved.
|
||||
|------------------------------------------------------------------------------
|
||||
| File : dfs_efs.h
|
||||
|------------------------------------------------------------------------------
|
||||
| Chang Logs:
|
||||
| Date Author Notes
|
||||
| 2008-08-30 Yi.Qiu
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef __DFS_EFS_H__
|
||||
#define __DFS_EFS_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int efsl_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,273 +0,0 @@
|
||||
/*
|
||||
+------------------------------------------------------------------------------
|
||||
| Project : Device Filesystem
|
||||
+------------------------------------------------------------------------------
|
||||
| Copyright 2004 - 2009 www.rt-thread.org
|
||||
| All rights reserved.
|
||||
|------------------------------------------------------------------------------
|
||||
| File : dfs_cache.c, the LUT disk cache implementation
|
||||
|------------------------------------------------------------------------------
|
||||
| Chang Logs:
|
||||
| Date Author Notes
|
||||
| 2009-04-26 bernard The first version.
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
#include "dfs_cache.h"
|
||||
|
||||
#define ioman_isReqRo(mode) ((mode)&(IOM_MODE_READONLY))
|
||||
#define ioman_isReqRw(mode) ((mode)&(IOM_MODE_READWRITE))
|
||||
#define ioman_isReqExp(mode) ((mode)&(IOM_MODE_EXP_REQ))
|
||||
|
||||
rt_err_t ioman_init(IOManager* ioman)
|
||||
{
|
||||
register rt_uint32_t index;
|
||||
RT_ASSERT(ioman != RT_NULL);
|
||||
|
||||
ioman->numbuf = DFS_CACHE_MAX_NUM;
|
||||
|
||||
rt_memset(ioman->sector, 0,sizeof(ioman->sector));
|
||||
rt_memset(ioman->status, 0,sizeof(ioman->status));
|
||||
rt_memset(ioman->usage, 0, sizeof(ioman->usage));
|
||||
rt_memset(ioman->ring_fifo, 0, sizeof(ioman->ring_fifo));
|
||||
rt_memset(ioman->cache, 0, sizeof(ioman->cache));
|
||||
|
||||
/* init fifo */
|
||||
for (index = 0; index < ioman->numbuf; index ++)
|
||||
{
|
||||
ioman->ring_fifo[index] = ioman->numbuf - index - 1;
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/*
|
||||
* get the last fifo item and put it to the top of fifo ring
|
||||
*/
|
||||
static rt_uint8_t ioman_ring_fifo_swap(IOManager *ioman)
|
||||
{
|
||||
rt_uint8_t bp;
|
||||
rt_uint32_t index;
|
||||
|
||||
bp = ioman->ring_fifo[ioman->numbuf - 1];
|
||||
for (index = ioman->numbuf - 1; index > 0; index --)
|
||||
{
|
||||
ioman->ring_fifo[index] = ioman->ring_fifo[index - 1];
|
||||
}
|
||||
|
||||
ioman->ring_fifo[0] = bp;
|
||||
|
||||
return bp;
|
||||
}
|
||||
|
||||
/*
|
||||
* get the index of bp in fifo ring and then put it to the top of
|
||||
* fifo ring
|
||||
*/
|
||||
static void ioman_ring_fifo_relocate(IOManager *ioman, rt_uint32_t bp)
|
||||
{
|
||||
rt_uint32_t bp_index = 0;
|
||||
register rt_uint32_t index;
|
||||
|
||||
/* find bp in fifo ring */
|
||||
for (index = 0; index < ioman->numbuf; index ++)
|
||||
{
|
||||
if (ioman->ring_fifo[index] == bp)
|
||||
{
|
||||
bp_index = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* not found bp in fifo ring */
|
||||
if (index == ioman->numbuf) return;
|
||||
|
||||
/* move the bp to the top of fifo ring */
|
||||
for (index = bp_index; index > 0; index --)
|
||||
{
|
||||
ioman->ring_fifo[index] = ioman->ring_fifo[index - 1];
|
||||
}
|
||||
ioman->ring_fifo[0] = bp;
|
||||
}
|
||||
|
||||
/*
|
||||
* get last bp in fifo ring
|
||||
*/
|
||||
rt_inline rt_uint8_t ioman_ring_fifo_last(IOManager *ioman)
|
||||
{
|
||||
RT_ASSERT(ioman != RT_NULL);
|
||||
return ioman->ring_fifo[ioman->numbuf - 1];
|
||||
}
|
||||
|
||||
static rt_err_t ioman_readSector(IOManager *ioman, rt_uint32_t address, rt_uint8_t* buf)
|
||||
{
|
||||
rt_err_t result;
|
||||
|
||||
RT_ASSERT(buf != RT_NULL);
|
||||
|
||||
result = rt_device_read(ioman->device, address * DFS_SECTOR_SIZE, buf, DFS_SECTOR_SIZE);
|
||||
if (result == DFS_SECTOR_SIZE) return RT_EOK;
|
||||
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
static rt_err_t ioman_writeSector(IOManager *ioman, rt_uint32_t address, rt_uint8_t* buf)
|
||||
{
|
||||
rt_err_t result;
|
||||
|
||||
RT_ASSERT(buf != RT_NULL);
|
||||
|
||||
result = rt_device_write(ioman->device, address * DFS_SECTOR_SIZE, buf, DFS_SECTOR_SIZE);
|
||||
if (result == DFS_SECTOR_SIZE) return RT_EOK;
|
||||
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
static rt_int32_t ioman_findSectorInCache(IOManager *ioman, rt_uint32_t address)
|
||||
{
|
||||
rt_uint32_t c;
|
||||
|
||||
for(c=0;c<ioman->numbuf;c++)
|
||||
{
|
||||
if((ioman->status[c] & (1 << IOMAN_STATUS_ATTR_VALIDDATA)) &&
|
||||
ioman->sector[c] == address)
|
||||
return (c);
|
||||
}
|
||||
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
static rt_err_t ioman_flushSector(IOManager *ioman, rt_uint32_t bp)
|
||||
{
|
||||
rt_err_t result;
|
||||
|
||||
RT_ASSERT(ioman != RT_NULL);
|
||||
|
||||
result = ioman_writeSector(ioman, ioman->sector[bp], &ioman->cache[bp][0]);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
/* set status */
|
||||
ioman->status[bp] &= ~(1 << IOMAN_STATUS_ATTR_WRITE);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
rt_uint8_t* ioman_getSector(IOManager *ioman, rt_uint32_t address, rt_uint8_t mode)
|
||||
{
|
||||
rt_int32_t bp;
|
||||
|
||||
RT_ASSERT(ioman != RT_NULL);
|
||||
|
||||
bp = ioman_findSectorInCache(ioman, address);
|
||||
if (bp != -RT_ERROR)
|
||||
{
|
||||
/* incress cache usage */
|
||||
ioman->usage[bp] ++;
|
||||
|
||||
/* relocate bp in fifo ring */
|
||||
ioman_ring_fifo_relocate(ioman, bp);
|
||||
|
||||
if (ioman_isReqRw(mode))
|
||||
ioman->status[bp] |= (1 << IOMAN_STATUS_ATTR_WRITE);
|
||||
|
||||
return &(ioman->cache[bp][0]);
|
||||
}
|
||||
|
||||
/* not find in cache, get the last bp in fifo ring */
|
||||
bp = ioman_ring_fifo_last(ioman);
|
||||
if ((ioman->status[bp] & (1 << IOMAN_STATUS_ATTR_WRITE)) &&
|
||||
ioman->usage[bp] == 0)
|
||||
{
|
||||
/* it's a writable buffer, flush it */
|
||||
ioman_flushSector(ioman, bp);
|
||||
}
|
||||
|
||||
/* strip last bp in fifo ring */
|
||||
bp = ioman_ring_fifo_swap(ioman);
|
||||
|
||||
/* read sector */
|
||||
ioman_readSector(ioman, address, &ioman->cache[bp][0]);
|
||||
ioman->sector[bp] = address;
|
||||
ioman->usage [bp] = 1;
|
||||
ioman->status[bp] = (1 << IOMAN_STATUS_ATTR_VALIDDATA);
|
||||
if (ioman_isReqRw(mode))
|
||||
ioman->status[bp] |= (1 << IOMAN_STATUS_ATTR_WRITE);
|
||||
|
||||
return &ioman->cache[bp][0];
|
||||
}
|
||||
|
||||
rt_err_t ioman_releaseSector(IOManager *ioman, rt_uint8_t* buf)
|
||||
{
|
||||
rt_uint32_t bp;
|
||||
|
||||
/* get buffer place */
|
||||
bp = ((rt_uint32_t)buf - (rt_uint32_t)&ioman->cache[0]) / DFS_SECTOR_SIZE;
|
||||
|
||||
/* decrease usage */
|
||||
if (ioman->usage[bp] > 0) ioman->usage[bp] --;
|
||||
if (ioman->usage[bp] == 0)
|
||||
{
|
||||
if(ioman->status[bp] & (1 << IOMAN_STATUS_ATTR_WRITE))
|
||||
{
|
||||
ioman_flushSector(ioman,bp);
|
||||
}
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
rt_err_t ioman_flushRange(IOManager *ioman, rt_uint32_t address_low, rt_uint32_t address_high)
|
||||
{
|
||||
rt_uint32_t c;
|
||||
|
||||
if(address_low > address_high)
|
||||
{
|
||||
c = address_low; address_low = address_high; address_high = c;
|
||||
}
|
||||
|
||||
for(c = 0; c < ioman->numbuf; c++)
|
||||
{
|
||||
if((ioman->sector[c]>=address_low)
|
||||
&& (ioman->sector[c]<=address_high)
|
||||
&& (ioman->status[c] & (1 << IOMAN_STATUS_ATTR_WRITE)))
|
||||
{
|
||||
if(ioman_flushSector(ioman,c) != RT_EOK)
|
||||
return -RT_ERROR;
|
||||
|
||||
/* remove writable status */
|
||||
if(ioman->usage[c]==0) ioman->status[c] &= ~IOMAN_STATUS_ATTR_WRITE;
|
||||
}
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/*
|
||||
* read multi-sectors directly (none-cachable)
|
||||
*/
|
||||
rt_err_t ioman_directSectorRead(IOManager *ioman, rt_uint32_t address, rt_uint8_t* buf, rt_uint32_t numsector)
|
||||
{
|
||||
rt_err_t result;
|
||||
|
||||
RT_ASSERT(buf != RT_NULL);
|
||||
|
||||
result = rt_device_read(ioman->device, address * DFS_SECTOR_SIZE, buf, DFS_SECTOR_SIZE * numsector);
|
||||
if (result == DFS_SECTOR_SIZE * numsector) return RT_EOK;
|
||||
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* write multi-sectors directly (none-cachable)
|
||||
*/
|
||||
rt_err_t ioman_directSectorWrite(IOManager *ioman, rt_uint32_t address, rt_uint8_t* buf, rt_uint32_t numsector)
|
||||
{
|
||||
rt_err_t result;
|
||||
|
||||
RT_ASSERT(buf != RT_NULL);
|
||||
|
||||
result = rt_device_write(ioman->device, address * DFS_SECTOR_SIZE, buf, DFS_SECTOR_SIZE * numsector);
|
||||
if (result == DFS_SECTOR_SIZE * numsector) return RT_EOK;
|
||||
|
||||
return -RT_ERROR;
|
||||
}
|
||||
Reference in New Issue
Block a user