Hacker News new | ask | show | jobs
by JdeBP 41 days ago
In Unix Seventh Edition, ls and others read directory entries with fread() and parsed the struct direct themselves in application-mode code. The C library and application mode matter, here.

On the gripping hand, there is no strncpy in the Spinellis 7th Edition source code; 4.2BSD was using strncpy() inside readdir() in 1982, though.

2 comments

login used it, but not for directory entries:

https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/lo...

The code, but not the function, occurred in multiple places in the V6 kernel and userland.

> The code, but not the function, occurred in multiple places in the V6 kernel and userland.

Yep. The code is essential given the design of the direct structure, which harkens back to the fixed-width data fields of punched cards.

It doesn't have anything to do with punch cards, it's to pack as many elements as possible into the very small amounts of memory on PDP-11s. A 16 byte directory structure (which divides evenly into a disk sector) with a 2 byte inode number and an up to 14 byte name is a memory-optimized structure, and memory optimization drove everything on UNIX. (I've been programming since 1965, used punch cards for a decade, was a UNIX V6/V7/PWB kernel and userland developer for a different decade).
I know the guy said "harkens", and I pointed out that it's wrong (but maybe he doesn't understand what it means, and thinks it's the same as "reminds me of"). Fixed size fields both precede and follow punch cards ... they are still used today in every struct.
I said "harkens". Of course that structure never appeared on a punched card, and was designed with the unix block size in mind.