From: Karel Zak Date: Tue, 6 Feb 2007 10:35:15 +0000 (+0100) Subject: Clean up pagesize/PAGE_SIZE usage. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ac3b5b8e3ec944e7cd3bcc6d992882c4d443414;p=util-linux Clean up pagesize/PAGE_SIZE usage. Now all code in util-linux uses sysconf(_SC_PAGESIZE) that is standardized and preferred way of querying page size. The asm/page.h file is not included to the code anymore. (This patch doesn't change mount's FS detection code which will be removed later). Signed-off-by: Karel Zak --- diff --git a/config.h.in b/config.h.in index 3659702a..b486f264 100644 --- a/config.h.in +++ b/config.h.in @@ -4,9 +4,6 @@ language is requested. */ #undef ENABLE_NLS -/* Define to 1 if you have the header file. */ -#undef HAVE_ASM_PAGE_H - /* Define if the GNU dcgettext() function is already present or preinstalled. */ #undef HAVE_DCGETTEXT diff --git a/configure.ac b/configure.ac index 20349cd2..dd7da82c 100644 --- a/configure.ac +++ b/configure.ac @@ -26,7 +26,6 @@ AC_CHECK_HEADERS(linux/blkpg.h,,,[ ]) AC_CHECK_HEADERS(langinfo.h) AC_CHECK_HEADERS(sys/user.h) -AC_CHECK_HEADERS(asm/page.h) AC_CHECK_HEADERS(rpcsvc/nfs_prot.h) AC_CHECK_HEADERS(sys/io.h) AC_CHECK_HEADERS(pty.h) diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index 861290fe..cbf898c1 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -47,17 +47,6 @@ #include #endif -/* Try to get PAGE_SIZE from libc or kernel includes */ -#ifdef HAVE_SYS_USER_H - /* Note: says: for gdb only */ -#include /* for PAGE_SIZE and PAGE_SHIFT */ -#else -#ifdef HAVE_ASM_PAGE_H -#include /* for PAGE_SIZE and PAGE_SHIFT */ - /* we also get PAGE_SIZE via getpagesize() */ -#endif -#endif - #ifndef _IO /* pre-1.3.45 */ #define BLKGETSIZE 0x1260 @@ -142,22 +131,25 @@ is_sparc64(void) { #endif /* - * The definition of the union swap_header uses the constant PAGE_SIZE. - * Unfortunately, on some architectures this depends on the hardware model, - * and can only be found at run time -- we use getpagesize(), so that - * we do not need separate binaries e.g. for sun4, sun4c/d/m and sun4u. + * The definition of the union swap_header uses the kernel constant PAGE_SIZE. + * Unfortunately, on some architectures this depends on the hardware model, and + * can only be found at run time -- we use getpagesize(), so that we do not + * need separate binaries e.g. for sun4, sun4c/d/m and sun4u. + * + * Even more unfortunately, getpagesize() does not always return the right + * information. For example, libc4, libc5 and glibc 2.0 do not use the system + * call but invent a value themselves (EXEC_PAGESIZE or NBPG * CLSIZE or NBPC), + * and thus it may happen that e.g. on a sparc kernel PAGE_SIZE=4096 and + * getpagesize() returns 8192. * - * Even more unfortunately, getpagesize() does not always return - * the right information. For example, libc4 and libc5 do not use - * the system call but invent a value themselves - * (EXEC_PAGESIZE or NBPG * CLSIZE or NBPC), and thus it may happen - * that e.g. on a sparc PAGE_SIZE=4096 and getpagesize() returns 8192. * What to do? Let us allow the user to specify the pagesize explicitly. + * + * Update 05-Feb-2007 (kzak): + * - use sysconf(_SC_PAGESIZE) to be consistent with the rest of + * util-linux code. It is the standardized and preferred way of + * querying page size. */ - -static int user_pagesize = 0; -static int kernel_pagesize; /* obtained via getpagesize(); */ -static int defined_pagesize = 0; /* PAGE_SIZE, when that exists */ +static int user_pagesize; static int pagesize; static long *signature_page; struct swap_header_v1 *p; @@ -165,11 +157,7 @@ struct swap_header_v1 *p; static void init_signature_page(void) { -#ifdef PAGE_SIZE - defined_pagesize = PAGE_SIZE; -#endif - kernel_pagesize = getpagesize(); - pagesize = kernel_pagesize; + int kernel_pagesize = pagesize = (int) sysconf(_SC_PAGESIZE); if (user_pagesize) { if ((user_pagesize & (user_pagesize-1)) || @@ -181,14 +169,10 @@ init_signature_page(void) { pagesize = user_pagesize; } - if (user_pagesize && user_pagesize != kernel_pagesize && - user_pagesize != defined_pagesize) + if (user_pagesize && user_pagesize != kernel_pagesize) fprintf(stderr, _("Using user-specified page size %d, " - "instead of the system values %d/%d\n"), - pagesize, kernel_pagesize, defined_pagesize); - else if (defined_pagesize && pagesize != defined_pagesize) - fprintf(stderr, _("Assuming pages of size %d (not %d)\n"), - pagesize, defined_pagesize); + "instead of the system value %d\n"), + pagesize, kernel_pagesize); signature_page = (long *) malloc(pagesize); memset(signature_page, 0, pagesize); diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c index 4c2ec9a0..0c2316ba 100644 --- a/sys-utils/ipcs.c +++ b/sys-utils/ipcs.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "nls.h" /* X/OPEN tells us to use for semctl() */ @@ -280,7 +281,7 @@ void do_shm (char format) printf (_("max seg size (kbytes) = %lu\n"), (unsigned long) (shminfo.shmmax >> 10)); printf (_("max total shared memory (kbytes) = %llu\n"), - getpagesize()/1024 * (unsigned long long) shminfo.shmall); + sysconf(_SC_PAGESIZE) / 1024 * (unsigned long long) shminfo.shmall); printf (_("min seg size (bytes) = %lu\n"), (unsigned long) shminfo.shmmin); return; diff --git a/tests/helpers/mnt_test_sysinfo.c b/tests/helpers/mnt_test_sysinfo.c index 90cf0233..9bbcefa3 100644 --- a/tests/helpers/mnt_test_sysinfo.c +++ b/tests/helpers/mnt_test_sysinfo.c @@ -20,7 +20,7 @@ hlp_wordsize(void) int hlp_pagesize(void) { - printf("%d\n", getpagesize()); + printf("%d\n", (int) sysconf(_SC_PAGESIZE)); return 0; }