1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml" dir=
"ltr">
5 <meta http-equiv=
"Content-Type" content=
"text/html;charset=utf-8" />
6 <title>Petter Reinholdtsen: Testing if a file system can be used for home directories...
</title>
7 <link rel=
"stylesheet" type=
"text/css" media=
"screen" href=
"http://people.skolelinux.org/pere/blog/style.css" />
8 <link rel=
"stylesheet" type=
"text/css" media=
"screen" href=
"http://people.skolelinux.org/pere/blog/vim.css" />
13 <a href=
"http://people.skolelinux.org/pere/blog/">Petter Reinholdtsen
</a>
21 <div class=
"title">Testing if a file system can be used for home directories...
</div>
22 <div class=
"date"> 8th August
2010</div>
23 <div class=
"body"><p>A few years ago, I was involved in a project planning to use
24 Windows file servers as home directory servers for Debian
25 Edu/Skolelinux machines. This was thought to be no problem, as the
26 access would be through the SMB network file system protocol, and we
27 knew other sites used SMB with unix and samba as the file server to
28 mount home directories without any problems. But, after months of
29 struggling, we had to conclude that our goal was impossible.
</p>
31 <p>The reason is simply that while SMB can be used for home
32 directories when the file server is Samba running on Unix, this only
33 work because of Samba have some extensions and the fact that the
34 underlying file system is a unix file system. When using a Windows
35 file server, the underlying file system do not have POSIX semantics,
36 and several programs will fail if the users home directory where they
37 want to store their configuration lack POSIX semantics.
</p>
39 <p>As part of this work, I wrote a small C program I want to share
40 with you all, to replicate a few of the problematic applications (like
41 OpenOffice.org and GCompris) and see if the file system was working as
42 it should. If you find yourself in spooky file system land, it might
43 help you find your way out again. This is the fs-test.c source:
</p>
47 * Some tests to check the file system sematics. Used to verify that
48 * CIFS from a windows server do not work properly as a linux home
50 * License: GPL v2 or later
52 * needs libsqlite3-dev and build-essential installed
53 * compile with: gcc -Wall -lsqlite3 -DTEST_SQLITE fs-test.c -o fs-test
56 #define _FILE_OFFSET_BITS
64
57 #define _LARGEFILE_SOURCE
1
58 #define _LARGEFILE64_SOURCE
1
60 #define _GNU_SOURCE /* for asprintf() */
65 #include
<string.h
>
66 #include
<stdlib.h
>
67 #include
<sys/file.h
>
68 #include
<sys/stat.h
>
69 #include
<sys/types.h
>
70 #include
<unistd.h
>
74 * Test sqlite open, as done by gcompris require the libsqlite3-dev
75 * package and linking with -lsqlite3. A more low level test is
77 * See also
<URL: http://www.sqlite.org./faq.html#q5
>.
79 #include
<sqlite3.h
>
80 #define CREATE_TABLE_USERS \
81 "CREATE TABLE users (user_id INT UNIQUE, login TEXT, lastname TEXT, firstname TEXT, birthdate TEXT, class_id INT ); "
82 int test_sqlite_open(void) {
84 char *name = "testsqlite.db";
87 int rc = sqlite3_open(name, &db);
89 printf("error: sqlite open of %s failed: %s\n", name, sqlite3_errmsg(db));
95 rc = sqlite3_exec(db,CREATE_TABLE_USERS, NULL,
0, &zErrMsg);
96 if( rc != SQLITE_OK ){
97 printf("error: sqlite table create failed: %s\n", zErrMsg);
101 printf("info: sqlite worked\n");
105 #endif /* TEST_SQLITE */
108 * Demonstrate locking issue found in gcompris using sqlite3. This
109 * work with ext3, but not with cifs server on Windows
2003. This is
110 * done in the sqlite3 library.
112 *
<URL:http://www.cygwin.com/ml/cygwin/
2001-
08/msg00854.html
> and the
113 * POSIX specification
114 *
<URL:http://www.opengroup.org/onlinepubs/
009695399/functions/fcntl.html
>.
116 int test_gcompris_locking(void) {
118 char *name = "testsqlite.db";
120 int fd = open(name, O_RDWR|O_CREAT|O_LARGEFILE,
0644);
121 printf("info: testing fcntl locking\n");
123 fl.l_whence = SEEK_SET;
125 printf(" Read-locking
1 byte from
1073741824");
126 fl.l_start =
1073741824;
129 if (
0 != fcntl(fd, F_SETLK, &fl) ) printf(" - error!\n"); else printf("\n");
131 printf(" Read-locking
510 byte from
1073741826");
132 fl.l_start =
1073741826;
135 if (
0 != fcntl(fd, F_SETLK, &fl) ) printf(" - error!\n"); else printf("\n");
137 printf(" Unlocking
1 byte from
1073741824");
138 fl.l_start =
1073741824;
141 if (
0 != fcntl(fd, F_SETLK, &fl) ) printf(" - error!\n"); else printf("\n");
143 printf(" Write-locking
1 byte from
1073741824");
144 fl.l_start =
1073741824;
147 if (
0 != fcntl(fd, F_SETLK, &fl) ) printf(" - error!\n"); else printf("\n");
149 printf(" Write-locking
510 byte from
1073741826");
150 fl.l_start =
1073741826;
152 if (
0 != fcntl(fd, F_SETLK, &fl) ) printf(" - error!\n"); else printf("\n");
154 printf(" Unlocking
2 byte from
1073741824");
155 fl.l_start =
1073741824;
158 if (
0 != fcntl(fd, F_SETLK, &fl) ) printf(" - error!\n"); else printf("\n");
165 * Test if permissions of freshly created directories allow entries
166 * below them. This was a problem with OpenOffice.org and gcompris.
167 * Mounting with option 'sync' seem to solve this problem while
168 * slowing down file operations.
170 int test_subdirectory_creation(void) {
172 char *path = strdup("test");
175 printf("info: testing subdirectory creation\n");
176 for (level =
0; level
< LEVELS; level++) {
177 char *newpath = NULL;
178 if (-
1 == mkdir(path,
0777)) {
179 printf(" error: Unable to create directory '%s': %s\n",
180 path, strerror(errno));
183 asprintf(&newpath, "%s/%s", path, "test");
191 * Test if symlinks can be created. This was a problem detected with
194 int test_symlinks(void) {
195 printf("info: testing symlink creation\n");
197 if (-
1 == symlink("file", "symlink"))
198 printf(" error: Unable to create symlink\n");
202 int main(int argc, char **argv) {
203 printf("Testing POSIX/Unix sematics on file system\n");
205 test_subdirectory_creation();
208 #endif /* TEST_SQLITE */
209 test_gcompris_locking();
214 <p>When everything is working, it should print something like
218 Testing POSIX/Unix sematics on file system
219 info: testing symlink creation
220 info: testing subdirectory creation
222 info: testing fcntl locking
223 Read-locking
1 byte from
1073741824
224 Read-locking
510 byte from
1073741826
225 Unlocking
1 byte from
1073741824
226 Write-locking
1 byte from
1073741824
227 Write-locking
510 byte from
1073741826
228 Unlocking
2 byte from
1073741824
231 <p>I do not remember the exact details of the problems we saw, but one
232 of them was with locking, where if I remember correctly, POSIX allow a
233 read-only lock to be upgraded to a read-write lock without unlocking
234 the read-only lock (while Windows do not). Another was a bug in the
235 CIFS/SMB client implementation in the Linux kernel where directory
236 meta information would be wrong for a fraction of a second, making
237 OpenOffice.org fail to create its deep directory tree because it was
238 not allowed to create files in its freshly created directory.
</p>
240 <p>Anyway, here is a nice tool for your tool box, might you never need
243 <p>Update
2010-
08-
27: Michael Gebetsroither report that he found the
244 script so useful that he created a GIT repository and stored it in
245 <a href=
"http://github.com/gebi/fs-test">http://github.com/gebi/fs-test
</a>.
</p>
248 <div class=
"tags">Tags:
<a href=
"http://people.skolelinux.org/pere/blog/tags/debian edu">debian edu
</a>,
<a href=
"http://people.skolelinux.org/pere/blog/tags/english">english
</a>,
<a href=
"http://people.skolelinux.org/pere/blog/tags/nuug">nuug
</a>.
</div>
266 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2012/01/">January (
7)
</a></li>
268 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2012/02/">February (
10)
</a></li>
270 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2012/03/">March (
17)
</a></li>
272 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2012/04/">April (
12)
</a></li>
274 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2012/05/">May (
12)
</a></li>
276 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2012/06/">June (
8)
</a></li>
283 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2011/01/">January (
16)
</a></li>
285 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2011/02/">February (
6)
</a></li>
287 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2011/03/">March (
6)
</a></li>
289 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2011/04/">April (
7)
</a></li>
291 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2011/05/">May (
3)
</a></li>
293 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2011/06/">June (
2)
</a></li>
295 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2011/07/">July (
7)
</a></li>
297 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2011/08/">August (
6)
</a></li>
299 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2011/09/">September (
4)
</a></li>
301 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2011/10/">October (
2)
</a></li>
303 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2011/11/">November (
3)
</a></li>
305 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2011/12/">December (
1)
</a></li>
312 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2010/01/">January (
2)
</a></li>
314 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2010/02/">February (
1)
</a></li>
316 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2010/03/">March (
3)
</a></li>
318 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2010/04/">April (
3)
</a></li>
320 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2010/05/">May (
9)
</a></li>
322 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2010/06/">June (
14)
</a></li>
324 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2010/07/">July (
12)
</a></li>
326 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2010/08/">August (
13)
</a></li>
328 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2010/09/">September (
7)
</a></li>
330 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2010/10/">October (
9)
</a></li>
332 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2010/11/">November (
13)
</a></li>
334 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2010/12/">December (
12)
</a></li>
341 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2009/01/">January (
8)
</a></li>
343 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2009/02/">February (
8)
</a></li>
345 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2009/03/">March (
12)
</a></li>
347 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2009/04/">April (
10)
</a></li>
349 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2009/05/">May (
9)
</a></li>
351 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2009/06/">June (
3)
</a></li>
353 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2009/07/">July (
4)
</a></li>
355 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2009/08/">August (
3)
</a></li>
357 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2009/09/">September (
1)
</a></li>
359 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2009/10/">October (
2)
</a></li>
361 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2009/11/">November (
3)
</a></li>
363 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2009/12/">December (
3)
</a></li>
370 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2008/11/">November (
5)
</a></li>
372 <li><a href=
"http://people.skolelinux.org/pere/blog/archive/2008/12/">December (
7)
</a></li>
383 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/3d-printer">3d-printer (
13)
</a></li>
385 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/amiga">amiga (
1)
</a></li>
387 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/aros">aros (
1)
</a></li>
389 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/bitcoin">bitcoin (
2)
</a></li>
391 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/bootsystem">bootsystem (
12)
</a></li>
393 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/bsa">bsa (
2)
</a></li>
395 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/debian">debian (
54)
</a></li>
397 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/debian edu">debian edu (
104)
</a></li>
399 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/digistan">digistan (
8)
</a></li>
401 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/drivstoffpriser">drivstoffpriser (
3)
</a></li>
403 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/english">english (
135)
</a></li>
405 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/fiksgatami">fiksgatami (
16)
</a></li>
407 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/fildeling">fildeling (
12)
</a></li>
409 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/intervju">intervju (
27)
</a></li>
411 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/kart">kart (
16)
</a></li>
413 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/ldap">ldap (
8)
</a></li>
415 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/lenker">lenker (
4)
</a></li>
417 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/ltsp">ltsp (
1)
</a></li>
419 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/multimedia">multimedia (
16)
</a></li>
421 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/norsk">norsk (
170)
</a></li>
423 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/nuug">nuug (
130)
</a></li>
425 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/offentlig innsyn">offentlig innsyn (
1)
</a></li>
427 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/open311">open311 (
2)
</a></li>
429 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/opphavsrett">opphavsrett (
25)
</a></li>
431 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/personvern">personvern (
47)
</a></li>
433 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/raid">raid (
1)
</a></li>
435 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/reprap">reprap (
11)
</a></li>
437 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/rfid">rfid (
2)
</a></li>
439 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/robot">robot (
4)
</a></li>
441 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/rss">rss (
1)
</a></li>
443 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/ruter">ruter (
4)
</a></li>
445 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/scraperwiki">scraperwiki (
1)
</a></li>
447 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/sikkerhet">sikkerhet (
23)
</a></li>
449 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/sitesummary">sitesummary (
4)
</a></li>
451 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/standard">standard (
29)
</a></li>
453 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/stavekontroll">stavekontroll (
1)
</a></li>
455 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/stortinget">stortinget (
4)
</a></li>
457 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/surveillance">surveillance (
10)
</a></li>
459 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/valg">valg (
6)
</a></li>
461 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/video">video (
25)
</a></li>
463 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/vitenskap">vitenskap (
1)
</a></li>
465 <li><a href=
"http://people.skolelinux.org/pere/blog/tags/web">web (
20)
</a></li>
471 <p style=
"text-align: right">
472 Created by
<a href=
"http://steve.org.uk/Software/chronicle">Chronicle v4.4
</a>