Annotation of linux/tools/build.c, revision 1.1.1.2

1.1       root        1: #include <stdio.h>     /* fprintf */
                      2: #include <stdlib.h>    /* contains exit */
                      3: #include <sys/types.h> /* unistd.h needs this */
                      4: #include <unistd.h>    /* contains read/write */
                      5: #include <fcntl.h>
                      6: 
                      7: #define MINIX_HEADER 32
                      8: #define GCC_HEADER 1024
                      9: 
                     10: void die(char * str)
                     11: {
                     12:        fprintf(stderr,"%s\n",str);
                     13:        exit(1);
                     14: }
                     15: 
                     16: void usage(void)
                     17: {
                     18:        die("Usage: build boot system [> image]");
                     19: }
                     20: 
                     21: int main(int argc, char ** argv)
                     22: {
                     23:        int i,c,id;
                     24:        char buf[1024];
                     25: 
                     26:        if (argc != 3)
                     27:                usage();
                     28:        for (i=0;i<sizeof buf; i++) buf[i]=0;
                     29:        if ((id=open(argv[1],O_RDONLY,0))<0)
                     30:                die("Unable to open 'boot'");
                     31:        if (read(id,buf,MINIX_HEADER) != MINIX_HEADER)
                     32:                die("Unable to read header of 'boot'");
                     33:        if (((long *) buf)[0]!=0x04100301)
                     34:                die("Non-Minix header of 'boot'");
                     35:        if (((long *) buf)[1]!=MINIX_HEADER)
                     36:                die("Non-Minix header of 'boot'");
                     37:        if (((long *) buf)[3]!=0)
                     38:                die("Illegal data segment in 'boot'");
                     39:        if (((long *) buf)[4]!=0)
                     40:                die("Illegal bss in 'boot'");
                     41:        if (((long *) buf)[5] != 0)
                     42:                die("Non-Minix header of 'boot'");
                     43:        if (((long *) buf)[7] != 0)
                     44:                die("Illegal symbol table in 'boot'");
                     45:        i=read(id,buf,sizeof buf);
                     46:        fprintf(stderr,"Boot sector %d bytes.\n",i);
                     47:        if (i>510)
                     48:                die("Boot block may not exceed 510 bytes");
                     49:        buf[510]=0x55;
                     50:        buf[511]=0xAA;
                     51:        i=write(1,buf,512);
                     52:        if (i!=512)
                     53:                die("Write call failed");
                     54:        close (id);
                     55:        
                     56:        if ((id=open(argv[2],O_RDONLY,0))<0)
                     57:                die("Unable to open 'system'");
                     58:        if (read(id,buf,GCC_HEADER) != GCC_HEADER)
                     59:                die("Unable to read header of 'system'");
                     60:        if (((long *) buf)[5] != 0)
                     61:                die("Non-GCC header of 'system'");
                     62:        for (i=0 ; (c=read(id,buf,sizeof buf))>0 ; i+=c )
                     63:                if (write(1,buf,c)!=c)
                     64:                        die("Write call failed");
1.1.1.2 ! root       65: 
        !            66:        /* only needed by qemu. ( qemu may not read last sector if
        !            67:         * size is < 512 bytes ) 
        !            68:         */
        !            69:        memset(buf,0,512);
        !            70:        write(1,buf,512);       
        !            71: 
1.1       root       72:        close(id);
                     73:        fprintf(stderr,"System %d bytes.\n",i);
                     74:        return(0);
                     75: }

unix.superglobalmegacorp.com

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