4bd2c0b942714b26d4c72ee8305842ecdec1b5f2
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
24 #include "win32_compat.h"
25 #pragma comment(lib, "ws2_32.lib")
33 #include <sys/statvfs.h>
38 #include "aros_compat.h"
45 #include <sys/types.h>
48 #include "libnfs-zdr.h"
50 #include "libnfs-raw.h"
51 #include "libnfs-raw-mount.h"
61 char buf
[3*1024*1024+337];
63 void print_usage(void)
65 fprintf(stderr
, "Usage: nfsclient-sync [-?|--help] [--usage] <url>\n");
68 int main(int argc
, char *argv
[])
70 struct nfs_context
*nfs
= NULL
;
76 struct nfsdir
*nfsdir
;
77 struct nfsdirent
*nfsdirent
;
80 const char *url
= NULL
;
81 char *server
= NULL
, *path
= NULL
, *strp
;
84 if (WSAStartup(MAKEWORD(2,2), &wsaData
) != 0) {
85 printf("Failed to start Winsock2\n");
97 fprintf(stderr
, "No URL specified.\n");
102 if (strncmp(url
, "nfs://", 6)) {
103 fprintf(stderr
, "Invalid URL specified.\n");
108 server
= strdup(url
+ 6);
109 if (server
== NULL
) {
110 fprintf(stderr
, "Failed to strdup server string\n");
113 if (server
[0] == '/' || server
[0] == '\0') {
114 fprintf(stderr
, "Invalid server string.\n");
118 strp
= strchr(server
, '/');
120 fprintf(stderr
, "Invalid URL specified.\n");
127 fprintf(stderr
, "Failed to strdup server string\n");
131 if (path
[0] != '/') {
132 fprintf(stderr
, "Invalid path.\n");
139 client
.server
= server
;
140 client
.export
= path
;
141 client
.is_finished
= 0;
144 nfs
= nfs_init_context();
146 printf("failed to init context\n");
150 ret
= nfs_mount(nfs
, client
.server
, client
.export
);
152 printf("Failed to mount nfs share : %s\n", nfs_get_error(nfs
));
157 ret
= nfs_opendir(nfs
, "/", &nfsdir
);
159 printf("Failed to opendir(\"/\")\n", nfs_get_error(nfs
));
162 while((nfsdirent
= nfs_readdir(nfs
, nfsdir
)) != NULL
) {
165 if (!strcmp(nfsdirent
->name
, ".") || !strcmp(nfsdirent
->name
, "..")) {
169 snprintf(path
, 1024, "%s/%s", "/", nfsdirent
->name
);
170 ret
= nfs_stat(nfs
, path
, &st
);
172 fprintf(stderr
, "Failed to stat(%s) %s\n", path
, nfs_get_error(nfs
));
176 switch (st
.st_mode
& S_IFMT
) {
192 "-r"[!!(st
.st_mode
& S_IRUSR
)],
193 "-w"[!!(st
.st_mode
& S_IWUSR
)],
194 "-x"[!!(st
.st_mode
& S_IXUSR
)]
197 "-r"[!!(st
.st_mode
& S_IRGRP
)],
198 "-w"[!!(st
.st_mode
& S_IWGRP
)],
199 "-x"[!!(st
.st_mode
& S_IXGRP
)]
202 "-r"[!!(st
.st_mode
& S_IROTH
)],
203 "-w"[!!(st
.st_mode
& S_IWOTH
)],
204 "-x"[!!(st
.st_mode
& S_IXOTH
)]
206 printf(" %2d", st
.st_nlink
);
207 printf(" %5d", st
.st_uid
);
208 printf(" %5d", st
.st_gid
);
209 printf(" %12" PRId64
, st
.st_size
);
211 printf(" %s\n", nfsdirent
->name
);
213 nfs_closedir(nfs
, nfsdir
);
220 nfs_destroy_context(nfs
);