1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <stdlib.h>
20 
21 #include <lib/tipc/tipc.h>
22 #include <lk/compiler.h>
23 
24 struct fs;
25 
26 enum storage_aidl_filesystem {
27     STORAGE_AIDL_TP,
28     STORAGE_AIDL_TDEA,
29     STORAGE_AIDL_TDP,
30     STORAGE_AIDL_TD,
31     STORAGE_AIDL_NSP,
32     STORAGE_AIDL_FILESYSTEMS_COUNT,
33 };
34 
35 __BEGIN_CDECLS
36 
37 #if STORAGE_AIDL_ENABLED
38 
39 struct storage_service_aidl_context_inner;
40 
41 struct storage_service_aidl_context {
42     struct storage_service_aidl_context_inner* inner;
43 };
44 
45 #define STORAGE_SERVICE_AIDL_CONTEXT_INITIAL_VALUE(ctx) \
46     (struct storage_service_aidl_context) {             \
47         .inner = NULL                                   \
48     }
49 
50 /**
51  * storage_aidl_create_service() - Initialize a storage aidl service
52  * @ctx: Out-param. Will contain the created &struct
53  * storage_aidl_create_service, which must be cleaned up by passing it to
54  * storage_aidl_delete_service().
55  * @hset: The handle set the service will run on.
56  */
57 int storage_aidl_create_service(struct storage_service_aidl_context* ctx,
58                                 struct tipc_hset* hset);
59 
60 /**
61  * storage_aidl_delete_service() - Delete a storage aidl service
62  * @ctx: The &struct storage_aidl_create_service to delete. When called, there
63  * must not be any remaining AIDL objects created from @ctx that are still
64  * callable (including remotely).
65  */
66 void storage_aidl_delete_service(struct storage_service_aidl_context* ctx);
67 
68 /**
69  * storage_aidl_enable_filesystem() - Connect the storage aidl service to a
70  * backing filesystem
71  * @ctx: The &struct storage_aidl_create_service to modify.
72  * @fs: Filesystem object to use for access when AIDL calls are made.
73  * @fs_type: The type of filesystem to connect. Callers should not connect a
74  * second time for the same @fs_type without calling
75  * storage_aidl_disable_filesystem() first.
76  */
77 void storage_aidl_enable_filesystem(struct storage_service_aidl_context* ctx,
78                                     struct fs* fs,
79                                     enum storage_aidl_filesystem fs_type);
80 
81 /**
82  * storage_aidl_disable_filesystem() - Disconnect the storage aidl service from
83  a backing filesystem
84  * @ctx: The &struct storage_aidl_create_service to modify.
85  * @fs_type: The type of filesystem to disconnect. Callers should not disconnect
86  from a @fs_type that has not been previously connected with
87  storage_aidl_enable_filesystem().
88 
89  */
90 void storage_aidl_disable_filesystem(struct storage_service_aidl_context* ctx,
91                                      enum storage_aidl_filesystem fs_type);
92 
93 #else
94 
95 struct storage_service_aidl_context {};
96 
97 #define STORAGE_SERVICE_AIDL_CONTEXT_INITIAL_VALUE(ctx) \
98     (struct storage_service_aidl_context) {}
99 
100 static inline int storage_aidl_create_service(
101         struct storage_service_aidl_context* ctx,
102         struct tipc_hset* hset) {
103     *ctx = STORAGE_SERVICE_AIDL_CONTEXT_INITIAL_VALUE(*ctx);
104     return EXIT_SUCCESS;
105 }
106 
107 static inline void storage_aidl_delete_service(
108         struct storage_service_aidl_context* ctx) {}
109 
110 static inline void storage_aidl_enable_filesystem(
111         struct storage_service_aidl_context* ctx,
112         struct fs* fs,
113         enum storage_aidl_filesystem fs_type) {}
114 
115 static inline void storage_aidl_disable_filesystem(
116         struct storage_service_aidl_context* ctx,
117         enum storage_aidl_filesystem fs_type) {}
118 
119 #endif
120 
121 __END_CDECLS
122