Package org.jnode.driver.block

Examples of org.jnode.driver.block.BlockDeviceAPI


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

        BlockDeviceAPIContext parentCtx = createParentBlockDeviceAPI();
        BlockDeviceAPI api = new BlockAlignmentSupport(parentCtx.getApi(), 512);
        init(parentCtx, api, null);
    }
View Full Code Here


        log.info(bounds.toString());
        ByteBuffer bb = ByteBuffer.allocate(IDEConstants.SECTOR_SIZE);

        long offset = bounds.getStart();
        int toRead;
        BlockDeviceAPI api = getBlockDeviceAPI();

        while (offset < bounds.getEnd()) {
            toRead = Math.min(bb.remaining(), (int) (bounds.getEnd() - offset));

            bb.position(0).limit(toRead);
            api.read(offset, bb);
            bb.clear();

            offset += toRead;
        }
    }
View Full Code Here

        log.info(bounds.toString());
        ByteBuffer bb = ByteBuffer.allocate(IDEConstants.SECTOR_SIZE);

        long offset = bounds.getStart();
        int toWrite;
        BlockDeviceAPI api = getBlockDeviceAPI();

        while (offset < bounds.getEnd()) {
            toWrite = Math.min(bb.remaining(), (int) (bounds.getEnd() - offset));

            bb.position(0).limit(toWrite);
            api.write(offset, bb);
            bb.clear();

            offset += toWrite;
        }
    }
View Full Code Here

    }

    public static File copyDeviceToFile(Device imageDevice, String destFile)
        throws SecurityException, IOException, ApiNotFoundException {
        File dest = new File(destFile);
        BlockDeviceAPI imgApi = imageDevice.getAPI(BlockDeviceAPI.class);

        if (dest.exists())
            dest.delete();

        FileOutputStream fos = null;

        try {
            fos = new FileOutputStream(dest);

            byte[] buffer = new byte[1024];
            int toRead = 0;
            long devOffset = 0;
            long remaining = imgApi.getLength();
            while (remaining > 0) {
                toRead = (int) Math.min(buffer.length, remaining);
                imgApi.read(devOffset, ByteBuffer.wrap(buffer, 0, toRead));
                fos.write(buffer, 0, toRead);

                devOffset += toRead;
                remaining -= toRead;
            }
View Full Code Here

     */

    public static void copyInputStreamToDevice(InputStream imageStream,
                                               Device workDevice) throws ApiNotFoundException,
        NameNotFoundException, IOException, FileSystemException {
        BlockDeviceAPI wrkApi = workDevice.getAPI(BlockDeviceAPI.class);

        int sectorSize = 512;
        byte[] sector = new byte[sectorSize];
        long nbSectors = wrkApi.getLength() / sectorSize;
        long devOffset = 0;
        for (int s = 0; s < nbSectors; s++) {
            // log.debug("copying sector "+s);
            int nbRead = imageStream.read(sector);
            if (nbRead < 0)
                break;

            wrkApi.write(devOffset, ByteBuffer.wrap(sector, 0, nbRead));
            devOffset += nbRead;
        }
    }
View Full Code Here

        }
    }

    public static void copyDevice(Device imageDevice, Device workDevice)
        throws ApiNotFoundException, IOException {
        BlockDeviceAPI imgApi = imageDevice.getAPI(BlockDeviceAPI.class);
        BlockDeviceAPI wrkApi = workDevice.getAPI(BlockDeviceAPI.class);

        if (imgApi.getLength() != wrkApi.getLength())
            throw new IllegalArgumentException("devices of different length");
        // if(imgApi.getSectorSize() != wrkApi.getSectorSize())
        // throw new IllegalArgumentException("devices of different sector
        // size");

        // int sectorSize = imgApi.getSectorSize();
        int sectorSize = 512;
        byte[] sector = new byte[sectorSize];
        long nbSectors = imgApi.getLength() / sectorSize;
        long devOffset = 0;
        for (int s = 0; s < nbSectors; s++) {
            // log.debug("copying sector "+s);
            imgApi.read(devOffset, ByteBuffer.wrap(sector, 0, sector.length));
            wrkApi.write(devOffset, ByteBuffer.wrap(sector, 0, sector.length));
            devOffset += sectorSize;
        }
    }
View Full Code Here

    public static void main(String[] args) {

        try {
            final DeviceManager dm = InitialNaming.lookup(DeviceManager.NAME);
            final Device fd0 = dm.getDevice("fd0");
            final BlockDeviceAPI api = fd0.getAPI(BlockDeviceAPI.class);
            try {

                final ByteBuffer buf = ByteBuffer.allocate(512);
                api.read(0, buf);
            } catch (IOException ex) {
                log.error("Oops", ex);
            }
        } catch (ApiNotFoundException ex) {
            log.error("BlockDeviceAPI not found", ex);
View Full Code Here

     *
     * @throws IOException
     */
    public void flush() throws IOException {

        final BlockDeviceAPI api = getApi();

        if (bs.isDirty()) {
            bs.write(api);
        }

View Full Code Here

    public String toString() {
        if (ContextManager.getInstance().getContext() == null) {
            return getContextClass().getName() + "[NO_CONTEXT]";
        }

        BlockDeviceAPI api = getBlockDeviceAPI();
        return (api == null) ? getContextClass().getName() + "[NO_API]" : api
            .getClass().getName();
    }
View Full Code Here

            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++;
        }
    }
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.