tar.c File Reference

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pwd.h>
#include <grp.h>
#include <tar.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <utime.h>
#include <sys/wait.h>
#include <stdio.h>
#include <errno.h>
#include <dirent.h>

Include dependency graph for tar.c:

Go to the source code of this file.

Data Structures

struct  link

Defines

#define POSIX_COMP
#define DIRECT_3
#define direct   dirent
#define TRUE   1
#define FALSE   0
#define STRING_SIZE   256
#define HEADER_SIZE   TBLOCK
#define NAME_SIZE   NAMSIZ
#define m_name   name
#define m_mode   mode
#define m_uid   uid
#define m_gid   gid
#define m_size   size
#define m_time   mtime
#define m_checksum   chksum
#define m_linked   typeflag
#define m_link   linkname
#define hdr_block   dummy
#define m   header
#define member   dbuf
#define INT_TYPE   (sizeof(header.member.m_uid))
#define LONG_TYPE   (sizeof(header.member.m_size))
#define NIL_HEADER   ((HEADER *) 0)
#define NIL_PTR   ((char *) 0)
#define TBLOCK_SIZE   TBLOCK
#define flush()   print(NIL_PTR)
#define block_size()

Typedefs

typedef char BOOL
typedef hblock HEADER

Functions

 _PROTOTYPE (int main,(int argc, char **argv))
 _PROTOTYPE (void error,(char *s1, char *s2))
 _PROTOTYPE (BOOL get_header,(void))
 _PROTOTYPE (void tarfile,(void))
 _PROTOTYPE (void extract,(char *file))
 _PROTOTYPE (void copy,(char *file, int from, int to, long bytes))
 _PROTOTYPE (long convert,(char str[], int type))
 _PROTOTYPE (int checksum,(void))
 _PROTOTYPE (int is_dir,(char *file))
 _PROTOTYPE (char *path_name,(char *file))
 _PROTOTYPE (void add_path,(char *name))
 _PROTOTYPE (void add_close,(int fd))
 _PROTOTYPE (int add_open,(char *file, struct stat *st))
 _PROTOTYPE (void make_header,(char *file, struct stat *st))
 _PROTOTYPE (void is_added,(struct stat *st, char *file))
 _PROTOTYPE (void is_deleted,(struct stat *st))
 _PROTOTYPE (char *is_linked,(struct stat *st))
 _PROTOTYPE (void mread,(int fd, char *address, int bytes))
 _PROTOTYPE (int bread,(int fd, char *address, int bytes))
 _PROTOTYPE (void print,(char *str))
 _PROTOTYPE (char *num_out,(long number))
 _PROTOTYPE (void string_print,(char *buffer, char *fmt,...))
void error (char *s1, char *s2)
int main (int argc, argv)
BOOL get_header ()
void tarfile ()
void skip_entry ()
void extract (char *file)
void delete (char *file)
void do_chown (char *file)
void timestamp (char *file)
void copy (char *file, int from, int to, long bytes)
long convert (str, int type)
int checksum ()
int is_dir (char *file)
char * path_name (char *file)
void add_path (char *name)
void add_file (char *file)
void verb_print (char *s1, char *s2)
void add_close (int fd)
int add_open (char *file, struct stat *st)
void make_header (char *file, struct stat *st)
void is_added (struct stat *st, char *file)
void is_deleted (struct stat *st)
char * is_linked (struct stat *st)
void clear_header ()
void adjust_boundary ()
void mread (int fd, char *address, int bytes)
void mwrite (int fd, char *address, int bytes)
int bread (int fd, char *address, int bytes)
int bwrite (int fd, char *address, int bytes)
void print (char *str)
char * num_out (long number)
void string_print (char *buffer, char *fmt)

Variables

linklink_top
HEADER header
BOOL show_fl
BOOL creat_fl
BOOL ext_fl
int tar_fd
char usage [] = "Usage: tar [cxt][vo][F][f] tarfile [files]."
char io_buffer [TBLOCK_SIZE]
char path [NAME_SIZE]
char pathname [NAME_SIZE]
int force_flag = 0
int chown_flag = 0
int verbose_flag = 0
int norec_flag = 0
ino_t ar_inode
dev_t ar_dev
int total_blocks
int u_mask
char output [TBLOCK_SIZE]


Define Documentation

 
#define block_size  ) 
 

Value:

