file-systems: Support the 'no-atime' flag.
[jackhill/guix/guix.git] / gnu / build / file-systems.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2016, 2017 David Craven <david@craven.ch>
4 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
5 ;;;
6 ;;; This file is part of GNU Guix.
7 ;;;
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
12 ;;;
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
17 ;;;
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21 (define-module (gnu build file-systems)
22 #:use-module (gnu system uuid)
23 #:use-module (gnu system file-systems)
24 #:use-module (guix build utils)
25 #:use-module (guix build bournish)
26 #:use-module ((guix build syscalls)
27 #:hide (file-system-type))
28 #:use-module (rnrs io ports)
29 #:use-module (rnrs bytevectors)
30 #:use-module (ice-9 match)
31 #:use-module (ice-9 rdelim)
32 #:use-module (system foreign)
33 #:autoload (system repl repl) (start-repl)
34 #:use-module (srfi srfi-1)
35 #:use-module (srfi srfi-26)
36 #:export (disk-partitions
37 partition-label-predicate
38 partition-uuid-predicate
39 partition-luks-uuid-predicate
40 find-partition-by-label
41 find-partition-by-uuid
42 find-partition-by-luks-uuid
43 canonicalize-device-spec
44
45 read-partition-label
46 read-partition-uuid
47 read-luks-partition-uuid
48
49 bind-mount
50
51 mount-flags->bit-mask
52 check-file-system
53 mount-file-system))
54
55 ;;; Commentary:
56 ;;;
57 ;;; This modules provides tools to deal with disk partitions, and to mount and
58 ;;; check file systems.
59 ;;;
60 ;;; Code:
61
62 (define (bind-mount source target)
63 "Bind-mount SOURCE at TARGET."
64 (mount source target "" MS_BIND))
65
66 (define (seek* fd/port offset whence)
67 "Like 'seek' but return -1 instead of throwing to 'system-error' upon
68 EINVAL. This makes it easier to catch cases like OFFSET being too large for
69 FD/PORT."
70 (catch 'system-error
71 (lambda ()
72 (seek fd/port offset whence))
73 (lambda args
74 (if (= EINVAL (system-error-errno args))
75 -1
76 (apply throw args)))))
77
78 (define (read-superblock device offset size magic?)
79 "Read a superblock of SIZE from OFFSET and DEVICE. Return the raw
80 superblock on success, and #f if no valid superblock was found. MAGIC?
81 takes a bytevector and returns #t when it's a valid superblock."
82 (call-with-input-file device
83 (lambda (port)
84 (and (= offset (seek* port offset SEEK_SET))
85 (let ((block (make-bytevector size)))
86 (match (get-bytevector-n! port block 0 (bytevector-length block))
87 ((? eof-object?)
88 #f)
89 ((? number? len)
90 (and (= len (bytevector-length block))
91 (and (magic? block)
92 block)))))))))
93
94 (define null-terminated-latin1->string
95 (cut latin1->string <> zero?))
96
97 \f
98 ;;;
99 ;;; Ext2 file systems.
100 ;;;
101
102 ;; <http://www.nongnu.org/ext2-doc/ext2.html#DEF-SUPERBLOCK>.
103 ;; TODO: Use "packed structs" from Guile-OpenGL or similar.
104
105 (define-syntax %ext2-endianness
106 ;; Endianness of ext2 file systems.
107 (identifier-syntax (endianness little)))
108
109 (define (ext2-superblock? sblock)
110 "Return #t when SBLOCK is an ext2 superblock."
111 (let ((magic (bytevector-u16-ref sblock 56 %ext2-endianness)))
112 (= magic #xef53)))
113
114 (define (read-ext2-superblock device)
115 "Return the raw contents of DEVICE's ext2 superblock as a bytevector, or #f
116 if DEVICE does not contain an ext2 file system."
117 (read-superblock device 1024 264 ext2-superblock?))
118
119 (define (ext2-superblock-uuid sblock)
120 "Return the UUID of ext2 superblock SBLOCK as a 16-byte bytevector."
121 (sub-bytevector sblock 104 16))
122
123 (define (ext2-superblock-volume-name sblock)
124 "Return the volume name of SBLOCK as a string of at most 16 characters, or
125 #f if SBLOCK has no volume name."
126 (null-terminated-latin1->string (sub-bytevector sblock 120 16)))
127
128 (define (check-ext2-file-system device)
129 "Return the health of an ext2 file system on DEVICE."
130 (match (status:exit-val
131 (system* "e2fsck" "-v" "-p" "-C" "0" device))
132 (0 'pass)
133 (1 'errors-corrected)
134 (2 'reboot-required)
135 (_ 'fatal-error)))
136
137 \f
138 ;;;
139 ;;; Btrfs file systems.
140 ;;;
141
142 ;; <https://btrfs.wiki.kernel.org/index.php/On-disk_Format#Superblock>.
143
144 (define-syntax %btrfs-endianness
145 ;; Endianness of btrfs file systems.
146 (identifier-syntax (endianness little)))
147
148 (define (btrfs-superblock? sblock)
149 "Return #t when SBLOCK is a btrfs superblock."
150 (bytevector=? (sub-bytevector sblock 64 8)
151 (string->utf8 "_BHRfS_M")))
152
153 (define (read-btrfs-superblock device)
154 "Return the raw contents of DEVICE's btrfs superblock as a bytevector, or #f
155 if DEVICE does not contain a btrfs file system."
156 (read-superblock device 65536 4096 btrfs-superblock?))
157
158 (define (btrfs-superblock-uuid sblock)
159 "Return the UUID of a btrfs superblock SBLOCK as a 16-byte bytevector."
160 (sub-bytevector sblock 32 16))
161
162 (define (btrfs-superblock-volume-name sblock)
163 "Return the volume name of SBLOCK as a string of at most 256 characters, or
164 #f if SBLOCK has no volume name."
165 (null-terminated-latin1->string (sub-bytevector sblock 299 256)))
166
167 (define (check-btrfs-file-system device)
168 "Return the health of a btrfs file system on DEVICE."
169 (match (status:exit-val
170 (system* "btrfs" "device" "scan"))
171 (0 'pass)
172 (_ 'fatal-error)))
173
174 \f
175 ;;;
176 ;;; FAT32 file systems.
177 ;;;
178
179 ;; <http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-107.pdf>.
180
181 (define (fat32-superblock? sblock)
182 "Return #t when SBLOCK is a fat32 superblock."
183 (bytevector=? (sub-bytevector sblock 82 8)
184 (string->utf8 "FAT32 ")))
185
186 (define (read-fat32-superblock device)
187 "Return the raw contents of DEVICE's fat32 superblock as a bytevector, or
188 #f if DEVICE does not contain a fat32 file system."
189 (read-superblock device 0 90 fat32-superblock?))
190
191 (define (fat32-superblock-uuid sblock)
192 "Return the Volume ID of a fat superblock SBLOCK as a 4-byte bytevector."
193 (sub-bytevector sblock 67 4))
194
195 (define (fat32-superblock-volume-name sblock)
196 "Return the volume name of SBLOCK as a string of at most 11 characters, or
197 #f if SBLOCK has no volume name. The volume name is a latin1 string.
198 Trailing spaces are trimmed."
199 (string-trim-right (latin1->string (sub-bytevector sblock 71 11) (lambda (c) #f)) #\space))
200
201 (define (check-fat-file-system device)
202 "Return the health of a fat file system on DEVICE."
203 (match (status:exit-val
204 (system* "fsck.vfat" "-v" "-a" device))
205 (0 'pass)
206 (1 'errors-corrected)
207 (_ 'fatal-error)))
208
209 \f
210 ;;;
211 ;;; FAT16 file systems.
212 ;;;
213
214 (define (fat16-superblock? sblock)
215 "Return #t when SBLOCK is a fat16 boot record."
216 (bytevector=? (sub-bytevector sblock 54 8)
217 (string->utf8 "FAT16 ")))
218
219 (define (read-fat16-superblock device)
220 "Return the raw contents of DEVICE's fat16 superblock as a bytevector, or
221 #f if DEVICE does not contain a fat16 file system."
222 (read-superblock device 0 62 fat16-superblock?))
223
224 (define (fat16-superblock-uuid sblock)
225 "Return the Volume ID of a fat superblock SBLOCK as a 4-byte bytevector."
226 (sub-bytevector sblock 39 4))
227
228 (define (fat16-superblock-volume-name sblock)
229 "Return the volume name of SBLOCK as a string of at most 11 characters, or
230 #f if SBLOCK has no volume name. The volume name is a latin1 string.
231 Trailing spaces are trimmed."
232 (string-trim-right (latin1->string (sub-bytevector sblock 43 11)
233 (lambda (c) #f))
234 #\space))
235
236 \f
237 ;;;
238 ;;; ISO9660 file systems.
239 ;;;
240
241 ;; <http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-119.pdf>.
242
243 (define (iso9660-superblock? sblock)
244 "Return #t when SBLOCK is an iso9660 volume descriptor."
245 (bytevector=? (sub-bytevector sblock 1 6)
246 ;; Note: "\x01" is the volume descriptor format version
247 (string->utf8 "CD001\x01")))
248
249 (define (read-iso9660-primary-volume-descriptor device offset)
250 "Find and read the first primary volume descriptor, starting at OFFSET.
251 Return #f if not found."
252 (let* ((sblock (read-superblock device offset 2048 iso9660-superblock?))
253 (type-code (if sblock
254 (bytevector-u8-ref sblock 0)
255 (error (format #f
256 "Could not read ISO9660 primary
257 volume descriptor from ~s"
258 device)))))
259 (match type-code
260 (255 #f) ; Volume Descriptor Set Terminator.
261 (1 sblock) ; Primary Volume Descriptor
262 (_ (read-iso9660-primary-volume-descriptor device (+ offset 2048))))))
263
264 (define (read-iso9660-superblock device)
265 "Return the raw contents of DEVICE's iso9660 primary volume descriptor
266 as a bytevector, or #f if DEVICE does not contain an iso9660 file system."
267 ;; Start reading at sector 16.
268 ;; Since we are not sure that the device contains an ISO9660 file system,
269 ;; we have to find that out first.
270 (if (read-superblock device (* 2048 16) 2048 iso9660-superblock?)
271 (read-iso9660-primary-volume-descriptor device (* 2048 16))
272 #f)) ; Device does not contain an iso9660 file system.
273
274 (define (iso9660-superblock-uuid sblock)
275 "Return the modification time of an iso9660 primary volume descriptor
276 SBLOCK as a bytevector. If that's not set, returns the creation time."
277 ;; Drops GMT offset for compatibility with Grub, blkid and /dev/disk/by-uuid.
278 ;; Compare Grub: "2014-12-02-19-30-23-00".
279 ;; Compare blkid result: "2014-12-02-19-30-23-00".
280 ;; Compare /dev/disk/by-uuid entry: "2014-12-02-19-30-23-00".
281 (let* ((creation-time (sub-bytevector sblock 813 17))
282 (modification-time (sub-bytevector sblock 830 17))
283 (unset-time (make-bytevector 17 0))
284 (time (if (bytevector=? unset-time modification-time)
285 creation-time
286 modification-time)))
287 (sub-bytevector time 0 16))) ; strips GMT offset.
288
289 (define (iso9660-superblock-volume-name sblock)
290 "Return the volume name of SBLOCK as a string. The volume name is an ASCII
291 string. Trailing spaces are trimmed."
292 ;; Note: Valid characters are of the set "[0-9][A-Z]_" (ECMA-119 Appendix A)
293 (string-trim-right (latin1->string (sub-bytevector sblock 40 32)
294 (lambda (c) #f)) #\space))
295
296 \f
297 ;;;
298 ;;; LUKS encrypted devices.
299 ;;;
300
301 ;; The LUKS header format is described in "LUKS On-Disk Format Specification":
302 ;; <https://gitlab.com/cryptsetup/cryptsetup/wikis/Specification>. We follow
303 ;; version 1.2.1 of this document.
304
305 (define-syntax %luks-endianness
306 ;; Endianness of LUKS headers.
307 (identifier-syntax (endianness big)))
308
309 (define (luks-superblock? sblock)
310 "Return #t when SBLOCK is a luks superblock."
311 (define %luks-magic
312 ;; The 'LUKS_MAGIC' constant.
313 (u8-list->bytevector (append (map char->integer (string->list "LUKS"))
314 (list #xba #xbe))))
315 (let ((magic (sub-bytevector sblock 0 6))
316 (version (bytevector-u16-ref sblock 6 %luks-endianness)))
317 (and (bytevector=? magic %luks-magic)
318 (= version 1))))
319
320 (define (read-luks-header file)
321 "Read a LUKS header from FILE. Return the raw header on success, and #f if
322 not valid header was found."
323 ;; Size in bytes of the LUKS header, including key slots.
324 (read-superblock file 0 592 luks-superblock?))
325
326 (define (luks-header-uuid header)
327 "Return the LUKS UUID from HEADER, as a 16-byte bytevector."
328 ;; 40 bytes are reserved for the UUID, but in practice, it contains the 36
329 ;; bytes of its ASCII representation.
330 (let ((uuid (sub-bytevector header 168 36)))
331 (string->uuid (utf8->string uuid))))
332
333 \f
334 ;;;
335 ;;; Partition lookup.
336 ;;;
337
338 (define (disk-partitions)
339 "Return the list of device names corresponding to valid disk partitions."
340 (define (partition? name major minor)
341 ;; grub-mkrescue does some funny things for EFI support which
342 ;; makes it a lot more difficult than one would expect to support
343 ;; booting an ISO-9660 image from an USB flash drive.
344 ;; For example there's a buggy (too small) hidden partition in it
345 ;; which Linux mounts and then proceeds to fail while trying to
346 ;; fall off the edge.
347 ;; In any case, partition tables are supposed to be optional so
348 ;; here we allow checking entire disks for file systems, too.
349 (> major 2)) ;ignore RAM disks and floppy disks
350
351 (call-with-input-file "/proc/partitions"
352 (lambda (port)
353 ;; Skip the two header lines.
354 (read-line port)
355 (read-line port)
356
357 ;; Read each subsequent line, and extract the last space-separated
358 ;; field.
359 (let loop ((parts '()))
360 (let ((line (read-line port)))
361 (if (eof-object? line)
362 (reverse parts)
363 (match (string-tokenize line)
364 (((= string->number major) (= string->number minor)
365 blocks name)
366 (if (partition? name major minor)
367 (loop (cons name parts))
368 (loop parts))))))))))
369
370 (define (ENOENT-safe proc)
371 "Wrap the one-argument PROC such that ENOENT errors are caught and lead to a
372 warning and #f as the result."
373 (lambda (device)
374 (catch 'system-error
375 (lambda ()
376 (proc device))
377 (lambda args
378 ;; When running on the hand-made /dev,
379 ;; 'disk-partitions' could return partitions for which
380 ;; we have no /dev node. Handle that gracefully.
381 (let ((errno (system-error-errno args)))
382 (cond ((= ENOENT errno)
383 (format (current-error-port)
384 "warning: device '~a' not found~%" device)
385 #f)
386 ((= ENOMEDIUM errno) ;for removable media
387 #f)
388 ((= EIO errno) ;unreadable hardware like audio CDs
389 (format (current-error-port)
390 "warning: failed to read from device '~a'~%" device)
391 #f)
392 (else
393 (apply throw args))))))))
394
395 (define (partition-field-reader read field)
396 "Return a procedure that takes a device and returns the value of a FIELD in
397 the partition superblock or #f."
398 (let ((read (ENOENT-safe read)))
399 (lambda (device)
400 (let ((sblock (read device)))
401 (and sblock
402 (field sblock))))))
403
404 (define (read-partition-field device partition-field-readers)
405 "Returns the value of a FIELD in the partition superblock of DEVICE or #f. It
406 takes a list of PARTITION-FIELD-READERS and returns the result of the first
407 partition field reader that returned a value."
408 (match (filter-map (cut apply <> (list device)) partition-field-readers)
409 ((field . _) field)
410 (_ #f)))
411
412 (define %partition-label-readers
413 (list (partition-field-reader read-iso9660-superblock
414 iso9660-superblock-volume-name)
415 (partition-field-reader read-ext2-superblock
416 ext2-superblock-volume-name)
417 (partition-field-reader read-btrfs-superblock
418 btrfs-superblock-volume-name)
419 (partition-field-reader read-fat32-superblock
420 fat32-superblock-volume-name)
421 (partition-field-reader read-fat16-superblock
422 fat16-superblock-volume-name)))
423
424 (define %partition-uuid-readers
425 (list (partition-field-reader read-iso9660-superblock
426 iso9660-superblock-uuid)
427 (partition-field-reader read-ext2-superblock
428 ext2-superblock-uuid)
429 (partition-field-reader read-btrfs-superblock
430 btrfs-superblock-uuid)
431 (partition-field-reader read-fat32-superblock
432 fat32-superblock-uuid)
433 (partition-field-reader read-fat16-superblock
434 fat16-superblock-uuid)))
435
436 (define read-partition-label
437 (cut read-partition-field <> %partition-label-readers))
438
439 (define read-partition-uuid
440 (cut read-partition-field <> %partition-uuid-readers))
441
442 (define luks-partition-field-reader
443 (partition-field-reader read-luks-header luks-header-uuid))
444
445 (define read-luks-partition-uuid
446 (cut read-partition-field <> (list luks-partition-field-reader)))
447
448 (define (partition-predicate reader =)
449 "Return a predicate that returns true if the FIELD of partition header that
450 was READ is = to the given value."
451 (lambda (expected)
452 (lambda (device)
453 (let ((actual (reader device)))
454 (and actual
455 (= actual expected))))))
456
457 (define partition-label-predicate
458 (partition-predicate read-partition-label string=?))
459
460 (define partition-uuid-predicate
461 (partition-predicate read-partition-uuid uuid=?))
462
463 (define luks-partition-uuid-predicate
464 (partition-predicate luks-partition-field-reader uuid=?))
465
466 (define (find-partition predicate)
467 "Return the first partition found that matches PREDICATE, or #f if none
468 were found."
469 (lambda (expected)
470 (find (predicate expected)
471 (map (cut string-append "/dev/" <>)
472 (disk-partitions)))))
473
474 (define find-partition-by-label
475 (find-partition partition-label-predicate))
476
477 (define find-partition-by-uuid
478 (find-partition partition-uuid-predicate))
479
480 (define find-partition-by-luks-uuid
481 (find-partition luks-partition-uuid-predicate))
482
483 \f
484 (define (canonicalize-device-spec spec)
485 "Return the device name corresponding to SPEC, which can be a <uuid>, a
486 <file-system-label>, or a string (typically a /dev file name)."
487 (define max-trials
488 ;; Number of times we retry partition label resolution, 1 second per
489 ;; trial. Note: somebody reported a delay of 16 seconds (!) before their
490 ;; USB key would be detected by the kernel, so we must wait for at least
491 ;; this long.
492 20)
493
494 (define (resolve find-partition spec fmt)
495 (let loop ((count 0))
496 (let ((device (find-partition spec)))
497 (or device
498 ;; Some devices take a bit of time to appear, most notably USB
499 ;; storage devices. Thus, wait for the device to appear.
500 (if (> count max-trials)
501 (error "failed to resolve partition" (fmt spec))
502 (begin
503 (format #t "waiting for partition '~a' to appear...~%"
504 (fmt spec))
505 (sleep 1)
506 (loop (+ 1 count))))))))
507
508 (match spec
509 ((? string?)
510 ;; Nothing to do, but wait until SPEC shows up.
511 (resolve identity spec identity))
512 ((? file-system-label?)
513 ;; Resolve the label.
514 (resolve find-partition-by-label
515 (file-system-label->string spec)
516 identity))
517 ((? uuid?)
518 (resolve find-partition-by-uuid
519 (uuid-bytevector spec)
520 uuid->string))))
521
522 (define (check-file-system device type)
523 "Run a file system check of TYPE on DEVICE."
524 (define check-procedure
525 (cond
526 ((string-prefix? "ext" type) check-ext2-file-system)
527 ((string-prefix? "btrfs" type) check-btrfs-file-system)
528 ((string-suffix? "fat" type) check-fat-file-system)
529 (else #f)))
530
531 (if check-procedure
532 (match (check-procedure device)
533 ('pass
534 #t)
535 ('errors-corrected
536 (format (current-error-port)
537 "File system check corrected errors on ~a; continuing~%"
538 device))
539 ('reboot-required
540 (format (current-error-port)
541 "File system check corrected errors on ~a; rebooting~%"
542 device)
543 (sleep 3)
544 (reboot))
545 ('fatal-error
546 (format (current-error-port) "File system check on ~a failed~%"
547 device)
548
549 ;; Spawn a REPL only if someone would be able to interact with it.
550 (when (isatty? (current-input-port))
551 (format (current-error-port) "Spawning Bourne-like REPL.~%")
552
553 ;; 'current-output-port' is typically connected to /dev/klog (in
554 ;; PID 1), but here we want to make sure we talk directly to the
555 ;; user.
556 (with-output-to-file "/dev/console"
557 (lambda ()
558 (start-repl %bournish-language))))))
559 (format (current-error-port)
560 "No file system check procedure for ~a; skipping~%"
561 device)))
562
563 (define (mount-flags->bit-mask flags)
564 "Return the number suitable for the 'flags' argument of 'mount' that
565 corresponds to the symbols listed in FLAGS."
566 (let loop ((flags flags))
567 (match flags
568 (('read-only rest ...)
569 (logior MS_RDONLY (loop rest)))
570 (('bind-mount rest ...)
571 (logior MS_BIND (loop rest)))
572 (('no-suid rest ...)
573 (logior MS_NOSUID (loop rest)))
574 (('no-dev rest ...)
575 (logior MS_NODEV (loop rest)))
576 (('no-exec rest ...)
577 (logior MS_NOEXEC (loop rest)))
578 (('no-atime rest ...)
579 (logior MS_NOATIME (loop rest)))
580 (()
581 0))))
582
583 (define* (mount-file-system fs #:key (root "/root"))
584 "Mount the file system described by FS, a <file-system> object, under ROOT.
585
586 DEVICE, MOUNT-POINT, and TYPE must be strings; OPTIONS can be a string or #f;
587 FLAGS must be a list of symbols. CHECK? is a Boolean indicating whether to
588 run a file system check."
589
590 (define (mount-nfs source mount-point type flags options)
591 (let* ((idx (string-rindex source #\:))
592 (host-part (string-take source idx))
593 ;; Strip [] from around host if present
594 (host (match (string-split host-part (string->char-set "[]"))
595 (("" h "") h)
596 ((h) h)))
597 (aa (match (getaddrinfo host "nfs") ((x . _) x)))
598 (sa (addrinfo:addr aa))
599 (inet-addr (inet-ntop (sockaddr:fam sa)
600 (sockaddr:addr sa))))
601
602 ;; Mounting an NFS file system requires passing the address
603 ;; of the server in the addr= option
604 (mount source mount-point type flags
605 (string-append "addr="
606 inet-addr
607 (if options
608 (string-append "," options)
609 "")))))
610 (let ((type (file-system-type fs))
611 (options (file-system-options fs))
612 (source (canonicalize-device-spec (file-system-device fs)))
613 (mount-point (string-append root "/"
614 (file-system-mount-point fs)))
615 (flags (mount-flags->bit-mask (file-system-flags fs))))
616 (when (file-system-check? fs)
617 (check-file-system source type))
618
619 ;; Create the mount point. Most of the time this is a directory, but
620 ;; in the case of a bind mount, a regular file or socket may be needed.
621 (if (and (= MS_BIND (logand flags MS_BIND))
622 (not (file-is-directory? source)))
623 (unless (file-exists? mount-point)
624 (mkdir-p (dirname mount-point))
625 (call-with-output-file mount-point (const #t)))
626 (mkdir-p mount-point))
627
628 (cond
629 ((string-prefix? "nfs" type)
630 (mount-nfs source mount-point type flags options))
631 (else
632 (mount source mount-point type flags options)))
633
634 ;; For read-only bind mounts, an extra remount is needed, as per
635 ;; <http://lwn.net/Articles/281157/>, which still applies to Linux 4.0.
636 (when (and (= MS_BIND (logand flags MS_BIND))
637 (= MS_RDONLY (logand flags MS_RDONLY)))
638 (let ((flags (logior MS_BIND MS_REMOUNT MS_RDONLY)))
639 (mount source mount-point type flags #f)))))
640
641 ;;; file-systems.scm ends here