• 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);

    }

  • 相关阅读:
    JS基础
    NodeJs实现他人项目实例
    Node.js在任意目录下使用express命令‘不是内部或外部命令’解决方法
    HTTP基本知识
    RESTful API
    基本概念和方法1
    Node.js--安装express以及创建第一个express项目(windows)
    Node-debug方法
    css3动画划过有一个框
    translate 动画不同时间飞入文字
  • 原文地址:https://www.cnblogs.com/xiaofengwei/p/3753351.html
Copyright © 2020-2023  润新知