[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 4/6] daemon/Win32: make some functions and fields optional.



-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/
>From edb9b3abc03c0a0f84b1cbd9cf5920e3c84e5c18 Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones redhat com>
Date: Fri, 20 Nov 2009 10:38:07 +0000
Subject: [PATCH 4/6] daemon/Win32: make some functions and fields optional.

inotify: Make this optional on platforms that don't have this interface.

mknod, mkfifo etc.: Make these optional on non-Unix platforms.

readdir: If d_type field is missing on the platform, set the corresponding
field to 'u'.

stat: st_blocks and st_blksize are missing on non-Unix platforms, so
set these fields to -1 in the corresponding structures.
---
 daemon/configure.ac |   34 ++++++++++++++++++++++++++++++----
 daemon/inotify.c    |   35 +++++++++++++++++++++++++++++++++++
 daemon/mknod.c      |    5 +++++
 daemon/readdir.c    |    4 ++++
 daemon/stat.c       |   24 ++++++++++++++++++++++++
 5 files changed, 98 insertions(+), 4 deletions(-)

diff --git a/daemon/configure.ac b/daemon/configure.ac
index 0deaa3c..92776c2 100644
--- a/daemon/configure.ac
+++ b/daemon/configure.ac
@@ -127,6 +127,14 @@ AM_PROG_CC_C_O
 dnl Check support for 64 bit file offsets.
 AC_SYS_LARGEFILE
 
+dnl Check if dirent (readdir) supports d_type member.
+AC_STRUCT_DIRENT_D_TYPE
+
+dnl Check if stat has the required fields.
+AC_STRUCT_ST_BLOCKS
+AC_CHECK_MEMBER([struct stat.st_blksize],[
+	AC_DEFINE([HAVE_STRUCT_STAT_ST_BLKSIZE],[1],[Define to 1 if 'st_blksize' is a member of 'struct stat'])])
+
 dnl Check for Augeas (now optional).
 AC_CHECK_LIB([augeas],[aug_match],[
         LIBS="-laugeas $LIBS"
@@ -155,7 +163,28 @@ AC_CHECK_LIB([portablexdr],[xdrmem_create],[],[
         ])
 
 dnl Functions which may not be available in older distributions.
-AC_CHECK_FUNCS([futimens listxattr llistxattr getxattr lgetxattr setxattr lsetxattr removexattr lremovexattr inotify_init1])
+AC_CHECK_FUNCS([\
+	futimens \
+	getxattr \
+	inotify_init1 \
+	lgetxattr \
+	listxattr \
+	llistxattr \
+	lsetxattr \
+	lremovexattr \
+	mknod \
+	removexattr \
+	setxattr])
+
+dnl Headers.
+AC_CHECK_HEADERS([\
+	attr/xattr.h \
+	netdb.h \
+	printf.h \
+	sys/inotify.h \
+	sys/select.h \
+	sys/wait.h \
+	sys/xattr.h])
 
 dnl For modified printf, we need glibc either (old-style)
 dnl register_printf_function or (new-style) register_printf_specifier.
@@ -173,9 +202,6 @@ AC_CHECK_FUNC([register_printf_specifier],[
 This means you either have a very old glibc (pre-2.0) or you
 are using some other libc where this is not supported.])])])
 
-dnl Headers.
-AC_CHECK_HEADERS([attr/xattr.h sys/xattr.h])
-
 dnl Produce output files.
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_FILES([Makefile lib/Makefile tests/Makefile])
diff --git a/daemon/inotify.c b/daemon/inotify.c
index 3e314f0..465d0b6 100644
--- a/daemon/inotify.c
+++ b/daemon/inotify.c
@@ -23,17 +23,22 @@
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
+
+#ifdef HAVE_SYS_INOTIFY_H
 #include <sys/inotify.h>
+#endif
 
 #include "../src/guestfs_protocol.h"
 #include "daemon.h"
 #include "actions.h"
 
+#ifdef HAVE_SYS_INOTIFY_H
 /* Currently open inotify handle, or -1 if not opened. */
 static int inotify_fd = -1;
 
 static char inotify_buf[64*1024*1024];	/* Event buffer, [0..posn-1] is valid */
 static size_t inotify_posn = 0;
+#endif
 
 /* Because inotify_init does NEED_ROOT, NEED_INOTIFY implies NEED_ROOT. */
 #define NEED_INOTIFY(errcode)						\
