示例#1
0
  /**
   * Flush all changed structures to the device.
   *
   * @throws IOException
   */
  public void flush() throws IOException {

    final BlockDeviceAPI api = getApi();

    if (bs.isDirty()) {
      bs.write(api);
    }

    for (FatFile f : files.values()) {
      f.flush();
    }

    if (fat.isDirty()) {
      for (int i = 0; i < bs.getNrFats(); i++) {
        fat.write(api, FatUtils.getFatOffset(bs, i));
      }
    }

    if (rootDir.isDirty()) {
      rootDir.flush();
    }
  }
示例#2
0
  /** Constructor for FatFileSystem in specified readOnly mode */
  public FatFileSystem(Device device, boolean readOnly, FatFileSystemType type)
      throws FileSystemException {
    super(device, readOnly, type); // false = read/write mode

    try {
      bs = new BootSector(512);
      bs.read(getApi());
      //            if (!bs.isaValidBootSector()) throw new FileSystemException(
      //                "Can't mount this partition: Invalid BootSector");

      // System.out.println(bs);

      Fat[] fats = new Fat[bs.getNrFats()];
      rootDir = new FatLfnDirectory(this, bs.getNrRootDirEntries());
      FatType bitSize;

      if (bs.getMediumDescriptor() == 0xf8) {
        bitSize = FatType.FAT16;
      } else {
        bitSize = FatType.FAT12;
      }

      for (int i = 0; i < fats.length; i++) {
        Fat fat =
            new Fat(
                bitSize, bs.getMediumDescriptor(), bs.getSectorsPerFat(), bs.getBytesPerSector());
        fats[i] = fat;
        fat.read(getApi(), FatUtils.getFatOffset(bs, i));
      }

      for (int i = 1; i < fats.length; i++) {
        if (!fats[0].equals(fats[i])) {
          System.out.println("FAT " + i + " differs from FAT 0");
        }
      }
      fat = fats[0];
      rootDir.read(getApi(), FatUtils.getRootDirOffset(bs));
      rootEntry = new FatRootEntry(rootDir);
      // files = new FatFile[fat.getNrEntries()];
    } catch (IOException ex) {
      throw new FileSystemException(ex);
    } catch (Exception e) { // something bad happened in the FAT boot
      // sector... just ignore this FS
      throw new FileSystemException(e);
    }
  }
示例#3
0
 public int getClusterSize() {
   return bs.getBytesPerSector() * bs.getSectorsPerCluster();
 }