1#![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 type Vmoid = u16;
12
13pub const BLOCK_GUID_LEN: u32 = 16;
14
15pub const BLOCK_VMOID_INVALID: u16 = 0;
16
17pub const MAX_TXN_GROUP_COUNT: u32 = 8;
74
75bitflags! {
76 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
77 pub struct BlockIoFlag: u32 {
78 const GROUP_ITEM = 1;
80 const GROUP_LAST = 2;
83 const FORCE_ACCESS = 4;
87 }
88}
89
90impl BlockIoFlag {
91 #[deprecated = "Strict bits should not use `has_unknown_bits`"]
92 #[inline(always)]
93 pub fn has_unknown_bits(&self) -> bool {
94 false
95 }
96
97 #[deprecated = "Strict bits should not use `get_unknown_bits`"]
98 #[inline(always)]
99 pub fn get_unknown_bits(&self) -> u32 {
100 0
101 }
102}
103
104#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
105#[repr(u8)]
106pub enum BlockOpcode {
107 Read = 1,
110 Write = 2,
111 Flush = 3,
113 Trim = 4,
119 CloseVmo = 5,
121}
122
123impl BlockOpcode {
124 #[inline]
125 pub fn from_primitive(prim: u8) -> Option<Self> {
126 match prim {
127 1 => Some(Self::Read),
128 2 => Some(Self::Write),
129 3 => Some(Self::Flush),
130 4 => Some(Self::Trim),
131 5 => Some(Self::CloseVmo),
132 _ => None,
133 }
134 }
135
136 #[inline]
137 pub const fn into_primitive(self) -> u8 {
138 self as u8
139 }
140
141 #[deprecated = "Strict enums should not use `is_unknown`"]
142 #[inline]
143 pub fn is_unknown(&self) -> bool {
144 false
145 }
146}
147
148#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
149pub struct BlockCommand {
150 pub opcode: BlockOpcode,
151 pub flags: BlockIoFlag,
152}
153
154impl fidl::Persistable for BlockCommand {}
155
156#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
158pub struct BlockTrim {
159 pub command: BlockCommand,
161 pub length: u32,
163 pub offset_dev: u64,
165}
166
167impl fidl::Persistable for BlockTrim {}
168
169#[derive(Clone, Debug, PartialEq)]
170pub struct CommonQueryResponse {
171 pub info: fidl_fuchsia_hardware_block::BlockInfo,
172 pub block_op_size: u64,
173}
174
175impl fidl::Persistable for CommonQueryResponse {}
176
177mod internal {
178 use super::*;
179 unsafe impl fidl::encoding::TypeMarker for BlockIoFlag {
180 type Owned = Self;
181
182 #[inline(always)]
183 fn inline_align(_context: fidl::encoding::Context) -> usize {
184 4
185 }
186
187 #[inline(always)]
188 fn inline_size(_context: fidl::encoding::Context) -> usize {
189 4
190 }
191 }
192
193 impl fidl::encoding::ValueTypeMarker for BlockIoFlag {
194 type Borrowed<'a> = Self;
195 #[inline(always)]
196 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
197 *value
198 }
199 }
200
201 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for BlockIoFlag {
202 #[inline]
203 unsafe fn encode(
204 self,
205 encoder: &mut fidl::encoding::Encoder<'_, D>,
206 offset: usize,
207 _depth: fidl::encoding::Depth,
208 ) -> fidl::Result<()> {
209 encoder.debug_check_bounds::<Self>(offset);
210 if self.bits() & Self::all().bits() != self.bits() {
211 return Err(fidl::Error::InvalidBitsValue);
212 }
213 encoder.write_num(self.bits(), offset);
214 Ok(())
215 }
216 }
217
218 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for BlockIoFlag {
219 #[inline(always)]
220 fn new_empty() -> Self {
221 Self::empty()
222 }
223
224 #[inline]
225 unsafe fn decode(
226 &mut self,
227 decoder: &mut fidl::encoding::Decoder<'_, D>,
228 offset: usize,
229 _depth: fidl::encoding::Depth,
230 ) -> fidl::Result<()> {
231 decoder.debug_check_bounds::<Self>(offset);
232 let prim = decoder.read_num::<u32>(offset);
233 *self = Self::from_bits(prim).ok_or(fidl::Error::InvalidBitsValue)?;
234 Ok(())
235 }
236 }
237 unsafe impl fidl::encoding::TypeMarker for BlockOpcode {
238 type Owned = Self;
239
240 #[inline(always)]
241 fn inline_align(_context: fidl::encoding::Context) -> usize {
242 std::mem::align_of::<u8>()
243 }
244
245 #[inline(always)]
246 fn inline_size(_context: fidl::encoding::Context) -> usize {
247 std::mem::size_of::<u8>()
248 }
249
250 #[inline(always)]
251 fn encode_is_copy() -> bool {
252 true
253 }
254
255 #[inline(always)]
256 fn decode_is_copy() -> bool {
257 false
258 }
259 }
260
261 impl fidl::encoding::ValueTypeMarker for BlockOpcode {
262 type Borrowed<'a> = Self;
263 #[inline(always)]
264 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
265 *value
266 }
267 }
268
269 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for BlockOpcode {
270 #[inline]
271 unsafe fn encode(
272 self,
273 encoder: &mut fidl::encoding::Encoder<'_, D>,
274 offset: usize,
275 _depth: fidl::encoding::Depth,
276 ) -> fidl::Result<()> {
277 encoder.debug_check_bounds::<Self>(offset);
278 encoder.write_num(self.into_primitive(), offset);
279 Ok(())
280 }
281 }
282
283 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for BlockOpcode {
284 #[inline(always)]
285 fn new_empty() -> Self {
286 Self::Read
287 }
288
289 #[inline]
290 unsafe fn decode(
291 &mut self,
292 decoder: &mut fidl::encoding::Decoder<'_, D>,
293 offset: usize,
294 _depth: fidl::encoding::Depth,
295 ) -> fidl::Result<()> {
296 decoder.debug_check_bounds::<Self>(offset);
297 let prim = decoder.read_num::<u8>(offset);
298
299 *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
300 Ok(())
301 }
302 }
303
304 impl fidl::encoding::ValueTypeMarker for BlockCommand {
305 type Borrowed<'a> = &'a Self;
306 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
307 value
308 }
309 }
310
311 unsafe impl fidl::encoding::TypeMarker for BlockCommand {
312 type Owned = Self;
313
314 #[inline(always)]
315 fn inline_align(_context: fidl::encoding::Context) -> usize {
316 4
317 }
318
319 #[inline(always)]
320 fn inline_size(_context: fidl::encoding::Context) -> usize {
321 8
322 }
323 }
324
325 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<BlockCommand, D>
326 for &BlockCommand
327 {
328 #[inline]
329 unsafe fn encode(
330 self,
331 encoder: &mut fidl::encoding::Encoder<'_, D>,
332 offset: usize,
333 _depth: fidl::encoding::Depth,
334 ) -> fidl::Result<()> {
335 encoder.debug_check_bounds::<BlockCommand>(offset);
336 fidl::encoding::Encode::<BlockCommand, D>::encode(
338 (
339 <BlockOpcode as fidl::encoding::ValueTypeMarker>::borrow(&self.opcode),
340 <BlockIoFlag as fidl::encoding::ValueTypeMarker>::borrow(&self.flags),
341 ),
342 encoder,
343 offset,
344 _depth,
345 )
346 }
347 }
348 unsafe impl<
349 D: fidl::encoding::ResourceDialect,
350 T0: fidl::encoding::Encode<BlockOpcode, D>,
351 T1: fidl::encoding::Encode<BlockIoFlag, D>,
352 > fidl::encoding::Encode<BlockCommand, D> for (T0, T1)
353 {
354 #[inline]
355 unsafe fn encode(
356 self,
357 encoder: &mut fidl::encoding::Encoder<'_, D>,
358 offset: usize,
359 depth: fidl::encoding::Depth,
360 ) -> fidl::Result<()> {
361 encoder.debug_check_bounds::<BlockCommand>(offset);
362 unsafe {
365 let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
366 (ptr as *mut u32).write_unaligned(0);
367 }
368 self.0.encode(encoder, offset + 0, depth)?;
370 self.1.encode(encoder, offset + 4, depth)?;
371 Ok(())
372 }
373 }
374
375 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for BlockCommand {
376 #[inline(always)]
377 fn new_empty() -> Self {
378 Self {
379 opcode: fidl::new_empty!(BlockOpcode, D),
380 flags: fidl::new_empty!(BlockIoFlag, D),
381 }
382 }
383
384 #[inline]
385 unsafe fn decode(
386 &mut self,
387 decoder: &mut fidl::encoding::Decoder<'_, D>,
388 offset: usize,
389 _depth: fidl::encoding::Depth,
390 ) -> fidl::Result<()> {
391 decoder.debug_check_bounds::<Self>(offset);
392 let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
394 let padval = unsafe { (ptr as *const u32).read_unaligned() };
395 let mask = 0xffffff00u32;
396 let maskedval = padval & mask;
397 if maskedval != 0 {
398 return Err(fidl::Error::NonZeroPadding {
399 padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
400 });
401 }
402 fidl::decode!(BlockOpcode, D, &mut self.opcode, decoder, offset + 0, _depth)?;
403 fidl::decode!(BlockIoFlag, D, &mut self.flags, decoder, offset + 4, _depth)?;
404 Ok(())
405 }
406 }
407
408 impl fidl::encoding::ValueTypeMarker for BlockTrim {
409 type Borrowed<'a> = &'a Self;
410 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
411 value
412 }
413 }
414
415 unsafe impl fidl::encoding::TypeMarker for BlockTrim {
416 type Owned = Self;
417
418 #[inline(always)]
419 fn inline_align(_context: fidl::encoding::Context) -> usize {
420 8
421 }
422
423 #[inline(always)]
424 fn inline_size(_context: fidl::encoding::Context) -> usize {
425 24
426 }
427 }
428
429 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<BlockTrim, D>
430 for &BlockTrim
431 {
432 #[inline]
433 unsafe fn encode(
434 self,
435 encoder: &mut fidl::encoding::Encoder<'_, D>,
436 offset: usize,
437 _depth: fidl::encoding::Depth,
438 ) -> fidl::Result<()> {
439 encoder.debug_check_bounds::<BlockTrim>(offset);
440 fidl::encoding::Encode::<BlockTrim, D>::encode(
442 (
443 <BlockCommand as fidl::encoding::ValueTypeMarker>::borrow(&self.command),
444 <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.length),
445 <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.offset_dev),
446 ),
447 encoder,
448 offset,
449 _depth,
450 )
451 }
452 }
453 unsafe impl<
454 D: fidl::encoding::ResourceDialect,
455 T0: fidl::encoding::Encode<BlockCommand, D>,
456 T1: fidl::encoding::Encode<u32, D>,
457 T2: fidl::encoding::Encode<u64, D>,
458 > fidl::encoding::Encode<BlockTrim, D> for (T0, T1, T2)
459 {
460 #[inline]
461 unsafe fn encode(
462 self,
463 encoder: &mut fidl::encoding::Encoder<'_, D>,
464 offset: usize,
465 depth: fidl::encoding::Depth,
466 ) -> fidl::Result<()> {
467 encoder.debug_check_bounds::<BlockTrim>(offset);
468 unsafe {
471 let ptr = encoder.buf.as_mut_ptr().add(offset).offset(8);
472 (ptr as *mut u64).write_unaligned(0);
473 }
474 self.0.encode(encoder, offset + 0, depth)?;
476 self.1.encode(encoder, offset + 8, depth)?;
477 self.2.encode(encoder, offset + 16, depth)?;
478 Ok(())
479 }
480 }
481
482 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for BlockTrim {
483 #[inline(always)]
484 fn new_empty() -> Self {
485 Self {
486 command: fidl::new_empty!(BlockCommand, D),
487 length: fidl::new_empty!(u32, D),
488 offset_dev: fidl::new_empty!(u64, D),
489 }
490 }
491
492 #[inline]
493 unsafe fn decode(
494 &mut self,
495 decoder: &mut fidl::encoding::Decoder<'_, D>,
496 offset: usize,
497 _depth: fidl::encoding::Depth,
498 ) -> fidl::Result<()> {
499 decoder.debug_check_bounds::<Self>(offset);
500 let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(8) };
502 let padval = unsafe { (ptr as *const u64).read_unaligned() };
503 let mask = 0xffffffff00000000u64;
504 let maskedval = padval & mask;
505 if maskedval != 0 {
506 return Err(fidl::Error::NonZeroPadding {
507 padding_start: offset + 8 + ((mask as u64).trailing_zeros() / 8) as usize,
508 });
509 }
510 fidl::decode!(BlockCommand, D, &mut self.command, decoder, offset + 0, _depth)?;
511 fidl::decode!(u32, D, &mut self.length, decoder, offset + 8, _depth)?;
512 fidl::decode!(u64, D, &mut self.offset_dev, decoder, offset + 16, _depth)?;
513 Ok(())
514 }
515 }
516
517 impl fidl::encoding::ValueTypeMarker for CommonQueryResponse {
518 type Borrowed<'a> = &'a Self;
519 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
520 value
521 }
522 }
523
524 unsafe impl fidl::encoding::TypeMarker for CommonQueryResponse {
525 type Owned = Self;
526
527 #[inline(always)]
528 fn inline_align(_context: fidl::encoding::Context) -> usize {
529 8
530 }
531
532 #[inline(always)]
533 fn inline_size(_context: fidl::encoding::Context) -> usize {
534 32
535 }
536 }
537
538 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<CommonQueryResponse, D>
539 for &CommonQueryResponse
540 {
541 #[inline]
542 unsafe fn encode(
543 self,
544 encoder: &mut fidl::encoding::Encoder<'_, D>,
545 offset: usize,
546 _depth: fidl::encoding::Depth,
547 ) -> fidl::Result<()> {
548 encoder.debug_check_bounds::<CommonQueryResponse>(offset);
549 fidl::encoding::Encode::<CommonQueryResponse, D>::encode(
551 (
552 <fidl_fuchsia_hardware_block::BlockInfo as fidl::encoding::ValueTypeMarker>::borrow(&self.info),
553 <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.block_op_size),
554 ),
555 encoder, offset, _depth
556 )
557 }
558 }
559 unsafe impl<
560 D: fidl::encoding::ResourceDialect,
561 T0: fidl::encoding::Encode<fidl_fuchsia_hardware_block::BlockInfo, D>,
562 T1: fidl::encoding::Encode<u64, D>,
563 > fidl::encoding::Encode<CommonQueryResponse, D> for (T0, T1)
564 {
565 #[inline]
566 unsafe fn encode(
567 self,
568 encoder: &mut fidl::encoding::Encoder<'_, D>,
569 offset: usize,
570 depth: fidl::encoding::Depth,
571 ) -> fidl::Result<()> {
572 encoder.debug_check_bounds::<CommonQueryResponse>(offset);
573 self.0.encode(encoder, offset + 0, depth)?;
577 self.1.encode(encoder, offset + 24, depth)?;
578 Ok(())
579 }
580 }
581
582 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for CommonQueryResponse {
583 #[inline(always)]
584 fn new_empty() -> Self {
585 Self {
586 info: fidl::new_empty!(fidl_fuchsia_hardware_block::BlockInfo, D),
587 block_op_size: fidl::new_empty!(u64, D),
588 }
589 }
590
591 #[inline]
592 unsafe fn decode(
593 &mut self,
594 decoder: &mut fidl::encoding::Decoder<'_, D>,
595 offset: usize,
596 _depth: fidl::encoding::Depth,
597 ) -> fidl::Result<()> {
598 decoder.debug_check_bounds::<Self>(offset);
599 fidl::decode!(
601 fidl_fuchsia_hardware_block::BlockInfo,
602 D,
603 &mut self.info,
604 decoder,
605 offset + 0,
606 _depth
607 )?;
608 fidl::decode!(u64, D, &mut self.block_op_size, decoder, offset + 24, _depth)?;
609 Ok(())
610 }
611 }
612}