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

StackOverflow https://stackoverflow.com/questions/22595823

  •  19-06-2023
  •  | 
  •  

Pregunta

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

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top