Browse Source

Plan 9 from Bell Labs 2006-08-10

David du Colombier 17 years ago
parent
commit
2307581e3b
5 changed files with 126 additions and 24 deletions
  1. 2 2
      dist/replica/_plan9.db
  2. 2 2
      dist/replica/plan9.db
  3. 2 0
      dist/replica/plan9.log
  4. 6 5
      sys/man/8/plan9.ini
  5. 114 15
      sys/src/cmd/file.c

+ 2 - 2
dist/replica/_plan9.db

@@ -7730,7 +7730,7 @@ sys/man/8/nfsserver - 664 sys sys 1142693998 3585
 sys/man/8/pcmcia - 664 sys sys 944959679 408
 sys/man/8/pem - 664 sys sys 1060263669 1189
 sys/man/8/ping - 664 sys sys 1139667147 3489
-sys/man/8/plan9.ini - 664 sys sys 1154459321 22479
+sys/man/8/plan9.ini - 664 sys sys 1155153087 22548
 sys/man/8/pop3 - 664 sys sys 1063854676 2720
 sys/man/8/ppp - 664 sys sys 1125530075 4414
 sys/man/8/prep - 664 sys sys 1152729153 14013
@@ -10140,7 +10140,7 @@ sys/src/cmd/fax/receiverc - 775 sys sys 944960990 581
 sys/src/cmd/fax/send.c - 664 sys sys 944960990 923
 sys/src/cmd/fax/subr.c - 664 sys sys 1015090401 1245
 sys/src/cmd/fcp.c - 664 sys sys 1136651872 3799
-sys/src/cmd/file.c - 664 sys sys 1148481459 24833
+sys/src/cmd/file.c - 664 sys sys 1155176190 26901
 sys/src/cmd/fmt.c - 664 sys sys 1137603598 4078
 sys/src/cmd/fortune.c - 664 sys sys 1072729222 1779
 sys/src/cmd/fossil - 20000000775 sys sys 1042005512 0

+ 2 - 2
dist/replica/plan9.db

@@ -7730,7 +7730,7 @@ sys/man/8/nfsserver - 664 sys sys 1142693998 3585
 sys/man/8/pcmcia - 664 sys sys 944959679 408
 sys/man/8/pem - 664 sys sys 1060263669 1189
 sys/man/8/ping - 664 sys sys 1139667147 3489
-sys/man/8/plan9.ini - 664 sys sys 1154459321 22479
+sys/man/8/plan9.ini - 664 sys sys 1155153087 22548
 sys/man/8/pop3 - 664 sys sys 1063854676 2720
 sys/man/8/ppp - 664 sys sys 1125530075 4414
 sys/man/8/prep - 664 sys sys 1152729153 14013
@@ -10140,7 +10140,7 @@ sys/src/cmd/fax/receiverc - 775 sys sys 944960990 581
 sys/src/cmd/fax/send.c - 664 sys sys 944960990 923
 sys/src/cmd/fax/subr.c - 664 sys sys 1015090401 1245
 sys/src/cmd/fcp.c - 664 sys sys 1136651872 3799
-sys/src/cmd/file.c - 664 sys sys 1148481459 24833
+sys/src/cmd/file.c - 664 sys sys 1155176190 26901
 sys/src/cmd/fmt.c - 664 sys sys 1137603598 4078
 sys/src/cmd/fortune.c - 664 sys sys 1072729222 1779
 sys/src/cmd/fossil - 20000000775 sys sys 1042005512 0

+ 2 - 0
dist/replica/plan9.log

@@ -30223,3 +30223,5 @@
 1154460605 0 c sys/man/8/plan9.ini - 664 sys sys 1154459321 22479
 1154723405 0 c sys/src/cmd/ssh/util.c - 664 sys sys 1154722953 4522
 1154727005 0 c sys/src/9/pc/usbuhci.c - 664 sys sys 1154725785 30910
+1155153606 0 c sys/man/8/plan9.ini - 664 sys sys 1155153087 22548
+1155177006 0 c sys/src/cmd/file.c - 664 sys sys 1155176190 26901

+ 6 - 5
sys/man/8/plan9.ini

@@ -578,14 +578,15 @@ When available, the kernel uses the BIOS E820 memory map
 to size memory.  This variable disables the scan.
 .SS \fL*maxmem=value\fP
 This defines the maximum physical address that the system will scan when sizing memory.
