Can statfs() read a remote FTP drive?

428 views Asked by At

I am mounting a remote network drive using FTP. When I do a statfs() on it, I get a -1. So I wanted to know

  1. Can statfs() read a remote network drive mounted using FTP?
  2. If not then how else can I get information (size, free space available) about this drive?

Thank you. Satya Sidhu

2

There are 2 answers

0
Steffen Ullrich On

Can statfs() read a remote network drive mounted using FTP?

No.

If not then how else can I get information (size, free space available) about this drive?

There is a FTP SITE command which allows the client to send any command to the FTP server. Usually this is used for chmod and usually it is highly restricted by the server what commands you can use. You can try to check if the df command is available, but mostly it is not. Then you are out of luck, it least as long as you can only use ftp to communicate with the server.

6
stu On

Can statfs() read a remote network drive mounted using FTP?

Yes.

You must use statfs() correctly. Please see the following example:

#include <stat.h>
#include <stdio.h>

int myStatFs() {
    struct statfs sfs;
    int ret = statfs("host:", &sfs);
    printf("[+] f_fbsize: %ld\n",sfs.f_bsize);
    printf("[+] f_files: %ld\n",sfs.f_files);
    printf("[+] f_bfree: %ld\n",sfs.f_bfree);
    return ret;
}

And this is what it looks like when the above example runs:

-> myStatFs()
[+] f_fbsize: 16
[+] f_files: 25067444
[+] f_bfree: 2952740
value = -1 = 0xffffffff
->

You must make sure that you mount your network drive correctly. This is what my hostShow() returns:

-> hostShow
hostname         inet address      aliases
--------         ------------      -------
localhost        127.0.0.1
xlnx_zynq7k      192.168.1.10
host             192.168.1.11
value = 0 = 0x0
->

The machine at 192.168.1.11 is running an FTP server.

This is what the statfs struct looks like:

struct statfs {
    long f_type;                    /* type of info, zero for now */
    long f_bsize;                   /* fundamental file system block size */
    long f_blocks;                  /* total blocks in file system */
    long f_bfree;                   /* free block in fs */
    long f_bavail;                  /* free blocks avail to non-superuser */
    long f_files;                   /* total file nodes in file system */
    long f_ffree;                   /* free file nodes in fs */
    fsid_t f_fsid;                  /* file system id */
    long f_spare[7];                /* spare for later */
};

Here is the vxWorks 5.5 statfs documentation (and it's basically the same for vxWorks 6.9):

http://www.vxdev.com/docs/vx55man/vxworks/ref/dirLib.html#statfs