12654012fSReza Sabdar /* 2*b6b15642SReza Sabdar * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 32654012fSReza Sabdar * Use is subject to license terms. 42654012fSReza Sabdar */ 52654012fSReza Sabdar 62654012fSReza Sabdar /* 72654012fSReza Sabdar * BSD 3 Clause License 82654012fSReza Sabdar * 92654012fSReza Sabdar * Copyright (c) 2007, The Storage Networking Industry Association. 102654012fSReza Sabdar * 112654012fSReza Sabdar * Redistribution and use in source and binary forms, with or without 122654012fSReza Sabdar * modification, are permitted provided that the following conditions 132654012fSReza Sabdar * are met: 142654012fSReza Sabdar * - Redistributions of source code must retain the above copyright 152654012fSReza Sabdar * notice, this list of conditions and the following disclaimer. 162654012fSReza Sabdar * 172654012fSReza Sabdar * - Redistributions in binary form must reproduce the above copyright 182654012fSReza Sabdar * notice, this list of conditions and the following disclaimer in 192654012fSReza Sabdar * the documentation and/or other materials provided with the 202654012fSReza Sabdar * distribution. 212654012fSReza Sabdar * 222654012fSReza Sabdar * - Neither the name of The Storage Networking Industry Association (SNIA) 232654012fSReza Sabdar * nor the names of its contributors may be used to endorse or promote 242654012fSReza Sabdar * products derived from this software without specific prior written 252654012fSReza Sabdar * permission. 262654012fSReza Sabdar * 272654012fSReza Sabdar * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 282654012fSReza Sabdar * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 292654012fSReza Sabdar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 302654012fSReza Sabdar * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 312654012fSReza Sabdar * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 322654012fSReza Sabdar * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 332654012fSReza Sabdar * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 342654012fSReza Sabdar * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 352654012fSReza Sabdar * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 362654012fSReza Sabdar * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 372654012fSReza Sabdar * POSSIBILITY OF SUCH DAMAGE. 382654012fSReza Sabdar */ 392654012fSReza Sabdar #ifndef _TLM_H_ 402654012fSReza Sabdar #define _TLM_H_ 412654012fSReza Sabdar 422654012fSReza Sabdar #include <sys/types.h> 432654012fSReza Sabdar #include <synch.h> 442654012fSReza Sabdar #include <limits.h> 452654012fSReza Sabdar #include <cstack.h> 462654012fSReza Sabdar #include <sys/acl.h> 472654012fSReza Sabdar #include <stdio.h> 482654012fSReza Sabdar #include <errno.h> 492654012fSReza Sabdar #include <fcntl.h> 502654012fSReza Sabdar #include <strings.h> 512654012fSReza Sabdar #include <sys/stat.h> 522654012fSReza Sabdar #include <time.h> 532654012fSReza Sabdar #include <sys/queue.h> 542654012fSReza Sabdar 552654012fSReza Sabdar #define IS_SET(f, m) (((f) & (m)) != 0) 562654012fSReza Sabdar 572654012fSReza Sabdar #define TLM_MAX_BACKUP_JOB_NAME 32 /* max size of a job's name */ 582654012fSReza Sabdar #define TLM_TAPE_BUFFERS 10 /* number of rotating tape buffers */ 592654012fSReza Sabdar #define TLM_LINE_SIZE 128 /* size of text messages */ 602654012fSReza Sabdar 612654012fSReza Sabdar 622654012fSReza Sabdar #define TLM_BACKUP_RUN 0x00000001 632654012fSReza Sabdar #define TLM_RESTORE_RUN 0x00000002 642654012fSReza Sabdar #define TLM_STOP 0x00000009 /* graceful stop */ 652654012fSReza Sabdar #define TLM_ABORT 0x99999999 /* abandon the run */ 662654012fSReza Sabdar 672654012fSReza Sabdar #define TLM_EXTRA_SPACE 64 682654012fSReza Sabdar #define TLM_MAX_PATH_NAME (PATH_MAX + TLM_EXTRA_SPACE) 692654012fSReza Sabdar 702654012fSReza Sabdar #define ENTRYTYPELEN 14 712654012fSReza Sabdar #define PERMS 4 722654012fSReza Sabdar #define ID_STR_MAX 20 732654012fSReza Sabdar #define APPENDED_ID_MAX (ID_STR_MAX + 1) 742654012fSReza Sabdar #define ACL_ENTRY_SIZE (ENTRYTYPELEN + ID_STR_MAX + PERMS + APPENDED_ID_MAX) 752654012fSReza Sabdar #define TLM_MAX_ACL_TXT MAX_ACL_ENTRIES * ACL_ENTRY_SIZE 762654012fSReza Sabdar 772654012fSReza Sabdar 782654012fSReza Sabdar /* operation flags */ 792654012fSReza Sabdar #define TLM_OP_CHOOSE_ARCHIVE 0x00000001 /* look for archive bit */ 802654012fSReza Sabdar 812654012fSReza Sabdar /* 822654012fSReza Sabdar * Synchronization flags used when launching the TLM threads. 832654012fSReza Sabdar */ 842654012fSReza Sabdar #define TLM_TAPE_READER 0x00000001 852654012fSReza Sabdar #define TLM_TAPE_WRITER 0x00000002 862654012fSReza Sabdar #define TLM_SOCK_READER 0x00000004 872654012fSReza Sabdar #define TLM_SOCK_WRITER 0x00000008 882654012fSReza Sabdar #define TLM_BUF_READER 0x00000010 892654012fSReza Sabdar #define TLM_BUF_WRITER 0x00000020 902654012fSReza Sabdar #define TLM_TAR_READER 0x00000040 912654012fSReza Sabdar #define TLM_TAR_WRITER 0x00000080 922654012fSReza Sabdar 937bc22e45SReza Sabdar #define SCSI_SERIAL_PAGE 0x80 947bc22e45SReza Sabdar #define SCSI_DEVICE_IDENT_PAGE 0x83 952654012fSReza Sabdar #define SCMD_READ_ELEMENT_STATUS 0xB8 962654012fSReza Sabdar 97*b6b15642SReza Sabdar #define OCTAL7CHAR 07777777 98*b6b15642SReza Sabdar #define SYSATTR_RDONLY "SUNWattr_ro" 99*b6b15642SReza Sabdar #define SYSATTR_RW "SUNWattr_rw" 100*b6b15642SReza Sabdar 1012654012fSReza Sabdar typedef int (*func_t)(); 1022654012fSReza Sabdar 1037bc22e45SReza Sabdar typedef struct scsi_serial { 1047bc22e45SReza Sabdar int sr_flags; 1057bc22e45SReza Sabdar char sr_num[16]; 1067bc22e45SReza Sabdar } scsi_serial_t; 1077bc22e45SReza Sabdar 1082654012fSReza Sabdar typedef struct fs_fhandle { 1092654012fSReza Sabdar int fh_fid; 1102654012fSReza Sabdar char *fh_fpath; 1112654012fSReza Sabdar } fs_fhandle_t; 1122654012fSReza Sabdar 1132654012fSReza Sabdar typedef struct scsi_link { 1142654012fSReza Sabdar struct scsi_link *sl_next; 1152654012fSReza Sabdar struct scsi_link *sl_prev; 1162654012fSReza Sabdar struct scsi_adapter *sl_sa; 1172654012fSReza Sabdar unsigned int sl_sid; 1182654012fSReza Sabdar unsigned int sl_lun; 1192654012fSReza Sabdar unsigned int sl_requested_max_active; 1202654012fSReza Sabdar unsigned int sl_granted_max_active; 1212654012fSReza Sabdar unsigned int sl_n_active; 1222654012fSReza Sabdar unsigned int sl_type; /* SCSI device type */ 1232654012fSReza Sabdar } scsi_link_t; 1242654012fSReza Sabdar 1252654012fSReza Sabdar typedef struct scsi_adapter { 1262654012fSReza Sabdar struct scsi_adapter *sa_next; 1272654012fSReza Sabdar char sa_name[16]; 1282654012fSReza Sabdar struct scsi_link sa_link_head; 1292654012fSReza Sabdar } scsi_adapter_t; 1302654012fSReza Sabdar 1312654012fSReza Sabdar typedef struct sasd_drive { 1322654012fSReza Sabdar char sd_name[256]; 1332654012fSReza Sabdar char sd_vendor[8 + 1]; 1342654012fSReza Sabdar char sd_id[16 + 1]; 1352654012fSReza Sabdar char sd_rev[4 + 1]; 1367bc22e45SReza Sabdar char sd_serial[16 + 1]; 1377bc22e45SReza Sabdar char sd_wwn[32 + 1]; 1382654012fSReza Sabdar } sasd_drive_t; 1392654012fSReza Sabdar 1402654012fSReza Sabdar typedef struct scsi_sasd_drive { 1412654012fSReza Sabdar sasd_drive_t ss_sd; 1422654012fSReza Sabdar scsi_link_t ss_slink; 1432654012fSReza Sabdar } scsi_sasd_drive_t; 1442654012fSReza Sabdar 1452654012fSReza Sabdar 1462654012fSReza Sabdar #define DEFAULT_SLINK_MAX_XFER (64*1024) 1472654012fSReza Sabdar 1482654012fSReza Sabdar typedef struct tlm_info { 1492654012fSReza Sabdar int ti_init_done; /* initialization done ? */ 1502654012fSReza Sabdar int ti_library_count; /* number of libraries */ 1512654012fSReza Sabdar struct tlm_library *ti_library; /* first in chain */ 1522654012fSReza Sabdar struct tlm_chain_link *ti_job_stats; /* chain of job statistics */ 1532654012fSReza Sabdar } tlm_info_t; 1542654012fSReza Sabdar 1552654012fSReza Sabdar typedef struct tlm_chain_link { 1562654012fSReza Sabdar struct tlm_chain_link *tc_next; /* next blob of statistics */ 1572654012fSReza Sabdar struct tlm_chain_link *tc_prev; /* previous blob in the chain */ 1582654012fSReza Sabdar int tc_ref_count; /* number of routines */ 1592654012fSReza Sabdar void *tc_data; /* the data blob */ 1602654012fSReza Sabdar } tlm_chain_link_t; 1612654012fSReza Sabdar 1622654012fSReza Sabdar typedef struct tlm_robot { 1632654012fSReza Sabdar struct tlm_robot *tr_next; 1642654012fSReza Sabdar struct tlm_library *tr_library; 1652654012fSReza Sabdar int tr_number; 1662654012fSReza Sabdar } tlm_robot_t; 1672654012fSReza Sabdar 1682654012fSReza Sabdar typedef struct tlm_drive { 1692654012fSReza Sabdar struct tlm_drive *td_next; 1702654012fSReza Sabdar struct tlm_library *td_library; 1712654012fSReza Sabdar char td_job_name[TLM_MAX_BACKUP_JOB_NAME]; 1722654012fSReza Sabdar int td_number; /* number of this tape drive */ 1732654012fSReza Sabdar int td_element; /* the library's number for the drive */ 1742654012fSReza Sabdar struct scsi_link *td_slink; /* because the drive may be connected */ 1752654012fSReza Sabdar /* to a different SCSI card than the */ 1762654012fSReza Sabdar /* library */ 1772654012fSReza Sabdar short td_scsi_id; 1782654012fSReza Sabdar short td_lun; 1792654012fSReza Sabdar short td_volume_number; /* for current job */ 1802654012fSReza Sabdar /* an index into the tape set */ 1812654012fSReza Sabdar int td_fd; /* I/O file descriptor */ 1822654012fSReza Sabdar int td_errno; /* system error number */ 1832654012fSReza Sabdar long td_exists : 1; 1842654012fSReza Sabdar 1852654012fSReza Sabdar } tlm_drive_t; 1862654012fSReza Sabdar 1872654012fSReza Sabdar typedef struct tlm_slot { 1882654012fSReza Sabdar struct tlm_slot *ts_next; 1892654012fSReza Sabdar struct tlm_library *ts_library; 1902654012fSReza Sabdar int ts_number; /* number of this slot */ 1912654012fSReza Sabdar int ts_element; 1922654012fSReza Sabdar short ts_use_count; /* number of times used since loaded */ 1932654012fSReza Sabdar long ts_status_full : 1; 1942654012fSReza Sabdar } tlm_slot_t; 1952654012fSReza Sabdar 1962654012fSReza Sabdar typedef struct tlm_library { 1972654012fSReza Sabdar struct tlm_library *tl_next; 1982654012fSReza Sabdar int tl_number; /* number of this tape library */ 1992654012fSReza Sabdar long tl_capability_robot : 1, 2002654012fSReza Sabdar tl_capability_door : 1, 2012654012fSReza Sabdar tl_capability_lock : 1, 2022654012fSReza Sabdar tl_capability_slots : 1, 2032654012fSReza Sabdar tl_capability_export : 1, 2042654012fSReza Sabdar tl_capability_drives : 1, 2052654012fSReza Sabdar tl_capability_barcodes : 1, 2062654012fSReza Sabdar tl_ghost_drives : 1; 2072654012fSReza Sabdar /* 2082654012fSReza Sabdar * "ghost_drives" is used to make sure that 2092654012fSReza Sabdar * all drives claimed by the library really 2102654012fSReza Sabdar * exist ... libraries have been known to lie. 2112654012fSReza Sabdar */ 2122654012fSReza Sabdar struct scsi_link *tl_slink; 2132654012fSReza Sabdar 2142654012fSReza Sabdar int tl_robot_count; 2152654012fSReza Sabdar tlm_robot_t *tl_robot; 2162654012fSReza Sabdar int tl_drive_count; 2172654012fSReza Sabdar tlm_drive_t *tl_drive; 2182654012fSReza Sabdar int tl_slot_count; 2192654012fSReza Sabdar tlm_slot_t *tl_slot; 2202654012fSReza Sabdar } tlm_library_t; 2212654012fSReza Sabdar 2227bc22e45SReza Sabdar typedef struct { 2237bc22e45SReza Sabdar unsigned char d_name[8]; 2247bc22e45SReza Sabdar } device_info_t; 2257bc22e45SReza Sabdar 2267bc22e45SReza Sabdar typedef struct { 2277bc22e45SReza Sabdar unsigned char p_number[4]; 2287bc22e45SReza Sabdar } port_info_t; 2297bc22e45SReza Sabdar 2307bc22e45SReza Sabdar typedef struct { 2317bc22e45SReza Sabdar #ifdef _BIG_ENDIAN 2327bc22e45SReza Sabdar uint8_t di_peripheral_qual : 3, 2337bc22e45SReza Sabdar di_peripheral_dev_type : 5; 2347bc22e45SReza Sabdar uint8_t di_page_code; 2357bc22e45SReza Sabdar uint16_t di_page_length; 2367bc22e45SReza Sabdar #else 2377bc22e45SReza Sabdar uint8_t di_peripheral_dev_type : 5, 2387bc22e45SReza Sabdar di_peripheral_qual : 3; 2397bc22e45SReza Sabdar uint8_t di_page_code; 2407bc22e45SReza Sabdar uint16_t di_page_length; 2417bc22e45SReza Sabdar #endif 2427bc22e45SReza Sabdar } device_ident_header_t; 2437bc22e45SReza Sabdar 2447bc22e45SReza Sabdar typedef struct { 2457bc22e45SReza Sabdar #ifdef _BIG_ENDIAN 2467bc22e45SReza Sabdar uint8_t ni_proto_ident : 4, 2477bc22e45SReza Sabdar ni_code_set : 4; 2487bc22e45SReza Sabdar 2497bc22e45SReza Sabdar uint8_t ni_PIV : 1, 2507bc22e45SReza Sabdar : 1, 2517bc22e45SReza Sabdar ni_asso : 2, 2527bc22e45SReza Sabdar ni_ident_type : 4; 2537bc22e45SReza Sabdar 2547bc22e45SReza Sabdar uint8_t ni_reserved; 2557bc22e45SReza Sabdar uint8_t ni_ident_length; 2567bc22e45SReza Sabdar #else 2577bc22e45SReza Sabdar uint8_t ni_code_set : 4, 2587bc22e45SReza Sabdar ni_proto_ident : 4; 2597bc22e45SReza Sabdar 2607bc22e45SReza Sabdar uint8_t ni_ident_type : 4, 2617bc22e45SReza Sabdar ni_asso : 2, 2627bc22e45SReza Sabdar : 1, 2637bc22e45SReza Sabdar ni_PIV : 1; 2647bc22e45SReza Sabdar uint8_t ni_reserved; 2657bc22e45SReza Sabdar uint8_t ni_ident_length; 2667bc22e45SReza Sabdar #endif 2677bc22e45SReza Sabdar } name_ident_t; 2687bc22e45SReza Sabdar 2697bc22e45SReza Sabdar typedef struct { 2707bc22e45SReza Sabdar device_ident_header_t np_header; 2717bc22e45SReza Sabdar name_ident_t np_node; 2727bc22e45SReza Sabdar device_info_t np_node_info; 2737bc22e45SReza Sabdar name_ident_t np_port; 2747bc22e45SReza Sabdar device_info_t np_port_info; 2757bc22e45SReza Sabdar name_ident_t np_portno; 2767bc22e45SReza Sabdar port_info_t np_portid; 2777bc22e45SReza Sabdar } device_name_page_t; 2787bc22e45SReza Sabdar 2792654012fSReza Sabdar #define TLM_NO_ERRORS 0x00000000 2802654012fSReza Sabdar #define TLM_ERROR_BUSY 0x00000001 2812654012fSReza Sabdar #define TLM_ERROR_INTERNAL 0x00000002 2822654012fSReza Sabdar #define TLM_ERROR_NO_ROBOTS 0x00000003 2832654012fSReza Sabdar #define TLM_TIMEOUT 0x00000004 2842654012fSReza Sabdar #define TLM_ERROR_RANGE 0x00000005 2852654012fSReza Sabdar #define TLM_EMPTY 0x00000006 2862654012fSReza Sabdar #define TLM_DRIVE_NOT_ASSIGNED 0x00000007 2872654012fSReza Sabdar #define TLM_NO_TAPE_NAME 0x00000008 2882654012fSReza Sabdar #define TLM_NO_BACKUP_DIR 0x00000009 2892654012fSReza Sabdar #define TLM_NO_BACKUP_HARDWARE 0x0000000a 2902654012fSReza Sabdar #define TLM_NO_SOURCE_FILE 0x0000000b 2912654012fSReza Sabdar #define TLM_NO_FREE_TAPES 0x0000000c 2922654012fSReza Sabdar #define TLM_EOT 0x0000000d 2932654012fSReza Sabdar #define TLM_SERIAL_NOT_FOUND 0x0000000e 2942654012fSReza Sabdar #define TLM_SMALL_READ 0x0000000f 2952654012fSReza Sabdar #define TLM_NO_RESTORE_FILE 0x00000010 2962654012fSReza Sabdar #define TLM_EOF 0x00000011 2972654012fSReza Sabdar #define TLM_NO_DIRECTORY 0x00000012 2982654012fSReza Sabdar #define TLM_NO_MEMORY 0x00000013 2992654012fSReza Sabdar #define TLM_WRITE_ERROR 0x00000014 3002654012fSReza Sabdar #define TLM_NO_SCRATCH_SPACE 0x00000015 3012654012fSReza Sabdar #define TLM_INVALID 0x00000016 3022654012fSReza Sabdar #define TLM_MOVE 0x00000017 3032654012fSReza Sabdar #define TLM_SKIP 0x00000018 3042654012fSReza Sabdar #define TLM_OPEN_ERR 0x00000019 3052654012fSReza Sabdar 3062654012fSReza Sabdar 3072654012fSReza Sabdar #define TLM_MAX_TAPE_DRIVES 16 3082654012fSReza Sabdar #define TLM_NAME_SIZE 100 3092654012fSReza Sabdar #define TLM_MAX_TAR_IMAGE 017777777770 3102654012fSReza Sabdar 3112654012fSReza Sabdar #define TLM_VOLNAME_MAX_LENGTH 255 3122654012fSReza Sabdar #define NAME_MAX 255 3132654012fSReza Sabdar 3142654012fSReza Sabdar #define TLM_MAGIC "ustar " 3152654012fSReza Sabdar #define TLM_SNAPSHOT_PREFIX ".zfs" 3162654012fSReza Sabdar #define TLM_SNAPSHOT_DIR ".zfs/snapshot" 3172654012fSReza Sabdar 3182654012fSReza Sabdar #define RECORDSIZE 512 3192654012fSReza Sabdar #define NAMSIZ 100 3202654012fSReza Sabdar 3212654012fSReza Sabdar typedef struct tlm_tar_hdr { 3222654012fSReza Sabdar char th_name[TLM_NAME_SIZE]; 3232654012fSReza Sabdar char th_mode[8]; 3242654012fSReza Sabdar char th_uid[8]; 3252654012fSReza Sabdar char th_gid[8]; 3262654012fSReza Sabdar char th_size[12]; 3272654012fSReza Sabdar char th_mtime[12]; 3282654012fSReza Sabdar char th_chksum[8]; 3292654012fSReza Sabdar char th_linkflag; 3302654012fSReza Sabdar char th_linkname[TLM_NAME_SIZE]; 3312654012fSReza Sabdar char th_magic[8]; 332*b6b15642SReza Sabdar char th_uname[32]; 333*b6b15642SReza Sabdar char th_gname[32]; 3342654012fSReza Sabdar union { 3352654012fSReza Sabdar struct { 3362654012fSReza Sabdar char th_devmajor[8]; 3372654012fSReza Sabdar char th_devminor[8]; 3382654012fSReza Sabdar } th_dev; 3392654012fSReza Sabdar char th_hlink_ino[12]; 3402654012fSReza Sabdar } th_shared; 3412654012fSReza Sabdar } tlm_tar_hdr_t; 3422654012fSReza Sabdar 3432654012fSReza Sabdar 3442654012fSReza Sabdar 3452654012fSReza Sabdar /* 3462654012fSReza Sabdar * The linkflag defines the type of file 3472654012fSReza Sabdar */ 3482654012fSReza Sabdar #define LF_OLDNORMAL '\0' /* Normal disk file, Unix compat */ 3492654012fSReza Sabdar #define LF_NORMAL '0' /* Normal disk file */ 3502654012fSReza Sabdar #define LF_LINK '1' /* Link to previously dumped file */ 3512654012fSReza Sabdar #define LF_SYMLINK '2' /* Symbolic link */ 3522654012fSReza Sabdar #define LF_CHR '3' /* Character special file */ 3532654012fSReza Sabdar #define LF_BLK '4' /* Block special file */ 3542654012fSReza Sabdar #define LF_DIR '5' /* Directory */ 3552654012fSReza Sabdar #define LF_FIFO '6' /* FIFO special file */ 3562654012fSReza Sabdar #define LF_CONTIG '7' /* Contiguous file */ 3572654012fSReza Sabdar /* Further link types may be defined later. */ 3582654012fSReza Sabdar 3592654012fSReza Sabdar #define LF_DUMPDIR 'D' 3602654012fSReza Sabdar /* 3612654012fSReza Sabdar * This is a dir entry that contains 3622654012fSReza Sabdar * the names of files that were in 3632654012fSReza Sabdar * the dir at the time the dump 3642654012fSReza Sabdar * was made 3652654012fSReza Sabdar */ 3662654012fSReza Sabdar #define LF_HUMONGUS 'H' 3672654012fSReza Sabdar /* 3682654012fSReza Sabdar * Identifies the NEXT file on the tape 3692654012fSReza Sabdar * as a HUGE file 3702654012fSReza Sabdar */ 3712654012fSReza Sabdar #define LF_LONGLINK 'K' 3722654012fSReza Sabdar /* 3732654012fSReza Sabdar * Identifies the NEXT file on the tape 3742654012fSReza Sabdar * as having a long linkname 3752654012fSReza Sabdar */ 3762654012fSReza Sabdar #define LF_LONGNAME 'L' 3772654012fSReza Sabdar /* 3782654012fSReza Sabdar * Identifies the NEXT file on the tape 3792654012fSReza Sabdar * as having a long name. 3802654012fSReza Sabdar */ 3812654012fSReza Sabdar #define LF_MULTIVOL 'M' 3822654012fSReza Sabdar /* 3832654012fSReza Sabdar * This is the continuation 3842654012fSReza Sabdar * of a file that began on another 3852654012fSReza Sabdar * volume 3862654012fSReza Sabdar */ 3872654012fSReza Sabdar 3882654012fSReza Sabdar #define LF_VOLHDR 'V' /* This file is a tape/volume header */ 3892654012fSReza Sabdar /* Ignore it on extraction */ 3902654012fSReza Sabdar 3912654012fSReza Sabdar #define LF_ACL 'A' /* Access Control List */ 3922654012fSReza Sabdar 3932654012fSReza Sabdar #define LF_XATTR 'E' /* Extended attribute */ 3942654012fSReza Sabdar 3952654012fSReza Sabdar #define KILOBYTE 1024 3962654012fSReza Sabdar 3972654012fSReza Sabdar 3982654012fSReza Sabdar /* 3992654012fSReza Sabdar * ACL support structure 4002654012fSReza Sabdar */ 4012654012fSReza Sabdar typedef struct sec_attr { 4022654012fSReza Sabdar char attr_type; 4032654012fSReza Sabdar char attr_len[7]; 4042654012fSReza Sabdar char attr_info[TLM_MAX_ACL_TXT]; 4052654012fSReza Sabdar } sec_attr_t; 4062654012fSReza Sabdar 4072654012fSReza Sabdar typedef struct tlm_acls { 4082654012fSReza Sabdar int acl_checkpointed : 1, /* are checkpoints active ? */ 4092654012fSReza Sabdar acl_clear_archive : 1, /* clear archive bit ? */ 4102654012fSReza Sabdar acl_overwrite : 1, /* always overwrite ? */ 4112654012fSReza Sabdar acl_update : 1, /* only update ? */ 4122654012fSReza Sabdar acl_non_trivial : 1; /* real ACLs? */ 4132654012fSReza Sabdar /* 4142654012fSReza Sabdar * The following fields are here to allow 4152654012fSReza Sabdar * the backup reader to open a file one time 4162654012fSReza Sabdar * and keep the information for ACL, ATTRs, 4172654012fSReza Sabdar * and reading the file. 4182654012fSReza Sabdar */ 4192654012fSReza Sabdar sec_attr_t acl_info; 4202654012fSReza Sabdar 4212654012fSReza Sabdar char acl_root_dir[TLM_VOLNAME_MAX_LENGTH]; /* name of root filesystem */ 4222654012fSReza Sabdar fs_fhandle_t acl_dir_fh; /* parent dir's info */ 4232654012fSReza Sabdar fs_fhandle_t acl_fil_fh; /* file's info */ 4242654012fSReza Sabdar struct stat64 acl_attr; /* file system attributes */ 425*b6b15642SReza Sabdar char uname[32]; 426*b6b15642SReza Sabdar char gname[32]; 4272654012fSReza Sabdar } tlm_acls_t; 4282654012fSReza Sabdar 4292654012fSReza Sabdar 4302654012fSReza Sabdar /* 4312654012fSReza Sabdar * Tape manager's data archiving ops vector 4322654012fSReza Sabdar * 4332654012fSReza Sabdar * This vector represents the granular operations for 4342654012fSReza Sabdar * performing backup/restore. Each backend should provide 4352654012fSReza Sabdar * such a vector interface in order to be invoked by NDMP 4362654012fSReza Sabdar * server. 4372654012fSReza Sabdar * The reserved callbacks are kept for different backup 4382654012fSReza Sabdar * types which are volume-based rather than file-based 4392654012fSReza Sabdar * e.g. zfs send. 4402654012fSReza Sabdar */ 4412654012fSReza Sabdar typedef struct tm_ops { 4422654012fSReza Sabdar char *tm_name; 4432654012fSReza Sabdar int (*tm_putfile)(); 4442654012fSReza Sabdar int (*tm_putdir)(); 4452654012fSReza Sabdar int (*tm_putvol)(); /* Reserved */ 4462654012fSReza Sabdar int (*tm_getfile)(); 4472654012fSReza Sabdar int (*tm_getdir)(); 4482654012fSReza Sabdar int (*tm_getvol)(); /* Reserved */ 4492654012fSReza Sabdar } tm_ops_t; 4502654012fSReza Sabdar 4512654012fSReza Sabdar /* The checksum field is filled with this while the checksum is computed. */ 4522654012fSReza Sabdar #define CHKBLANKS " " /* 8 blanks, no null */ 4532654012fSReza Sabdar 4542654012fSReza Sabdar #define LONGNAME_PREFIX "././_LoNg_NaMe_" 4552654012fSReza Sabdar extern void ndmp_log(ulong_t, char *, char *, ...); 4562654012fSReza Sabdar char ndmp_log_info[256]; 4572654012fSReza Sabdar #define NDMP_LOG(p, ...) { \ 4582654012fSReza Sabdar (void) snprintf(ndmp_log_info, \ 4592654012fSReza Sabdar sizeof (ndmp_log_info), \ 4602654012fSReza Sabdar "[%d][%s:%d]", \ 4612654012fSReza Sabdar (int)pthread_self(), __func__, __LINE__); \ 4622654012fSReza Sabdar ndmp_log(p, ndmp_log_info, __VA_ARGS__); \ 4632654012fSReza Sabdar } 4642654012fSReza Sabdar extern void *ndmp_malloc(size_t size); 4652654012fSReza Sabdar 4662654012fSReza Sabdar /* 4672654012fSReza Sabdar * ZFS metadata plug-in module structures 4682654012fSReza Sabdar */ 4692654012fSReza Sabdar #define ZFS_MAX_PROPS 100 4702654012fSReza Sabdar #define ZFS_META_MAGIC "ZFSMETA" 4712654012fSReza Sabdar 4722654012fSReza Sabdar typedef struct ndmp_metadata_property { 4732654012fSReza Sabdar char mp_name[NAME_MAX]; 4742654012fSReza Sabdar char mp_value[NAME_MAX]; 4752654012fSReza Sabdar char mp_source[NAME_MAX]; 4762654012fSReza Sabdar } ndmp_metadata_property_t; 4772654012fSReza Sabdar 4782654012fSReza Sabdar typedef struct ndmp_metadata_header { 4792654012fSReza Sabdar char nh_plname[100]; 4802654012fSReza Sabdar uint_t nh_plversion; 4812654012fSReza Sabdar char nh_magic[10]; 4822654012fSReza Sabdar void *nh_handle; 4832654012fSReza Sabdar int nh_count; 4842654012fSReza Sabdar char nh_dataset[NAME_MAX]; 4852654012fSReza Sabdar ndmp_metadata_property_t nh_property[1]; 4862654012fSReza Sabdar } ndmp_metadata_header_t; 4872654012fSReza Sabdar 4882654012fSReza Sabdar /* 4892654012fSReza Sabdar * Node in struct hardlink_q 4902654012fSReza Sabdar * 4912654012fSReza Sabdar * inode: the inode of the hardlink 4922654012fSReza Sabdar * path: the name of the hardlink, used during restore 4932654012fSReza Sabdar * offset: tape offset of the data records for the hardlink, used during backup 4942654012fSReza Sabdar * is_tmp: indicate whether the file was created temporarily for restoring 4952654012fSReza Sabdar * other links during a non-DAR partial restore 4962654012fSReza Sabdar */ 4972654012fSReza Sabdar struct hardlink_node { 4982654012fSReza Sabdar unsigned long inode; 4992654012fSReza Sabdar char *path; 5002654012fSReza Sabdar unsigned long long offset; 5012654012fSReza Sabdar int is_tmp; 5022654012fSReza Sabdar SLIST_ENTRY(hardlink_node) next_hardlink; 5032654012fSReza Sabdar }; 5042654012fSReza Sabdar 5052654012fSReza Sabdar /* 5062654012fSReza Sabdar * Hardlinks that have been backed up or restored. 5072654012fSReza Sabdar * 5082654012fSReza Sabdar * During backup, each node represents a file whose 5092654012fSReza Sabdar * (1) inode has multiple links 5102654012fSReza Sabdar * (2) data has been backed up 5112654012fSReza Sabdar * 5122654012fSReza Sabdar * When we run into a file with multiple links during backup, 5132654012fSReza Sabdar * we first check the list to see whether a file with the same inode 5142654012fSReza Sabdar * has been backed up. If yes, we backup an empty record, while 5152654012fSReza Sabdar * making the file history of this file contain the data offset 5162654012fSReza Sabdar * of the offset of the file that has been backed up. If no, 5172654012fSReza Sabdar * we backup this file, and add an entry to the list. 5182654012fSReza Sabdar * 5192654012fSReza Sabdar * During restore, each node represents an LF_LINK type record whose 5202654012fSReza Sabdar * data has been restored (v.s. a hard link has been created). 5212654012fSReza Sabdar * 5222654012fSReza Sabdar * During restore, when we run into a record of LF_LINK type, we 5232654012fSReza Sabdar * first check the queue to see whether a file with the same inode 5242654012fSReza Sabdar * has been restored. If yes, we create a hardlink to it. 5252654012fSReza Sabdar * If no, we restore the data, and add an entry to the list. 5262654012fSReza Sabdar */ 5272654012fSReza Sabdar struct hardlink_q { 5282654012fSReza Sabdar struct hardlink_node *slh_first; 5292654012fSReza Sabdar }; 5302654012fSReza Sabdar 5312654012fSReza Sabdar /* Utility functions from handling hardlink */ 5322654012fSReza Sabdar extern struct hardlink_q *hardlink_q_init(); 5332654012fSReza Sabdar extern void hardlink_q_cleanup(struct hardlink_q *qhead); 5342654012fSReza Sabdar extern int hardlink_q_get(struct hardlink_q *qhead, unsigned long inode, 5352654012fSReza Sabdar unsigned long long *offset, char **path); 5362654012fSReza Sabdar extern int hardlink_q_add(struct hardlink_q *qhead, unsigned long inode, 5372654012fSReza Sabdar unsigned long long offset, char *path, int is_tmp); 5382654012fSReza Sabdar 5392654012fSReza Sabdar #endif /* !_TLM_H_ */ 540