10static void usage (
void);
12 char *files[],
size_t file_cnt);
15main (
int argc,
char *argv[])
27 printf (
"tar, tar archive creator\n"
28 "Usage: tar ARCHIVE FILE...\n"
29 "where ARCHIVE is the tar archive to create\n"
30 " and FILE... is a list of files or directories to put into it.\n"
31 "(ARCHIVE itself will not be included in the archive, even if it\n"
32 "is in a directory to be archived.)\n");
37 int archive_fd,
bool *write_error);
40 int archive_fd,
bool *write_error);
42 int file_fd,
int archive_fd,
bool *write_error);
44 int archive_fd,
bool *write_error);
46static bool do_write (
int fd,
const char *
buffer,
int size,
bool *write_error);
51 static const char zeros[512];
54 bool write_error =
false;
57 if (!
create (archive_name, 0))
59 printf (
"%s: create failed\n", archive_name);
62 archive_fd =
open (archive_name);
65 printf (
"%s: open failed\n", archive_name);
69 for (i = 0; i < file_cnt; i++)
75 archive_fd, &write_error))
79 if (!
do_write (archive_fd, zeros, 512, &write_error)
80 || !
do_write (archive_fd, zeros, 512, &write_error))
90 int archive_fd,
bool *write_error)
101 archive_fd, write_error);
104 archive_fd, write_error);
125 int archive_fd,
bool *write_error)
127 bool read_error =
false;
132 archive_fd, write_error))
135 while (file_size > 0)
137 static char buf[512];
138 int chunk_size = file_size > 512 ? 512 : file_size;
139 int read_retval =
read (file_fd,
buf, chunk_size);
140 int bytes_read = read_retval > 0 ? read_retval : 0;
142 if (bytes_read != chunk_size && !read_error)
149 memset (
buf + bytes_read, 0, 512 - bytes_read);
153 file_size -= chunk_size;
161 int archive_fd,
bool *write_error)
187 int archive_fd,
bool *write_error)
189 static char header[512];
191 &&
do_write (archive_fd, header, 512, write_error));
203 printf (
"error writing archive\n");
static char buf[BUF_SIZE]
int printf(const char *format,...)
Writes formatted output to the console.
bool readdir(int fd, char name[READDIR_MAX_LEN+1])
bool create(const char *file, unsigned initial_size)
int open(const char *file)
int write(int fd, const void *buffer, unsigned size)
int inumber(int fd)
lib/user/syscall.h
int read(int fd, void *buffer, unsigned size)
#define EXIT_SUCCESS
Typical return values from main() and arguments to exit().
#define EXIT_FAILURE
Unsuccessful execution.
#define READDIR_MAX_LEN
Maximum characters in a filename written by readdir().
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.
static const char file_name[]
tests/filesys/base/syn-read.h
int main(int argc, char *argv[])
static bool archive_directory(char file_name[], size_t file_name_size, int file_fd, int archive_fd, bool *write_error)
static bool make_tar_archive(const char *archive_name, char *files[], size_t file_cnt)
static bool archive_file(char file_name[], size_t file_name_size, int archive_fd, bool *write_error)
static bool archive_ordinary_file(const char *file_name, int file_fd, int archive_fd, bool *write_error)
static void usage(void)
tar.c
static bool write_header(const char *file_name, enum ustar_type, int size, int archive_fd, bool *write_error)
static bool do_write(int fd, const char *buffer, int size, bool *write_error)
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...
ustar_type
Support for the standard Posix "ustar" format.
@ USTAR_REGULAR
Ordinary file.
@ USTAR_DIRECTORY
Directory.