2 Copyright (C) by Peter Lieven <pl@kamp.de> 2013
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
26 #include "aros_compat.h"
30 #include "win32_compat.h"
31 #pragma comment(lib, "ws2_32.lib")
38 #include <sys/statvfs.h>
40 #include <sys/statvfs.h>
51 #include <sys/types.h>
54 #include "libnfs-zdr.h"
56 #include "libnfs-raw.h"
57 #include "libnfs-raw-mount.h"
59 void print_usage(void)
61 fprintf(stderr
, "Usage: nfs-io [-?|--help|--usage] [stat|creat|unlink|mkdir|rmdir] <url>\n");
64 int main(int argc
, char *argv
[])
67 struct nfs_context
*nfs
= NULL
;
68 struct nfsfh
*nfsfh
= NULL
;
69 struct nfs_url
*url
= NULL
;
72 if (WSAStartup(MAKEWORD(2,2), &wsaData
) != 0) {
73 printf("Failed to start Winsock2\n");
83 fprintf(stderr
, "No URL specified.\n");
87 nfs
= nfs_init_context();
89 printf("failed to init context\n");
93 url
= nfs_parse_url_full(nfs
, argv
[argc
- 1]);
95 fprintf(stderr
, "%s\n", nfs_get_error(nfs
));
99 if (nfs_mount(nfs
, url
->server
, url
->path
) != 0) {
100 fprintf(stderr
, "Failed to mount nfs share : %s\n", nfs_get_error(nfs
));
104 if (!strncmp(argv
[1], "creat", 5)) {
105 ret
= nfs_creat(nfs
, url
->file
, 0600, &nfsfh
);
106 } else if (!strncmp(argv
[1], "unlink", 6)) {
107 ret
= nfs_unlink(nfs
, url
->file
);
108 } else if (!strncmp(argv
[1], "mkdir", 5)) {
109 ret
= nfs_mkdir(nfs
, url
->file
);
110 } else if (!strncmp(argv
[1], "rmdir", 5)) {
111 ret
= nfs_rmdir(nfs
, url
->file
);
112 } else if (!strncmp(argv
[1], "stat", 4)) {
114 ret
= nfs_stat(nfs
, url
->file
, &st
);
116 switch (st
.st_mode
& S_IFMT
) {
136 "-r"[!!(st
.st_mode
& S_IRUSR
)],
137 "-w"[!!(st
.st_mode
& S_IWUSR
)],
138 "-x"[!!(st
.st_mode
& S_IXUSR
)]
141 "-r"[!!(st
.st_mode
& S_IRGRP
)],
142 "-w"[!!(st
.st_mode
& S_IWGRP
)],
143 "-x"[!!(st
.st_mode
& S_IXGRP
)]
146 "-r"[!!(st
.st_mode
& S_IROTH
)],
147 "-w"[!!(st
.st_mode
& S_IWOTH
)],
148 "-x"[!!(st
.st_mode
& S_IXOTH
)]
150 printf(" %2d", (int) st
.st_nlink
);
151 printf(" %5d", st
.st_uid
);
152 printf(" %5d", st
.st_gid
);
153 printf(" %12" PRId64
, st
.st_size
);
161 fprintf(stderr
, "ERROR: %s\n", nfs_get_error(nfs
));
168 nfs_destroy_url(url
);
171 nfs_close(nfs
, nfsfh
);
173 nfs_destroy_context(nfs
);