sdisk.h

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' incl-file-exclusion='SDISK_H'>
00025 
00026  $Id: sdisk.h,v 1.23 2010/05/26 01:21:28 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 #ifndef SDISK_H
00054 #define SDISK_H
00055 
00056 #include "w_defines.h"
00057 
00058 /*  -- do not edit anything above this line --   </std-header>*/
00059 
00060 
00061 /*
00062  *   NewThreads I/O is Copyright 1995, 1996, 1997, 1998 by:
00063  *
00064  *    Josef Burger    <bolo@cs.wisc.edu>
00065  *
00066  *   All Rights Reserved.
00067  *
00068  *   NewThreads I/O may be freely used as long as credit is given
00069  *   to the above author(s) and the above copyright is maintained.
00070  */
00071 
00072 /**\cond skip */
00073 class sdisk_base_t {
00074 public:
00075 
00076     struct iovec_t {
00077         void    *iov_base;
00078         size_t    iov_len;
00079 
00080         iovec_t(void *base = 0, int len = 0) 
00081             : iov_base(base), iov_len(len) { }
00082     };
00083 
00084     /* Don't use off_t, cause we may want the system off_t */
00085 #if !defined(LARGEFILE_AWARE) && !defined(ARCH_LP64)
00086     /* XXX if !LARGEFILE, should choose on per operating system
00087        to pick the native size. */
00088     typedef w_base_t::int4_t fileoff_t;
00089 #else
00090     typedef w_base_t::int8_t fileoff_t;
00091 #endif
00092 
00093     struct    filestat_t {
00094         fileoff_t    st_size;
00095         fileoff_t    st_file_id;
00096         unsigned    st_device_id;
00097         unsigned    st_block_size;
00098         bool        is_file;
00099         bool        is_dir;
00100         bool        is_device;
00101 
00102         filestat_t() : st_size(0),
00103             st_file_id(0), st_device_id(0), st_block_size(0),
00104             is_file(false), is_dir(false), 
00105             is_device(false)
00106         { }
00107     };
00108 
00109     /* posix-compatabile file modes, namespace contortion */
00110     enum {
00111         /* open modes ... 1 of n */
00112         OPEN_RDONLY=0,
00113         OPEN_WRONLY=0x1,
00114         OPEN_RDWR=0x2,
00115         MODE_FLAGS=0x3,        // internal
00116 
00117         /* open options ... m of n */
00118         OPEN_TRUNC=0x10,
00119         OPEN_EXCL=0x20,
00120         OPEN_CREATE=0x40,
00121         OPEN_SYNC=0x80,
00122         OPEN_APPEND=0x100,
00123         OPEN_RAW=0x200,
00124         OPTION_FLAGS=0x3f0    // internal
00125     };
00126 
00127     /* seek modes; contortions to avoid namespace problems */
00128     enum {
00129         SEEK_AT_SET=0,        // absolute
00130         SEEK_AT_CUR=1,        // from current position
00131         SEEK_AT_END=2        // from end-of-file 
00132     };
00133 
00134     /* utility functions */
00135     static    int    vsize(const iovec_t *iov, int iovcnt);
00136 };
00137 
00138 
00139 /* sdisk is an interface class which isn't useful by itself */ 
00140 
00141 class sdisk_t : public sdisk_base_t {
00142 protected:
00143     sdisk_t() { }
00144 
00145     /* methods for lookint at open flags to extract I/O mode and options */
00146     static    int    modeBits(int mode);
00147     static    bool    hasMode(int mode, int wanted);
00148     static    bool    hasOption(int mode, int wanted);
00149 
00150 public:
00151     virtual    ~sdisk_t() { }
00152 
00153     virtual w_rc_t    open(const char *name, int flags, int mode) = 0;
00154     virtual    w_rc_t    close() = 0;
00155 
00156     virtual    w_rc_t    read(void *buf, int count, int &done) = 0;
00157     virtual    w_rc_t    write(const void *buf, int count, int &done) = 0;
00158 
00159     virtual    w_rc_t    readv(const iovec_t *iov, int ioc, int &done);
00160     virtual w_rc_t    writev(const iovec_t *iov, int ioc, int &done);
00161 
00162     virtual    w_rc_t    pread(void *buf, int count, fileoff_t pos, int &done);
00163     virtual    w_rc_t    pwrite(const void *buf, int count,
00164                    fileoff_t pos, int &done);
00165 
00166     virtual w_rc_t    seek(fileoff_t pos, int origin, fileoff_t &newpos) = 0;
00167 
00168     virtual w_rc_t    truncate(fileoff_t size) = 0;
00169     virtual w_rc_t    sync();
00170 
00171     virtual    w_rc_t    stat(filestat_t &stat);
00172 };
00173 
00174 /**\endcond skip */
00175 
00176 /*<std-footer incl-file-exclusion='SDISK_H'>  -- do not edit anything below this line -- */
00177 
00178 #endif          /*</std-footer>*/

Generated on Wed Jul 7 17:22:32 2010 for Shore Storage Manager by  doxygen 1.4.7