libssh2_sftp_statvfs(3)
π libssh2_sftp_statvfs β get file system statistics π
okay so bestie, you know how statvfs(2) tells you all the juicy numbers about a file system? yeah. this is that, but over SFTP. it's part of the libssh2 manual, and it lives in <libssh2.h> and <libssh2_sftp.h> β two icons fr fr. let's get into it π
β¨ SYNOPSIS β¨
#include <libssh2.h>
#include <libssh2_sftp.h>
int
libssh2_sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path,
size_t path_len, LIBSSH2_SFTP_STATVFS *st);
int
libssh2_sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle,
LIBSSH2_SFTP_STATVFS *st)
two functions, one vibe. libssh2_sftp_statvfs goes by path, libssh2_sftp_fstatvfs goes by handle. pick your fighter π«Ά
πΈ DESCRIPTION πΈ
so these functions give you statvfs(2)-like operations, but β and this is the important part, no cap β they require statvfs@openssh.com and fstatvfs@openssh.com extension support on the server. if your server doesn't speak that language? nothing's happening. it's giving unsupported. π
here's who's who in the cast:
sftpβ the SFTP instance you got back fromlibssh2_sftp_init(3). your main character.handleβ the SFTP File Handle you got back fromlibssh2_sftp_open_ex(3).pathβ full path of any file within the mounted file system. any file, bestie, you just need to be inside the fs.path_lenβ the length of that full path. yes you have to tell it. it's that kind of API.stβ pointer to aLIBSSH2_SFTP_STATVFSstructure where the file system statistics get placed. that's where the numbers go π
π¦ DATA TYPES π¦
LIBSSH2_SFTP_STATVFS is a typedefed struct, and here's exactly what it looks like:
struct _LIBSSH2_SFTP_STATVFS {
libssh2_uint64_t f_bsize; /* file system block size */
libssh2_uint64_t f_frsize; /* fragment size */
libssh2_uint64_t f_blocks; /* size of fs in f_frsize units */
libssh2_uint64_t f_bfree; /* # free blocks */
libssh2_uint64_t f_bavail; /* # free blocks for non-root */
libssh2_uint64_t f_files; /* # inodes */
libssh2_uint64_t f_ffree; /* # free inodes */
libssh2_uint64_t f_favail; /* # free inodes for non-root */
libssh2_uint64_t f_fsid; /* file system ID */
libssh2_uint64_t f_flag; /* mount flags */
libssh2_uint64_t f_namemax; /* maximum filename length */
};
heads up bestie: it is unspecified whether all members of the returned struct have meaningful values on all file systems. so like... don't assume every field is loaded. some of them might be ghosting you. π
the field f_flag is a bit mask, and the bits are defined like this:
LIBSSH2_SFTP_ST_RDONLYβ Read-only file system. can't write, won't write, periodt.LIBSSH2_SFTP_ST_NOSUIDβ Set-user-ID/set-group-ID bits are ignored byexec(3). the bits are literally getting ignored, it's giving disrespect ngl.
β RETURN VALUE β
Returns 0 on success, or negative on failure. classic.
if you're using it in non-blocking mode, it returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. and yes, while LIBSSH2_ERROR_EAGAIN is a negative number, it is not really a failure per se β it's just the function saying "not right now babe, come back later." don't panic. π
π₯ ERRORS π₯
LIBSSH2_ERROR_ALLOCβ an internal memory allocation call failed. the malloc said no. πLIBSSH2_ERROR_SOCKET_SENDβ unable to send data on socket.LIBSSH2_ERROR_SOCKET_TIMEOUTβ (no description given, it just is what it is π)LIBSSH2_ERROR_SFTP_PROTOCOLβ an invalid SFTP protocol response was received on the socket, or an SFTP operation caused an errorcode to be returned by the server. messy behavior all around.
π AVAILABILITY π
Added in libssh2 1.2.6. so if you're on something older than that... bestie. it's not there. it never was. upgrade era. β¨
π SEE ALSO π
and that's the whole page, no notes. this manual came from libssh2 and it's dated 22 May 2010 β yeah, it's an elder, but it still ate. go get those file system stats, you absolute legend π«Άπβ¨
π¦ where this page comes from
- alpine 3.22: libssh2-doc 1.11.1-r3 Β· BSD-3-Clause
- alpine 3.23: libssh2-doc 1.11.1-r4 Β· BSD-3-Clause
- alpine 3.24: libssh2-doc 1.11.1-r4 Β· BSD-3-Clause
- arch rolling: libssh2 1.11.1-7 Β· BSD-3-Clause
- debian trixie: libssh2-1-dev 1.11.1-1+deb13u1 Β· BSD3
- debian trixie: libssh2-1-dev 1.11.1-1+deb13u2 Β· BSD3
- epel 10: libssh2-docs 1.11.1-9.el10_3 Β· BSD-3-Clause
- epel 9: libssh2-docs 1.11.1-9.el9 Β· BSD-3-Clause
- fedora 43: libssh2-docs 1.11.1-4.fc43 Β· BSD-3-Clause
- fedora 43: libssh2-docs 1.11.1-9.fc43 Β· BSD-3-Clause
- fedora 44: libssh2-docs 1.11.1-5.fc44 Β· BSD-3-Clause
- fedora 44: libssh2-docs 1.11.1-9.fc44 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- ubuntu questing: libssh2-1-dev 1.11.1-1build1
- ubuntu questing: libssh2-1-dev 1.11.1-1ubuntu0.25.10.2
- ubuntu resolute: libssh2-1-dev 1.11.1-1build2 Β· BSD3
- ubuntu resolute: libssh2-1-dev 1.11.1-1ubuntu0.26.04.4 Β· BSD3
- ubuntu stonking: libssh2-1-dev 1.11.1-6 Β· BSD3
- π the page's license: BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms