summaryrefslogtreecommitdiffstats
path: root/heimdall-frontend/Source/Packaging.h
blob: 97637de0ab96ef3124e6ad5ebdc59d9a6bfb08c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.*/

#ifndef PACKAGING_H
#define PACKAGING_H

// Qt
#include <QList>
#include <QString>
#include <QTemporaryFile>

// Heimdall Frontend
#include "PackageData.h"

namespace HeimdallFrontend
{
	union TarHeader
	{		
		enum
		{
			kBlockLength = 512,
			kBlockReadCount = 8,
			kBlockWriteCount = 8,

			kTarHeaderLength = 257,
			kUstarHeaderLength = 500,
		};

		enum : quint64
		{
			kMaxFileSize = 8589934592
		};

		enum
		{
			kModeOtherExecute = 1,
			kModeOtherWrite = 1 << 1,
			kModeOtherRead = 1 << 2,

			kModeGroupExecute = 1 << 3,
			kModeGroupWrite = 1 << 4,
			kModeGroupRead = 1 << 5,

			kModeOwnerExecute = 1 << 6,
			kModeOwnerWrite = 1 << 7,
			kModeOwnerRead = 1 << 8,

			kModeReserved = 2 << 9,
			kModeSetGid = 2 << 10,
			kModeSetUid = 2 << 11		
		};

		struct
		{
			char name[100];
			char mode[8];
			char userId[8];
			char groupId[8];
			char size[12];
			char modifiedTime[12];
			char checksum[8];
			char typeFlag;
			char linkName[100];
			char magic[6];
			char version[2];
			char userName[32];
			char groupName[32];
			char devMajor[8];
			char devMinor[8];
			char prefix[155];
		} fields;

		char buffer[kBlockLength];
	};

	class Packaging
	{
		private:

			enum
			{
				kExtractBufferLength = 262144,
				kCompressBufferLength = 262144
			};
			
			// TODO: Add support for sparse files to both methods.
			static bool ExtractTar(QTemporaryFile& tarFile, PackageData *packageData);

			static bool WriteTarEntry(const QString& filename, QTemporaryFile *tarFile, bool firmwareXml = false);
			static bool CreateTar(const FirmwareInfo& firmwareInfo, QTemporaryFile *tarFile); // Uses original TAR format.

		public:

			static const char *ustarMagic;

			static bool ExtractPackage(const QString& packagePath, PackageData *packageData);
			static bool BuildPackage(const QString& packagePath, const FirmwareInfo& firmwareInfo);
	};
}

#endif