コード例 #1
0
ファイル: FatTest.java プロジェクト: NanoGame/jnode
  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();
  }
コード例 #2
0
ファイル: BasicFSTest.java プロジェクト: NanoGame/jnode
  @Test
  public void testAddDirectory() throws Exception {

    setUp();
    FSDirectory rootDir = getFs().getRootEntry().getDirectory();
    String dirName = "A new directory.text";

    log.debug("Root dir before testAddDirectory :");
    TestUtils.listEntries(rootDir.iterator());
    if (config.isReadOnly()) {
      try {
        rootDir.addDirectory(dirName);
        fail("addDirectory must fail in readOnly mode");
      } catch (ReadOnlyFileSystemException e) {
        // success
      }
      assertContainsOnly("must be empty", rootDir.iterator(), getEmptyDirNames(config, true));
    } else {
      try {
        FSEntry entry = rootDir.addDirectory(dirName);
        // success
        log.debug("added directory entry=" + FSUtils.toString(entry, true));
      } catch (ReadOnlyFileSystemException e) {
        fail("addDirectory must succeed in read/write mode");
      }
      assertContainsOnly(
          "must contain " + dirName,
          rootDir.iterator(),
          TestUtils.append(getEmptyDirNames(config, true), new String[] {dirName}));
      FSEntry gotEntry = rootDir.getEntry(dirName);
      assertNotNull("must contain the added directory", gotEntry);
      assertEquals("returned bad entry", dirName, gotEntry.getName());
    }
    log.debug("Root dir after testAddDirectory :\n" + rootDir);
    TestUtils.listEntries(rootDir.iterator());
  }