From 53d5f088164385766c2a2defb319a406254cb60f Mon Sep 17 00:00:00 2001 From: Geoff Rehmet Date: Sat, 3 Sep 1994 19:31:29 +0000 Subject: [PATCH] Changes to file(1) for FreeBSD: - Makefile: bmake the sucker - file.1, magic.5: replace __MAGIC__ and __SECTION__ - add Magdir/freebsd - add file to usr.bin/Makefile A note on the FreeBSD magic entry: The magic number "000000407" is reported as "impure format". This stops file(1) telling us that our object files are "PDP-11 executables". (Saying anything more than "impure format" would probably be bogus. Submitted by: Geoff. --- usr.bin/Makefile | 4 +- usr.bin/file/Magdir/freebsd | 16 ++++ usr.bin/file/Makefile | 153 ++++++------------------------------ usr.bin/file/file.1 | 10 +-- usr.bin/file/magic.5 | 4 +- 5 files changed, 51 insertions(+), 136 deletions(-) create mode 100644 usr.bin/file/Magdir/freebsd diff --git a/usr.bin/Makefile b/usr.bin/Makefile index 516e50545beb..91c98f1a3fc3 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -2,7 +2,7 @@ # XXX MISSING: bc dc deroff diction diff ex graph learn plot # ptx spell spline struct units xsend -# XXX MISSING SOURCES: file grep sort +# XXX MISSING SOURCES: grep sort # XXX MISSING Makefile: uucp # XXX Use GNU versions: ld man apropos whatis patch # Moved to secure: bdes @@ -10,7 +10,7 @@ SUBDIR= apply ar at banner basename biff cal calendar \ cap_mkdb checknr chflags chpass cksum col colcrt colrm column \ comm compress cpp ctags cut dirname du \ - env error expand false find finger fmt fold fpr from \ + env error expand false file find finger fmt fold fpr from \ fsplit fstat ftp gcore gprof head hexdump id indent \ join jot kdump ktrace key keyinfo keyinit lam last \ lastcomm leave lex locate lock logger login logname lorder \ diff --git a/usr.bin/file/Magdir/freebsd b/usr.bin/file/Magdir/freebsd new file mode 100644 index 000000000000..28ad615bf93a --- /dev/null +++ b/usr.bin/file/Magdir/freebsd @@ -0,0 +1,16 @@ +# the following are for 386BSD/FreeBSD + +0 lelong 0410 pure executable +0 lelong 0413 demand paged executable +0 lelong&077777777 041400314 FreeBSD/i386 demand paged +>3 byte &0x80 +>>20 lelong <4096 shared library +>>20 lelong =4096 dynamically linked executable +>>20 lelong >4096 dynamically linked executable +>3 byte ^0x80 executable +>16 lelong >0 not stripped + +# This covers object files, and is better than "PDP-11 executable" +0 lelong 000000407 impure format +>16 lelong >0 not stripped + diff --git a/usr.bin/file/Makefile b/usr.bin/file/Makefile index d59f490fe237..54c748307ad0 100644 --- a/usr.bin/file/Makefile +++ b/usr.bin/file/Makefile @@ -21,139 +21,38 @@ # ever read sources, credits must appear in the documentation. # # 4. This notice may not be removed or altered. -VERSION = 3.14 -SHELL = /bin/sh -#MAGIC = /etc/magic -MAGIC = /usr/local/etc/magic -DEFS = -DMAGIC='"$(MAGIC)"' # -Dvoid=int -CC = cc -COPTS = -O -g # newer compilers allow both; else drop -O -# For truly antique environments, use this for (dummy) include files: -COPTS = -O # -Ilocalinc -CFLAGS = $(COPTS) $(DEFS) -LDFLAGS = $(COPTS) # -Bstatic # older gdb couldn't handle shared libs -SHAR = bundle -OFILE = /usr/bin/file # old or distributed version, for comparison -# Where new binary lives; typically /usr/local (BSD), /usr/lbin (USG). -BINDIR = /usr/local/bin -# For installing our man pages; -# MANCxxx is manual section for Commands, MANFxxx is section for file formats. -# MANxDIR is directory names; MANxEXT is the filename extention. Usual values: -# Variable V7 4BSD Sys V -# MANCDIR /usr/man/man1 /usr/man/man1 /usr/man/u_man/man1 -# MANFDIR /usr/man/man5 /usr/man/man5 /usr/man/u_man/man4 -# MANCEXT 1 1 1 -# MANFEXT 5 5 4 -# --- possible alternative for 4BSD --- -# MANCDIR /usr/local/man/man1 -# MANCEXT 1 -# or -# MANCDIR /usr/man/manl -# MANCEXT l -# --- possible alternative for USG --- -# MANCDIR /usr/man/local/man1 -# MANCEXT 1 - -MANCDIR = /usr/local/man/man1 -MANCEXT = 1 -MANFDIR = /usr/local/man/man4 -MANFEXT = 4 - -# There are no system-dependant configuration options (except maybe CFLAGS). -# Uncomment any of these that is missing from your "standard" library. -LOCALSRCS = # localsrc/getopt.c localsrc/strtol.c \ -# localsrc/strtok.c localsrc/strchr.c -LOCALOBJS = # localsrc/getopt.o localsrc/strtol.o \ -# localsrc/strtok.o localsrc/strchr.o -# These are not compiled in unless you use -Ilocalinc, but -# are not commented out as "make dist" &c use them. -LOCALINC = # localinc/*.h localinc/sys/*.h - -SRCS = file.c apprentice.c fsmagic.c softmagic.c ascmagic.c \ - compress.c is_tar.c \ - print.c $(LOCALSRCS) $(LOCALINC) -OBJS = file.o apprentice.o fsmagic.o softmagic.o ascmagic.o \ - compress.o is_tar.o \ - print.o $(LOCALOBJS) - -ALLSRC = LEGAL.NOTICE README MAINT PORTING $(SRCS) *.h \ - Makefile file.man magic.man -ALLMAGIC = Magdir/Makefile Magdir/Localstuff Magdir/Header Magdir/[a-z]* - -all: file magic file.${MANCEXT} magic.${MANFEXT} - -TESTFILES = * tst/* -try: all $(OFILE) - cd tst; $(MAKE) - time $(OFILE) $(TESTFILES) >/tmp/t1 # can't use ./magic - time ./file -m ./magic $(TESTFILES) >/tmp/t2 - -diff -b /tmp/t[12] - what ./file >lastnocore - -file: $(OBJS) - $(CC) $(CFLAGS) $(OBJS) -o $@ -lint: $(SRCS) - lint -ha $(DEFS) $(SRCS) | tee $@ -magic: Magdir -# Magdir/Makefile's "install" mv's magic to here for testing. - cd Magdir; $(MAKE) install - -ascmagic.o: names.h - -compress.o apprentice.o ascmagic.o file.o fsmagic.o print.o softmagic.o: file.h - -install: file magic - cp file $(BINDIR)/file - cp magic $(MAGIC) - -install.man: file.${MANCEXT} magic.${MANFEXT} - cp file.${MANCEXT} $(MANCDIR)/file.$(MANCEXT) - cp magic.${MANFEXT} $(MANFDIR)/magic.$(MANFEXT) - -clean: - rm -f *.o core file magic lint dist.* MANIFEST \ - magic.${MANFEXT} file.${MANCEXT} -clobber: - cd tst; $(MAKE) clean +# +# Hacked and dismembered for bmake (Geoff Rehmet). +MAGIC= /etc/magic +MAGICOWN= bin +MAGICGRP= bin +MAGICMODE= 444 -magic.${MANFEXT} : Makefile magic.man - @rm -f $@ - sed -e s@__SECTION__@${MANFEXT}@g \ - -e s@__MAGIC__@${MAGIC}@g magic.man > $@ +CFLAGS+= -DMAGIC='"$(MAGIC)"' -file.${MANCEXT} : Makefile file.man - @rm -f $@ - sed -e s@__SECTION__@${MANCEXT}@g \ - -e s@__MAGIC__@${MAGIC}@g file.man > $@ +PROG= file +SRCS= file.c apprentice.c fsmagic.c softmagic.c ascmagic.c \ + compress.c is_tar.c print.c -send: dist - ftp ftp.cs +MAN1= file.1 +MAN5= magic.5 -dist: dist.src dist.magic - @echo Now check this patchlevel! - ident patchlevel.h +CLEANFILES+= magic -dist.src: $(ALLSRC) MANIFEST -# Some versions of shar can't handle a single file from -# a subdirectory, so we manually insert mkdir as needed. -# The point is to exclude all the generable targets in tst. - (echo mkdir localinc localinc/sys localsrc tst; \ - $(SHAR) $(ALLSRC) MANIFEST) > $@ +MAGFILES= $(.CURDIR)/Magdir/Header\ + $(.CURDIR)/Magdir/Localstuff\ + $(.CURDIR)/Magdir/[a-z]* -rcsdiff: $(ALLSRC) - rcsdiff -q RCS/* -MANIFEST: $(ALLSRC) - ident $(ALLSRC) > MANIFEST -dist.magic: Magdir -# As above, but to exclude Magdir/RCS from being shipped. - (echo mkdir Magdir; $(SHAR) $(ALLMAGIC)) >$@ +all: file magic + +magic: $(MAGFILES) + cat $(MAGFILES) > $(.TARGET) + +afterinstall: + install -c -o $(MAGICOWN) -g $(MAGICGRP) -m $(MAGICMODE) magic \ + $(DESTDIR)$(MAGIC) + +.include -tar: $(ALLSRC) $(ALLMAGIC) - -rm -fr file-${VERSION} - -mkdir file-${VERSION} file-${VERSION}/Magdir - ln $(ALLSRC) file-${VERSION} - ln ${ALLMAGIC} file-${VERSION}/Magdir - tar cvf file-${VERSION}.tar file-${VERSION} - -rm -fr file-${VERSION} diff --git a/usr.bin/file/file.1 b/usr.bin/file/file.1 index c10b221c26ca..555261f54ed9 100644 --- a/usr.bin/file/file.1 +++ b/usr.bin/file/file.1 @@ -43,7 +43,7 @@ meaning anything else (data is usually `binary' or non-printable). Exceptions are well-known file formats (core files, tar archives) that are known to contain binary data. When modifying the file -.I __MAGIC__ +.I /etc/magic or the program itself, .B "preserve these keywords" . People depend on knowing that all the readable files in a directory @@ -79,7 +79,7 @@ The concept of `magic number' has been applied by extension to data files. Any file with some invariant identifier at a small fixed offset into the file can usually be described in this way. The information in these files is read from the magic file -.I __MAGIC__. +.I /etc/magic. .PP If an argument appears to be an .SM ASCII @@ -135,10 +135,10 @@ The option causes symlinks to be followed, as the like-named option in .IR ls (1). .SH FILES -.I __MAGIC__ +.I /etc/magic \- default list of magic numbers .SH SEE ALSO -.IR magic (__SECTION__) +.IR magic (5) \- description of magic file format. .br .IR Strings (1), " od" (1) @@ -197,7 +197,7 @@ If your old command uses a magic file, keep the old magic file around for comparison purposes (rename it to -.IR __MAGIC__.orig ). +.IR /etc/magic.orig ). .SH HISTORY There has been a .I file diff --git a/usr.bin/file/magic.5 b/usr.bin/file/magic.5 index 7c2788e9b434..6c6f3ef26767 100644 --- a/usr.bin/file/magic.5 +++ b/usr.bin/file/magic.5 @@ -1,4 +1,4 @@ -.TH MAGIC __SECTION__ "Public Domain" +.TH MAGIC 5 "Public Domain" .\" install as magic.4 on USG, magic.5 on V7 or Berkeley systems. .SH NAME magic \- file command's magic number file @@ -10,7 +10,7 @@ among other tests, a test for whether the file begins with a certain .IR "magic number" . The file -.B __MAGIC__ +.B /etc/magic specifies what magic numbers are to be tested for, what message to print if a particular magic number is found, and additional information to extract from the file.