PKUOS - Pintos
Pintos source browser for PKU Operating System course
Macros | Enumerations | Functions
ustar.h File Reference
#include <stdbool.h>
Include dependency graph for ustar.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define USTAR_HEADER_SIZE   512
 Size of a ustar archive header, in bytes. More...
 

Enumerations

enum  ustar_type { USTAR_REGULAR = '0' , USTAR_DIRECTORY = '5' , USTAR_EOF = -1 }
 Support for the standard Posix "ustar" format. More...
 

Functions

bool ustar_make_header (const char *file_name, enum ustar_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 named FILE_NAME of the given TYPE. More...
 
const char * ustar_parse_header (const char header[USTAR_HEADER_SIZE], const char **file_name, enum ustar_type *, int *size)
 lib/ustar.h More...
 

Macro Definition Documentation

◆ USTAR_HEADER_SIZE

#define USTAR_HEADER_SIZE   512

Size of a ustar archive header, in bytes.

Definition at line 21 of file ustar.h.

Enumeration Type Documentation

◆ ustar_type

enum ustar_type

Support for the standard Posix "ustar" format.

See the documentation of the "pax" utility in [SUSv3] for the the "ustar" format specification. Type of a file entry in an archive. The values here are the bytes that appear in the file format. Only types of interest to Pintos are listed here.

Enumerator
USTAR_REGULAR 

Ordinary file.

USTAR_DIRECTORY 

Directory.

USTAR_EOF 

End of archive (not an official value).

Definition at line 13 of file ustar.h.

Function Documentation

◆ ustar_make_header()

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 named FILE_NAME of the given TYPE.

The caller is responsible for writing the header to a file or device.

If successful, returns true. On failure (due to an excessively long file name), returns false.

Definition at line 83 of file ustar.c.

References ASSERT, calculate_chksum(), ustar_header::chksum, file_name, ustar_header::gid, ustar_header::gname, ustar_header::magic, memset(), ustar_header::mode, ustar_header::mtime, ustar_header::name, printf(), ustar_header::size, snprintf(), strip_antisocial_prefixes(), strlcpy(), strlen(), ustar_header::typeflag, ustar_header::uid, ustar_header::uname, USTAR_DIRECTORY, USTAR_HEADER_SIZE, USTAR_REGULAR, and ustar_header::version.

Referenced by fsutil_append(), and write_header().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ustar_parse_header()

const char * ustar_parse_header ( const char  header[USTAR_HEADER_SIZE],
const char **  file_name,
enum ustar_type type,
int *  size 
)

lib/ustar.h

lib/ustar.h

If successful, stores the archived file's name in *FILE_NAME (as a pointer into HEADER or a string literal), its type in *TYPE, and its size in bytes in *SIZE, and returns a null pointer. On failure, returns a human-readable error message.

Definition at line 182 of file ustar.c.

References ASSERT, calculate_chksum(), ustar_header::chksum, file_name, INT_MAX, is_all_zeros(), ustar_header::magic, memcmp(), ustar_header::name, NULL, parse_octal_field(), ustar_header::prefix, ustar_header::size, strip_antisocial_prefixes(), ustar_header::typeflag, USTAR_DIRECTORY, USTAR_EOF, USTAR_HEADER_SIZE, USTAR_REGULAR, and ustar_header::version.

Referenced by fsutil_extract().

Here is the call graph for this function:
Here is the caller graph for this function: