File: stubs-macros.h

package info (click to toggle)
libguestfs 1%3A1.48.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 98,368 kB
  • sloc: ansic: 376,405; ml: 38,310; sh: 10,217; java: 9,578; cs: 6,328; haskell: 5,674; makefile: 5,165; python: 3,800; perl: 2,454; erlang: 2,446; ruby: 350; xml: 303; pascal: 257; javascript: 157; cpp: 10
file content (120 lines) | stat: -rw-r--r-- 6,491 bytes parent folder | download | duplicates (2)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* libguestfs - the guestfsd daemon
 * Copyright (C) 2009-2020 Red Hat Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef GUESTFSD_STUBS_MACROS_H
#define GUESTFSD_STUBS_MACROS_H

/* Some macros to make resolving devices easier.  These used to
 * be available in daemon.h but now they are only used by stubs.
 */

/* All functions that need an argument that is a device or partition name
 * must call this macro.  It checks that the device exists and does
 * device name translation (described in the guestfs(3) manpage).
 * Note that the "path" argument may be modified.
 */
#define RESOLVE_DEVICE(path,path_out,is_filein)                         \
  do {									\
    (path_out) = device_name_translation ((path));                      \
    if ((path_out) == NULL) {                                           \
      const int err = errno;                                            \
      if (is_filein) cancel_receive ();                                 \
      errno = err;                                                      \
      reply_with_perror ("%s: %s", __func__, path);                     \
      return;							        \
    }                                                                   \
    if (!is_device_parameter ((path_out))) {                            \
      if (is_filein) cancel_receive ();                                 \
      reply_with_error ("%s: %s: expecting a device name", __func__, (path)); \
      return;							        \
    }									\
  } while (0)

/* All functions that take a mountable argument must call this macro.
 * It parses the mountable into a mountable_t, ensures any
 * underlying device exists, and does device name translation
 * (described in the guestfs(3) manpage).
 *
 * Note that the "string" argument may be modified.
 */
#define RESOLVE_MOUNTABLE(string,mountable,is_filein)                   \
  do {                                                                  \
    if (STRPREFIX ((string), "btrfsvol:")) {                            \
      if (parse_btrfsvol ((string) + strlen ("btrfsvol:"), &(mountable)) == -1)\
      {                                                                 \
        if (is_filein) cancel_receive ();                               \
        reply_with_error ("%s: %s: expecting a btrfs volume",           \
                          __func__, (string));                          \
        return;                                                         \
      }                                                                 \
    }                                                                   \
    else {                                                              \
      (mountable).type = MOUNTABLE_DEVICE;                              \
      (mountable).device = NULL;                                        \
      (mountable).volume = NULL;                                        \
      RESOLVE_DEVICE ((string), (mountable).device, (is_filein));       \
    }                                                                   \
  } while (0)

/* Helper for functions which need either an absolute path in the
 * mounted filesystem, OR a /dev/ device which exists.
 *
 * NB: Functions which mix filenames and device paths should be
 * avoided, and existing functions should be deprecated.  This is
 * because we intend in future to make device parameters a distinct
 * type from filenames.
 */
#define REQUIRE_ROOT_OR_RESOLVE_DEVICE(path,path_out,is_filein)         \
  do {									\
    if (is_device_parameter ((path)))                                   \
      RESOLVE_DEVICE ((path), (path_out), (is_filein));                 \
    else {								\
      NEED_ROOT ((is_filein), return);                                  \
      ABS_PATH ((path), (is_filein), return);                           \
      (path_out) = strdup ((path));                                     \
      if ((path_out) == NULL) {                                         \
        if (is_filein) cancel_receive ();                               \
        reply_with_perror ("strdup");                                   \
        return;                                                         \
      }                                                                 \
    }									\
  } while (0)

/* Helper for functions which need either an absolute path in the
 * mounted filesystem, OR a valid mountable description.
 */
#define REQUIRE_ROOT_OR_RESOLVE_MOUNTABLE(string, mountable, is_filein) \
  do {                                                                  \
    if (is_device_parameter ((string)) || (string)[0] != '/') {         \
      RESOLVE_MOUNTABLE ((string), (mountable), (is_filein));           \
    }                                                                   \
    else {                                                              \
      NEED_ROOT ((is_filein), return);                                  \
      /* NB: It's a path, not a device. */                              \
      (mountable).type = MOUNTABLE_PATH;                                \
      (mountable).device = strdup ((string));                           \
      (mountable).volume = NULL;                                        \
      if ((mountable).device == NULL) {                                 \
        if (is_filein) cancel_receive ();                               \
        reply_with_perror ("strdup");                                   \
        return;                                                         \
      }                                                                 \
    }                                                                   \
  } while (0)                                                           \

#endif /* GUESTFSD_STUBS_MACROS_H */