-->
Page 228
The /dev/vcs* files provide a snapshot of what is in view on the corresponding VC. This contains no newlines because there are none actually on the screen; a newline character just moves the cursor after all. To make the captured data into the kind of thing you usually see in text files or send to printers, you need to add newlines in the appropriate places. This can be done with dd:
$ dd cbs=80 conv=unblock </dev/vcs1 | lpr
This command works only if the screen is 80 columns wide. This is not always true; the kernel can set up a different video mode at boot time, and the SVGATextMode command can be used to change it at any time.
This problem can be overcome by using the other set of devices, /dev/vcsa*. Reading from these devices gives a header, followed by the screen data with attribute bytes. The header consists of two bytes indicating the screen size (height first), followed by two bytes indicating the cursor position. The screen data is provided two bytes per character cell, the first containing the attribute byte and the second containing the character data (as with /dev/vcs*). This can be used to provide full-color screen dumps and so on. The following script uses /dev/vcsa1 to determine the width of the VC and to get the conversion of /dev/vcs1 right:
#! /bin/sh # Insist on exactly one argument (the VC number to dump) [ $# -eq 1 ] || { echo "usage: $0 [vc-number]" >&2; exit 1 } vc=$1 # Which VC to dump. # Extract the VC's width from the second byte of the vcsa device. # Th "unpack" expression extracts the value of the second # character of the input (the vcsa device). width=`perl -e `print unpack("x%C",<>);' < /dev/vcsa${vc}` # Use dd(1) to convert the output now that we know the width. dd cbs=${width} conv=unblock </dev/vcs${vc}
This chapter introduces the topics of character and block devices and filesystem administration, with an overview of the hardware accessed via the special files in the directory /dev. Further information can be obtained from the Linux Documentation Project material at http://sunsite.unc.edu/LDP. Much of the LDP material is also provided on the CD-ROM accompaning this book.