From owner-freebsd-arch Thu May 17 4:31:47 2001 Delivered-To: freebsd-arch@freebsd.org Received: from nothing-going-on.demon.co.uk (pc-62-31-42-140-hy.blueyonder.co.uk [62.31.42.140]) by hub.freebsd.org (Postfix) with ESMTP id A577B37B43E for ; Thu, 17 May 2001 04:31:30 -0700 (PDT) (envelope-from nik@nothing-going-on.demon.co.uk) Received: (from nik@localhost) by nothing-going-on.demon.co.uk (8.11.3/8.11.3) id f4HBJOJ03178 for arch@freebsd.org; Thu, 17 May 2001 12:19:25 +0100 (BST) (envelope-from nik) Date: Thu, 17 May 2001 12:19:02 +0100 From: Nik Clayton To: arch@freebsd.org Subject: [PATCH] syscons ioctl() to grab text mode buffer Message-ID: <20010517121902.A3047@catkin.nothing-going-on.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-md5; protocol="application/pgp-signature"; boundary="8GpibOaaTibBMecb" Content-Disposition: inline User-Agent: Mutt/1.2.5i Organization: FreeBSD Project Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --8GpibOaaTibBMecb Content-Type: multipart/mixed; boundary="nFreZHaLTZJo0R7j" Content-Disposition: inline --nFreZHaLTZJo0R7j Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Two things for review. The first set of patches add a new ioctl, CONS_SCRSHOT, to syscons. This allows user mode programs to request a dump of the current contents of the text mode video buffer, typically consisting of tuples of the form (character code x video attribute). This isn't a security problem, because it will only work on vtys that you already have read access to. The second, scrshot.c uses the ioctl to dump the contents of the video memory to stdout. Usage is scrshot /dev/ttyv0 > shot.scr Both of these were (IIRC) originally written by jmallet back in the 2.2.x days, I've just forward-ported them to -current. I'd like to commit both of these, with scrshot becoming src/usr.bin/scrshot (I'll write a man page before I commit it). There's a third utility, shot2gif which reads the screen dumps and kicks out GIF files -- I'll bring that in as a port. In case you're wondering, this should make it a bit easier for the doc. project to generate accurate screenshots. 1. You don't need to be in X to do screenshots. 2. The size of the .scr files is smaller than the equivalent .gif or .png files. 3. An accompanying shot2txt utility is trivial to write, making the production of text only alternatives for the images much less effort. 4. Should a screen dump need to be changed (perhaps to fix a typo), it's easier to fix a .scr file than it is to recapture the screen. 5. shot2gif parses the same font files as syscons, giving a much closer rendition of the output from a text screen than doing the=20 capture in X. N --=20 FreeBSD: The Power to Serve http://www.freebsd.org/ FreeBSD Documentation Project http://www.freebsd.org/docproj/ --- 15B8 3FFC DDB4 34B0 AA5F 94B7 93A8 0764 2C37 E375 --- --nFreZHaLTZJo0R7j Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="syscons2.diff" Content-Transfer-Encoding: quoted-printable Index: dev/syscons/syscons.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/ncvs/src/sys/dev/syscons/syscons.c,v retrieving revision 1.357 diff -u -r1.357 syscons.c --- dev/syscons/syscons.c 2001/05/01 08:12:05 1.357 +++ dev/syscons/syscons.c 2001/05/17 09:42:15 @@ -838,6 +838,24 @@ splx(s); return 0; =20 + case CONS_SCRSHOT: /* get a screen shot */ + { + scrshot_t *ptr =3D (scrshot_t*)data; + s =3D spltty(); + if (ISGRAPHSC(scp)) { + splx(s); + return EOPNOTSUPP; + } + if (scp->xsize !=3D ptr->xsize || scp->ysize !=3D ptr->ysize) { + splx(s); + return EINVAL; + } + copyout ((void*)scp->vtb.vtb_buffer, ptr->buf, + ptr->xsize * ptr->ysize * sizeof(u_int16_t)); + splx(s); + return 0; + } + case VT_SETMODE: /* set screen switcher mode */ { struct vt_mode *mode; Index: sys/consio.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/ncvs/src/sys/sys/consio.h,v retrieving revision 1.6 diff -u -r1.6 consio.h --- sys/consio.h 2000/04/27 13:34:31 1.6 +++ sys/consio.h 2001/05/16 22:54:44 @@ -239,6 +239,16 @@ /* release the current keyboard */ #define CONS_RELKBD _IO('c', 111) =20 +/* Snapshot the current video buffer */ +#define CONS_SCRSHOT _IOWR('c', 105, scrshot_t) + +struct scrshot { + int xsize; + int ysize; + u_int16_t* buf; +}; +typedef struct scrshot scrshot_t; + /* get/set the current terminal emulator info. */ #define TI_NAME_LEN 32 #define TI_DESC_LEN 64 --nFreZHaLTZJo0R7j Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="scrshot.c" Content-Transfer-Encoding: quoted-printable /*- * Copyright (c) 2001 Nik Clayton * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer, * without modification, immediately at the beginning of the file. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include /* * Given the path to a syscons terminal (e.g., "/dev/ttyv0"), tries to * snapshot the video memory of that terminal, using the CONS_SCRSHOT * ioctl, and writes the results to stdout. */ int main(int argc, char *argv[]) { int fd; int result; scrshot_t shot; vid_info_t info; if (argc !=3D 2) errx(1, "improper # of args"); fd =3D open(argv[1], O_RDWR); if (fd < 0) { perror(argv[1]); exit(1); } =09 info.size =3D sizeof(info); result =3D ioctl(fd, CONS_GETINFO, &info); if (result !=3D 0) { perror("getinfo failed"); exit(1); } =09 shot.buf =3D malloc(info.mv_csz * info.mv_rsz * sizeof(u_int16_t)); if (!shot.buf) { perror("couldn't allocate shot space"); exit(1); } =09 shot.xsize =3D info.mv_csz; shot.ysize =3D info.mv_rsz; result =3D ioctl (fd, CONS_SCRSHOT, &shot); if (result !=3D 0) { perror("CONS_SCRSHOT failed"); exit(1); } =09 write(1, shot.buf, shot.xsize * shot.ysize * sizeof(u_int16_t)); return 0; } --nFreZHaLTZJo0R7j-- --8GpibOaaTibBMecb Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.5 (FreeBSD) Comment: For info see http://www.gnupg.org iEYEARECAAYFAjsDs6UACgkQk6gHZCw343UpEwCgityz05R9NdQAvOwq6t7wX0oW w8UAoI1RZGjl1tjZFtbUrcko9HHXpj5v =mDb5 -----END PGP SIGNATURE----- --8GpibOaaTibBMecb-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message