It Came from Bell Labs

One of the things that I find most exciting about the new open source release of Solaris is that for the first time, a modern, ready-to-use form of the original, genuine, Unix source code from AT&T Bell Labs is open to the whole world.

The AT&T Unix source code used to be available only under expensive licensing contracts made between AT&T (later Unix System Laboratories) and large corporations (at least large enough to pay the $100,000 source license fee plus the per-binary-user royalties). And in some cases Universities got educational licenses to use the source code for research purposes. But in any case, the programmers and students who had access to the source code were forbidden to reveal or discuss it publicly. Only recently did some of the Ancient Unix source code archives become available to the public, and they can not really be run on any modern hardware.

I learned Unix kernel programming before I worked for a company with a source license by using adb to disassemble kernel modules and decompile them into C code by hand. It was a fun hobby for a while but not a practical way to become an expert kernel hacker. Once I decided to focus my career on Unix kernel development, it became essential for me always to work for a company with a Unix source license, otherwise I would be just an outsider.

But now, thanks to Sun's investment in the 1990's (purchasing from USL an unlimited right to the Unix SVR4 source code) and contribution of that technology (or its decendent, anyway) as open source, we all are Real Unix Insiders now.

So, you may be wondering, how much of the original AT&T Unix source code is in OpenSolaris? Let's think of the kernel first. I think it would be hard to find any major piece of functionality in the kernel that hasn't been overhauled by Sun. But there are significant structural design elements that have survived intact. And there are definitely blocks of code in there that were, presumably, actually typed in by Dennis Ritchie or Ken Thompson somewhere in New Jersey over 25 years ago. I took a peek at a fairly random file that I knew had been around that long: acct.c, which implements the acct(2) system call and writing the account records when a process exits. I compared the Solaris version with the version from AT&T Unix Version 7 from 1979. The Solaris code has been enhanced and tweaked in various ways, but you can still see the same basic lines of code. And here's an example of some code that is pretty near unchanged since 1979:

    343 /\*
    344  \* Produce a pseudo-floating point representation
    345  \* with 3 bits base-8 exponent, 13 bits fraction.
    346  \*/
    347 static comp_t
    348 acct_compress(ulong_t t)
    349 {
    350 	int exp = 0, round = 0;
    351 
    352 	while (t >= 8192) {
    353 		exp++;
    354 		round = t & 04;
    355 		t >>= 3;
    356 	}
    357 	if (round) {
    358 		t++;
    359 		if (t >= 8192) {
    360 			t >>= 3;
    361 			exp++;
    362 		}
    363 	}
    364 #ifdef _LP64
    365 	if (exp > 7) {
    366 		/\* prevent wraparound \*/
    367 		t = 8191;
    368 		exp = 7;
    369 	}
    370 #endif
    371 	return ((exp << 13) + t);
    372 }

That entire function, including the comment, are byte-for-byte identical with the Unix Version 7 code except for the following: spaces inserted around the & and << operators and return keyword, the #ifdef _LP64 section added for 64-bit platform support, and the function has been renamed and converted to ANSI C function declaration style. Pretty cool, huh? Well, at least I think so. Yes, they call me a Unix geek.

If you look outside the kernel, it's much easier to find large sections of code written at AT&T and barely touched over the years. Some large programs like sh(1) contain complex old code that people are afraid to touch :-). Some programs that you'd think are perfectly portable C code using simple standard APIs, have actually been substantially changed for things like internationalization and conformance to new Unix standards. But usually the guts of the algorithms are still in place.

tags: ,

Comments:

Mike, OLD = SEASONED = NOT NAIVE = GOOD! Neat stuff, that original code!

Posted by William R. Walling on June 29, 2005 at 06:12 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

ford

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today