From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMZK1-0005rK-1k for guix-patches@gnu.org; Wed, 06 Dec 2017 08:01:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMZJw-0005oi-7g for guix-patches@gnu.org; Wed, 06 Dec 2017 08:01:09 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:39942) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eMZJw-0005oZ-4w for guix-patches@gnu.org; Wed, 06 Dec 2017 08:01:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eMZJv-0001bx-S1 for guix-patches@gnu.org; Wed, 06 Dec 2017 08:01:03 -0500 Subject: [bug#29409] [PATCH 4/4] bootloader: Factorize write-file-on-device. Resent-Message-ID: From: m.othacehe@gmail.com Date: Wed, 6 Dec 2017 13:59:53 +0100 Message-Id: <1512565193-3234-5-git-send-email-m.othacehe@gmail.com> In-Reply-To: <1512565193-3234-1-git-send-email-m.othacehe@gmail.com> References: <1512565193-3234-1-git-send-email-m.othacehe@gmail.com> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 29409@debbugs.gnu.org From: Mathieu Othacehe * gnu/bootloader/extlinux.scm (install-extlinux): Factorize bootloader writing in a new procedure ... * gnu/bootloader.scm (write-file-on-device): ... defined and exported here. --- gnu/bootloader.scm | 21 ++++++++++++++++++++- gnu/bootloader/extlinux.scm | 9 ++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/gnu/bootloader.scm b/gnu/bootloader.scm index 736f119..a715ba1 100644 --- a/gnu/bootloader.scm +++ b/gnu/bootloader.scm @@ -22,6 +22,7 @@ #:use-module (guix discovery) #:use-module (guix records) #:use-module (guix ui) + #:use-module (guix gexp) #:use-module (srfi srfi-1) #:export (menu-entry menu-entry? @@ -55,7 +56,8 @@ bootloader-configuration-additional-configuration %bootloaders - lookup-bootloader-by-name)) + lookup-bootloader-by-name + write-file-on-device)) ;;; @@ -163,3 +165,20 @@ (eq? name (bootloader-name bootloader))) (force %bootloaders)) (leave (G_ "~a: no such bootloader~%") name))) + + +;;; +;;; Writing utils. +;;; + +(define write-file-on-device + #~(lambda (file size device offset) + ;; Write SIZE bytes from FILE to DEVICE starting at OFFSET. + (call-with-input-file file + (lambda (input) + (let ((bv (get-bytevector-n input size))) + (call-with-output-file device + (lambda (output) + (seek output offset SEEK_SET) + (put-bytevector output bv)) + #:binary #t)))))) diff --git a/gnu/bootloader/extlinux.scm b/gnu/bootloader/extlinux.scm index 9b6e2c7..304fb98 100644 --- a/gnu/bootloader/extlinux.scm +++ b/gnu/bootloader/extlinux.scm @@ -95,13 +95,8 @@ TIMEOUT ~a~%" (find-files syslinux-dir "\\.c32$")) (unless (and (zero? (system* extlinux "--install" install-dir)) - (call-with-input-file (string-append syslinux-dir "/" #$mbr) - (lambda (input) - (let ((bv (get-bytevector-n input 440))) - (call-with-output-file device - (lambda (output) - (put-bytevector output bv)) - #:binary #t))))) + (#$write-file-on-device + (string-append syslinux-dir "/" #$mbr) 440 device 0)) (error "failed to install SYSLINUX"))))) (define install-extlinux-mbr -- 2.7.4