Package org.jnode.driver.block

Examples of org.jnode.driver.block.BlockDeviceAPI


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


        DeviceManager dm;
        try {
            dm = InitialNaming.lookup(DeviceManager.NAME);

            IDEDevice current = (IDEDevice) dm.getDevice(args[0]);
            BlockDeviceAPI api = current.getAPI(BlockDeviceAPI.class);

            int size = (int) (Math.random() * 5 /*256*/) * 512;
            int offset = (int) (Math.random() * 10000) * 512;
            System.out.println("Create Random Buffer");
            System.out.println("Size = " + size);
            byte[] src = new byte[size];
            for (int i = 0; i < size; i++) {
                src[i] = (byte) (Math.random() * 255);
            }

            System.out.println("Put it at " + offset);
            api.write(offset, ByteBuffer.wrap(src));

            System.out.println("Retreive it back ...");
            byte[] dest = new byte[size];
            api.read(offset, ByteBuffer.wrap(dest));

            System.out.println("Check consistency ...");
            for (int i = 0; i < size; i++) {
                System.out.print(src[i] + "|" + dest[i] + ",");
                if (src[i] != dest[i])
View Full Code Here

        final String parentDeviceName = deviceName.substring(0, i + 1);
        final int partitionNumber = Integer.parseInt(deviceName.substring(i + 1));
        //

        final Device parentDevice = getDevice(dm, parentDeviceName);
        final BlockDeviceAPI parentDeviceApi = getBlockDeviceAPI(parentDevice);

        stage1.format(parentDeviceApi);
        stage1_5.format(parentDeviceApi, partitionNumber);

        stage2.format(getMountPoint());
View Full Code Here

        }
        return parentDevice;
    }

    private BlockDeviceAPI getBlockDeviceAPI(Device device) throws GrubException {
        BlockDeviceAPI deviceApi = null;
        try {
            deviceApi = device.getAPI(BlockDeviceAPI.class);
        } catch (ApiNotFoundException e) {
            throw new GrubException("device must be a partition device", e);
        }
View Full Code Here

        final long startLBA = current.getStartLba();
        final ByteBuffer sector = ByteBuffer.allocate(IDEConstants.SECTOR_SIZE);
        try {
            log.debug("Try to read the Extended Partition Table");
            BlockDeviceAPI api = driveDevice.getAPI(BlockDeviceAPI.class);
            api.read(startLBA * IDEConstants.SECTOR_SIZE, sector);
        } catch (ApiNotFoundException e) {
            // I think we can't get it
            log.error("API Not Found Exception");
        } catch (IOException e) {
            // I think we can't get it
View Full Code Here

        final FileDevice newFd = new FileDevice(destFile, "rw");
        try {
            newFd.setLength(getDeviceLength());
            formatDevice(newFd);
            final Device sysDev = getSystemDevice(newFd);
            final BlockDeviceAPI sysDevApi = sysDev
                .getAPI(BlockDeviceAPI.class);
            copySystemFiles(sysDev);
            sysDevApi.flush();
        } catch (ApiNotFoundException ex) {
            final IOException ioe = new IOException("BlockDeviceAPI not found on device");
            ioe.initCause(ex);
            throw ioe;
        } finally {
View Full Code Here

TOP

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

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.