• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "cj_common_ffi.h"
17 #include "macro.h"
18 #include "uni_error.h"
19 #include "xattr.h"
20 
21 namespace OHOS {
22 namespace CJSystemapi {
23 namespace FileFs {
24 extern "C" {
25 
FfiOHOSFileFsReleaseCString(char * str)26 FFI_EXPORT void FfiOHOSFileFsReleaseCString(char *str)
27 {
28     LOGD("FS_TEST::FfiOHOSFileFsReleaseCString");
29     free(str);
30 }
31 
FfiOHOSFileFsSetXattr(const char * path,const char * key,const char * value)32 FFI_EXPORT int32_t FfiOHOSFileFsSetXattr(const char *path, const char *key, const char *value)
33 {
34     LOGD("FS_TEST::FfiOHOSFileFsSetXattr");
35     if (path == nullptr || key == nullptr || value == nullptr) {
36         return ERR_INVALID_INSTANCE_CODE;
37     }
38     auto state = Xattr::SetSync(path, key, value);
39     if (state != SUCCESS_CODE) {
40         LOGE("FS_TEST::FfiOHOSFileFsSetXattr error");
41         return GetErrorCode(state);
42     }
43     return SUCCESS_CODE;
44 }
45 
FfiOHOSFileFsGetXattr(const char * path,const char * key)46 FFI_EXPORT RetDataCString FfiOHOSFileFsGetXattr(const char *path, const char *key)
47 {
48     LOGD("FS_TEST::FfiOHOSFileFsGetXattr");
49     RetDataCString retData = { .code = ERR_INVALID_INSTANCE_CODE, .data = nullptr };
50     if (path == nullptr || key == nullptr) {
51         return retData;
52     }
53     auto [state, result] = Xattr::GetSync(path, key);
54     if (state != SUCCESS_CODE) {
55         LOGE("FS_TEST::FfiOHOSFileFsGetXattr error");
56         retData.code = GetErrorCode(state);
57         return retData;
58     }
59     retData.data = result;
60     retData.code = SUCCESS_CODE;
61     return retData;
62 }
63 }
64 }  // namespace FileFs
65 }  // namespace CJSystemapi
66 }  // namespace OHOS
67