49 const size_t chksum_end = chksum_start +
sizeof h->
chksum;
50 bool in_chksum_field = i >= chksum_start && i < chksum_end;
51 chksum += in_chksum_field ?
' ' : header[i];
135 for (ofs = 0; ofs <
size; ofs++)
138 if (c >=
'0' && c <=
'7')
147 else if (c ==
' ' || c ==
'\0')
186 unsigned long int chksum, size_ul;
201 return "not a ustar archive";
203 return "invalid ustar version";
205 return "corrupt chksum field";
207 return "checksum mismatch";
208 else if (h->
name[
sizeof h->
name - 1] !=
'\0' || h->
prefix[0] !=
'\0')
209 return "file name too long";
211 return "unimplemented file type";
215 return "corrupt file size field";
217 return "file too large";
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
int snprintf(char *buffer, size_t buf_size, const char *format,...)
Like printf(), except that output is stored into BUFFER, which must have space for BUF_SIZE character...
int printf(const char *format,...)
Writes formatted output to the console.
static uint8_t s[256]
RC4-based pseudo-random number generator (PRNG).
#define offsetof(TYPE, MEMBER)
char * strchr(const char *string, int c_)
Finds and returns the first occurrence of C in STRING, or a null pointer if C does not appear in STRI...
int memcmp(const void *a_, const void *b_, size_t size)
Find the first differing byte in the two blocks of SIZE bytes at A and B.
size_t strlen(const char *string)
Returns the length of STRING.
void * memset(void *dst_, int value, size_t size)
Sets the SIZE bytes in DST to VALUE.
size_t strlcpy(char *dst, const char *src, size_t size)
Copies string SRC to DST.
int strcmp(const char *a_, const char *b_)
Finds the first differing characters in strings A and B.
static const char file_name[]
tests/filesys/base/syn-read.h
static unsigned int calculate_chksum(const struct ustar_header *h)
Returns the checksum for the given ustar format HEADER.
static bool parse_octal_field(const char *s, size_t size, unsigned long int *value)
Parses a SIZE-byte octal field in S in the format used by ustar format.
bool ustar_make_header(const char *file_name, enum ustar_type type, int size, char header[USTAR_HEADER_SIZE])
Composes HEADER as a USTAR_HEADER_SIZE (512)-byte archive header in ustar format for a SIZE-byte file...
static bool is_all_zeros(const char *block, size_t cnt)
Returns true if the CNT bytes starting at BLOCK are all zero, false otherwise.
const char * ustar_parse_header(const char header[USTAR_HEADER_SIZE], const char **file_name, enum ustar_type *type, int *size)
Parses HEADER as a ustar-format archive header for a regular file or directory.
struct ustar_header PACKED
static const char * strip_antisocial_prefixes(const char *file_name)
Drop possibly dangerous prefixes from FILE_NAME and return the stripped name.
ustar_type
Support for the standard Posix "ustar" format.
@ USTAR_REGULAR
Ordinary file.
@ USTAR_EOF
End of archive (not an official value).
@ USTAR_DIRECTORY
Directory.
#define USTAR_HEADER_SIZE
Size of a ustar archive header, in bytes.