FreeBSD ZFS
The Zettabyte File System
|
00001 /* 00002 * CDDL HEADER START 00003 * 00004 * The contents of this file are subject to the terms of the 00005 * Common Development and Distribution License (the "License"). 00006 * You may not use this file except in compliance with the License. 00007 * 00008 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 00009 * or http://www.opensolaris.org/os/licensing. 00010 * See the License for the specific language governing permissions 00011 * and limitations under the License. 00012 * 00013 * When distributing Covered Code, include this CDDL HEADER in each 00014 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 00015 * If applicable, add the following below this CDDL HEADER, with the 00016 * fields enclosed by brackets "[]" replaced with your own identifying 00017 * information: Portions Copyright [yyyy] [name of copyright owner] 00018 * 00019 * CDDL HEADER END 00020 */ 00021 00022 /* 00023 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 00024 * Use is subject to license terms. 00025 */ 00026 00027 #pragma ident "%Z%%M% %I% %E% SMI" 00028 00029 #include <sys/debug.h> 00030 #include <sys/types.h> 00031 #include <sys/zmod.h> 00032 00033 #ifdef _KERNEL 00034 #include <sys/systm.h> 00035 #else 00036 #include <strings.h> 00037 #endif 00038 00039 size_t 00040 gzip_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n) 00041 { 00042 size_t dstlen = d_len; 00043 00044 ASSERT(d_len <= s_len); 00045 00046 if (z_compress_level(d_start, &dstlen, s_start, s_len, n) != Z_OK) { 00047 if (d_len != s_len) 00048 return (s_len); 00049 00050 bcopy(s_start, d_start, s_len); 00051 return (s_len); 00052 } 00053 00054 return (dstlen); 00055 } 00056 00057 /*ARGSUSED*/ 00058 int 00059 gzip_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n) 00060 { 00061 size_t dstlen = d_len; 00062 00063 ASSERT(d_len >= s_len); 00064 00065 if (z_uncompress(d_start, &dstlen, s_start, s_len) != Z_OK) 00066 return (-1); 00067 00068 return (0); 00069 }