fidl_fuchsia_storage_partitions_common/
fidl_fuchsia_storage_partitions_common.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
8use futures::future::{self, MaybeDone, TryFutureExt};
9use zx_status;
10
11pub const MAX_PARTITIONS: u32 = 128;
12
13#[derive(Clone, Debug, PartialEq)]
14pub struct PartitionInfo {
15    pub name: String,
16    pub type_guid: fidl_fuchsia_hardware_block_partition::Guid,
17    pub instance_guid: fidl_fuchsia_hardware_block_partition::Guid,
18    pub start_block: u64,
19    pub num_blocks: u64,
20    pub flags: u64,
21}
22
23impl fidl::Persistable for PartitionInfo {}
24
25#[derive(Clone, Debug, PartialEq)]
26pub struct PartitionsAdminResetPartitionTableRequest {
27    pub partitions: Vec<PartitionInfo>,
28}
29
30impl fidl::Persistable for PartitionsAdminResetPartitionTableRequest {}
31
32#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
33#[repr(C)]
34pub struct PartitionsManagerGetBlockInfoResponse {
35    pub block_count: u64,
36    pub block_size: u32,
37}
38
39impl fidl::Persistable for PartitionsManagerGetBlockInfoResponse {}
40
41mod internal {
42    use super::*;
43
44    impl fidl::encoding::ValueTypeMarker for PartitionInfo {
45        type Borrowed<'a> = &'a Self;
46        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
47            value
48        }
49    }
50
51    unsafe impl fidl::encoding::TypeMarker for PartitionInfo {
52        type Owned = Self;
53
54        #[inline(always)]
55        fn inline_align(_context: fidl::encoding::Context) -> usize {
56            8
57        }
58
59        #[inline(always)]
60        fn inline_size(_context: fidl::encoding::Context) -> usize {
61            72
62        }
63    }
64
65    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<PartitionInfo, D>
66        for &PartitionInfo
67    {
68        #[inline]
69        unsafe fn encode(
70            self,
71            encoder: &mut fidl::encoding::Encoder<'_, D>,
72            offset: usize,
73            _depth: fidl::encoding::Depth,
74        ) -> fidl::Result<()> {
75            encoder.debug_check_bounds::<PartitionInfo>(offset);
76            // Delegate to tuple encoding.
77            fidl::encoding::Encode::<PartitionInfo, D>::encode(
78                (
79                    <fidl::encoding::BoundedString<128> as fidl::encoding::ValueTypeMarker>::borrow(&self.name),
80                    <fidl_fuchsia_hardware_block_partition::Guid as fidl::encoding::ValueTypeMarker>::borrow(&self.type_guid),
81                    <fidl_fuchsia_hardware_block_partition::Guid as fidl::encoding::ValueTypeMarker>::borrow(&self.instance_guid),
82                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.start_block),
83                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.num_blocks),
84                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.flags),
85                ),
86                encoder, offset, _depth
87            )
88        }
89    }
90    unsafe impl<
91            D: fidl::encoding::ResourceDialect,
92            T0: fidl::encoding::Encode<fidl::encoding::BoundedString<128>, D>,
93            T1: fidl::encoding::Encode<fidl_fuchsia_hardware_block_partition::Guid, D>,
94            T2: fidl::encoding::Encode<fidl_fuchsia_hardware_block_partition::Guid, D>,
95            T3: fidl::encoding::Encode<u64, D>,
96            T4: fidl::encoding::Encode<u64, D>,
97            T5: fidl::encoding::Encode<u64, D>,
98        > fidl::encoding::Encode<PartitionInfo, D> for (T0, T1, T2, T3, T4, T5)
99    {
100        #[inline]
101        unsafe fn encode(
102            self,
103            encoder: &mut fidl::encoding::Encoder<'_, D>,
104            offset: usize,
105            depth: fidl::encoding::Depth,
106        ) -> fidl::Result<()> {
107            encoder.debug_check_bounds::<PartitionInfo>(offset);
108            // Zero out padding regions. There's no need to apply masks
109            // because the unmasked parts will be overwritten by fields.
110            // Write the fields.
111            self.0.encode(encoder, offset + 0, depth)?;
112            self.1.encode(encoder, offset + 16, depth)?;
113            self.2.encode(encoder, offset + 32, depth)?;
114            self.3.encode(encoder, offset + 48, depth)?;
115            self.4.encode(encoder, offset + 56, depth)?;
116            self.5.encode(encoder, offset + 64, depth)?;
117            Ok(())
118        }
119    }
120
121    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for PartitionInfo {
122        #[inline(always)]
123        fn new_empty() -> Self {
124            Self {
125                name: fidl::new_empty!(fidl::encoding::BoundedString<128>, D),
126                type_guid: fidl::new_empty!(fidl_fuchsia_hardware_block_partition::Guid, D),
127                instance_guid: fidl::new_empty!(fidl_fuchsia_hardware_block_partition::Guid, D),
128                start_block: fidl::new_empty!(u64, D),
129                num_blocks: fidl::new_empty!(u64, D),
130                flags: fidl::new_empty!(u64, D),
131            }
132        }
133
134        #[inline]
135        unsafe fn decode(
136            &mut self,
137            decoder: &mut fidl::encoding::Decoder<'_, D>,
138            offset: usize,
139            _depth: fidl::encoding::Depth,
140        ) -> fidl::Result<()> {
141            decoder.debug_check_bounds::<Self>(offset);
142            // Verify that padding bytes are zero.
143            fidl::decode!(
144                fidl::encoding::BoundedString<128>,
145                D,
146                &mut self.name,
147                decoder,
148                offset + 0,
149                _depth
150            )?;
151            fidl::decode!(
152                fidl_fuchsia_hardware_block_partition::Guid,
153                D,
154                &mut self.type_guid,
155                decoder,
156                offset + 16,
157                _depth
158            )?;
159            fidl::decode!(
160                fidl_fuchsia_hardware_block_partition::Guid,
161                D,
162                &mut self.instance_guid,
163                decoder,
164                offset + 32,
165                _depth
166            )?;
167            fidl::decode!(u64, D, &mut self.start_block, decoder, offset + 48, _depth)?;
168            fidl::decode!(u64, D, &mut self.num_blocks, decoder, offset + 56, _depth)?;
169            fidl::decode!(u64, D, &mut self.flags, decoder, offset + 64, _depth)?;
170            Ok(())
171        }
172    }
173
174    impl fidl::encoding::ValueTypeMarker for PartitionsAdminResetPartitionTableRequest {
175        type Borrowed<'a> = &'a Self;
176        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
177            value
178        }
179    }
180
181    unsafe impl fidl::encoding::TypeMarker for PartitionsAdminResetPartitionTableRequest {
182        type Owned = Self;
183
184        #[inline(always)]
185        fn inline_align(_context: fidl::encoding::Context) -> usize {
186            8
187        }
188
189        #[inline(always)]
190        fn inline_size(_context: fidl::encoding::Context) -> usize {
191            16
192        }
193    }
194
195    unsafe impl<D: fidl::encoding::ResourceDialect>
196        fidl::encoding::Encode<PartitionsAdminResetPartitionTableRequest, D>
197        for &PartitionsAdminResetPartitionTableRequest
198    {
199        #[inline]
200        unsafe fn encode(
201            self,
202            encoder: &mut fidl::encoding::Encoder<'_, D>,
203            offset: usize,
204            _depth: fidl::encoding::Depth,
205        ) -> fidl::Result<()> {
206            encoder.debug_check_bounds::<PartitionsAdminResetPartitionTableRequest>(offset);
207            // Delegate to tuple encoding.
208            fidl::encoding::Encode::<PartitionsAdminResetPartitionTableRequest, D>::encode(
209                (
210                    <fidl::encoding::Vector<PartitionInfo, 128> as fidl::encoding::ValueTypeMarker>::borrow(&self.partitions),
211                ),
212                encoder, offset, _depth
213            )
214        }
215    }
216    unsafe impl<
217            D: fidl::encoding::ResourceDialect,
218            T0: fidl::encoding::Encode<fidl::encoding::Vector<PartitionInfo, 128>, D>,
219        > fidl::encoding::Encode<PartitionsAdminResetPartitionTableRequest, D> for (T0,)
220    {
221        #[inline]
222        unsafe fn encode(
223            self,
224            encoder: &mut fidl::encoding::Encoder<'_, D>,
225            offset: usize,
226            depth: fidl::encoding::Depth,
227        ) -> fidl::Result<()> {
228            encoder.debug_check_bounds::<PartitionsAdminResetPartitionTableRequest>(offset);
229            // Zero out padding regions. There's no need to apply masks
230            // because the unmasked parts will be overwritten by fields.
231            // Write the fields.
232            self.0.encode(encoder, offset + 0, depth)?;
233            Ok(())
234        }
235    }
236
237    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
238        for PartitionsAdminResetPartitionTableRequest
239    {
240        #[inline(always)]
241        fn new_empty() -> Self {
242            Self { partitions: fidl::new_empty!(fidl::encoding::Vector<PartitionInfo, 128>, D) }
243        }
244
245        #[inline]
246        unsafe fn decode(
247            &mut self,
248            decoder: &mut fidl::encoding::Decoder<'_, D>,
249            offset: usize,
250            _depth: fidl::encoding::Depth,
251        ) -> fidl::Result<()> {
252            decoder.debug_check_bounds::<Self>(offset);
253            // Verify that padding bytes are zero.
254            fidl::decode!(fidl::encoding::Vector<PartitionInfo, 128>, D, &mut self.partitions, decoder, offset + 0, _depth)?;
255            Ok(())
256        }
257    }
258
259    impl fidl::encoding::ValueTypeMarker for PartitionsManagerGetBlockInfoResponse {
260        type Borrowed<'a> = &'a Self;
261        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
262            value
263        }
264    }
265
266    unsafe impl fidl::encoding::TypeMarker for PartitionsManagerGetBlockInfoResponse {
267        type Owned = Self;
268
269        #[inline(always)]
270        fn inline_align(_context: fidl::encoding::Context) -> usize {
271            8
272        }
273
274        #[inline(always)]
275        fn inline_size(_context: fidl::encoding::Context) -> usize {
276            16
277        }
278    }
279
280    unsafe impl<D: fidl::encoding::ResourceDialect>
281        fidl::encoding::Encode<PartitionsManagerGetBlockInfoResponse, D>
282        for &PartitionsManagerGetBlockInfoResponse
283    {
284        #[inline]
285        unsafe fn encode(
286            self,
287            encoder: &mut fidl::encoding::Encoder<'_, D>,
288            offset: usize,
289            _depth: fidl::encoding::Depth,
290        ) -> fidl::Result<()> {
291            encoder.debug_check_bounds::<PartitionsManagerGetBlockInfoResponse>(offset);
292            unsafe {
293                // Copy the object into the buffer.
294                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
295                (buf_ptr as *mut PartitionsManagerGetBlockInfoResponse)
296                    .write_unaligned((self as *const PartitionsManagerGetBlockInfoResponse).read());
297                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
298                // done second because the memcpy will write garbage to these bytes.
299                let padding_ptr = buf_ptr.offset(8) as *mut u64;
300                let padding_mask = 0xffffffff00000000u64;
301                padding_ptr.write_unaligned(padding_ptr.read_unaligned() & !padding_mask);
302            }
303            Ok(())
304        }
305    }
306    unsafe impl<
307            D: fidl::encoding::ResourceDialect,
308            T0: fidl::encoding::Encode<u64, D>,
309            T1: fidl::encoding::Encode<u32, D>,
310        > fidl::encoding::Encode<PartitionsManagerGetBlockInfoResponse, D> for (T0, T1)
311    {
312        #[inline]
313        unsafe fn encode(
314            self,
315            encoder: &mut fidl::encoding::Encoder<'_, D>,
316            offset: usize,
317            depth: fidl::encoding::Depth,
318        ) -> fidl::Result<()> {
319            encoder.debug_check_bounds::<PartitionsManagerGetBlockInfoResponse>(offset);
320            // Zero out padding regions. There's no need to apply masks
321            // because the unmasked parts will be overwritten by fields.
322            unsafe {
323                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(8);
324                (ptr as *mut u64).write_unaligned(0);
325            }
326            // Write the fields.
327            self.0.encode(encoder, offset + 0, depth)?;
328            self.1.encode(encoder, offset + 8, depth)?;
329            Ok(())
330        }
331    }
332
333    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
334        for PartitionsManagerGetBlockInfoResponse
335    {
336        #[inline(always)]
337        fn new_empty() -> Self {
338            Self { block_count: fidl::new_empty!(u64, D), block_size: fidl::new_empty!(u32, D) }
339        }
340
341        #[inline]
342        unsafe fn decode(
343            &mut self,
344            decoder: &mut fidl::encoding::Decoder<'_, D>,
345            offset: usize,
346            _depth: fidl::encoding::Depth,
347        ) -> fidl::Result<()> {
348            decoder.debug_check_bounds::<Self>(offset);
349            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
350            // Verify that padding bytes are zero.
351            let ptr = unsafe { buf_ptr.offset(8) };
352            let padval = unsafe { (ptr as *const u64).read_unaligned() };
353            let mask = 0xffffffff00000000u64;
354            let maskedval = padval & mask;
355            if maskedval != 0 {
356                return Err(fidl::Error::NonZeroPadding {
357                    padding_start: offset + 8 + ((mask as u64).trailing_zeros() / 8) as usize,
358                });
359            }
360            // Copy from the buffer into the object.
361            unsafe {
362                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 16);
363            }
364            Ok(())
365        }
366    }
367}