bug-guix
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#25573: Adding btrfs support may break reconfigured system


From: Ludovic Courtès
Subject: bug#25573: Adding btrfs support may break reconfigured system
Date: Mon, 30 Jan 2017 10:41:49 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

Hi,

Alex Kost <address@hidden> skribis:

> Hello, recently I found that "guix system" makes a "broken" system for
> me.  When I boot a freshly created system, I get something like this:
>
>   In procedure <...> at ./gnu/build/file-systems.scm:282:4 (device)
>   In procedure fport_seek: Invalid argument
>
> and I'm thrown at the Guile promt.

I think this is due to ‘read-superblock’ trying to seek beyond the end
of one of the devices that’s on your machine.

Could you try the attached patch and see if it solves the problem?

Thanks for reporting it!

Ludo’.

diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm
index 6e5c6aaf1..f8ab95370 100644
--- a/gnu/build/file-systems.scm
+++ b/gnu/build/file-systems.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <address@hidden>
+;;; Copyright © 2014, 2015, 2016, 2017 Ludovic Courtès <address@hidden>
 ;;; Copyright © 2016, 2017 David Craven <address@hidden>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -72,14 +72,25 @@
   "Bind-mount SOURCE at TARGET."
   (mount source target "" MS_BIND))
 
+(define (seek* fd/port offset whence)
+  "Like 'seek' but return -1 instead of throwing to 'system-error' upon
+EINVAL.  This makes it easier to catch cases like OFFSET being too large for
+FD/PORT."
+  (catch 'system-error
+    (lambda ()
+      (seek fd/port offset whence))
+    (lambda args
+      (if (= EINVAL (system-error-errno args))
+          -1
+          (apply throw args)))))
+
 (define (read-superblock device offset size magic?)
   "Read a superblock of SIZE from OFFSET and DEVICE.  Return the raw
 superblock on success, and #f if no valid superblock was found.  MAGIC?
 takes a bytevector and returns #t when it's a valid superblock."
   (call-with-input-file device
     (lambda (port)
-      (seek port offset SEEK_SET)
-
+      (and (= offset (seek* port offset SEEK_SET))
            (let ((block (make-bytevector size)))
              (match (get-bytevector-n! port block 0 (bytevector-length block))
                ((? eof-object?)
@@ -87,7 +98,7 @@ takes a bytevector and returns #t when it's a valid 
superblock."
                ((? number? len)
                 (and (= len (bytevector-length block))
                      (and (magic? block)
-                     block))))))))
+                          block)))))))))
 
 (define (sub-bytevector bv start size)
   "Return a copy of the SIZE bytes of BV starting from offset START."

reply via email to

[Prev in Thread] Current Thread [Next in Thread]