;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2014, 2016 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (gnu build linux-modules) #:use-module (guix elf) #:use-module (rnrs io ports) #:use-module (rnrs bytevectors) #:use-module (srfi srfi-1) #:use-module (srfi
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '.gitignore')
0 files changed, 0 insertions, 0 deletions
(delete-duplicates (reverse result))) ((head . tail) (let* ((visited? (vhash-assoc head visited)) (deps (if visited? '() (map lookup-module (module-dependencies head)))) (visited (if visited? visited (vhash-cons head #t visited)))) (loop (append deps tail) (append result deps) visited)))))) (define %not-newline (char-set-complement (char-set #\newline))) (define (modules-loaded) "Return the list of names of currently loaded Linux modules." (let* ((contents (call-with-input-file "/proc/modules" get-string-all)) (lines (string-tokenize contents %not-newline))) (match (map string-tokenize lines) (((modules . _) ...) modules)))) (define (module-black-list) "Return the black list of modules that must not be loaded. This black list is specified using 'modprobe.blacklist=MODULE1,MODULE2,...' on the kernel command line; it is honored by libkmod for users that pass 'KMOD_PROBE_APPLY_BLACKLIST', which includes 'modprobe --use-blacklist' and udev." (define parameter "modprobe.blacklist=") (let ((command (call-with-input-file "/proc/cmdline" get-string-all))) (append-map (lambda (arg) (if (string-prefix? parameter arg) (string-tokenize (string-drop arg (string-length parameter)) %not-comma) '())) (string-tokenize command)))) (define (module-loaded? module) "Return #t if MODULE is already loaded. MODULE must be a Linux module name, not a file name." (member module (modules-loaded))) (define* (load-linux-module* file #:key (recursive? #t) (lookup-module dot-ko) (black-list (module-black-list))) "Load Linux module from FILE, the name of a '.ko' file; return true on success, false otherwise. When RECURSIVE? is true, load its dependencies first (à la 'modprobe'.) The actual files containing modules depended on are obtained by calling LOOKUP-MODULE with the module name. Modules whose name appears in BLACK-LIST are not loaded." (define (slurp module) ;; TODO: Use 'finit_module' to reduce memory usage. (call-with-input-file file get-bytevector-all)) (define (black-listed? module) (let ((result (member module black-list))) (when result (format (current-module-debugging-port) "not loading module '~a' because it's black-listed~%" module)) result)) (define (load-dependencies file) (let ((dependencies (module-dependencies file))) (every (cut load-linux-module* <> #:lookup-module lookup-module) (map lookup-module dependencies)))) (and (not (black-listed? (file-name->module-name file))) (or (not recursive?) (load-dependencies file)) (begin (format (current-module-debugging-port) "loading Linux module from '~a'...~%" file) (catch 'system-error (lambda () (load-linux-module (slurp file))) (lambda args ;; If this module was already loaded and we're in modprobe style, ignore ;; the error. (or (and recursive? (= EEXIST (system-error-errno args))) (apply throw args))))))) ;;; linux-modules.scm ends here