From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Q2Mog-0005bx-Sm for mharc-grub-devel@gnu.org; Wed, 23 Mar 2011 08:05:34 -0400 Received: from [140.186.70.92] (port=40981 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q2Mod-0005Zq-Th for grub-devel@gnu.org; Wed, 23 Mar 2011 08:05:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q2Mob-0002zR-Vp for grub-devel@gnu.org; Wed, 23 Mar 2011 08:05:31 -0400 Received: from mail-ey0-f169.google.com ([209.85.215.169]:35705) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q2Mob-0002z0-Nd for grub-devel@gnu.org; Wed, 23 Mar 2011 08:05:29 -0400 Received: by eyh6 with SMTP id 6so2220322eyh.0 for ; Wed, 23 Mar 2011 05:05:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:x-enigmail-version:content-type; bh=wWczJDPOHnMR3AeO73aprzDVYgrVW4hBdON+WeoCY4I=; b=eCyhI/typbErj0K9hofQh739GWXHcwVGGlg7RsXEVx23NUltfltHOXQkbJ2jtHbOsd fzCxuuhXggMEwrphigq9T9iWY2Xu7SZbsGPra2g1mH3gj8EfVm464zRErUwxA3s6sy6N K+Ale0EH4xjR8/HOAbx+e1wU59eBmhoI8KWH8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type; b=MlmF1byEroaWA4WVEMJIjR/X1p4phvCra2zezG284DAuz/543GR55Tjt9GmPHXrCyP dBzGkJBtM4CG0gupIElqU4iTkWBJUchGGrLemQqt0q5l+A0UDLiFCjbCbSJ1loXe3ppq Ik9rjQbQ/lsjvdvexL/D0fC/Ty94T09IK+oKU= Received: by 10.14.49.206 with SMTP id x54mr2450982eeb.151.1300881928986; Wed, 23 Mar 2011 05:05:28 -0700 (PDT) Received: from debian.x201.phnet (etx-public-dock-248-dhcp.ethz.ch [82.130.81.248]) by mx.google.com with ESMTPS id q53sm3592126eeh.11.2011.03.23.05.05.27 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 23 Mar 2011 05:05:27 -0700 (PDT) Message-ID: <4D89E206.1080708@gmail.com> Date: Wed, 23 Mar 2011 13:05:26 +0100 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20110303 Iceowl/1.0b1 Icedove/3.0.11 MIME-Version: 1.0 To: grub-devel@gnu.org References: <20110321181748.GD9163@riva.ucam.org> In-Reply-To: <20110321181748.GD9163@riva.ucam.org> X-Enigmail-Version: 1.0.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enig0805088F4A66040C109FEADD" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.215.169 Subject: Re: [PATCH] Add grub-fstest cat subcommand X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Mar 2011 12:05:33 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig0805088F4A66040C109FEADD Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 21.03.2011 19:17, Colin Watson wrote: > This would make it easier to use grub-fstest to inspect files in > filesystems supported by GRUB without needing to mount the device. The= > same thing can be done using the cp subcommand, but that requires a > temporary file which often isn't needed. A cat subcommand is generally= > more convenient. > =20 Patch is ok after 1.99. > For context: temporarily mounting filesystems in the context of an OS > installer or a tool such as os-prober can be problematic on Linux. In > particular, if you want to inspect files on a journalled filesystem, > then you have three choices to the best of my knowledge: > > 1) Just go ahead and mount it read-only. This seems superficially > sensible. Unfortunately, Linux's journalling filesystem > implementations will write to the block device anyway. If the > filesystem was hibernated, disaster will ensue. (And, on > principle, the kinds of places where I'm doing this kind of > read-only mount, such as os-prober, should never write to the > disk.) > > 2) Mark the block device read-only using blockdev, to ensure that eve= n > journalling filesystems will never write to it. This solves the > hibernation problem, but has two other flaws. If the journal need= s > recovery, mounting will fail when an ordinary read-only mount woul= d > succeed; and blockdev has system-wide effect, so this will > interfere with anything unlucky enough to be trying to mount the > filesystem for real at the same time. > > 3) Create a device-mapper snapshot of the block device and operate on= > that. Unfortunately, if the block device is not itself a > device-mapper device, this increments the reference count of the > block device such that you can't mount the filesystem on it > ("/dev/foo already mounted or /mnt busy"). > > I'm thus getting increasingly tempted to use grub-fstest for this kind > of application wherever possible. Of course we need a fallback for > architectures where GRUB doesn't yet work, but aside from that I suspec= t > that it would make things significantly more reliable. > > 2011-03-21 Colin Watson > > * util/grub-fstest.c (cmd_cat): New function. > (fstest): Handle CMD_CAT. > (options): Add cat. > (argp_parser): Handle cat. > > =3D=3D=3D modified file 'util/grub-fstest.c' > --- util/grub-fstest.c 2010-09-20 18:09:31 +0000 > +++ util/grub-fstest.c 2011-03-21 17:32:32 +0000 > @@ -54,12 +54,15 @@ execute_command (char *name, int n, char > return (cmd->func) (cmd, n, args); > } > =20 > -#define CMD_LS 1 > -#define CMD_CP 2 > -#define CMD_CMP 3 > -#define CMD_HEX 4 > -#define CMD_CRC 6 > -#define CMD_BLOCKLIST 7 > +enum { > + CMD_LS =3D 1, > + CMD_CP, > + CMD_CAT, > + CMD_CMP, > + CMD_HEX, > + CMD_CRC, > + CMD_BLOCKLIST > +}; > =20 > #define BUF_SIZE 32256 > =20 > @@ -182,6 +185,26 @@ cmd_cp (char *src, char *dest) > } > =20 > static void > +cmd_cat (char *src) > +{ > + auto int cat_hook (grub_off_t ofs, char *buf, int len); > + int cat_hook (grub_off_t ofs, char *buf, int len) > + { > + (void) ofs; > + > + if ((int) fwrite (buf, 1, len, stdout) !=3D len) > + { > + grub_util_error (_("write error")); > + return 1; > + } > + > + return 0; > + } > + > + read_file (src, cat_hook); > +} > + > +static void > cmd_cmp (char *src, char *dest) > { > FILE *ff; > @@ -312,6 +335,9 @@ fstest (int n, char **args) > case CMD_CP: > cmd_cp (args[0], args[1]); > break; > + case CMD_CAT: > + cmd_cat (args[0]); > + break; > case CMD_CMP: > cmd_cmp (args[0], args[1]); > break; > @@ -347,6 +373,7 @@ static struct argp_option options[] =3D { > {0, 0, 0 , OPTION_DOC, N_("Commands:"), 1}, > {N_("ls PATH"), 0, 0 , OPTION_DOC, N_("List files in PATH."), = 1}, > {N_("cp FILE LOCAL"), 0, 0, OPTION_DOC, N_("Copy FILE to local file= LOCAL."), 1}, > + {N_("cat FILE"), 0, 0 , OPTION_DOC, N_("Copy FILE to standard o= utput."), 1}, > {N_("cmp FILE LOCAL"), 0, 0, OPTION_DOC, N_("Compare FILE with local= file LOCAL."), 1}, > {N_("hex FILE"), 0, 0 , OPTION_DOC, N_("Hex dump FILE."), 1}, > {N_("crc FILE"), 0, 0 , OPTION_DOC, N_("Get crc32 checksum of FI= LE."), 1}, > @@ -459,6 +486,11 @@ argp_parser (int key, char *arg, struct > cmd =3D CMD_CP; > nparm =3D 2; > } > + else if (!grub_strcmp (arg, "cat")) > + { > + cmd =3D CMD_CAT; > + nparm =3D 1; > + } > else if (!grub_strcmp (arg, "cmp")) > { > cmd =3D CMD_CMP; > > =20 --=20 Regards Vladimir '=CF=86-coder/phcoder' Serbinenko --------------enig0805088F4A66040C109FEADD Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iF4EAREKAAYFAk2J4gYACgkQNak7dOguQglyTQD/RMkAbAlzF6JsbZNgj2GJkS+h d10kesultoVsOoMqPO0A/RwxUclbfo21YNku6dK7PbiG1ruZT8k0XPs1cMGHmt/i =uv2q -----END PGP SIGNATURE----- --------------enig0805088F4A66040C109FEADD--