OpenCores
URL https://opencores.org/ocsvn/plasma/plasma/trunk

Subversion Repositories plasma

[/] [plasma/] [trunk/] [kernel/] [filesys.c] - Diff between revs 360 and 398

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 360 Rev 398
Line 18... Line 18...
 *                MediaBlockRead() //low level read
 *                MediaBlockRead() //low level read
 *          FileOpen()             //open next directory
 *          FileOpen()             //open next directory
 *        OS_fwrite()              //write file entry into directory
 *        OS_fwrite()              //write file entry into directory
 *        BlockRead()              //flush changes to directory
 *        BlockRead()              //flush changes to directory
 *--------------------------------------------------------------------*/
 *--------------------------------------------------------------------*/
#ifdef WIN32
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <string.h>
 
#define  _LIBC
 
#endif
 
#include "rtos.h"
#include "rtos.h"
 
 
#define FLASH_SIZE        1024*1024*16
#define FLASH_SIZE        1024*1024*16
#define FLASH_SECTOR_SIZE 1024*128
#define FLASH_SECTOR_SIZE 1024*128
#define FLASH_BLOCK_SIZE  512
#define FLASH_BLOCK_SIZE  512
Line 54... Line 48...
   uint8 isDirectory;
   uint8 isDirectory;
   uint8 attributes;
   uint8 attributes;
   uint8 valid;
   uint8 valid;
   uint8 mediaType;
   uint8 mediaType;
   uint16 blockSize;        //Normally BLOCK_SIZE
   uint16 blockSize;        //Normally BLOCK_SIZE
 
   uint8 pad1, pad2;
} OS_FileEntry_t;
} OS_FileEntry_t;
 
 
typedef struct OS_Block_s {
typedef struct OS_Block_s {
   uint32 next;
   uint32 next;
   uint8 data[4];
   uint8 data[BLOCK_SIZE - sizeof(uint32)];
} OS_Block_t;
} OS_Block_t;
 
 
struct OS_FILE_s {
struct OS_FILE_s {
   OS_FileEntry_t fileEntry;  //written to directory upon OS_fclose()
   OS_FileEntry_t fileEntry;  //written to directory upon OS_fclose()
   uint8 fileModified;
   uint8 fileModified;
   uint8 blockModified;
   uint8 blockModified;
 
   uint8 pad1, pad2;
   uint32 blockIndex;         //index of block
   uint32 blockIndex;         //index of block
   uint32 blockOffset;        //byte offset into block
   uint32 blockOffset;        //byte offset into block
   uint32 fileOffset;         //byte offset into file
   uint32 fileOffset;         //byte offset into file
   char fullname[FULL_NAME_SIZE]; //includes full path
   char fullname[FULL_NAME_SIZE]; //includes full path
   OS_Block_t *block;
   OS_Block_t *block;
   OS_Block_t *blockLocal;    //local copy for flash or disk file system
   OS_Block_t blockLocal;     //local copy for flash or disk file system
};
};
 
 
static OS_FileEntry_t rootFileEntry;
static OS_FileEntry_t rootFileEntry;
static OS_Mutex_t *mutexFilesys;
static OS_Mutex_t *mutexFilesys;
 
 
Line 205... Line 201...
   if(file->fileEntry.mediaType == FILE_MEDIA_RAM)
   if(file->fileEntry.mediaType == FILE_MEDIA_RAM)
      file->block = (OS_Block_t*)blockIndex;
      file->block = (OS_Block_t*)blockIndex;
#ifdef INCLUDE_FLASH
#ifdef INCLUDE_FLASH
   else
   else
   {
   {
      if(file->blockLocal == NULL)
      file->block = &file->blockLocal;
         file->blockLocal = (OS_Block_t*)malloc(FLASH_BLOCK_SIZE);
 
      file->block = file->blockLocal;
 
      FlashRead((uint16*)file->block, blockIndex << FLASH_LN2_SIZE, FLASH_BLOCK_SIZE);
      FlashRead((uint16*)file->block, blockIndex << FLASH_LN2_SIZE, FLASH_BLOCK_SIZE);
   }
   }
