PORTMAP: Rename the functions in PMAP to PMAP2 to desribe the version of PMAP we...
[deb_libnfs.git] / lib / libnfs-sync.c
index 2fe5ed5a5886a78ab0050a3af02ddb6ff0c98d37..e539a4559dbb5d03835c25e0415676bc1d0115e9 100644 (file)
 /*
  * High level api to nfs filesystems
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef AROS
+#include "aros_compat.h"
+#endif
+
 #ifdef WIN32
 #include "win32_compat.h"
-#define DllExport
-#define HAVE_POLL_H
-#else
-#include <strings.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <netdb.h>
-#include <sys/socket.h>
+#endif
+
+#ifdef HAVE_NET_IF_H
 #include <net/if.h>
+#endif
 
-#ifdef AROS
-#include "aros_compat.h"
-#else
 #ifdef ANDROID
-#include <netinet/in.h>
-#include <sys/vfs.h>
 #define statvfs statfs
-#else
+#endif
+
+#ifdef HAVE_SYS_VFS_H
+#include <sys/vfs.h>
+#endif
+
+#ifdef HAVE_SYS_STATVFS_H
 #include <sys/statvfs.h>
-#endif /*ANDRIOD*/
-#endif /*AROS*/
-#endif /*WIN32*/
+#endif
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
 #endif
 
 #ifdef HAVE_POLL_H
 #include <poll.h>
 #endif
 
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -185,11 +208,18 @@ static void stat_cb(int status, struct nfs_context *nfs, void *data, void *priva
                nfs_set_error(nfs, "stat call failed with \"%s\"", (char *)data);
                return;
        }
-
-       memcpy(cb_data->return_data, data, sizeof(struct stat));
+#ifdef WIN32
+       memcpy(cb_data->return_data, data, sizeof(struct __stat64));
+#else
+  memcpy(cb_data->return_data, data, sizeof(struct stat));
+#endif
 }
 
+#ifdef WIN32
+int nfs_stat(struct nfs_context *nfs, const char *path, struct __stat64 *st)
+#else
 int nfs_stat(struct nfs_context *nfs, const char *path, struct stat *st)
+#endif
 {
        struct sync_cb_data cb_data;
 
@@ -206,8 +236,36 @@ int nfs_stat(struct nfs_context *nfs, const char *path, struct stat *st)
        return cb_data.status;
 }
 
+static void stat64_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
+{
+       struct sync_cb_data *cb_data = private_data;
+
+       cb_data->is_finished = 1;
+       cb_data->status = status;
+
+       if (status < 0) {
+               nfs_set_error(nfs, "stat call failed with \"%s\"", (char *)data);
+               return;
+       }
+       memcpy(cb_data->return_data, data, sizeof(struct nfs_stat_64));
+}
+
+int nfs_stat64(struct nfs_context *nfs, const char *path, struct nfs_stat_64 *st)
+{
+       struct sync_cb_data cb_data;
 
+       cb_data.is_finished = 0;
+       cb_data.return_data = st;
 
+       if (nfs_stat64_async(nfs, path, stat64_cb, &cb_data) != 0) {
+               nfs_set_error(nfs, "nfs_stat64_async failed");
+               return -1;
+       }
+
+       wait_for_nfs_reply(nfs, &cb_data);
+
+       return cb_data.status;
+}
 
 /*
  * open()
@@ -230,14 +288,14 @@ static void open_cb(int status, struct nfs_context *nfs, void *data, void *priva
        *nfsfh = fh;
 }
 
-int nfs_open(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh)
+int nfs_open(struct nfs_context *nfs, const char *path, int flags, struct nfsfh **nfsfh)
 {
        struct sync_cb_data cb_data;
 
        cb_data.is_finished = 0;
        cb_data.return_data = nfsfh;
 
-       if (nfs_open_async(nfs, path, mode, open_cb, &cb_data) != 0) {
+       if (nfs_open_async(nfs, path, flags, open_cb, &cb_data) != 0) {
                nfs_set_error(nfs, "nfs_open_async failed");
                return -1;
        }
@@ -247,6 +305,38 @@ int nfs_open(struct nfs_context *nfs, const char *path, int mode, struct nfsfh *
        return cb_data.status;
 }
 
+/*
+ * chdir()
+ */
+static void chdir_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
+{
+       struct sync_cb_data *cb_data = private_data;
+
+       cb_data->is_finished = 1;
+       cb_data->status = status;
+
+       if (status < 0) {
+               nfs_set_error(nfs, "chdir call failed with \"%s\"", (char *)data);
+               return;
+       }
+}
+
+int nfs_chdir(struct nfs_context *nfs, const char *path)
+{
+       struct sync_cb_data cb_data;
+
+       cb_data.is_finished = 0;
+
+       if (nfs_chdir_async(nfs, path, chdir_cb, &cb_data) != 0) {
+               nfs_set_error(nfs, "nfs_chdir_async failed with %s",
+                       nfs_get_error(nfs));
+               return -1;
+       }
+
+       wait_for_nfs_reply(nfs, &cb_data);
+
+       return cb_data.status;
+}
 
 
 
@@ -1347,7 +1437,7 @@ static int send_nfsd_probes(struct rpc_context *rpc, INTERFACE_INFO *InterfaceLi
       return -1;
     }
 
-    if (rpc_pmap_callit_async(rpc, MOUNT_PROGRAM, 2, 0, NULL, 0, callit_cb, data) < 0) 
+    if (rpc_pmap2_callit_async(rpc, MOUNT_PROGRAM, 2, 0, NULL, 0, callit_cb, data) < 0) 
     {
       return -1;
     }
@@ -1481,7 +1571,7 @@ static int send_nfsd_probes(struct rpc_context *rpc, struct ifconf *ifc, struct
                        return -1;
                }
 
-               if (rpc_pmap_callit_async(rpc, MOUNT_PROGRAM, 2, 0, NULL, 0, callit_cb, data) < 0) {
+               if (rpc_pmap2_callit_async(rpc, MOUNT_PROGRAM, 2, 0, NULL, 0, callit_cb, data) < 0) {
                        return -1;
                }
        }