コード例 #1
0
ファイル: FatFile.java プロジェクト: NanoGame/jnode
  public synchronized void read(long fileOffset, ByteBuffer destBuf) throws IOException {
    int len = destBuf.remaining();

    final long max = (isDir) ? getLengthOnDisk() : getLength();
    if (fileOffset + len > max) {
      throw new IOException("Cannot read beyond the EOF");
    }

    final FatFileSystem fs = getFatFileSystem();
    final long[] chain = fs.getFat().getChain(startCluster);
    final BlockDeviceAPI api = fs.getApi();

    int chainIdx = (int) (fileOffset / clusterSize);
    if (fileOffset % clusterSize != 0) {
      int clusOfs = (int) (fileOffset % clusterSize);
      int size = Math.min(len, (int) (clusterSize - (fileOffset % clusterSize) - 1));
      destBuf.limit(destBuf.position() + size);
      api.read(getDevOffset(chain[chainIdx], clusOfs), destBuf);
      fileOffset += size;
      len -= size;
      chainIdx++;
    }
    while (len > 0) {
      int size = Math.min(clusterSize, len);
      destBuf.limit(destBuf.position() + size);
      api.read(getDevOffset(chain[chainIdx], 0), destBuf);
      len -= size;
      chainIdx++;
    }
  }
コード例 #2
0
  /** @see org.jnode.fs.fat.FatFormatter#format(BlockDeviceAPI) */
  public void format(BlockDeviceAPI api) throws IOException {

    formatter.format(api);
    GrubBootSector bs = (GrubBootSector) formatter.getBootSector();
    /* Fixup the blocklist end the end of the first sector of stage2 */
    LittleEndian.setInt32(stage2, 512 - 8, bootSectorOffset + 2);

    /* Fixup the install partition */
    LittleEndian.setInt32(stage2, 512 + 0x08, installPartition);

    /* Fixup the config file */
    if (configFile != null) {
      int ofs = 512 + 0x12;
      while (stage2[ofs] != 0) {
        ofs++;
      }
      ofs++; /* Skip '\0' */
      for (int i = 0; i < configFile.length(); i++) {
        stage2[ofs++] = (byte) configFile.charAt(i);
      }
      stage2[ofs] = 0;
    }

    /* Write stage2 */
    api.write(bs.getBytesPerSector(), ByteBuffer.wrap(stage2));
  }
コード例 #3
0
ファイル: FatFile.java プロジェクト: NanoGame/jnode
  public synchronized void write(long fileOffset, ByteBuffer srcBuf) throws IOException {
    int len = srcBuf.remaining();

    if (getFileSystem().isReadOnly()) {
      throw new ReadOnlyFileSystemException("write in readonly filesystem");
    }

    final long max = (isDir) ? getLengthOnDisk() : getLength();
    if (fileOffset > max) {
      throw new IOException("Cannot write beyond the EOF");
    }

    if (fileOffset + len > max) { // this is too short increase the size
      // of the file
      setLength(fileOffset + len);
    }

    final FatFileSystem fs = getFatFileSystem();
    final long[] chain = fs.getFat().getChain(getStartCluster());
    final BlockDeviceAPI api = fs.getApi();

    int chainIdx = (int) (fileOffset / clusterSize);
    if (fileOffset % clusterSize != 0) {
      int clusOfs = (int) (fileOffset % clusterSize);
      int size = Math.min(len, (int) (clusterSize - (fileOffset % clusterSize) - 1));
      srcBuf.limit(srcBuf.position() + size);
      api.write(getDevOffset(chain[chainIdx], clusOfs), srcBuf);
      fileOffset += size;
      len -= size;
      chainIdx++;
    }
    while (len > 0) {
      int size = Math.min(clusterSize, len);
      srcBuf.limit(srcBuf.position() + size);
      api.write(getDevOffset(chain[chainIdx], 0), srcBuf);
      len -= size;
      chainIdx++;
    }
  }