Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/pax/pax-flash.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1987-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
22
/*
23
* pax solaris flash format
24
*/
25
26
#include "format.h"
27
28
#define FLASH_MAGIC "FlAsH-aRcHiVe-"
29
#define FLASH_DATA "section_begin=archive"
30
31
static int
32
flash_getprologue(Pax_t* pax, Format_t* fp, register Archive_t* ap, File_t* f, unsigned char* buf, size_t size)
33
{
34
unsigned char* s;
35
unsigned char* e;
36
unsigned char* t;
37
char* v;
38
int i;
39
off_t n;
40
char version[16];
41
42
if (size < sizeof(FLASH_MAGIC) - 1 || memcmp(buf, FLASH_MAGIC, sizeof(FLASH_MAGIC) - 1))
43
return 0;
44
45
/*
46
* get the flash format version
47
*/
48
49
s = buf + sizeof(FLASH_MAGIC) - 1;
50
e = buf + size;
51
v = version;
52
while (v < &version[sizeof(version) - 1] && s < e && *s != '\n')
53
*v++ = *s++;
54
*v = 0;
55
56
/*
57
* skip over the flash headers to the embedded archive
58
*/
59
60
s = e;
61
for (;;)
62
{
63
if (s >= e)
64
{
65
if (!(buf = (unsigned char*)paxget(pax, ap, -PAX_DEFBUFFER * PAX_BLOCK, &n)))
66
return -1;
67
s = buf;
68
e = buf + n;
69
}
70
if (t = (unsigned char*)memchr(s, '\n', e - s))
71
{
72
if ((t - s) == (sizeof(FLASH_DATA) - 1) && !memcmp(s, FLASH_DATA, sizeof(FLASH_DATA) - 1))
73
{
74
if (paxseek(pax, ap, -(e - t - 1), SEEK_CUR, 0) < 0)
75
return -1;
76
break;
77
}
78
if (t < e)
79
{
80
s = t + 1;
81
continue;
82
}
83
}
84
if (paxseek(pax, ap, -(e - s), SEEK_CUR, 0) < 0)
85
return -1;
86
s = e;
87
}
88
ap->entry = 0;
89
ap->swap = 0;
90
ap->swapio = 0;
91
ap->volume--;
92
i = state.volume[0];
93
if (getprologue(ap) <= 0)
94
{
95
error(2, "%s: %s format embedded archive expected", ap->name, fp->name);
96
return -1;
97
}
98
state.volume[0] = i;
99
ap->package = strdup(sfprints("%s %s", fp->name, version));
100
return 1;
101
}
102
103
Format_t pax_flash_format =
104
{
105
"flash",
106
0,
107
"Solaris flash package encapsulated archive",
108
0,
109
ARCHIVE|IN,
110
DEFBUFFER,
111
DEFBLOCKS,
112
0,
113
PAXNEXT(flash),
114
0,
115
0,
116
flash_getprologue,
117
};
118
119
PAXLIB(flash)
120
121