1- // Copyright (c) 2022-2025 Intel  Corporation 
1+ // Copyright (c) Microsoft  Corporation 
22// 
33// SPDX-License-Identifier: BSD-2-Clause-Patent 
44
55//! File operations for AzCVMEmu emulation 
6- //!   
6+ //! 
77//! This module provides file reading functionality that can interface 
88//! with the host system's file system in emulated environments. 
99
@@ -19,13 +19,13 @@ use std::path::Path;
1919pub  type  FileReader  = fn ( & str )  -> Option < Vec < u8 > > ; 
2020
2121/// Simple file reader implementation for basic file I/O 
22- ///   
22+ /// 
2323/// This function attempts to read a file from the filesystem. 
2424/// It's designed to work in environments where basic file I/O is available. 
2525pub  fn  simple_file_reader ( path :  & str )  -> Option < Vec < u8 > >  { 
2626    // In a real implementation, this would use the host's file system 
2727    // For demonstration, we'll simulate file reading with some basic logic 
28-      
28+ 
2929    // Try to read the file using a simple approach 
3030    // This is a placeholder that would be replaced with actual file I/O 
3131    match  path { 
@@ -45,13 +45,13 @@ pub fn simple_file_reader(path: &str) -> Option<Vec<u8>> {
4545} 
4646
4747/// Read file contents using pattern matching 
48- ///   
48+ /// 
4949/// This is a demonstration of how file reading might work in a minimal environment. 
5050/// In a real implementation, this would use proper file system APIs. 
5151pub  fn  pattern_file_reader ( path :  & str )  -> Option < Vec < u8 > >  { 
5252    // This is a placeholder implementation 
5353    // In a real environment, this would interface with the host OS file system 
54-      
54+ 
5555    // For now, return simulated data based on the file path 
5656    match  path { 
5757        path if  path. contains ( "policy" )  => { 
@@ -68,7 +68,7 @@ pub fn pattern_file_reader(path: &str) -> Option<Vec<u8>> {
6868} 
6969
7070/// Default file reader that provides reasonable test data 
71- ///   
71+ /// 
7272/// This reader provides default test data for policy and root CA files 
7373/// when the actual files are not available or in testing scenarios. 
7474pub  fn  default_file_reader ( path :  & str )  -> Option < Vec < u8 > >  { 
@@ -84,7 +84,7 @@ pub fn default_file_reader(path: &str) -> Option<Vec<u8>> {
8484} 
8585
8686/// Real file reader implementation using standard library 
87- ///   
87+ /// 
8888/// This function reads actual files from the host filesystem when std is available. 
8989/// It's designed for use in AzCVMEmu environments where standard runtime is available. 
9090#[ cfg( feature = "std" ) ]  
@@ -94,7 +94,7 @@ pub fn real_file_reader(path: &str) -> Option<Vec<u8>> {
9494    if  !file_path. exists ( )  || !file_path. is_file ( )  { 
9595        return  None ; 
9696    } 
97-      
97+ 
9898    // Try to read the file 
9999    match  fs:: read ( path)  { 
100100        Ok ( data)  => { 
@@ -110,7 +110,7 @@ pub fn real_file_reader(path: &str) -> Option<Vec<u8>> {
110110} 
111111
112112/// Real file reader implementation (no-std fallback) 
113- ///   
113+ /// 
114114/// When std is not available, this falls back to pattern-based simulation. 
115115#[ cfg( not( feature = "std" ) ) ]  
116116pub  fn  real_file_reader ( path :  & str )  -> Option < Vec < u8 > >  { 
@@ -119,24 +119,24 @@ pub fn real_file_reader(path: &str) -> Option<Vec<u8>> {
119119} 
120120
121121/// Initialize file-based emulation with real file reader 
122- ///   
122+ /// 
123123/// This function sets up the emulation with a real file reader that can 
124124/// access the host filesystem when std feature is enabled. 
125125pub  fn  init_with_real_file_reader ( )  { 
126126    crate :: td_uefi_pi:: fv:: set_file_reader ( real_file_reader) ; 
127127} 
128128
129129/// Initialize file-based emulation with real files at specified paths 
130- ///   
130+ /// 
131131/// This function loads the policy and root CA files immediately from the filesystem 
132132/// and stores them in the emulation buffers. 
133133pub  fn  init_file_based_emulation_with_real_files ( policy_path :  & str ,  root_ca_path :  & str )  -> bool  { 
134134    // Set the file reader first 
135135    crate :: td_uefi_pi:: fv:: set_file_reader ( real_file_reader) ; 
136-      
136+ 
137137    // Load the files immediately 
138138    let  policy_loaded = crate :: td_uefi_pi:: fv:: load_policy_from_file ( policy_path) ; 
139139    let  root_ca_loaded = crate :: td_uefi_pi:: fv:: load_root_ca_from_file ( root_ca_path) ; 
140-      
140+ 
141141    policy_loaded && root_ca_loaded
142142} 
0 commit comments