Package org.jnode.driver.block

Examples of org.jnode.driver.block.FileDevice


    }

    public void init(TestConfig config, MockObjectTestCase testCase) throws Exception {
        super.init(config, testCase);

        FileDevice device = new FileDevice(f, "rw");
        init(null, device, null);
    }
View Full Code Here


        Assert.assertTrue("Must contains one directory", root.iterator().hasNext());
    }

    private Device createTestDisk(boolean formatted) throws IOException {
        File file = TestUtils.makeTempFile("hfsDevice", "10M");
        Device device = new FileDevice(file, "rw");
        return device;

    }
View Full Code Here

        printInfo(f, out);
    }

    public static void printInfo(File file, PrintWriter out)
        throws IOException, FileSystemException {
        FileDevice fd = new FileDevice(file, "r");
        try {
            final FileSystemService fSS = InitialNaming.lookup(FileSystemService.NAME);
            FatFileSystemType type = fSS.getFileSystemType(FatFileSystemType.ID);
            FatFileSystem fs = new FatFileSystem(fd, false, type);
            try {
                BootSector bs = fs.getBootSector();
                bs.read(fd);

                out.println("OEM name          " + bs.getOemName());
                out.println("bytes/sector      " + bs.getBytesPerSector());
                out.println("sectors/cluster   " + bs.getSectorsPerCluster());
                out.println("#reserved sectors " + bs.getNrReservedSectors());
                out.println("#fats             " + bs.getNrFats());
                out.println("#rootdir entries  " + bs.getNrRootDirEntries());
                out.println("#logical sectors  " + bs.getNrLogicalSectors());
                out.println("Medium descriptor 0x" + Integer.toHexString(bs.getMediumDescriptor()));
                out.println("sectors/fat       " + bs.getSectorsPerFat());
                out.println("sectors/track     " + bs.getSectorsPerTrack());
                out.println("#heads            " + bs.getNrHeads());
                out.println("#hidden sectors   " + bs.getNrHiddenSectors());

                fs.getFat().printTo(out);
                fs.getRootDir().printTo(out);

                try {
                    FatDirectory dir =
                            (FatDirectory) fs.getRootEntry().getDirectory().getEntry("AAP")
                                    .getDirectory();
                    dir.printTo(out);
                } catch (FileNotFoundException ex) {
                    out.println("No AAP directory");
                }

                try {
                    FatDirectory dir =
                            (FatDirectory) fs.getRootEntry().getDirectory().getEntry("boot")
                                    .getDirectory();
                    dir.printTo(out);
                } catch (FileNotFoundException ex) {
                    out.println("No boot directory");
                }

            } finally {
                // fd.stop();
                fd.close();
            }
        } catch (NameNotFoundException e) {
            throw new FileSystemException(e);
        }
    }
View Full Code Here

    }

    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();
    }
View Full Code Here

    }

    @Test
    public void testReadExt4SpecialFiles() throws Exception {

        device = new FileDevice(FileSystemTestUtils.getTestFile("test/fs/ext4/test-special-files.ext4"), "r");
        Ext2FileSystemType type = fss.getFileSystemType(Ext2FileSystemType.ID);
        Ext2FileSystem fs = type.create(device, true);

        String expectedStructure =
            "type: EXT2 vol: total:15728640 free:13918208\n" +
View Full Code Here

     */
    public void testExtremeFragmentation() {
        System.out.println("NTFS : Test extreme fragmentation (" + TEST_IMAGE_FILENAME_1 + ").");
        try {
            File file = new File(TEST_IMAGE_FILENAME_1);
            Device device = new FileDevice(file, "r");
            FileSystem<?> fileSystem = new NTFSFileSystemType().create(device, true);
            FSDirectory root = fileSystem.getRootEntry().getDirectory();

            // Check the big file.  Every byte should be readable as zero, hopefully.
            FSFile bigFile = root.getEntry("bigfile.dat").getFile();
View Full Code Here

     */
    public void testSparseFiles() {
        System.out.println("NTFS : Test sparse file (" + TEST_IMAGE_FILENAME_2 + ").");
        try {
            File file = new File(TEST_IMAGE_FILENAME_2);
            Device device = new FileDevice(file, "r");
            FileSystem<?> fileSystem = new NTFSFileSystemType().create(device, true);
            FSDirectory root = fileSystem.getRootEntry().getDirectory();

            // The first file has 256 bytes of real data at the front, and the rest is sparse.
            byte[] expectedContents = new byte[10240];
View Full Code Here

    /**
     *
     */
    public Device createDevice() throws IOException {
        return new FileDevice(file, "r");
    }
View Full Code Here

    public NTFSTest() {
        //read the disk image of an ext2fs partition

        //FileDevice implements BlockDeviceAPI
        FileDevice fd = null;
        try {
            fd = new FileDevice(partImg, "r");
        } catch (IOException e) {
            System.out.println("error when reading disk image");
            System.exit(-1);
        }
View Full Code Here

    public Device createDevice() throws IOException {
        String mode = isInput() ? "r" : "rw";
        if (!isInput() && (fileSize > 0L) && (!file.exists() || (file.length() != fileSize)))
            TestUtils.makeFile(file.getAbsolutePath(), fileSize);

        return new FileDevice(file, mode);
    }
View Full Code Here

TOP

Related Classes of org.jnode.driver.block.FileDevice

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.