Skip to content

Commit

Permalink
Merge branch 'tbutter-master' (Linux ARM compatibility)
Browse files Browse the repository at this point in the history
  • Loading branch information
EtiennePerot committed Feb 25, 2015
2 parents 5e9f9d5 + 3dd0343 commit f60bf86
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ This being said, you can greatly increase throughput by preventing FUSE from chu
Following [fuse.py], fuse-jna should work with:

* OS X with [MacFUSE]/[fuse4x]/[OSXFUSE] on Intel architectures
* Linux with [FUSE][Linux-Fuse] on Intel and PowerPC architectures
* Linux with [FUSE][Linux-Fuse] on Intel, ARM, and PowerPC architectures
* FreeBSD with [FUSE][FreeBSD-Fuse] on Intel architectures

#### Projects using fuse-jna
Expand Down
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'maven-publish'

Expand All @@ -9,8 +10,10 @@ repositories {
mavenCentral()
}


dependencies {
compile 'net.java.dev.jna:jna:3.5.2'
compile 'net.java.dev.jna:jna:4.1.0'
compile "org.codehaus.groovy:groovy-all:2.1.5"
}

task uberJar(type: Jar) {
Expand Down
4 changes: 4 additions & 0 deletions examples/groovyfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

cd "`dirname "$0"`"
./run.sh net.fusejna.examples.GroovyFS "$@"
89 changes: 89 additions & 0 deletions src/main/groovy/net/fusejna/examples/GroovyFS.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package net.fusejna.examples


import java.util.Map
import java.util.Arrays
import java.util.HashMap
import java.nio.ByteBuffer
import net.fusejna.DirectoryFiller
import net.fusejna.ErrorCodes
import net.fusejna.FuseException
import net.fusejna.StructFuseFileInfo.FileInfoWrapper
import net.fusejna.StructStat.StatWrapper
import net.fusejna.types.TypeMode.NodeType
import net.fusejna.util.FuseFilesystemAdapterFull
import net.fusejna.XattrFiller
import net.fusejna.XattrListFiller

public class GroovyFS extends FuseFilesystemAdapterFull
{
public static void main(final String... args) throws FuseException
{
if (args.length != 1) {
System.err.println("Usage: GroovyFS <mountpoint>");
System.exit(1);
}
new GroovyFS().log(true).mount(args[0]);
}

def slurper = new groovy.json.JsonSlurper()
def helloTxtAttrs = slurper.parseText '''
{
"user.attr1" : "xattr 1 value",
"user.attr2" : "xattr 2 value",
"user.attr3" : "xattr 3 value"
}'''
final String filename = "/psaux.txt"
String contents = "ps aux".execute().text

@Override
public int getattr(final String path, final StatWrapper stat)
{
if (path.equals(File.separator)) { // Root directory
stat.setMode(NodeType.DIRECTORY);
return 0;
}
if (path.equals(filename)) { // psaux.txt
stat.setMode(NodeType.FILE).size(contents.length());
return 0;
}
return -ErrorCodes.ENOENT();
}
@Override
public int read(final String path, final ByteBuffer buffer, final long size, final long offset, final FileInfoWrapper info)
{
// Compute substring that we are being asked to read
final String s = contents.substring((int) offset,
(int) Math.max(offset, Math.min(contents.length() - offset, offset + size)));
buffer.put(s.getBytes());
return s.getBytes().length;
}
@Override
public int readdir(final String path, final DirectoryFiller filler)
{
filler.add(filename);
return 0;
}
@Override
public int listxattr(final String path, final XattrListFiller filler)
{
if (!path.equals(filename)) {
return -ErrorCodes.ENOTSUP();
}
filler.add(helloTxtAttrs.keySet());
return 0;
}
@Override
public int getxattr(final String path, final String xattr, final XattrFiller filler, final long size, final long position)
{
if (!path.equals(filename)) {
return -ErrorCodes.firstNonNull(ErrorCodes.ENOATTR(), ErrorCodes.ENOATTR(), ErrorCodes.ENODATA());
}
if (!helloTxtAttrs.containsKey(xattr)) {
return -ErrorCodes.firstNonNull(ErrorCodes.ENOATTR(), ErrorCodes.ENOATTR(), ErrorCodes.ENODATA());
}
filler.set(helloTxtAttrs.get(xattr).getBytes());
return 0;
};
}

5 changes: 4 additions & 1 deletion src/main/java/net/fusejna/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public final class Platform
{
public static enum PlatformEnum
{
LINUX_X86_64, LINUX_I686, LINUX_PPC, MAC, MAC_MACFUSE, FREEBSD
LINUX_X86_64, LINUX_I686, LINUX_PPC, MAC, MAC_MACFUSE, FREEBSD, LINUX_ARM
}

private static final String[] osxFuseLibraries = { "fuse4x", "osxfuse", "macfuse", "fuse" };
Expand Down Expand Up @@ -81,6 +81,9 @@ private static final void init()
if (com.sun.jna.Platform.isIntel()) {
platform = com.sun.jna.Platform.is64Bit() ? PlatformEnum.LINUX_X86_64 : PlatformEnum.LINUX_I686;
}
else if (com.sun.jna.Platform.isARM()) {
platform = PlatformEnum.LINUX_ARM;
}
else {
platform = PlatformEnum.LINUX_PPC;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/fusejna/StructFuseOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public final int callback(final String path, final StructStat.X86_64.ByReference
}
};
break;
case LINUX_ARM:
case LINUX_I686:
getattr = new Callback()
{
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/fusejna/types/TypeBlkCnt.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TypeBlkCnt extends IntegerType
size = 8;
break;
case LINUX_I686:
case LINUX_ARM:
case LINUX_PPC:
size = Platform.size(TypeLongLong.class);
break;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/fusejna/types/TypeBlkSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TypeBlkSize extends IntegerType
size = 4;
break;
case LINUX_I686:
case LINUX_ARM:
case LINUX_PPC:
case LINUX_X86_64:
size = Platform.size(NativeLong.class);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/fusejna/types/TypeDev.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class TypeDev extends IntegerType
size = 4;
break;
case LINUX_I686:
case LINUX_ARM:
case LINUX_PPC:
case LINUX_X86_64:
size = Platform.size(TypeLongLong.class);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/fusejna/types/TypeFsFilCnt.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TypeFsFilCnt extends IntegerType
size = Platform.size(NativeLong.class);
break;
case LINUX_I686:
case LINUX_ARM:
case LINUX_PPC:
case LINUX_X86_64:
size = Platform.size(TypeLongLong.class);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/fusejna/types/TypeGid.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class TypeGid extends IntegerType
size = 4;
break;
case LINUX_I686:
case LINUX_ARM:
case LINUX_PPC:
case LINUX_X86_64:
size = Platform.size(Integer.class);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/fusejna/types/TypeIno.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class TypeIno extends IntegerType
size = 4;
break;
case LINUX_I686:
case LINUX_ARM:
case LINUX_PPC:
size = Platform.size(TypeLongLong.class);
break;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/fusejna/types/TypeMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public final long getBits()
size = 2;
break;
case LINUX_I686:
case LINUX_ARM:
case LINUX_PPC:
case LINUX_X86_64:
size = Platform.size(Integer.class);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/fusejna/types/TypeNLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TypeNLink extends IntegerType
size = 2;
break;
case LINUX_I686:
case LINUX_ARM:
case LINUX_PPC:
size = Platform.size(Integer.class);
break;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/fusejna/types/TypeOff.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class TypeOff extends IntegerType
size = 8;
break;
case LINUX_I686:
case LINUX_ARM:
case LINUX_PPC:
case LINUX_X86_64:
size = Platform.size(TypeLongLong.class);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/fusejna/types/TypePid.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class TypePid extends IntegerType
size = 4;
break;
case LINUX_I686:
case LINUX_ARM:
case LINUX_PPC:
case LINUX_X86_64:
size = Platform.size(Integer.class);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/fusejna/types/TypeSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TypeSize extends IntegerType
size = 8;
break;
case LINUX_I686:
case LINUX_ARM:
size = 4;
break;
case LINUX_PPC:
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/fusejna/types/TypeUid.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class TypeUid extends IntegerType
size = 4;
break;
case LINUX_I686:
case LINUX_ARM:
case LINUX_PPC:
case LINUX_X86_64:
size = Platform.size(Integer.class);
Expand Down

0 comments on commit f60bf86

Please sign in to comment.