source: rtems/cpukit/libfs/src/jffs2/src/compr.c @ 6ac6a5c8

Last change on this file since 6ac6a5c8 was 6ac6a5c8, checked in by Sebastian Huber <sebastian.huber@…>, on Mar 27, 2018 at 11:01:56 AM

jffs2: Do not use command line defines

Update #3375.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1#include "rtems-jffs2-config.h"
2
3/*
4 * JFFS2 -- Journalling Flash File System, Version 2.
5 *
6 * Copyright © 2001-2007 Red Hat, Inc.
7 * Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
8 * Copyright © 2004 Ferenc Havasi <havasi@inf.u-szeged.hu>,
9 *                  University of Szeged, Hungary
10 * Copyright © 2013 embedded brains GmbH <rtems@embedded-brains.de>
11 *
12 * Created by Arjan van de Ven <arjan@infradead.org>
13 *
14 * For licensing information, see the file 'LICENCE' in this directory.
15 *
16 */
17
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
20#include "compr.h"
21
22/* jffs2_compress:
23 * @data_in: Pointer to uncompressed data
24 * @cpage_out: Pointer to returned pointer to buffer for compressed data
25 * @datalen: On entry, holds the amount of data available for compression.
26 *      On exit, expected to hold the amount of data actually compressed.
27 * @cdatalen: On entry, holds the amount of space available for compressed
28 *      data. On exit, expected to hold the actual size of the compressed
29 *      data.
30 *
31 * Returns: Lower byte to be stored with data indicating compression type used.
32 * Zero is used to show that the data could not be compressed - the
33 * compressed version was actually larger than the original.
34 * Upper byte will be used later. (soon)
35 *
36 * If the cdata buffer isn't large enough to hold all the uncompressed data,
37 * jffs2_compress should compress as much as will fit, and should set
38 * *datalen accordingly to show the amount of data which were compressed.
39 */
40uint16_t jffs2_compress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
41                        unsigned char *data_in, unsigned char **cpage_out,
42                        uint32_t *datalen, uint32_t *cdatalen)
43{
44        struct super_block *sb = OFNI_BS_2SFFJ(c);
45        rtems_jffs2_compressor_control *cc = sb->s_compressor_control;
46        int ret;
47
48        if (cc != NULL) {
49                *cpage_out = &cc->buffer[0];
50                ret = (*cc->compress)(cc, data_in, *cpage_out, datalen, cdatalen);
51        } else {
52                ret = JFFS2_COMPR_NONE;
53        }
54
55        if (ret == JFFS2_COMPR_NONE) {
56                *cpage_out = data_in;
57                *datalen = *cdatalen;
58        }
59        return ret;
60}
61
62int jffs2_decompress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
63                     uint16_t comprtype, unsigned char *cdata_in,
64                     unsigned char *data_out, uint32_t cdatalen, uint32_t datalen)
65{
66        struct super_block *sb = OFNI_BS_2SFFJ(c);
67        rtems_jffs2_compressor_control *cc = sb->s_compressor_control;
68
69        /* Older code had a bug where it would write non-zero 'usercompr'
70           fields. Deal with it. */
71        if ((comprtype & 0xff) <= JFFS2_COMPR_ZLIB)
72                comprtype &= 0xff;
73
74        switch (comprtype & 0xff) {
75        case JFFS2_COMPR_NONE:
76                /* This should be special-cased elsewhere, but we might as well deal with it */
77                memcpy(data_out, cdata_in, datalen);
78                break;
79        case JFFS2_COMPR_ZERO:
80                memset(data_out, 0, datalen);
81                break;
82        default:
83                if (cc != NULL) {
84                        return (*cc->decompress)(cc, comprtype, cdata_in, data_out, cdatalen, datalen);
85                } else {
86                        return -EIO;
87                }
88        }
89        return 0;
90}
Note: See TracBrowser for help on using the repository browser.