Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Checked out from CVS
  • Loading branch information
kohsuke committed Apr 14, 2009
0 parents commit 86df383
Show file tree
Hide file tree
Showing 180 changed files with 5,210 additions and 0 deletions.
2 changes: 2 additions & 0 deletions loopy-core/CREDITS.txt
@@ -0,0 +1,2 @@
loopy is based on the file system code from JNode (www.jnode.org). Thanks to the JNode developers for doing a lot of
hard work :)
4 changes: 4 additions & 0 deletions loopy-core/CVS/Entries
@@ -0,0 +1,4 @@
/CREDITS.txt/1.2/Wed Jul 4 02:35:23 2007//
/LICENSE.txt/1.2/Wed Jul 4 02:35:23 2007//
/pom.xml/1.3/Wed Jul 4 18:48:42 2007//
D
1 change: 1 addition & 0 deletions loopy-core/CVS/Entries.Log
@@ -0,0 +1 @@
A D/src////
1 change: 1 addition & 0 deletions loopy-core/CVS/Repository
@@ -0,0 +1 @@
loopy/loopy-core
1 change: 1 addition & 0 deletions loopy-core/CVS/Root
@@ -0,0 +1 @@
:pserver:anonymous@loopy.cvs.sourceforge.net:/cvsroot/loopy
458 changes: 458 additions & 0 deletions loopy-core/LICENSE.txt

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions loopy-core/pom.xml
@@ -0,0 +1,37 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>loopy-core</name>
<description>loopy core library.</description>

<parent>
<groupId>net.didion.loopy</groupId>
<artifactId>loopy</artifactId>
<version>0.3</version>
</parent>

<artifactId>loopy-core</artifactId>

