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")
39 #include <sys/statvfs.h>
50 #include <sys/types.h>
53 #include "libnfs-zdr.h"
55 #include "libnfs-raw.h"
56 #include "libnfs-raw-mount.h"
65 void print_usage(void)
67 fprintf(stderr
, "Usage: nfs-ls [-?|--help] [--usage] <url>\n");
70 int main(int argc
, char *argv
[])
72 struct nfs_context
*nfs
= NULL
;
78 struct nfsdir
*nfsdir
;
79 struct nfsdirent
*nfsdirent
;
82 const char *url
= NULL
;
83 char *server
= NULL
, *path
= NULL
, *strp
;
86 if (WSAStartup(MAKEWORD(2,2), &wsaData
) != 0) {
87 printf("Failed to start Winsock2\n");
99 fprintf(stderr
, "No URL specified.\n");
104 if (strncmp(url
, "nfs://", 6)) {
105 fprintf(stderr
, "Invalid URL specified.\n");
110 server
= strdup(url
+ 6);
111 if (server
== NULL
) {
112 fprintf(stderr
, "Failed to strdup server string\n");
115 if (server
[0] == '/' || server
[0] == '\0') {
116 fprintf(stderr
, "Invalid server string.\n");
120 strp
= strchr(server
, '/');
122 fprintf(stderr
, "Invalid URL specified.\n");
129 fprintf(stderr
, "Failed to strdup server string\n");
133 if (path
[0] != '/') {
134 fprintf(stderr
, "Invalid path.\n");
141 client
.server
= server
;
142 client
.export
= path
;
143 client
.is_finished
= 0;
146 nfs
= nfs_init_context();
148 printf("failed to init context\n");
152 ret
= nfs_mount(nfs
, client
.server
, client
.export
);
154 printf("Failed to mount nfs share : %s\n", nfs_get_error(nfs
));
159 ret
= nfs_opendir(nfs
, "/", &nfsdir
);
161 printf("Failed to opendir(\"/\")\n", nfs_get_error(nfs
));
164 while((nfsdirent
= nfs_readdir(nfs
, nfsdir
)) != NULL
) {
167 if (!strcmp(nfsdirent
->name
, ".") || !strcmp(nfsdirent
->name
, "..")) {
171 sprintf(path
, "%s/%s", "/", nfsdirent
->name
);
172 ret
= nfs_stat(nfs
, path
, &st
);
174 fprintf(stderr
, "Failed to stat(%s) %s\n", path
, nfs_get_error(nfs
));
178 switch (st
.st_mode
& S_IFMT
) {
196 "-r"[!!(st
.st_mode
& S_IRUSR
)],
197 "-w"[!!(st
.st_mode
& S_IWUSR
)],
198 "-x"[!!(st
.st_mode
& S_IXUSR
)]
201 "-r"[!!(st
.st_mode
& S_IRGRP
)],
202 "-w"[!!(st
.st_mode
& S_IWGRP
)],
203 "-x"[!!(st
.st_mode
& S_IXGRP
)]
206 "-r"[!!(st
.st_mode
& S_IROTH
)],
207 "-w"[!!(st
.st_mode
& S_IWOTH
)],
208 "-x"[!!(st
.st_mode
& S_IXOTH
)]
210 printf(" %2d", st
.st_nlink
);
211 printf(" %5d", st
.st_uid
);
212 printf(" %5d", st
.st_gid
);
213 printf(" %12" PRId64
, st
.st_size
);
215 printf(" %s\n", nfsdirent
->name
);
217 nfs_closedir(nfs
, nfsdir
);
224 nfs_destroy_context(nfs
);