This is needed to be able to support statfs operation on an SSH
filesystem (http://fuse.sourceforge.net/sshfs.html).

It uses and sends only those fields of struct statfs which are common
with struct statvfs as defined by POSIX, and which are shared among
most UNIX-like systems.

The SSH_FXP_EXTENDED message type is used, so this change is backward
compatible and conforms to the protocol specification.

Please comment on whether this change is acceptable or what is needed
for it's acceptance into the openssh tree.

Thanks,
Miklos

Index: ssh/sftp-server.c
================================================== =================
--- ssh.orig/sftp-server.c 2006-08-19 16:24:17.000000000 +0200
+++ ssh/sftp-server.c 2006-08-19 16:49:03.000000000 +0200
@@ -19,6 +19,7 @@
#include
#include
#include
+#include

#include
#include
@@ -462,6 +463,24 @@ send_attrib(u_int32_t id, const Attrib *
buffer_free(&msg);
}

+static void
+send_statfs(u_int32_t id, struct statfs *st)
+{
+ Buffer msg;
+
+ buffer_init(&msg);
+ buffer_put_char(&msg, SSH2_FXP_EXTENDED_REPLY);
+ buffer_put_int(&msg, id);
+ buffer_put_int(&msg, st->f_bsize);
+ buffer_put_int64(&msg, st->f_blocks);
+ buffer_put_int64(&msg, st->f_bfree);
+ buffer_put_int64(&msg, st->f_bavail);
+ buffer_put_int64(&msg, st->f_files);
+ buffer_put_int64(&msg, st->f_ffree);
+ send_msg(&msg);
+ buffer_free(&msg);
+}
+
/* parse incoming */

static void
@@ -1049,6 +1068,25 @@ process_symlink(void)
}

static void
+process_extended_statfs(u_int32_t id)
+{
+ char *path;
+ struct statfs st;
+ int ret;
+
+ path = get_string(NULL);
+ debug3("request %u: statfs", id);
+ logit("statfs \"%s\"", path);
+
+ ret = statfs(path, &st);
+ if (ret == -1)
+ send_status(id, errno_to_portable(errno));
+ else
+ send_statfs(id, &st);
+ xfree(path);
+}
+
+static void
process_extended(void)
{
u_int32_t id;
@@ -1056,7 +1094,10 @@ process_extended(void)

id = get_int();
request = get_string(NULL);
- send_status(id, SSH2_FX_OP_UNSUPPORTED); /* MUST */
+ if (strcmp(request, "statfs@openssh.org") == 0)
+ process_extended_statfs(id);
+ else
+ send_status(id, SSH2_FX_OP_UNSUPPORTED); /* MUST */
xfree(request);
}


_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
http://lists.mindrot.org/mailman/lis...enssh-unix-dev