Annotation of coherent/d/conf/tboot/Examples/dir.c, revision 1.1.1.1

1.1       root        1: /* Bootable program to list files in /.
                      2:  * This is an example of an alternate bootable program.
                      3:  * Here is it's Makefile entry:
                      4:  * dir: dir.o $(OBJECTS) 
                      5:  *     $(LD) -o dir $(OBJECTS) dir.o $(LIBS)
                      6:  *
                      7:  * Take great care in selecting routines from libc.  In particular,
                      8:  * you can not use ANY of the stdio functions (including sprintf()).
                      9:  * Avoid anything else that might do system calls.
                     10:  *
                     11:  * La Monte H. Yarroll <[email protected]>, September 1991
                     12:  */
                     13: 
                     14: #include <ctype.h>
                     15: #include <canon.h>
                     16: #include <sys/types.h>
                     17: #include <sys/ino.h>
                     18: #include <sys/inode.h>
                     19: #include <sys/dir.h>
                     20: #include "tboot.h"
                     21: 
                     22: main()
                     23: {
                     24:        int i, j;
                     25:        char outbuff[LINESIZE]; /* Buffer for outputing numbers.  */
                     26:        struct inode rootinode;
                     27:        struct direct dirent;
                     28: 
                     29:        /* Open "/" and print out the direct block file entries.  */
                     30:        iopen(&rootinode, (ino_t) 2);
                     31: 
                     32:        /* Read each directory entry one at a time.  */
                     33:        /* We are careful to print an even fraction of 80 for each
                     34:         * directory entry, so that everything lines up nicely.
                     35:         */
                     36:        for (i = 0; i < rootinode.i_size; i += sizeof(struct direct)) {
                     37: 
                     38:                iread(&rootinode, (char *) &dirent, (fsize_t) i,
                     39:                      (uint16) sizeof(struct direct));
                     40:                
                     41:                /* NUL terminate the name.  */
                     42:                strncpy(outbuff,
                     43:                        dirent.d_name,
                     44:                        DIRSIZ);
                     45:                outbuff[DIRSIZ] = '\0';
                     46:                /* Print the file name.  */
                     47:                puts(outbuff);
                     48:                for (j = DIRSIZ - strlen(outbuff); j > 0; --j) {
                     49:                        putchar(' ');
                     50:                }
                     51:                puts(" :"); /* Bring total to 16 (80/5) characters.  */
                     52:        }
                     53:        
                     54: } /* main() */

unix.superglobalmegacorp.com

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