(int) ((convert(header.member.m_size, LONG_TYPE) \
  + (long) TBLOCK_SIZE - 1) / (long) TBLOCK_SIZE)

Definition at line 188 of file tar.c.

Referenced by add_z_2(), alloc_block(), alloc_inode(), allocate_buffer(), allocbitmap(), bf_append(), bf_pack(), chkdev(), chkdirzone(), chksuper(), Data_Block(), devio(), devread(), devwrite(), df(), diskio(), dodir(), dumpbitmap(), eat_dir(), eat_file(), enter_dir(), file_vir2sec(), get_block(), getsuper(), incr_link(), incr_size(), loadbitmap(), main(), make_bootable(), print_fs(), printtotal(), put_block(), r_readdir(), r_stat(), r_super(), r_vir2abs(), rahead(), read_ahead(), read_write(), rw_block(), rw_scattered(), select_image(), sizeup(), skip_entry(), super(), tape_inquire(), tarfile(), and was_blk_special().

#define direct   dirent
 

Definition at line 85 of file tar.c.

#define DIRECT_3
 

Definition at line 78 of file tar.c.

#define FALSE   0
 

Definition at line 101 of file tar.c.

#define flush void   )     print(NIL_PTR)
 

Definition at line 161 of file tar.c.

#define hdr_block   dummy
 

Definition at line 120 of file tar.c.

#define HEADER_SIZE   TBLOCK
 

Definition at line 104 of file tar.c.

#define INT_TYPE   (sizeof(header.member.m_uid))
 

Definition at line 154 of file tar.c.

Referenced by checksum(), do_chown(), extract(), and get_header().

#define LONG_TYPE   (sizeof(header.member.m_size))
 

Definition at line 155 of file tar.c.

Referenced by extract(), and timestamp().

#define m   header
 

Definition at line 121 of file tar.c.

Referenced by _exit(), _ext_str_cvt(), _pm_findproc(), _read_pm(), _write_pm(), access(), ack_get_operand(), ack_get_statement(), add_reductions(), alarm(), alloc(), allocmem(), aohand(), argmatch(), argscan(), bas_get_operand(), bas_get_statement(), brk(), build_tree(), chdir(), chmod(), chown(), chroot(), cihand(), clock_task(), close(), creat(), crnlcat(), decode_ioctl(), default_goto(), delete(), dev_status(), devctl(), do_change(), do_diagnostics(), do_exec(), do_ioctl(), do_kbd(), do_kbdaux(), do_status(), do_video(), env_get_param(), execve(), fallbackQSort3(), fchdir(), fcntl(), filbuf(), fill_window(), fkey_ctl(), fmode(), fork(), freemem(), fstat(), fstatfs(), fsync(), ftruncate(), func_key(), gen_bitlen(), getegid(), geteuid(), getgid(), getn(), getnpid(), getnprocnr(), getpgrp(), getpid(), getppid(), getpprocnr(), getpriority(), getprocnr(), getsigset(), getsysinfo(), gettimeofday(), getuid(), getuptime(), glob2(), glob3(), gnu_get_statement(), gz_open(), gzerror(), handle_req(), handle_status(), image_dmp(), imhand(), indx(), input(), ioctl(), itoa(), kbd_status(), kill(), kputc(), link(), ljhand(), lookup(), lseek(), lstat(), m_init(), m_ioctl(), mail(), main(), mainQSort3(), Malloc(), matcher(), mihand(), mini_notify(), mini_receive(), mkdir(), mknod(), mount(), mqhand(), mvhand(), open(), panic(), pause(), pci_attr_r16(), pci_attr_r32(), pci_attr_r8(), pci_attr_w16(), pci_attr_w32(), pci_attr_w8(), pci_dev_name(), pci_find_dev(), pci_first_dev(), pci_ids(), pci_init1(), pci_next_dev(), pci_rescan_bus(), pci_reserve(), pci_slot_name(), pipe(), prepare_shutdown(), print_dir_date(), process_req_q(), ptrace(), range_parse(), read(), read_header(), read_symbol(), reader(), readlink(), reboot(), rehand(), rename(), reply(), rmdir(), save_column(), search_mnem(), select(), setdash(), setegid(), seteuid(), setgid(), setpriority(), setsid(), setuid(), sigaction(), sigpending(), sigprocmask(), sigreturn(), sigsuspend(), sjhand(), sr_get_userdata(), sr_put_userdata(), sr_repl_queue(), start_service(), startprocess(), stat(), stime(), Strfun(), subst(), svrctl(), symlink(), sync(), sys_abort(), sys_endksig(), sys_exec(), sys_exit(), sys_fork(), sys_getinfo(), sys_getksig(), sys_int86(), sys_kill(), sys_newmap(), sys_nice(), sys_privctl(), sys_segctl(), sys_setalarm(), sys_sigreturn(), sys_sigsend(), sys_svrctl(), sys_task(), sys_times(), sys_trace(), sys_umap(), sys_vm_map(), sys_vm_setbuf(), tell_fs(), test16a(), test7c(), tickdelay(), time(), timegmt(), times(), tqhand(), truncate(), umask(), umount(), unlink(), utime(), w_hw_int(), w_intr_wait(), w_other(), wait(), waitpid(), and write().