@@ -49,6 +54,7 @@ static size_t inotify_posn = 0;
 int
 do_inotify_init (int max_events)
 {
+#ifdef HAVE_SYS_INOTIFY_H
   FILE *fp;
 
   NEED_ROOT (return -1);
@@ -99,11 +105,16 @@ do_inotify_init (int max_events)
 #endif
 
   return 0;
+#else
+  reply_with_error ("%s is not available", __func__);
+  return -1;
+#endif
 }
 
 int
 do_inotify_close (void)
 {
+#ifdef HAVE_SYS_INOTIFY_H
   NEED_INOTIFY (-1);
 
   if (inotify_fd == -1) {
@@ -120,11 +131,16 @@ do_inotify_close (void)
   inotify_posn = 0;
 
   return 0;
+#else
+  reply_with_error ("%s is not available", __func__);
+  return -1;
+#endif
 }
 
 int64_t
 do_inotify_add_watch (const char *path, int mask)
 {
+#ifdef HAVE_SYS_INOTIFY_H
   int64_t r;
   char *buf;
 
@@ -144,11 +160,16 @@ do_inotify_add_watch (const char *path, int mask)
   }
 
   return r;
+#else
+  reply_with_error ("%s is not available", __func__);
+  return -1;
+#endif
 }
 
 int
 do_inotify_rm_watch (int wd)
 {
+#ifdef HAVE_SYS_INOTIFY_H
   NEED_INOTIFY (-1);
 
   if (inotify_rm_watch (inotify_fd, wd) == -1) {
@@ -157,11 +178,16 @@ do_inotify_rm_watch (int wd)
   }
 
   return 0;
+#else
+  reply_with_error ("%s is not available", __func__);
+  return -1;
+#endif
 }
 
 guestfs_int_inotify_event_list *
 do_inotify_read (void)
 {
+#ifdef HAVE_SYS_INOTIFY_H
   int space;
   guestfs_int_inotify_event_list *ret;
 
@@ -267,11 +293,16 @@ do_inotify_read (void)
   xdr_free ((xdrproc_t) xdr_guestfs_int_inotify_event_list, (char *) ret);
   free (ret);
   return NULL;
+#else
+  reply_with_error ("%s is not available", __func__);
+  return NULL;
+#endif
 }
 
 char **
 do_inotify_files (void)
 {
+#ifdef HAVE_SYS_INOTIFY_H
   char **ret = NULL;
   int size = 0, alloc = 0;
   unsigned int i;
@@ -339,4 +370,8 @@ do_inotify_files (void)
  error:
   unlink ("/tmp/inotify");
   return NULL;
+#else
+  reply_with_error ("%s is not available", __func__);
+  return NULL;
+#endif
 }
diff --git a/daemon/mknod.c b/daemon/mknod.c
index adaeb80..6ff88ef 100644
--- a/daemon/mknod.c
+++ b/daemon/mknod.c
@@ -33,6 +33,7 @@
 int
 do_mknod (int mode, int devmajor, int devminor, const char *path)
 {
+#ifdef HAVE_MKNOD
   int r;
 
   CHROOT_IN;
@@ -45,6 +46,10 @@ do_mknod (int mode, int devmajor, int devminor, const char *path)
   }
 
   return 0;
+#else
+  reply_with_error ("%s is not available", __func__);
+  return -1;
+#endif
 }
 
 int
diff --git a/daemon/readdir.c b/daemon/readdir.c
index ab42dfd..876041e 100644
--- a/daemon/readdir.c
+++ b/daemon/readdir.c
@@ -74,6 +74,7 @@ do_readdir (const char *path)
     ret->guestfs_int_dirent_list_val = p;
 
     v.ino = d->d_ino;
+#ifdef HAVE_STRUCT_DIRENT_D_TYPE
     switch (d->d_type) {
     case DT_BLK: v.ftyp = 'b'; break;
     case DT_CHR: v.ftyp = 'c'; break;
@@ -85,6 +86,9 @@ do_readdir (const char *path)
     case DT_UNKNOWN: v.ftyp = 'u'; break;
     default: v.ftyp = '?'; break;
     }
+#else
+    v.ftyp = 'u';
+#endif
 
     ret->guestfs_int_dirent_list_val[i] = v;
 
diff --git a/daemon/stat.c b/daemon/stat.c
index 2441c9f..45d2cb8 100644
--- a/daemon/stat.c
+++ b/daemon/stat.c
@@ -61,8 +61,16 @@ do_stat (const char *path)
   ret->gid = statbuf.st_gid;
   ret->rdev = statbuf.st_rdev;
   ret->size = statbuf.st_size;
+#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
   ret->blksize = statbuf.st_blksize;
+#else
+  ret->blksize = -1;
+#endif
+#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
   ret->blocks = statbuf.st_blocks;
+#else
+  ret->blocks = -1;
+#endif
   ret->atime = statbuf.st_atime;
   ret->mtime = statbuf.st_mtime;
   ret->ctime = statbuf.st_ctime;
@@ -100,8 +108,16 @@ do_lstat (const char *path)
   ret->gid = statbuf.st_gid;
   ret->rdev = statbuf.st_rdev;
   ret->size = statbuf.st_size;
+#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
   ret->blksize = statbuf.st_blksize;
+#else
+  ret->blksize = -1;
+#endif
+#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
   ret->blocks = statbuf.st_blocks;
+#else
+  ret->blocks = -1;
+#endif
   ret->atime = statbuf.st_atime;
   ret->mtime = statbuf.st_mtime;
   ret->ctime = statbuf.st_ctime;
@@ -158,8 +174,16 @@ do_lstatlist (const char *path, char *const *names)
       ret->guestfs_int_stat_list_val[i].gid = statbuf.st_gid;
       ret->guestfs_int_stat_list_val[i].rdev = statbuf.st_rdev;
       ret->guestfs_int_stat_list_val[i].size = statbuf.st_size;
+#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
       ret->guestfs_int_stat_list_val[i].blksize = statbuf.st_blksize;
+#else
+      ret->guestfs_int_stat_list_val[i].blksize = -1;
+#endif
+#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
       ret->guestfs_int_stat_list_val[i].blocks = statbuf.st_blocks;
+#else
+      ret->guestfs_int_stat_list_val[i].blocks = -1;
+#endif
       ret->guestfs_int_stat_list_val[i].atime = statbuf.st_atime;
       ret->guestfs_int_stat_list_val[i].mtime = statbuf.st_mtime;
       ret->guestfs_int_stat_list_val[i].ctime = statbuf.st_ctime;
-- 
1.6.5.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]