Skip to content

Commit 4aba12d

Browse files
tpetazzonitytso
authored andcommitted
configure: check for FS_IOC_READ_VERITY_METADATA availability
Commit 6bfa843 ("mke2fs: enable copying of fs-verity metadata") introduced support for reading fs-verity metadata, which requires using the FS_IOC_READ_VERITY_METADATA. The code is conditionally compiled when the kernel headers have <linux/fsverity.h> available. Unfortunately, this check is not sufficient: <linux/fsverity.h> was introduced in Linux 5.10, but the FS_IOC_READ_VERITY_METADATA was not introduced before 5.12, so if one is using 5.10 or 5.11 kernel headers, the build fails with: ./../misc/create_inode.c: In function ‘copy_fs_verity_data’: ./../misc/create_inode.c:589:10: error: variable ‘arg’ has initializer but incomplete type 589 | struct fsverity_read_metadata_arg arg = { | ^~~~~~~~~~~~~~~~~~~~~~~~~~ [...] ./../misc/create_inode.c:600:20: error: ‘FS_IOC_READ_VERITY_METADATA’ undeclared (first use in this function) 600 | size = ioctl(fd, FS_IOC_READ_VERITY_METADATA, &arg); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ This commit therefore extends the configure.ac check to ensure that not only <linux/fsverity.h> exists but also that it defines the FS_IOC_READ_VERITY_METADATA ioctl. Closes: #256 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
1 parent 6f03c69 commit 4aba12d

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

configure

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16823,6 +16823,44 @@ case "$host_os" in
1682316823
esac
1682416824

1682516825

16826+
if test "${ac_cv_header_linux_fsverity_h}" = "yes"; then
16827+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for FS_IOC_READ_VERITY_METADATA ioctl" >&5
16828+
printf %s "checking for FS_IOC_READ_VERITY_METADATA ioctl... " >&6; }
16829+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
16830+
/* end confdefs.h. */
16831+
16832+
#include <linux/fsverity.h>
16833+
#ifndef FS_IOC_READ_VERITY_METADATA
16834+
# error "FS_IOC_READ_VERITY_METADATA not available"
16835+
#endif
16836+
16837+
int
16838+
main (void)
16839+
{
16840+
16841+
;
16842+
return 0;
16843+
}
16844+
_ACEOF
16845+
if ac_fn_c_try_cpp "$LINENO"
16846+
then :
16847+
16848+
16849+
printf "%s\n" "#define HAVE_FS_IOC_READ_VERITY_METADATA 1" >>confdefs.h
16850+
16851+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
16852+
printf "%s\n" "yes" >&6; }
16853+
16854+
else case e in #(
16855+
e)
16856+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
16857+
printf "%s\n" "no" >&6; }
16858+
;;
16859+
esac
16860+
fi
16861+
rm -f conftest.err conftest.i conftest.$ac_ext
16862+
fi
16863+
1682616864
test -d lib || mkdir lib
1682716865
test -d include || mkdir include
1682816866
test -d include/linux || mkdir include/linux

configure.ac

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,24 @@ OS_IO_FILE=""
19971997
esac]
19981998
AC_SUBST(OS_IO_FILE)
19991999

2000+
dnl Check for fsverity ioctl
2001+
if test "${ac_cv_header_linux_fsverity_h}" = "yes"; then
2002+
AC_MSG_CHECKING([for FS_IOC_READ_VERITY_METADATA ioctl])
2003+
AC_PREPROC_IFELSE(
2004+
[AC_LANG_PROGRAM([[
2005+
#include <linux/fsverity.h>
2006+
#ifndef FS_IOC_READ_VERITY_METADATA
2007+
# error "FS_IOC_READ_VERITY_METADATA not available"
2008+
#endif
2009+
]], [])], [
2010+
AC_DEFINE([HAVE_FS_IOC_READ_VERITY_METADATA], [1], [Define to 1 if FS_IOC_READ_VERITY_METADATA ioctl is available])
2011+
AC_MSG_RESULT([yes])
2012+
],
2013+
[
2014+
AC_MSG_RESULT([no])
2015+
])
2016+
fi
2017+
20002018
dnl
20012019
dnl Make our output files, being sure that we create the some miscellaneous
20022020
dnl directories

misc/create_inode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#ifdef HAVE_SYS_SYSMACROS_H
3131
#include <sys/sysmacros.h>
3232
#endif
33-
#ifdef HAVE_LINUX_FSVERITY_H
33+
#if defined(HAVE_LINUX_FSVERITY_H) && defined(HAVE_FS_IOC_READ_VERITY_METADATA)
3434
#include <linux/fsverity.h>
3535
#include <linux/fs.h>
3636
#endif
@@ -569,7 +569,7 @@ static errcode_t try_fiemap_copy(ext2_filsys fs, int fd, ext2_file_t e2_file,
569569
}
570570
#endif /* FS_IOC_FIEMAP */
571571

572-
#ifdef HAVE_LINUX_FSVERITY_H
572+
#if defined(HAVE_LINUX_FSVERITY_H) && defined(HAVE_FS_IOC_READ_VERITY_METADATA)
573573
static inline off_t round_up(off_t n, off_t blksz, off_t bias)
574574
{
575575
return ((n - bias + (blksz - 1)) & ~(blksz - 1)) + bias;
@@ -738,7 +738,7 @@ static errcode_t copy_file(ext2_filsys fs, int fd, struct stat *statbuf,
738738
err = copy_file_chunk(fs, fd, e2_file, 0, statbuf->st_size, buf,
739739
zerobuf);
740740

741-
#ifdef HAVE_LINUX_FSVERITY_H
741+
#if defined(HAVE_LINUX_FSVERITY_H) && defined(HAVE_FS_IOC_READ_VERITY_METADATA)
742742
if (!err && (flags & EXT4_VERITY_FL))
743743
err = copy_fs_verity(fs, fd, e2_file, statbuf->st_size);
744744
#endif

0 commit comments

Comments
 (0)