#define m_checksum   chksum
 

Definition at line 117 of file tar.c.

#define m_gid   gid
 

Definition at line 114 of file tar.c.

#define m_link   linkname
 

Definition at line 119 of file tar.c.

#define m_linked   typeflag
 

Definition at line 118 of file tar.c.

#define m_mode   mode
 

Definition at line 112 of file tar.c.

#define m_name   name
 

Definition at line 111 of file tar.c.

#define m_size   size
 

Definition at line 115 of file tar.c.

#define m_time   mtime
 

Definition at line 116 of file tar.c.

#define m_uid   uid
 

Definition at line 113 of file tar.c.

#define member   dbuf
 

Definition at line 122 of file tar.c.

Referenced by add(), get(), get_member(), and trymandir().

#define NAME_SIZE   NAMSIZ
 

Definition at line 105 of file tar.c.

#define NIL_HEADER   ((HEADER *) 0)
 

Definition at line 157 of file tar.c.

#define NIL_PTR   ((char *) 0)
 

Definition at line 158 of file tar.c.

#define POSIX_COMP
 

Definition at line 77 of file tar.c.

#define STRING_SIZE   256
 

Definition at line 103 of file tar.c.

Referenced by string_print().

#define TBLOCK_SIZE   TBLOCK
 

Definition at line 159 of file tar.c.

Referenced by checksum(), clear_header(), copy(), print(), and skip_entry().

#define TRUE   1
 

Definition at line 100 of file tar.c.


Typedef Documentation

typedef char BOOL
 

Definition at line 99 of file tar.c.

typedef union hblock HEADER
 

Definition at line 108 of file tar.c.


Function Documentation

_PROTOTYPE void  string_print,
(char *buffer, char *fmt,...) 
 

_PROTOTYPE char *  num_out,
(long number) 
 

