1 /*
2  * Copyright (C) 2022 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 #ifndef FSCRYPT_CONTROL_H
16 #define FSCRYPT_CONTROL_H
17 
18 #include "key_control.h"
19 #include <stdint.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 #define SDP_VERSIOIN 0
25 #define SDP_FLAGS 0
26 #define SDP_CONTENTS_ENCRYPTION_MODE 1
27 #define SDP_FILENAMES_ENCRYPTION_MODE 4
28 #define FS_KEY_DESC_SIZE 8
29 #define F2FS_IOCTL_MAGIC 0xf5
30 #define F2FS_IOC_SET_SDP_ENCRYPTION_POLICY _IOW(F2FS_IOCTL_MAGIC, 80, struct FscryptSdpPolicy)
31 
32 #pragma pack(push, 1)
33 struct FscryptSdpPolicy {
34     uint8_t version;
35     uint8_t sdpclass;
36     uint8_t contentsEncryptionMode;
37     uint8_t filenamesEncryptionMode;
38     uint8_t flags;
39     uint8_t masterKeyDescriptor[FS_KEY_DESC_SIZE];
40 };
41 #pragma pack(pop)
42 
43 int FscryptSetSysparam(const char *policy);
44 int SetGlobalEl1DirPolicy(const char *dir);
45 int LoadAndSetPolicy(const char *keyDir, const char *dir);
46 int LoadAndSetEceAndSecePolicy(const char *keyDir, const char *dir, int type);
47 int InitFscryptPolicy(void);
48 uint8_t GetFscryptVersionFromPolicy(void);
49 
50 #ifdef __cplusplus
51 }
52 #endif
53 
54 #endif