9ca58b467c8461f97c9043d1fcc120d2edd0416c
2 Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2010
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>.
18 #define _FILE_OFFSET_BITS 64
21 /* Example program using the highlevel sync interface
28 #include "aros_compat.h"
32 #include "win32_compat.h"
33 #pragma comment(lib, "ws2_32.lib")
41 #include <sys/statvfs.h>
52 #include <sys/types.h>
55 #include "libnfs-zdr.h"
57 #include "libnfs-raw.h"
58 #include "libnfs-raw-mount.h"
68 char buf
[3*1024*1024+337];
70 void print_usage(void)
72 fprintf(stderr
, "Usage: nfsclient-sync [-?|--help] [--usage] <url>\n");
75 int main(int argc
, char *argv
[])
77 struct nfs_context
*nfs
= NULL
;
83 struct nfsdir
*nfsdir
;
84 struct nfsdirent
*nfsdirent
;
87 const char *url
= NULL
;
88 char *server
= NULL
, *path
= NULL
, *strp
;
91 if (WSAStartup(MAKEWORD(2,2), &wsaData
) != 0) {
92 printf("Failed to start Winsock2\n");
104 fprintf(stderr
, "No URL specified.\n");
109 if (strncmp(url
, "nfs://", 6)) {
110 fprintf(stderr
, "Invalid URL specified.\n");
115 server
= strdup(url
+ 6);
116 if (server
== NULL
) {
117 fprintf(stderr
, "Failed to strdup server string\n");
120 if (server
[0] == '/' || server
[0] == '\0') {
121 fprintf(stderr
, "Invalid server string.\n");
125 strp
= strchr(server
, '/');
127 fprintf(stderr
, "Invalid URL specified.\n");
134 fprintf(stderr
, "Failed to strdup server string\n");
138 if (path
[0] != '/') {
139 fprintf(stderr
, "Invalid path.\n");
146 client
.server
= server
;
147 client
.export
= path
;
148 client
.is_finished
= 0;
151 nfs
= nfs_init_context();
153 printf("failed to init context\n");
157 ret
= nfs_mount(nfs
, client
.server
, client
.export
);
159 printf("Failed to mount nfs share : %s\n", nfs_get_error(nfs
));
164 ret
= nfs_opendir(nfs
, "/", &nfsdir
);
166 printf("Failed to opendir(\"/\")\n", nfs_get_error(nfs
));
169 while((nfsdirent
= nfs_readdir(nfs
, nfsdir
)) != NULL
) {
172 if (!strcmp(nfsdirent
->name
, ".") || !strcmp(nfsdirent
->name
, "..")) {
176 sprintf(path
, "%s/%s", "/", nfsdirent
->name
);
177 ret
= nfs_stat(nfs
, path
, &st
);
179 fprintf(stderr
, "Failed to stat(%s) %s\n", path
, nfs_get_error(nfs
));
183 switch (st
.st_mode
& S_IFMT
) {
201 "-r"[!!(st
.st_mode
& S_IRUSR
)],
202 "-w"[!!(st
.st_mode
& S_IWUSR
)],
203 "-x"[!!(st
.st_mode
& S_IXUSR
)]
206 "-r"[!!(st
.st_mode
& S_IRGRP
)],
207 "-w"[!!(st
.st_mode
& S_IWGRP
)],
208 "-x"[!!(st
.st_mode
& S_IXGRP
)]
211 "-r"[!!(st
.st_mode
& S_IROTH
)],
212 "-w"[!!(st
.st_mode
& S_IWOTH
)],
213 "-x"[!!(st
.st_mode
& S_IXOTH
)]
215 printf(" %2d", st
.st_nlink
);
216 printf(" %5d", st
.st_uid
);
217 printf(" %5d", st
.st_gid
);
218 printf(" %12" PRId64
, st
.st_size
);
220 printf(" %s\n", nfsdirent
->name
);
222 nfs_closedir(nfs
, nfsdir
);
229 nfs_destroy_context(nfs
);