From 06a18f676636059d85c0e3f7878635629dc35de6 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 1 Aug 2013 13:36:39 -0700 Subject: [PATCH] Pull info from stat() during file open. --- src/protocols/rdp/guac_rdpdr/rdpdr_fs.c | 28 ++++++++++++++++++++++++ src/protocols/rdp/guac_rdpdr/rdpdr_fs.h | 29 +++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_fs.c b/src/protocols/rdp/guac_rdpdr/rdpdr_fs.c index 11c85d2c..5187ab30 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_fs.c +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_fs.c @@ -45,6 +45,10 @@ #include "compat/winpr-stream.h" #endif +#include +#include +#include + #include #include "rdpdr_messages.h" @@ -117,6 +121,7 @@ int guac_rdpdr_fs_open(guac_rdpdr_device* device, const char* path, guac_rdpdr_fs_data* data = (guac_rdpdr_fs_data*) device->data; char path_buffer[GUAC_RDPDR_FS_MAX_PATH]; + struct stat file_stat; int fd; int file_id; guac_rdpdr_fs_file* file; @@ -203,6 +208,29 @@ int guac_rdpdr_fs_open(guac_rdpdr_device* device, const char* path, file = &(data->files[file_id]); file->fd = fd; + /* Attempt to pull file information */ + if (fstat(fd, &file_stat) == 0) { + file->size = file_stat.st_size; + file->ctime = file_stat.st_ctime; + file->mtime = file_stat.st_mtime; + file->atime = file_stat.st_atime; + } + + /* If information cannot be retrieved, fake it */ + else { + + guac_client_log_info(device->rdpdr->client, "Unable to read information for \"%s\"", + path_buffer); + + /* Init information to 0, lacking any alternative */ + file->size = 0; + file->ctime = 0; + file->mtime = 0; + file->atime = 0; + + } + + data->open_files++; return file_id; diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_fs.h b/src/protocols/rdp/guac_rdpdr/rdpdr_fs.h index 6f6c23bf..b645acf2 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_fs.h +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_fs.h @@ -55,6 +55,9 @@ #include "compat/winpr-stream.h" #endif +#include +#include + #include #include "rdpdr_service.h" @@ -145,6 +148,32 @@ typedef struct guac_rdpdr_fs_file { */ int fd; + /** + * Associated directory stream, if any. This field only applies + * if the file is being used as a directory. + */ + DIR* dir; + + /** + * The size of this file, in bytes. + */ + off_t size; + + /** + * The time this file was created, as a UNIX timestamp. + */ + time_t ctime; + + /** + * The time this file was last modified, as a UNIX timestamp. + */ + time_t mtime; + + /** + * The time this file was last accessed, as a UNIX timestamp. + */ + time_t atime; + } guac_rdpdr_fs_file; /**