17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 53d7072f8Seschrock * Common Development and Distribution License (the "License"). 63d7072f8Seschrock * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 2293239addSjohnlev * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _SYS_LOFI_H 287c478bd9Sstevel@tonic-gate #define _SYS_LOFI_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #include <sys/types.h> 317c478bd9Sstevel@tonic-gate #include <sys/time.h> 327c478bd9Sstevel@tonic-gate #include <sys/taskq.h> 337c478bd9Sstevel@tonic-gate #include <sys/vtoc.h> 347c478bd9Sstevel@tonic-gate #include <sys/dkio.h> 357c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #ifdef __cplusplus 387c478bd9Sstevel@tonic-gate extern "C" { 397c478bd9Sstevel@tonic-gate #endif 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate /* 427c478bd9Sstevel@tonic-gate * /dev names: 437c478bd9Sstevel@tonic-gate * /dev/lofictl - master control device 447c478bd9Sstevel@tonic-gate * /dev/lofi - block devices, named by minor number 457c478bd9Sstevel@tonic-gate * /dev/rlofi - character devices, named by minor number 467c478bd9Sstevel@tonic-gate */ 477c478bd9Sstevel@tonic-gate #define LOFI_DRIVER_NAME "lofi" 487c478bd9Sstevel@tonic-gate #define LOFI_CTL_NODE "ctl" 497c478bd9Sstevel@tonic-gate #define LOFI_CTL_NAME LOFI_DRIVER_NAME LOFI_CTL_NODE 507c478bd9Sstevel@tonic-gate #define LOFI_BLOCK_NAME LOFI_DRIVER_NAME 517c478bd9Sstevel@tonic-gate #define LOFI_CHAR_NAME "r" LOFI_DRIVER_NAME 527c478bd9Sstevel@tonic-gate 5387117650Saalok #define SEGHDR 1 5487117650Saalok #define COMPRESSED 1 5587117650Saalok #define UNCOMPRESSED 0 5687117650Saalok #define MAXALGLEN 36 5787117650Saalok 587c478bd9Sstevel@tonic-gate /* 597c478bd9Sstevel@tonic-gate * 607c478bd9Sstevel@tonic-gate * Use is: 617c478bd9Sstevel@tonic-gate * ld = open("/dev/lofictl", O_RDWR | O_EXCL); 627c478bd9Sstevel@tonic-gate * 637c478bd9Sstevel@tonic-gate * lofi must be opened exclusively. Access is controlled by permissions on 647c478bd9Sstevel@tonic-gate * the device, which is 644 by default. Write-access is required for ioctls 657c478bd9Sstevel@tonic-gate * that change state, but only read-access is required for the ioctls that 667c478bd9Sstevel@tonic-gate * return information. Basically, only root can add and remove files, but 677c478bd9Sstevel@tonic-gate * non-root can look at the current lists. 687c478bd9Sstevel@tonic-gate * 697c478bd9Sstevel@tonic-gate * ioctl usage: 707c478bd9Sstevel@tonic-gate * 717c478bd9Sstevel@tonic-gate * kernel ioctls 727c478bd9Sstevel@tonic-gate * 737c478bd9Sstevel@tonic-gate * strcpy(li.li_filename, "somefilename"); 747c478bd9Sstevel@tonic-gate * ioctl(ld, LOFI_MAP_FILE, &li); 757c478bd9Sstevel@tonic-gate * newminor = li.li_minor; 767c478bd9Sstevel@tonic-gate * 777c478bd9Sstevel@tonic-gate * strcpy(li.li_filename, "somefilename"); 787c478bd9Sstevel@tonic-gate * ioctl(ld, LOFI_UNMAP_FILE, &li); 797c478bd9Sstevel@tonic-gate * 807c478bd9Sstevel@tonic-gate * strcpy(li.li_filename, "somefilename"); 817c478bd9Sstevel@tonic-gate * li.li_minor = minor_number; 827c478bd9Sstevel@tonic-gate * ioctl(ld, LOFI_MAP_FILE_MINOR, &li); 837c478bd9Sstevel@tonic-gate * 847c478bd9Sstevel@tonic-gate * li.li_minor = minor_number; 857c478bd9Sstevel@tonic-gate * ioctl(ld, LOFI_UNMAP_FILE_MINOR, &li); 867c478bd9Sstevel@tonic-gate * 877c478bd9Sstevel@tonic-gate * li.li_minor = minor_number; 887c478bd9Sstevel@tonic-gate * ioctl(ld, LOFI_GET_FILENAME, &li); 897c478bd9Sstevel@tonic-gate * 907c478bd9Sstevel@tonic-gate * strcpy(li.li_filename, "somefilename"); 917c478bd9Sstevel@tonic-gate * ioctl(ld, LOFI_GET_MINOR, &li); 927c478bd9Sstevel@tonic-gate * 937c478bd9Sstevel@tonic-gate * li.li_minor = 0; 947c478bd9Sstevel@tonic-gate * ioctl(ld, LOFI_GET_MAXMINOR, &li); 957c478bd9Sstevel@tonic-gate * maxminor = li.li_minor; 967c478bd9Sstevel@tonic-gate * 9787117650Saalok * strcpy(li.li_filename, "somefilename"); 9887117650Saalok * li.li_minor = 0; 9987117650Saalok * ioctl(ld, LOFI_CHECK_COMPRESSED, &li); 10087117650Saalok * 1013d7072f8Seschrock * If the 'li_force' flag is set for any of the LOFI_UNMAP_* commands, then if 1023d7072f8Seschrock * the device is busy, the underlying vnode will be closed, and any subsequent 1033d7072f8Seschrock * operations will fail. It will behave as if the device had been forcibly 1043d7072f8Seschrock * removed, so the DKIOCSTATE ioctl will return DKIO_DEV_GONE. When the device 1053d7072f8Seschrock * is last closed, it will be torn down. 1063d7072f8Seschrock * 10793239addSjohnlev * If the 'li_cleanup' flag is set for any of the LOFI_UNMAP_* commands, then 10893239addSjohnlev * if the device is busy, it is marked for removal at the next time it is 10993239addSjohnlev * no longer held open by anybody. When the device is last closed, it will be 11093239addSjohnlev * torn down. 11193239addSjohnlev * 1127c478bd9Sstevel@tonic-gate * Oh, and last but not least: these ioctls are totally private and only 1137c478bd9Sstevel@tonic-gate * for use by lofiadm(1M). 1147c478bd9Sstevel@tonic-gate * 1157c478bd9Sstevel@tonic-gate */ 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate struct lofi_ioctl { 1187c478bd9Sstevel@tonic-gate uint32_t li_minor; 1193d7072f8Seschrock boolean_t li_force; 12093239addSjohnlev boolean_t li_cleanup; 121*6f02aa44SDina K Nimeh char li_filename[MAXPATHLEN]; 12287117650Saalok char li_algorithm[MAXALGLEN]; 1237c478bd9Sstevel@tonic-gate }; 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate #define LOFI_IOC_BASE (('L' << 16) | ('F' << 8)) 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate #define LOFI_MAP_FILE (LOFI_IOC_BASE | 0x01) 1287c478bd9Sstevel@tonic-gate #define LOFI_MAP_FILE_MINOR (LOFI_IOC_BASE | 0x02) 1297c478bd9Sstevel@tonic-gate #define LOFI_UNMAP_FILE (LOFI_IOC_BASE | 0x03) 1307c478bd9Sstevel@tonic-gate #define LOFI_UNMAP_FILE_MINOR (LOFI_IOC_BASE | 0x04) 1317c478bd9Sstevel@tonic-gate #define LOFI_GET_FILENAME (LOFI_IOC_BASE | 0x05) 1327c478bd9Sstevel@tonic-gate #define LOFI_GET_MINOR (LOFI_IOC_BASE | 0x06) 1337c478bd9Sstevel@tonic-gate #define LOFI_GET_MAXMINOR (LOFI_IOC_BASE | 0x07) 13487117650Saalok #define LOFI_CHECK_COMPRESSED (LOFI_IOC_BASE | 0x08) 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* 1377c478bd9Sstevel@tonic-gate * file types that might be usable with lofi, maybe. Only regular 1387c478bd9Sstevel@tonic-gate * files are documented though. 1397c478bd9Sstevel@tonic-gate */ 1407c478bd9Sstevel@tonic-gate #define S_ISLOFIABLE(mode) \ 1417c478bd9Sstevel@tonic-gate (S_ISREG(mode) || S_ISBLK(mode) || S_ISCHR(mode)) 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate #if defined(_KERNEL) 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate /* 1467c478bd9Sstevel@tonic-gate * We limit the maximum number of active lofi devices to 128, which seems very 1477c478bd9Sstevel@tonic-gate * large. You can tune this by changing lofi_max_files in /etc/system. 1487c478bd9Sstevel@tonic-gate * If you change it dynamically, which you probably shouldn't do, make sure 1497c478bd9Sstevel@tonic-gate * to only _increase_ it. 1507c478bd9Sstevel@tonic-gate */ 1517c478bd9Sstevel@tonic-gate #define LOFI_MAX_FILES 128 1527c478bd9Sstevel@tonic-gate extern uint32_t lofi_max_files; 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate #define V_ISLOFIABLE(vtype) \ 1557c478bd9Sstevel@tonic-gate ((vtype == VREG) || (vtype == VBLK) || (vtype == VCHR)) 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate struct lofi_state { 1587c478bd9Sstevel@tonic-gate char *ls_filename; /* filename to open */ 1597c478bd9Sstevel@tonic-gate size_t ls_filename_sz; 1607c478bd9Sstevel@tonic-gate struct vnode *ls_vp; /* open vnode */ 1613d7072f8Seschrock kmutex_t ls_vp_lock; /* protects ls_vp */ 1623d7072f8Seschrock kcondvar_t ls_vp_cv; /* signal changes to ls_vp */ 1633d7072f8Seschrock uint32_t ls_vp_iocount; /* # pending I/O requests */ 1643d7072f8Seschrock boolean_t ls_vp_closereq; /* force close requested */ 1657c478bd9Sstevel@tonic-gate u_offset_t ls_vp_size; 1667c478bd9Sstevel@tonic-gate uint32_t ls_blk_open; 1677c478bd9Sstevel@tonic-gate uint32_t ls_chr_open; 1687c478bd9Sstevel@tonic-gate uint32_t ls_lyr_open_count; 1697c478bd9Sstevel@tonic-gate int ls_openflag; 17093239addSjohnlev boolean_t ls_cleanup; /* cleanup on close */ 1717c478bd9Sstevel@tonic-gate taskq_t *ls_taskq; 1727c478bd9Sstevel@tonic-gate kstat_t *ls_kstat; 1737c478bd9Sstevel@tonic-gate kmutex_t ls_kstat_lock; 1747c478bd9Sstevel@tonic-gate struct dk_geom ls_dkg; 1757c478bd9Sstevel@tonic-gate struct vtoc ls_vtoc; 1767c478bd9Sstevel@tonic-gate struct dk_cinfo ls_ci; 17787117650Saalok 17887117650Saalok /* the following fields are required for compression support */ 17987117650Saalok int ls_comp_algorithm_index; /* idx into compress_table */ 18087117650Saalok char ls_comp_algorithm[MAXALGLEN]; 18187117650Saalok uint32_t ls_uncomp_seg_sz; /* sz of uncompressed segment */ 18287117650Saalok uint32_t ls_comp_index_sz; /* number of index entries */ 18387117650Saalok uint32_t ls_comp_seg_shift; /* exponent for byte shift */ 18487117650Saalok uint32_t ls_uncomp_last_seg_sz; /* sz of last uncomp segment */ 18587117650Saalok uint64_t ls_comp_offbase; /* offset of actual compressed data */ 18687117650Saalok uint64_t *ls_comp_seg_index; /* array of index entries */ 18787117650Saalok caddr_t ls_comp_index_data; /* index pages loaded from file */ 18887117650Saalok uint32_t ls_comp_index_data_sz; 18987117650Saalok u_offset_t ls_vp_comp_size; /* actual compressed file size */ 1907c478bd9Sstevel@tonic-gate }; 1917c478bd9Sstevel@tonic-gate 19287117650Saalok #endif /* _KERNEL */ 19387117650Saalok 19487117650Saalok /* 19587117650Saalok * Common signature for all lofi compress functions 19687117650Saalok */ 19787117650Saalok typedef int lofi_compress_func_t(void *src, size_t srclen, void *dst, 19887117650Saalok size_t *destlen, int level); 19987117650Saalok 20087117650Saalok /* 20187117650Saalok * Information about each compression function 20287117650Saalok */ 20387117650Saalok typedef struct lofi_compress_info { 20487117650Saalok lofi_compress_func_t *l_decompress; 20587117650Saalok lofi_compress_func_t *l_compress; 20687117650Saalok int l_level; 20787117650Saalok char *l_name; /* algorithm name */ 20887117650Saalok } lofi_compress_info_t; 20987117650Saalok 21087117650Saalok enum lofi_compress { 21187117650Saalok LOFI_COMPRESS_GZIP = 0, 21287117650Saalok LOFI_COMPRESS_GZIP_6 = 1, 21387117650Saalok LOFI_COMPRESS_GZIP_9 = 2, 21487117650Saalok LOFI_COMPRESS_FUNCTIONS 21587117650Saalok }; 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2187c478bd9Sstevel@tonic-gate } 2197c478bd9Sstevel@tonic-gate #endif 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate #endif /* _SYS_LOFI_H */ 222