Add FsAccess::getFileMode and SysfsAccess::getFileMode methods

Change-Id: I4dddf1b3983e63ef6ad664009ebd20d474c8cc17
Signed-off-by: Bill Jordan <bill.jordan@intel.com>
This commit is contained in:
Bill Jordan
2020-03-26 15:34:20 -04:00
committed by sys_ocldev
parent 24cee4611d
commit 5d756b7b15
2 changed files with 16 additions and 0 deletions

View File

@@ -119,6 +119,15 @@ ze_result_t FsAccess::canWrite(const std::string file) {
return ZE_RESULT_SUCCESS;
}
ze_result_t FsAccess::getFileMode(const std::string file, ::mode_t &mode) {
struct stat sb;
if (0 != stat(file.c_str(), &sb)) {
return getResult(errno);
}
mode = sb.st_mode;
return ZE_RESULT_SUCCESS;
}
ze_result_t FsAccess::readSymLink(const std::string path, std::string &val) {
// returns the value of symlink at path
char buf[PATH_MAX];
@@ -305,6 +314,11 @@ ze_result_t SysfsAccess::canWrite(const std::string file) {
return FsAccess::canWrite(fullPath(file));
}
ze_result_t SysfsAccess::getFileMode(const std::string file, ::mode_t &mode) {
// Prepend sysfs directory path and call the base getFileMode
return FsAccess::getFileMode(fullPath(file), mode);
}
ze_result_t SysfsAccess::read(const std::string file, std::string &val) {
// Prepend sysfs directory path and call the base read
return FsAccess::read(fullPath(file).c_str(), val);

View File

@@ -30,6 +30,7 @@ class FsAccess {
ze_result_t canRead(const std::string file);
ze_result_t canWrite(const std::string file);
ze_result_t getFileMode(const std::string file, ::mode_t &mode);
ze_result_t read(const std::string file, std::string &val);
ze_result_t read(const std::string file, std::vector<std::string> &val);
@@ -74,6 +75,7 @@ class SysfsAccess : private FsAccess {
ze_result_t canRead(const std::string file);
ze_result_t canWrite(const std::string file);
ze_result_t getFileMode(const std::string file, ::mode_t &mode);
ze_result_t read(const std::string file, std::string &val);
ze_result_t read(const std::string file, int &val);