Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
00001 /* 00002 00003 Copyright (C) 2000, 2001, Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2.1 of the GNU Lesser General Public License 00007 as published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU Lesser General Public 00021 License along with this program; if not, write the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 00023 USA. 00024 00025 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00026 Mountain View, CA 94043, or: 00027 00028 http://www.sgi.com 00029 00030 For further information regarding this notice, see: 00031 00032 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00033 00034 */ 00035 00036 00037 00038 #pragma ident "@(#) libf/fio/stats.c 92.1 06/21/99 10:37:55" 00039 00040 /* 00041 * stats.c Fortran I/O statistics support routines. This 00042 * code is common between the CRAY Y-MP and the 00043 * CRAY-2. Any changes to one copy should also be 00044 * made in the other. 00045 */ 00046 #if !defined(_CRAYMPP) && defined(_UNICOS) 00047 #define _STATS_ENABLED 00048 #endif 00049 00050 #ifdef _STATS_ENABLED 00051 extern int _pstatfd; /* file descriptor of stat pipe */ 00052 #endif 00053 00054 #include <errno.h> 00055 #include <stdlib.h> 00056 #include <string.h> 00057 #include <unistd.h> 00058 #include "fio.h" 00059 00060 /* 00061 * _ft_stopen - Initialize unit fields associated with statistics gathering. 00062 * Allocate a close packet. Send Fortran open packet to procstat. 00063 * This should be the last routine called during open processing 00064 * to ensure that an open packet is sent only when an open 00065 * succeeds. 00066 * 00067 * Return value: 0 on normal exit, -1 with errno set on error. 00068 */ 00069 _ft_stopen( 00070 unit *cup, /* unit pointer */ 00071 char *atstr) /* assign attributes associated with the file or unit */ 00072 { 00073 #ifndef _STATS_ENABLED 00074 /* No procstat support for MPP or SPARC yet */ 00075 return(0); /* normal return */ 00076 #else 00077 unum_t unum; 00078 int fd; /* system file descriptor number */ 00079 int pktsiz; 00080 int limit; 00081 int len_name; 00082 int len_attr; 00083 char *cp; 00084 char *file_name; 00085 union stat_ntry *sp; 00086 union stat_ntry open_packet; 00087 00088 if (cup == NULL) 00089 return(0); 00090 00091 fd = cup->usysfd; 00092 00093 if (STDIN_FILENO <= fd && fd <= STDERR_FILENO) 00094 return(0); /* no Fortran stats for standard files for now*/ 00095 00096 file_name = (cup->ufnm != NULL ? cup->ufnm : "(unnamed)"); 00097 00098 /* 00099 * Initialize the open packet. 00100 * 00101 * Notice that pktsiz includes the null terminator for the filename 00102 * since the size of the fname[1] field ensures room for an extra byte. 00103 */ 00104 len_name = strlen(file_name); 00105 len_attr = (atstr == NULL) ? 0 : strlen(atstr); 00106 pktsiz = MIN(MAXPACK, 00107 sizeof(open_packet.fopn_pkt) + 00108 len_name + 1 + len_attr + 1); 00109 open_packet.fopn_pkt.h.pktsiz = pktsiz; 00110 open_packet.fopn_pkt.h.pid = getpid(); 00111 open_packet.fopn_pkt.h.typ = FOPEN_PACK; 00112 open_packet.fopn_pkt.h.tstmp = _rtc(); 00113 open_packet.fopn_pkt.h.rsv0 = 0; 00114 open_packet.fopn_pkt.h.rsv1 = 0; 00115 open_packet.fopn_pkt.h.rsv2 = 0; 00116 open_packet.fopn_pkt.h.rsv3 = 0; 00117 open_packet.fopn_pkt.unitnum = cup->uid; 00118 open_packet.fopn_pkt.iotype = IO_TYPE(cup); 00119 open_packet.fopn_pkt.fstruct = _deduce_fstruct(cup->ufs, 00120 (struct fdinfo*)cup->ufp.fdc,cup->ufmt); 00121 open_packet.fopn_pkt.sys_fd = fd; 00122 open_packet.fopn_pkt.smode = 0; 00123 open_packet.fopn_pkt.recl = cup->urecl; 00124 open_packet.fopn_pkt.rsv1 = 0; 00125 open_packet.fopn_pkt.rsv2 = 0; 00126 open_packet.fopn_pkt.rsv3 = 0; 00127 00128 cp = &open_packet.fopn_pkt.strings[0]; 00129 limit = pktsiz - (cp - (char*)&open_packet); 00130 00131 if (len_name > limit - 1) 00132 len_name = limit - 1; 00133 if (len_name >= 0) { /* truncate name to max length of packet */ 00134 (void)memcpy(cp, file_name, len_name); /* copy file name */ 00135 cp[len_name] = '\0'; 00136 } 00137 00138 cp += len_name + 1; /* skip over name & null terminator */ 00139 limit -= len_name + 1; 00140 00141 if (len_attr > limit - 1) 00142 len_attr = limit - 1; 00143 if (len_attr >= 0) { /* don't copy of no room or no attrs */ 00144 (void)memcpy(cp, atstr, len_attr); /* copy assign attrs */ 00145 cp[len_attr] = '\0'; 00146 } 00147 00148 /* 00149 * Allocate and zero the close packet. 00150 */ 00151 if ((sp = (union stat_ntry *)malloc(sizeof(union stat_ntry))) == NULL) { 00152 errno = FENOMEMY; 00153 return(-1); 00154 } 00155 cup->ftstat = sp; 00156 memset((char*)sp, 0, sizeof(*(cup->ftstat))); 00157 00158 /* 00159 * Now send open packet. The open has succeeded. 00160 */ 00161 (void)write( _pstatfd, 00162 (char*)&open_packet, 00163 open_packet.fopn_pkt.h.pktsiz); 00164 00165 return(0); /* normal return */ 00166 #endif 00167 } 00168 /* 00169 * _ft_stclose - Send a close packet at the end of close processing for 00170 * a particular unit. Then deallocate the close packet. 00171 * 00172 * Return value: 0 on normal exit, -1 with errno set otherwise. 00173 */ 00174 _ft_stclose(unit *cup) 00175 { 00176 #ifndef _STATS_ENABLED 00177 /* No procstat support for MPP or SPARC yet */ 00178 return(0); /* normal return */ 00179 #else 00180 int pktsiz; 00181 char *file_name; 00182 union stat_ntry *sp; 00183 00184 if (cup->ftstat == NULL) 00185 return(0); 00186 00187 file_name = (cup->ufnm != NULL ? cup->ufnm : "(unnamed)"); 00188 00189 /* 00190 * Fill in the close packet. 00191 */ 00192 sp = cup->ftstat; 00193 pktsiz = sizeof(sp->fcls_pkt); 00194 sp->fcls_pkt.h.pktsiz = pktsiz; 00195 sp->fcls_pkt.h.pid = getpid(); 00196 sp->fcls_pkt.h.typ = FCLOSE_PACK; 00197 sp->fcls_pkt.h.tstmp = _rtc(); 00198 sp->fcls_pkt.h.rsv0 = 0; 00199 sp->fcls_pkt.h.rsv1 = 0; 00200 sp->fcls_pkt.h.rsv2 = 0; 00201 sp->fcls_pkt.h.rsv3 = 0; 00202 sp->fcls_pkt.unitnum = cup->uid; 00203 sp->fcls_pkt.iotype = IO_TYPE(cup); 00204 sp->fcls_pkt.sys_fd = cup->usysfd; 00205 sp->fcls_pkt.smode = 0; 00206 sp->fcls_pkt.rsv1 = 0; 00207 sp->fcls_pkt.rsv2 = 0; 00208 sp->fcls_pkt.rsv3 = 0; 00209 sp->fcls_pkt.rsv4 = 0; 00210 sp->fcls_pkt.rsv5 = 0; 00211 sp->fcls_pkt.rsv6 = 0; 00212 sp->fcls_pkt.rsv7 = 0; 00213 00214 /* 00215 * fname gets the first 15 characters of the file name. The 00216 * complete file name can be found in the open packet. 00217 */ 00218 (void) strncpy(&sp->fcls_pkt.fname[0], file_name, 15); 00219 sp->fcls_pkt.fname[15] = '\0'; 00220 00221 /* 00222 * Now send the close packet, and then deallocate it. 00223 */ 00224 (void)write(_pstatfd, (char*)sp, sp->fcls_pkt.h.pktsiz); 00225 free(sp); 00226 cup->ftstat = NULL; 00227 00228 return(0); 00229 #endif 00230 }