header.h

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.7 kB
5
Indexable
Never
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <stdio.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>

#ifndef HH
#define HH

/* Field size macros */
#define NAME_SIZE 100
#define MODE_SIZE 8
#define UID_SIZE 8
#define GID_SIZE 8
#define FILESIZE_SIZE 12
#define MTIME_SIZE 12
#define CHKSUM_SIZE 8
#define TYPEFLAG_SIZE 1
#define LINKNAME_SIZE 100
#define MAGIC_SIZE 6
#define VERSION_SIZE 2
#define UNAME_SIZE 32
#define GNAME_SIZE 32
#define DEVMAJOR_SIZE 8
#define DEVMINOR_SIZE 8
#define PREFIX_SIZE 155
#define HEADER_PAD_SIZE 12

/* Name length macros */
#define MAX_NAME_LEN 256

typedef struct header{
    char *name; /* NUL-terminated is NUL fits; size: 100 */
    char *mode; /* Octal string; size: 8 */
    char *uid; /* Octal string; size: 8 */
    char *gid; /* Octal string; size: 8 */
    char *size; /* Octal string; size: 12 */
    char *mtime; /* Octal string; size: 12 */
    char *chksum; /* Octal string; size: 8 */
    char typeflag;
    char *linkname; /* NUL-terminated if NUL fits; size: 100 */
    char *magic; /* Must be "ustar", NUL-terminated; size: 6 */
    char *version; /* Must be "00"; size: 2 */
    char *uname; /* NUL-terminated; size: 32 */
    char *gname; /* NUL-terminated; size: 32 */
    char *devmajor; /* Octal string; size: 8 */
    char *devminor; /* Octal string; size: 8 */
    char *prefix; /* NUL-terminated if NUL fits; size: 155 */
} header;

header *create_header(struct stat sb, char *path);

char *duplicate_buff(char *buff);

int pack_name_and_prefix(char *path, header *curr_header);

unsigned int get_chksum_val(struct stat sb, char *name, struct passwd *pw,
                            struct group *gr);

#endif
Leave a Comment