| 1 |
/* COVERAGE: name_to_handle_at open_by_handle_at */ |
| 2 |
|
| 3 |
#define _GNU_SOURCE |
| 4 |
#include <sys/types.h> |
| 5 |
#include <sys/stat.h> |
| 6 |
#include <fcntl.h> |
| 7 |
#include <stdio.h> |
| 8 |
#include <stdlib.h> |
| 9 |
#include <unistd.h> |
| 10 |
#include <errno.h> |
| 11 |
#include <string.h> |
| 12 |
#include <sys/syscall.h> |
| 13 |
|
| 14 |
int main() |
| 15 |
{ |
| 16 |
// glibc added support for name_to_handle_at() and open_by_handle_at() |
| 17 |
// in glibc 2.14. |
| 18 |
#if __GLIBC_PREREQ(2, 14) |
| 19 |
struct file_handle *fhp; |
| 20 |
int fd; |
| 21 |
int mount_id; |
| 22 |
|
| 23 |
fd = creat("foobar", S_IREAD|S_IWRITE); |
| 24 |
close(fd); |
| 25 |
|
| 26 |
/* Allocate an initial file_handle structure. */ |
| 27 |
fhp = malloc(sizeof(*fhp)); |
| 28 |
|
| 29 |
/* Make an initial call to name_to_handle_at() to discover |
| 30 |
* the real size required for the file_handle structure. */ |
| 31 |
fhp->handle_bytes = 0; |
| 32 |
name_to_handle_at(AT_FDCWD, "foobar", fhp, &mount_id, 0); |
| 33 |
//staptest// name_to_handle_at (AT_FDCWD, "foobar", XXXX, XXXX, 0x0) = NNNN |
| 34 |
|
| 35 |
/* Reallocate the file_handle structure with the correct size. */ |
| 36 |
fhp = realloc(fhp, sizeof(*fhp) + fhp->handle_bytes); |
| 37 |
|
| 38 |
/* Get a file handle. */ |
| 39 |
name_to_handle_at(AT_FDCWD, "foobar", fhp, &mount_id, 0); |
| 40 |
//staptest// name_to_handle_at (AT_FDCWD, "foobar", XXXX, XXXX, 0x0) = NNNN |
| 41 |
|
| 42 |
/* Now that we have a file handle, open up the file using the handle. */ |
| 43 |
fd = open_by_handle_at(AT_FDCWD, fhp, O_RDONLY); |
| 44 |
//staptest// open_by_handle_at (AT_FDCWD, XXXX, O_RDONLY) = NNNN |
| 45 |
|
| 46 |
close(fd); |
| 47 |
//staptest// close (NNNN) = NNNN |
| 48 |
|
| 49 |
/* Limit testing. */ |
| 50 |
name_to_handle_at(-1, "foobar", fhp, &mount_id, AT_EMPTY_PATH); |
| 51 |
//staptest// name_to_handle_at (-1, "foobar", XXXX, XXXX, AT_EMPTY_PATH) = NNNN |
| 52 |
|
| 53 |
name_to_handle_at(AT_FDCWD, (char *)-1, fhp, &mount_id, AT_SYMLINK_FOLLOW); |
| 54 |
#ifdef __s390__ |
| 55 |
//staptest// name_to_handle_at (AT_FDCWD, 0x[7]?[f]+, XXXX, XXXX, AT_SYMLINK_FOLLOW) = NNNN |
| 56 |
#else |
| 57 |
//staptest// name_to_handle_at (AT_FDCWD, 0x[f]+, XXXX, XXXX, AT_SYMLINK_FOLLOW) = NNNN |
| 58 |
#endif |
| 59 |
|
| 60 |
name_to_handle_at(AT_FDCWD, "foobar", (struct file_handle *)-1, &mount_id, 0); |
| 61 |
#ifdef __s390__ |
| 62 |
//staptest// name_to_handle_at (AT_FDCWD, "foobar", 0x[7]?[f]+, XXXX, 0x0) = NNNN |
| 63 |
#else |
| 64 |
//staptest// name_to_handle_at (AT_FDCWD, "foobar", 0x[f]+, XXXX, 0x0) = NNNN |
| 65 |
#endif |
| 66 |
|
| 67 |
name_to_handle_at(AT_FDCWD, "foobar", fhp, (int *)-1, 0); |
| 68 |
#ifdef __s390__ |
| 69 |
//staptest// name_to_handle_at (AT_FDCWD, "foobar", XXXX, 0x[7]?[f]+, 0x0) = NNNN |
| 70 |
#else |
| 71 |
//staptest// name_to_handle_at (AT_FDCWD, "foobar", XXXX, 0x[f]+, 0x0) = NNNN |
| 72 |
#endif |
| 73 |
|
| 74 |
name_to_handle_at(AT_FDCWD, "foobar", fhp, &mount_id, -1); |
| 75 |
//staptest// name_to_handle_at (AT_FDCWD, "foobar", XXXX, XXXX, AT_[^ ]+|XXXX) = NNNN |
| 76 |
|
| 77 |
fd = open_by_handle_at(-1, fhp, O_RDONLY); |
| 78 |
//staptest// open_by_handle_at (-1, XXXX, O_RDONLY) = NNNN |
| 79 |
|
| 80 |
fd = open_by_handle_at(AT_FDCWD, (struct file_handle *)-1, O_RDONLY); |
| 81 |
//staptest// open_by_handle_at (AT_FDCWD, 0x[f]+, O_RDONLY) = NNNN |
| 82 |
|
| 83 |
fd = open_by_handle_at(AT_FDCWD, fhp, -1); |
| 84 |
//staptest// open_by_handle_at (AT_FDCWD, XXXX, O_[^ ]+|XXXX) = NNNN |
| 85 |
|
| 86 |
#endif |
| 87 |
return 0; |
| 88 |
} |