diff options
| author | Richard Sent <richard@freakingpenguin.com> | 2024-06-01 19:26:18 -0400 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2024-06-04 12:08:34 +0200 |
| commit | 3e87b207ce96679e2f289a5522a248d38c4f3962 (patch) | |
| tree | 8901c5cf6509e934a6e3a1bc5ef1b6dc389e0307 /gnu | |
| parent | 9d6c4f5160c872bf8813d9e75f80a9f0157bf769 (diff) | |
file-systems: Add support for mounting CIFS file systems
* gnu/build/file-systems (canonicalize-device-name): Do not attempt to resolve
CIFS formatted device specifications.
(mount-file-systems): Add mount-cifs nested function.
* gnu/machine/ssh.scm (machine-check-file-system-availability): Skip checking
for CIFS availability, similar to NFS.
* guix/scripts/system.scm (check-file-system-availability): Likewise.
Change-Id: I182e290eba64bbe5d1332815eb93bb68c01e0c3c
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'gnu')
| -rw-r--r-- | gnu/build/file-systems.scm | 45 | ||||
| -rw-r--r-- | gnu/machine/ssh.scm | 3 |
2 files changed, 45 insertions, 3 deletions
diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index e47ac39ab0e..ae29b36c4e4 100644 --- a/gnu/build/file-systems.scm +++ b/gnu/build/file-systems.scm | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com> | 8 | ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com> |
| 9 | ;;; Copyright © 2022 Oleg Pykhalov <go.wigust@gmail.com> | 9 | ;;; Copyright © 2022 Oleg Pykhalov <go.wigust@gmail.com> |
| 10 | ;;; Copyright © 2024 Nicolas Graves <ngraves@ngraves.fr> | 10 | ;;; Copyright © 2024 Nicolas Graves <ngraves@ngraves.fr> |
| 11 | ;;; Copyright © 2024 Richard Sent <richard@freakingpenguin.com> | ||
| 11 | ;;; | 12 | ;;; |
| 12 | ;;; This file is part of GNU Guix. | 13 | ;;; This file is part of GNU Guix. |
| 13 | ;;; | 14 | ;;; |
| @@ -37,6 +38,7 @@ | |||
| 37 | #:use-module (rnrs bytevectors) | 38 | #:use-module (rnrs bytevectors) |
| 38 | #:use-module (ice-9 match) | 39 | #:use-module (ice-9 match) |
| 39 | #:use-module (ice-9 rdelim) | 40 | #:use-module (ice-9 rdelim) |
| 41 | #:use-module (ice-9 regex) | ||
| 40 | #:use-module (system foreign) | 42 | #:use-module (system foreign) |
| 41 | #:autoload (system repl repl) (start-repl) | 43 | #:autoload (system repl repl) (start-repl) |
| 42 | #:use-module (srfi srfi-1) | 44 | #:use-module (srfi srfi-1) |
| @@ -1047,8 +1049,11 @@ file name or an nfs-root containing ':/')." | |||
| 1047 | 1049 | ||
| 1048 | (match spec | 1050 | (match spec |
| 1049 | ((? string?) | 1051 | ((? string?) |
| 1050 | (if (or (string-contains spec ":/") (string=? spec "none")) | 1052 | (if (or (string-contains spec ":/") ;nfs |
| 1051 | spec ; do not resolve NFS / tmpfs devices | 1053 | (and (>= (string-length spec) 2) |
| 1054 | (equal? (string-take spec 2) "//")) ;cifs | ||
| 1055 | (string=? spec "none")) | ||
| 1056 | spec ; do not resolve NFS / CIFS / tmpfs devices | ||
| 1052 | ;; Nothing to do, but wait until SPEC shows up. | 1057 | ;; Nothing to do, but wait until SPEC shows up. |
| 1053 | (resolve identity spec identity))) | 1058 | (resolve identity spec identity))) |
| 1054 | ((? file-system-label?) | 1059 | ((? file-system-label?) |
| @@ -1181,6 +1186,40 @@ corresponds to the symbols listed in FLAGS." | |||
| 1181 | (string-append "," options) | 1186 | (string-append "," options) |
| 1182 | ""))))) | 1187 | ""))))) |
| 1183 | 1188 | ||
| 1189 | (define (mount-cifs source mount-point type flags options) | ||
| 1190 | ;; Source is of form "//<server-ip-or-host>/<service>" | ||
| 1191 | (let* ((regex-match (string-match "//([^/]+)/(.+)" source)) | ||
| 1192 | (server (match:substring regex-match 1)) | ||
| 1193 | (share (match:substring regex-match 2)) | ||
| 1194 | ;; Match ",guest,", ",guest$", "^guest,", or "^guest$," not | ||
| 1195 | ;; e.g. user=foo,pass=notaguest | ||
| 1196 | (guest? (string-match "(^|,)(guest)($|,)" options)) | ||
| 1197 | ;; Perform DNS resolution now instead of attempting kernel dns | ||
| 1198 | ;; resolver upcalling. /sbin/request-key does not exist and the | ||
| 1199 | ;; kernel hardcodes the path. | ||
| 1200 | ;; | ||
| 1201 | ;; (getaddrinfo) doesn't support cifs service, so omit it. | ||
| 1202 | (inet-addr (host-to-ip server))) | ||
| 1203 | (mount source mount-point type flags | ||
| 1204 | (string-append "ip=" | ||
| 1205 | inet-addr | ||
| 1206 | ;; As of Linux af1a3d2ba9 (v5.11) unc is ignored | ||
| 1207 | ;; and source is parsed by the kernel | ||
| 1208 | ;; directly. Pass it for compatibility. | ||
| 1209 | ",unc=" | ||
| 1210 | ;; Match format of mount.cifs's mount syscall. | ||
| 1211 | "\\\\" server "\\" share | ||
| 1212 | (if guest? | ||
| 1213 | ",user=,pass=" | ||
| 1214 | "") | ||
| 1215 | (if options | ||
| 1216 | ;; No need to delete "guest" from options. | ||
| 1217 | ;; linux/fs/smb/client/fs_context.c explicitly | ||
| 1218 | ;; ignores it. Also, avoiding excess commas | ||
| 1219 | ;; when deleting is a pain. | ||
| 1220 | (string-append "," options) | ||
| 1221 | ""))))) | ||
| 1222 | |||
| 1184 | (let* ((type (file-system-type fs)) | 1223 | (let* ((type (file-system-type fs)) |
| 1185 | (source (canonicalize-device-spec (file-system-device fs))) | 1224 | (source (canonicalize-device-spec (file-system-device fs))) |
| 1186 | (target (string-append root "/" | 1225 | (target (string-append root "/" |
| @@ -1215,6 +1254,8 @@ corresponds to the symbols listed in FLAGS." | |||
| 1215 | (cond | 1254 | (cond |
| 1216 | ((string-prefix? "nfs" type) | 1255 | ((string-prefix? "nfs" type) |
| 1217 | (mount-nfs source target type flags options)) | 1256 | (mount-nfs source target type flags options)) |
| 1257 | ((string-prefix? "cifs" type) | ||
| 1258 | (mount-cifs source target type flags options)) | ||
| 1218 | ((memq 'shared (file-system-flags fs)) | 1259 | ((memq 'shared (file-system-flags fs)) |
| 1219 | (mount source target type flags options) | 1260 | (mount source target type flags options) |
| 1220 | (mount "none" target #f MS_SHARED)) | 1261 | (mount "none" target #f MS_SHARED)) |
diff --git a/gnu/machine/ssh.scm b/gnu/machine/ssh.scm index b47ce7c2252..0be9ebbc0d7 100644 --- a/gnu/machine/ssh.scm +++ b/gnu/machine/ssh.scm | |||
| @@ -222,7 +222,8 @@ exist on the machine." | |||
| 222 | (not (member (file-system-type fs) | 222 | (not (member (file-system-type fs) |
| 223 | %pseudo-file-system-types)) | 223 | %pseudo-file-system-types)) |
| 224 | ;; Don't try to validate network file systems. | 224 | ;; Don't try to validate network file systems. |
| 225 | (not (string-prefix? "nfs" (file-system-type fs))) | 225 | (not (or (string-prefix? "nfs" (file-system-type fs)) |
| 226 | (string-prefix? "cifs" (file-system-type fs)))) | ||
| 226 | (not (memq 'bind-mount (file-system-flags fs))))) | 227 | (not (memq 'bind-mount (file-system-flags fs))))) |
| 227 | (operating-system-file-systems (machine-operating-system machine)))) | 228 | (operating-system-file-systems (machine-operating-system machine)))) |
| 228 | 229 | ||
