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: devid_t.cpp,v 1.17 2010/05/26 01:20:11 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 #define DEVID_T_C 00058 00059 #ifdef __GNUC__ 00060 #pragma implementation 00061 #endif 00062 00063 #include <cstdlib> 00064 #include <w_stream.h> 00065 #include <w_base.h> 00066 #include "basics.h" 00067 #include "devid_t.h" 00068 00069 #include <sthread.h> 00070 00071 devid_t::devid_t(const char* path) 00072 : id(0), 00073 dev(0) 00074 { 00075 // generate a device id by stat'ing the path and using the 00076 // inode number 00077 00078 int fd; 00079 w_rc_t e; 00080 #if W_DEBUG_LEVEL > 2 00081 const char *what = "open"; 00082 #endif 00083 00084 e = sthread_t::open(path, sthread_t::OPEN_RDONLY, 0, fd); 00085 if (!e.is_error()) { 00086 sthread_t::filestat_t st; 00087 #if W_DEBUG_LEVEL > 2 00088 what = "fstat"; 00089 #endif 00090 e = sthread_t::fstat(fd, st); 00091 if (!e.is_error()) { 00092 id = st.st_file_id; 00093 dev = st.st_device_id; 00094 } 00095 W_COERCE(sthread_t::close(fd)); 00096 } 00097 /* XXX don't complain if file doesn't exist? IDs should only 00098 be generated in a valid state. */ 00099 if (e.is_error()) { 00100 #if W_DEBUG_LEVEL > 2 00101 cerr << "devid_t::devid_t(" << path 00102 << "): " << what << ":" << endl << e << endl; 00103 #endif 00104 *this = null; 00105 } 00106 } 00107 00108 ostream& operator<<(ostream& o, const devid_t& d) 00109 { 00110 return o << d.dev << "." << d.id; 00111 } 00112 00113 const devid_t devid_t::null; 00114