Fuse Example File System - The file changed on disk do you want to reload the file

匆匆过客 提交于 2019-12-12 02:18:11

问题


Running built-in fuse HelloFS example file system, shows a hello.txt file on root. Opening this file show an error as "...The file changed on disk do you want to reload the file. Reload/cancel"

How can I remove this error.

I am facing the same error in my custom File System because I had taken HelloFS as starting point. To make question simple I quoted HelloFS code because the same error is in helloFS also.

example code, log and screenshot of error are as below:

HelloFS java Code:

package net.fusejna.examples;

import java.io.File;
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;

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

    private final String filename = "/hello.txt";
    private final String contents = "Hello World!\n";

    @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)) { // hello.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;
    }
}

error: ...The file changed on disk do you want to reload the file. Reload/cancel

log:

Mar 24, 2014 12:16:15 AM HelloFS statfs
INFO: [/] Method succeeded. Result: 0
Mar 24, 2014 12:16:33 AM HelloFS getattr
INFO: [/hello.txt] Method succeeded. Result: 0
Mar 24, 2014 12:16:36 AM HelloFS getattr
INFO: [/hello.txt] Method succeeded. Result: 0
Mar 24, 2014 12:16:45 AM HelloFS getattr
INFO: [/hello.txt] Method succeeded. Result: 0
Mar 24, 2014 12:16:45 AM HelloFS getattr
INFO: [/] Method succeeded. Result: 0
Mar 24, 2014 12:16:45 AM HelloFS open
INFO: [/hello.txt] Method succeeded. Result: 0
Mar 24, 2014 12:16:45 AM HelloFS read
INFO: [/hello.txt] Method succeeded. Result: 13
Mar 24, 2014 12:16:45 AM HelloFS getattr
INFO: [/hello.txt] Method succeeded. Result: 0
Mar 24, 2014 12:16:45 AM HelloFS flush
INFO: [/hello.txt] Method succeeded. Result: 0
Mar 24, 2014 12:16:45 AM HelloFS lock
INFO: [/hello.txt] Method succeeded. Result: -38
Mar 24, 2014 12:16:45 AM HelloFS release
INFO: [/hello.txt] Method succeeded. Result: 0
Mar 24, 2014 12:16:46 AM HelloFS getattr
INFO: [/hello.txt] Method succeeded. Result: 0
Mar 24, 2014 12:16:46 AM HelloFS getattr
INFO: [/] Method succeeded. Result: 0
Mar 24, 2014 12:16:48 AM HelloFS getattr
INFO: [/hello.txt] Method succeeded. Result: 0

Please Guide me how to fix this


回答1:


I am not as familiar with the Java version of FUSE (I mostly do C++/Python), but based on your trace, I'd say that your editor application is the one releasing the file handle. Maybe it's doing something like open/read/close, and then holding it in cache. Try opening the file in something even simpler, like vi, or using cat on it.

The thing about "the contents have changed on disk" is probably your editor responding to a continuously changing timestamp in your stat structure. Try setting your StatWrapper.mtime (in your getattr function) to some fixed time, like unix epoch, and see if that helps.

The example file systems are a good jumping off point, but in order to be easy to understand, there's often a lot they don't implement.



来源:https://stackoverflow.com/questions/22595823/fuse-example-file-system-the-file-changed-on-disk-do-you-want-to-reload-the-fi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!