// // $Header: D:/ext2-os2/RCS/log.c,v 1.6 1995/08/16 17:37:40 Willm Exp Willm $ // // Linux ext2 file system driver for OS/2 2.x and WARP - Allows OS/2 to // access your Linux ext2fs partitions as normal drive letters. // OS/2 implementation : Copyright (C) 1995 Matthieu WILLM // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #define INCL_DOS #define INCL_DOSERRORS #include // From the "Developer Connection Device Driver Kit" version 2.0 #include #ifdef FS_DEBUG #include #include #endif #include #include #include #include // // Buffer used to communicate with ext2-os2.exe // char BufMsg[BUFMSGSIZ]; // Circular buffer UINT16 BufPtr; // Buffer pointer UINT16 BufOpen; // Open flag (ext2-os2.exe present ?) UINT32 BufSem; // Buffer semaphore int fs_err(UINT32 infunction, UINT32 errfunction, int retcode, UINT32 sourcefile, UINT32 sourceline) { int rc; err_record *Tmp; int i; i = sizeof(err_record); if (i + BufPtr < BUFMSGSIZ) { Tmp = (err_record *)&(BufMsg[BufPtr]); Tmp->Type = LOG_FS_ERR; Tmp->infunction = infunction; /* function where error occured */ Tmp->errfunction = errfunction; /* function returning error code */ Tmp->retcode = retcode; /* return code from errfunction */ Tmp->sourcefile = sourcefile; /* file where error occured */ Tmp->sourceline = sourceline; /* line number in sourcefile */ BufPtr += i; } else { Tmp = (err_record *)BufMsg; Tmp->Type = LOG_FS_ERR; Tmp->infunction = infunction; /* function where error occured */ Tmp->errfunction = errfunction; /* function returning error code */ Tmp->retcode = retcode; /* return code from errfunction */ Tmp->sourcefile = sourcefile; /* file where error occured */ Tmp->sourceline = sourceline; /* line number in sourcefile */ BufPtr = i; } /* end if */ // // Clears the log semaphore so that ext2-os2.exe can retrieve data // if ((rc = FSH_SEMCLEAR(&BufSem)) != NO_ERROR) { BufOpen = 0; return rc; } /* end if */ return NO_ERROR; } /***********************************************************************************/ /*** fs_log() ***/ /***********************************************************************************/ int fs_log(char *text) { int rc; // // We copy the text into the circular buffer : // - at the current position if it fits // - at the buffer beginning otherwise // int i = strlen(text) + 1; if (i + BufPtr < BUFMSGSIZ) { strcpy(&(BufMsg[BufPtr]), text); BufPtr += i; } else { strcpy(BufMsg, text); BufPtr = i; } /* end if */ // // Clears the log semaphore so that ext2-os2.exe can retrieve data // if ((rc = FSH_SEMCLEAR(&BufSem)) != NO_ERROR) { BufOpen = 0; return rc; } /* end if */ #if defined (FS_TRACE) || defined (FS_TRACE_LOCKS) FSH_YIELD(); #endif return NO_ERROR; } /*** fs_log() ****/ #if 0 // No more used int fs_logger(UINT16 Type, UINT16 uid, UINT16 pid, UINT16 pdb) { int i; int rc; switch(Type) { case LOG_FS_EXIT : case LOG_GET_ID : /**************************************/ /*** unsigned short Type ***/ /*** unsigned short uid ***/ /*** unsigned short pid ***/ /*** unsigned short pdb ***/ /**************************************/ i = sizeof(log_fs_exit); if (i + BufPtr < BUFMSGSIZ) { log_fs_exit *Tmp = (log_fs_exit *)&(BufMsg[BufPtr]); Tmp->Type = Type; Tmp->uid = uid; Tmp->pid = pid; Tmp->pdb = pdb; BufPtr += i; } else { log_fs_exit *Tmp = (log_fs_exit *)BufMsg; Tmp->Type = Type; Tmp->uid = uid; Tmp->pid = pid; Tmp->pdb = pdb; BufPtr = i; } /* end if */ break; case LOG_L_malloc : case LOG_L_free : /*************************************/ /*** unsigned short Type ***/ /*** unsigned short uid ***/ /*** unsigned short seg ***/ /*** unsigned short ofs ***/ /**************************************/ i = sizeof(log_fs_exit); if (i + BufPtr < BUFMSGSIZ) { log_fs_exit *Tmp = (log_fs_exit *)&(BufMsg[BufPtr]); Tmp->Type = Type; Tmp->uid = uid; Tmp->pid = pid; Tmp->pdb = pdb; BufPtr += i; } else { log_fs_exit *Tmp = (log_fs_exit *)BufMsg; Tmp->Type = Type; Tmp->uid = uid; Tmp->pid = pid; Tmp->pdb = pdb; BufPtr = i; } /* end if */ break; default : break; } /* end switch */ /******************************************************/ /*** Baisse du s‚maphore du log ***/ /******************************************************/ if ((rc = FSH_SEMCLEAR(&BufSem)) != NO_ERROR) { BufOpen = 0; return rc; } /* end if */ /******************************************************/ return NO_ERROR; } void log_id(void) { int rc; id_t myid; if ((rc = FSH_QSYSINFO(2, (pchar)&myid, sizeof(id_t))) != NO_ERROR) { fs_log("log_id() erreur FSH_QSYSINFO()"); return; } fs_logger(LOG_GET_ID, myid.uid, myid.pid, myid.pdb); } #endif #ifdef FS_DEBUG int kernel_printf(const char *fmt, ...) { va_list arg; char Buf[256]; pchar buf=Buf; unsigned short absolute_tid; FSH_QSYSINFO(3, (pchar)&absolute_tid, sizeof(unsigned short)); sprintf(Buf, "[ %04X ] ", absolute_tid); buf += strlen(Buf); va_start(arg, fmt); vsprintf(buf, fmt, arg); va_end(arg); return fs_log(Buf); } #endif