utils: Add 'invoke/quiet'.
[jackhill/guix/guix.git] / gnu / build / bootloader.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
3 ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
4 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
11 ;;;
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
16 ;;;
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20 (define-module (gnu build bootloader)
21 #:use-module (ice-9 binary-ports)
22 #:export (write-file-on-device))
23
24 \f
25 ;;;
26 ;;; Writing utils.
27 ;;;
28
29 (define (write-file-on-device file size device offset)
30 "Write SIZE bytes from FILE to DEVICE starting at OFFSET."
31 (call-with-input-file file
32 (lambda (input)
33 (let ((bv (get-bytevector-n input size)))
34 (call-with-output-file device
35 (lambda (output)
36 (seek output offset SEEK_SET)
37 (put-bytevector output bv))
38 #:binary #t)))))