File: handle_at.c

package info (click to toggle)
systemtap 5.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 47,964 kB
  • sloc: cpp: 80,838; ansic: 54,757; xml: 49,725; exp: 43,665; sh: 11,527; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (88 lines) | stat: -rw-r--r-- 3,023 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* COVERAGE:  name_to_handle_at open_by_handle_at */

#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/syscall.h>

int main()
{
// glibc added support for name_to_handle_at() and open_by_handle_at()
// in glibc 2.14.
#if __GLIBC_PREREQ(2, 14)
    struct file_handle *fhp;
    int fd;
    int mount_id;

    fd = creat("foobar", S_IREAD|S_IWRITE);
    close(fd);

    /* Allocate an initial file_handle structure. */
    fhp = malloc(sizeof(*fhp));

    /* Make an initial call to name_to_handle_at() to discover
     * the real size required for the file_handle structure. */
    fhp->handle_bytes = 0;
    name_to_handle_at(AT_FDCWD, "foobar", fhp, &mount_id, 0);
    //staptest// name_to_handle_at (AT_FDCWD, "foobar", XXXX, XXXX, 0x0) = NNNN

    /* Reallocate the file_handle structure with the correct size. */
    fhp = realloc(fhp, sizeof(*fhp) + fhp->handle_bytes);

    /* Get a file handle. */
    name_to_handle_at(AT_FDCWD, "foobar", fhp, &mount_id, 0);
    //staptest// name_to_handle_at (AT_FDCWD, "foobar", XXXX, XXXX, 0x0) = NNNN
    
    /* Now that we have a file handle, open up the file using the handle. */
    fd = open_by_handle_at(AT_FDCWD, fhp, O_RDONLY);
    //staptest// open_by_handle_at (AT_FDCWD, XXXX, O_RDONLY) = NNNN

    close(fd);
    //staptest// close (NNNN) = NNNN

    /* Limit testing. */
    name_to_handle_at(-1, "foobar", fhp, &mount_id, AT_EMPTY_PATH);
    //staptest// name_to_handle_at (-1, "foobar", XXXX, XXXX, AT_EMPTY_PATH) = NNNN

    name_to_handle_at(AT_FDCWD, (char *)-1, fhp, &mount_id, AT_SYMLINK_FOLLOW);
#ifdef __s390__
    //staptest// name_to_handle_at (AT_FDCWD, 0x[7]?[f]+, XXXX, XXXX, AT_SYMLINK_FOLLOW) = NNNN
#else
    //staptest// name_to_handle_at (AT_FDCWD, 0x[f]+, XXXX, XXXX, AT_SYMLINK_FOLLOW) = NNNN
#endif

    name_to_handle_at(AT_FDCWD, "foobar", (struct file_handle *)-1, &mount_id, 0);
#ifdef __s390__
    //staptest// name_to_handle_at (AT_FDCWD, "foobar", 0x[7]?[f]+, XXXX, 0x0) = NNNN
#else
    //staptest// name_to_handle_at (AT_FDCWD, "foobar", 0x[f]+, XXXX, 0x0) = NNNN
#endif

    name_to_handle_at(AT_FDCWD, "foobar", fhp, (int *)-1, 0);
#ifdef __s390__
    //staptest// name_to_handle_at (AT_FDCWD, "foobar", XXXX, 0x[7]?[f]+, 0x0) = NNNN
#else
    //staptest// name_to_handle_at (AT_FDCWD, "foobar", XXXX, 0x[f]+, 0x0) = NNNN
#endif

    name_to_handle_at(AT_FDCWD, "foobar", fhp, &mount_id, -1);
    //staptest// name_to_handle_at (AT_FDCWD, "foobar", XXXX, XXXX, AT_[^ ]+|XXXX) = NNNN

    fd = open_by_handle_at(-1, fhp, O_RDONLY);
    //staptest// open_by_handle_at (-1, XXXX, O_RDONLY) = NNNN

    fd = open_by_handle_at(AT_FDCWD, (struct file_handle *)-1, O_RDONLY);
    //staptest// open_by_handle_at (AT_FDCWD, 0x[f]+, O_RDONLY) = NNNN

    fd = open_by_handle_at(AT_FDCWD, fhp, -1);
    //staptest// open_by_handle_at (AT_FDCWD, XXXX, O_[^ ]+|XXXX) = NNNN

#endif
    return 0;
}