-By default the operating system will scan up to 768 megabytes, but setting
+By default the operating system will scan up to 3.75 gigabytes
+(0xF0000000, the base of kernel virtual address space), but setting
 .B *maxmem
 will limit the scan.
-If the system has more than 768 megabytes, you must set
+.\" If the system has more than 3.75 gigabytes, you must set
+.\" .B *maxmem
+.\" for the kernel to find it.
 .B *maxmem
-for the kernel to find it.
-.B *maxmem
-must be less than 1.75 gigabytes.
+must be less than 3.75 gigabytes.
 This variable is not consulted if using the E820 memory map.
 .SS \fL*kernelpercent=value\fP
 This defines what percentage of available memory is reserved for the kernel allocation pool.

+ 114 - 15
sys/src/cmd/file.c

@@ -52,7 +52,7 @@ struct
 	"common",	Fword,
 	"con",		Lword,
 	"data",		Fword,
-	"dimension",	Fword,	
+	"dimension",	Fword,
 	"double",	Cword,
 	"extern",	Cword,
 	"bio",		I2,
@@ -86,7 +86,7 @@ struct
 enum	{
 		Normal	= 0,
 		First,		/* first entry for language spanning several ranges */
-		Multi,		/* later entries "   "       "  ... */ 
+		Multi,		/* later entries "   "       "  ... */
 		Shared,		/* codes used in several languages */
 	};
 
@@ -97,7 +97,7 @@ struct
 	int	low;
 	int	high;
 	char	*name;
-	
+
 } language[] =
 {
 	Normal, 0,	0x0080, 0x0080,	"Extended Latin",
@@ -127,8 +127,8 @@ struct
 	Shared,	0,	0x4e00,	0x9fff,	"CJK",
 	Normal,	0,	0,	0,	0,		/* terminal entry */
 };
-	
-	
+
+
 enum
 {
 	Fascii,		/* printable ascii */
@@ -159,8 +159,10 @@ int	isrtf(void);
 int	ismsdos(void);
 int	iself(void);
 int	istring(void);
+int	isoffstr(void);
 int	iff(void);
 int	long0(void);
+int	longoff(void);
 int	istar(void);
 int	isface(void);
 int	isexec(void);
@@ -178,6 +180,8 @@ int	(*call[])(void) =
 	iself,		/* ELF (foreign) executable */
 	isexec,		/* native executables */
 	iff,		/* interchange file format (strings) */
+	longoff,	/* recognizable by 4 bytes at some offset */
+	isoffstr,	/* recognizable by string at some offset */
 	isrfc822,	/* email file */
 	ismbox,		/* mail box */
 	istar,		/* recognizable by tar checksum */
@@ -339,15 +343,22 @@ filetype(int fd)
 	else if (cfreq[Ceascii])
 		guess = Feascii;
 	else if (cfreq[Cnull] == n) {
+		/*
+		 * ISO9660 CDs, venti and fossil partitions start with zeroes or
+		 * unwritten blocks, so this old heuristic is no longer helpful.
+		 */
+	/*
 		print(mime ? OCTET : "first block all null bytes\n");
 		return;
+	 */
+		guess = Fbinary;
 	}
 	else guess = Fascii;
 	/*
 	 * lookup dictionary words
 	 */
 	memset(wfreq, 0, sizeof(wfreq));
-	if(guess == Fascii || guess == Flatin || guess == Futf) 
+	if(guess == Fascii || guess == Flatin || guess == Futf)
 		wordfreq();
 	/*
 	 * call individual classify routines
@@ -518,10 +529,16 @@ struct Filemagic {
 	char *mime;
 };
 
+/*
+ * integers in this table must be as seen on a little-endian machine
+ * when read from a file.
+ */
 Filemagic long0tab[] = {
 	0xF16DF16D,	0xFFFFFFFF,	"pac1 audio file\n",	OCTET,
+	/* "pac1" */
 	0x31636170,	0xFFFFFFFF,	"pac3 audio file\n",	OCTET,
-	0x32636170,	0xFFFF00FF,	"pac4 audio file\n",	OCTET,
+	/* "pXc2 */
+	0x32630070,	0xFFFF00FF,	"pac4 audio file\n",	OCTET,
 	0xBA010000,	0xFFFFFFFF,	"mpeg system stream\n",	OCTET,
 	0x30800CC0,	0xFFFFFFFF,	"inferno .dis executable\n", OCTET,
 	0x04034B50,	0xFFFFFFFF,	"zip archive\n", "application/zip",
@@ -532,6 +549,11 @@ Filemagic long0tab[] = {
 	0xfffe,		0xffffffff,	"utf-32le\n",	"text/plain charset=utf-32le",
 	0xfeff,		0xffff,		"utf-16be\n",	"text/plain charset=utf-16be",
 	0xfffe,		0xffff,		"utf-16le\n",	"text/plain charset=utf-16le",
+	/*
+	 * venti & fossil magic numbers are stored big-endian on disk,
+	 * thus the numbers appear reversed in this table.
+	 */
+	0xad4e5cd1,	0xFFFFFFFF,	"venti arena\n", OCTET,
 };
 
 int
@@ -546,18 +568,61 @@ filemagic(Filemagic *tab, int ntab, ulong x)
 		}
 	return 0;
 }
