3a43084eaf08bb5e0a9993a24e7e3788636aa1ff
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>
55 #include "libnfs-raw.h"
56 #include "libnfs-raw-mount.h"
58 void print_usage(void)
60 fprintf(stderr
, "Usage: nfs-io [-?|--help|--usage] [stat|creat|unlink|mkdir|rmdir] <url>\n");
63 int main(int argc
, char *argv
[])
66 struct nfs_context
*nfs
= NULL
;
67 struct nfsfh
*nfsfh
= NULL
;
68 struct nfs_url
*url
= NULL
;
71 if (WSAStartup(MAKEWORD(2,2), &wsaData
) != 0) {
72 printf("Failed to start Winsock2\n");
82 fprintf(stderr
, "No URL specified.\n");
86 nfs
= nfs_init_context();
88 printf("failed to init context\n");
92 url
= nfs_parse_url_full(nfs
, argv
[argc
- 1]);
94 fprintf(stderr
, "%s\n", nfs_get_error(nfs
));
98 if (nfs_mount(nfs
, url
->server
, url
->path
) != 0) {
99 fprintf(stderr
, "Failed to mount nfs share : %s\n", nfs_get_error(nfs
));
103 if (!strncmp(argv
[1], "creat", 5)) {
104 ret
= nfs_creat(nfs
, url
->file
, 0600, &nfsfh
);
105 } else if (!strncmp(argv
[1], "unlink", 6)) {
106 ret
= nfs_unlink(nfs
, url
->file
);
107 } else if (!strncmp(argv
[1], "mkdir", 5)) {
108 ret
= nfs_mkdir(nfs
, url
->file
);
109 } else if (!strncmp(argv
[1], "rmdir", 5)) {
110 ret
= nfs_rmdir(nfs
, url
->file
);
111 } else if (!strncmp(argv
[1], "stat", 4)) {
113 ret
= nfs_stat(nfs
, url
->file
, &st
);
115 switch (st
.st_mode
& S_IFMT
) {
135 "-r"[!!(st
.st_mode
& S_IRUSR
)],
136 "-w"[!!(st
.st_mode
& S_IWUSR
)],
137 "-x"[!!(st
.st_mode
& S_IXUSR
)]
140 "-r"[!!(st
.st_mode
& S_IRGRP
)],
141 "-w"[!!(st
.st_mode
& S_IWGRP
)],
142 "-x"[!!(st
.st_mode
& S_IXGRP
)]
145 "-r"[!!(st
.st_mode
& S_IROTH
)],
146 "-w"[!!(st
.st_mode
& S_IWOTH
)],
147 "-x"[!!(st
.st_mode
& S_IXOTH
)]
149 printf(" %2d", (int) st
.st_nlink
);
150 printf(" %5d", st
.st_uid
);
151 printf(" %5d", st
.st_gid
);
152 printf(" %12" PRId64
, st
.st_size
);
160 fprintf(stderr
, "ERROR: %s\n", nfs_get_error(nfs
));
167 nfs_destroy_url(url
);
170 nfs_close(nfs
, nfsfh
);
172 nfs_destroy_context(nfs
);