SerCeMan / jnr-fuse

FUSE implementation in Java using Java Native Runtime (JNR)
MIT License
363 stars 86 forks source link

How to set `birth_time` in `getattr` #113

Closed Kianoosh76 closed 3 years ago

Kianoosh76 commented 3 years ago

Hi!

I was following your examples for the getattr implementation. But when it comes to the Timespec fields, it won't work anymore

Here's the code:

    @Override
    public int getattr(String path, FileStat stat) {
        try {
            stat.st_uid.set(0);
            stat.st_gid.set(0);
            stat.st_size.set(100);
            stat.st_birthtime.tv_nsec.set(1 << 15); // Throws a NullPointerException
        } catch (Exception e){
            e.printStackTrace();
        }

        return 0;
    }

I couldn't find any documentation about how to instantiate the Timespec fields. Could you provide some hint?

spinkb commented 3 years ago

Its definitely far from obvious with no examples...I finally figure this out for my scenario to set the modified time:

stat.st_mtim.tv_nsec.set(System.currentTimeMillis()); stat.st_mtim.tv_sec.set((System.currentTimeMillis() / 1000L));

Kianoosh76 commented 3 years ago

Thanks!

Yes that worked fine. The problem was that in my linux system birth_time was always null. It does not show that for regular files either