Continued from Page 2
Remember that youve to be in root to register file formats.
Lets start with a simple example of text files. Lets say we want to
register all the files with the TXT extension as binary files, to be interpreted by the
editor vi (or any other editor for that matter).
To do this, simply type at the prompt (in the rest of this article, lines beginning
with % are typed at the prompt):
% cd /proc/sys/fs/binfmt_misc
% echo ":text:E::txt::/bin/vi:" > register
Thats all! The first fieldtextis
the name that we give to this format. "E" indicates that recognition will be by
file extension. The next field is empty because were not using magic numbers in this
case. The extension is TXT, without the dot. And finally, "/bin/vi" is the
program which will be invoked when you "execute" a text file.
Now youll find a new file in /proc/sys/fs/binfmt_misc called "text".
This happens for every binary format registered. That file will have something like:
enabled
interpreter /bin/vi
extension .txt
To test your new file format, make the file, say,
foo.txt, executable with "% chmod +x foo.txt".
Then at the prompt type "% ./foo.txt". This should bring up foo.txt in vi.
An example with magic numbers
Now lets have some more fun, and register the JPEG image format, so that we can
view one in XV just by making it executable, and typing its name at the prompt.
Well use magic numbers this time. The magic number for JPEG images is ffd8 (in
hexadecimal). Registering it is easy:
% cd /proc/sys/fs/binfmt_misc
% echo ":jpeg_img:M::\xff\xd8::/usr/X11R6/bin/xv:" > register
Now you should have a new file called
"jpeg_img" in /proc/sys/binfmt_misc, which should look like:
enabled
interpreter /usr/X11R6/bin/xv
offset 0
magic ffd8
To get back to where it all began, Java classes, you
can register that too. But I wont explain that here. Its done in the kernel
documentation. Look at /usr/src/linux/Documentation/java.txt.
Next time well see how to write a small wrapper, a shell script to tweak things a
bit before actually calling the interpreter.
Page(s) 1 2 3 |
|