_PROTOTYPE void  print,
(char *str
 

_PROTOTYPE int  bread,
(int fd, char *address, int bytes
 

_PROTOTYPE void  mread,
(int fd, char *address, int bytes
 

_PROTOTYPE char *  is_linked,
(struct stat *st
 

_PROTOTYPE void  is_deleted,
(struct stat *st
 

_PROTOTYPE void  is_added,
(struct stat *st, char *file
 

_PROTOTYPE void  make_header,
(char *file, struct stat *st
 

_PROTOTYPE int  add_open,
(char *file, struct stat *st
 

_PROTOTYPE void  add_close,
(int fd
 

_PROTOTYPE void  add_path,
(char *name
 

_PROTOTYPE char *  path_name,
(char *file
 

_PROTOTYPE int  is_dir,
(char *file
 

_PROTOTYPE int  checksum,
(void) 
 

_PROTOTYPE long  convert,
(char str[], int type
 

_PROTOTYPE void  copy,
(char *file, int from, int to, long bytes
 

_PROTOTYPE void  extract,
(char *file
 

_PROTOTYPE void  tarfile,
(void) 
 

_PROTOTYPE BOOL  get_header,
(void) 
 

_PROTOTYPE void  error,
(char *s1, char *s2) 
 

_PROTOTYPE int  main,
(int argc, char **argv) 
 

void add_close int  fd  ) 
 

Definition at line 839 of file tar.c.

References close.

Referenced by add_file().

void add_file char *  file  ) 
 

Definition at line 664 of file tar.c.

References add_close(), add_open(), add_path(), ar_dev, ar_inode, bread(), chdir, closedir, copy, cwd, direct::d_name, dir, DIRSIZ, errno, getcwd, header, if(), is_added(), is_deleted(), is_linked(), lstat, make_header(), mread(), mwrite(), NAMSIZ, NIL_PTR, norec_flag, NULL, opendir, path_name, readdir, readlink, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, st, stat::st_dev, stat::st_ino, stat::st_mode, stat::st_size, stat, strcmp, strcpy(), strerror(), string_print, strncpy(), tar_fd, TSIZLEN, verb_print(), and verbose_flag.

int add_open char *  file,
struct stat st
 

Definition at line 848 of file tar.c.

References errno, fprintf(), O_RDONLY, open, S_IFDIR, S_IFMT, S_IFREG, st, stat::st_mode, stderr, and strerror().

Referenced by add_file().

void add_path char *  name  ) 
 

Definition at line 638 of file tar.c.

References error, NAME_SIZE, NIL_PTR, and path.

void adjust_boundary  ) 
 

Definition at line 963 of file tar.c.

References clear_header(), close, header, mwrite(), tar_fd, and total_blocks.

int bread int  fd,
char *  address,
int  bytes
 

Definition at line 992 of file tar.c.

References n, r, and read.

int bwrite int  fd,
char *  address,
int  bytes
 

Definition at line 1008 of file tar.c.

References n, r, and write.

int checksum  ) 
 

Definition at line 608 of file tar.c.

References header, INT_TYPE, ptr, and TBLOCK_SIZE.

void clear_header  ) 
 

Definition at line 956 of file tar.c.

References header, ptr, and TBLOCK_SIZE.

Referenced by adjust_boundary(), and make_header().

long convert str  ,
int  type
 

Definition at line 591 of file tar.c.

References L, and long().

Referenced by do_chown(), extract(), get_header(), main(), and timestamp().

void copy char *  file,
int  from,
int  to,
long  bytes
 

Definition at line 572 of file tar.c.

References blocks, bread(), int(), io_buffer, long(), mwrite(), NIL_PTR, string_print, tar_fd, TBLOCK_SIZE, and verbose_flag.

void delete char *  file  ) 
 

Definition at line 522 of file tar.c.

References rmdir, S_ISDIR, stat::st_mode, stat, and unlink.

void do_chown char *  file  ) 
 

Definition at line 534 of file tar.c.

References chmod, chown, chown_flag, convert(), getgrnam(), getpwnam(), gid, group::gr_gid, header, int(), INT_TYPE, NULL, passwd::pw_uid, pwd, strncmp(), timestamp(), TMAGIC, TMAGLEN, u_mask, and uid.

void error char *  s1,
char *  s2
 

Definition at line 224 of file tar.c.

References exit(), flush, NIL_PTR, and string_print.

void extract char *  file  ) 
 

Definition at line 412 of file tar.c.

References access, close, convert(), copy, creat, do_chown(), errno, header, index(), int(), INT_TYPE, link, LONG_TYPE, mkdir, mkfifo, mknod, NIL_PTR, print, r, S_IFBLK, S_IFCHR, strerror(), string_print, symlink, tar_fd, verb_print(), and verbose_flag.

BOOL get_header  ) 
 

Definition at line 332 of file tar.c.

References check, checksum(), convert(), error, FALSE, force_flag, header, int(), INT_TYPE, mread(), NIL_PTR, tar_fd, and TRUE.

Referenced by tarfile().

void is_added struct stat st,
char *  file
 

Definition at line 901 of file tar.c.

References link::dev, link_top, malloc(), NULL, path_name, print, strcpy(), and strlen().

Referenced by add_file().

void is_deleted struct stat st  ) 
 

Definition at line 923 of file tar.c.

References free, link_top, link::next, and NULL.

Referenced by add_file().

int is_dir char *  file  ) 
 

Definition at line 621 of file tar.c.

char* is_linked struct stat st  ) 
 

Definition at line 934 of file tar.c.

References link::dev, link::ino, link_top, link::name, NAMSIZ, link::next, link::nlink, NULL, and strncpy().

Referenced by add_file().

int main int  argc,
argv 
 

Definition at line 232 of file tar.c.

References chown_flag, creat_fl, error, ext_fl, force_flag, i, NIL_PTR, norec_flag, ptr, show_fl, st, TRUE, umask, usage, and verbose_flag.

void make_header char *  file,
struct stat st
 

Definition at line 862 of file tar.c.

References clear_header(), getgrgid(), getpwuid(), group::gr_name, header, NULL, ptr, passwd::pw_name, pwd, S_IFBLK, S_IFCHR, S_IFDIR, S_IFMT, S_IFREG, string_print, strncpy(), TGNMLEN, TMAGIC, TMAGLEN, TSIZLEN, and TUNMLEN.

Referenced by add_file().

void mread int  fd,
char *  address,
int  bytes
 

Definition at line 976 of file tar.c.

References bread(), error, and NIL_PTR.

void mwrite int  fd,
char *  address,
int  bytes
 

Definition at line 983 of file tar.c.

References bwrite(), error, NIL_PTR, and total_blocks.

char* num_out long  number  ) 
 

Definition at line 1045 of file tar.c.

References i.

Referenced by change(), file_insert(), GOTO(), scratch_file(), string_print(), and yank().

char* path_name char *  file  ) 
 

