Annotation of coherent/d/conf/tboot/bootcmd.c, revision 1.1

1.1     ! root        1: static char _version[]="boot_cmd version 1.0";
        !             2: /*
        !             3:  * This is a standalone program to extract the
        !             4:  * command line from /dev/boot_gift.
        !             5:  *
        !             6:  * Prints the command line on stdout with spaces between arguments.
        !             7:  * If there was not command line (i.e. tboot ran /autoboot),
        !             8:  * there will be no output.
        !             9:  *
        !            10:  * An exit value of 0 is normal.
        !            11:  * An exit value of 1 indicates that there was no command line.
        !            12:  * An exit value of 2 indicates that there is an abnormal
        !            13:  * condition--there will be an error message on stderr.
        !            14:  */
        !            15: #include <fcntl.h>
        !            16: #define KERNEL
        !            17: #include <sys/typed.h>
        !            18: 
        !            19: TYPED_SPACE(boot_gift, BG_LEN, T_FIFO_SIC);
        !            20: 
        !            21: #define fd_stdout      1
        !            22: #define fd_stderr      2
        !            23: void
        !            24: main()
        !            25: {
        !            26:        int fd;
        !            27:        FIFO *ffp;
        !            28:        typed_space *tp;
        !            29: 
        !            30:        /*
        !            31:         * Read the boot gift from /dev/boot_gift.
        !            32:         */
        !            33:        if (-1 == (fd = open("/dev/boot_gift", O_RDONLY))) {
        !            34:                write(fd_stderr, "Can not open /dev/boot_gift\n", 
        !            35:                        strlen("Can not open /dev/boot_gift\n") );
        !            36:                exit(2);
        !            37:        }
        !            38:        
        !            39:        if (0 == read(fd, &boot_gift, BG_LEN)) {
        !            40:                close(fd);
        !            41:                write(fd_stderr, "Can not read /dev/boot_gift\n",
        !            42:                        strlen("Can not read /dev/boot_gift\n") );
        !            43:                exit(2);
        !            44:        }
        !            45: 
        !            46:        close(fd);
        !            47: 
        !            48:        /*
        !            49:         * Find the command line in the boot gift.
        !            50:         */
        !            51:        ffp = fifo_open(&boot_gift, 0);
        !            52: 
        !            53:        if (F_NULL != ffp) {
        !            54:                while (T_NULL != (tp = fifo_read(ffp))) {
        !            55:                        if (T_STR_ARGF == tp->ts_type) {
        !            56:                                break;
        !            57:                        }
        !            58:                }
        !            59:        }
        !            60:        
        !            61:        fifo_close(ffp);
        !            62: 
        !            63:        /*
        !            64:         * We've found the command line.  
        !            65:         */
        !            66:        if (T_NULL != tp) {
        !            67:                /* Recast the argument list, so we can read it.  */
        !            68:                RETYPE(tp, T_FIFO_SIC);
        !            69:                ffp = fifo_open(tp, 0);
        !            70:                while (T_NULL != (tp = fifo_read(ffp))) {
        !            71:                        if (T_STR_STR == tp->ts_type) {
        !            72:                                /*
        !            73:                                 * Print out each command item, followed
        !            74:                                 * by a space.
        !            75:                                 */
        !            76:                                write(fd_stdout, tp->ts_data,
        !            77:                                        strlen(tp->ts_data));
        !            78:                                write(fd_stdout, " ", strlen(" ") );
        !            79:                        } else {
        !            80:                                /*
        !            81:                                 * Illegal item found in the command line.
        !            82:                                 */
        !            83:                                write(fd_stderr, "/dev/bootgift is corrupt.\n",
        !            84:                                      strlen("/dev/bootgift is corrupt.\n") );
        !            85:                                fifo_close(ffp);
        !            86:                                exit(2);
        !            87:                        }
        !            88:                } /* while there are more command arguments */
        !            89:                fifo_close(ffp);
        !            90:                write(1, "\n", 1);
        !            91:                exit(0);
        !            92:        } else {
        !            93:                /*
        !            94:                 * There was no command line.  Generate no output,
        !            95:                 * but exit 1 to indicate this fact.
        !            96:                 */
        !            97:                exit(1);
        !            98:        }
        !            99:        write(fd_stdout, "Unreachable code in main().\n",
        !           100:                strlen("Unreachable code in main().\n") );
        !           101: } /* main() */

unix.superglobalmegacorp.com

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