SASC-NG
DVBSoftCAM

cFileMap Class Reference

#include <data.h>

Inheritance diagram for cFileMap:

List of all members.

Public Member Functions

 cFileMap (const char *Filename, bool Rw)
 ~cFileMap ()
bool Map (void)
bool Unmap (void)
void Sync (void)
int Size (void) const
unsigned char * Addr (void) const
bool IsFileMap (const char *Name, bool Rw)

Detailed Description

Definition at line 36 of file data.h.


Constructor & Destructor Documentation

cFileMap::cFileMap ( const char *  Filename,
bool  Rw 
)

Definition at line 41 of file data.c.

{
  filename=strdup(Filename);
  rw=Rw;
  fd=-1; count=len=0; addr=0; failed=false;
}
cFileMap::~cFileMap ( )

Definition at line 48 of file data.c.

References free.

{
  Clean();
  free(filename);
}

Member Function Documentation

unsigned char* cFileMap::Addr ( void  ) const [inline]
bool cFileMap::IsFileMap ( const char *  Name,
bool  Rw 
)

Definition at line 54 of file data.c.

Referenced by cFileMaps::GetFileMap().

{
  return (!strcmp(Name,filename) && (!Rw || rw));
}
bool cFileMap::Map ( void  )

Definition at line 65 of file data.c.

References count, fd, L_GEN_ERROR, open(), and PRINTF.

Referenced by cMapEeprom::cMapEeprom(), cMapRom::cMapRom(), and cSeca2Prov::GetMap().

{
  cMutexLock lock(this);
  if(addr) { count++; return true; }
  if(!failed) {
    struct stat64 ds;
    if(!stat64(filename,&ds)) {
      if(S_ISREG(ds.st_mode)) {
        fd=open(filename,rw ? O_RDWR : O_RDONLY);
        if(fd>=0) {
          unsigned char *map=(unsigned char *)mmap(0,ds.st_size,rw ? (PROT_READ|PROT_WRITE):(PROT_READ),MAP_SHARED,fd,0);
          if(map!=MAP_FAILED) {
            addr=map; len=ds.st_size; count=1;
            return true;
            }
          else PRINTF(L_GEN_ERROR,"mapping failed on %s: %s",filename,strerror(errno));
          close(fd); fd=-1;
          }
        else PRINTF(L_GEN_ERROR,"error opening filemap %s: %s",filename,strerror(errno));
        }
      else PRINTF(L_GEN_ERROR,"filemap %s is not a regular file",filename);
      }
    else PRINTF(L_GEN_ERROR,"can't stat filemap %s: %s",filename,strerror(errno));
    failed=true; // don't try this one over and over again
    }
  return false;
}
int cFileMap::Size ( void  ) const [inline]

Definition at line 52 of file data.h.

Referenced by cMapEeprom::cMapEeprom(), cMapRom::cMapRom(), and cSeca2Prov::GetMap().

{ return len; }
void cFileMap::Sync ( void  )

Definition at line 103 of file data.c.

Referenced by Unmap().

{
  cMutexLock lock(this);
  if(addr) msync(addr,len,MS_ASYNC);
}
bool cFileMap::Unmap ( void  )

Definition at line 93 of file data.c.

References count, and Sync().

Referenced by cSeca2Prov::GetMap(), cMapEeprom::~cMapEeprom(), cMapRom::~cMapRom(), cSeca2Prov::~cSeca2Prov(), cSeca2ProvSSE::~cSeca2ProvSSE(), and cSystemFakeNDS::~cSystemFakeNDS().

{
  cMutexLock lock(this);
  if(addr) {
    if(!(--count)) { Clean(); return true; }
    else Sync();
    }
  return false;
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines