void CallTraceExportStats(char *FileName)
{
  char                  Output[512];
  char                  AbsFileName[FBLIB_DIR_SIZE];
  int                   f;
  double                t;
  int                   i;

  if(!CallTraceInitialized) CallTraceInit();

  if(CallTraceStats && FileName)
  {
    ConvertPathType(FileName, AbsFileName, PF_FullLinuxPath);
    f = open(AbsFileName, O_WRONLY | O_CREAT | O_TRUNC);
    if(f >= 0)
    {
      strcpy(Output, "Name;NrCalls;MinTime;MaxTime;TotalTime;AvgTime\r\n");
      write(f, Output, strlen(Output));

      for(i = 0; i < CallTraceStatsEntries;i++)
      {
        if(CallTraceStats[i].NrCalls)
          t = (double)(CallTraceStats[i].TotalTime * 10) / CallTraceStats[i].NrCalls;
        else
          t = 0;
        TAP_SPrint(Output, "%s;%d;%d;%d;%d;%1.1f\r\n", CallTraceStats[i].ProcName, CallTraceStats[i].NrCalls, CallTraceStats[i].MinTime*10, CallTraceStats[i].MaxTime*10, CallTraceStats[i].TotalTime*10, t);
        write(f, Output, strlen(Output));
      }
      close(f);
    }
  }
}
Beispiel #2
0
bool StringDBLoad(tStringDB *StringDB, char *FileName)
{
  TRACEENTER();

  int                   f;
  bool                  ret;
  dword                 l, p;
  char                  AbsFileName[FBLIB_DIR_SIZE];

  if(!StringDB || !StringDB->DB || !FileName || !*FileName)
  {
    TRACEEXIT();
    return FALSE;
  }

  ConvertPathType(FileName, AbsFileName, PF_FullLinuxPath);

  ret = FALSE;
  if(*AbsFileName)
  {
    f = open(AbsFileName, O_RDONLY);
    if(f >= 0)
    {
      TAP_MemFree(StringDB->DB);

      //DB Size
      read(f, &l, sizeof(dword));
      StringDB->DB = TAP_MemAlloc(l);

      if(!StringDB->DB)
      {
        StringDB->DBSize = 0;
        close(f);

        TRACEEXIT();
        return FALSE;
      }
      StringDB->DBSize = l;
      StringDB->DBEnd = l + StringDB->DB - 1;

      //Current pointer
      read(f, &p, sizeof(dword));
      StringDB->DBPtr = p + StringDB->DB;

      read(f, StringDB->DB, l);

      close(f);

      ret = TRUE;
    }
  }

  TRACEEXIT();
  return ret;
}
Beispiel #3
0
bool HDD_Exist(char *FileName)
{
  TRACEENTER();

  char                  LinuxPath[FBLIB_DIR_SIZE];
  tstat64               statbuf;
  bool                  ret;

  if(!FileName || !*FileName)
  {
    TRACEEXIT();
    return FALSE;
  }

  ConvertPathType(FileName, LinuxPath, PF_FullLinuxPath);
  if(!LinuxPath[0]) ConvertPathType(FileName, LinuxPath, PF_LinuxPathOnly);

  ret = (stat64(LinuxPath, &statbuf) == 0);

  TRACEEXIT();
  return ret;
}
bool HDD_FindMountPointDevice(char *File, char *MountPoint, char *MountDevice)
{
  TRACEENTER();

  struct mntent        *ent;
  FILE                 *aFile;
  char                  AbsFile[FBLIB_DIR_SIZE], Root[FBLIB_DIR_SIZE], Dev[FBLIB_DIR_SIZE];
  char                 *x;

  Root[0] = '\0';
  Dev[0] = '\0';
  AbsFile[0] = '\0';
  ConvertPathType(File, AbsFile, PF_LinuxPathOnly);
  if(*AbsFile)
  {
    aFile = setmntent("/proc/mounts", "r");
    if(aFile != NULL)
    {
      while(NULL != (ent = getmntent(aFile)))
      {
        x = ansicstr(ent->mnt_dir, strlen(ent->mnt_dir), 0, NULL, NULL);
        if(x)
        {
          if((strstr(AbsFile, x) == AbsFile) && (strlen(x) > strlen(Root)))
          {
            strcpy(Root, x);
            strcpy(Dev, ent->mnt_fsname);
          }
          TAP_MemFree(x);
        }
        else if((strstr(AbsFile, ent->mnt_dir) == AbsFile) && (strlen(ent->mnt_dir) > strlen(Root)))
        {
          strcpy(Root, ent->mnt_dir);
          strcpy(Dev, ent->mnt_fsname);
        }
      }
      endmntent(aFile);
    }
  }

  if(*Root && (Root[strlen(Root) - 1] != '/')) strcat(Root, "/");
  if(*Dev && (Dev[strlen(Dev) - 1] != '/')) strcat(Dev, "/");

  if(MountPoint) strcpy(MountPoint, Root);
  if(MountDevice) strcpy(MountDevice, Dev);

  TRACEEXIT();
  return (Root[0] != '\0' || Dev[0] != '\0');
}
Beispiel #5
0
bool ExtAttribSet(char *FileName, char *AttrName, byte *Data, int DataLen)
{
  TRACEENTER();

  char                  FullAttrName[128];
  char                  AbsFileName[FBLIB_DIR_SIZE];
  int                   f;

  if(!FileName || !*FileName || !AttrName || !*AttrName)
  {
    TRACEEXIT();
    return FALSE;
  }

  ConvertPathType(FileName, AbsFileName, PF_FullLinuxPath);
  if(*AbsFileName)
  {
    f = open(AbsFileName, O_RDWR, 0600);
    if(f >= 0)
    {
      TAP_SPrint(FullAttrName, "user.%s", AttrName);
      if(fsetxattr(f, FullAttrName, Data, DataLen, XATTR_CREATE) == 0)
      {
        close(f);

        TRACEEXIT();
        return TRUE;
      }
      else
      {
        //As the attribute may already exist, retry with the replace flag
        if(fsetxattr(f, FullAttrName, Data, DataLen, XATTR_REPLACE) == 0)
        {
          close(f);

          TRACEEXIT();
          return TRUE;
        }
      }
      close(f);
    }
  }

  TRACEEXIT();
  return FALSE;
}
dword HDD_GetFileTimeByFileName(char *FileName)
{
  TRACEENTER();

  tstat64               statbuf;
  dword                 ret;
  char                  AbsFileName[FBLIB_DIR_SIZE];

  ret = 0;
  if(FileName && *FileName)
  {
    ConvertPathType(FileName, AbsFileName, PF_FullLinuxPath);
    if(*AbsFileName && !lstat64(AbsFileName, &statbuf))
      ret = statbuf.st_mtime;
  }

  TRACEEXIT();
  return ret;
}
tFileInUse HDD_isFileInUse(char *FileName)
{
  TRACEENTER();

  TYPE_PlayInfo         PlayInfo;
  int                   i, NrRecSlots;
  char                  WorkingFileName[FBLIB_DIR_SIZE];
  char                  AbsFileName[FBLIB_DIR_SIZE];
  TYPE_File            *RecFile;

  if(!FileName || !*FileName)
  {
    TRACEEXIT();
    return FIU_No;
  }

  //Convert to an Linux path and cut away any .inf or .nav
  ConvertPathType(FileName, AbsFileName, PF_FullLinuxPath);
  if(StringEndsWith(AbsFileName, ".inf")) AbsFileName[strlen(AbsFileName) - 4] = '\0';

  //Is any Playback running
  TAP_Hdd_GetPlayInfo(&PlayInfo);
  if(PlayInfo.playMode && PlayInfo.totalBlock > 0)
  {
    //Compare the full path of both files
    HDD_GetAbsolutePathByTypeFile(PlayInfo.file, WorkingFileName);
    if(StringEndsWith(WorkingFileName, ".inf") || StringEndsWith(WorkingFileName, ".nav")) WorkingFileName[strlen(WorkingFileName) - 4] = '\0';

    if(!strcmp(AbsFileName, WorkingFileName))
    {
      if(PlayInfo.playMode == PLAYMODE_Mp3)
      {
        TRACEEXIT();
        return FIU_PlayMP3;
      }
      else
      {
        TRACEEXIT();
        return FIU_Playback;
      }
    }
  }

  //Loop through all recording slots
  NrRecSlots = (int)HDD_NumberOfRECSlots();
  for(i = 0; i < NrRecSlots; i++)
  {
    //Get the full path of the rec file
    if(HDD_GetRecSlotFiles(i, &RecFile, NULL, NULL) && HDD_GetAbsolutePathByTypeFile(RecFile, WorkingFileName))
    {
      //Check if both paths are equal
      if(!strcmp(AbsFileName, WorkingFileName))
      {
        TRACEEXIT();
        return (FIU_RecSlot1 + i);
      }
    }
  }

  TRACEEXIT();
  return FIU_No;
}
TYPE_File *HDD_FappendOpen(char *FileName)
{
  TRACEENTER();

  TYPE_File            *file;
  char                  buffer[512];
  dword                 pos, blks, i;
  char                 *end;
  char                  TAPPath[FBLIB_DIR_SIZE], Name[FBLIB_DIR_SIZE];

  if(!FileName || !*FileName)
  {
    TRACEEXIT();
    return NULL;
  }

  ConvertPathType(FileName, TAPPath, PF_TAPPathOnly);
  ConvertPathType(FileName, Name, PF_FileNameOnly);

  HDD_TAP_PushDir();
  if(*TAPPath) HDD_ChangeDir(TAPPath);

  if(!TAP_Hdd_Exist(Name)) TAP_Hdd_Create(Name, ATTR_NORMAL);

  if((file = TAP_Hdd_Fopen(Name)))
  {
    if(TAP_Hdd_Fseek(file, 0, SEEK_SET) != 0)
    {
      TAP_Hdd_Fclose(file);
      file = NULL;
    }
    else
    {
      pos = 0;

      do
      {
        memset(buffer, 0, sizeof(buffer));
        blks = TAP_Hdd_Fread(&buffer, sizeof(buffer), 1, file);

        for(i = 0, end = buffer; i < sizeof(buffer); i++)
          if(buffer[i] == '\0')
          {
            end = buffer + i;
            break;
          }

        if(i < sizeof(buffer)) break;
        else pos += sizeof(buffer);
      }
      while(blks == 1);

      pos += end - buffer;

      if(TAP_Hdd_Fseek(file, pos, SEEK_SET) != pos)
      {
        TAP_Hdd_Fclose(file);
        file = NULL;
      }
    }
  }

  HDD_TAP_PopDir();

  TRACEEXIT();
  return file;
}
Beispiel #9
0
void LogEntry(char *FileName, char *ProgramName, bool Console, eTimeStampFormat TimeStampFormat, char *Text)
{
  TRACEENTER();

  int                   f;
  char                  TimeResult[40];
  char                  CRLF[] = {'\r', '\n'};
  byte                  Sec;
  byte                 *ISOText;
  char                  AbsFileName[FBLIB_DIR_SIZE];
  struct utimbuf        times;

  if(!Text)
  {
    TRACEEXIT();
    return;
  }

  TimeFormat(Now(&Sec), Sec, TimeStampFormat, TimeResult);
  if(TimeResult[0]) strcat(TimeResult, " ");

  if(FileName && FileName[0])
  {
    ConvertPathType(FileName, AbsFileName, PF_FullLinuxPath);
    f = open(AbsFileName, O_WRONLY | O_CREAT | O_APPEND);
    if(f >= 0)
    {
      write(f, TimeResult, strlen(TimeResult));
      if(Text && Text[0]) write(f, Text, strlen(Text));
      write(f, CRLF, 2);
      close(f);

      //As the log would receive the Linux time stamp (01.01.2000), adjust to the PVR's time
      times.actime = PvrTimeToLinux(Now(NULL));
      times.modtime = times.actime;
      utime(AbsFileName, &times);
    }
  }

  if(Console)
  {
    if(TimeStampFormat != TIMESTAMP_NONE) TAP_Print(TimeResult);
    if(ProgramName && ProgramName[0]) TAP_Print("%s: ", ProgramName);

    if(isUTFToppy())
    {
      if(strlen(Text) < 510)
      {
        TAP_Print("%s", Text);
      }
      else
      {
        char *p = Text;

        while(*p)
        {
          int     l;
          char    q;

          l = strlen(p);
          q = p[l];
          p[l] = '\0';
          TAP_Print("%s", p);
          p[l] = q;
          p += l;
        }
      }
      TAP_Print("\n");
    }
    else
    {
      //Max length is 512. If above, a buffer overflow may occur
      StrToISOAlloc(Text, &ISOText);
      if(ISOText && ISOText[0])
      {
        if(strlen(ISOText) < 510)
        {
          TAP_Print("%s", ISOText);
        }
        else
        {
          char *p = ISOText;

          while(*p)
          {
            int     l;
            char    q;

            l = strlen(p);
            if(l > 510) l = 510;

            q = p[l];
            p[l] = '\0';
            TAP_Print("%s", p);
            p[l] = q;
            p += l;
          }
        }
      }
      TAP_Print("\n");
      TAP_MemFree(ISOText);
    }
  }

  TRACEEXIT();
}