+static int
+rpc_file_md5(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ struct blob_attr *msg)
+{
+ int rv, i;
+ char *path;
+ struct stat s;
+ uint8_t md5[16];
+ char *wbuf;
+
+ if (!rpc_check_path(msg, R, "read", &path, &s))
+ return rpc_errno_status();
+
+ if (!S_ISREG(s.st_mode))
+ return UBUS_STATUS_NOT_SUPPORTED;
+
+ if ((rv = md5sum(path, md5)) <= 0)
+ return rpc_errno_status();
+
+ blob_buf_init(&buf, 0);
+ wbuf = blobmsg_alloc_string_buffer(&buf, "md5", 33);
+
+ for (i = 0; i < 16; i++)
+ sprintf(wbuf + (i * 2), "%02x", (uint8_t) md5[i]);
+
+ blobmsg_add_string_buffer(&buf);
+ ubus_send_reply(ctx, req, buf.head);
+ blob_buf_free(&buf);
+
+ return UBUS_STATUS_OK;
+}
+
+static void
+_rpc_file_add_stat(struct stat *s)
+{
+ int type;
+
+ type = S_ISREG(s->st_mode) ? DT_REG :
+ S_ISDIR(s->st_mode) ? DT_DIR :
+ S_ISCHR(s->st_mode) ? DT_CHR :
+ S_ISBLK(s->st_mode) ? DT_BLK :
+ S_ISFIFO(s->st_mode) ? DT_FIFO :
+ S_ISLNK(s->st_mode) ? DT_LNK :
+ S_ISSOCK(s->st_mode) ? DT_SOCK :
+ DT_UNKNOWN;
+
+ blobmsg_add_string(&buf, "type", d_types[type]);
+ blobmsg_add_u32(&buf, "size", s->st_size);
+ blobmsg_add_u32(&buf, "mode", s->st_mode);
+ blobmsg_add_u32(&buf, "atime", s->st_atime);
+ blobmsg_add_u32(&buf, "mtime", s->st_mtime);
+ blobmsg_add_u32(&buf, "ctime", s->st_ctime);
+ blobmsg_add_u32(&buf, "inode", s->st_ino);
+ blobmsg_add_u32(&buf, "uid", s->st_uid);
+ blobmsg_add_u32(&buf, "gid", s->st_gid);
+}
+