Further extensions for VxWorks wrapper
authorCharles Manning <cdhmanning@gmail.com>
Wed, 11 Nov 2015 03:51:28 +0000 (16:51 +1300)
committerCharles Manning <cdhmanning@gmail.com>
Wed, 11 Nov 2015 03:51:28 +0000 (16:51 +1300)
Signed-off-by: Charles Manning <cdhmanning@gmail.com>
direct/test-framework/yramsim.c
direct/yaffsfs.c
direct/yaffsfs.h
yaffs_guts.c

index 881c6e3500e6bf689db979e1dea3948ff70bcf42..6466d3b9a2ce9e1c1088927d27515b856d95c259 100644 (file)
  * NAND Simulator for testing YAFFS
  */
 
-#include <string.h>
 
 #include "yramsim.h"
 
 #include "yaffs_guts.h"
+#include <string.h>
+
 
 
 #define DATA_SIZE      2048
@@ -88,10 +89,10 @@ static int yramsim_deinitialise(struct yaffs_dev *dev)
        return 1;
 }
 
-static int yramsim_rd_chunk (struct yaffs_dev *dev, unsigned pageId,
-                                         unsigned char *data, unsigned dataLength,
-                                         unsigned char *spare, unsigned spareLength,
-                                         int *eccStatus)
+static int yramsim_rd_chunk (struct yaffs_dev *dev, int pageId,
+                                         u8 *data, int dataLength,
+                                         u8 *spare, int spareLength,
+                                         enum yaffs_ecc_result *ecc_result)
 {
        SimData *sim = DevToSim(dev);
        Block **blockList = sim->blockList;
@@ -104,9 +105,8 @@ static int yramsim_rd_chunk (struct yaffs_dev *dev, unsigned pageId,
           pageOffset >= PAGES_PER_BLOCK ||
           dataLength >DATA_SIZE ||
           spareLength > SPARE_SIZE ||
-          !eccStatus ||
           !blockList[blockId]->blockOk){
-                  return 0;
+                  return YAFFS_FAIL;
        }
 
        d = blockList[blockId]->page[pageOffset];
@@ -118,14 +118,15 @@ static int yramsim_rd_chunk (struct yaffs_dev *dev, unsigned pageId,
        if(spare)
                memcpy(spare,s,spareLength);
 
-       *eccStatus = 0; /* 0 = no error, -1 = unfixable error, 1 = fixable */
+       if (ecc_result) 
+               *ecc_result  = YAFFS_ECC_RESULT_NO_ERROR;
 
-       return 1;
+       return YAFFS_OK;
 }
 
-static int yramsim_wr_chunk (struct yaffs_dev *dev,unsigned pageId,
-                                          const unsigned char *data, unsigned dataLength,
-                                          const unsigned char *spare, unsigned spareLength)
+static int yramsim_wr_chunk (struct yaffs_dev *dev, int pageId,
+                                          const u8 *data, int dataLength,
+                                          const u8 *spare, int spareLength)
 {
        SimData *sim = DevToSim(dev);
        Block **blockList = sim->blockList;
@@ -139,7 +140,7 @@ static int yramsim_wr_chunk (struct yaffs_dev *dev,unsigned pageId,
           dataLength >DATA_SIZE ||
           spareLength > SPARE_SIZE ||
           !blockList[blockId]->blockOk){
-                  return 0;
+                  return YAFFS_FAIL;
        }
 
        d = blockList[blockId]->page[pageOffset];
@@ -151,11 +152,11 @@ static int yramsim_wr_chunk (struct yaffs_dev *dev,unsigned pageId,
        if(spare)
                memcpy(s,spare,spareLength);
 
-       return 1;
+       return YAFFS_OK;
 }
 
 
-static int yramsim_erase(struct yaffs_dev *dev,unsigned blockId)
+static int yramsim_erase(struct yaffs_dev *dev, int blockId)
 {
        SimData *sim = DevToSim(dev);
 
@@ -163,7 +164,7 @@ static int yramsim_erase(struct yaffs_dev *dev,unsigned blockId)
        return yramsim_erase_internal(sim,blockId,0);
 }
 
-static int yramsim_check_block_bad(struct yaffs_dev *dev,unsigned blockId)
+static int yramsim_check_block_bad(struct yaffs_dev *dev, int blockId)
 {
        SimData *sim = DevToSim(dev);
        Block **blockList = sim->blockList;
@@ -174,17 +175,17 @@ static int yramsim_check_block_bad(struct yaffs_dev *dev,unsigned blockId)
        return blockList[blockId]->blockOk ? YAFFS_OK : YAFFS_FAIL;
 }
 
-static int yramsim_mark_block_bad(struct yaffs_dev *dev,unsigned blockId)
+static int yramsim_mark_block_bad(struct yaffs_dev *dev, int blockId)
 {
        SimData *sim = DevToSim(dev);
        Block **blockList = sim->blockList;
        if(blockId >= sim->nBlocks){
-               return 0;
+               return YAFFS_FAIL;
        }
 
        blockList[blockId]->blockOk = 0;
 
-       return 1;
+       return YAFFS_OK;
 }
 
 
index 05cd22977720acd42e1bc925f9fc119e05a81584..3cb11a92a3c4675ec4220cad03e4378625168ec1 100644 (file)
@@ -346,8 +346,10 @@ static int yaffsfs_PutFileDes(int fdId)
                fd = &yaffsfs_fd[fdId];
                fd->handleCount--;
                if (fd->handleCount < 1) {
-                       if (fd->isDir)
+                       if (fd->isDir) {
                                yaffsfs_closedir_no_lock(fd->v.dir);
+                               fd->v.dir = NULL;
+                       }
                        if (fd->inodeId >= 0) {
                                yaffsfs_PutInode(fd->inodeId);
                                fd->inodeId = -1;
@@ -836,7 +838,7 @@ int yaffs_open_sharing_reldir(struct yaffs_obj *reldir, const YCHAR *path,
        int notDir = 0;
        int loop = 0;
        int is_dir = 0;
-       yaffs_DIR *dsc;
+       yaffs_DIR *dsc = NULL;
 
        if (yaffsfs_CheckMemRegion(path, 0, 0)< 0) {
                yaffsfs_SetError(-EFAULT);
@@ -869,7 +871,7 @@ int yaffs_open_sharing_reldir(struct yaffs_obj *reldir, const YCHAR *path,
 
        if (handle < 0) {
                yaffsfs_SetError(-ENFILE);
-               errorReported = 1;
+               errorReported = __LINE__;
        } else {
 
                fd = yaffsfs_HandleToFileDes(handle);
@@ -892,19 +894,18 @@ int yaffs_open_sharing_reldir(struct yaffs_obj *reldir, const YCHAR *path,
 
                        /* A directory can't be opened except for read */
                        if ( is_dir &&
-                           (writeRequested || !readRequested ||
-                               (oflag & ~O_RDONLY))) {
-                               openDenied = 1;
+                           (writeRequested || !readRequested || rwflags != O_RDONLY)) {
+                               openDenied = __LINE__;
                                yaffsfs_SetError(-EISDIR);
-                               errorReported = 1;
+                               errorReported = __LINE__;
                        }
 
                        if(is_dir) {
                                dsc = yaffsfs_opendir_reldir_no_lock(reldir, path);
                                if (!dsc) {
-                                       openDenied = 1;
+                                       openDenied = __LINE__;
                                        yaffsfs_SetError(-ENFILE);
-                                       errorReported = 1;
+                                       errorReported = __LINE__;
                                }
                        }
 
@@ -913,28 +914,28 @@ int yaffs_open_sharing_reldir(struct yaffs_obj *reldir, const YCHAR *path,
                         */
                        if (!errorReported &&
                            (oflag & O_EXCL) && (oflag & O_CREAT)) {
-                               openDenied = 1;
+                               openDenied = __LINE__;
                                yaffsfs_SetError(-EEXIST);
-                               errorReported = 1;
+                               errorReported = __LINE__;
                        }
 
                        /* Check file permissions */
                        if (readRequested && !(obj->yst_mode & S_IRUSR))
-                               openDenied = 1;
+                               openDenied = __LINE__;
 
                        if (writeRequested && !(obj->yst_mode & S_IWUSR))
-                               openDenied = 1;
+                               openDenied = __LINE__;
 
                        if (!errorReported && writeRequested &&
                            obj->my_dev->read_only) {
-                               openDenied = 1;
+                               openDenied = __LINE__;
                                yaffsfs_SetError(-EROFS);
-                               errorReported = 1;
+                               errorReported = __LINE__;
                        }
 
                        if (openDenied && !errorReported) {
                                yaffsfs_SetError(-EACCES);
-                               errorReported = 1;
+                               errorReported = __LINE__;
                        }
 
                        /* Check sharing of an existing object. */
@@ -967,9 +968,9 @@ int yaffs_open_sharing_reldir(struct yaffs_obj *reldir, const YCHAR *path,
                                    (!shareRead && alreadyReading) ||
                                    (!sharedWriteAllowed && writeRequested) ||
                                    (!shareWrite && alreadyWriting)) {
-                                       openDenied = 1;
+                                       openDenied = __LINE__;
                                        yaffsfs_SetError(-EBUSY);
-                                       errorReported = 1;
+                                       errorReported = __LINE__;
                                }
                        }
 
@@ -983,13 +984,13 @@ int yaffs_open_sharing_reldir(struct yaffs_obj *reldir, const YCHAR *path,
                                                    &notDir, &loop);
                        if (!dir && notDir) {
                                yaffsfs_SetError(-ENOTDIR);
-                               errorReported = 1;
+                               errorReported = __LINE__;
                        } else if (loop) {
                                yaffsfs_SetError(-ELOOP);
-                               errorReported = 1;
+                               errorReported = __LINE__;
                        } else if (!dir) {
                                yaffsfs_SetError(-ENOENT);
-                               errorReported = 1;
+                               errorReported = __LINE__;
                        }
                }
 
@@ -997,22 +998,22 @@ int yaffs_open_sharing_reldir(struct yaffs_obj *reldir, const YCHAR *path,
                        /* Let's see if we can create this file */
                        if (dir->my_dev->read_only) {
                                yaffsfs_SetError(-EROFS);
-                               errorReported = 1;
+                               errorReported = __LINE__;
                        } else if (yaffsfs_TooManyObjects(dir->my_dev)) {
                                yaffsfs_SetError(-ENFILE);
-                               errorReported = 1;
+                               errorReported = __LINE__;
                        } else
                                obj = yaffs_create_file(dir, name, mode, 0, 0);
 
                        if (!obj && !errorReported) {
                                yaffsfs_SetError(-ENOSPC);
-                               errorReported = 1;
+                               errorReported = __LINE__;
                        }
                }
 
                if (!obj && dir && !errorReported && !(oflag & O_CREAT)) {
                        yaffsfs_SetError(-ENOENT);
-                       errorReported = 1;
+                       errorReported = __LINE__;
                }
 
                if (obj && !openDenied) {
@@ -1045,6 +1046,9 @@ int yaffs_open_sharing_reldir(struct yaffs_obj *reldir, const YCHAR *path,
                        if (!is_dir && (oflag & O_TRUNC) && fd->writing)
                                yaffs_resize_file(obj, 0);
                } else {
+                       if (dsc)
+                               yaffsfs_closedir_no_lock(dsc);
+                       dsc = NULL;
                        yaffsfs_PutHandle(handle);
                        if (!errorReported)
                                yaffsfs_SetError(0);    /* Problem */
@@ -1601,15 +1605,12 @@ int yaffs_funlink(int fd)
                yaffsfs_SetError(-EBADF);
        else if (obj->my_dev->read_only)
                yaffsfs_SetError(-EROFS);
-       else if (!isDirectory &&
-                obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
-               yaffsfs_SetError(-EISDIR);
-       else if (isDirectory &&
-                obj->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
-               yaffsfs_SetError(-ENOTDIR);
-       else if (isDirectory && obj == obj->my_dev->root_dir)
+       else if (obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY &&
+                       !(list_empty(&obj->variant.dir_variant.children)))
+               yaffsfs_SetError(-ENOTEMPTY);
+       else if (obj == obj->my_dev->root_dir)
                yaffsfs_SetError(-EBUSY);       /* Can't rmdir a root */
-       else if (yaffs_unlink_obj(oobj) == YAFFS_OK)
+       else if (yaffs_unlink_obj(obj) == YAFFS_OK)
                        retVal = 0;
 
        yaffsfs_Unlock();
@@ -1617,6 +1618,30 @@ int yaffs_funlink(int fd)
        return retVal;
 }
 
+int yaffs_fgetfl(int fd, int *flags)
+{
+       struct yaffsfs_FileDes *fdp = yaffsfs_HandleToFileDes(fd);
+       int retVal;
+       
+       yaffsfs_Lock();
+
+       if(!flags || !fdp) {
+               yaffsfs_SetError(-EINVAL);
+               retVal = -1;
+       } else {
+               if (fdp->reading && fdp->writing)
+                       *flags = O_RDWR;
+               else if (fdp->writing)
+                       *flags = O_WRONLY;
+               else
+                       *flags = O_RDONLY;
+               retVal = 0;
+       }
+       
+       yaffsfs_Unlock();
+       return retVal;
+}
+
 
 static int rename_file_over_dir(struct yaffs_obj *obj, struct yaffs_obj *newobj)
 {
index 8a6a8b85f0aadc3b530f4cc0a5b6cf3da412a15e..3e0ddd0b3eb18325ba61ca801d972f8194bde9d5 100644 (file)
@@ -95,6 +95,8 @@ int yaffs_access(const YCHAR *path, int amode);
 
 int yaffs_dup(int fd);
 
+int yaffs_fgetfl(int fd, int *flags);
+
 int yaffs_read(int fd, void *buf, unsigned int nbyte) ;
 int yaffs_write(int fd, const void *buf, unsigned int nbyte) ;
 
index 89fb2a9bbac589f10c1c058312b02db4ccc205f5..4e679bf2cf97efabcfcc6eddfaa81c36c748238c 100644 (file)
@@ -4080,7 +4080,7 @@ static int yaffs_unlink_worker(struct yaffs_obj *obj)
        }
 }
 
-static int yaffs_unlink_obj(struct yaffs_obj *obj)
+int yaffs_unlink_obj(struct yaffs_obj *obj)
 {
        if (obj && obj->unlink_allowed)
                return yaffs_unlink_worker(obj);