English 中文(简体)
利用FUSE与Java的图书馆;试图复制hello.c。
原标题:Using FUSE library with Java; trying to replicate hello.c example

我正试图通过

The FUSE library comes with a few example filesystems written in C. The simplest of them is hello.c. The following is a minimized version of its code to simply a few prints in the filesystem functions:

hello.c:

/*
  FUSE: Filesystem in Userspace
  Copyright (C) 2001-2007  Miklos Szeredi <[email protected]>

  This program can be distributed under the terms of the GNU GPL.
  See the file COPYING.

  gcc -Wall hello.c -o hello `pkg-config fuse --cflags --libs`
*/
#define FUSE_USE_VERSION 26

#include <fuse.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>

static int hello_getattr(const char *path, struct stat *stbuf)
{
    printf("getattr was called
");
    return 0;
}

static int hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi)
{
    printf("readdir was called
");
    return 0;
}

static int hello_open(const char *path, struct fuse_file_info *fi)
{
    printf("open was called
");
    return 0;
}

static int hello_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
{
    printf("read was called
");
    return 0;
}

static struct fuse_operations hello_oper = {
    .getattr    = hello_getattr,
    .readdir    = hello_readdir,
    .open       = hello_open,
    .read       = hello_read,
};

int main(int argc, char *argv[])
{
    return fuse_main_real(argc, argv, &hello_oper, sizeof(hello_oper), NULL);
}

可使用<代码>gcc-Wall hello.c-o hello进行汇编。 -D_FILE_OFFSET_BITS=64 -I/usr/include/fuse - pthread -lfuse -lrt -ldl

引用<条码>。

<代码>-f的旗帜是使其停留在地下,以便你能够看到<代码>f(>。

所有这些工作都很好,你可以看到<条码>(<>/条码>)妥善执行。 我正试图利用日本退休人员协会在贾瓦邦重复同样的事情。 这里我要谈谈:

:

import com.sun.jna.Callback;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;

public class FuseTemp
{
    public static interface Fuse extends Library
    {
        int fuse_main_real(int argc, String[] argv, StructFuseOperations op, long size, Pointer user_data);
    }

    @SuppressWarnings("unused")
    public static class StructFuseOperations extends Structure
    {
        public static class ByReference extends StructFuseOperations implements Structure.ByReference
        {
        }

        public Callback getattr = new Callback()
        {
            public int callback(final String path, final Pointer stat)
            {
                System.out.println("getattr was called");
                return 0;
            }
        };
        public Callback readlink = null;
        public Callback mknod = null;
        public Callback mkdir = null;
        public Callback unlink = null;
        public Callback rmdir = null;
        public Callback symlink = null;
        public Callback rename = null;
        public Callback link = null;
        public Callback chmod = null;
        public Callback chown = null;
        public Callback truncate = null;
        public Callback utime = null;
        public Callback open = new Callback()
        {
            public int callback(final String path, final Pointer info)
            {
                System.out.println("open was called");
                return 0;
            }
        };
        public Callback read = new Callback()
        {
            public int callback(final String path, final Pointer buffer, final long size, final long offset, final Pointer fi)
            {
                System.out.println("read was called");
                return 0;
            }
        };
        public Callback write = null;
        public Callback statfs = null;
        public Callback flush = null;
        public Callback release = null;
        public Callback fsync = null;
        public Callback setxattr = null;
        public Callback getxattr = null;
        public Callback listxattr = null;
        public Callback removexattr = null;
        public Callback opendir = null;
        public Callback readdir = new Callback()
        {
            public int callback(final String path, final Pointer buffer, final Pointer filler, final long offset,
                    final Pointer fi)
            {
                System.out.println("readdir was called");
                return 0;
            }
        };
        public Callback releasedir = null;
        public Callback fsyncdir = null;
        public Callback init = null;
        public Callback destroy = null;
        public Callback access = null;
        public Callback create = null;
        public Callback ftruncate = null;
        public Callback fgetattr = null;
        public Callback lock = null;
        public Callback utimens = null;
        public Callback bmap = null;
        public int flag_nullpath_ok;
        public int flag_reserved;
        public Callback ioctl = null;
        public Callback poll = null;
    }

    public static void main(final String[] args)
    {
        final String[] actualArgs = { "-f", "/some/mount/point" };
        final Fuse fuse = (Fuse) Native.loadLibrary("fuse", Fuse.class);
        final StructFuseOperations.ByReference operations = new StructFuseOperations.ByReference();
        System.out.println("Mounting");
        final int result = fuse.fuse_main_real(actualArgs.length, actualArgs, operations, operations.size(), null);
        System.out.println("Result: " + result);
        System.out.println("Mounted");
    }
}

<代码>fuse_operations的定义 可见。

可使用<代码>javac加以汇编。 - c 页: 1 FuseTemp.java

引用java -cp path/to/jna.jar: FuseTemp

jna.jar,可在上查阅。

The error that comes up is: fusermount: failed to access mountpoint /some/mount/point: Permission denied.

我正在执行与同一用户相同的方案,同时在同一个顶点夹上获得同样的许可,我参加了<代码>fuse。 我正在使用:

  • Linux kernel 3.0.0
  • FUSE 2.8.4
  • OpenJDK 1.6.0_23
  • JNA 3.4.0

So my question is: What exactly is different between these two programs (hello.c and FuseTemp.java), and how to make them do the same thing?

Thanks in advance.

<>Edit:此处是附加信息。

页: 1

  File: `/some/mount/point 
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 803h/2051d      Inode: 540652      Links: 2
Access: (0777/drwxrwxrwx)  Uid: ( 1000/ myusername)   Gid: ( 1000/ myusername)

产出一从作为经常用户的 Java方案运行:

Mounting
fusermount: failed to access mountpoint /some/mount/point: Permission denied
Result: 1
Mounted
(program exits with return code 0)

After this, trying to execute stat gives the following error message:

www.un.org/Depts/DGACM/index_russian.htm 运输终点没有连接 ......

这是因为, Java方案是徒劳无益的,因此,它不能称呼。 如果我尝试<条码>用户群——u /some/mount/point,我就得:

fusermount: entry for /some/mountpoint not found in /etc/mtab

And if I try sudo fusermount -u /some/mount/point, the mountpoint is successfully unmounted and there is no output from fusermount. /etc/mtab is chmod d 644 (-rw-r--r--) so my user can read it, but it doesn t contain /some/mount/point. After a successful unmount, the mountpoint is back to its old permissions (777 directory).

如今,把 j瓦方案作为根基:

Mounting
Result: 1
Mounted
(program exits with return code 0)

之后,stating /about/mount/point 这表明尚未修改,即仍然有777份名录。

I have also rewritten FuseTemp.java to include all Callbacks as Callbacks instead of Pointers. The behavior is the same, however.

我审视了引信源代码,错误代码1在整个执行过程中可在多个地点返回。 我将在这里指出,在什么地方,它完全是失败的。

Now for hello.c: running it as regular user, starting with the same permissions on /some/mount/point and passing it the arguments -f and /some/mount/point, the program doesn t print any output at first but keeps running. When running stat on the mountpoint, the program prints

getattr was called

就像它一样。 。 在作为经常用户执行<条码>的用户数量——u /about/mount/point后,方案采用回归代码0而未完成。

从<条码>/部分/最高/点<>/条码>的相同许可开始,并通过<条码>-f和<条码>/部分/最高/点等论点,方案首先印刷了任何产出,但继续运作。 当在顶点上运行<条码><> > /代码>时,由于我不是根基,我就获得了许可。 内容提要

getattr was called

就像它一样。 缩略语 定期用户产量

fusermount: entry for /some/mount/point not found in /etc/mtab

实际执行<代码>fusermount,方案从回归代码0 退出,未完成。

最佳回答

创立。 虽然这一错误确实是可笑的,但很容易发现。

www.un.org/Depts/DGACM/index_spanish.htm 解决办法:Fuse s fuse_main_real 方法第一种论点是论点清单。 在这份清单中,它希望0号论点成为档案系统的名称或某种有意义的方案名称。 因此,而不是

final String[] actualArgs = { "-f", "/some/mount/point" };

本来应该

final String[] actualArgs = { "programName", "-f", "/some/mount/point" };

This also means that you can t use the argument list that Java gives you in your main method, since that doesn t include the program name either.

www.un.org/Depts/DGACM/index_spanish.htm 为什么要处理:实际使用的是自己的论据:<条码>/bin/mount。 通过以下论点:

--no-canonicalize -i -f -t fuse.(arg 0) -o (options) (mountpoints) ...

因此,如果你将<条码>-f / s/mount/point<>/code>作为理由清单,将试图操作:

/bin/mount --no-canonicalize -i -f -t fuse.-f -o rw,nosuid,nodev /some/mount/point

www.un.org/Depts/DGACM/index_spanish.htm 如何发现: 在使用源代码中添加>>>的序号,以显示在哪些地方发生故障:/lib/mount_util.c,第82行:

execl("/bin/mount", "/bin/mount", "--no-canonicalize", "-i",
      "-f", "-t", type, "-o", opts, fsname, mnt, NULL);

我对假设错误表示歉意,是因为该错误与 Java相关或与JNA有关或与许可有关。 我将编辑问题标题和标题,以反映这一点。 (在我的辩护中,错误的引信正在回来(“被拒”)肯定是有用的 t!)

感谢您的助手和技师,我再次表示歉意,因为事实证明你是sil误的。

问题回答

B. 关于在开斋时被否认的问题...... 我确信, Java的安全许可事项正在这里解释为什么在超级用户模式运行时没有发现任何例外,但在非超级用户模式运行时,不允许例外。

从我可以理解的角度来看, Java的安全等级不同于标准C方案(一些可能包括安全检查的C图书馆除外,例如网络管理C++图书馆)。 尽管文件操作功能来自<代码>libfuse.so,但也可能指可能在系统方圆存储空间内执行的LC系统方言。 从现在起,它通过 Java, Java必须装上/绘制所有图书馆功能,包括系统打上记忆。 如果Java在系统掩体记忆空间而不是执行期间的用户记忆空间中发现记忆图,它将请其安全主管对照 Java方案目前的用户状况进行核查。

否则,所否认的错误实际上可能来自试图从正常使用者那里获得限制的顶点,而这是预期的行为。 然后,这与 Java毫无关系。 但是,这种错误也发生在C方案。 但是,从您的职位和评论来看,这并没有说明这一点。

However, running the program as root didn t cause the error to appear. Alas, it didn t seem to do anything: It just said "Mounting" and "Mounted" instantly. So it does go up to completion, but the fuse_main_real call returns instantly. The number it returns is 1. That is some progress, but the program needs to be runnable as a regular user like hello.c can.

另一方面,根据你最近的上述评论,似乎你的职能点(回顾)领域位于<代码>。 结构用途业务 结构并不致力于“引发”任何可能援引的引信事件。

<>说明: 我假定,“无人”的主要 Java方案显示“发育”和“发育”以及两者间实际上涉及电话<代码>fuse_main_real的任何其它内容。 在超级用户模式管理该方案时,采用不焚烧任何引信事件的方法,但采用1套回归法。 我没有在那个职位上尝试过该守则,因为现在我没有机会接触到诺琴科公司。

<>Update>strong>:从现在起,关于JNA结构中的退胎的讨论在最近更新员额之后不再有效:

Based on the given link, fuse_operations Struct Reference, you only focus on a few fields of the C structure as follows:

static struct fuse_operations hello_oper = {
    int (getattr*)(const char *path, struct stat *stbuf);
    /** some 12 skipped callbacks in between **/
    int (open*)(const char *path, struct fuse_file_info *fi);
    int (read*)(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
    /** some 10 skipped callbacks in between **/
    int (readdir*)(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi);
    /** some 11 skipped callbacks in between **/
    unsigned int flag_nullpath_ok;
    unsigned int flag_reserved;
    /** some 2 skipped callbacks in between **/
};

然而,你似乎试图用dding子跳出几个警钟。 因此,维持在<条码>fuse_operations中说明的回击田的顺序。 您将<密码><><> > /代码>的类型适用于您所熟知的每个反馈领域。 然而,通过为这些熟练的结构领域假定一个简单的<代码>><>>>>领域,你删除了关于每个领域吸引力的重要信息:背书。

From JNA API Overview:

<Callbacks (Function Pointers)

JNA supports supplying Java callbacks to native code. You must define an interface that extends the Callback interface, and define a single callback method with a signature that matches the function pointer required by the native code. The name of the method may be something other than "callback" only if there is only a single method in the interface which extends Callback or the class which implements Callback. The arguments and return value follow the same rules as for a direct function invocation.

If the callback returns a String or String[], the returned memory will be valid until the returned object is GC d.

Following is what is suggested in the overview:

// Original C code
struct _functions {
  int (*open)(const char*,int);
  int (*close)(int);
};

// Equivalent JNA mapping
public class Functions extends Structure {
  public static interface OpenFunc extends Callback {
    int invoke(String name, int options);
  }
  public static interface CloseFunc extends Callback {
    int invoke(int fd);
  }
  public OpenFunc open;
  public CloseFunc close;
}
...
Functions funcs = new Functions();
lib.init(funcs);
int fd = funcs.open.invoke("myfile", 0);
funcs.close.invoke(fd);

然而,它并没有建议一种办法,在结构中,特别是在结构太大而且你不想界定你不关心的每一项呼吁时,适当地绕过 call技术。 也许,这并不必要,可能像你所面对的那种不明确的行为。

Probably, instead of Pointer for each callback field that you want to pad, you can use Callback field, maintain its field name as in the specification. You may or may not initialize it with the null value (I haven t tried this; possibly it may not work).

<>Update:

It seems that my suggestion above can work based on the unrelated JNA solution by tgdavies in C callback with JNA makes JRE crash where he padded those callback fields he wasn t interested with simple Callback type but the matching callback field names remained intact in the sp_session_callbacks Structure.

I guess,因为fuse_operations <代码>fuse_main_real无法向您感兴趣的预期引信事件开火。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签