From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Thompson Subject: [PATCH] build: file-systems: Allow for bind mounting regular files. Date: Sat, 01 Aug 2015 15:17:59 -0400 Message-ID: <87a8uarf6g.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60824) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLcID-0000er-Ol for guix-devel@gnu.org; Sat, 01 Aug 2015 15:18:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZLcIC-0001Bz-Md for guix-devel@gnu.org; Sat, 01 Aug 2015 15:18:01 -0400 Received: from mail.fsf.org ([208.118.235.13]:47963) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLcIC-0001Bv-IW for guix-devel@gnu.org; Sat, 01 Aug 2015 15:18:00 -0400 Received: from 209-6-40-86.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.40.86]:45834 helo=izanagi) by mail.fsf.org with esmtpsa (TLS-1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1ZLcIC-00089V-36 for guix-devel@gnu.org; Sat, 01 Aug 2015 15:18:00 -0400 List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org --=-=-= Content-Type: text/plain As I was working on my container implementation I noticed that 'mount-file-system' doesn't support bind mounting regular files because it assumes that all mount points are directories. This patch fixes that. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-build-file-systems-Allow-for-bind-mounting-regular-f.patch >From f94fec6cde3826f20c0d69a45c2aa1928c1d0a78 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 1 Aug 2015 13:43:33 -0400 Subject: [PATCH] build: file-systems: Allow for bind mounting regular files. * gnu/build/file-systems.scm (regular-file?): New procedure. (mount-file-system): Create a regular file instead of a directory when bind mounting a regular file. --- gnu/build/file-systems.scm | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index c58d23c..f0d6f70 100644 --- a/gnu/build/file-systems.scm +++ b/gnu/build/file-systems.scm @@ -305,6 +305,10 @@ the following: fsck code device) (start-repl))))) +(define (regular-file? file-name) + "Return #t if FILE-NAME is a regular file." + (eq? (stat:type (stat file-name)) 'regular)) + (define (mount-flags->bit-mask flags) "Return the number suitable for the 'flags' argument of 'mount' that corresponds to the symbols listed in FLAGS." @@ -339,7 +343,16 @@ run a file system check." (flags (mount-flags->bit-mask flags))) (when check? (check-file-system source type)) - (mkdir-p mount-point) + + ;; Create the mount point. Most of the time this is a directory, but + ;; in the case of a bind mount, a regular file may be needed. + (if (and (= MS_BIND (logand flags MS_BIND)) + (regular-file? source)) + (begin + (mkdir-p (dirname mount-point)) + (call-with-output-file mount-point (const #t))) + (mkdir-p mount-point)) + (mount source mount-point type flags options) ;; For read-only bind mounts, an extra remount is needed, as per -- 2.4.3 --=-=-= Content-Type: text/plain -- David Thompson GPG Key: 0FF1D807 --=-=-=--