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>
56 #include "libnfs-raw.h"
57 #include "libnfs-raw-mount.h"
67 char buf
[3*1024*1024+337];
69 void print_usage(void)
71 fprintf(stderr
, "Usage: nfsclient-sync [-?|--help] [--usage] <url>\n");
74 int main(int argc
, char *argv
[])
76 struct nfs_context
*nfs
= NULL
;
82 struct nfsdir
*nfsdir
;
83 struct nfsdirent
*nfsdirent
;
86 const char *url
= NULL
;
87 char *server
= NULL
, *path
= NULL
, *strp
;
90 if (WSAStartup(MAKEWORD(2,2), &wsaData
) != 0) {
91 printf("Failed to start Winsock2\n");
103 fprintf(stderr
, "No URL specified.\n");
108 if (strncmp(url
, "nfs://", 6)) {
109 fprintf(stderr
, "Invalid URL specified.\n");
114 server
= strdup(url
+ 6);
115 if (server
== NULL
) {
116 fprintf(stderr
, "Failed to strdup server string\n");
119 if (server
[0] == '/' || server
[0] == '\0') {
120 fprintf(stderr
, "Invalid server string.\n");
124 strp
= strchr(server
, '/');
126 fprintf(stderr
, "Invalid URL specified.\n");
133 fprintf(stderr
, "Failed to strdup server string\n");
137 if (path
[0] != '/') {
138 fprintf(stderr
, "Invalid path.\n");
145 client
.server
= server
;
146 client
.export
= path
;
147 client
.is_finished
= 0;
150 nfs
= nfs_init_context();
152 printf("failed to init context\n");
156 ret
= nfs_mount(nfs
, client
.server
, client
.export
);
158 printf("Failed to mount nfs share : %s\n", nfs_get_error(nfs
));
163 ret
= nfs_opendir(nfs
, "/", &nfsdir
);
165 printf("Failed to opendir(\"/\") %s\n", nfs_get_error(nfs
));
168 while((nfsdirent
= nfs_readdir(nfs
, nfsdir
)) != NULL
) {
171 if (!strcmp(nfsdirent
->name
, ".") || !strcmp(nfsdirent
->name
, "..")) {
175 sprintf(path
, "%s/%s", "/", nfsdirent
->name
);
176 ret
= nfs_stat(nfs
, path
, &st
);
178 fprintf(stderr
, "Failed to stat(%s) %s\n", path
, nfs_get_error(nfs
));
182 switch (st
.st_mode
& S_IFMT
) {
200 "-r"[!!(st
.st_mode
& S_IRUSR
)],
201 "-w"[!!(st
.st_mode
& S_IWUSR
)],
202 "-x"[!!(st
.st_mode
& S_IXUSR
)]
205 "-r"[!!(st
.st_mode
& S_IRGRP
)],
206 "-w"[!!(st
.st_mode
& S_IWGRP
)],
207 "-x"[!!(st
.st_mode
& S_IXGRP
)]
210 "-r"[!!(st
.st_mode
& S_IROTH
)],
211 "-w"[!!(st
.st_mode
& S_IWOTH
)],
212 "-x"[!!(st
.st_mode
& S_IXOTH
)]
214 printf(" %2d", (int)st
.st_nlink
);
215 printf(" %5d", st
.st_uid
);
216 printf(" %5d", st
.st_gid
);
217 printf(" %12" PRId64
, st
.st_size
);
219 printf(" %s\n", nfsdirent
->name
);
221 nfs_closedir(nfs
, nfsdir
);
228 nfs_destroy_context(nfs
);