tail_core 0.1.0

Core library for the Tail operating system
Documentation
// Copyright 2025, TAIL OS. All Rights Reserved.
//
// You must obtain a written license from and pay applicable license fees to TAIL OS
// before you may reproduce, modify, or distribute this software, or any work that
// includes all or part of this software.
//
// Free development licenses are available for evaluation, research, and non-commercial
// purposes, which may include access to the source code under these terms. Redistribution
// or commercial use without a license is strictly prohibited.
//
// This file may contain contributions from others. Please review this entire file for
// other proprietary rights or license notices, as well as the TAIL OS License Guide at
// https://tail-os.com/license-guide/ for more information.
//
// For licensing inquiries, visit https://tail-os.com or email license@tail-os.com.


use super::OpenMode;
use crate::kprint;
use crate::service::fat_file_system_server;
use crate::service::client;
use crate::service::service_request::ServiceRequestData;
use crate::service::service_reply::ServiceReplyData;
use crate::alloc::string::ToString;
//use crate::service::fat_file_system_server::FatFileSystemServerMessage;

pub fn open_file(file_path: &str, flags: OpenMode) -> Result<crate::file::File, crate::error_kind::ErrorKind> {
    let mut file = crate::file::File::new();
    let file_path_bytes = file_path.as_bytes();
    let request_data = ServiceRequestData::new(&file_path_bytes[0], file_path_bytes.len());
    let result = client::send_service_request_and_wait_for_reply("fat_file_system_server",
    fat_file_system_server::FAT_FILE_SYSTEM_SERVER_OPEN_FILE, &request_data);  
    if result.is_err() {
        return Err(crate::error_kind::ErrorKind::from(result.err().unwrap()));
    } else {
        let reply: ServiceReplyData<crate::file::File> = result.unwrap();
        let reply_message_ref: &crate::file::File = reply.get_reply_message_ref();
        return Ok(reply_message_ref.clone());
    }
}