summaryrefslogtreecommitdiff
path: root/libs/androidfw/misc.cpp
diff options
context:
space:
mode:
author Xin Li <delphij@google.com> 2023-08-25 12:59:08 -0700
committer Xin Li <delphij@google.com> 2023-08-25 12:59:08 -0700
commit7d3ffbae618e9e728644a96647ed709bf39ae759 (patch)
treeab369a30c6a0e17a69c8f80c6353be4de3692e10 /libs/androidfw/misc.cpp
parenta8a87bbca9162af7add830139198c4ee899fa123 (diff)
parent8a809c6e46007521f75ac035ad4b1dcc1d00d9cf (diff)
Merge Android U (ab/10368041)
Bug: 291102124 Merged-In: I3c9e9d15786fbead1b874636b46844f6c24bccc2 Change-Id: Id6cf6cc13baef4e67486c6271a1510146204affa
Diffstat (limited to 'libs/androidfw/misc.cpp')
-rw-r--r--libs/androidfw/misc.cpp44
1 files changed, 38 insertions, 6 deletions
diff --git a/libs/androidfw/misc.cpp b/libs/androidfw/misc.cpp
index 52854205207c..d3949e9cf69f 100644
--- a/libs/androidfw/misc.cpp
+++ b/libs/androidfw/misc.cpp
@@ -21,12 +21,17 @@
//
#include <androidfw/misc.h>
-#include <sys/stat.h>
+#include "android-base/logging.h"
+
+#ifdef __linux__
+#include <sys/statvfs.h>
+#include <sys/vfs.h>
+#endif // __linux__
+
#include <cstring>
-#include <errno.h>
#include <cstdio>
-
-using namespace android;
+#include <errno.h>
+#include <sys/stat.h>
namespace android {
@@ -41,8 +46,7 @@ FileType getFileType(const char* fileName)
if (errno == ENOENT || errno == ENOTDIR)
return kFileTypeNonexistent;
else {
- fprintf(stderr, "getFileType got errno=%d on '%s'\n",
- errno, fileName);
+ PLOG(ERROR) << "getFileType(): stat(" << fileName << ") failed";
return kFileTypeUnknown;
}
} else {
@@ -82,4 +86,32 @@ time_t getFileModDate(const char* fileName)
return sb.st_mtime;
}
+#ifndef __linux__
+// No need to implement these on the host, the functions only matter on a device.
+bool isReadonlyFilesystem(const char*) {
+ return false;
+}
+bool isReadonlyFilesystem(int) {
+ return false;
+}
+#else // __linux__
+bool isReadonlyFilesystem(const char* path) {
+ struct statfs sfs;
+ if (::statfs(path, &sfs)) {
+ PLOG(ERROR) << "isReadonlyFilesystem(): statfs(" << path << ") failed";
+ return false;
+ }
+ return (sfs.f_flags & ST_RDONLY) != 0;
+}
+
+bool isReadonlyFilesystem(int fd) {
+ struct statfs sfs;
+ if (::fstatfs(fd, &sfs)) {
+ PLOG(ERROR) << "isReadonlyFilesystem(): fstatfs(" << fd << ") failed";
+ return false;
+ }
+ return (sfs.f_flags & ST_RDONLY) != 0;
+}
+#endif // __linux__
+
}; // namespace android