1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** FileX Component                                                       */
16 /**                                                                       */
17 /**   File                                                                */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define FX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "fx_api.h"
28 #include "fx_file.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _fx_file_best_effort_allocate                       PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    William E. Lamie, Microsoft Corporation                             */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function attempts to allocate the number of consecutive        */
44 /*    clusters required to satisfy the user's request.  If there are not  */
45 /*    enough clusters, the largest set of clusters are allocated and      */
46 /*    linked to the file.  If there are no free clusters, an error        */
47 /*    code is returned to the caller.                                     */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    file_ptr                              File control block pointer    */
52 /*    size                                  Number of bytes to allocate   */
53 /*    actual_size_allocated                 Number of bytes allocated     */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    return status                                                       */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    _fx_file_extended_best_effort_allocate                              */
62 /*                                          Allocate the largest set of   */
63 /*                                            clusters                    */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    Application Code                                                    */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
74 /*  09-30-2020     William E. Lamie         Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_fx_file_best_effort_allocate(FX_FILE * file_ptr,ULONG size,ULONG * actual_size_allocated)78 UINT  _fx_file_best_effort_allocate(FX_FILE *file_ptr, ULONG size, ULONG *actual_size_allocated)
79 {
80 
81 UINT    status;
82 ULONG64 temp_actual_size_allocated;
83 
84     /* Call actual best effort file allocate service.  */
85     status = _fx_file_extended_best_effort_allocate(file_ptr, (ULONG64)size, &temp_actual_size_allocated);
86 
87     /* Check status.  */
88     if (status == FX_SUCCESS)
89     {
90         *actual_size_allocated = (ULONG)temp_actual_size_allocated;
91     }
92 
93     /* Return status to the caller.  */
94     return(status);
95 }
96 
97