From: VMware, Inc <> Date: Tue, 28 Jun 2011 20:20:02 +0000 (-0700) Subject: Stage compat_log2.h. X-Git-Tag: 2011.06.27-437995~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=166bbe1d28da4dab763b9568f163c8dca99ced9c;p=thirdparty%2Fopen-vm-tools.git Stage compat_log2.h. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/modules/linux/shared/compat_log2.h b/open-vm-tools/modules/linux/shared/compat_log2.h new file mode 100644 index 000000000..318304918 --- /dev/null +++ b/open-vm-tools/modules/linux/shared/compat_log2.h @@ -0,0 +1,60 @@ +/********************************************************* + * Copyright (C) 2011 VMware, Inc. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 and no later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *********************************************************/ + +#ifndef __COMPAT_LOG2_H__ +# define __COMPAT_LOG2_H__ + +#ifndef LINUX_VERSION_CODE +# error "Include compat_version.h before compat_log2.h" +#endif + +/* linux/log2.h was introduced in 2.6.20. */ +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 19) +# include +#endif + +/* + * is_power_of_2 was introduced in 2.6.21. This implementation is almost + * identical to the one found there. + */ +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 20) +#define compat_is_power_of_2(n) is_power_of_2(n) +#else +static inline __attribute__((const)) +int compat_is_power_of_2(unsigned long n) +{ + return (n != 0 && ((n && (n - 1)) == 0)); +} +#endif + +/* + * rounddown_power_of_two was introduced in 2.6.24. This implementation is + * similar to the one in log2.h but with input of int instead of long to + * avoid more version related checks for fls_long(). + */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) +#define compat_rounddown_pow_of_two(n) rounddown_pow_of_two(n) +#else +static inline __attribute__((const)) +unsigned int compat_rounddown_pow_of_two(unsigned int n) +{ + return 1U << (fls(n) -1); +} +#endif + +#endif /* __COMPAT_LOG2_H__ */