(root)/
strace-6.5/
tests-mx32/
fallocate.c
       1  /*
       2   * Check decoding of fallocate syscall.
       3   *
       4   * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
       5   * Copyright (c) 2016-2021 The strace developers.
       6   * All rights reserved.
       7   *
       8   * SPDX-License-Identifier: GPL-2.0-or-later
       9   */
      10  
      11  #include "tests.h"
      12  
      13  #include "scno.h"
      14  
      15  #if defined(__NR_fallocate) && defined(HAVE_FALLOCATE) && HAVE_FALLOCATE
      16  
      17  # include <errno.h>
      18  # include <fcntl.h>
      19  # include <stdio.h>
      20  
      21  # ifndef FALLOC_FL_UNSHARE_RANGE
      22  /* Avoid conflicts between <fcntl.h> and <linux/falloc.h>.  */
      23  #  undef FALLOC_FL_KEEP_SIZE
      24  #  undef FALLOC_FL_PUNCH_HOLE
      25  #  undef FALLOC_FL_NO_HIDE_STALE
      26  #  undef FALLOC_FL_COLLAPSE_RANGE
      27  #  undef FALLOC_FL_ZERO_RANGE
      28  #  undef FALLOC_FL_INSERT_RANGE
      29  #  include <linux/falloc.h>
      30  # endif
      31  
      32  # include "xlat.h"
      33  # include "xlat/falloc_flags.h"
      34  
      35  int
      36  main(void)
      37  {
      38  	static const int bogus_fd = 0xbeefface;
      39  	static const int bogus_mode = 0xdeadca75;
      40  	static const off_t bogus_offset = (off_t) 0xbadc0dedda7a1057LLU;
      41  	static const off_t bogus_len = (off_t) 0xbadfaceca7b0d1e5LLU;
      42  
      43  	long rc = fallocate(bogus_fd, bogus_mode, bogus_offset, bogus_len);
      44  	/*
      45  	 * Workaround a bug fixed by commit glibc-2.11-346-gde240a0.
      46  	 */
      47  	if (rc > 0) {
      48  		errno = rc;
      49  		rc = -1;
      50  	}
      51  	const char *errstr = sprintrc(rc);
      52  
      53  	printf("fallocate(%d, ", bogus_fd);
      54  	printflags(falloc_flags, (unsigned) bogus_mode, "FALLOC_FL_???");
      55  	printf(", %lld, %lld) = %s\n",
      56  	       (long long) bogus_offset, (long long) bogus_len, errstr);
      57  
      58  	puts("+++ exited with 0 +++");
      59  
      60  	return 0;
      61  }
      62  
      63  #else
      64  
      65  SKIP_MAIN_UNDEFINED("__NR_fallocate && HAVE_FALLOCATE");
      66  
      67  #endif