Bug 242645 - sysutils/fusefs-exfat: cannot set modification timestamp (utimes(2)) if non-root user is used
Summary: sysutils/fusefs-exfat: cannot set modification timestamp (utimes(2)) if non-r...
Status: Closed Not A Bug
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Oleksii Samorukov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-15 09:03 UTC by Martin Birgmeier
Modified: 2021-11-25 18:45 UTC (History)
1 user (show)

See Also:
bugzilla: maintainer-feedback? (samm)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Birgmeier 2019-12-15 09:03:11 UTC
Scenario:
- FreeBSD 12.1
- All ports recompiled for 12.1
- Using a combination of tar cf - ... | ( cd <exfat-fs> ; tar xfp - ) to copy files to an exfat-formatted SD card

Result:
- Since a few weeks, the receiving tar gives messages like

x <filename>: Can't restore time

- I believe this started to happen when I installed FreeBSD 12.1 and recompiled all ports
- The file contents are otherwise o.k. (verified using diff -r)

Scenario (continued):
- I have written a small utility "cptimes" which copies the atime and mtime from one file to another

Result:
- Trying to use this utility to correct these times manually results in

[1]% cptimes <sourcefile> <destinationfile>
<destinationfile>: Operation not permitted
[1]% 

-- Martin
Comment 1 Martin Birgmeier 2019-12-15 09:06:47 UTC
One more note: The same commands on another SD-card which is formatted as NTFS and uses sysutils/fusefs-ntfs work fine.
Comment 2 Oleksii Samorukov freebsd_committer freebsd_triage 2020-05-03 20:51:16 UTC
Unable to reproduce and issue is most likely related to the damaged fs on the target sd card.


# mdconfig -a -s 1g
md0

# mkfs.exfat /dev/md0
mkexfatfs 1.3.0
Creating... done.
Flushing... done.
File system created successfully.

# fsck.exfat /dev/md0
exfatfsck 1.3.0
Checking file system on /dev/md0.
File system version           1.0
Sector size                 512 bytes
Cluster size                 32 KB
Volume size                   1 GB
Used space                  288 KB
Available space               1 GB
Totally 0 directories and 0 files.
File system checking finished. No errors found.

Below is a test provided by me:


# mount.exfat /dev/md0 /mnt/
FUSE exfat 1.3.0

[root@bunny /mnt]# echo test > test
[root@bunny /mnt]# ls -l
total 32
-rwxrwxrwx  1 root  wheel  5 May  3 22:43 test

# rsync -a /etc/hosts /mnt/hosts

# ls -l /mnt/hosts
-rwxrwxrwx  1 root  wheel  1116 Nov 28 14:36 /mnt/hosts


# touch -d "2018-01-02T22:13:14" /mnt/hosts

# stat /mnt/hosts
18446744073391374205 4 -rwxrwxrwx 1 root wheel 0 1116 "Jan  2 22:13:14 2018" "Jan  2 22:13:14 2018" "Jan  2 22:13:14 2018" "Jan  1 00:59:59 1970" 4096 64 0 /mnt/hosts

Also i tested that timestamp persist after remount. My recommendation would be to reformat the card and start from scratch. Feel free to reopen if needed.
Comment 3 Martin Birgmeier 2020-05-04 11:42:50 UTC
O.k. thank you for checking.

-- Martin
Comment 4 Martin Birgmeier 2021-08-01 06:44:11 UTC
Setting file times on exfat is still not working - and now I have also found out why it could not be reproduced: It is working only for the root user but not for a regular user.

This is the fstab line used for mounting:

/dev/diskid/DISK-12345678s1     /d/69s1 exfat   rw,noauto,mountprog=/usr/local/sbin/mount.exfat 0 0

-- Martin
Comment 5 Martin Birgmeier 2021-08-01 06:47:55 UTC
... and the problem probably is that even though the manpage states

       uid=n  Set the owner for all files and directories.  The default is the
              owner of the current process.

       gid=n  Set the group for all files and directories.  The default is the
              group of the current process.

all files are instead owned by root, even though they are being written by another user.

This can be seen by writing some files to the exfat filesystem as another user and then listing them - they are all owned by root.

-- Martin
Comment 6 Martin Birgmeier 2021-08-01 09:24:43 UTC
Furthermore, calls to chown and chgrp should silently succeed instead of returning with an error code. Exfat does not support the concept of an owner, so changing to any owner should just be fine.

-- Martin
Comment 7 Oleksii Samorukov freebsd_committer freebsd_triage 2021-11-24 21:44:59 UTC
I found a workaround for the issue. You can mount FS from user itself, e.g.

mount_fusefs auto /home/samm/fuse mount.exfat-fuse /dev/md0 /home/samm/fuse

and this would show you all the files with user uid/gid
Comment 8 Oleksii Samorukov freebsd_committer freebsd_triage 2021-11-24 21:45:45 UTC
> Furthermore, calls to chown and chgrp should silently succeed instead of returning with an error code. 

not sure what logic is actually "correct" here. Better to report to upstream, i do not want to change that myself
Comment 9 Oleksii Samorukov freebsd_committer freebsd_triage 2021-11-24 21:50:12 UTC
And another workaround. If mounted from root using 

sudo mount_fusefs -o allow_other auto /mnt/ mount.exfat-fuse /dev/md0 /mnt/

it allows to change the perms
Comment 10 Oleksii Samorukov freebsd_committer freebsd_triage 2021-11-24 22:00:36 UTC
UID/GID options are not supported on the FreeBSD. Patch from upstream to disable them already landed. Closing this as there is nothing to do and workaround exists.
Comment 11 Martin Birgmeier 2021-11-25 16:54:35 UTC
Dear Oleksii,

Thank you for pointing out the workaround of using "-o allow_other".

Best regards,

Martin
Comment 12 Oleksii Samorukov freebsd_committer freebsd_triage 2021-11-25 17:14:17 UTC
You welcome. Likely we need to put this in some place. Port install message? FreeBSD wiki? Not sure yet.
Comment 13 Martin Birgmeier 2021-11-25 18:45:31 UTC
The port install message is probably the best suited.

-- Martin