1 /* -*-  mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil;  -*- */
2 /*
3    Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2017
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #define _FILE_OFFSET_BITS 64
20 #define _GNU_SOURCE
21 
22 #include <fcntl.h>
23 #include <inttypes.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <stdint.h>
27 #include <string.h>
28 #include <sys/stat.h>
29 #include <sys/types.h>
30 
31 #include "libnfs.h"
32 
usage(void)33 void usage(void)
34 {
35 	fprintf(stderr, "Usage: prog_timeout <file>\n");
36 	exit(1);
37 }
38 
main(int argc,char * argv[])39 int main(int argc, char *argv[])
40 {
41 	struct nfs_context *nfs = NULL;
42 	struct nfs_url *url = NULL;
43 	struct nfs_stat_64 st;
44 
45 	if (argc != 2) {
46 		usage();
47 	}
48 
49 	nfs = nfs_init_context();
50 	if (nfs == NULL) {
51 		printf("failed to init context\n");
52 		exit(1);
53 	}
54 
55 	nfs_set_timeout(nfs, 1000);
56 
57 	url = nfs_parse_url_full(nfs, argv[argc - 1]);
58 	if (url == NULL) {
59 		fprintf(stderr, "%s\n", nfs_get_error(nfs));
60 		exit(1);
61 	}
62 
63 	if (nfs_mount(nfs, url->server, url->path) != 0) {
64  		fprintf(stderr, "Failed to mount nfs share : %s\n",
65 			nfs_get_error(nfs));
66 		goto finished;
67 	}
68 
69 	if (nfs_stat64(nfs, url->file, &st)) {
70  		fprintf(stderr, "Failed to stat file : %s\n",
71 			nfs_get_error(nfs));
72 		goto finished;
73 	}
74 
75 	printf("nfs_ino:%" PRIu64 "\n", st.nfs_ino);
76 	printf("nfs_mode:%" PRIo64 "\n", st.nfs_mode);
77 	printf("nfs_nlink:%" PRIu64 "\n", st.nfs_nlink);
78 	printf("nfs_uid:%" PRIu64 "\n", st.nfs_uid);
79 	printf("nfs_gid:%" PRIu64 "\n", st.nfs_gid);
80 	printf("nfs_size:%" PRIu64 "\n", st.nfs_size);
81 	printf("nfs_atime:%" PRIu64 "\n", st.nfs_atime);
82 	printf("nfs_mtime:%" PRIu64 "\n", st.nfs_mtime);
83 	printf("nfs_ctime:%" PRIu64 "\n", st.nfs_ctime);
84 
85 finished:
86 	nfs_destroy_url(url);
87 	nfs_destroy_context(nfs);
88 
89 	/* Always return 0 as we want to catch valgrind
90 	 * overriding this with return code 1 upon memory leaks.
91 	 */
92 	return 0;
93 }
94