aboutsummaryrefslogtreecommitdiff
path: root/sample.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-08-12 14:04:13 +0200
committerAndreas Schneider <mail@cynapses.org>2009-08-12 17:13:42 +0200
commit63011c29a0922a7fd57a14bb2b45695e716a9b00 (patch)
tree7bad2233d88b6c0e0e7a156fef93b4c90c3380ac /sample.c
parente68c3b09a69ece9cdb041b229f4264474d86d873 (diff)
downloadlibssh-63011c29a0922a7fd57a14bb2b45695e716a9b00.tar.gz
libssh-63011c29a0922a7fd57a14bb2b45695e716a9b00.tar.xz
libssh-63011c29a0922a7fd57a14bb2b45695e716a9b00.zip
Implement an example for statvfs.
Diffstat (limited to 'sample.c')
-rw-r--r--sample.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/sample.c b/sample.c
index 1a8b0580..c114b529 100644
--- a/sample.c
+++ b/sample.c
@@ -21,6 +21,7 @@ clients must be made or how a client should react.
#include <sys/select.h>
#include <sys/time.h>
+#include <sys/statvfs.h>
#ifdef HAVE_PTY_H
#include <pty.h>
#endif
@@ -280,6 +281,8 @@ void do_sftp(SSH_SESSION *session){
SFTP_SESSION *sftp_session=sftp_new(session);
SFTP_DIR *dir;
SFTP_ATTRIBUTES *file;
+ SFTP_STATVFS *sftpstatvfs;
+ struct statvfs sysstatvfs;
SFTP_FILE *fichier;
SFTP_FILE *to;
int len=1;
@@ -324,6 +327,67 @@ void do_sftp(SSH_SESSION *session){
sftp_unlink(sftp_session, "/tmp/sftp_symlink_test");
+ sftpstatvfs = sftp_statvfs(sftp_session, "/tmp");
+ if (sftpstatvfs == NULL) {
+ fprintf(stderr, "statvfs failed (%s)\n", ssh_get_error(session));
+ return;
+ }
+
+ printf("sftp statvfs:\n"
+ "\tfile system block size: %llu\n"
+ "\tfundamental fs block size: %llu\n"
+ "\tnumber of blocks (unit f_frsize): %llu\n"
+ "\tfree blocks in file system: %llu\n"
+ "\tfree blocks for non-root: %llu\n"
+ "\ttotal file inodes: %llu\n"
+ "\tfree file inodes: %llu\n"
+ "\tfree file inodes for to non-root: %llu\n"
+ "\tfile system id: %llu\n"
+ "\tbit mask of f_flag values: %llu\n"
+ "\tmaximum filename length: %llu\n",
+ sftpstatvfs->f_bsize,
+ sftpstatvfs->f_frsize,
+ sftpstatvfs->f_blocks,
+ sftpstatvfs->f_bfree,
+ sftpstatvfs->f_bavail,
+ sftpstatvfs->f_files,
+ sftpstatvfs->f_ffree,
+ sftpstatvfs->f_favail,
+ sftpstatvfs->f_fsid,
+ sftpstatvfs->f_flag,
+ sftpstatvfs->f_namemax);
+
+ sftp_statvfs_free(sftpstatvfs);
+
+ if (statvfs("/tmp", &sysstatvfs) < 0) {
+ fprintf(stderr, "statvfs failed (%s)\n", strerror(errno));
+ return;
+ }
+
+ printf("sys statvfs:\n"
+ "\tfile system block size: %llu\n"
+ "\tfundamental fs block size: %llu\n"
+ "\tnumber of blocks (unit f_frsize): %llu\n"
+ "\tfree blocks in file system: %llu\n"
+ "\tfree blocks for non-root: %llu\n"
+ "\ttotal file inodes: %llu\n"
+ "\tfree file inodes: %llu\n"
+ "\tfree file inodes for to non-root: %llu\n"
+ "\tfile system id: %llu\n"
+ "\tbit mask of f_flag values: %llu\n"
+ "\tmaximum filename length: %llu\n",
+ sysstatvfs.f_bsize,
+ sysstatvfs.f_frsize,
+ sysstatvfs.f_blocks,
+ sysstatvfs.f_bfree,
+ sysstatvfs.f_bavail,
+ sysstatvfs.f_files,
+ sysstatvfs.f_ffree,
+ sysstatvfs.f_favail,
+ sysstatvfs.f_fsid,
+ sysstatvfs.f_flag,
+ sysstatvfs.f_namemax);
+
/* the connection is made */
/* opening a directory */
dir=sftp_opendir(sftp_session,"./");
@@ -388,6 +452,7 @@ void do_sftp(SSH_SESSION *session){
}
}
sftp_close(to);
+
/* close the sftp session */
sftp_free(sftp_session);
printf("sftp session terminated\n");