From 8e39e35bea215bf160f0895aa3868928fb106f28 Mon Sep 17 00:00:00 2001 From: Gautham B A Date: Fri, 8 Jul 2022 09:29:13 +0530 Subject: [PATCH] HDFS-16466. Implement Linux permission flags on Windows (#4526) * HDFS-16466. Implement Linux permission flags on Windows * statinfo.cc uses POSIX permission flags. These flags aren't available for Windows. * This PR implements the equivalent flags on Windows to make this cross platform compatible. --- .../native/libhdfspp/lib/common/statinfo.cc | 4 +- .../native/libhdfspp/lib/x-platform/stat.h | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/stat.h diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/statinfo.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/statinfo.cc index 2fb744fbdd..072a3f3658 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/statinfo.cc +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/statinfo.cc @@ -17,10 +17,12 @@ */ #include -#include + #include #include +#include "x-platform/stat.h" + namespace hdfs { StatInfo::StatInfo() diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/stat.h b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/stat.h new file mode 100644 index 0000000000..c078d44a51 --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/stat.h @@ -0,0 +1,42 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NATIVE_LIBHDFSPP_LIB_CROSS_PLATFORM_STAT +#define NATIVE_LIBHDFSPP_LIB_CROSS_PLATFORM_STAT + +#include + +#if defined(_WIN32) + +// Windows defines the macros for user RWX (_S_IREAD, _S_IWRITE and _S_IEXEC), +// but not for group and others. We implement the permissions for group and +// others through appropriate bit shifting. + +#define S_IRUSR _S_IREAD +#define S_IWUSR _S_IWRITE +#define S_IXUSR _S_IEXEC +#define S_IRGRP (S_IRUSR >> 3) +#define S_IWGRP (S_IWUSR >> 3) +#define S_IXGRP (S_IXUSR >> 3) +#define S_IROTH (S_IRGRP >> 3) +#define S_IWOTH (S_IWGRP >> 3) +#define S_IXOTH (S_IXGRP >> 3) + +#endif + +#endif