00001 /* -*- mode:C++; c-basic-offset:4 -*- 00002 Shore-MT -- Multi-threaded port of the SHORE storage manager 00003 00004 Copyright (c) 2007-2009 00005 Data Intensive Applications and Systems Labaratory (DIAS) 00006 Ecole Polytechnique Federale de Lausanne 00007 00008 All Rights Reserved. 00009 00010 Permission to use, copy, modify and distribute this software and 00011 its documentation is hereby granted, provided that both the 00012 copyright notice and this permission notice appear in all copies of 00013 the software, derivative works or modified versions, and any 00014 portions thereof, and that both notices appear in supporting 00015 documentation. 00016 00017 This code is distributed in the hope that it will be useful, but 00018 WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS 00020 DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER 00021 RESULTING FROM THE USE OF THIS SOFTWARE. 00022 */ 00023 00024 /*<std-header orig-src='shore'> 00025 00026 $Id: sdisk.cpp,v 1.11 2010/10/27 17:04:30 nhall Exp $ 00027 00028 SHORE -- Scalable Heterogeneous Object REpository 00029 00030 Copyright (c) 1994-99 Computer Sciences Department, University of 00031 Wisconsin -- Madison 00032 All Rights Reserved. 00033 00034 Permission to use, copy, modify and distribute this software and its 00035 documentation is hereby granted, provided that both the copyright 00036 notice and this permission notice appear in all copies of the 00037 software, derivative works or modified versions, and any portions 00038 thereof, and that both notices appear in supporting documentation. 00039 00040 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY 00041 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS 00042 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND 00043 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 00044 00045 This software was developed with support by the Advanced Research 00046 Project Agency, ARPA order number 018 (formerly 8230), monitored by 00047 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518. 00048 Further funding for this work was provided by DARPA through 00049 Rome Research Laboratory Contract No. F30602-97-2-0247. 00050 00051 */ 00052 00053 #include "w_defines.h" 00054 00055 /* -- do not edit anything above this line -- </std-header>*/ 00056 00057 /**\cond skip */ 00058 00059 /* 00060 * NewThreads I/O is Copyright 1995, 1996, 1997, 1998 by: 00061 * 00062 * Josef Burger <bolo@cs.wisc.edu> 00063 * 00064 * All Rights Reserved. 00065 * 00066 * NewThreads I/O may be freely used as long as credit is given 00067 * to the above author(s) and the above copyright is maintained. 00068 */ 00069 00070 #include <w.h> 00071 #include <sdisk.h> 00072 00073 #include <sthread.h> /* XXX for error codes */ 00074 00075 00076 00077 int sdisk_base_t::vsize(const iovec_t *iov, int iovcnt) 00078 { 00079 int total = 0; 00080 00081 for (int i = 0; i < iovcnt; i++) 00082 total += iov[i].iov_len; 00083 00084 return total; 00085 } 00086 00087 00088 int sdisk_t::modeBits(int mode) 00089 { 00090 return mode & MODE_FLAGS; 00091 } 00092 00093 00094 /* open mode is a 1-of-n choice */ 00095 bool sdisk_t::hasMode(int mode, int wanted) 00096 { 00097 mode = modeBits(mode); 00098 return mode == wanted; 00099 } 00100 00101 /* options are one-of-many; true if all wanted are found */ 00102 bool sdisk_t::hasOption(int mode, int wanted) 00103 { 00104 mode &= OPTION_FLAGS; 00105 return (mode & wanted) == wanted; 00106 } 00107 00108 00109 /* Emulate vector I/O operations on thos boxes which don't 00110 support it. Either an error or a short transfer will 00111 abort the I/O and return the transfer count. */ 00112 00113 w_rc_t sdisk_t::readv(const iovec_t *iov, int iovcnt, int &transfered) 00114 { 00115 int done = 0; 00116 int n; 00117 int i; 00118 w_rc_t e; 00119 00120 (void) vsize(iov, iovcnt); 00121 00122 for (i = 0; i < iovcnt; i++) { 00123 e = read(iov[i].iov_base, iov[i].iov_len, n); 00124 if (e.is_error()) 00125 break; 00126 done += n; 00127 if (size_t(n) != iov[i].iov_len) 00128 break; 00129 } 00130 00131 transfered = done; 00132 00133 return e; 00134 } 00135 00136 00137 w_rc_t sdisk_t::writev(const iovec_t *iov, int iovcnt, int &transfered) 00138 { 00139 int done = 0; 00140 int n; 00141 int i; 00142 w_rc_t e; 00143 00144 (void) vsize(iov, iovcnt); 00145 00146 for (i = 0; i < iovcnt; i++) { 00147 e = write(iov[i].iov_base, iov[i].iov_len, n); 00148 if (e.is_error()) 00149 break; 00150 done += n; 00151 if (size_t(n) != iov[i].iov_len) 00152 break; 00153 } 00154 00155 transfered = done; 00156 00157 return e; 00158 } 00159 00160 /* Emulate positioned I/O operations on thos boxes which don't 00161 support it. It isn't "race safe", that is a difficult problem 00162 to deal with. Pread/Pwrite don't move the file pointer, but 00163 that is difficult to do if the OS doens't support them. We 00164 seek to where the I/O is supposed to be, execute it, and 00165 then restore the old position. */ 00166 00167 w_rc_t sdisk_t::pread(void *, int , fileoff_t , int &) 00168 { 00169 // make it safe or don't do it at all. 00170 return RC(fcNOTIMPLEMENTED); 00171 } 00172 00173 w_rc_t sdisk_t::pwrite(const void *, int , fileoff_t , 00174 int &) 00175 { 00176 // make it safe or don't do it at all. 00177 return RC(fcNOTIMPLEMENTED); 00178 } 00179 00180 00181 /* a no-op file-sync if the underlying implementation doesn't support it. */ 00182 w_rc_t sdisk_t::sync() 00183 { 00184 return RCOK; 00185 } 00186 00187 00188 w_rc_t sdisk_t::stat(filestat_t &) 00189 { 00190 return RC(fcNOTIMPLEMENTED); 00191 } 00192 /**\endcond skip */