/*
 * rminfo.h - SAM-FS removable media file access definitions.
 *
 * Defines the SAM-FS removable media file access structure and functions.
 *
 */

/*
 *    SAM-QFS_notice_begin
 *
 *      Solaris 2.x Sun Storage & Archiving Management File System
 *
 *		Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
 *
 *		U.S. Government Rights - Commercial software. Government users are
 *	subject to the Sun Microsystems, Inc. standard license agreement and applicable
 *	provisions of the FAR and its supplements.
 *
 *      	Use is subject to license terms. Sun, Sun Microsystems and the Sun logo
 *	are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S.
 *	and other countries.
 *
 *    SAM-QFS_notice_end
 */

/*
 *	LGPL NOTICE
 *
 *	This library is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation; either
 *	version 2.1 of the License, or (at your option) any later version.
 *
 *	This library is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *	Lesser General Public License for more details.
 *
 *	You should have received a copy of the GNU Lesser General Public
 *	License along with this library; if not, write to the Free Software
 *	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

/*
 * $Revision$
 */

#ifdef sun
#pragma ident "$Revision$"
#endif


#ifndef SAM_RMINFO_H
#define	SAM_RMINFO_H


#ifdef	linux
#include <linux/types.h>
#else	/* linux */
#include <sys/types.h>
#endif	/* linux */

#ifndef SAM_STAT_H
#include "pub/stat.h"
#endif /* SAM_STAT_H */

#ifdef  __cplusplus
extern "C" {
#endif

/*
 * Allocate sam_rminfo structure based on the number of vsns.
 */

#define	MAX_VOLUMES 	256			/* Maximum number of overflow vsns */

#define	SAM_RMINFO_SIZE(n) (sizeof (struct sam_rminfo) + ((n) - 1) * sizeof (struct sam_section))

/*
 * Begin: 32-bit align copyin() structs for amd64 only due to 32-bit x86 ABI
 */
#if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
#pragma pack(4)
#endif

#if defined(__sparcv9) || defined(__amd64)

struct sam_rminfo {
	ushort_t	flags;			/* Access flags */
	ushort_t	unused;
	char		media[4];		/* Media type */
	time_t		creation_time;		/* Time file created */
	u_longlong_t 	position;		/* Current position on the media */
	u_longlong_t 	required_size;		/* Required size on a request */
	uint_t		block_size;		/* Media block size */

	/* For optical media */
	char		file_id[32];		/* Recorded file name */
	int		version;		/* Version number */
	char		owner_id[32];		/* Owner identifier */
	char		group_id[32];		/* Group identifier */
	char		info[160];		/* User information */

	/* For all media. */
	short		n_vsns;			/* Number of VSNs available */
	short		c_vsn;			/* Current VSN */
	struct 		sam_section section[1];	/* VSNs information */
};

#else   /* __sparcv9 || __amd64 */

struct sam_rminfo {
	ushort_t 	flags;			/* Access flags */
	ushort_t 	unused;
	char		media[4];		/* Media type */
	ulong_t		pad0;
	time_t		creation_time;		/* Time file created */
	u_longlong_t 	position;		/* Current position on the media */
	u_longlong_t 	required_size;		/* Required size on a request */
	uint_t		block_size;		/* Media block size */

	/* For optical media */
	char		file_id[32];		/* Recorded file name */
	int		version;		/* Version number */
	char		owner_id[32];		/* Owner identifier */
	char		group_id[32];		/* Group identifier */
	char		info[160];		/* User information */

	/* For all media. */
	short		n_vsns;			/* Number of VSNs available */
	short		c_vsn;			/* Current VSN */
	struct 		sam_section section[1];	/* VSNs information */
};

#endif   /* __sparcv9 || __amd64 */

/*
 * End: 32-bit align copyin() structs for amd64 only due to 32-bit x86 ABI
 */
#if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
#pragma pack()
#endif


/*
 * Flags.
 */
#define	RI_blockio 	0x0001			/* Use block I/O for data transfers */
#define	RI_bufio   	0x0002			/* Use buffered block I/O for data transfers */
#define	RI_foreign	0x0004			/* Open Non SAM tape for read only access */
#define	RI_nopos    	0x0008			/* For block I/O, don't position media on mount */

int sam_readrminfo(const char *path, struct sam_rminfo *buf, size_t bufsize);
int sam_request(const char *path, struct sam_rminfo *buf, size_t bufsize);

#ifdef  __cplusplus
}
#endif

#endif  /* SAM_RMINFO_H */