-	
+
 int
 long0(void)
 {
-	long x;
+	return filemagic(long0tab, nelem(long0tab), LENDIAN(buf));
+}
 
-	x = LENDIAN(buf);
-	if(filemagic(long0tab, nelem(long0tab), x))
-		return 1;
+typedef struct Fileoffmag Fileoffmag;
+struct Fileoffmag {
+	ulong	off;
+	Filemagic;
+};
+
+/*
+ * integers in this table must be as seen on a little-endian machine
+ * when read from a file.
+ */
+Fileoffmag longofftab[] = {
+	/*
+	 * venti & fossil magic numbers are stored big-endian on disk,
+	 * thus the numbers appear reversed in this table.
+	 */
+	256*1024, 0xe7a5e4a9, 0xFFFFFFFF, "venti arenas partition\n", OCTET,
+	256*1024, 0xc75e5cd1, 0xFFFFFFFF, "venti index section\n", OCTET,
+	128*1024, 0x89ae7637, 0xFFFFFFFF, "fossil write buffer\n", OCTET,
+};
+
+int
+fileoffmagic(Fileoffmag *tab, int ntab)
+{
+	int i;
+	ulong x;
+	Fileoffmag *tp;
+	uchar buf[sizeof(long)];
+
+	for(i=0; i<ntab; i++) {
+		tp = tab + i;
+		seek(fd, tp->off, 0);
+		if (read(fd, buf, sizeof buf) != sizeof buf)
+			continue;
+		x = LENDIAN(buf);
+		if((x&tp->mask) == tp->x){
+			print(mime? tp->mime: tp->desc);
+			return 1;
+		}
+	}
 	return 0;
 }
 
+int
+longoff(void)
+{
+	return fileoffmagic(longofftab, nelem(longofftab));
+}
+
 int
 isexec(void)
 {
@@ -712,6 +777,40 @@ istring(void)
 	return 0;
 }
 
+struct offstr
+{
+	ulong	off;
+	struct FILE_STRING;
+} offstrs[] = {
+	32*1024, "\001CD001\001",	"ISO9660 CD image",	7,	OCTET,	
+	0, 0, 0, 0, 0
+};
+
+int
+isoffstr(void)
+{
+	int n;
+	char buf[256];
+	struct offstr *p;
+
+	for(p = offstrs; p->key; p++) {
+		seek(fd, p->off, 0);
+		n = p->length;
+		if (n > sizeof buf)
+			n = sizeof buf;
+		if (read(fd, buf, n) != n)
+			continue;
+		if(memcmp(buf, p->key, n) == 0) {
+			if(mime)
+				print("%s\n", p->mime);
+			else
+				print("%s\n", p->filetype);
+			return 1;
+		}
+	}
+	return 0;
+}
+
 int
 iff(void)
 {
@@ -902,7 +1001,7 @@ yes:
 	}
 	if(wfreq[Alword] > 0)
 		print("alef program\n");
-	else 
+	else
 		print("c program\n");
 	return 1;
 }
@@ -1074,7 +1173,7 @@ depthof(char *s, int *newp)
 		s++;	/* skip letter */
 		d += strtoul(s, &s, 10);
 	}
-	
+
 	switch(d){
 	case 32:
 	case 24:
@@ -1335,7 +1434,7 @@ isface(void)
 		if (*p++ != '\n')
 			return 0;
 	}
-	
+
 	if(mime)
 		print("application/x-face\n");
 	else