GCC Code Coverage Report


Directory: ./
File: File.cpp
Date: 2026-09-03 22:13:42
Exec Total Coverage
Lines: 21 25 84.0%
Functions: 2 2 100.0%
Branches: 12 16 75.0%

Line Branch Exec Source
1 // ======================================================================
2 // \title File.cpp
3 // \author bocchino
4 // \brief cpp file for FileUplink::File
5 //
6 // \copyright
7 // Copyright 2009-2016, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12
13 #include <Fw/Types/Assert.hpp>
14 #include <Fw/Types/StringUtils.hpp>
15 #include <Svc/FileUplink/FileUplink.hpp>
16
17 #include <cstring>
18 namespace Svc {
19
20 2 Os::File::Status FileUplink::File::open(const Fw::FilePacket::StartPacket& startPacket) {
21 2 const U32 length = startPacket.getDestinationPath().getLength();
22 char path[Fw::FilePacket::PathName::MAX_LENGTH + 1];
23 // Ensure that length is not greater that the size of the variable we will copy into
24
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (length >= sizeof(path)) {
25 return Os::File::Status::BAD_SIZE;
26 }
27 2 (void)memcpy(path, startPacket.getDestinationPath().getValue(), length);
28 2 path[length] = 0;
29
1/1
✓ Branch 1 taken 2 times.
2 Fw::LogStringArg logStringArg(path);
30
1/1
✓ Branch 1 taken 2 times.
2 this->name = logStringArg;
31 2 this->size = startPacket.getFileSize();
32
1/1
✓ Branch 1 taken 2 times.
2 CFDP::Checksum checksum;
33
1/1
✓ Branch 1 taken 2 times.
2 this->m_checksum = checksum;
34
1/1
✓ Branch 1 taken 2 times.
2 return this->osFile.open(path, Os::File::OPEN_WRITE);
35 2 }
36
37 1 Os::File::Status FileUplink::File::write(const U8* const data, const U32 byteOffset, const U32 length) {
38 Os::File::Status status;
39
1/1
✓ Branch 1 taken 1 times.
1 status = this->osFile.seek(byteOffset, Os::File::SeekType::ABSOLUTE);
40
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (status != Os::File::OP_OK) {
41 return status;
42 }
43
44 1 FwSizeType intLength = length;
45 // Note: not waiting for the file write to finish
46
1/1
✓ Branch 1 taken 1 times.
1 status = this->osFile.write(data, intLength, Os::File::WaitType::NO_WAIT);
47
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (status != Os::File::OP_OK) {
48 return status;
49 }
50
51 // A short write (e.g. disk full) is an error, not an assertion failure
52
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (static_cast<U32>(intLength) != length) {
53 return Os::File::NO_SPACE;
54 }
55
1/1
✓ Branch 1 taken 1 times.
1 this->m_checksum.update(data, byteOffset, length);
56 1 return Os::File::OP_OK;
57 }
58
59 } // namespace Svc
60