zoukankan      html  css  js  c++  java
  • zboot/piggyback.c

    /*
     *    linux/zBoot/piggyback.c
     *
     *    (C) 1993 Hannu Savolainen
     */

    /*
     *    This program reads the compressed system image from stdin and
     *    encapsulates it into an object file written to the stdout.
     */
    //这个程序读取压缩的system映像文件从标准输入然后压缩后写入标准输出
    #include <stdio.h>
    #include <unistd.h>
    #include <a.out.h>

    //主函数
    int main(int argc, char *argv[])
    {
        int c, n=0, len=0;
        //定义缓冲区
        char tmp_buf[512*1024];
        
        //可执行文件头
        struct exec obj = {0x00640107};    /* object header */
        //输入的数据和输入的长度
        char string_names[] = {"_input_data_input_len"};

        //标号表,变量名
        struct nlist var_names[2] = /* Symbol table */
            {    
                {    /* _input_data    */
                    (char *)4, 7, 0, 0, 0
                },
                {    /* _input_len */
                    (char *)16, 7, 0, 0, 0
                }
            };


        len = 0;
        //从标准输入中读取数据到缓冲区
        while ((n = read(0, &tmp_buf[len], sizeof(tmp_buf)-len+1)) > 0)
              len += n;

        //校验读取的长度
        if (n==-1)
        {
            perror("stdin");
            exit(-1);
        }

        if (len >= sizeof(tmp_buf))
        {
            fprintf(stderr, "%s: Input too large ", argv[0]);
            exit(-1);
        }

        //输出长度信息
        fprintf(stderr, "Compressed size %d. ", len);

    /*
     *    Output object header
     */
        //输出对象头
        obj.a_data = len + sizeof(long);
        obj.a_syms = sizeof(var_names);
        write(1, (char *)&obj, sizeof(obj));

    /*
     *    Output data segment (compressed system & len)
     */
        //输出数据段
        write(1, tmp_buf, len);
        write(1, (char *)&len, sizeof(len));

    /*
     *    Output symbol table
     */
        //输出符号表
        var_names[1].n_value = len;
        write(1, (char *)&var_names, sizeof(var_names));

    /*
     *    Output string table
     */
        //输出字符表
        len = sizeof(string_names) + sizeof(len);
        write(1, (char *)&len, sizeof(len));
        write(1, string_names, sizeof(string_names));

        exit(0);

    }

  • 相关阅读:
    how to uninstall devkit
    asp.net中bin目录下的 dll.refresh文件
    查找2个分支的共同父节点
    Three ways to do WCF instance management
    WCF Concurrency (Single, Multiple, and Reentrant) and Throttling
    检查string是否为double
    How to hide TabPage from TabControl
    获取当前系统中的时区
    git svn cygwin_exception
    lodoop打印控制具体解释
  • 原文地址:https://www.cnblogs.com/xiaofengwei/p/3753351.html
Copyright © 2011-2022 走看看