⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 up_deviceimage.c

📁 這是一個實時嵌入式作業系統 實作了MCS51 ARM等MCU
💻 C
📖 第 1 页 / 共 2 页
字号:
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x77, 0x7d, 0x06};/**************************************************************************** * Private Functions ****************************************************************************//**************************************************************************** * Public Functions ****************************************************************************//**************************************************************************** * Name: up_deviceimage * * Description: Return an allocated buffer representing an in-memory VFAT *   file system. * ****************************************************************************/char *up_deviceimage(void){    char    *pbuffer;    int      bufsize = 1024*1024;    int      offset  = 0;    z_stream strm;    int      ret;    /* Ininitilize inflate state */    strm.zalloc   = Z_NULL;    strm.zfree    = Z_NULL;    strm.opaque   = Z_NULL;    strm.avail_in = 0;    strm.next_in  = Z_NULL;    ret           = inflateInit(&strm);    if (ret != Z_OK)      {        sdbg("inflateInit FAILED: ret=%d msg=\"%s\"\n", ret, strm.msg ? strm.msg : "No message" );        return NULL;      }    /* Allocate a buffer to hold the decompressed buffer.  We may have     * to reallocate this a few times to get the size right.     */    pbuffer = (char*)malloc(bufsize);    /* Set up the input buffer */    strm.avail_in = sizeof(g_vfatdata);    strm.next_in = (Bytef*)g_vfatdata;    /* Run inflate() on input until output buffer not full */    do {        /* Set up to catch the next output chunk in the output buffer */        strm.avail_out = bufsize - offset;        strm.next_out  = (Bytef*)&pbuffer[offset];        /* inflate */        ret = inflate(&strm, Z_NO_FLUSH);        /* Handle inflate() error return values */        switch (ret)          {            case Z_NEED_DICT:            case Z_DATA_ERROR:            case Z_MEM_ERROR:            case Z_STREAM_ERROR:                sdbg("inflate FAILED: ret=%d msg=\"%s\"\n", ret, strm.msg ? strm.msg : "No message" );                (void)inflateEnd(&strm);                free(pbuffer);                return NULL;          }        /* If avail_out is zero, then inflate() returned only         * because it is out of buffer space.  In this case, we         * will have to reallocate the buffer and try again.         */        if (strm.avail_out == 0)          {            int newbufsize = bufsize + 128*1024;            char *newbuffer = realloc(pbuffer, newbufsize);            if (!newbuffer)              {                free(pbuffer);                return NULL;              }            else              {                pbuffer = newbuffer;                offset  = bufsize;                bufsize = newbufsize;              }          }        else          {             /* There are unused bytes in the buffer, reallocate to              * correct size.              */             int newbufsize = bufsize - strm.avail_out;             char *newbuffer = realloc(pbuffer, newbufsize);             if (!newbuffer)               {                free(pbuffer);                return NULL;              }            else              {                pbuffer = newbuffer;                bufsize = newbufsize;              }          }    } while (strm.avail_out == 0 && ret != Z_STREAM_END);    (void)inflateEnd(&strm);    return pbuffer;}/**************************************************************************** * Name: main * * Description: Used to test decompression logic * *  gcc -g -Wall -DVFAT_STANDALONE -lz -o vfat-test up_deviceimage.c * ****************************************************************************/#ifdef VFAT_STANDALONEint main(int argc, char **argv, char **envp){    char *deviceimage;    int cmf;    int fdict;    int flg;    int check;    cmf = g_vfatdata[0];    printf("CMF=%02x: CM=%d CINFO=%d\n", cmf, cmf &0x0f, cmf >> 4);    flg   = g_vfatdata[1];    fdict = (flg >> 5) & 1;    printf("FLG=%02x: FCHECK=%d FDICT=%d FLEVEL=%d\n", flg, flg &0x1f, fdict, flg >> 6);    /* The FCHECK value must be such that CMF and FLG, when viewed as     * a 16-bit unsigned integer stored in MSB order (CMF*256 + FLG),     * is a multiple of 31.     */    check = cmf*256 + flg;    if (check % 31 != 0)    {        printf("Fails check: %04x is not a multiple of 31\n", check);    }    deviceimage = up_deviceimage();    if (deviceimage)    {        printf("Inflate SUCCEEDED\n");        free(deviceimage);        return 0;    }    else    {        printf("Inflate FAILED\n");        return 1;    }}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -