]> pere.pagekite.me Git - homepage.git/blob - blog/data/2010-08-26-fs-sematics.txt
Generated.
[homepage.git] / blog / data / 2010-08-26-fs-sematics.txt
1 Title: Broken umask handling with sshfs
2 Tags: english, nuug, debian edu
3 Date: 2010-08-26 13:30
4
5 <p>My file system sematics program
6 <a href="http://people.skolelinux.org/pere/blog/Testing_if_a_file_system_can_be_used_for_home_directories___.html">presented
7 a few days ago</a> is very useful to verify that a file system can
8 work as a unix home directory,and today I had to extend it a bit. I'm
9 looking into alternatives for home directory access here at the
10 University of Oslo, and one of the options is sshfs. My friend
11 Finn-Arne mentioned a while back that they had used sshfs with Debian
12 Edu, but stopped because of problems. I asked today what the problems
13 where, and he mentioned that sshfs failed to handle umask properly.
14 Trying to detect the problem I wrote this addition to my fs testing
15 script:</p>
16
17 <pre>
18 mode_t touch_get_mode(const char *name, mode_t mode) {
19 mode_t retval = 0;
20 int fd = open(name, O_RDWR|O_CREAT|O_LARGEFILE, mode);
21 if (-1 != fd) {
22 unlink(name);
23 struct stat statbuf;
24 if (-1 != fstat(fd, &statbuf)) {
25 retval = statbuf.st_mode & 0x1ff;
26 }
27 close(fd);
28 }
29 return retval;
30 }
31
32 /* Try to detect problem discovered using sshfs */
33 int test_umask(void) {
34 printf("info: testing umask effect on file creation\n");
35
36 mode_t orig_umask = umask(000);
37 mode_t newmode;
38 if (0666 != (newmode = touch_get_mode("foobar", 0666))) {
39 printf(" error: Wrong file mode %o when creating using mode 666 and umask 000\n",
40 newmode);
41 }
42 umask(007);
43 if (0660 != (newmode = touch_get_mode("foobar", 0666))) {
44 printf(" error: Wrong file mode %o when creating using mode 666 and umask 007\n",
45 newmode);
46 }
47
48 umask (orig_umask);
49 return 0;
50 }
51
52 int main(int argc, char **argv) {
53 [...]
54 test_umask();
55 return 0;
56 }
57 </pre>
58
59 <p>Sure enough. On NFS to a netapp, I get this result:</p>
60
61 <pre>
62 Testing POSIX/Unix sematics on file system
63 info: testing symlink creation
64 info: testing subdirectory creation
65 info: testing fcntl locking
66 Read-locking 1 byte from 1073741824
67 Read-locking 510 byte from 1073741826
68 Unlocking 1 byte from 1073741824
69 Write-locking 1 byte from 1073741824
70 Write-locking 510 byte from 1073741826
71 Unlocking 2 byte from 1073741824
72 info: testing umask effect on file creation
73 </pre>
74
75 <p>When mounting the same directory using sshfs, I get this
76 result:</p>
77
78 <pre>
79 Testing POSIX/Unix sematics on file system
80 info: testing symlink creation
81 info: testing subdirectory creation
82 info: testing fcntl locking
83 Read-locking 1 byte from 1073741824
84 Read-locking 510 byte from 1073741826
85 Unlocking 1 byte from 1073741824
86 Write-locking 1 byte from 1073741824
87 Write-locking 510 byte from 1073741826
88 Unlocking 2 byte from 1073741824
89 info: testing umask effect on file creation
90 error: Wrong file mode 644 when creating using mode 666 and umask 000
91 error: Wrong file mode 640 when creating using mode 666 and umask 007
92 </pre>
93
94 <p>So, I can conclude that sshfs is better than smb to a Netapp or a
95 Windows server, but not good enough to be used as a home
96 directory.</p>
97
98 <p>Update 2010-08-26: Reported the issue in
99 <a href="http://bugs.debian.org/594498">BTS report #594498</a></p>
100
101 <p>Update 2010-08-27: Michael Gebetsroither report that he found the
102 script so useful that he created a GIT repository and stored it in
103 <a href="http://github.com/gebi/fs-test">http://github.com/gebi/fs-test</a>.</p>