projects
/
yaffs2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add files to hook up yaffs direct to u-boot
[yaffs2.git]
/
direct
/
yaffsfs.c
diff --git
a/direct/yaffsfs.c
b/direct/yaffsfs.c
index 2b2b8593422466736b82c20d5ccd8fb534bf2c57..fffc11eece7b691892c767c5122a04e556374514 100644
(file)
--- a/
direct/yaffsfs.c
+++ b/
direct/yaffsfs.c
@@
-17,7
+17,7
@@
#include "yportenv.h"
#include "yaffs_trace.h"
#include "yportenv.h"
#include "yaffs_trace.h"
-#include
<string.h> /* for memset */
+#include
"string.h"
#define YAFFSFS_MAX_SYMLINK_DEREFERENCES 5
#define YAFFSFS_MAX_SYMLINK_DEREFERENCES 5
@@
-75,7
+75,7
@@
typedef struct{
u8 shareWrite:1;
int inodeId:12; /* Index to corresponding yaffsfs_Inode */
int handleCount:10; /* Number of handles for this fd */
u8 shareWrite:1;
int inodeId:12; /* Index to corresponding yaffsfs_Inode */
int handleCount:10; /* Number of handles for this fd */
-
u32 position;
/* current position in file */
+
loff_t position;
/* current position in file */
}yaffsfs_FileDes;
typedef struct {
}yaffsfs_FileDes;
typedef struct {
@@
-380,13
+380,27
@@
static void yaffsfs_BreakDeviceHandles(struct yaffs_dev *dev)
/*
* Stuff to handle names.
*/
/*
* Stuff to handle names.
*/
+#ifdef CONFIG_YAFFS_CASE_INSENSITIVE
+
+static int yaffs_toupper(YCHAR a)
+{
+ if(a >= 'a' && a <= 'z')
+ return (a - 'a') + 'A';
+ else
+ return a;
+}
-
+int yaffsfs_Match(YCHAR a, YCHAR b)
+{
+ return (yaffs_toupper(a) == yaffs_toupper(b));
+}
+#else
int yaffsfs_Match(YCHAR a, YCHAR b)
{
/* case sensitive */
return (a == b);
}
int yaffsfs_Match(YCHAR a, YCHAR b)
{
/* case sensitive */
return (a == b);
}
+#endif
int yaffsfs_IsPathDivider(YCHAR ch)
{
int yaffsfs_IsPathDivider(YCHAR ch)
{
@@
-405,7
+419,7
@@
int yaffsfs_CheckNameLength(const char *name)
{
int retVal = 0;
{
int retVal = 0;
- int nameLength = strnlen(name,YAFFS_MAX_NAME_LENGTH+1);
+ int nameLength =
yaffs_
strnlen(name,YAFFS_MAX_NAME_LENGTH+1);
if(nameLength == 0){
yaffsfs_SetError(-ENOENT);
if(nameLength == 0){
yaffsfs_SetError(-ENOENT);
@@
-430,7
+444,7
@@
static int yaffsfs_alt_dir_path(const YCHAR *path, YCHAR **ret_path)
* We will use 3 * max name length instead.
*/
*ret_path = NULL;
* We will use 3 * max name length instead.
*/
*ret_path = NULL;
- path_length = strnlen(path,(YAFFS_MAX_NAME_LENGTH+1)*3 +1);
+ path_length =
yaffs_
strnlen(path,(YAFFS_MAX_NAME_LENGTH+1)*3 +1);
/* If the last character is a path divider, then we need to
* trim it back so that the name look-up works properly.
/* If the last character is a path divider, then we need to
* trim it back so that the name look-up works properly.
@@
-443,7
+457,7
@@
static int yaffsfs_alt_dir_path(const YCHAR *path, YCHAR **ret_path)
alt_path = kmalloc(path_length + 1, 0);
if(!alt_path)
return -1;
alt_path = kmalloc(path_length + 1, 0);
if(!alt_path)
return -1;
- strcpy(alt_path, path);
+
yaffs_
strcpy(alt_path, path);
for(i = path_length-1;
i >= 0 && yaffsfs_IsPathDivider(alt_path[i]);
i--)
for(i = path_length-1;
i >= 0 && yaffsfs_IsPathDivider(alt_path[i]);
i--)
@@
-650,9
+664,9
@@
static struct yaffs_obj *yaffsfs_DoFindDirectory(struct yaffs_obj *startDir,
/* got to the end of the string */
return dir;
else{
/* got to the end of the string */
return dir;
else{
- if(strcmp(str,_Y(".")) == 0){
+ if(
yaffs_
strcmp(str,_Y(".")) == 0){
/* Do nothing */
/* Do nothing */
- } else if(strcmp(str,_Y("..")) == 0) {
+ } else if(
yaffs_
strcmp(str,_Y("..")) == 0) {
dir = dir->parent;
} else{
dir = yaffs_find_by_name(dir,str);
dir = dir->parent;
} else{
dir = yaffs_find_by_name(dir,str);
@@
-743,7
+757,15
@@
int yaffs_dup(int handle)
}
}
+static int yaffsfs_TooManyObjects(struct yaffs_dev *dev)
+{
+ int current_objects = dev->n_obj - dev->n_deleted_files;
+ if(dev->param.max_objects && current_objects > dev->param.max_objects)
+ return 1;
+ else
+ return 0;
+}
int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
{
int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
{
@@
-915,6
+937,9
@@
int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
if(dir->my_dev->read_only){
yaffsfs_SetError(-EROFS);
errorReported = 1;
if(dir->my_dev->read_only){
yaffsfs_SetError(-EROFS);
errorReported = 1;
+ } else if(yaffsfs_TooManyObjects(dir->my_dev)) {
+ yaffsfs_SetError(-ENFILE);
+ errorReported = 1;
} else
obj = yaffs_create_file(dir,name,mode,0,0);
} else
obj = yaffs_create_file(dir,name,mode,0,0);
@@
-1037,17
+1062,17
@@
int yaffs_close(int handle)
-int yaffsfs_do_read(int handle, void *vbuf, unsigned int nbyte, int isPread,
in
t offset)
+int yaffsfs_do_read(int handle, void *vbuf, unsigned int nbyte, int isPread,
loff_
t offset)
{
yaffsfs_FileDes *fd = NULL;
struct yaffs_obj *obj = NULL;
{
yaffsfs_FileDes *fd = NULL;
struct yaffs_obj *obj = NULL;
-
in
t pos = 0;
-
in
t startPos = 0;
-
in
t endPos = 0;
+
loff_
t pos = 0;
+
loff_
t startPos = 0;
+
loff_
t endPos = 0;
int nRead = 0;
int nToRead = 0;
int totalRead = 0;
int nRead = 0;
int nToRead = 0;
int totalRead = 0;
-
unsigned in
t maxRead;
+
loff_
t maxRead;
u8 *buf = (u8 *)vbuf;
if(!vbuf){
u8 *buf = (u8 *)vbuf;
if(!vbuf){
@@
-1154,18
+1179,18
@@
int yaffs_read(int handle, void *buf, unsigned int nbyte)
return yaffsfs_do_read(handle, buf, nbyte, 0, 0);
}
return yaffsfs_do_read(handle, buf, nbyte, 0, 0);
}
-int yaffs_pread(int handle, void *buf, unsigned int nbyte,
unsigned in
t offset)
+int yaffs_pread(int handle, void *buf, unsigned int nbyte,
loff_
t offset)
{
return yaffsfs_do_read(handle, buf, nbyte, 1, offset);
}
{
return yaffsfs_do_read(handle, buf, nbyte, 1, offset);
}
-int yaffsfs_do_write(int handle, const void *vbuf, unsigned int nbyte, int isPwrite,
in
t offset)
+int yaffsfs_do_write(int handle, const void *vbuf, unsigned int nbyte, int isPwrite,
loff_
t offset)
{
yaffsfs_FileDes *fd = NULL;
struct yaffs_obj *obj = NULL;
{
yaffsfs_FileDes *fd = NULL;
struct yaffs_obj *obj = NULL;
-
in
t pos = 0;
-
in
t startPos = 0;
-
in
t endPos;
+
loff_
t pos = 0;
+
loff_
t startPos = 0;
+
loff_
t endPos;
int nWritten = 0;
int totalWritten = 0;
int write_trhrough = 0;
int nWritten = 0;
int totalWritten = 0;
int write_trhrough = 0;
@@
-1268,13
+1293,13
@@
int yaffs_write(int fd, const void *buf, unsigned int nbyte)
return yaffsfs_do_write(fd, buf, nbyte, 0, 0);
}
return yaffsfs_do_write(fd, buf, nbyte, 0, 0);
}
-int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte,
unsigned in
t offset)
+int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte,
loff_
t offset)
{
return yaffsfs_do_write(fd, buf, nbyte, 1, offset);
}
{
return yaffsfs_do_write(fd, buf, nbyte, 1, offset);
}
-int yaffs_truncate(const YCHAR *path,off_t new_size)
+int yaffs_truncate(const YCHAR *path,
l
off_t new_size)
{
struct yaffs_obj *obj = NULL;
struct yaffs_obj *dir = NULL;
{
struct yaffs_obj *obj = NULL;
struct yaffs_obj *dir = NULL;
@@
-1312,14
+1337,14
@@
int yaffs_truncate(const YCHAR *path,off_t new_size)
else if(new_size < 0 || new_size > YAFFS_MAX_FILE_SIZE)
yaffsfs_SetError(-EINVAL);
else
else if(new_size < 0 || new_size > YAFFS_MAX_FILE_SIZE)
yaffsfs_SetError(-EINVAL);
else
- result = yaffs_resize_file(obj,new_size);
+ result = yaffs_resize_file(obj,
new_size);
yaffsfs_Unlock();
return (result) ? 0 : -1;
}
yaffsfs_Unlock();
return (result) ? 0 : -1;
}
-int yaffs_ftruncate(int handle, off_t new_size)
+int yaffs_ftruncate(int handle,
l
off_t new_size)
{
yaffsfs_FileDes *fd = NULL;
struct yaffs_obj *obj = NULL;
{
yaffsfs_FileDes *fd = NULL;
struct yaffs_obj *obj = NULL;
@@
-1340,19
+1365,19
@@
int yaffs_ftruncate(int handle, off_t new_size)
yaffsfs_SetError(-EINVAL);
else
/* resize the file */
yaffsfs_SetError(-EINVAL);
else
/* resize the file */
- result = yaffs_resize_file(obj,new_size);
+ result = yaffs_resize_file(obj,
new_size);
yaffsfs_Unlock();
return (result) ? 0 : -1;
}
yaffsfs_Unlock();
return (result) ? 0 : -1;
}
-
off_t yaffs_lseek(int handle,
off_t offset, int whence)
+
loff_t yaffs_lseek(int handle, l
off_t offset, int whence)
{
yaffsfs_FileDes *fd = NULL;
struct yaffs_obj *obj = NULL;
{
yaffsfs_FileDes *fd = NULL;
struct yaffs_obj *obj = NULL;
-
in
t pos = -1;
-
in
t fSize = -1;
+
loff_
t pos = -1;
+
loff_
t fSize = -1;
yaffsfs_Lock();
fd = yaffsfs_HandleToFileDes(handle);
yaffsfs_Lock();
fd = yaffsfs_HandleToFileDes(handle);
@@
-1419,7
+1444,7
@@
int yaffsfs_DoUnlink(const YCHAR *path,int isDirectory)
yaffsfs_SetError(-ELOOP);
else if(!dir)
yaffsfs_SetError(-ENOENT);
yaffsfs_SetError(-ELOOP);
else if(!dir)
yaffsfs_SetError(-ENOENT);
- else if(strncmp(name,_Y("."),2) == 0)
+ else if(
yaffs_
strncmp(name,_Y("."),2) == 0)
yaffsfs_SetError(-EINVAL);
else if(!obj)
yaffsfs_SetError(-ENOENT);
yaffsfs_SetError(-EINVAL);
else if(!obj)
yaffsfs_SetError(-ENOENT);
@@
-1507,7
+1532,7
@@
int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath)
} else if(oldLoop || newLoop) {
yaffsfs_SetError(-ELOOP);
rename_allowed = 0;
} else if(oldLoop || newLoop) {
yaffsfs_SetError(-ELOOP);
rename_allowed = 0;
- } else if (olddir && oldname && strncmp(oldname, _Y("."),2) == 0){
+ } else if (olddir && oldname &&
yaffs_
strncmp(oldname, _Y("."),2) == 0){
yaffsfs_SetError(-EINVAL);
rename_allowed = 0;
}else if(!olddir || !newdir || !obj) {
yaffsfs_SetError(-EINVAL);
rename_allowed = 0;
}else if(!olddir || !newdir || !obj) {
@@
-2366,7
+2391,9
@@
int yaffs_mkdir(const YCHAR *path, mode_t mode)
yaffsfs_SetError(-ELOOP);
else if(!parent)
yaffsfs_SetError(-ENOENT);
yaffsfs_SetError(-ELOOP);
else if(!parent)
yaffsfs_SetError(-ENOENT);
- else if(strnlen(name,5) == 0){
+ else if(yaffsfs_TooManyObjects(parent->my_dev))
+ yaffsfs_SetError(-ENFILE);
+ else if(yaffs_strnlen(name,5) == 0){
/* Trying to make the root itself */
yaffsfs_SetError(-EEXIST);
} else if(parent->my_dev->read_only)
/* Trying to make the root itself */
yaffsfs_SetError(-EEXIST);
} else if(parent->my_dev->read_only)
@@
-2425,7
+2452,7
@@
void * yaffs_getdev(const YCHAR *path)
return (void *)dev;
}
return (void *)dev;
}
-int yaffs_mount
2(const YCHAR *path,int read_only
)
+int yaffs_mount
_common(const YCHAR *path,int read_only, int skip_checkpt
)
{
int retVal=-1;
int result=YAFFS_FAIL;
{
int retVal=-1;
int result=YAFFS_FAIL;
@@
-2451,7
+2478,15
@@
int yaffs_mount2(const YCHAR *path,int read_only)
if(dev){
if(!dev->is_mounted){
dev->read_only = read_only ? 1 : 0;
if(dev){
if(!dev->is_mounted){
dev->read_only = read_only ? 1 : 0;
- result = yaffs_guts_initialise(dev);
+ if(skip_checkpt) {
+ u8 skip = dev->param.skip_checkpt_rd;
+ dev->param.skip_checkpt_rd = 1;
+ result = yaffs_guts_initialise(dev);
+ dev->param.skip_checkpt_rd = skip;
+ } else {
+ result = yaffs_guts_initialise(dev);
+ }
+
if(result == YAFFS_FAIL)
yaffsfs_SetError(-ENOMEM);
retVal = result ? 0 : -1;
if(result == YAFFS_FAIL)
yaffsfs_SetError(-ENOMEM);
retVal = result ? 0 : -1;
@@
-2467,9
+2502,13
@@
int yaffs_mount2(const YCHAR *path,int read_only)
}
}
+int yaffs_mount2(const YCHAR *path, int readonly)
+{
+ return yaffs_mount_common(path, readonly, 0);
+}
int yaffs_mount(const YCHAR *path)
{
int yaffs_mount(const YCHAR *path)
{
- return yaffs_mount
2(path,
0);
+ return yaffs_mount
_common(path, 0,
0);
}
int yaffs_sync(const YCHAR *path)
}
int yaffs_sync(const YCHAR *path)
@@
-2707,6
+2746,14
@@
int yaffs_inodecount(const YCHAR *path)
void yaffs_add_device(struct yaffs_dev *dev)
{
void yaffs_add_device(struct yaffs_dev *dev)
{
+ struct list_head *cfg;
+ /* First check that the device is not in the list. */
+
+ list_for_each(cfg, &yaffsfs_deviceList){
+ if(dev == list_entry(cfg, struct yaffs_dev, dev_list))
+ return;
+ }
+
dev->is_mounted = 0;
dev->param.remove_obj_fn = yaffsfs_RemoveObjectCallback;
dev->is_mounted = 0;
dev->param.remove_obj_fn = yaffsfs_RemoveObjectCallback;
@@
-2852,7
+2899,7
@@
yaffs_DIR *yaffs_opendir(const YCHAR *dirname)
memset(dsc,0,sizeof(yaffsfs_DirectorySearchContext));
dsc->magic = YAFFS_MAGIC;
dsc->dirObj = obj;
memset(dsc,0,sizeof(yaffsfs_DirectorySearchContext));
dsc->magic = YAFFS_MAGIC;
dsc->dirObj = obj;
- strncpy(dsc->name,dirname,NAME_MAX);
+
yaffs_
strncpy(dsc->name,dirname,NAME_MAX);
INIT_LIST_HEAD(&dsc->others);
if(!search_contexts.next)
INIT_LIST_HEAD(&dsc->others);
if(!search_contexts.next)
@@
-2883,10
+2930,10
@@
struct yaffs_dirent *yaffs_readdir(yaffs_DIR *dirp)
dsc->de.d_dont_use = (unsigned)dsc->nextReturn;
dsc->de.d_off = dsc->offset++;
yaffs_get_obj_name(dsc->nextReturn,dsc->de.d_name,NAME_MAX);
dsc->de.d_dont_use = (unsigned)dsc->nextReturn;
dsc->de.d_off = dsc->offset++;
yaffs_get_obj_name(dsc->nextReturn,dsc->de.d_name,NAME_MAX);
- if(strnlen(dsc->de.d_name,NAME_MAX+1) == 0)
+ if(
yaffs_
strnlen(dsc->de.d_name,NAME_MAX+1) == 0)
{
/* this should not happen! */
{
/* this should not happen! */
- strcpy(dsc->de.d_name,_Y("zz"));
+
yaffs_
strcpy(dsc->de.d_name,_Y("zz"));
}
dsc->de.d_reclen = sizeof(struct yaffs_dirent);
retVal = &dsc->de;
}
dsc->de.d_reclen = sizeof(struct yaffs_dirent);
retVal = &dsc->de;
@@
-2962,8
+3009,10
@@
int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath)
yaffsfs_SetError(-ENOTDIR);
else if(loop)
yaffsfs_SetError(-ELOOP);
yaffsfs_SetError(-ENOTDIR);
else if(loop)
yaffsfs_SetError(-ELOOP);
- else if( !parent || strnlen(name,5) < 1)
+ else if( !parent ||
yaffs_
strnlen(name,5) < 1)
yaffsfs_SetError(-ENOENT);
yaffsfs_SetError(-ENOENT);
+ else if(yaffsfs_TooManyObjects(parent->my_dev))
+ yaffsfs_SetError(-ENFILE);
else if(parent->my_dev->read_only)
yaffsfs_SetError(-EROFS);
else if(parent){
else if(parent->my_dev->read_only)
yaffsfs_SetError(-EROFS);
else if(parent){
@@
-3010,7
+3059,7
@@
int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz)
else {
YCHAR *alias = obj->variant.symlink_variant.alias;
memset(buf,0,bufsiz);
else {
YCHAR *alias = obj->variant.symlink_variant.alias;
memset(buf,0,bufsiz);
- strncpy(buf,alias,bufsiz - 1);
+
yaffs_
strncpy(buf,alias,bufsiz - 1);
retVal = 0;
}
yaffsfs_Unlock();
retVal = 0;
}
yaffsfs_Unlock();
@@
-3056,6
+3105,8
@@
int yaffs_link(const YCHAR *oldpath, const YCHAR *linkpath)
yaffsfs_SetError(-ENOENT);
else if(obj->my_dev->read_only)
yaffsfs_SetError(-EROFS);
yaffsfs_SetError(-ENOENT);
else if(obj->my_dev->read_only)
yaffsfs_SetError(-EROFS);
+ else if(yaffsfs_TooManyObjects(obj->my_dev))
+ yaffsfs_SetError(-ENFILE);
else if(lnk)
yaffsfs_SetError(-EEXIST);
else if(lnk_dir->my_dev != obj->my_dev)
else if(lnk)
yaffsfs_SetError(-EEXIST);
else if(lnk_dir->my_dev != obj->my_dev)