]> xenbits.xensource.com Git - people/hx242/xen.git/commitdiff
tools: make libxenhypfs interface more future proof
authorJuergen Gross <jgross@suse.com>
Tue, 2 Jun 2020 06:00:21 +0000 (08:00 +0200)
committerWei Liu <wl@xen.org>
Tue, 2 Jun 2020 12:05:30 +0000 (12:05 +0000)
As compilers are free to choose the width of an enum they should be
avoided in stable interfaces when declaring a variable. So the
struct xenhypfs_dirent definition should be modified to have explicitly
sized members for type and encoding and the related enums should be
defined separately.

Additionally it is better to have a larger flags member in that struct
with the "writable" indicator occupying only a single bit. This will
make future additions easier.

Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Wei Liu <wl@xen.org>
Release-acked-by: Paul Durrant <paul@xen.org>
tools/libs/hypfs/core.c
tools/libs/hypfs/include/xenhypfs.h
tools/misc/xenhypfs.c

index d4309b5ae2a9a8b14b07cac9b038ad0559f2facb..c91e1657059ff599466bcfa6d01c7c9d8fcebef5 100644 (file)
@@ -204,7 +204,7 @@ static void xenhypfs_set_attrs(struct xen_hypfs_direntry *entry,
         dirent->type = xenhypfs_type_blob;
     }
 
-    dirent->is_writable = entry->max_write_len;
+    dirent->flags = entry->max_write_len ? XENHYPFS_FLAG_WRITABLE : 0;
 }
 
 void *xenhypfs_read_raw(xenhypfs_handle *fshdl, const char *path,
index ab157edcebf5c04f73f827be5947ed77ada313dd..25432d2a1657d8a59b04ffdefca6d7ee1734cf55 100644 (file)
@@ -26,22 +26,27 @@ struct xentoollog_logger;
 
 typedef struct xenhypfs_handle xenhypfs_handle;
 
+enum xenhypfs_type {
+    xenhypfs_type_dir,
+    xenhypfs_type_blob,
+    xenhypfs_type_string,
+    xenhypfs_type_uint,
+    xenhypfs_type_int,
+    xenhypfs_type_bool,
+};
+
+enum xenhypfs_encoding {
+    xenhypfs_enc_plain,
+    xenhypfs_enc_gzip
+};
+
 struct xenhypfs_dirent {
     char *name;
     size_t size;
-    enum {
-        xenhypfs_type_dir,
-        xenhypfs_type_blob,
-        xenhypfs_type_string,
-        xenhypfs_type_uint,
-        xenhypfs_type_int,
-        xenhypfs_type_bool
-    } type;
-    enum {
-        xenhypfs_enc_plain,
-        xenhypfs_enc_gzip
-    } encoding;
-    bool is_writable;
+    unsigned short type;
+    unsigned short encoding;
+    unsigned int flags;
+#define XENHYPFS_FLAG_WRITABLE  0x00000001
 };
 
 xenhypfs_handle *xenhypfs_open(struct xentoollog_logger *logger,
index 5145b8969fe358174ca5c06fa190d7ef2888fd45..5da24aed905c95940e9193e2474bc05a9043b904 100644 (file)
@@ -125,7 +125,8 @@ static int xenhypfs_ls(char *path)
     } else {
         for (i = 0; i < n; i++)
             printf("%s r%c %s\n", xenhypfs_type(ent + i),
-                   ent[i].is_writable ? 'w' : '-', ent[i].name);
+                   (ent[i].flags & XENHYPFS_FLAG_WRITABLE) ? 'w' : '-',
+                   ent[i].name);
 
         free(ent);
     }