File:  [MW Coherent from dump] / coherent / d / conf / old_tboot / Examples / newdir.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:37 2019 UTC (7 years, 2 months ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

/* Bootable program to list files in /.
 * This is an example of an alternate bootable program.
 * Here is it's Makefile entry:
 * newdir: newdir.o $(OBJECTS) 
 *	$(LD) -o newdir $(OBJECTS) newdir.o $(LIBS)
 *
 * Take great care in selecting routines from libc.  In particular,
 * you can not use ANY of the stdio functions (including sprintf()).
 * Avoid anything else that might do system calls.
 *
 * La Monte H. Yarroll <[email protected]>, October 1991
 */

#include <ctype.h>
#include <canon.h>
#include <sys/types.h>
#include <sys/ino.h>
#include <sys/inode.h>
#include <sys/dir.h>
#include <a_out.h>

#define MAIN
#include "tboot.h"
#undef MAIN

main()
{
	int i, j;
	int fd;
	uint16 value;
	char outbuff[LINESIZE];	/* Buffer for outputing numbers.  */
	struct direct dirent;

	puts("Calling object_nlist().\r\n");
	/* Look up the name "rootdev" in "/at386".  */
	value = object_nlist(I386MAGIC, "at386", "rootdev");

	puts("rootdev ");
	/* Print out what we just found.  */
	puts("value:  0x");
	itobase((uint16) (value), outbuff, 16);
	puts(outbuff);
	puts("\r\n");
	
	/* Open "/" and print out the direct block file entries.  */
	if (-1 == (fd = open(".", 0))) {
		puts("Can't open /.\r\n");
		return;
	}	

	/* Read each directory entry one at a time.  */
	/* We are careful to print an even fraction of 80 for each
	 * directory entry, so that everything lines up nicely.
	 */
	while ( 0 != read(fd, (char *) &dirent, sizeof(struct direct)) ) {
		
		/* NUL terminate the name.  */
		strncpy(outbuff,
			dirent.d_name,
			DIRSIZ);
		outbuff[DIRSIZ] = '\0';
		/* Print the file name.  */
		puts(outbuff);
		for (j = DIRSIZ - strlen(outbuff); j > 0; --j) {
			putchar(' ');
		}
		puts(" :"); /* Bring total to 16 (80/5) characters.  */
	}
	
	close(fd);
	
} /* main() */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.