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")
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"
66 int recursive
= 0, summary
= 0;
68 void print_usage(void)
70 fprintf(stderr
, "Usage: nfs-ls [-?|--help|--usage] [-R|--recursive] [-s|--summary] <url>\n");
73 void process_dir(struct nfs_context
*nfs
, char *dir
, int level
) {
75 struct nfsdirent
*nfsdirent
;
77 struct nfsdir
*nfsdir
;
81 printf("Recursion detected!\n");
85 ret
= nfs_opendir(nfs
, dir
, &nfsdir
);
87 printf("Failed to opendir(\"%s\")\n", dir
, nfs_get_error(nfs
));
90 while((nfsdirent
= nfs_readdir(nfs
, nfsdir
)) != NULL
) {
93 if (!strcmp(nfsdirent
->name
, ".") || !strcmp(nfsdirent
->name
, "..")) {
97 snprintf(path
, 1024, "%s/%s", dir
, nfsdirent
->name
);
98 ret
= nfs_stat(nfs
, path
, &st
);
100 fprintf(stderr
, "Failed to stat(%s) %s\n", path
, nfs_get_error(nfs
));
104 switch (st
.st_mode
& S_IFMT
) {
124 "-r"[!!(st
.st_mode
& S_IRUSR
)],
125 "-w"[!!(st
.st_mode
& S_IWUSR
)],
126 "-x"[!!(st
.st_mode
& S_IXUSR
)]
129 "-r"[!!(st
.st_mode
& S_IRGRP
)],
130 "-w"[!!(st
.st_mode
& S_IWGRP
)],
131 "-x"[!!(st
.st_mode
& S_IXGRP
)]
134 "-r"[!!(st
.st_mode
& S_IROTH
)],
135 "-w"[!!(st
.st_mode
& S_IWOTH
)],
136 "-x"[!!(st
.st_mode
& S_IXOTH
)]
138 printf(" %2d", (int) st
.st_nlink
);
139 printf(" %5d", st
.st_uid
);
140 printf(" %5d", st
.st_gid
);
141 printf(" %12" PRId64
, st
.st_size
);
143 printf(" %s\n", path
+ 1);
145 if (recursive
&& (st
.st_mode
& S_IFMT
) == S_IFDIR
) {
146 process_dir(nfs
, path
, level
- 1);
149 nfs_closedir(nfs
, nfsdir
);
152 int main(int argc
, char *argv
[])
154 struct nfs_context
*nfs
= NULL
;
157 struct client client
;
159 struct statvfs stvfs
;
162 char *server
= NULL
, *path
= NULL
, *strp
;
165 if (WSAStartup(MAKEWORD(2,2), &wsaData
) != 0) {
166 printf("Failed to start Winsock2\n");
176 fprintf(stderr
, "No URL specified.\n");
180 for (i
=1; i
< argc
-1; i
++) {
181 if (!strcmp(argv
[i
], "-R") || !strcmp(argv
[i
], "--recursive")) {
183 } else if (!strcmp(argv
[i
], "-s") || !strcmp(argv
[i
], "--summary")) {
190 nfs
= nfs_init_context();
192 printf("failed to init context\n");
196 url
= nfs_parse_url_dir(nfs
, argv
[argc
- 1]);
198 fprintf(stderr
, "%s\n", nfs_get_error(nfs
));
202 client
.server
= url
->server
;
203 client
.export
= url
->path
;
204 client
.is_finished
= 0;
206 if (nfs_mount(nfs
, client
.server
, client
.export
) != 0) {
207 fprintf(stderr
, "Failed to mount nfs share : %s\n", nfs_get_error(nfs
));
211 process_dir(nfs
, "", 16);
214 if (nfs_statvfs(nfs
, "/", &stvfs
) != 0) {
217 printf("\n%12" PRId64
" of %12" PRId64
" bytes free.\n",
218 stvfs
.f_frsize
* stvfs
.f_bfree
, stvfs
.f_frsize
* stvfs
.f_blocks
);
229 nfs_destroy_url(url
);
231 nfs_destroy_context(nfs
);