From 8904257ce69262094631dd9473f6fbed91120aff Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 5 Jul 2013 13:37:28 +0200 Subject: [PATCH] luci2: add diskfree call --- luci2.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/luci2.c b/luci2.c index ba91533..d6f2e5f 100644 --- a/luci2.c +++ b/luci2.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -259,6 +260,39 @@ rpc_luci2_system_dmesg(struct ubus_context *ctx, struct ubus_object *obj, return 0; } +static int +rpc_luci2_system_diskfree(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + int i; + void *c; + struct statvfs s; + const char *fslist[] = { + "/", "root", + "/tmp", "tmp", + }; + + blob_buf_init(&buf, 0); + + for (i = 0; i < sizeof(fslist) / sizeof(fslist[0]); i += 2) + { + if (statvfs(fslist[i], &s)) + continue; + + c = blobmsg_open_table(&buf, fslist[i+1]); + + blobmsg_add_u32(&buf, "total", s.f_blocks * s.f_frsize); + blobmsg_add_u32(&buf, "free", s.f_bfree * s.f_frsize); + blobmsg_add_u32(&buf, "used", (s.f_blocks - s.f_bfree) * s.f_frsize); + + blobmsg_close_table(&buf, c); + } + + ubus_send_reply(ctx, req, buf.head); + return 0; +} + static int rpc_luci2_process_list(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, @@ -1408,6 +1442,7 @@ int rpc_luci2_api_init(struct ubus_context *ctx) static const struct ubus_method luci2_system_methods[] = { UBUS_METHOD_NOARG("syslog", rpc_luci2_system_log), UBUS_METHOD_NOARG("dmesg", rpc_luci2_system_dmesg), + UBUS_METHOD_NOARG("diskfree", rpc_luci2_system_diskfree), UBUS_METHOD_NOARG("process_list", rpc_luci2_process_list), UBUS_METHOD("process_signal", rpc_luci2_process_signal, rpc_signal_policy),