Example #1
0
  void loadFS() throws Exception {
    byte sb[] = new byte[1024];
    file.seek(0);
    file.read(sb);
    superBlock = new SuperBlock(sb);
    superBlock.loadDMap(superBlock.getLatestVerison(), file);
    lastblock = superBlock.lastblock;
    version = superBlock.getLatestVerison();

    Main.print("\nVersion Loaded:  " + version + "\n");
  }
Example #2
0
  @SuppressWarnings({"unchecked"})
  void initializeFS() {
    try {
      JSONObject obj = new JSONObject();
      JSONArray jar = new JSONArray();
      jar.add("0 1#1");
      obj.put("version", jar);
      obj.put("lastblock", "1");
      version = 0;
      file.write(obj.toJSONString().getBytes());

      superBlock = new SuperBlock(obj.toJSONString().getBytes());
      // Done super block
      lastblock = 1;
      file.seek(1024);
      // root direc
      JSONObject obj1 = new JSONObject();
      JSONArray ch_dir = new JSONArray();
      obj1.put("dir", ch_dir);
      file.write(obj1.toJSONString().getBytes());
      file.close();

      getFile();
      superBlock.loadDMap(version, file);

    } catch (IOException | ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Example #3
0
 void copyfs(int ver, String outputdir) {
   try {
     superBlock.copyfs(ver, outputdir, file);
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (ParseException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Example #4
0
 void switchVersion(int ver) {
   try {
     superBlock.loadDMap(ver, file);
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (ParseException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
 private static void dumpContents(String[] args) {
   try {
     RandomAccessFile file = open(args[0]);
     SuperBlock sb = getSuperBlock(file);
     DirectoryBlock db = readDirB(file);
     Dentry[] dentries = db.getDentries();
     int i;
     Arrays.sort(dentries);
     for (i = 0; i < dentries.length; ++i) {
       if (dentries[i].getIno() == Inode.EMPTY) continue;
       System.out.println(dentries[i].getFileName());
       int ino = dentries[i].getIno();
       Inode inode = new Inode(sb);
       int blkNum =
           VFS.BLK_DIRINODE + (sb.getInodeBlockRatio() + 1) * (ino / sb.getInodesPerBlock());
       byte[] block = readSector(file, blkNum);
       inode.setBytes(block, ino % sb.getInodesPerBlock());
       MessageDigest md = MessageDigest.getInstance("MD5");
       ByteBuffer[] bbArr = new ByteBuffer[inode.getDataBlocksUsed()];
       for (int j = 0; j < inode.getDataBlocksUsed(); ++j) {
         blkNum = inode.getDataBlock(j);
         block = readSector(file, blkNum);
         md.reset();
         bbArr[j] = ByteBuffer.wrap(md.digest(block));
       }
       Arrays.sort(bbArr);
       for (int j = 0; j < inode.getDataBlocksUsed(); ++j) {
         byte[] digest = bbArr[j].array();
         for (int k = 0; k < digest.length; k++) System.out.print(toHexString((int) digest[k], 2));
         System.out.println("");
       }
     }
   } catch (Exception e) {
     System.err.println("Error");
   }
 }
Example #6
0
  int write(String name, int bn, String name_input) {

    superBlock.write(version, name, name_input, bn, file);
    return 1;
  }
Example #7
0
 void deleteFile(String name) {
   superBlock.deleteFile(name, file);
 }
Example #8
0
 void cd(String dr) {
   superBlock.changedr(dr);
 }
Example #9
0
 void read(String name, String input, int blk) {
   superBlock.read(version, name, input, blk, file);
 }
Example #10
0
 void createCheckPoint() {
   superBlock = superBlock.writeCheckPoint();
   version++;
   System.out.println("Version : " + version);
 }
Example #11
0
 void listfiles() {
   superBlock.listfile();
 }