<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>net/didion/loopy/udf/*.*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
1 change: 1 addition & 0 deletions loopy-core/src/CVS/Entries
@@ -0,0 +1 @@
D/main////
1 change: 1 addition & 0 deletions loopy-core/src/CVS/Repository
@@ -0,0 +1 @@
loopy/loopy-core/src
1 change: 1 addition & 0 deletions loopy-core/src/CVS/Root
@@ -0,0 +1 @@
:pserver:anonymous@loopy.cvs.sourceforge.net:/cvsroot/loopy
1 change: 1 addition & 0 deletions loopy-core/src/main/CVS/Entries
@@ -0,0 +1 @@
D/java////
1 change: 1 addition & 0 deletions loopy-core/src/main/CVS/Repository
@@ -0,0 +1 @@
loopy/loopy-core/src/main
1 change: 1 addition & 0 deletions loopy-core/src/main/CVS/Root
@@ -0,0 +1 @@
:pserver:anonymous@loopy.cvs.sourceforge.net:/cvsroot/loopy
1 change: 1 addition & 0 deletions loopy-core/src/main/java/CVS/Entries
@@ -0,0 +1 @@
D
1 change: 1 addition & 0 deletions loopy-core/src/main/java/CVS/Entries.Log
@@ -0,0 +1 @@
A D/net////
1 change: 1 addition & 0 deletions loopy-core/src/main/java/CVS/Repository
@@ -0,0 +1 @@
loopy/loopy-core/src/main/java
1 change: 1 addition & 0 deletions loopy-core/src/main/java/CVS/Root
@@ -0,0 +1 @@
:pserver:anonymous@loopy.cvs.sourceforge.net:/cvsroot/loopy
1 change: 1 addition & 0 deletions loopy-core/src/main/java/net/CVS/Entries
@@ -0,0 +1 @@
D/didion////
1 change: 1 addition & 0 deletions loopy-core/src/main/java/net/CVS/Repository
@@ -0,0 +1 @@
loopy/loopy-core/src/main/java/net
1 change: 1 addition & 0 deletions loopy-core/src/main/java/net/CVS/Root
@@ -0,0 +1 @@
:pserver:anonymous@loopy.cvs.sourceforge.net:/cvsroot/loopy
1 change: 1 addition & 0 deletions loopy-core/src/main/java/net/didion/CVS/Entries
@@ -0,0 +1 @@
D/loopy////
1 change: 1 addition & 0 deletions loopy-core/src/main/java/net/didion/CVS/Repository
@@ -0,0 +1 @@
loopy/loopy-core/src/main/java/net/didion
1 change: 1 addition & 0 deletions loopy-core/src/main/java/net/didion/CVS/Root
@@ -0,0 +1 @@
:pserver:anonymous@loopy.cvs.sourceforge.net:/cvsroot/loopy
135 changes: 135 additions & 0 deletions loopy-core/src/main/java/net/didion/loopy/AbstractBlockFileSystem.java
@@ -0,0 +1,135 @@
/*
Copyright (C) 2006-2007 loopy project (http://loopy.sourceforge.net)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.didion.loopy;

import java.io.File;
import java.io.IOException;
import java.util.Enumeration;

/**
* A block file system is segmented into multiple fixed-size blocks. It consists of a set of volume
* descriptors followed by an index, which points to the file locations.
*/
public abstract class AbstractBlockFileSystem extends AbstractFileSystem {
private final int blockSize;
private final int reservedBlocks;
private VolumeDescriptorSet volumeDescriptorSet;

protected AbstractBlockFileSystem(final File file, final boolean readOnly, final int blockSize,
final int reservedBlocks)
throws IOException {
super(file, readOnly);

if (blockSize <= 0) {
throw new IllegalArgumentException("'blockSize' must be > 0");
}
if (reservedBlocks < 0) {
throw new IllegalArgumentException("'reservedBlocks' must be >= 0");
}

this.blockSize = blockSize;
this.reservedBlocks = reservedBlocks;
}

public Enumeration getEntries() {
ensureOpen();

// load the volume descriptors if necessary
if (null == this.volumeDescriptorSet) {
try {
loadVolumeDescriptors();
}
catch (IOException ex) {
throw new RuntimeException(ex);
}
}

return enumerate(this.volumeDescriptorSet.getRootEntry());
}

protected void loadVolumeDescriptors() throws IOException {
final byte[] buffer = new byte[this.blockSize];

this.volumeDescriptorSet = createVolumeDescriptorSet();

// skip the reserved blocks, then read volume descriptor blocks sequentially and add them
// to the VolumeDescriptorSet
for (int block = this.reservedBlocks;
readBlock(block, buffer) && !this.volumeDescriptorSet.deserialize(buffer);
block++);
}

/**
* Read the data for the specified block into the specified buffer.
*
* @param block
* @param buffer
* @return if the block was actually read
* @throws IOException if the number of bytes read into the buffer was less than the expected
* number (i.e. the block size)
*/
protected boolean readBlock(final long block, final byte[] buffer) throws IOException {
final int bytesRead = readData(block * this.blockSize, buffer, 0, this.blockSize);

if (bytesRead <= 0) {
return false;
}

if (this.blockSize != bytesRead) {
throw new IOException("Could not deserialize a complete block");
}

return true;
}

/**
* Read file data, starting at the specified position.
*
* @param startPos
* @param buffer
* @param offset
* @param len
* @return the number of bytes read into the buffer
* @throws IOException
*/
protected synchronized int readData(final long startPos, final byte[] buffer, final int offset,
final int len)
throws IOException {
seek(startPos);
return read(buffer, offset, len);
}

protected VolumeDescriptorSet getVolumeDescriptorSet() {
return this.volumeDescriptorSet;
}

/**
* Returns an enumeration of the file entries starting at <code>root</code>.
*
* @param root
* @return
*/
protected abstract Enumeration enumerate(FileEntry root);

/**
* Creates the VolumeDescriptorSet that deserializes volume descriptors for this file system.
*
* @return
*/
protected abstract VolumeDescriptorSet createVolumeDescriptorSet();
}
103 changes: 103 additions & 0 deletions loopy-core/src/main/java/net/didion/loopy/AbstractFileSystem.java
@@ -0,0 +1,103 @@
/*
Copyright (C) 2006-2007 loopy project (http://loopy.sourceforge.net)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.didion.loopy;

import java.io.RandomAccessFile;
import java.io.File;
import java.io.IOException;
import java.io.FileNotFoundException;

/**
* Implementation of FileSystem that is backed by a {@link RandomAccessFile}.
*/
public abstract class AbstractFileSystem implements FileSystem {
/**
* Channel to the open file.
*/
private RandomAccessFile channel;

protected AbstractFileSystem(final File file, final boolean readOnly) throws IOException {
if (!readOnly) {
throw new IllegalArgumentException("Currrently, only read-only is supported");
}

// check that the underlying file is valid
if (!file.exists()) {
throw new FileNotFoundException("File does not exist: " + file);
}

// open the channel
this.channel = new RandomAccessFile(file, "r");
}

// TODO: close open streams automatically
public synchronized void close() throws IOException {
if (isClosed()) {
return;
}

try {
this.channel.close();
}
finally {
this.channel = null;
}
}

public boolean isClosed() {
return (null == this.channel);
}

/**
* Throws an exception if the underlying file is closed.
*
* @throws IllegalStateException
*/
protected void ensureOpen() throws IllegalStateException {
if (isClosed()) {
throw new IllegalStateException("File has been closed");
}
}

/**
* Moves the pointer in the underlying file to the specified position.
*
* @param pos
* @throws IOException
*/
protected void seek(long pos) throws IOException {
ensureOpen();
this.channel.seek(pos);
}

/**
* Reads up to <code>length</code> bytes into the specified buffer, starting at the specified
* offset. The actual number of bytes read will be less than <code>length</code> if there are
* not enough available bytes to read, or if the buffer is not large enough.
*
* @param buffer
* @param offset
* @param length
* @return the number of bytes read into the buffer
* @throws IOException
*/
protected int read(byte[] buffer, int offset, int length) throws IOException {
ensureOpen();
return this.channel.read(buffer, offset, length);
}
}
7 changes: 7 additions & 0 deletions loopy-core/src/main/java/net/didion/loopy/CVS/Entries
@@ -0,0 +1,7 @@
/AbstractBlockFileSystem.java/1.2/Wed Jul 4 18:48:43 2007//
/AbstractFileSystem.java/1.2/Wed Jul 4 18:48:43 2007//
/FileEntry.java/1.2/Wed Jul 4 02:35:23 2007//
/FileSystem.java/1.2/Wed Jul 4 02:35:23 2007//
/LoopyException.java/1.3/Wed Jul 4 18:48:43 2007//
/VolumeDescriptorSet.java/1.1/Wed Jul 4 02:35:23 2007//
D
4 changes: 4 additions & 0 deletions loopy-core/src/main/java/net/didion/loopy/CVS/Entries.Log
@@ -0,0 +1,4 @@
A D/impl////
A D/iso9660////
A D/udf////
A D/util////
1 change: 1 addition & 0 deletions loopy-core/src/main/java/net/didion/loopy/CVS/Repository
@@ -0,0 +1 @@
loopy/loopy-core/src/main/java/net/didion/loopy
1 change: 1 addition & 0 deletions loopy-core/src/main/java/net/didion/loopy/CVS/Root
@@ -0,0 +1 @@
:pserver:anonymous@loopy.cvs.sourceforge.net:/cvsroot/loopy

0 comments on commit 86df383

Please sign in to comment.