home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / linux / backup / star-1.3.1.tar.gz / star-1.3.1.tar / star-1.3.1 / star / star.h < prev    next >
C/C++ Source or Header  |  2001-04-07  |  15KB  |  449 lines

  1. /* @(#)star.h    1.33 01/04/07 Copyright 1985, 1995 J. Schilling */
  2. /*
  3.  *    Copyright (c) 1985, 1995 J. Schilling
  4.  */
  5. /*
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2, or (at your option)
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; see the file COPYING.  If not, write to
  18.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include <utypes.h>
  22. #include <timedefs.h>
  23.  
  24. #define tarblocks(s)    (((s) + (TBLOCK-1)) / TBLOCK)
  25. #define tarsize(s)    (tarblocks(s) * TBLOCK)
  26.  
  27. /*
  28.  * Defines for header type recognition
  29.  * N.B. these must kept in sync with hdrtxt[] in header.c
  30.  */
  31. #define    H_SWAPPED(t)    ((-1)*(t))
  32. #define    H_ISSWAPPED(t)    ((t) < H_UNDEF)
  33. #define    H_TYPE(t)    ((int)(H_ISSWAPPED(t) ? ((-1)*(t)):(t)))
  34. #define    H_UNDEF        0
  35. #define    H_TAR        1    /* tar unbekanntes format */
  36. #define    H_OTAR        2    /* tar altes format */
  37. #define    H_STAR        3    /* star format */
  38. #define    H_GNUTAR    4    /* gnu tar format */
  39. #define    H_USTAR        5    /* ieee 1003.1 format */
  40. #define    H_XSTAR        6    /* extended 1003.1 format */
  41. #define    H_XUSTAR    7    /* extended 1003.1 format without "tar" signature */
  42. #define    H_RES8        8    /* Reserved */
  43. #define    H_BAR        9    /* SUN bar format */
  44. #define    H_CPIO        10    /* XXX entfΣllt */
  45. #define    H_CPIO_BIN    10    /* cpio BinΣr */
  46. #define    H_CPIO_CHR    11    /* cpio -c format */
  47. #define    H_CPIO_NBIN    12    /* cpio neu BinΣr */
  48. #define    H_CPIO_CRC    13    /* cpio crc BinΣr */
  49. #define    H_CPIO_ASC    14    /* cpio ascii expanded maj/min */
  50. #define    H_CPIO_ACRC    15    /* cpio crc expanded maj/min */
  51. #define    H_MAX_ARCH    15    /* Highest possible # */
  52.  
  53.  
  54. #define TBLOCK        512
  55. #define NAMSIZ        100
  56. #define    PFXSIZ        155
  57.  
  58. #define    TMODLEN        8
  59. #define    TUIDLEN        8
  60. #define    TGIDLEN        8
  61. #define    TSIZLEN        12
  62. #define    TMTMLEN        12
  63. #define    TCKSLEN        8
  64.  
  65. #define    TMAGIC        "ustar"    /* ustar magic */
  66. #define    TMAGLEN        6    /* "ustar" including NULL byte */
  67. #define    TVERSION    "00"
  68. #define    TVERSLEN    2
  69. #define    TUNMLEN        32
  70. #define    TGNMLEN        32
  71. #define    TDEVLEN        8
  72.  
  73. #define    REGTYPE        '0'
  74. #define    AREGTYPE    '\0'
  75. #define    LNKTYPE        '1'
  76. #define    SYMTYPE        '2'
  77. #define    CHRTYPE        '3'
  78. #define    BLKTYPE        '4'
  79. #define    DIRTYPE        '5'
  80. #define    FIFOTYPE    '6'
  81. #define    CONTTYPE    '7'
  82.  
  83. /*
  84.  * star/gnu tar extensions:
  85.  */
  86. /* Note that the standards committee allows only capital A through
  87.    capital Z for user-defined expansion.  This means that defining something
  88.    as, say '8' is a *bad* idea. */
  89.  
  90. #define    LF_ACL        'A'    /* Access Control List    */
  91. #define LF_DUMPDIR    'D'    /* This is a dir entry that contains
  92.                        the names of files that were in
  93.                        the dir at the time the dump
  94.                        was made */
  95. #define LF_LONGLINK    'K'    /* Identifies the NEXT file on the tape
  96.                        as having a long linkname */
  97. #define LF_LONGNAME    'L'    /* Identifies the NEXT file on the tape
  98.                        as having a long name. */
  99. #define LF_MULTIVOL    'M'    /* This is the continuation
  100.                        of a file that began on another
  101.                        volume */
  102. #define LF_NAMES    'N'    /* For storing filenames that didn't
  103.                        fit in 100 characters */
  104. #define LF_SPARSE    'S'    /* This is for sparse files */
  105. #define LF_VOLHDR    'V'    /* This file is a tape/volume header */
  106.                 /* Ignore it on extraction */
  107.  
  108. /*
  109.  * This is the ustar (Posix 1003.1) header.
  110.  */
  111. struct header {
  112.     char t_name[NAMSIZ];    /*   0    Dateiname    */
  113.     char t_mode[8];        /* 100    Zugriffsrechte     */
  114.     char t_uid[8];        /* 108    Benutzernummer    */
  115.     char t_gid[8];        /* 116    Benutzergruppe    */
  116.     char t_size[12];    /* 124    Dateigroesze    */
  117.     char t_mtime[12];    /* 136    Zeit d. letzten Aenderung */
  118.     char t_chksum[8];    /* 148    Checksumme    */
  119.     char t_typeflag;    /* 156    Typ der Datei    */
  120.     char t_linkname[NAMSIZ];/* 157    Zielname des Links */
  121.     char t_magic[TMAGLEN];    /* 257    "ustar"        */
  122.     char t_version[TVERSLEN];/*263    Version v. star    */
  123.     char t_uname[TUNMLEN];    /* 265    Benutzername    */
  124.     char t_gname[TGNMLEN];    /* 297    Gruppenname    */
  125.     char t_devmajor[8];    /* 329    Major bei Geraeten */
  126.     char t_devminor[8];    /* 337    Minor bei Geraeten */
  127.     char t_prefix[PFXSIZ];    /* 345    Prefix fuer t_name */
  128.                 /* 500    Ende        */
  129.     char t_mfill[12];    /* 500    Filler bis 512    */
  130. };
  131.  
  132. /*
  133.  * star header specific definitions
  134.  */
  135. #define    STMAGIC        "tar"    /* star magic */
  136. #define    STMAGLEN    4    /* "tar" including NULL byte */
  137. #define    STVERSION    '1'    /* current star version */
  138.  
  139. #define    STUNMLEN    16    /* star user name length */
  140. #define    STGNMLEN    15    /* star group name length */
  141.  
  142. /*
  143.  * This is the old (pre Posix 1003.1) star header defined in 1985.
  144.  */
  145. struct star_header {
  146.     char t_name[NAMSIZ];    /*   0    Dateiname    */
  147.     char t_mode[8];        /* 100    Zugriffsrechte     */
  148.     char t_uid[8];        /* 108    Benutzernummer    */
  149.     char t_gid[8];        /* 116    Benutzergruppe    */
  150.     char t_size[12];    /* 124    Dateigroesze    */
  151.     char t_mtime[12];    /* 136    Zeit d. letzten Aenderung */
  152.     char t_chksum[8];    /* 148    Checksumme    */
  153.     char t_linkflag;    /* 156    Linktyp der Datei */
  154.     char t_linkname[NAMSIZ];/* 157    Zielname des Links */
  155.     char t_vers;        /* 257    Version v. star    */
  156.     char t_filetype[8];    /* 258    Interner Dateityp */
  157.     char t_type[12];    /* 266    Dateityp (UNIX)    */
  158. #ifdef    no_minor_bits_in_rdev
  159.     char t_rdev[12];    /* 278    Major/Minor bei Geraeten */
  160. #else
  161.     char t_rdev[11];    /* 278    Major/Minor bei Geraeten */
  162.     char t_devminorbits;    /* 298    Anzahl d. Minor Bits in t_rdev */
  163. #endif
  164.     char t_atime[12];    /* 290    Zeit d. letzten Zugriffs */
  165.     char t_ctime[12];    /* 302    Zeit d. letzten Statusaend. */
  166.     char t_uname[STUNMLEN];    /* 314    Benutzername    */
  167.     char t_gname[STGNMLEN];    /* 330    Gruppenname    */
  168.     char t_prefix[PFXSIZ];    /* 345    Prefix fuer t_name */
  169.     char t_mfill[8];    /* 500    Filler bis magic */
  170.     char t_magic[4];    /* 508    "tar"        */
  171. };
  172.  
  173. /*
  174.  * This is the new (post Posix 1003.1) xstar header.
  175.  *
  176.  * t_prefix[130]    is garanteed to be '\0' to prevent ustar compliant
  177.  *            implementations from failing.
  178.  * t_mfill & t_xmagic    need to be zero for a 100% ustar compliant
  179.  *            implementation, so setting t_xmagic to "tar" should
  180.  *            be avoided in the future.
  181.  *
  182.  * A different method to recognise this format is to verify that
  183.  * t_prefix[130]    is equal to '\0' and
  184.  * t_atime[0]/t_ctime[0] is an octal number and
  185.  * t_atime[11]        is equal to ' ' and
  186.  * t_ctime[11]        is equal to ' '.
  187.  *
  188.  * Note that t_atime[11]/t_ctime[11] may be changed in future.
  189.  */
  190. struct xstar_header {
  191.     char t_name[NAMSIZ];    /*   0    Dateiname    */
  192.     char t_mode[8];        /* 100    Zugriffsrechte     */
  193.     char t_uid[8];        /* 108    Benutzernummer    */
  194.     char t_gid[8];        /* 116    Benutzergruppe    */
  195.     char t_size[12];    /* 124    Dateigroesze    */
  196.     char t_mtime[12];    /* 136    Zeit d. letzten Aenderung */
  197.     char t_chksum[8];    /* 148    Checksumme    */
  198.     char t_typeflag;    /* 156    Typ der Datei    */
  199.     char t_linkname[NAMSIZ];/* 157    Zielname des Links */
  200.     char t_magic[TMAGLEN];    /* 257    "ustar"        */
  201.     char t_version[TVERSLEN];/*263    Version v. star    */
  202.     char t_uname[TUNMLEN];    /* 265    Benutzername    */
  203.     char t_gname[TGNMLEN];    /* 297    Gruppenname    */
  204.     char t_devmajor[8];    /* 329    Major bei Geraeten */
  205.     char t_devminor[8];    /* 337    Minor bei Geraeten */
  206.     char t_prefix[131];    /* 345    Prefix fuer t_name */
  207.     char t_atime[12];    /* 476    Zeit d. letzten Zugriffs */
  208.     char t_ctime[12];    /* 488    Zeit d. letzten Statusaend. */
  209.     char t_mfill[8];    /* 500    Filler bis magic */
  210.     char t_xmagic[4];    /* 508    "tar"        */
  211. };
  212.  
  213. struct sparse {
  214.     char t_offset[12];
  215.     char t_numbytes[12];
  216. };
  217.  
  218. #define SPARSE_EXT_HDR  21
  219. #define SPARSE_IN_HDR    4
  220. #define    SIH        SPARSE_IN_HDR
  221. #define    SEH        SPARSE_EXT_HDR
  222.  
  223. struct xstar_in_header {
  224.     char t_fill[345];    /*   0  Everything that is before t_prefix */
  225.     char t_prefix[1];    /* 345    Prefix fuer t_name */
  226.     char t_fill2;        /* 346  */
  227.     char t_fill3[8];    /* 347  */
  228.     char t_isextended;    /* 355    */
  229.     struct sparse t_sp[SIH];/* 356    8 x 12        */
  230.     char t_realsize[12];    /* 452    Echte Gr÷▀e bei sparse Dateien */
  231.     char t_offset[12];    /* 464    Offset fⁿr Multivol cont. Dateien */
  232.     char t_atime[12];    /* 476    Zeit d. letzten Zugriffs */
  233.     char t_ctime[12];    /* 488    Zeit d. letzten Statusaend. */
  234.     char t_mfill[8];    /* 500    Filler bis magic */
  235.     char t_xmagic[4];    /* 508    "tar"        */
  236. };
  237.  
  238. struct xstar_ext_header {
  239.     struct sparse t_sp[SEH];
  240.     char t_isextended;
  241. };
  242.  
  243. /*
  244.  * gnu tar header specific definitions
  245.  */
  246.  
  247. #define    GMAGIC        "ustar  "/* gnu tar magic */
  248. #define    GMAGLEN        8    /* "ustar" two blanks and a NULL */
  249.  
  250. typedef struct {
  251.     unsigned long    sp_offset;
  252.     unsigned long    sp_numbytes;
  253. } sp_t;
  254.  
  255. struct gnu_in_header {
  256.     char    t_fill[386];
  257.     struct sparse t_sp[SIH];/* 386    */
  258.     char t_isextended;    /* 482    */
  259.     char t_realsize[12];    /* true size of the sparse file *//* 483 */
  260. };
  261.  
  262. struct gnu_extended_header {
  263.     struct sparse t_sp[SEH];
  264.     char t_isextended;
  265. };
  266.  
  267. struct gnu_header {
  268.     char t_name[NAMSIZ];    /*   0    Dateiname    */
  269.     char t_mode[8];        /* 100    Zugriffsrechte    */
  270.     char t_uid[8];        /* 108    Benutzernummer    */
  271.     char t_gid[8];        /* 116    Benutzergruppe    */
  272.     char t_size[12];    /* 124    Dateigroesze    */
  273.     char t_mtime[12];    /* 136    Zeit d. letzten Aenderung */
  274.     char t_chksum[8];    /* 148    Checksumme    */
  275.     char t_linkflag;    /* 156    Typ der Datei    */
  276.     char t_linkname[NAMSIZ];/* 157    Zielname des Links */
  277.     char t_magic[8];    /* 257    "ustar"        */
  278.     char t_uname[TUNMLEN];    /* 265    Benutzername    */
  279.     char t_gname[TGNMLEN];    /* 297    Gruppenname    */
  280.     char t_devmajor[8];    /* 329    Major bei Geraeten */
  281.     char t_devminor[8];    /* 337    Minor bei Geraeten */
  282.     /* these following fields were added by JF for gnu */
  283.     /* and are NOT standard */
  284.     char t_atime[12];    /* 345    */
  285.     char t_ctime[12];    /* 357    */
  286.     char t_offset[12];    /* 369    */
  287.     char t_longnames[4];    /* 381    */
  288. #ifdef    xxx
  289. #ifdef NEEDPAD
  290.     char pad;        /* 385    */
  291. #endif
  292.     struct sparse t_sp[SPARSE_IN_HDR];/* 386    */
  293.     char t_isextended;    /* 482    */
  294.     char t_realsize[12];    /* true size of the sparse file *//* 483 */
  295.     /* char    ending_blanks[12];*//* number of nulls at the    *//* 495 */
  296.     /* end of the file, if any */
  297. #endif /* xxx */
  298. };
  299. #undef    SIH
  300. #undef    SEH
  301.  
  302. #define    BAR_UNSPEC    '\0'    /* XXX Volheader ??? */
  303. #define    BAR_REGTYPE    '0'
  304. #define    BAR_LNKTYPE    '1'
  305. #define    BAR_SYMTYPE    '2'
  306. #define    BAR_SPECIAL    '3'
  307.  
  308. #define    BAR_VOLHEAD    "V"
  309.  
  310. struct bar_header {
  311.     char mode[8];        /*   0    file type and mode (top bit masked) */
  312.     char uid[8];        /*   8    Benutzernummer    */
  313.     char gid[8];        /*  16    Benutzergruppe    */
  314.     char size[12];        /*  24    Dateigroesze    */
  315.     char mtime[12];        /*  36    Zeit d. letzten Aenderung */
  316.     char t_chksum[8];    /*  48    Checksumme    */
  317.     char rdev[8];        /*  56    Major/Minor bei Geraeten */
  318.     char linkflag;        /*  64    Linktyp der Datei */
  319.     char bar_magic[2];    /*  65    xxx        */
  320.     char volume_num[4];    /*  67    Volume Nummer    */
  321.     char compressed;    /*  71    Compress Flag    */
  322.     char date[12];        /*  72    Aktuelles Datum    */
  323.     char start_of_name[1];    /*  84    Dateiname    */
  324. };
  325.  
  326. typedef union hblock {
  327.     char dummy[TBLOCK];
  328.     struct star_header dbuf;
  329.     struct star_header star_dbuf;
  330.     struct xstar_header xstar_dbuf;
  331.     struct xstar_in_header xstar_in_dbuf;
  332.     struct xstar_ext_header xstar_ext_dbuf;
  333.     struct header ustar_dbuf;
  334.     struct gnu_header gnu_dbuf;
  335.     struct gnu_in_header gnu_in_dbuf;
  336.     struct gnu_extended_header gnu_ext_dbuf;
  337.     struct bar_header bar_dbuf;
  338. }TCB ;
  339.  
  340. typedef    struct    {
  341.     TCB    *f_tcb;
  342.     char    *f_name;    /* Zeiger auf den langen Dateinamen */
  343.     Ulong    f_namelen;    /* LΣnge des Dateinamens */
  344.     char    *f_lname;    /* Zeiger auf den langen Linknamen */
  345.     Ulong    f_lnamelen;    /* LΣnge des Linknamens */
  346.     char    *f_uname;    /* User name oder NULL Pointer */
  347.     Ulong    f_umaxlen;    /* Maximale LΣnge des Usernamens*/
  348.     char    *f_gname;    /* Group name oder NULL Pointer */
  349.     Ulong    f_gmaxlen;    /* Maximale LΣnge des Gruppennamens*/
  350.     Ulong    f_dev;        /* Geraet auf dem sich d. Datei befindet */
  351.     Ulong    f_ino;        /* Dateinummer            */
  352.     Ulong    f_nlink;    /* Anzahl der Links        */
  353.     Ulong    f_mode;        /* Zugriffsrechte         */
  354.     Ulong    f_uid;        /* Benutzernummer        */
  355.     Ulong    f_gid;        /* Benutzergruppe        */
  356.     Ulong    f_size;        /* Dateigroesze            */
  357.     Ulong    f_rsize;    /* Dateigroesze auf Band    */
  358.     Ulong    f_offset;    /* Offset fⁿr Multivol cont. Dateien */
  359.     Ulong    f_flags;    /* Bearbeitungshinweise        */
  360.     Ulong    f_xftype;    /* Typ der Datei (neu generell)    */
  361.     Ulong    f_filetype;    /* Typ der Datei (star alt)    */
  362.     Ulong    f_type;        /* Dateityp            */
  363.     Ulong    f_rdev;        /* Major/Minor bei Geraeten    */
  364.     Ulong    f_rdevmaj;    /* Major bei Geraeten        */
  365.     Ulong    f_rdevmin;    /* Minor bei Geraeten        */
  366.     time_t    f_atime;    /* Zeit d. letzten Zugriffs    */
  367.     Ulong    f_ansec;    /* nsec Teil "            */
  368.     time_t    f_mtime;    /* Zeit d. letzten Aenderung    */
  369.     Ulong    f_mnsec;    /* nsec Teil "            */
  370.     time_t    f_ctime;    /* Zeit d. letzten Statusaend.    */
  371.     Ulong    f_cnsec;    /* nsec Teil "            */
  372. } FINFO;
  373.  
  374. #define    F_LONGNAME    0x01    /* Langer Name passt nicht in Header         */
  375. #define    F_LONGLINK    0x02    /* Langer Linkname passt nicht in Header     */
  376. #define    F_SPLIT_NAME    0x04    /* Langer Name wurde gesplitted             */
  377. #define    F_HAS_NAME    0x08    /* Langer Name in f_name/f_lname soll bleiben*/
  378. #define    F_SPARSE    0x10    /* Datei enthΣlt L÷cher                 */
  379. #define    F_TCB_BUF    0x20    /* TCB ist/war vom Buffer alloziert         */
  380. #define    F_ADDSLASH    0x40    /* Langer Name ben÷tigt Slash am Ende         */
  381.  
  382. #define    F_SPEC    0
  383. #define    F_FILE    1
  384. #define    F_SLINK    2
  385. #define    F_DIR    3
  386.  
  387. #define    is_special(i)    ((i)->f_filetype == F_SPEC)
  388. #define    is_file(i)    ((i)->f_filetype == F_FILE)
  389. #define    is_symlink(i)    ((i)->f_filetype == F_SLINK)
  390. #define    is_dir(i)    ((i)->f_filetype == F_DIR)
  391.  
  392. #define    is_bdev(i)    ((i)->f_xftype == XT_BLK)
  393. #define    is_cdev(i)    ((i)->f_xftype == XT_CHR)
  394. #define    is_dev(i)    (is_bdev(i) || is_cdev(i))
  395. #define    is_fifo(i)    ((i)->f_xftype == XT_FIFO)
  396. #define    is_link(i)    ((i)->f_xftype == XT_LINK)
  397. #define    is_volhdr(i)    ((i)->f_xftype == XT_VOLHDR)
  398. #define    is_sparse(i)    ((i)->f_xftype == XT_SPARSE)
  399. #define    is_multivol(i)    ((i)->f_xftype == XT_MULTIVOL)
  400.  
  401. #define isoctal(c)    ((c) >= '0' && (c) <= '7')
  402. #define    isupper(c)    ((c) >= 'A' && (c) <= 'Z')
  403. #define    toupper(c)    (isupper(c) ? (c) : (c) - ('a' - 'A'))
  404. /*
  405.  * Needed for QNX
  406.  */
  407. #ifdef    max
  408. #undef    max
  409. #endif
  410. #ifdef    min
  411. #undef    min
  412. #endif
  413. #define    max(a,b)    ((a) < (b) ? (b) : (a))
  414. #define    min(a,b)    ((a) < (b) ? (a) : (b))
  415.  
  416.  
  417. struct star_stats {
  418.     int    s_staterrs;    /* Could not stat(2) file    */
  419.     int    s_openerrs;    /* Open/Create error for file    */
  420.     int    s_rwerrs;    /* Read/Write error from file    */
  421.     int    s_sizeerrs;    /* File changed size        */
  422.     int    s_misslinks;    /* Missing links to file    */
  423.     int    s_toolong;    /* File name too long        */
  424.     int    s_toobig;    /* File does not fit on one tape*/
  425.     int    s_isspecial;    /* File is special - not dumped    */
  426. };
  427.  
  428. extern    struct    star_stats    xstats;
  429.  
  430.  
  431. #include <sys/param.h>
  432.  
  433. #if !defined(PATH_MAX) && defined(MAXPATHLEN)
  434. #define    PATH_MAX    MAXPATHLEN
  435. #endif
  436.  
  437. #ifndef    PATH_MAX
  438. #define    PATH_MAX    1024
  439. #endif
  440.  
  441. /*
  442.  * Make sure that regardless what the OS defines, star reserves
  443.  * space for 1024 chars in filenames.
  444.  */
  445. #if    PATH_MAX < 1024
  446. #undef    PATH_MAX
  447. #define    PATH_MAX    1024
  448. #endif
  449.