/*
* YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
*
- * Copyright (C) 2002-2010 Aleph One Ltd.
+ * Copyright (C) 2002-2011 Aleph One Ltd.
* for Toby Churchill Ltd and Brightstar Engineering
*
* Created by Charles Manning <charles@aleph1.co.uk>
static int yaffsfs_handlesInitialised;
-unsigned yaffs_set_trace(unsigned tm)
+unsigned yaffs_set_trace(unsigned tm)
{
yaffs_trace_mask = tm;
return yaffs_trace_mask;
{
yaffsfs_FileDes *fd = yaffsfs_HandleToFileDes(handle);
- if(fd && fd->handleCount > 0 &&
+ if(fd && fd->handleCount > 0 &&
fd->inodeId >= 0 && fd->inodeId < YAFFSFS_N_HANDLES)
return &yaffsfs_inode[fd->inodeId];
{
int i;
int ret = -1;
-
+
if(obj)
obj = yaffs_get_equivalent_obj(obj);
int i;
int ret;
yaffsfs_Inode *in = NULL;
-
+
if(obj)
obj = yaffs_get_equivalent_obj(obj);
in->iObj = obj;
in->count++;
}
-
-
+
+
return ret;
}
static void yaffsfs_ReleaseInode(yaffsfs_Inode *in)
{
struct yaffs_obj *obj;
-
+
obj = in->iObj;
if(obj->unlinked)
yaffs_del_obj(obj);
-
+
obj->my_inode = NULL;
in->iObj = NULL;
yaffsfs_ReleaseInode(in);
in->count = 0;
}
- }
+ }
}
{
yaffsfs_Handle *h = yaffsfs_HandleToPointer(handle);
- if(h && h->useCount > 0){
+ if(h && h->useCount > 0){
h->useCount++;
return 0;
}
{
yaffsfs_Handle *h = yaffsfs_HandleToPointer(handle);
- if(h && h->useCount > 0){
+ if(h && h->useCount > 0){
h->useCount--;
if(h->useCount < 1){
yaffsfs_PutFileDes(h->fdId);
h->fdId = 0;
}
if(fd && fd->handleCount>0 && obj && obj->my_dev == dev){
-
+
fd->handleCount = 0;
yaffsfs_PutInode(fd->inodeId);
fd->inodeId = -1;
int yaffsfs_CheckNameLength(const char *name)
{
- int retVal = 0;
+ int retVal = 0;
int nameLength = strnlen(name,YAFFS_MAX_NAME_LENGTH+1);
-
+
if(nameLength == 0){
yaffsfs_SetError(-ENOENT);
retVal = -1;
retVal = -1;
}
- return retVal;
+ return retVal;
}
* Curveball: Need to handle multiple path dividers:
* eg. /foof/sdfse///// -> /foo/sdfse
*/
- if(path_length > 0 &&
+ if(path_length > 0 &&
yaffsfs_IsPathDivider(path[path_length-1])){
alt_path = kmalloc(path_length + 1, 0);
if(!alt_path)
n++;
path++;
}
-
+
return (*path) ? -1 : 0;
}
dir = yaffsfs_FollowLink(dir,symDepth,loop);
- if(dir && dir->variant_type !=
+ if(dir && dir->variant_type !=
YAFFS_OBJECT_TYPE_DIRECTORY){
if(notDir)
*notDir = 1;
dir = NULL;
}
-
+
}
}
}
/*************************************************************************
- * Start of yaffsfs visible functions.
+ * Start of yaffsfs visible functions.
*************************************************************************/
int yaffs_dup(int handle)
if( writeRequested && !(obj->yst_mode & S_IWRITE))
openDenied = 1;
- if( !errorReported && writeRequested &&
+ if( !errorReported && writeRequested &&
obj->my_dev->read_only){
openDenied = 1;
yaffsfs_SetError(-EROFS);
- if((!sharedReadAllowed && readRequested)||
+ if((!sharedReadAllowed && readRequested)||
(!shareRead && alreadyReading) ||
(!sharedWriteAllowed && writeRequested) ||
(!shareWrite && alreadyWriting)){
if(inodeId<0) {
/*
* Todo: Fix any problem if inodes run out, though that
- * can't happen if the number of inode items >= number of handles.
+ * can't happen if the number of inode items >= number of handles.
*/
}
-
+
fd->inodeId = inodeId;
fd->reading = readRequested;
fd->writing = writeRequested;
yaffs_resize_file(obj,0);
} else {
yaffsfs_PutHandle(handle);
- if(!errorReported)
+ if(!errorReported)
yaffsfs_SetError(0); /* Problem */
handle = -1;
}
yaffsfs_SetError(-EBADF);
else if(obj->my_dev->read_only)
yaffsfs_SetError(-EROFS);
- else {
+ else {
yaffs_flush_file(obj,1,datasync);
retVal = 0;
}
startPos = fd->position;
pos = startPos;
-
+
if(yaffs_get_obj_length(obj) > pos)
maxRead = yaffs_get_obj_length(obj) - pos;
else
if(nToRead > nbyte)
nToRead = nbyte;
- /* Tricky bit...
+ /* Tricky bit...
* Need to reverify object in case the device was
* unmounted in another thread.
*/
nbyte-=nRead;
else
nbyte = 0; /* no more to read */
-
-
+
+
if(nbyte > 0){
yaffsfs_Unlock();
yaffsfs_Lock();
if(nToWrite > nbyte)
nToWrite = nbyte;
- /* Tricky bit...
+ /* Tricky bit...
* Need to reverify object in case the device was
* remounted or unmounted in another thread.
*/
fSize = yaffs_get_obj_length(obj);
if(fSize >= 0 && (fSize + offset) >= 0)
pos = fSize + offset;
- }
+ }
if(pos >= 0 && pos <= YAFFS_MAX_FILE_SIZE)
fd->position = pos;
obj = yaffsfs_FindObject(NULL,oldPath,0,0,NULL,NULL,NULL);
newobj = yaffsfs_FindObject(NULL,newPath,0,0,NULL,NULL,NULL);
- /* If the object being renamed is a directory and the
+ /* If the object being renamed is a directory and the
* path ended with a "/" then the olddir == obj.
* We pass through NULL for the old name to tell the lower layers
* to use olddir as the object.
/*
* It is a directory, check that it is not being renamed to
* being its own decendent.
- * Do this by tracing from the new directory back to the root,
+ * Do this by tracing from the new directory back to the root,
* checking for obj
*/
return retVal;
}
+static int yaffsfs_DoUtime(struct yaffs_obj *obj,const struct yaffs_utimbuf *buf)
+{
+ int retVal = -1;
+ int result;
+
+ struct yaffs_utimbuf local;
+
+ obj = yaffs_get_equivalent_obj(obj);
+
+ if(obj && obj->my_dev->read_only) {
+ yaffsfs_SetError(-EROFS);
+ return -1;
+ }
+
+
+ if(!buf){
+ local.actime = Y_CURRENT_TIME;
+ local.modtime = local.actime;
+ buf = &local;
+ }
+
+ if(obj){
+ obj->yst_atime = buf->actime;
+ obj->yst_mtime = buf->modtime;
+ obj->dirty = 1;
+ result = yaffs_flush_file(obj,0,0);
+ retVal = result == YAFFS_OK ? 0 : -1;
+ }
+
+ return retVal;
+}
+
+int yaffs_utime(const YCHAR *path, const struct yaffs_utimbuf *buf)
+{
+ struct yaffs_obj *obj=NULL;
+ struct yaffs_obj *dir=NULL;
+ int retVal = -1;
+ int notDir = 0;
+ int loop = 0;
+
+ if(!path){
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ if(yaffsfs_CheckPath(path) < 0){
+ yaffsfs_SetError(-ENAMETOOLONG);
+ return -1;
+ }
+
+ yaffsfs_Lock();
+
+ obj = yaffsfs_FindObject(NULL,path,0,1,&dir,¬Dir,&loop);
+
+ if(!dir && notDir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(loop)
+ yaffsfs_SetError(-ELOOP);
+ else if(!dir || !obj)
+ yaffsfs_SetError(-ENOENT);
+ else
+ retVal = yaffsfs_DoUtime(obj,buf);
+
+ yaffsfs_Unlock();
+
+ return retVal;
+
+}
+int yaffs_futime(int fd, const struct yaffs_utimbuf *buf)
+{
+ struct yaffs_obj *obj;
+
+ int retVal = -1;
+
+ yaffsfs_Lock();
+ obj = yaffsfs_HandleToObject(fd);
+
+ if(obj)
+ retVal = yaffsfs_DoUtime(obj,buf);
+ else
+ /* bad handle */
+ yaffsfs_SetError(-EBADF);
+
+ yaffsfs_Unlock();
+
+ return retVal;
+}
+
+
#ifndef CONFIG_YAFFS_WINCE
/* xattrib functions */
if(follow)
obj = yaffsfs_FollowLink(obj,0,&loop);
- if(!dir && notDir)
+ if(!dir && notDir)
yaffsfs_SetError(-ENOTDIR);
- else if(loop)
+ else if(loop)
yaffsfs_SetError(-ELOOP);
- else if(!dir || !obj)
+ else if(!dir || !obj)
yaffsfs_SetError(-ENOENT);
else {
retVal = yaffs_set_xattrib(obj,name,data,size,flags);
yaffsfs_Lock();
obj = yaffsfs_HandleToObject(fd);
- if(!obj)
+ if(!obj)
yaffsfs_SetError(-EBADF);
else {
retVal = yaffs_set_xattrib(obj,name,data,size,flags);
if(follow)
obj = yaffsfs_FollowLink(obj,0,&loop);
- if(!dir && notDir)
+ if(!dir && notDir)
yaffsfs_SetError(-ENOTDIR);
- else if(loop)
+ else if(loop)
yaffsfs_SetError(-ELOOP);
- else if(!dir || !obj)
+ else if(!dir || !obj)
yaffsfs_SetError(-ENOENT);
else {
retVal = yaffs_get_xattrib(obj,name,data,size);
if(follow)
obj = yaffsfs_FollowLink(obj,0,&loop);
- if(!dir && notDir)
+ if(!dir && notDir)
yaffsfs_SetError(-ENOTDIR);
- else if(loop)
+ else if(loop)
yaffsfs_SetError(-ELOOP);
- else if(!dir || !obj)
+ else if(!dir || !obj)
yaffsfs_SetError(-ENOENT);
else {
retVal = yaffs_list_xattrib(obj, data,size);
if(follow)
obj = yaffsfs_FollowLink(obj,0,&loop);
- if(!dir && notDir)
+ if(!dir && notDir)
yaffsfs_SetError(-ENOTDIR);
- else if(loop)
+ else if(loop)
yaffsfs_SetError(-ELOOP);
- else if(!dir || !obj)
+ else if(!dir || !obj)
yaffsfs_SetError(-ENOENT);
else {
retVal = yaffs_remove_xattrib(obj,name);
retVal = 0;
} else
/* bad handle */
- yaffsfs_SetError(-EBADF);
-
+ yaffsfs_SetError(-EBADF);
+
yaffsfs_Unlock();
-
+
return retVal;
}
-int yaffs_set_wince_times(int fd,
- const unsigned *wctime,
- const unsigned *watime,
+int yaffs_set_wince_times(int fd,
+ const unsigned *wctime,
+ const unsigned *watime,
const unsigned *wmtime)
{
struct yaffs_obj *obj;
obj = yaffsfs_FindObject(NULL,path,0,1, &dir,¬Dir,&loop);
obj = yaffsfs_FollowLink(obj,0,&loop);
- if(!dir && notDir)
+ if(!dir && notDir)
yaffsfs_SetError(-ENOTDIR);
- else if(loop)
+ else if(loop)
yaffsfs_SetError(-ELOOP);
- else if(!dir || !obj)
+ else if(!dir || !obj)
yaffsfs_SetError(-ENOENT);
else if((amode & W_OK) && obj->my_dev->read_only)
yaffsfs_SetError(-EROFS);
obj = yaffsfs_FindObject(NULL,path,0,1, &dir, ¬Dir,&loop);
obj = yaffsfs_FollowLink(obj,0,&loop);
- if(!dir && notDir)
+ if(!dir && notDir)
yaffsfs_SetError(-ENOTDIR);
- else if(loop)
+ else if(loop)
yaffsfs_SetError(-ELOOP);
- else if(!dir || !obj)
+ else if(!dir || !obj)
yaffsfs_SetError(-ENOENT);
else if(obj->my_dev->read_only)
yaffsfs_SetError(-EROFS);
}
if(alt_path)
path = alt_path;
-
+
yaffsfs_Lock();
parent = yaffsfs_FindDirectory(NULL,path,&name,0,¬Dir,&loop);
if(!parent && notDir)
yaffsfs_SetError(-ENAMETOOLONG);
return -1;
}
-
+
yaffsfs_Lock();
dev = yaffsfs_FindDevice(path,&dummy);
if(dev){
else if(dev->read_only)
yaffsfs_SetError(-EROFS);
else {
-
+
yaffs_flush_whole_cache(dev);
yaffs_checkpoint_save(dev);
retVal = 0;
-
- }
+
+ }
}else
yaffsfs_SetError(-ENODEV);
yaffsfs_Unlock();
- return retVal;
+ return retVal;
}
yaffsfs_Lock();
dev = yaffsfs_FindDevice(path,&dummy);
if(dev && dev->is_mounted){
- retVal = (dev->param.end_block - dev->param.start_block + 1) -
+ retVal = (dev->param.end_block - dev->param.start_block + 1) -
dev->param.n_reserved_blocks;
retVal *= dev->param.chunks_per_block;
retVal *= dev->data_bytes_per_chunk;
if(n_obj > dev->n_hardlinks)
retVal = n_obj - dev->n_hardlinks;
}
-
+
if(retVal < 0)
yaffsfs_SetError(-EINVAL);
-
+
yaffsfs_Unlock();
- return retVal;
+ return retVal;
}
struct yaffs_obj *dirObj; /* ptr to directory being searched */
struct yaffs_obj *nextReturn; /* obj to be returned by next readddir */
int offset;
- struct list_head others;
+ struct list_head others;
} yaffsfs_DirectorySearchContext;
if(!search_contexts.next)
INIT_LIST_HEAD(&search_contexts);
- list_add(&dsc->others,&search_contexts);
+ list_add(&dsc->others,&search_contexts);
yaffsfs_SetDirRewound(dsc);
}
obj = yaffsfs_FindObject(NULL,path,0,1, &dir,¬Dir,&loop);
- if(!dir && notDir)
+ if(!dir && notDir)
yaffsfs_SetError(-ENOTDIR);
- else if(loop)
+ else if(loop)
yaffsfs_SetError(-ELOOP);
- else if(!dir || !obj)
+ else if(!dir || !obj)
yaffsfs_SetError(-ENOENT);
else if(obj->variant_type != YAFFS_OBJECT_TYPE_SYMLINK)
yaffsfs_SetError(-EINVAL);
yaffsfs_SetError(-EEXIST);
else if(lnk_dir->my_dev != obj->my_dev)
yaffsfs_SetError(-EXDEV);
- else {
+ else {
retVal = yaffsfs_CheckNameLength(newname);
-
+
if(retVal == 0) {
lnk = yaffs_link_obj(lnk_dir,newname,obj);
if(lnk)
/*
* D E B U G F U N C T I O N S
*/
-
+
/*
* yaffs_n_handles()
* Returns number of handles attached to the object