1*b0d29bc4SBrooks Davisdnl Copyright 2011 The Kyua Authors. 2*b0d29bc4SBrooks Davisdnl All rights reserved. 3*b0d29bc4SBrooks Davisdnl 4*b0d29bc4SBrooks Davisdnl Redistribution and use in source and binary forms, with or without 5*b0d29bc4SBrooks Davisdnl modification, are permitted provided that the following conditions are 6*b0d29bc4SBrooks Davisdnl met: 7*b0d29bc4SBrooks Davisdnl 8*b0d29bc4SBrooks Davisdnl * Redistributions of source code must retain the above copyright 9*b0d29bc4SBrooks Davisdnl notice, this list of conditions and the following disclaimer. 10*b0d29bc4SBrooks Davisdnl * Redistributions in binary form must reproduce the above copyright 11*b0d29bc4SBrooks Davisdnl notice, this list of conditions and the following disclaimer in the 12*b0d29bc4SBrooks Davisdnl documentation and/or other materials provided with the distribution. 13*b0d29bc4SBrooks Davisdnl * Neither the name of Google Inc. nor the names of its contributors 14*b0d29bc4SBrooks Davisdnl may be used to endorse or promote products derived from this software 15*b0d29bc4SBrooks Davisdnl without specific prior written permission. 16*b0d29bc4SBrooks Davisdnl 17*b0d29bc4SBrooks Davisdnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18*b0d29bc4SBrooks Davisdnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19*b0d29bc4SBrooks Davisdnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20*b0d29bc4SBrooks Davisdnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21*b0d29bc4SBrooks Davisdnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22*b0d29bc4SBrooks Davisdnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23*b0d29bc4SBrooks Davisdnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24*b0d29bc4SBrooks Davisdnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25*b0d29bc4SBrooks Davisdnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26*b0d29bc4SBrooks Davisdnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27*b0d29bc4SBrooks Davisdnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28*b0d29bc4SBrooks Davis 29*b0d29bc4SBrooks Davisdnl \file m4/fs.m4 30*b0d29bc4SBrooks Davisdnl File system related checks. 31*b0d29bc4SBrooks Davisdnl 32*b0d29bc4SBrooks Davisdnl The macros in this file check for features required in the utils/fs 33*b0d29bc4SBrooks Davisdnl module. The global KYUA_FS_MODULE macro will call all checks required 34*b0d29bc4SBrooks Davisdnl for the library. 35*b0d29bc4SBrooks Davis 36*b0d29bc4SBrooks Davis 37*b0d29bc4SBrooks Davisdnl KYUA_FS_GETCWD_DYN 38*b0d29bc4SBrooks Davisdnl 39*b0d29bc4SBrooks Davisdnl Checks whether getcwd(NULL, 0) works; i.e. if getcwd(3) can dynamically 40*b0d29bc4SBrooks Davisdnl allocate the output buffer to fit the whole current path. 41*b0d29bc4SBrooks DavisAC_DEFUN([KYUA_FS_GETCWD_DYN], [ 42*b0d29bc4SBrooks Davis AC_CACHE_CHECK( 43*b0d29bc4SBrooks Davis [whether getcwd(NULL, 0) works], 44*b0d29bc4SBrooks Davis [kyua_cv_getcwd_dyn], [ 45*b0d29bc4SBrooks Davis AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <stdlib.h> 46*b0d29bc4SBrooks Davis#include <unistd.h> 47*b0d29bc4SBrooks Davis], [ 48*b0d29bc4SBrooks Davis char *cwd = getcwd(NULL, 0); 49*b0d29bc4SBrooks Davis return (cwd != NULL) ? EXIT_SUCCESS : EXIT_FAILURE; 50*b0d29bc4SBrooks Davis])], 51*b0d29bc4SBrooks Davis [kyua_cv_getcwd_dyn=yes], 52*b0d29bc4SBrooks Davis [kyua_cv_getcwd_dyn=no]) 53*b0d29bc4SBrooks Davis ]) 54*b0d29bc4SBrooks Davis if test "${kyua_cv_getcwd_dyn}" = yes; then 55*b0d29bc4SBrooks Davis AC_DEFINE_UNQUOTED([HAVE_GETCWD_DYN], [1], 56*b0d29bc4SBrooks Davis [Define to 1 if getcwd(NULL, 0) works]) 57*b0d29bc4SBrooks Davis fi 58*b0d29bc4SBrooks Davis]) 59*b0d29bc4SBrooks Davis 60*b0d29bc4SBrooks Davis 61*b0d29bc4SBrooks Davisdnl KYUA_FS_LCHMOD 62*b0d29bc4SBrooks Davisdnl 63*b0d29bc4SBrooks Davisdnl Checks whether lchmod(3) exists and if it works. Some systems, such as 64*b0d29bc4SBrooks Davisdnl Ubuntu 10.04.1 LTS, provide a lchmod(3) stub that is not implemented yet 65*b0d29bc4SBrooks Davisdnl allows programs to compile cleanly (albeit for a warning). It would be 66*b0d29bc4SBrooks Davisdnl nice to detect if lchmod(3) works at run time to prevent side-effects of 67*b0d29bc4SBrooks Davisdnl this test but doing so means we will keep receiving a noisy compiler 68*b0d29bc4SBrooks Davisdnl warning. 69*b0d29bc4SBrooks DavisAC_DEFUN([KYUA_FS_LCHMOD], [ 70*b0d29bc4SBrooks Davis AC_CACHE_CHECK( 71*b0d29bc4SBrooks Davis [for a working lchmod], 72*b0d29bc4SBrooks Davis [kyua_cv_lchmod_works], [ 73*b0d29bc4SBrooks Davis AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <sys/stat.h> 74*b0d29bc4SBrooks Davis#include <fcntl.h> 75*b0d29bc4SBrooks Davis#include <stdio.h> 76*b0d29bc4SBrooks Davis#include <stdlib.h> 77*b0d29bc4SBrooks Davis#include <unistd.h> 78*b0d29bc4SBrooks Davis], [ 79*b0d29bc4SBrooks Davis int fd = open("conftest.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644); 80*b0d29bc4SBrooks Davis if (fd == -1) { 81*b0d29bc4SBrooks Davis perror("creation of conftest.txt failed"); 82*b0d29bc4SBrooks Davis return EXIT_FAILURE; 83*b0d29bc4SBrooks Davis } 84*b0d29bc4SBrooks Davis 85*b0d29bc4SBrooks Davis return lchmod("conftest.txt", 0640) != -1 ? EXIT_SUCCESS : EXIT_FAILURE; 86*b0d29bc4SBrooks Davis])], 87*b0d29bc4SBrooks Davis [kyua_cv_lchmod_works=yes], 88*b0d29bc4SBrooks Davis [kyua_cv_lchmod_works=no]) 89*b0d29bc4SBrooks Davis ]) 90*b0d29bc4SBrooks Davis rm -f conftest.txt 91*b0d29bc4SBrooks Davis if test "${kyua_cv_lchmod_works}" = yes; then 92*b0d29bc4SBrooks Davis AC_DEFINE_UNQUOTED([HAVE_WORKING_LCHMOD], [1], 93*b0d29bc4SBrooks Davis [Define to 1 if your lchmod works]) 94*b0d29bc4SBrooks Davis fi 95*b0d29bc4SBrooks Davis]) 96*b0d29bc4SBrooks Davis 97*b0d29bc4SBrooks Davis 98*b0d29bc4SBrooks Davisdnl KYUA_FS_UNMOUNT 99*b0d29bc4SBrooks Davisdnl 100*b0d29bc4SBrooks Davisdnl Detect the correct method to unmount a file system. 101*b0d29bc4SBrooks DavisAC_DEFUN([KYUA_FS_UNMOUNT], [ 102*b0d29bc4SBrooks Davis AC_CHECK_FUNCS([unmount], [have_unmount2=yes], [have_unmount2=no]) 103*b0d29bc4SBrooks Davis if test "${have_unmount2}" = no; then 104*b0d29bc4SBrooks Davis have_umount8=yes 105*b0d29bc4SBrooks Davis AC_PATH_PROG([UMOUNT], [umount], [have_umount8=no]) 106*b0d29bc4SBrooks Davis if test "${have_umount8}" = yes; then 107*b0d29bc4SBrooks Davis AC_DEFINE_UNQUOTED([UMOUNT], ["${UMOUNT}"], 108*b0d29bc4SBrooks Davis [Set to the path of umount(8)]) 109*b0d29bc4SBrooks Davis else 110*b0d29bc4SBrooks Davis AC_MSG_ERROR([Don't know how to unmount a file system]) 111*b0d29bc4SBrooks Davis fi 112*b0d29bc4SBrooks Davis fi 113*b0d29bc4SBrooks Davis]) 114*b0d29bc4SBrooks Davis 115*b0d29bc4SBrooks Davis 116*b0d29bc4SBrooks Davisdnl KYUA_FS_MODULE 117*b0d29bc4SBrooks Davisdnl 118*b0d29bc4SBrooks Davisdnl Performs all checks needed by the utils/fs library. 119*b0d29bc4SBrooks DavisAC_DEFUN([KYUA_FS_MODULE], [ 120*b0d29bc4SBrooks Davis AC_CHECK_HEADERS([sys/mount.h sys/statvfs.h sys/vfs.h]) 121*b0d29bc4SBrooks Davis AC_CHECK_FUNCS([statfs statvfs]) 122*b0d29bc4SBrooks Davis KYUA_FS_GETCWD_DYN 123*b0d29bc4SBrooks Davis KYUA_FS_LCHMOD 124*b0d29bc4SBrooks Davis KYUA_FS_UNMOUNT 125*b0d29bc4SBrooks Davis]) 126