1.1 --- a/libfsclient/lib/src/file.cc Thu Feb 24 22:35:00 2022 +0100
1.2 +++ b/libfsclient/lib/src/file.cc Fri Feb 25 18:45:11 2022 +0100
1.3 @@ -189,6 +189,31 @@
1.4 return err;
1.5 }
1.6
1.7 +/* Obtain filesystem object statistics. This is a convenience function invoking
1.8 + file_context and file_context_stat. */
1.9 +
1.10 +long file_stat(const char *filename, struct stat *st, l4_cap_idx_t server)
1.11 +{
1.12 + file_t context;
1.13 + offset_t written;
1.14 + long err;
1.15 +
1.16 + err = file_context(&context, server);
1.17 + if (err)
1.18 + return err;
1.19 +
1.20 + if (!file_string_set(&context, filename, 0, &written))
1.21 + return -L4_ENOMEM;
1.22 +
1.23 + err = file_context_stat(st, &context);
1.24 +
1.25 + /* Close the context, although a separate mechanism could permit contexts to
1.26 + rename several files. */
1.27 +
1.28 + file_close(&context);
1.29 + return err;
1.30 +}
1.31 +
1.32
1.33
1.34 /* Initialise a file structure for a context obtained from the given server
1.35 @@ -247,6 +272,20 @@
1.36 return openercontext.rename();
1.37 }
1.38
1.39 +/* Obtain filesystem object statistics using the given context. */
1.40 +
1.41 +long file_context_stat(struct stat *st, file_t *context)
1.42 +{
1.43 + client_OpenerContext openercontext(context->ref);
1.44 + long err = openercontext.stat();
1.45 +
1.46 + if (err)
1.47 + return err;
1.48 +
1.49 + memcpy(st, context->memory, sizeof(struct stat));
1.50 + return L4_EOK;
1.51 +}
1.52 +
1.53
1.54
1.55 /* Flush populated data and obtain an updated file size and populated data