diff options
author | Karel Zak <kzak@redhat.com> | 2007-02-06 11:35:15 +0100 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2007-02-06 11:35:15 +0100 |
commit | 7ac3b5b8e3ec944e7cd3bcc6d992882c4d443414 (patch) | |
tree | 8670a08ffd55e656893f300ee0a8d75819ff5958 | |
parent | ca04734de12f317e4fa47da0ad6e7e3b45e8b3a8 (diff) | |
download | util-linux-old-7ac3b5b8e3ec944e7cd3bcc6d992882c4d443414.tar.gz |
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 <kzak@redhat.com>
-rw-r--r-- | config.h.in | 3 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | disk-utils/mkswap.c | 56 | ||||
-rw-r--r-- | sys-utils/ipcs.c | 3 | ||||
-rw-r--r-- | tests/helpers/mnt_test_sysinfo.c | 2 |
5 files changed, 23 insertions, 42 deletions
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 <asm/page.h> 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 <uuid/uuid.h> #endif -/* Try to get PAGE_SIZE from libc or kernel includes */ -#ifdef HAVE_SYS_USER_H - /* Note: <sys/user.h> says: for gdb only */ -#include <sys/user.h> /* for PAGE_SIZE and PAGE_SHIFT */ -#else -#ifdef HAVE_ASM_PAGE_H -#include <asm/page.h> /* 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 <time.h> #include <pwd.h> #include <grp.h> +#include <unistd.h> #include "nls.h" /* X/OPEN tells us to use <sys/{types,ipc,sem}.h> 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; } |