File Systems related problem using CCJavaPython Develop and

File Systems related problem: using C/C++/Java/Python
Develop and implement a small Unix-CP/M-like file system (\"FS\"). Your file system will not be part of an operating system, but, similar to modern file systems, it will run in several different operating systems to provide a \"portable\" file system. Your FS will Use a file (for example \"disk01\"), rather than a physical flash or disk, to store data. You may have several disk-like files (for example: disk0l, disk02), used to store data. The data stored in disk01 will be a user\'s programs, text files, other data files, or any type of binary information. In addition to the data stored, your FS will need to store other, meta-information, such as free space (blocks), directory details, and possibly other information. The FS directory is flat (one level) fixed sized, has a user name associated with each file, and has fixed sized entries. You should Use fixed size blocks (similar to disk blocks) of size 128 bytes to store Files and all meta-data in your \"disk\". You should provide the following operations: Createfs #ofblocks - creates a filesystem (disk) with #ofblocks size, each 128 bytes Formatfs #filenames #ABPTentries Savefs name- save the \"disk\" image in a file \"name\" Openfs name- Use an existing disk image List - list files (and other meta-information) in a FS Remove name -remove named file from fs Put ExternalFile - put (Host) OS file into the disk Get ExternalFile - get disk file copy to (host) OS file User name - this user owns this user\'s files Link/Unlink - Unix style file linking Bonus: Set/Use file permissions for r/w/x, implement subdirectories, \"check disk\" Your FS should have 4 (or more, if easier to implement) sections: A FilenameTable (FNT), an attribute/block pointer table (ABPT), and the data blocks. The FNT should be of size allocated, each entry should contain a 56 char (maximum) file name and an inode pointer (index to ABPT)(blocks are 256 byes). The ABPT should be allocated from disk blocks, one entry per block, where each entry should contain a file meta-information (FileSize, last time+date (secs), pointers to data blocks), user name The Block Pointer Table has direct pointers to data blocks, and one additional pointer to another entry in the Table, if needed (for big files), these may be chained for very large files. (Similar to CP/M extents) Since disks (and some meta-information) are fixed size, many small or one large file might not fit on the \"disk\". File names, file attributes and other file information stored in FS are restrictive (for example, file creation time).

Solution

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <fcntl.h>

#include <string.h>

#include <dirent.h>

#include <sys/types.h>

#include <sys/stat.h>

#define BUFFERSIZE 1024

#define COPYMORE 0644

void oops(char *, char *);

int copyDir(char *src, char *dest);

int copyFiles(char *src, char *dest);

int dostat(char *filename);

int mode_isReg(struct stat info);

int main(int ac, char *av[])

{

if(ac != 3)

  {

    fprintf(stderr, \"usage: %s source destination\ \", *av);

    exit(1);

  }

char *src = av[1];

   char *dest = av[2];

if( src[0] != \'/\' && dest[0] != \'/\' )

   {

       copyFiles(src, dest);

   }

   else if( src[0] != \'/\' && dest[0] == \'/\' )

   {

      int i;

      for(i=1; i<=strlen(dest); i++)

      {

          dest[(i-1)] = dest[i];

      }

      strcat(dest, \"/\");

      strcat(dest, src);

      copyFiles(src, dest);

  }

  else if( src[0] == \'/\' && dest[0] == \'/\' )

  {

      int i;

      for(i=1; i<=strlen(dest); i++)

      {

          dest[(i-1)] = dest[i];

      }

      for(i=1; i<=strlen(src); i++)

      {

          src[(i-1)] = src[i];

}

      copyDir(src, dest);

  }

  else

  {

      fprintf(stderr, \"usage: cp1 source destination\ \");

      exit(1);

  }

}

int copyDir(char *source, char *destination)

{

    DIR *dir_ptr = NULL;

    struct dirent *direntp;

    char tempDest[strlen(destination)+1];

    char tempSrc[strlen(source)+1];

    strcat(destination, \"/\");

    strcat(source, \"/\");

    strcpy(tempDest, destination);

    strcpy(tempSrc, source);

     

    //char *fileN;

    struct stat fileinfo;

if( (dir_ptr = opendir(source)) == NULL )

   {

      fprintf(stderr, \"cp1: cannot open %s for copying\ \", source);

      return 0;

   }

   else

   {

      while( (direntp = readdir(dir_ptr)))

      {     

      //printf(\"direntp DNAME is %s\ \", direntp->d_name);

      //fileN = direntp->d_name;

      //printf(\"File name before Reg Check is %s\ \", fileN);

       

      if(dostat(direntp->d_name))

      {  

              strcat(tempDest, direntp->d_name);

strcat(tempSrc, direntp->d_name);

          copyFiles(tempSrc, tempDest);

              strcpy(tempDest, destination);

          strcpy(tempSrc, source);           

      }

      }

      closedir(dir_ptr);

      return 1;

   }

}

int dostat(char *filename)

{

    struct stat fileInfo;

     

    //printf(\"Next File %s\ \", filename);

    if(stat(filename, &fileInfo) >=0)

    if(S_ISREG(fileInfo.st_mode))

      return 1;

    else return 0;

     

    return;

}

int copyFiles(char *source, char *destination)

{

  int in_fd, out_fd, n_chars;

  char buf[BUFFERSIZE];

  /* open files */

  if( (in_fd=open(source, O_RDONLY)) == -1 )

  {

    oops(\"Cannot open \", source);

  }

  if( (out_fd=creat(destination, COPYMORE)) == -1 )

  {

    oops(\"Cannot creat \", destination);

  }

  /* copy files */

  while( (n_chars = read(in_fd, buf, BUFFERSIZE)) > 0 )

  {

    if( write(out_fd, buf, n_chars) != n_chars )

    {

      oops(\"Write error to \", destination);

    }

    if( n_chars == -1 )

    {

      oops(\"Read error from \", source);

    }

  }

    if( close(in_fd) == -1 || close(out_fd) == -1 )

    {

      oops(\"Error closing files\", \"\");

    }

return 1;

}

void oops(char *s1, char *s2)

  {

    fprintf(stderr, \"Error: %s \", s1);

    perror(s2);

    exit(1);

  }

File Systems related problem: using C/C++/Java/Python Develop and implement a small Unix-CP/M-like file system (\
File Systems related problem: using C/C++/Java/Python Develop and implement a small Unix-CP/M-like file system (\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site