libssh2_sftp_statvfs(3)

πŸ“¦
version 1.11.1 Β· 3 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian trixie, epel 10, epel 9, fedora 43, fedora 44, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– 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 from libssh2_sftp_init(3). your main character.
  • handle β€” the SFTP File Handle you got back from libssh2_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 a LIBSSH2_SFTP_STATVFS structure 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 by exec(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 πŸ«ΆπŸ’–βœ¨