[win32] - make it compile on win32
[deb_libnfs.git] / examples / nfsclient-raw.c
index 40be303736f436c50b8f239a4a4aa97e895b8ab9..948909f720405436a7a6ac766f872b67be84bd00 100644 (file)
  * This allow accurate control of the exact commands that are being used.
  */
 
+#ifdef WIN32
+#include "win32_compat.h"
+#else
+#include <poll.h>
+#endif
 #define SERVER "10.1.1.27"
 #define EXPORT "/shared"
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <poll.h>
 #include "libnfs.h"
 #include "libnfs-raw.h"
 #include "libnfs-raw-mount.h"
@@ -44,7 +48,7 @@ struct client {
 void rquota_getquota_cb(struct rpc_context *rpc _U_, int status, void *data, void *private_data)
 {
        struct client *client = private_data;
-       GETQUOTA1res *res = data;
+//     GETQUOTA1res *res = data;
 
        if (status == RPC_STATUS_ERROR) {
                printf("rquota/getquota call failed with \"%s\"\n", (char *)data);
@@ -76,6 +80,54 @@ void rquota_connect_cb(struct rpc_context *rpc, int status, void *data _U_, void
        }
 }
 
+void acl_getacl_cb(struct rpc_context *rpc _U_, int status, void *data, void *private_data)
+{
+       struct client *client = private_data;
+       GETACL3res *res = data;
+
+       printf("Got NFSACL/GETACL reply\n");
+
+       if (status == RPC_STATUS_SUCCESS) {
+               printf("Got an ACL :  ACL status:%d\n", res->status);
+               if (res->status == NFS3_OK) {
+                       int i;
+                       printf("ACL MASK 0x%08x\n", res->GETACL3res_u.resok.mask);
+                       printf("NUM ACE %d\n", res->GETACL3res_u.resok.ace_count);
+                       for (i=0; i<res->GETACL3res_u.resok.ace.ace_len; i++) {
+                               printf("Type:0x%08x\n", res->GETACL3res_u.resok.ace.ace_val[i].type);
+                               printf("ID:%d\n", res->GETACL3res_u.resok.ace.ace_val[i].id);
+                               printf("Perm:0x%08x\n", res->GETACL3res_u.resok.ace.ace_val[i].perm);
+                       }
+               }
+       }
+
+       printf("Disconnect socket from nfs server\n");
+       if (rpc_disconnect(rpc, "normal disconnect") != 0) {
+               printf("Failed to disconnect socket to nfs\n");
+               exit(10);
+       }
+
+       printf("Connect to RPC.RQUOTAD on %s:%d\n", client->server, client->rquota_port);
+       if (rpc_connect_async(rpc, client->server, client->rquota_port, rquota_connect_cb, client) != 0) {
+               printf("Failed to start connection\n");
+               exit(10);
+       }
+}
+
+void acl_null_cb(struct rpc_context *rpc _U_, int status, void *data, void *private_data)
+{
+       struct client *client = private_data;
+
+       printf("Got NFSACL/NULL reply\n");
+       printf("Get ACL for root handle\n");
+
+       if (rpc_nfsacl_getacl_async(rpc, acl_getacl_cb, &client->rootfh, NFSACL_MASK_ACL_ENTRY|NFSACL_MASK_ACL_COUNT|NFSACL_MASK_ACL_DEFAULT_ENTRY|NFSACL_MASK_ACL_DEFAULT_COUNT, client) != 0) {
+               printf("Failed to send getacl request\n");
+               exit(10);
+       }
+
+}
+
 void nfs_fsinfo_cb(struct rpc_context *rpc _U_, int status, void *data, void *private_data)
 {
        struct client *client = private_data;
@@ -94,15 +146,9 @@ void nfs_fsinfo_cb(struct rpc_context *rpc _U_, int status, void *data, void *pr
        printf("Read Max:%d\n", (int)res->FSINFO3res_u.resok.rtmax);
        printf("Write Max:%d\n", (int)res->FSINFO3res_u.resok.wtmax);
 
-       printf("Disconnect socket from nfs server\n");
-       if (rpc_disconnect(rpc, "normal disconnect") != 0) {
-               printf("Failed to disconnect socket to nfs\n");
-               exit(10);
-       }
-
-       printf("Connect to RPC.RQUOTAD on %s:%d\n", client->server, client->rquota_port);
-       if (rpc_connect_async(rpc, client->server, client->rquota_port, rquota_connect_cb, client) != 0) {
-               printf("Failed to start connection\n");
+       printf("Send NFSACL/NULL request\n");
+       if (rpc_nfsacl_null_async(rpc, acl_null_cb, client) != 0) {
+               printf("Failed to send acl/null request\n");
                exit(10);
        }
 }
@@ -158,9 +204,11 @@ void mount_mnt_cb(struct rpc_context *rpc, int status, void *data, void *private
 }
 
 
-void mount_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
+
+void mount_export_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
 {
        struct client *client = private_data;
+       exports export = *(exports *)data;
 
        if (status == RPC_STATUS_ERROR) {
                printf("mount null call failed with \"%s\"\n", (char *)data);
@@ -171,7 +219,11 @@ void mount_null_cb(struct rpc_context *rpc, int status, void *data, void *privat
                exit(10);
        }
 
-       printf("Got reply from server for MOUNT/NULL procedure.\n");
+       printf("Got reply from server for MOUNT/EXPORT procedure.\n");
+       while (export != NULL) {
+             printf("Export: %s\n", export->ex_dir);
+             export = export->ex_next;
+       }
        printf("Send MOUNT/MNT command for %s\n", client->export);
        if (rpc_mount_mnt_async(rpc, mount_mnt_cb, client->export, client) != 0) {
                printf("Failed to send mnt request\n");
@@ -179,6 +231,27 @@ void mount_null_cb(struct rpc_context *rpc, int status, void *data, void *privat
        }
 }
 
+void mount_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
+{
+       struct client *client = private_data;
+
+       if (status == RPC_STATUS_ERROR) {
+               printf("mount null call failed with \"%s\"\n", (char *)data);
+               exit(10);
+       }
+       if (status != RPC_STATUS_SUCCESS) {
+               printf("mount null call to server %s failed, status:%d\n", client->server, status);
+               exit(10);
+       }
+
+       printf("Got reply from server for MOUNT/NULL procedure.\n");
+       printf("Send MOUNT/EXPORT command\n");
+       if (rpc_mount_export_async(rpc, mount_export_cb, client) != 0) {
+               printf("Failed to send export request\n");
+               exit(10);
+       }
+}
+
 void mount_connect_cb(struct rpc_context *rpc, int status, void *data _U_, void *private_data)
 {
        struct client *client = private_data;
@@ -247,7 +320,7 @@ void pmap_getport1_cb(struct rpc_context *rpc, int status, void *data, void *pri
        printf("GETPORT returned RPC.RQUOTAD on port:%d\n", client->rquota_port);
        if (client->rquota_port == 0) {
                printf("RPC.RQUOTAD is not available on server : %s:%d\n", client->server, client->rquota_port);
-               exit(10);
+//             exit(10);
        }               
 
        printf("Send getport request asking for MOUNT port\n");