Example #1
0
  public static void createFloppy(File f) throws Exception {

    GrubFatFormatter ff = new GrubFatFormatter(0, null, null);
    FileDevice newFd = new FileDevice(f, "rw");
    newFd.setLength(1440 * 1024);
    ff.format(newFd);

    // newFd.start();
    final FileSystemService fSS = InitialNaming.lookup(FileSystemService.NAME);
    FatFileSystemType type = fSS.getFileSystemType(FatFileSystemType.ID);
    FatFileSystem fs = new FatFileSystem(newFd, false, type);

    FSDirectory dir = fs.getRootEntry().getDirectory();
    FSDirectory bDir = dir.addDirectory("boot").getDirectory();
    FSDirectory bgDir = bDir.addDirectory("grub").getDirectory();

    URLConnection urlConn = FatTest.class.getClassLoader().getResource("menu.lst").openConnection();
    // byte[] buf = new byte[urlConn.getContentLength()];
    ByteBuffer buf = ByteBuffer.allocate(urlConn.getContentLength());
    FileUtils.copy(urlConn.getInputStream(), buf.array());

    final FSFile fh1 = dir.addFile("test.lst").getFile();
    fh1.setLength(urlConn.getContentLength());
    fh1.write(0, buf);

    final FSFile fh2 = bgDir.addFile("menu.lst").getFile();
    fh2.setLength(urlConn.getContentLength());
    fh2.write(0, buf);

    fs.flush();

    // newFd.stop();
    newFd.close();
  }