Definition at line 630 of file tar.c.

References path, and string_print.

void print char *  str  ) 
 

Definition at line 1025 of file tar.c.

References indx(), NIL_PTR, tar_fd, TBLOCK_SIZE, and write.

void skip_entry  ) 
 

Definition at line 405 of file tar.c.

References block_size, blocks, bread(), io_buffer, tar_fd, and TBLOCK_SIZE.

Referenced by tarfile().

void string_print char *  buffer,
char *  fmt
 

Definition at line 1063 of file tar.c.

References args, BOOL, buf_ptr, i, NIL_PTR, num_out(), pr_fl, print, STRING_SIZE, va_arg, va_end, and va_start.

void tarfile  ) 
 

Definition at line 352 of file tar.c.

References block_size, flush, get_header(), header, is_dir, NIL_PTR, skip_entry(), string_print, strncpy(), TSIZLEN, verb_print(), and verbose_flag.

void timestamp char *  file  ) 
 

Definition at line 563 of file tar.c.

References buf, convert(), header, LONG_TYPE, and utime.

void verb_print char *  s1,
char *  s2
 

Definition at line 833 of file tar.c.

References NIL_PTR, string_print, and verbose_flag.

Referenced by add_file(), extract(), and tarfile().


Variable Documentation

dev_t ar_dev
 

Definition at line 183 of file tar.c.

Referenced by add_file().

ino_t ar_inode
 

Definition at line 182 of file tar.c.

Referenced by add_file().

int chown_flag = 0
 

Definition at line 176 of file tar.c.

Referenced by do_chown(), and main().

BOOL creat_fl
 

Definition at line 163 of file tar.c.

Referenced by main().

BOOL ext_fl
 

Definition at line 163 of file tar.c.

Referenced by main().

int force_flag = 0
 

Definition at line 171 of file tar.c.

Referenced by get_header(), and main().

HEADER header
 

Definition at line 152 of file tar.c.

char io_buffer[TBLOCK_SIZE]
 

Definition at line 168 of file tar.c.

struct link * link_top
 

Referenced by is_added(), is_deleted(), and is_linked().

int norec_flag = 0
 

Definition at line 179 of file tar.c.

Referenced by add_file(), and main().

char output[TBLOCK_SIZE]
 

Definition at line 1024 of file tar.c.

char path[NAME_SIZE]
 

Definition at line 169 of file tar.c.

char pathname[NAME_SIZE]
 

Definition at line 170 of file tar.c.

BOOL show_fl
 

Definition at line 163 of file tar.c.

int tar_fd
 

Definition at line 165 of file tar.c.

Referenced by add_file(), adjust_boundary(), copy(), extract(), get_header(), print(), and skip_entry().

int total_blocks
 

Definition at line 185 of file tar.c.

Referenced by adjust_boundary(), and mwrite().

int u_mask
 

Definition at line 186 of file tar.c.

static void usage = "Usage: tar [cxt][vo][F][f] tarfile [files]."
 

Definition at line 167 of file tar.c.

Referenced by cache2file(), cache_reply(), domonth(), doyear(), getargs(), ifname2n(), letterToCode(), main(), make_time(), mattrib(), mcat(), mcopy(), mdel(), mdir(), mdoctorfat(), mdu(), mformat(), minfo(), mlabel(), mmd(), mmove(), mpartition(), mshowfat(), parse(), parse_args_init_io(), parse_time(), and setoption().

int verbose_flag = 0
 

Definition at line 177 of file tar.c.


Generated on Fri Apr 14 23:05:52 2006 for minix by  doxygen 1.4.6