1

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

Satya Sidhu
  • 103
  • 1
  • 9

2 Answers2

1

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

stu
  • 58
  • 7
  • Are you really sure that the mount is done by FTP (can you show the mount option) and that the data reflect the truth about the remote system? Since FTP does not have a general command to get the status of the remote file system there must be some magic (non-standard command) involved to make this work. – Steffen Ullrich Dec 03 '14 at 06:02
  • There is some non-standard magic that makes this work, and it's done by vxWorks when you add the host file system entry to the host table. Every time that a file system command is performed on host (in my example) vxWorks will automatically log in via FTP with hardcoded credentials, and perform the operation. – stu Dec 03 '14 at 06:17
  • "and perform the operation..." - do you know which operation (FTP command) this is? – Steffen Ullrich Dec 03 '14 at 06:22
  • If the file system command (in vxWorks C shell) is ls, then it will be ls on the remote file system. If it is cp, then it will be an FTP put, or an FTP get, and so on and so forth. – stu Dec 03 '14 at 06:50
  • Again, there is no standard FTP command which can be used to get the information needed for statfs (see RFC959). Are you sure you are talking about FTP and not SFTP (which is transfer over SSH)? – Steffen Ullrich Dec 03 '14 at 07:17
  • You're not wrong, and I agree with you, but there is no doubt that somehow statfs() (on vxWorks) is getting file system information over FTP. I'll investigate what statfs is doing differently that allows it to ascertain file system information over FTP. – stu Dec 03 '14 at 17:09
-2

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.

Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172