1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/host_file_opener.cc Wed Feb 03 00:15:16 2021 +0100
1.3 @@ -0,0 +1,34 @@
1.4 +#include <sys/stat.h>
1.5 +
1.6 +#include "host_file_accessor.h"
1.7 +#include "host_file_opener.h"
1.8 +
1.9 +/* Return a file identifier for the given 'path'. */
1.10 +
1.11 +fileid_t HostFileOpener::get_fileid(const char *path)
1.12 +{
1.13 + struct stat statbuf;
1.14 +
1.15 + /* Obtain the inode number.
1.16 + NOTE: This does not handle errors! */
1.17 +
1.18 + stat(path, &statbuf);
1.19 +
1.20 + _paths.insert(FilePathEntry(statbuf.st_ino, path));
1.21 +
1.22 + return statbuf.st_ino;
1.23 +}
1.24 +
1.25 +/* Return a new accessor for 'fileid'. */
1.26 +
1.27 +Accessor *HostFileOpener::make_accessor(fileid_t fileid)
1.28 +{
1.29 + FilePaths::iterator found = _paths.find(fileid);
1.30 +
1.31 + if (found != _paths.end())
1.32 + return new HostFileAccessor(found->second, fileid);
1.33 + else
1.34 + return NULL;
1.35 +}
1.36 +
1.37 +// vim: tabstop=4 expandtab shiftwidth=4