xref: /titanic_44/usr/src/cmd/ndmpd/include/tlm.h (revision a1988827cf132ed4264c002279c6126834830520)
12654012fSReza Sabdar /*
2e461e790SRandall Ralphs  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
3*a1988827SMatthew Ahrens  * Copyright (c) 2015 by Delphix. All rights reserved.
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>
5442ed7838SReza Sabdar #include <sys/fs/zfs.h>
5542ed7838SReza Sabdar #include <libzfs.h>
562654012fSReza Sabdar 
572654012fSReza Sabdar #define	IS_SET(f, m)	(((f) & (m)) != 0)
582654012fSReza Sabdar 
592654012fSReza Sabdar #define	TLM_MAX_BACKUP_JOB_NAME	32	/* max size of a job's name */
602654012fSReza Sabdar #define	TLM_TAPE_BUFFERS	10	/* number of rotating tape buffers */
612654012fSReza Sabdar #define	TLM_LINE_SIZE		128	/* size of text messages */
622654012fSReza Sabdar 
632654012fSReza Sabdar 
642654012fSReza Sabdar #define	TLM_BACKUP_RUN		0x00000001
652654012fSReza Sabdar #define	TLM_RESTORE_RUN		0x00000002
662654012fSReza Sabdar #define	TLM_STOP		0x00000009	/* graceful stop */
672654012fSReza Sabdar #define	TLM_ABORT		0x99999999	/* abandon the run */
682654012fSReza Sabdar 
692654012fSReza Sabdar #define	TLM_EXTRA_SPACE		64
702654012fSReza Sabdar #define	TLM_MAX_PATH_NAME	(PATH_MAX + TLM_EXTRA_SPACE)
712654012fSReza Sabdar 
722654012fSReza Sabdar #define	ENTRYTYPELEN	14
732654012fSReza Sabdar #define	PERMS		4
742654012fSReza Sabdar #define	ID_STR_MAX	20
752654012fSReza Sabdar #define	APPENDED_ID_MAX	(ID_STR_MAX + 1)
762654012fSReza Sabdar #define	ACL_ENTRY_SIZE	(ENTRYTYPELEN + ID_STR_MAX + PERMS + APPENDED_ID_MAX)
772654012fSReza Sabdar #define	TLM_MAX_ACL_TXT	MAX_ACL_ENTRIES * ACL_ENTRY_SIZE
782654012fSReza Sabdar 
792654012fSReza Sabdar 
802654012fSReza Sabdar /* operation flags */
812654012fSReza Sabdar #define	TLM_OP_CHOOSE_ARCHIVE	0x00000001	/* look for archive bit */
822654012fSReza Sabdar 
832654012fSReza Sabdar /*
842654012fSReza Sabdar  * Synchronization flags used when launching the TLM threads.
852654012fSReza Sabdar  */
862654012fSReza Sabdar #define	TLM_TAPE_READER		0x00000001
872654012fSReza Sabdar #define	TLM_TAPE_WRITER		0x00000002
882654012fSReza Sabdar #define	TLM_SOCK_READER		0x00000004
892654012fSReza Sabdar #define	TLM_SOCK_WRITER		0x00000008
902654012fSReza Sabdar #define	TLM_BUF_READER		0x00000010
912654012fSReza Sabdar #define	TLM_BUF_WRITER		0x00000020
922654012fSReza Sabdar #define	TLM_TAR_READER		0x00000040
932654012fSReza Sabdar #define	TLM_TAR_WRITER		0x00000080
942654012fSReza Sabdar 
957bc22e45SReza Sabdar #define	SCSI_SERIAL_PAGE	0x80
967bc22e45SReza Sabdar #define	SCSI_DEVICE_IDENT_PAGE	0x83
972654012fSReza Sabdar #define	SCMD_READ_ELEMENT_STATUS	0xB8
982654012fSReza Sabdar 
99b6b15642SReza Sabdar #define	OCTAL7CHAR	07777777
100b6b15642SReza Sabdar #define	SYSATTR_RDONLY	"SUNWattr_ro"
101b6b15642SReza Sabdar #define	SYSATTR_RW	"SUNWattr_rw"
102b6b15642SReza Sabdar 
1032654012fSReza Sabdar typedef	int (*func_t)();
1042654012fSReza Sabdar 
1057bc22e45SReza Sabdar typedef struct scsi_serial {
1067bc22e45SReza Sabdar 	int sr_flags;
1077bc22e45SReza Sabdar 	char sr_num[16];
1087bc22e45SReza Sabdar } scsi_serial_t;
1097bc22e45SReza Sabdar 
1102654012fSReza Sabdar typedef struct fs_fhandle {
1112654012fSReza Sabdar 	int fh_fid;
1122654012fSReza Sabdar 	char *fh_fpath;
1132654012fSReza Sabdar } fs_fhandle_t;
1142654012fSReza Sabdar 
1152654012fSReza Sabdar typedef struct scsi_link {
1162654012fSReza Sabdar 	struct scsi_link 	*sl_next;
1172654012fSReza Sabdar 	struct scsi_link 	*sl_prev;
1182654012fSReza Sabdar 	struct scsi_adapter 	*sl_sa;
1192654012fSReza Sabdar 	unsigned int		sl_sid;
1202654012fSReza Sabdar 	unsigned int		sl_lun;
1212654012fSReza Sabdar 	unsigned int		sl_requested_max_active;
1222654012fSReza Sabdar 	unsigned int		sl_granted_max_active;
1232654012fSReza Sabdar 	unsigned int		sl_n_active;
1242654012fSReza Sabdar 	unsigned int		sl_type; /* SCSI device type */
1252654012fSReza Sabdar } scsi_link_t;
1262654012fSReza Sabdar 
1272654012fSReza Sabdar typedef struct scsi_adapter {
1282654012fSReza Sabdar 	struct scsi_adapter	*sa_next;
1292654012fSReza Sabdar 	char			sa_name[16];
1302654012fSReza Sabdar 	struct scsi_link	sa_link_head;
1312654012fSReza Sabdar } scsi_adapter_t;
1322654012fSReza Sabdar 
1332654012fSReza Sabdar typedef struct sasd_drive {
1342654012fSReza Sabdar 	char		sd_name[256];
1352654012fSReza Sabdar 	char		sd_vendor[8 + 1];
1362654012fSReza Sabdar 	char		sd_id[16 + 1];
1372654012fSReza Sabdar 	char		sd_rev[4 + 1];
1387bc22e45SReza Sabdar 	char		sd_serial[16 + 1];
1397bc22e45SReza Sabdar 	char		sd_wwn[32 + 1];
1402654012fSReza Sabdar } sasd_drive_t;
1412654012fSReza Sabdar 
1422654012fSReza Sabdar typedef struct scsi_sasd_drive {
1432654012fSReza Sabdar 	sasd_drive_t	ss_sd;
1442654012fSReza Sabdar 	scsi_link_t	ss_slink;
1452654012fSReza Sabdar } scsi_sasd_drive_t;
1462654012fSReza Sabdar 
1472654012fSReza Sabdar 
1482654012fSReza Sabdar #define	DEFAULT_SLINK_MAX_XFER	(64*1024)
1492654012fSReza Sabdar 
1502654012fSReza Sabdar typedef struct	tlm_info {
1512654012fSReza Sabdar 	int			ti_init_done;	/* initialization done ? */
1522654012fSReza Sabdar 	int			ti_library_count; /* number of libraries */
1532654012fSReza Sabdar 	struct tlm_library	*ti_library;	/* first in chain */
1542654012fSReza Sabdar 	struct tlm_chain_link	*ti_job_stats;  /* chain of job statistics */
1552654012fSReza Sabdar } tlm_info_t;
1562654012fSReza Sabdar 
1572654012fSReza Sabdar typedef struct	tlm_chain_link {
1582654012fSReza Sabdar 	struct tlm_chain_link	*tc_next;	/* next blob of statistics */
1592654012fSReza Sabdar 	struct tlm_chain_link	*tc_prev;	/* previous blob in the chain */
1602654012fSReza Sabdar 	int	tc_ref_count;			/* number of routines */
1612654012fSReza Sabdar 	void	*tc_data;			/* the data blob */
1622654012fSReza Sabdar } tlm_chain_link_t;
1632654012fSReza Sabdar 
1642654012fSReza Sabdar typedef struct	tlm_robot {
1652654012fSReza Sabdar 	struct tlm_robot	*tr_next;
1662654012fSReza Sabdar 	struct tlm_library	*tr_library;
1672654012fSReza Sabdar 	int	tr_number;
1682654012fSReza Sabdar } tlm_robot_t;
1692654012fSReza Sabdar 
1702654012fSReza Sabdar typedef struct	tlm_drive {
1712654012fSReza Sabdar 	struct tlm_drive	*td_next;
1722654012fSReza Sabdar 	struct tlm_library	*td_library;
1732654012fSReza Sabdar 	char	td_job_name[TLM_MAX_BACKUP_JOB_NAME];
1742654012fSReza Sabdar 	int	td_number;		/* number of this tape drive */
1752654012fSReza Sabdar 	int	td_element;		/* the library's number for the drive */
1762654012fSReza Sabdar 	struct	scsi_link *td_slink;	/* because the drive may be connected */
1772654012fSReza Sabdar 					/* to a different SCSI card than the */
1782654012fSReza Sabdar 					/* library */
1792654012fSReza Sabdar 	short	td_scsi_id;
1802654012fSReza Sabdar 	short	td_lun;
1812654012fSReza Sabdar 	short	td_volume_number;	/* for current job */
1822654012fSReza Sabdar 					/*  an index into the tape set */
1832654012fSReza Sabdar 	int	td_fd;			/* I/O file descriptor */
1842654012fSReza Sabdar 	int	td_errno;		/* system error number */
1852654012fSReza Sabdar 	long	td_exists	: 1;
1862654012fSReza Sabdar 
1872654012fSReza Sabdar } tlm_drive_t;
1882654012fSReza Sabdar 
1892654012fSReza Sabdar typedef struct	tlm_slot {
1902654012fSReza Sabdar 	struct tlm_slot		*ts_next;
1912654012fSReza Sabdar 	struct tlm_library	*ts_library;
1922654012fSReza Sabdar 	int	ts_number;		/* number of this slot */
1932654012fSReza Sabdar 	int	ts_element;
1942654012fSReza Sabdar 	short	ts_use_count;		/* number of times used since loaded */
1952654012fSReza Sabdar 	long	ts_status_full		: 1;
1962654012fSReza Sabdar } tlm_slot_t;
1972654012fSReza Sabdar 
1982654012fSReza Sabdar typedef struct	tlm_library {
1992654012fSReza Sabdar 	struct tlm_library	*tl_next;
2002654012fSReza Sabdar 	int	tl_number;		/* number of this tape library */
2012654012fSReza Sabdar 	long	tl_capability_robot	: 1,
2022654012fSReza Sabdar 		tl_capability_door	: 1,
2032654012fSReza Sabdar 		tl_capability_lock	: 1,
2042654012fSReza Sabdar 		tl_capability_slots	: 1,
2052654012fSReza Sabdar 		tl_capability_export	: 1,
2062654012fSReza Sabdar 		tl_capability_drives	: 1,
2072654012fSReza Sabdar 		tl_capability_barcodes	: 1,
2082654012fSReza Sabdar 		tl_ghost_drives		: 1;
2092654012fSReza Sabdar 		/*
2102654012fSReza Sabdar 		 * "ghost_drives" is used to make sure that
2112654012fSReza Sabdar 		 * all drives claimed by the library really
2122654012fSReza Sabdar 		 * exist ... libraries have been known to lie.
2132654012fSReza Sabdar 		 */
2142654012fSReza Sabdar 	struct	scsi_link *tl_slink;
2152654012fSReza Sabdar 
2162654012fSReza Sabdar 	int		tl_robot_count;
2172654012fSReza Sabdar 	tlm_robot_t	*tl_robot;
2182654012fSReza Sabdar 	int		tl_drive_count;
2192654012fSReza Sabdar 	tlm_drive_t	*tl_drive;
2202654012fSReza Sabdar 	int		tl_slot_count;
2212654012fSReza Sabdar 	tlm_slot_t	*tl_slot;
2222654012fSReza Sabdar } tlm_library_t;
2232654012fSReza Sabdar 
2247bc22e45SReza Sabdar typedef struct {
2257bc22e45SReza Sabdar #ifdef _BIG_ENDIAN
2267bc22e45SReza Sabdar 	uint8_t	di_peripheral_qual	: 3,
2277bc22e45SReza Sabdar 		di_peripheral_dev_type	: 5;
2287bc22e45SReza Sabdar 	uint8_t	di_page_code;
2297bc22e45SReza Sabdar 	uint16_t	di_page_length;
2307bc22e45SReza Sabdar #else
2317bc22e45SReza Sabdar 	uint8_t	di_peripheral_dev_type	: 5,
2327bc22e45SReza Sabdar 		di_peripheral_qual	: 3;
2337bc22e45SReza Sabdar 	uint8_t	di_page_code;
2347bc22e45SReza Sabdar 	uint16_t	di_page_length;
2357bc22e45SReza Sabdar #endif
2367bc22e45SReza Sabdar } device_ident_header_t;
2377bc22e45SReza Sabdar 
2387bc22e45SReza Sabdar typedef struct {
2397bc22e45SReza Sabdar #ifdef _BIG_ENDIAN
2407bc22e45SReza Sabdar 	uint8_t	ni_proto_ident	: 4,
2417bc22e45SReza Sabdar 		ni_code_set	: 4;
2427bc22e45SReza Sabdar 
2437bc22e45SReza Sabdar 	uint8_t	ni_PIV		: 1,
2447bc22e45SReza Sabdar 				: 1,
2457bc22e45SReza Sabdar 		ni_asso		: 2,
2467bc22e45SReza Sabdar 		ni_ident_type	: 4;
2477bc22e45SReza Sabdar 
2487bc22e45SReza Sabdar 	uint8_t	ni_reserved;
2497bc22e45SReza Sabdar 	uint8_t	ni_ident_length;
2507bc22e45SReza Sabdar #else
2517bc22e45SReza Sabdar 	uint8_t	ni_code_set	: 4,
2527bc22e45SReza Sabdar 		ni_proto_ident	: 4;
2537bc22e45SReza Sabdar 
2547bc22e45SReza Sabdar 	uint8_t	ni_ident_type	: 4,
2557bc22e45SReza Sabdar 		ni_asso		: 2,
2567bc22e45SReza Sabdar 				: 1,
2577bc22e45SReza Sabdar 		ni_PIV		: 1;
2587bc22e45SReza Sabdar 	uint8_t	ni_reserved;
2597bc22e45SReza Sabdar 	uint8_t	ni_ident_length;
2607bc22e45SReza Sabdar #endif
2617bc22e45SReza Sabdar } name_ident_t;
2627bc22e45SReza Sabdar 
2632654012fSReza Sabdar #define	TLM_NO_ERRORS			0x00000000
2642654012fSReza Sabdar #define	TLM_ERROR_BUSY			0x00000001
2652654012fSReza Sabdar #define	TLM_ERROR_INTERNAL		0x00000002
2662654012fSReza Sabdar #define	TLM_ERROR_NO_ROBOTS		0x00000003
2672654012fSReza Sabdar #define	TLM_TIMEOUT			0x00000004
2682654012fSReza Sabdar #define	TLM_ERROR_RANGE			0x00000005
2692654012fSReza Sabdar #define	TLM_EMPTY			0x00000006
2702654012fSReza Sabdar #define	TLM_DRIVE_NOT_ASSIGNED		0x00000007
2712654012fSReza Sabdar #define	TLM_NO_TAPE_NAME		0x00000008
2722654012fSReza Sabdar #define	TLM_NO_BACKUP_DIR		0x00000009
2732654012fSReza Sabdar #define	TLM_NO_BACKUP_HARDWARE		0x0000000a
2742654012fSReza Sabdar #define	TLM_NO_SOURCE_FILE		0x0000000b
2752654012fSReza Sabdar #define	TLM_NO_FREE_TAPES		0x0000000c
2762654012fSReza Sabdar #define	TLM_EOT				0x0000000d
2772654012fSReza Sabdar #define	TLM_SERIAL_NOT_FOUND		0x0000000e
2782654012fSReza Sabdar #define	TLM_SMALL_READ			0x0000000f
2792654012fSReza Sabdar #define	TLM_NO_RESTORE_FILE		0x00000010
2802654012fSReza Sabdar #define	TLM_EOF				0x00000011
2812654012fSReza Sabdar #define	TLM_NO_DIRECTORY		0x00000012
2822654012fSReza Sabdar #define	TLM_NO_MEMORY			0x00000013
2832654012fSReza Sabdar #define	TLM_WRITE_ERROR			0x00000014
2842654012fSReza Sabdar #define	TLM_NO_SCRATCH_SPACE		0x00000015
2852654012fSReza Sabdar #define	TLM_INVALID			0x00000016
2862654012fSReza Sabdar #define	TLM_MOVE			0x00000017
2872654012fSReza Sabdar #define	TLM_SKIP			0x00000018
2882654012fSReza Sabdar #define	TLM_OPEN_ERR			0x00000019
2892654012fSReza Sabdar 
2902654012fSReza Sabdar 
2912654012fSReza Sabdar #define	TLM_MAX_TAPE_DRIVES	16
2922654012fSReza Sabdar #define	TLM_NAME_SIZE		100
2932654012fSReza Sabdar #define	TLM_MAX_TAR_IMAGE	017777777770
2942654012fSReza Sabdar 
2952654012fSReza Sabdar #define	TLM_VOLNAME_MAX_LENGTH	255
2962654012fSReza Sabdar #define	NAME_MAX		255
2972654012fSReza Sabdar 
2982654012fSReza Sabdar #define	TLM_MAGIC		"ustar  "
2992654012fSReza Sabdar #define	TLM_SNAPSHOT_PREFIX	".zfs"
3002654012fSReza Sabdar #define	TLM_SNAPSHOT_DIR	".zfs/snapshot"
3012654012fSReza Sabdar 
3022654012fSReza Sabdar #define	RECORDSIZE	512
3032654012fSReza Sabdar #define	NAMSIZ	100
3042654012fSReza Sabdar 
3052654012fSReza Sabdar typedef struct	tlm_tar_hdr {
3062654012fSReza Sabdar 	char	th_name[TLM_NAME_SIZE];
3072654012fSReza Sabdar 	char	th_mode[8];
3082654012fSReza Sabdar 	char	th_uid[8];
3092654012fSReza Sabdar 	char	th_gid[8];
3102654012fSReza Sabdar 	char	th_size[12];
3112654012fSReza Sabdar 	char	th_mtime[12];
3122654012fSReza Sabdar 	char	th_chksum[8];
3132654012fSReza Sabdar 	char	th_linkflag;
3142654012fSReza Sabdar 	char	th_linkname[TLM_NAME_SIZE];
3152654012fSReza Sabdar 	char	th_magic[8];
316b6b15642SReza Sabdar 	char	th_uname[32];
317b6b15642SReza Sabdar 	char	th_gname[32];
3182654012fSReza Sabdar 	union {
3192654012fSReza Sabdar 		struct {
3202654012fSReza Sabdar 			char	th_devmajor[8];
3212654012fSReza Sabdar 			char	th_devminor[8];
3222654012fSReza Sabdar 		} th_dev;
3232654012fSReza Sabdar 		char	th_hlink_ino[12];
3242654012fSReza Sabdar 	} th_shared;
3252654012fSReza Sabdar } tlm_tar_hdr_t;
3262654012fSReza Sabdar 
3272654012fSReza Sabdar 
3282654012fSReza Sabdar 
3292654012fSReza Sabdar /*
3302654012fSReza Sabdar  * The linkflag defines the type of file
3312654012fSReza Sabdar  */
3322654012fSReza Sabdar #define	LF_OLDNORMAL	'\0'		/* Normal disk file, Unix compat */
3332654012fSReza Sabdar #define	LF_NORMAL	'0'		/* Normal disk file */
3342654012fSReza Sabdar #define	LF_LINK		'1'		/* Link to previously dumped file */
3352654012fSReza Sabdar #define	LF_SYMLINK	'2'		/* Symbolic link */
3362654012fSReza Sabdar #define	LF_CHR		'3'		/* Character special file */
3372654012fSReza Sabdar #define	LF_BLK		'4'		/* Block special file */
3382654012fSReza Sabdar #define	LF_DIR		'5'		/* Directory */
3392654012fSReza Sabdar #define	LF_FIFO		'6'		/* FIFO special file */
3402654012fSReza Sabdar #define	LF_CONTIG	'7'		/* Contiguous file */
3412654012fSReza Sabdar /* Further link types may be defined later. */
3422654012fSReza Sabdar 
3432654012fSReza Sabdar #define	LF_DUMPDIR	'D'
3442654012fSReza Sabdar 					/*
3452654012fSReza Sabdar 					 * This is a dir entry that contains
3462654012fSReza Sabdar 					 * the names of files that were in
3472654012fSReza Sabdar 					 * the dir at the time the dump
3482654012fSReza Sabdar 					 * was made
3492654012fSReza Sabdar 					 */
3502654012fSReza Sabdar #define	LF_HUMONGUS	'H'
3512654012fSReza Sabdar 					/*
3522654012fSReza Sabdar 					 * Identifies the NEXT file on the tape
3532654012fSReza Sabdar 					 * as a HUGE file
3542654012fSReza Sabdar 					 */
3552654012fSReza Sabdar #define	LF_LONGLINK	'K'
3562654012fSReza Sabdar 					/*
3572654012fSReza Sabdar 					 * Identifies the NEXT file on the tape
3582654012fSReza Sabdar 					 * as having a long linkname
3592654012fSReza Sabdar 					 */
3602654012fSReza Sabdar #define	LF_LONGNAME	'L'
3612654012fSReza Sabdar 					/*
3622654012fSReza Sabdar 					 * Identifies the NEXT file on the tape
3632654012fSReza Sabdar 					 * as having a long name.
3642654012fSReza Sabdar 					 */
3652654012fSReza Sabdar #define	LF_MULTIVOL	'M'
3662654012fSReza Sabdar 					/*
3672654012fSReza Sabdar 					 * This is the continuation
3682654012fSReza Sabdar 					 * of a file that began on another
3692654012fSReza Sabdar 					 * volume
3702654012fSReza Sabdar 					 */
3712654012fSReza Sabdar 
3722654012fSReza Sabdar #define	LF_VOLHDR	'V'		/* This file is a tape/volume header */
3732654012fSReza Sabdar 					/* Ignore it on extraction */
3742654012fSReza Sabdar 
3752654012fSReza Sabdar #define	LF_ACL		'A'		/* Access Control List */
3762654012fSReza Sabdar 
3772654012fSReza Sabdar #define	LF_XATTR	'E'		/* Extended attribute */
3782654012fSReza Sabdar 
3792654012fSReza Sabdar #define	KILOBYTE	1024
3802654012fSReza Sabdar 
3812654012fSReza Sabdar 
3822654012fSReza Sabdar /*
3832654012fSReza Sabdar  * ACL support structure
3842654012fSReza Sabdar  */
3852654012fSReza Sabdar typedef struct sec_attr {
3862654012fSReza Sabdar 	char attr_type;
3872654012fSReza Sabdar 	char attr_len[7];
3882654012fSReza Sabdar 	char attr_info[TLM_MAX_ACL_TXT];
3892654012fSReza Sabdar } sec_attr_t;
3902654012fSReza Sabdar 
3912654012fSReza Sabdar typedef struct	tlm_acls {
3922654012fSReza Sabdar 	int	acl_checkpointed	: 1,	/* are checkpoints active ? */
3932654012fSReza Sabdar 		acl_clear_archive	: 1,	/* clear archive bit ? */
3942654012fSReza Sabdar 		acl_overwrite		: 1,	/* always overwrite ? */
3952654012fSReza Sabdar 		acl_update		: 1,	/* only update ? */
3962654012fSReza Sabdar 		acl_non_trivial		: 1;	/* real ACLs? */
3972654012fSReza Sabdar 		/*
3982654012fSReza Sabdar 		 * The following fields are here to allow
3992654012fSReza Sabdar 		 * the backup reader to open a file one time
4002654012fSReza Sabdar 		 * and keep the information for ACL, ATTRs,
4012654012fSReza Sabdar 		 * and reading the file.
4022654012fSReza Sabdar 		 */
4032654012fSReza Sabdar 	sec_attr_t acl_info;
4042654012fSReza Sabdar 
4052654012fSReza Sabdar 	char acl_root_dir[TLM_VOLNAME_MAX_LENGTH]; /* name of root filesystem */
4062654012fSReza Sabdar 	fs_fhandle_t acl_dir_fh;		/* parent dir's info */
4072654012fSReza Sabdar 	fs_fhandle_t acl_fil_fh;		/* file's info */
4082654012fSReza Sabdar 	struct stat64 acl_attr;			/* file system attributes */
409b6b15642SReza Sabdar 	char uname[32];
410b6b15642SReza Sabdar 	char gname[32];
4112654012fSReza Sabdar } tlm_acls_t;
4122654012fSReza Sabdar 
4132654012fSReza Sabdar 
4142654012fSReza Sabdar /*
4152654012fSReza Sabdar  * Tape manager's data archiving ops vector
4162654012fSReza Sabdar  *
4172654012fSReza Sabdar  * This vector represents the granular operations for
4182654012fSReza Sabdar  * performing backup/restore. Each backend should provide
4192654012fSReza Sabdar  * such a vector interface in order to be invoked by NDMP
4202654012fSReza Sabdar  * server.
4212654012fSReza Sabdar  * The reserved callbacks are kept for different backup
4222654012fSReza Sabdar  * types which are volume-based rather than file-based
4232654012fSReza Sabdar  * e.g. zfs send.
4242654012fSReza Sabdar  */
4252654012fSReza Sabdar typedef struct tm_ops {
4262654012fSReza Sabdar 	char *tm_name;
4272654012fSReza Sabdar 	int (*tm_putfile)();
4282654012fSReza Sabdar 	int (*tm_putdir)();
4292654012fSReza Sabdar 	int (*tm_putvol)();	/* Reserved */
4302654012fSReza Sabdar 	int (*tm_getfile)();
4312654012fSReza Sabdar 	int (*tm_getdir)();
4322654012fSReza Sabdar 	int (*tm_getvol)();	/* Reserved */
4332654012fSReza Sabdar } tm_ops_t;
4342654012fSReza Sabdar 
4352654012fSReza Sabdar /* The checksum field is filled with this while the checksum is computed. */
4362654012fSReza Sabdar #define	CHKBLANKS	"        "	/* 8 blanks, no null */
4372654012fSReza Sabdar 
4382654012fSReza Sabdar #define	LONGNAME_PREFIX	"././_LoNg_NaMe_"
4392654012fSReza Sabdar extern void ndmp_log(ulong_t, char *, char *, ...);
4402654012fSReza Sabdar char ndmp_log_info[256];
4412654012fSReza Sabdar #define	NDMP_LOG(p, ...) { \
4422654012fSReza Sabdar 				(void) snprintf(ndmp_log_info, \
4432654012fSReza Sabdar 				    sizeof (ndmp_log_info), \
4442654012fSReza Sabdar 				    "[%d][%s:%d]", \
4452654012fSReza Sabdar 				    (int)pthread_self(), __func__, __LINE__); \
4462654012fSReza Sabdar 				ndmp_log(p, ndmp_log_info, __VA_ARGS__); \
4472654012fSReza Sabdar 			}
4482654012fSReza Sabdar extern void *ndmp_malloc(size_t size);
4492654012fSReza Sabdar 
4502654012fSReza Sabdar /*
4512654012fSReza Sabdar  * ZFS metadata plug-in module structures
4522654012fSReza Sabdar  */
4532654012fSReza Sabdar #define	ZFS_MAX_PROPS		100
4542654012fSReza Sabdar #define	ZFS_META_MAGIC		"ZFSMETA"
45542ed7838SReza Sabdar #define	ZFS_META_MAGIC_EXT	"ZFSMETA2"
4562654012fSReza Sabdar 
45742ed7838SReza Sabdar /* Add new major/minor for header changes */
45842ed7838SReza Sabdar typedef enum {
45942ed7838SReza Sabdar 	META_HDR_MAJOR_0,	/* Original format */
46042ed7838SReza Sabdar 	META_HDR_MAJOR_1,	/* Extended format */
46142ed7838SReza Sabdar } ndmp_metadata_header_major_t;
46242ed7838SReza Sabdar 
46342ed7838SReza Sabdar #define	META_HDR_MAJOR_VERSION	META_HDR_MAJOR_1
46442ed7838SReza Sabdar 
46542ed7838SReza Sabdar typedef enum {
46642ed7838SReza Sabdar 	META_HDR_MINOR_0,
46742ed7838SReza Sabdar } ndmp_metadata_header_minor_t;
46842ed7838SReza Sabdar 
46942ed7838SReza Sabdar #define	META_HDR_MINOR_VERSION	META_HDR_MINOR_0
47042ed7838SReza Sabdar 
47142ed7838SReza Sabdar /* To support older backups */
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 
47842ed7838SReza Sabdar typedef struct ndmp_metadata_property_ext {
479*a1988827SMatthew Ahrens 	char mp_name[ZFS_MAX_DATASET_NAME_LEN];
48042ed7838SReza Sabdar 	char mp_value[ZFS_MAXPROPLEN];
48142ed7838SReza Sabdar 	char mp_source[ZFS_MAXPROPLEN];
48242ed7838SReza Sabdar } ndmp_metadata_property_ext_t;
48342ed7838SReza Sabdar 
48442ed7838SReza Sabdar typedef struct ndmp_metadata_top_header {
48542ed7838SReza Sabdar 	char th_plname[100];
48642ed7838SReza Sabdar 	uint_t th_plversion;
48742ed7838SReza Sabdar 	char th_magic[10];
48842ed7838SReza Sabdar 	void *th_reserved_1;
48942ed7838SReza Sabdar 	int th_count;
49042ed7838SReza Sabdar } ndmp_metadata_top_header_t;
49142ed7838SReza Sabdar 
49242ed7838SReza Sabdar /* Original metadata format */
4932654012fSReza Sabdar typedef struct ndmp_metadata_header {
49442ed7838SReza Sabdar 	ndmp_metadata_top_header_t nh_hdr;
4952654012fSReza Sabdar 	char nh_dataset[NAME_MAX];
4962654012fSReza Sabdar 	ndmp_metadata_property_t nh_property[1];
4972654012fSReza Sabdar } ndmp_metadata_header_t;
4982654012fSReza Sabdar 
49942ed7838SReza Sabdar /* Extended metadata format */
50042ed7838SReza Sabdar typedef struct ndmp_metadata_header_ext {
50142ed7838SReza Sabdar 	ndmp_metadata_top_header_t nh_hdr;
502*a1988827SMatthew Ahrens 	char nh_dataset[ZFS_MAX_DATASET_NAME_LEN];
50342ed7838SReza Sabdar 	int32_t nh_total_bytes;
50442ed7838SReza Sabdar 	int32_t nh_major;
50542ed7838SReza Sabdar 	int32_t nh_minor;
50642ed7838SReza Sabdar 	ndmp_metadata_property_ext_t nh_property[1];
50742ed7838SReza Sabdar } ndmp_metadata_header_ext_t;
50842ed7838SReza Sabdar 
50942ed7838SReza Sabdar #define	nh_plname	nh_hdr.th_plname
51042ed7838SReza Sabdar #define	nh_plversion	nh_hdr.th_plversion
51142ed7838SReza Sabdar #define	nh_magic	nh_hdr.th_magic
51242ed7838SReza Sabdar #define	nh_count	nh_hdr.th_count
51342ed7838SReza Sabdar 
51442ed7838SReza Sabdar typedef struct ndmp_metadata_handle {
51542ed7838SReza Sabdar 	void *ml_handle;
51642ed7838SReza Sabdar 	int32_t ml_quota_prop;
51742ed7838SReza Sabdar 	union {
51842ed7838SReza Sabdar 		ndmp_metadata_header_t *u_hdr;
51942ed7838SReza Sabdar 		ndmp_metadata_header_ext_t *u_xhdr;
52042ed7838SReza Sabdar 	} ml_hdr_u;
52142ed7838SReza Sabdar } ndmp_metadata_handle_t;
52242ed7838SReza Sabdar 
52342ed7838SReza Sabdar #define	ml_hdr	ml_hdr_u.u_hdr
52442ed7838SReza Sabdar #define	ml_xhdr	ml_hdr_u.u_xhdr
52542ed7838SReza Sabdar 
5262654012fSReza Sabdar /*
5272654012fSReza Sabdar  * Node in struct hardlink_q
5282654012fSReza Sabdar  *
5292654012fSReza Sabdar  * inode: the inode of the hardlink
5302654012fSReza Sabdar  * path: the name of the hardlink, used during restore
5312654012fSReza Sabdar  * offset: tape offset of the data records for the hardlink, used during backup
5322654012fSReza Sabdar  * is_tmp: indicate whether the file was created temporarily for restoring
5332654012fSReza Sabdar  * other links during a non-DAR partial restore
5342654012fSReza Sabdar  */
5352654012fSReza Sabdar struct hardlink_node {
5362654012fSReza Sabdar 	unsigned long inode;
5372654012fSReza Sabdar 	char *path;
5382654012fSReza Sabdar 	unsigned long long offset;
5392654012fSReza Sabdar 	int is_tmp;
5402654012fSReza Sabdar 	SLIST_ENTRY(hardlink_node) next_hardlink;
5412654012fSReza Sabdar };
5422654012fSReza Sabdar 
5432654012fSReza Sabdar /*
5442654012fSReza Sabdar  * Hardlinks that have been backed up or restored.
5452654012fSReza Sabdar  *
5462654012fSReza Sabdar  * During backup, each node represents a file whose
5472654012fSReza Sabdar  *   (1) inode has multiple links
5482654012fSReza Sabdar  *   (2) data has been backed up
5492654012fSReza Sabdar  *
5502654012fSReza Sabdar  * When we run into a file with multiple links during backup,
5512654012fSReza Sabdar  * we first check the list to see whether a file with the same inode
5522654012fSReza Sabdar  * has been backed up.  If yes, we backup an empty record, while
5532654012fSReza Sabdar  * making the file history of this file contain the data offset
5542654012fSReza Sabdar  * of the offset of the file that has been backed up.  If no,
5552654012fSReza Sabdar  * we backup this file, and add an entry to the list.
5562654012fSReza Sabdar  *
5572654012fSReza Sabdar  * During restore, each node represents an LF_LINK type record whose
5582654012fSReza Sabdar  * data has been restored (v.s. a hard link has been created).
5592654012fSReza Sabdar  *
5602654012fSReza Sabdar  * During restore, when we run into a record of LF_LINK type, we
5612654012fSReza Sabdar  * first check the queue to see whether a file with the same inode
5622654012fSReza Sabdar  * has been restored.  If yes, we create a hardlink to it.
5632654012fSReza Sabdar  * If no, we restore the data, and add an entry to the list.
5642654012fSReza Sabdar  */
5652654012fSReza Sabdar struct hardlink_q {
5662654012fSReza Sabdar 	struct hardlink_node *slh_first;
5672654012fSReza Sabdar };
5682654012fSReza Sabdar 
5692654012fSReza Sabdar /* Utility functions from handling hardlink */
5702654012fSReza Sabdar extern struct hardlink_q *hardlink_q_init();
5712654012fSReza Sabdar extern void hardlink_q_cleanup(struct hardlink_q *qhead);
5722654012fSReza Sabdar extern int hardlink_q_get(struct hardlink_q *qhead, unsigned long inode,
5732654012fSReza Sabdar     unsigned long long *offset, char **path);
5742654012fSReza Sabdar extern int hardlink_q_add(struct hardlink_q *qhead, unsigned long inode,
5752654012fSReza Sabdar     unsigned long long offset, char *path, int is_tmp);
5762654012fSReza Sabdar 
5772654012fSReza Sabdar #endif	/* !_TLM_H_ */
578