#endif
#endif
}
}
 
 
Line 476... Line 470...
   OS_FileEntry_t fileEntry;
   OS_FileEntry_t fileEntry;
   OS_FILE dir;
   OS_FILE dir;
   char filename[FILE_NAME_SIZE];  //Name without directories
   char filename[FILE_NAME_SIZE];  //Name without directories
   int rc;
   int rc;
 
 
 
   //printf("OS_fopen(%s)\n", name);
   if(rootFileEntry.blockIndex == 0)
   if(rootFileEntry.blockIndex == 0)
   {
   {
      // Mount file system
      // Mount file system
      mutexFilesys = OS_MutexCreate("filesys");
      mutexFilesys = OS_MutexCreate("filesys");
      memset(&dir, 0, sizeof(OS_FILE));
      memset(&dir, 0, sizeof(OS_FILE));
Line 497... Line 492...
      if(file == NULL)
      if(file == NULL)
         return NULL;
         return NULL;
      file->fileEntry.isDirectory = 1;
      file->fileEntry.isDirectory = 1;
      file->fileEntry.mediaType = FILE_MEDIA_FLASH;
      file->fileEntry.mediaType = FILE_MEDIA_FLASH;
      file->fileEntry.blockSize = FLASH_BLOCK_SIZE;
      file->fileEntry.blockSize = FLASH_BLOCK_SIZE;
      file->blockLocal = file->block;
 
      file->block = NULL;
      file->block = NULL;
      rc = MediaBlockInit();
      rc = MediaBlockInit();
      if(rc == 1)
      if(rc == 1)
         BlockRead(file, BLOCK_MALLOC);
         BlockRead(file, BLOCK_MALLOC);
      else
      else
Line 524... Line 518...
   if(mode[0] == 'w')
   if(mode[0] == 'w')
   {
   {
      //Don't over write a directory
      //Don't over write a directory
      fileEntry.isDirectory = 0;
      fileEntry.isDirectory = 0;
      rc = FileFindRecursive(&dir, name, &fileEntry, filename);
      rc = FileFindRecursive(&dir, name, &fileEntry, filename);
      if(dir.blockLocal)
 
         free(dir.blockLocal);
 
      if(rc == 0)
      if(rc == 0)
      {
      {
         if(fileEntry.isDirectory)
         if(fileEntry.isDirectory)
         {
         {
            free(file);
            free(file);
Line 537... Line 529...
         }
         }
         OS_fdelete(name);
         OS_fdelete(name);
      }
      }
   }
   }
   rc = FileFindRecursive(&dir, name, &fileEntry, filename);
   rc = FileFindRecursive(&dir, name, &fileEntry, filename);
   if(dir.blockLocal)
 
      free(dir.blockLocal);
 
   if(rc == -2 || (rc && mode[0] == 'r'))
   if(rc == -2 || (rc && mode[0] == 'r'))
   {
   {
      free(file);
      free(file);
      OS_MutexPost(mutexFilesys);
      OS_MutexPost(mutexFilesys);
      return NULL;
      return NULL;
Line 579... Line 569...
         OS_fwrite(&fileEntry, sizeof(OS_FileEntry_t), 1, &dir);
         OS_fwrite(&fileEntry, sizeof(OS_FileEntry_t), 1, &dir);
         FileFind(&dir, "endoffile", &fileEntry);
         FileFind(&dir, "endoffile", &fileEntry);
      }
      }
      OS_fwrite(&file->fileEntry, sizeof(OS_FileEntry_t), 1, &dir);
      OS_fwrite(&file->fileEntry, sizeof(OS_FileEntry_t), 1, &dir);
      BlockRead(&dir, BLOCK_EOF);  //flush data
      BlockRead(&dir, BLOCK_EOF);  //flush data
      if(dir.blockLocal)
 
         free(dir.blockLocal);
 
      OS_MutexPost(mutexFilesys);
      OS_MutexPost(mutexFilesys);
   }
   }
   if(file->blockLocal)
 
      free(file->blockLocal);
 
   free(file);
   free(file);
}
}
 
 
 
 
int OS_fmkdir(char *name)
int OS_fmkdir(char *name)
Line 623... Line 609...
      }
      }
      MediaBlockFree(&file, blockIndex);
      MediaBlockFree(&file, blockIndex);
      fileEntry.valid = 0;
      fileEntry.valid = 0;
      OS_fwrite((char*)&fileEntry, sizeof(OS_FileEntry_t), 1, &dir);
      OS_fwrite((char*)&fileEntry, sizeof(OS_FileEntry_t), 1, &dir);
      BlockRead(&dir, BLOCK_EOF);
      BlockRead(&dir, BLOCK_EOF);
      if(file.blockLocal)
 
         free(file.blockLocal);
 
   }
   }
   if(dir.blockLocal)
 
      free(dir.blockLocal);
 
   OS_MutexPost(mutexFilesys);
   OS_MutexPost(mutexFilesys);
}
}
 
 
 
 
int OS_flength(char *entry)
int OS_flength(char *entry)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.