GCC Code Coverage Report


Directory: ./
File: File.cpp
Date: 2026-09-03 22:13:41
Exec Total Coverage
Lines: 0 32 0.0%
Functions: 0 2 0.0%
Branches: 0 25 0.0%

Line Branch Exec Source
1 // ======================================================================
2 // \title File.cpp
3 // \author bocchino
4 // \brief cpp file for FileDownlink::File
5 //
6 // \copyright
7 // Copyright 2009-2015, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12
13 #include <Fw/FPrimeBasicTypes.hpp>
14 #include <Fw/Types/Assert.hpp>
15 #include <Svc/FileDownlink/FileDownlink.hpp>
16
17 namespace Svc {
18
19 Os::File::Status FileDownlink::File ::open(const Fw::FileNameString& sourceFileName,
20 const Fw::FileNameString& destFileName) {
21 // Set source name
22 Fw::LogStringArg sourceLogStringArg(sourceFileName);
23 this->m_sourceName = sourceLogStringArg;
24
25 // Set dest name
26 Fw::LogStringArg destLogStringArg(destFileName);
27 this->m_destName = destLogStringArg;
28
29 // Initialize checksum
30 CFDP::Checksum checksum;
31 this->m_checksum = checksum;
32
33 // Open osFile for reading (sandbox path validation happens here)
34 Os::File::Status status = this->m_osFile.open(sourceFileName.toChar(), Os::File::OPEN_READ);
35 if (status != Os::File::OP_OK) {
36 return status;
37 }
38
39 // Query size only after the path passes sandbox checks
40 FwSizeType file_size;
41 status = this->m_osFile.size(file_size);
42 if (status != Os::File::OP_OK) {
43 this->m_osFile.close();
44 return Os::File::BAD_SIZE;
45 }
46 // If the size does not cast cleanly to the desired U32 type, return size error
47 if (static_cast<FwSizeType>(static_cast<U32>(file_size)) != file_size) {
48 this->m_osFile.close();
49 return Os::File::BAD_SIZE;
50 }
51 this->m_size = static_cast<U32>(file_size);
52 return Os::File::OP_OK;
53 }
54
55 Os::File::Status FileDownlink::File ::read(U8* const data, const U32 byteOffset, const U32 size) {
56 Os::File::Status status;
57 status = this->m_osFile.seek(byteOffset, Os::File::SeekType::ABSOLUTE);
58 if (status != Os::File::OP_OK) {
59 return status;
60 }
61
62 FwSizeType intSize = size;
63 status = this->m_osFile.read(data, intSize);
64
65 if (status != Os::File::OP_OK) {
66 return status;
67 }
68 // Force a bad size error when the U32 carrying size is bad
69 if (static_cast<U32>(intSize) != size) {
70 return Os::File::BAD_SIZE;
71 }
72 this->m_checksum.update(data, byteOffset, size);
73
74 return Os::File::OP_OK;
75 }
76 } // namespace Svc
77