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 /* 223d7072f8Seschrock * Copyright 2007 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 #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <sys/types.h> 337c478bd9Sstevel@tonic-gate #include <sys/time.h> 347c478bd9Sstevel@tonic-gate #include <sys/taskq.h> 357c478bd9Sstevel@tonic-gate #include <sys/vtoc.h> 367c478bd9Sstevel@tonic-gate #include <sys/dkio.h> 377c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #ifdef __cplusplus 407c478bd9Sstevel@tonic-gate extern "C" { 417c478bd9Sstevel@tonic-gate #endif 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* 447c478bd9Sstevel@tonic-gate * /dev names: 457c478bd9Sstevel@tonic-gate * /dev/lofictl - master control device 467c478bd9Sstevel@tonic-gate * /dev/lofi - block devices, named by minor number 477c478bd9Sstevel@tonic-gate * /dev/rlofi - character devices, named by minor number 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate #define LOFI_DRIVER_NAME "lofi" 507c478bd9Sstevel@tonic-gate #define LOFI_CTL_NODE "ctl" 517c478bd9Sstevel@tonic-gate #define LOFI_CTL_NAME LOFI_DRIVER_NAME LOFI_CTL_NODE 527c478bd9Sstevel@tonic-gate #define LOFI_BLOCK_NAME LOFI_DRIVER_NAME 537c478bd9Sstevel@tonic-gate #define LOFI_CHAR_NAME "r" LOFI_DRIVER_NAME 547c478bd9Sstevel@tonic-gate 55*87117650Saalok #define SEGHDR 1 56*87117650Saalok #define COMPRESSED 1 57*87117650Saalok #define UNCOMPRESSED 0 58*87117650Saalok #define MAXALGLEN 36 59*87117650Saalok 607c478bd9Sstevel@tonic-gate /* 617c478bd9Sstevel@tonic-gate * 627c478bd9Sstevel@tonic-gate * Use is: 637c478bd9Sstevel@tonic-gate * ld = open("/dev/lofictl", O_RDWR | O_EXCL); 647c478bd9Sstevel@tonic-gate * 657c478bd9Sstevel@tonic-gate * lofi must be opened exclusively. Access is controlled by permissions on 667c478bd9Sstevel@tonic-gate * the device, which is 644 by default. Write-access is required for ioctls 677c478bd9Sstevel@tonic-gate * that change state, but only read-access is required for the ioctls that 687c478bd9Sstevel@tonic-gate * return information. Basically, only root can add and remove files, but 697c478bd9Sstevel@tonic-gate * non-root can look at the current lists. 707c478bd9Sstevel@tonic-gate * 717c478bd9Sstevel@tonic-gate * ioctl usage: 727c478bd9Sstevel@tonic-gate * 737c478bd9Sstevel@tonic-gate * kernel ioctls 747c478bd9Sstevel@tonic-gate * 757c478bd9Sstevel@tonic-gate * strcpy(li.li_filename, "somefilename"); 767c478bd9Sstevel@tonic-gate * ioctl(ld, LOFI_MAP_FILE, &li); 777c478bd9Sstevel@tonic-gate * newminor = li.li_minor; 787c478bd9Sstevel@tonic-gate * 797c478bd9Sstevel@tonic-gate * strcpy(li.li_filename, "somefilename"); 807c478bd9Sstevel@tonic-gate * ioctl(ld, LOFI_UNMAP_FILE, &li); 817c478bd9Sstevel@tonic-gate * 827c478bd9Sstevel@tonic-gate * strcpy(li.li_filename, "somefilename"); 837c478bd9Sstevel@tonic-gate * li.li_minor = minor_number; 847c478bd9Sstevel@tonic-gate * ioctl(ld, LOFI_MAP_FILE_MINOR, &li); 857c478bd9Sstevel@tonic-gate * 867c478bd9Sstevel@tonic-gate * li.li_minor = minor_number; 877c478bd9Sstevel@tonic-gate * ioctl(ld, LOFI_UNMAP_FILE_MINOR, &li); 887c478bd9Sstevel@tonic-gate * 897c478bd9Sstevel@tonic-gate * li.li_minor = minor_number; 907c478bd9Sstevel@tonic-gate * ioctl(ld, LOFI_GET_FILENAME, &li); 917c478bd9Sstevel@tonic-gate * 927c478bd9Sstevel@tonic-gate * strcpy(li.li_filename, "somefilename"); 937c478bd9Sstevel@tonic-gate * ioctl(ld, LOFI_GET_MINOR, &li); 947c478bd9Sstevel@tonic-gate * 957c478bd9Sstevel@tonic-gate * li.li_minor = 0; 967c478bd9Sstevel@tonic-gate * ioctl(ld, LOFI_GET_MAXMINOR, &li); 977c478bd9Sstevel@tonic-gate * maxminor = li.li_minor; 987c478bd9Sstevel@tonic-gate * 99*87117650Saalok * strcpy(li.li_filename, "somefilename"); 100*87117650Saalok * li.li_minor = 0; 101*87117650Saalok * ioctl(ld, LOFI_CHECK_COMPRESSED, &li); 102*87117650Saalok * 1033d7072f8Seschrock * If the 'li_force' flag is set for any of the LOFI_UNMAP_* commands, then if 1043d7072f8Seschrock * the device is busy, the underlying vnode will be closed, and any subsequent 1053d7072f8Seschrock * operations will fail. It will behave as if the device had been forcibly 1063d7072f8Seschrock * removed, so the DKIOCSTATE ioctl will return DKIO_DEV_GONE. When the device 1073d7072f8Seschrock * is last closed, it will be torn down. 1083d7072f8Seschrock * 1097c478bd9Sstevel@tonic-gate * Oh, and last but not least: these ioctls are totally private and only 1107c478bd9Sstevel@tonic-gate * for use by lofiadm(1M). 1117c478bd9Sstevel@tonic-gate * 1127c478bd9Sstevel@tonic-gate */ 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate struct lofi_ioctl { 1157c478bd9Sstevel@tonic-gate uint32_t li_minor; 1163d7072f8Seschrock boolean_t li_force; 1177c478bd9Sstevel@tonic-gate char li_filename[MAXPATHLEN + 1]; 118*87117650Saalok char li_algorithm[MAXALGLEN]; 1197c478bd9Sstevel@tonic-gate }; 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate #define LOFI_IOC_BASE (('L' << 16) | ('F' << 8)) 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate #define LOFI_MAP_FILE (LOFI_IOC_BASE | 0x01) 1247c478bd9Sstevel@tonic-gate #define LOFI_MAP_FILE_MINOR (LOFI_IOC_BASE | 0x02) 1257c478bd9Sstevel@tonic-gate #define LOFI_UNMAP_FILE (LOFI_IOC_BASE | 0x03) 1267c478bd9Sstevel@tonic-gate #define LOFI_UNMAP_FILE_MINOR (LOFI_IOC_BASE | 0x04) 1277c478bd9Sstevel@tonic-gate #define LOFI_GET_FILENAME (LOFI_IOC_BASE | 0x05) 1287c478bd9Sstevel@tonic-gate #define LOFI_GET_MINOR (LOFI_IOC_BASE | 0x06) 1297c478bd9Sstevel@tonic-gate #define LOFI_GET_MAXMINOR (LOFI_IOC_BASE | 0x07) 130*87117650Saalok #define LOFI_CHECK_COMPRESSED (LOFI_IOC_BASE | 0x08) 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate /* 1337c478bd9Sstevel@tonic-gate * file types that might be usable with lofi, maybe. Only regular 1347c478bd9Sstevel@tonic-gate * files are documented though. 1357c478bd9Sstevel@tonic-gate */ 1367c478bd9Sstevel@tonic-gate #define S_ISLOFIABLE(mode) \ 1377c478bd9Sstevel@tonic-gate (S_ISREG(mode) || S_ISBLK(mode) || S_ISCHR(mode)) 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate #if defined(_KERNEL) 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate /* 1427c478bd9Sstevel@tonic-gate * We limit the maximum number of active lofi devices to 128, which seems very 1437c478bd9Sstevel@tonic-gate * large. You can tune this by changing lofi_max_files in /etc/system. 1447c478bd9Sstevel@tonic-gate * If you change it dynamically, which you probably shouldn't do, make sure 1457c478bd9Sstevel@tonic-gate * to only _increase_ it. 1467c478bd9Sstevel@tonic-gate */ 1477c478bd9Sstevel@tonic-gate #define LOFI_MAX_FILES 128 1487c478bd9Sstevel@tonic-gate extern uint32_t lofi_max_files; 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate #define V_ISLOFIABLE(vtype) \ 1517c478bd9Sstevel@tonic-gate ((vtype == VREG) || (vtype == VBLK) || (vtype == VCHR)) 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate struct lofi_state { 1547c478bd9Sstevel@tonic-gate char *ls_filename; /* filename to open */ 1557c478bd9Sstevel@tonic-gate size_t ls_filename_sz; 1567c478bd9Sstevel@tonic-gate struct vnode *ls_vp; /* open vnode */ 1573d7072f8Seschrock kmutex_t ls_vp_lock; /* protects ls_vp */ 1583d7072f8Seschrock kcondvar_t ls_vp_cv; /* signal changes to ls_vp */ 1593d7072f8Seschrock uint32_t ls_vp_iocount; /* # pending I/O requests */ 1603d7072f8Seschrock boolean_t ls_vp_closereq; /* force close requested */ 1617c478bd9Sstevel@tonic-gate u_offset_t ls_vp_size; 1627c478bd9Sstevel@tonic-gate uint32_t ls_blk_open; 1637c478bd9Sstevel@tonic-gate uint32_t ls_chr_open; 1647c478bd9Sstevel@tonic-gate uint32_t ls_lyr_open_count; 1657c478bd9Sstevel@tonic-gate int ls_openflag; 1667c478bd9Sstevel@tonic-gate taskq_t *ls_taskq; 1677c478bd9Sstevel@tonic-gate kstat_t *ls_kstat; 1687c478bd9Sstevel@tonic-gate kmutex_t ls_kstat_lock; 1697c478bd9Sstevel@tonic-gate struct dk_geom ls_dkg; 1707c478bd9Sstevel@tonic-gate struct vtoc ls_vtoc; 1717c478bd9Sstevel@tonic-gate struct dk_cinfo ls_ci; 172*87117650Saalok 173*87117650Saalok /* the following fields are required for compression support */ 174*87117650Saalok int ls_comp_algorithm_index; /* idx into compress_table */ 175*87117650Saalok char ls_comp_algorithm[MAXALGLEN]; 176*87117650Saalok uint32_t ls_uncomp_seg_sz; /* sz of uncompressed segment */ 177*87117650Saalok uint32_t ls_comp_index_sz; /* number of index entries */ 178*87117650Saalok uint32_t ls_comp_seg_shift; /* exponent for byte shift */ 179*87117650Saalok uint32_t ls_uncomp_last_seg_sz; /* sz of last uncomp segment */ 180*87117650Saalok uint64_t ls_comp_offbase; /* offset of actual compressed data */ 181*87117650Saalok uint64_t *ls_comp_seg_index; /* array of index entries */ 182*87117650Saalok caddr_t ls_comp_index_data; /* index pages loaded from file */ 183*87117650Saalok uint32_t ls_comp_index_data_sz; 184*87117650Saalok u_offset_t ls_vp_comp_size; /* actual compressed file size */ 1857c478bd9Sstevel@tonic-gate }; 1867c478bd9Sstevel@tonic-gate 187*87117650Saalok #endif /* _KERNEL */ 188*87117650Saalok 189*87117650Saalok /* 190*87117650Saalok * Common signature for all lofi compress functions 191*87117650Saalok */ 192*87117650Saalok typedef int lofi_compress_func_t(void *src, size_t srclen, void *dst, 193*87117650Saalok size_t *destlen, int level); 194*87117650Saalok 195*87117650Saalok /* 196*87117650Saalok * Information about each compression function 197*87117650Saalok */ 198*87117650Saalok typedef struct lofi_compress_info { 199*87117650Saalok lofi_compress_func_t *l_decompress; 200*87117650Saalok lofi_compress_func_t *l_compress; 201*87117650Saalok int l_level; 202*87117650Saalok char *l_name; /* algorithm name */ 203*87117650Saalok } lofi_compress_info_t; 204*87117650Saalok 205*87117650Saalok enum lofi_compress { 206*87117650Saalok LOFI_COMPRESS_GZIP = 0, 207*87117650Saalok LOFI_COMPRESS_GZIP_6 = 1, 208*87117650Saalok LOFI_COMPRESS_GZIP_9 = 2, 209*87117650Saalok LOFI_COMPRESS_FUNCTIONS 210*87117650Saalok }; 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate #endif 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate #endif /* _SYS_LOFI_H */ 217