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
26 #include "aros_compat.h"
30 #include "win32_compat.h"
31 #pragma comment(lib, "ws2_32.lib")
37 #include <sys/statvfs.h>
49 #include <sys/types.h>
52 #include "libnfs-zdr.h"
54 #include "libnfs-raw.h"
55 #include "libnfs-raw-mount.h"
64 void print_usage(void)
66 fprintf(stderr
, "Usage: nfs-ls [-?|--help] [--usage] <url>\n");
69 int main(int argc
, char *argv
[])
71 struct nfs_context
*nfs
= NULL
;
77 struct nfsdir
*nfsdir
;
78 struct nfsdirent
*nfsdirent
;
81 const char *url
= NULL
;
82 char *server
= NULL
, *path
= NULL
, *strp
;
85 if (WSAStartup(MAKEWORD(2,2), &wsaData
) != 0) {
86 printf("Failed to start Winsock2\n");
98 fprintf(stderr
, "No URL specified.\n");
103 if (strncmp(url
, "nfs://", 6)) {
104 fprintf(stderr
, "Invalid URL specified.\n");
109 server
= strdup(url
+ 6);
110 if (server
== NULL
) {
111 fprintf(stderr
, "Failed to strdup server string\n");
114 if (server
[0] == '/' || server
[0] == '\0') {
115 fprintf(stderr
, "Invalid server string.\n");
119 strp
= strchr(server
, '/');
121 fprintf(stderr
, "Invalid URL specified.\n");
128 fprintf(stderr
, "Failed to strdup server string\n");
132 if (path
[0] != '/') {
133 fprintf(stderr
, "Invalid path.\n");
140 client
.server
= server
;
141 client
.export
= path
;
142 client
.is_finished
= 0;
145 nfs
= nfs_init_context();
147 printf("failed to init context\n");
151 ret
= nfs_mount(nfs
, client
.server
, client
.export
);
153 printf("Failed to mount nfs share : %s\n", nfs_get_error(nfs
));
158 ret
= nfs_opendir(nfs
, "/", &nfsdir
);
160 printf("Failed to opendir(\"/\")\n", nfs_get_error(nfs
));
163 while((nfsdirent
= nfs_readdir(nfs
, nfsdir
)) != NULL
) {
166 if (!strcmp(nfsdirent
->name
, ".") || !strcmp(nfsdirent
->name
, "..")) {
170 snprintf(path
, 1024, "%s/%s", "/", nfsdirent
->name
);
171 ret
= nfs_stat(nfs
, path
, &st
);
173 fprintf(stderr
, "Failed to stat(%s) %s\n", path
, nfs_get_error(nfs
));
177 switch (st
.st_mode
& S_IFMT
) {
193 "-r"[!!(st
.st_mode
& S_IRUSR
)],
194 "-w"[!!(st
.st_mode
& S_IWUSR
)],
195 "-x"[!!(st
.st_mode
& S_IXUSR
)]
198 "-r"[!!(st
.st_mode
& S_IRGRP
)],
199 "-w"[!!(st
.st_mode
& S_IWGRP
)],
200 "-x"[!!(st
.st_mode
& S_IXGRP
)]
203 "-r"[!!(st
.st_mode
& S_IROTH
)],
204 "-w"[!!(st
.st_mode
& S_IWOTH
)],
205 "-x"[!!(st
.st_mode
& S_IXOTH
)]
207 printf(" %2d", st
.st_nlink
);
208 printf(" %5d", st
.st_uid
);
209 printf(" %5d", st
.st_gid
);
210 printf(" %12" PRId64
, st
.st_size
);
212 printf(" %s\n", nfsdirent
->name
);
214 nfs_closedir(nfs
, nfsdir
);
221 nfs_destroy_context(nfs
);