GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_device_classes/src/ux_device_class_storage_prevent_allow_media_removal.c Lines: 6 7 85.7 %
Date: 2026-03-06 18:57:10 Branches: 1 2 50.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** USBX Component                                                        */
17
/**                                                                       */
18
/**   Device Storage Class                                                */
19
/**                                                                       */
20
/**************************************************************************/
21
/**************************************************************************/
22
23
#define UX_SOURCE_CODE
24
25
26
/* Include necessary system files.  */
27
28
#include "ux_api.h"
29
#include "ux_device_class_storage.h"
30
#include "ux_device_stack.h"
31
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _ux_device_class_storage_prevent_allow_media_removal                */
38
/*                                                        PORTABLE C      */
39
/*                                                           6.1          */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Chaoqiong Xiao, Microsoft Corporation                               */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function allows or prevents the removal of the media.          */
47
/*    The PREVENT ALLOW MEDIUM REMOVAL command allows an application      */
48
/*    client to restrict the demounting of the removable                  */
49
/*    medium.                                                             */
50
/*                                                                        */
51
/*  INPUT                                                                 */
52
/*                                                                        */
53
/*    storage                               Pointer to storage class      */
54
/*    lun                                   Logical unit number           */
55
/*    endpoint_in                           Pointer to IN endpoint        */
56
/*    endpoint_out                          Pointer to OUT endpoint       */
57
/*    cbwcb                                 Pointer to CBWCB              */
58
/*                                                                        */
59
/*  OUTPUT                                                                */
60
/*                                                                        */
61
/*    Completion Status                                                   */
62
/*                                                                        */
63
/*  CALLS                                                                 */
64
/*                                                                        */
65
/*    None                                                                */
66
/*                                                                        */
67
/*  CALLED BY                                                             */
68
/*                                                                        */
69
/*    Device Storage Class                                                */
70
/*                                                                        */
71
/**************************************************************************/
72
1
UINT  _ux_device_class_storage_prevent_allow_media_removal(UX_SLAVE_CLASS_STORAGE *storage, ULONG lun,
73
                                            UX_SLAVE_ENDPOINT *endpoint_in,
74
                                            UX_SLAVE_ENDPOINT *endpoint_out, UCHAR * cbwcb)
75
{
76
77
ULONG   prevent_flag;
78
79
    UX_PARAMETER_NOT_USED(endpoint_in);
80
    UX_PARAMETER_NOT_USED(endpoint_out);
81
82
    /* If trace is enabled, insert this event into the trace buffer.  */
83
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_STORAGE_PREVENT_ALLOW_MEDIA_REMOVAL, storage, lun, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
84
85
    /* Parse the PREVENT/ALLOW MEDIA REMOVAL command: byte 4 bit 0 is the prevent flag.  */
86
1
    prevent_flag = (ULONG)(cbwcb[4] & 0x01);
87
88
    /* Update internal flag to track prevent/allow state for this LUN.  */
89
1
    if (prevent_flag == UX_SLAVE_CLASS_STORAGE_MEDIUM_REMOVAL_IS_ALLOWED)
90
1
        storage -> ux_slave_class_storage_lun[lun].ux_slave_class_storage_prevent_medium_removal = 0;
91
    else
92
        storage -> ux_slave_class_storage_lun[lun].ux_slave_class_storage_prevent_medium_removal = 1;
93
94
    /* We set the CSW with success.  */
95
1
    storage -> ux_slave_class_storage_csw_status = UX_SLAVE_CLASS_STORAGE_CSW_PASSED;
96
97
    /* Return successful completion.  */
98
1
    return(UX_SUCCESS);
99
}