Esempio n. 1
0
static void InitObject(NVObject *object)
{
  UINT32 hash;
  int i;

  /* Will put an entry into the hash table */
  hash=HASH_FIFO(object->id,object->channel);
  
  for(i=0;i<HASH_TABLE_COLS;i++) {
    if(localHash[hash][i].id==0) break; /* Found an empty slot!!! */
    /* is object already in cache? */
    if(localHash[hash][i].context==object->id) return;
  }
  if(i==HASH_TABLE_COLS) {
    /* There is no room at the inn. Since we can't cope with reloading
     * context we had better abort here!!
     */
    Info("**** NO ROOM FOR OBJECT %08lx IN HASH TABLE ****\n",object->id);
    graphicsEngineOk=0; /* Set flag so that we won't use accel */
    return;
  }
  /* Ok, bung entry in at appropriate place */
  localHash[hash][i].id=object->id;
  localHash[hash][i].context=object->context;
  (realHash+HASH_ENTRY(hash,i))->id=object->id;
  (realHash+HASH_ENTRY(hash,i))->context=object->context;
}
Esempio n. 2
0
/**
 * Insert a fd and associated client into the hash table
 * @param fd: the file descriptor
 * @param client: the client
 */
static inline void hash_insert(int fd, struct client_struct *client)
{
    struct fd_struct *hash_entry = *HASH_ENTRY(fd);
    struct fd_struct *new_entry = malloc(sizeof(struct fd_struct));
    new_entry->fd = fd;
    client_cpy(&(new_entry->client), client);
    new_entry->next = hash_entry;
    *HASH_ENTRY(fd) = new_entry;
    return;
}
Esempio n. 3
0
/**
 * Delete a fd and associated client from the hash table
 * @param fd: the file descriptor
 * @param client: the client
 */
static inline void hash_delete(int fd, struct client_struct *client)
{
    struct fd_struct *hash_entry = *HASH_ENTRY(fd);
    struct fd_struct *next_fd = hash_entry, *prev_fd = next_fd;
    for (; next_fd; next_fd = next_fd->next)
    {
        if (fd == next_fd->fd) break;
        prev_fd = next_fd;
    }
    if (prev_fd == next_fd) *HASH_ENTRY(fd) = next_fd->next;
    prev_fd->next = next_fd->next;
    free(next_fd);
    return;
}
Esempio n. 4
0
/**
 * Find a matching fd and associated client in the hash table
 * @param fd: the file descriptor
 * @param client: the client
 * @return 1 when a matching is found, 0 otherwise.
 */
static inline int hash_find(int fd, struct client_struct *client)
{
    struct fd_struct *hash_entry = *HASH_ENTRY(fd);
    for (; hash_entry; hash_entry = hash_entry->next)
        if (fd == hash_entry->fd) break;
    if (!hash_entry) return 0;
    return is_equal(client, &(hash_entry->client));
}
Esempio n. 5
0
LOCAL void
compress_byte (gif_dest_ptr dinfo, int c)
/* Accept and compress one 8-bit byte */
{
  register hash_int i;
  register hash_int disp;
  register hash_entry probe_value;

  if (dinfo->first_byte) {	/* need to initialize waiting_code */
    dinfo->waiting_code = c;
    dinfo->first_byte = FALSE;
    return;
  }

  /* Probe hash table to see if a symbol exists for
   * waiting_code followed by c.
   * If so, replace waiting_code by that symbol and return.
   */
  i = ((hash_int) c << (MAX_LZW_BITS-8)) + dinfo->waiting_code;
  /* i is less than twice 2**MAX_LZW_BITS, therefore less than twice HSIZE */
  if (i >= HSIZE)
    i -= HSIZE;

  probe_value = HASH_ENTRY(dinfo->waiting_code, c);
  
  if (dinfo->hash_code[i] != 0) { /* is first probed slot empty? */
    if (dinfo->hash_value[i] == probe_value) {
      dinfo->waiting_code = dinfo->hash_code[i];
      return;
    }
    if (i == 0)			/* secondary hash (after G. Knott) */
      disp = 1;
    else
      disp = HSIZE - i;
    for (;;) {
      i -= disp;
      if (i < 0)
	i += HSIZE;
      if (dinfo->hash_code[i] == 0)
	break;			/* hit empty slot */
      if (dinfo->hash_value[i] == probe_value) {
	dinfo->waiting_code = dinfo->hash_code[i];
	return;
      }
    }
  }

  /* here when hashtable[i] is an empty slot; desired symbol not in table */
  output(dinfo, dinfo->waiting_code);
  if (dinfo->free_code < LZW_TABLE_SIZE) {
    dinfo->hash_code[i] = dinfo->free_code++; /* add symbol to hashtable */
    dinfo->hash_value[i] = probe_value;
  } else
    clear_block(dinfo);
  dinfo->waiting_code = c;
}
Esempio n. 6
0
static void ClearOutHashTables(void)
{
  int i,j;

  if(!realHash) realHash=(HashTableEntry *) nvPRAMHTPort;

  /* Clear out host copy of hash table */
  for(i=0;i<HASH_TABLE_ROWS;i++) {
    for(j=0;j<HASH_TABLE_COLS;j++) {
      localHash[i][j].id=0;
      localHash[i][j].context=0;
      (realHash+HASH_ENTRY(i,j))->id=0;
      (realHash+HASH_ENTRY(i,j))->context=0;
    }
  }
  /* Clear out hash virtual registers */
  for(i=0;i<NV_PRAM_HASH_VIRTUAL__SIZE_1;i++) {
    PRAM_Write(HASH_VIRTUAL(i),0);
  }
}
Esempio n. 7
0
bool hash_iter_next(lref_t hash, hash_iter_t * iter, lref_t * key, lref_t * val)
{
     assert(HASHP(hash));

     while (*iter < HASH_SIZE(hash))
     {
          if (hash_entry_used_p(HASH_ENTRY(hash, *iter)))
          {
               if (key)
                    *key = HASH_ENTRY(hash, *iter)->key;

               if (val)
                    *val = HASH_ENTRY(hash, *iter)->val;

               *iter = *iter + 1;

               return true;
          }

          *iter = *iter + 1;
     }

     return false;
}
#ifdef OST_TRACE_COMPILER_IN_USE
#include "imgcommon_src_isp_common_defcor_damperTraces.h"
#endif

#define HASH_ENTRY(i) i,#i

typedef struct
{
   t_defcor_damper_id id;
   const char*        name;
   t_uint32           addr;
} t_defcor_damper_info;

static const t_defcor_damper_info KDefCorDamperInfo[DEFCOR_DAMPERS_NUM] =
{
   { HASH_ENTRY(DEFCOR_DUSTER_RC_THRESHOLD),    DusterControl_u8_RingCorrectionNormThr_Byte0       },
   { HASH_ENTRY(DEFCOR_DUSTER_CC_SIGMA_FACTOR), DusterControl_u8_CenterCorrectionSigmaFactor_Byte0 }
};

/*
 * Constructor
 */
CDefCorDamper::CDefCorDamper(TraceObject *traceobj):CSharedDamper("DEFCOR", traceobj)
{
}

/*
 * Actual Constructor
 */
t_damper_error_code CDefCorDamper::Construct()
{
}

/*
 * Local stuff
 */
#define HASH_ENTRY(id) {id,#id}

typedef struct
{
    t_fileio_error id;
    const char* name;
} t_fileio_error_entry;

static const t_fileio_error_entry KFioErrorCodesList[] =
{
    HASH_ENTRY(FILE_IO_OK),
    HASH_ENTRY(FILE_IO_BAD_PARAMETER),
    HASH_ENTRY(FILE_IO_OPEN_FAILED),
    HASH_ENTRY(FILE_IO_SEEK_FAILED),
    HASH_ENTRY(FILE_IO_READ_FAILED),
    HASH_ENTRY(FILE_IO_WRITE_FAILED)
};

#define KFioErrorCodesListSize (sizeof(KFioErrorCodesList)/sizeof(KFioErrorCodesList[0]))

/*
 * Destructor
 */
METH(~fileio)()
{
    IN0("");
Esempio n. 10
0
/*******************************************************************
  lock a hash bucket entry in shared memory for share_mode management 
  ******************************************************************/
static BOOL shm_lock_share_entry(connection_struct *conn,
				 SMB_DEV_T dev, SMB_INO_T inode, int *ptok)
{
	*ptok = 0; /* For purify... */
	return shmops->lock_hash_entry(HASH_ENTRY(dev, inode));
}
Esempio n. 11
0
//-----------------------------------------------------------------
// compress a byte
void mgLZWEncode::compressByte(
  BYTE nByte)
{
  if (m_firstByte) 
  {	
    // need to initialize nWaitingCode 
    m_waitingCode = nByte;
    m_firstByte = FALSE;
    return;
  }

  // Probe hash table to see if a symbol exists for 
  // waiting_code followed by nByte.

  HashInt i = ((HashInt) nByte << (MAX_LZW_BITS-8)) + m_waitingCode;
  HashInt nDisp;

  // i is less than twice 2**MAX_LZW_BITS, therefore less than twice HSIZE
  if (i >= HASH_SIZE)
    i -= HASH_SIZE;

  mgLZWHash lProbeValue = HASH_ENTRY(m_waitingCode, nByte);
  // is first probed slot not empty?
  if (m_hashCode[i] != 0) 
  { 
    if (m_hashValue[i] == lProbeValue) 
    {
      m_waitingCode = m_hashCode[i];
      return;
    }
    if (i == 0)			// secondary hash (after G. Knott) 
      nDisp = 1;
    else nDisp = HASH_SIZE - i;

    for (;;) 
    {
      i -= nDisp;
      if (i < 0)
        i += HASH_SIZE;
      if (m_hashCode[i] == 0)
        break;			// hit empty slot
      if (m_hashValue[i] == lProbeValue) 
      {
	      m_waitingCode = m_hashCode[i];
        return;
      }
    }
  }

  // here when hashtable[i] is an empty slot; desired symbol not in table 
  writeCode(m_waitingCode);

  if (m_freeCode < LZW_TABLE_SIZE) 
  {
    m_hashCode[i] = m_freeCode++; // add symbol to hashtable
    m_hashValue[i] = lProbeValue;
  } 
  else clearBlock();

  m_waitingCode = nByte;
}
Esempio n. 12
0
/*******************************************************************
del the share mode of a file.
********************************************************************/
static void shm_del_share_mode(int token, int fnum)
{
  uint32 dev, inode;
  int *mode_array;
  unsigned int hash_entry;
  share_mode_record *file_scanner_p;
  share_mode_record *file_prev_p;
  shm_share_mode_entry *entry_scanner_p;
  shm_share_mode_entry *entry_prev_p;
  BOOL found = False;
  int pid = getpid();

  dev = Files[fnum].fd_ptr->dev;
  inode = Files[fnum].fd_ptr->inode;

  hash_entry = HASH_ENTRY(dev, inode);

  mode_array = (int *)shmops->offset2addr(shmops->get_userdef_off());
 
  if(mode_array[hash_entry] == 0)
  {  
    DEBUG(0,("PANIC ERROR:del_share_mode hash bucket %d empty\n", 
                  hash_entry));
    return;
  }  
  
  file_scanner_p = (share_mode_record *)shmops->offset2addr(mode_array[hash_entry]);
  file_prev_p = file_scanner_p;

  while(file_scanner_p)
  {
    if( (file_scanner_p->st_dev == dev) && (file_scanner_p->st_ino == inode) )
    {
      found = True;
      break;
    }
    else
    {
      file_prev_p = file_scanner_p ;
      file_scanner_p = (share_mode_record *)
                        shmops->offset2addr(file_scanner_p->next_offset);
    }
  }
    
  if(!found)
  {
     DEBUG(0,("ERROR: del_share_mode no entry for dev %d inode %d\n",
	      dev, inode));
     return;
  }
  
  if(file_scanner_p->locking_version != LOCKING_VERSION)
  {
    DEBUG(0,("ERROR: del_share_modes Deleting old share mode v1 %d dev=%d ino=%d\n",
	     file_scanner_p->locking_version, dev, inode));
    if(file_prev_p == file_scanner_p)
      mode_array[hash_entry] = file_scanner_p->next_offset;
    else
      file_prev_p->next_offset = file_scanner_p->next_offset;
    shmops->shm_free(shmops->addr2offset(file_scanner_p));
    return;
  }

  found = False;
  entry_scanner_p = (shm_share_mode_entry*)shmops->offset2addr(
                                         file_scanner_p->share_mode_entries);
  entry_prev_p = entry_scanner_p;
  while(entry_scanner_p)
  {
    if( (pid == entry_scanner_p->e.pid) && 
          (memcmp(&entry_scanner_p->e.time, 
                 &Files[fnum].open_time,sizeof(struct timeval)) == 0) )
    {
      found = True;
      break;
    }
    else
    {
      entry_prev_p = entry_scanner_p;
      entry_scanner_p = (shm_share_mode_entry *)
                          shmops->offset2addr(entry_scanner_p->next_share_mode_entry);
    }
  } 

  if (found)
  {
    /* Decrement the number of entries in the record. */
    file_scanner_p->num_share_mode_entries -= 1;

    DEBUG(2,("del_share_modes Deleting share mode entry dev=%d ino=%d\n",
              dev, inode));
    if(entry_prev_p == entry_scanner_p)
      /* We are at start of list */
      file_scanner_p->share_mode_entries = entry_scanner_p->next_share_mode_entry;
    else
      entry_prev_p->next_share_mode_entry = entry_scanner_p->next_share_mode_entry;
    shmops->shm_free(shmops->addr2offset(entry_scanner_p));

    /* PARANOIA TEST */
    if(file_scanner_p->num_share_mode_entries < 0)
    {
      DEBUG(0,("PANIC ERROR:del_share_mode num_share_mode_entries=%d\n", 
	       file_scanner_p->num_share_mode_entries));
      return;
    }

    /* If we deleted the last share mode entry then remove the share mode record. */
    if(file_scanner_p->num_share_mode_entries == 0)
    {
      DEBUG(2,("del_share_modes num entries = 0, deleting share_mode dev=%d ino=%d\n", 
	       dev, inode));
      if(file_prev_p == file_scanner_p)
        mode_array[hash_entry] = file_scanner_p->next_offset;
      else
        file_prev_p->next_offset = file_scanner_p->next_offset;
      shmops->shm_free(shmops->addr2offset(file_scanner_p));
    }
  }
  else
  {
    DEBUG(0,("ERROR: del_share_modes No share mode dev=%d ino=%d\n", 
	     dev, inode));
  }
}
Esempio n. 13
0
/*******************************************************************
  unlock a hash bucket entry in shared memory for share_mode management 
  ******************************************************************/
static BOOL shm_unlock_share_entry(connection_struct *conn,
				   SMB_DEV_T dev, SMB_INO_T inode, int token)
{
  return shmops->unlock_hash_entry(HASH_ENTRY(dev, inode));
}
Esempio n. 14
0
/*******************************************************************
set the share mode of a file. Return False on fail, True on success.
********************************************************************/
static BOOL shm_set_share_mode(int token, int fnum, uint16 port, uint16 op_type)
{
  files_struct *fs_p = &Files[fnum];
  int32 dev, inode;
  int *mode_array;
  unsigned int hash_entry;
  share_mode_record *file_scanner_p;
  share_mode_record *file_prev_p;
  shm_share_mode_entry *new_entry_p;
  int new_entry_offset;
  BOOL found = False;

  dev = fs_p->fd_ptr->dev;
  inode = fs_p->fd_ptr->inode;

  hash_entry = HASH_ENTRY(dev, inode);

  mode_array = (int *)shmops->offset2addr(shmops->get_userdef_off());

  file_scanner_p = (share_mode_record *)shmops->offset2addr(mode_array[hash_entry]);
  file_prev_p = file_scanner_p;
  
  while(file_scanner_p)
  {
    if( (file_scanner_p->st_dev == dev) && (file_scanner_p->st_ino == inode) )
    {
      found = True;
      break;
    }
    else
    {
      file_prev_p = file_scanner_p ;
      file_scanner_p = (share_mode_record *)
                         shmops->offset2addr(file_scanner_p->next_offset);
    }
  }
  
  if(!found)
  {
    /* We must create a share_mode_record */
    share_mode_record *new_mode_p = NULL;
    int new_offset = shmops->shm_alloc(sizeof(share_mode_record) +
				   strlen(fs_p->name) + 1);
    if(new_offset == 0) {
	    DEBUG(0,("ERROR:set_share_mode shmops->shm_alloc fail!\n"));
	    return False;
    }
    new_mode_p = shmops->offset2addr(new_offset);
    new_mode_p->locking_version = LOCKING_VERSION;
    new_mode_p->st_dev = dev;
    new_mode_p->st_ino = inode;
    new_mode_p->num_share_mode_entries = 0;
    new_mode_p->share_mode_entries = 0;
    pstrcpy(new_mode_p->file_name, fs_p->name);

    /* Chain onto the start of the hash chain (in the hope we will be used first). */
    new_mode_p->next_offset = mode_array[hash_entry];
    mode_array[hash_entry] = new_offset;

    file_scanner_p = new_mode_p;

    DEBUG(3,("set_share_mode: Created share record for %s (dev %d inode %d)\n", 
	     fs_p->name, dev, inode));
  }
 
  /* Now create the share mode entry */ 
  new_entry_offset = shmops->shm_alloc(sizeof(shm_share_mode_entry));
  if(new_entry_offset == 0) {
	  int delete_offset = mode_array[hash_entry];
	  DEBUG(0,("ERROR:set_share_mode: shmops->shm_alloc fail 1!\n"));
	  /* Unlink the damaged record */
	  mode_array[hash_entry] = file_scanner_p->next_offset;
	  /* And delete it */
	  shmops->shm_free( delete_offset );
	  return False;
  }

  new_entry_p = shmops->offset2addr(new_entry_offset);

  new_entry_p->e.pid = getpid();
  new_entry_p->e.share_mode = fs_p->share_mode;
  new_entry_p->e.op_port = port;
  new_entry_p->e.op_type = op_type;
  memcpy( (char *)&new_entry_p->e.time, (char *)&fs_p->open_time, sizeof(struct timeval));

  /* Chain onto the share_mode_record */
  new_entry_p->next_share_mode_entry = file_scanner_p->share_mode_entries;
  file_scanner_p->share_mode_entries = new_entry_offset;

  /* PARANOIA TEST */
  if(file_scanner_p->num_share_mode_entries < 0)
  {
    DEBUG(0,("PANIC ERROR:set_share_mode num_share_mode_entries=%d\n", 
	     file_scanner_p->num_share_mode_entries));
    return False;
  }

  /* Increment the share_mode_entries counter */
  file_scanner_p->num_share_mode_entries += 1;

  DEBUG(3,("set_share_mode: Created share entry for %s with mode 0x%X pid=%d\n",
	   fs_p->name, fs_p->share_mode, new_entry_p->e.pid));

  return(True);
}
Esempio n. 15
0
/*******************************************************************
Remove an oplock port and mode entry from a share mode.
********************************************************************/
static BOOL shm_remove_share_oplock(int fnum, int token)
{
  uint32 dev, inode;
  int *mode_array;
  unsigned int hash_entry;
  share_mode_record *file_scanner_p;
  share_mode_record *file_prev_p;
  shm_share_mode_entry *entry_scanner_p;
  shm_share_mode_entry *entry_prev_p;
  BOOL found = False;
  int pid = getpid();

  dev = Files[fnum].fd_ptr->dev;
  inode = Files[fnum].fd_ptr->inode;

  hash_entry = HASH_ENTRY(dev, inode);

  mode_array = (int *)shmops->offset2addr(shmops->get_userdef_off());

  if(mode_array[hash_entry] == 0)
  {
    DEBUG(0,("PANIC ERROR:remove_share_oplock: hash bucket %d empty\n",
                  hash_entry));
    return False;
  } 
    
  file_scanner_p = (share_mode_record *)shmops->offset2addr(mode_array[hash_entry]);
  file_prev_p = file_scanner_p;
    
  while(file_scanner_p)
  { 
    if( (file_scanner_p->st_dev == dev) && (file_scanner_p->st_ino == inode) )
    {
      found = True;
      break;
    }
    else
    {
      file_prev_p = file_scanner_p ;
      file_scanner_p = (share_mode_record *)
                        shmops->offset2addr(file_scanner_p->next_offset);
    }
  } 
   
  if(!found)
  { 
     DEBUG(0,("ERROR:remove_share_oplock: no entry found for dev=%d ino=%d\n", 
	      dev, inode));
     return False;
  } 

  if(file_scanner_p->locking_version != LOCKING_VERSION)
  {
    DEBUG(0,("ERROR: remove_share_oplock: Deleting old share mode v1=%d dev=%d ino=%d\n",
	     file_scanner_p->locking_version, dev, inode));
    if(file_prev_p == file_scanner_p)
      mode_array[hash_entry] = file_scanner_p->next_offset;
    else
      file_prev_p->next_offset = file_scanner_p->next_offset;
    shmops->shm_free(shmops->addr2offset(file_scanner_p));
    return False;
  }

  found = False;
  entry_scanner_p = (shm_share_mode_entry*)shmops->offset2addr(
                                         file_scanner_p->share_mode_entries);
  entry_prev_p = entry_scanner_p;
  while(entry_scanner_p)
  {
    if( (pid == entry_scanner_p->e.pid) && 
        (entry_scanner_p->e.share_mode == Files[fnum].share_mode) &&
        (memcmp(&entry_scanner_p->e.time, 
                &Files[fnum].open_time,sizeof(struct timeval)) == 0) )
    {
      /* Delete the oplock info. */
      entry_scanner_p->e.op_port = 0;
      entry_scanner_p->e.op_type = 0;
      found = True;
      break;
    }
    else
    {
      entry_prev_p = entry_scanner_p;
      entry_scanner_p = (shm_share_mode_entry *)
                          shmops->offset2addr(entry_scanner_p->next_share_mode_entry);
    }
  } 

  if(!found)
  {
    DEBUG(0,("ERROR: remove_share_oplock: No oplock granted. dev=%d ino=%d\n", 
	     dev, inode));
    return False;
  }

  return True;
}
Esempio n. 16
0
static BOOL shm_mod_share_entry(int token, files_struct *fsp,
                                void (*mod_fn)(share_mode_entry *, SMB_DEV_T, SMB_INO_T, void *),
                                void *param)
{
  SMB_DEV_T dev;
  SMB_INO_T inode;
  int *mode_array;
  unsigned int hash_entry;
  share_mode_record *file_scanner_p;
  share_mode_record *file_prev_p;
  shm_share_mode_entry *entry_scanner_p;
  BOOL found = False;
  pid_t pid = getpid();

  dev = fsp->fd_ptr->dev;
  inode = fsp->fd_ptr->inode;

  hash_entry = HASH_ENTRY(dev, inode);

  mode_array = (int *)shmops->offset2addr(shmops->get_userdef_off());

  if(mode_array[hash_entry] == 0)
  {
    DEBUG(0,("PANIC ERROR:modify_share_entry: hash bucket %d empty\n",
                  hash_entry));
    return False;
  } 
    
  file_scanner_p = (share_mode_record *)shmops->offset2addr(mode_array[hash_entry]);
  file_prev_p = file_scanner_p;
    
  while(file_scanner_p)
  { 
    if( (file_scanner_p->st_dev == dev) && (file_scanner_p->st_ino == inode) )
    {
      found = True;
      break;
    }
    else
    {
      file_prev_p = file_scanner_p ;
      file_scanner_p = (share_mode_record *)
                        shmops->offset2addr(file_scanner_p->next_offset);
    }
  } 
   
  if(!found)
  { 
     DEBUG(0,("ERROR:modify_share_entry: no entry found for dev=%x ino=%.0f\n", 
	      (unsigned int)dev, (double)inode));
     return False;
  } 

  if(file_scanner_p->locking_version != LOCKING_VERSION)
  {
    DEBUG(0,("ERROR: modify_share_entry: Deleting old share mode v1=%d dev=%x ino=%.0f\n",
	     file_scanner_p->locking_version, (unsigned int)dev, (double)inode));

    if(file_prev_p == file_scanner_p)
      mode_array[hash_entry] = file_scanner_p->next_offset;
    else
      file_prev_p->next_offset = file_scanner_p->next_offset;
    shmops->shm_free(shmops->addr2offset(file_scanner_p));
    return False;
  }

  found = False;
  entry_scanner_p = (shm_share_mode_entry*)shmops->offset2addr(
                                         file_scanner_p->share_mode_entries);
  while(entry_scanner_p)
  {
    if( (pid == entry_scanner_p->e.pid) && 
        (entry_scanner_p->e.share_mode == fsp->share_mode) &&
        (memcmp(&entry_scanner_p->e.time, 
                &fsp->open_time,sizeof(struct timeval)) == 0) )
    {
      /*
       * Call the generic function with the given parameter.
       */

      DEBUG(5,("modify_share_entry: Calling generic function to modify entry for dev=%x ino=%.0f\n",
            (unsigned int)dev, (double)inode));

      (*mod_fn)( &entry_scanner_p->e, dev, inode, param);
      found = True;
      break;
    }
    else
    {
      entry_scanner_p = (shm_share_mode_entry *)
                          shmops->offset2addr(entry_scanner_p->next_share_mode_entry);
    }
  } 

  if(!found)
  {
    DEBUG(0,("ERROR: modify_share_entry: No entry found for dev=%x ino=%.0f\n", 
	     (unsigned int)dev, (double)inode));
    return False;
  }

  return True;
}
Esempio n. 17
0
/*******************************************************************
get all share mode entries in shared memory for a dev/inode pair.
********************************************************************/
static int shm_get_share_modes(int cnum, int token, uint32 dev, uint32 inode, 
			       share_mode_entry **old_shares)
{
  int *mode_array;
  unsigned int hash_entry = HASH_ENTRY(dev, inode); 
  share_mode_record *file_scanner_p;
  share_mode_record *file_prev_p;
  shm_share_mode_entry *entry_scanner_p;
  shm_share_mode_entry *entry_prev_p;
  int num_entries;
  int num_entries_copied;
  BOOL found = False;
  share_mode_entry *share_array = (share_mode_entry *)0;

  *old_shares = 0;

  mode_array = (int *)shmops->offset2addr(shmops->get_userdef_off());
  
  if(mode_array[hash_entry] == 0)
  {
    DEBUG(5,("get_share_modes hash bucket %d empty\n", hash_entry));
    return 0;
  }

  file_scanner_p = (share_mode_record *)shmops->offset2addr(mode_array[hash_entry]);
  file_prev_p = file_scanner_p;
  while(file_scanner_p)
  {
    if( (file_scanner_p->st_dev == dev) && (file_scanner_p->st_ino == inode) )
    {
      found = True;
      break;
    }
    else
    {
      file_prev_p = file_scanner_p ;
      file_scanner_p = (share_mode_record *)shmops->offset2addr(
                                    file_scanner_p->next_offset);
    }
  }
  
  if(!found)
  {
    DEBUG(5,("get_share_modes no entry for file dev = %d ino = %d\n",
	     dev, inode));
    return (0);
  }
  
  if(file_scanner_p->locking_version != LOCKING_VERSION)
  {
    DEBUG(0,("ERROR: get_share_modes  Deleting old share mode v1 %d dev=%d ino=%d\n", 
	     file_scanner_p->locking_version, dev, inode));
    if(file_prev_p == file_scanner_p)
      mode_array[hash_entry] = file_scanner_p->next_offset;
    else
      file_prev_p->next_offset = file_scanner_p->next_offset;
    shmops->shm_free(shmops->addr2offset(file_scanner_p));
    return (0);
  }

  /* Allocate the old_shares array */
  num_entries = file_scanner_p->num_share_mode_entries;
  if(num_entries)
  {
    *old_shares = share_array = (share_mode_entry *)
                 malloc(num_entries * sizeof(share_mode_entry));
    if(*old_shares == 0)
    {
      DEBUG(0,("get_share_modes: malloc fail!\n"));
      return 0;
    }
  }

  num_entries_copied = 0;
  
  entry_scanner_p = (shm_share_mode_entry*)shmops->offset2addr(
                                           file_scanner_p->share_mode_entries);
  entry_prev_p = entry_scanner_p;
  while(entry_scanner_p)
  {
    int pid = entry_scanner_p->e.pid;

    if (pid && !process_exists(pid))
    {
      /* Delete this share mode entry */
      shm_share_mode_entry *delete_entry_p = entry_scanner_p;

      if(entry_prev_p == entry_scanner_p)
      {
        /* We are at start of list */
        file_scanner_p->share_mode_entries = entry_scanner_p->next_share_mode_entry;
        entry_scanner_p = (shm_share_mode_entry*)shmops->offset2addr(
                                           file_scanner_p->share_mode_entries);
        entry_prev_p = entry_scanner_p;
      }
      else
      {
        entry_prev_p->next_share_mode_entry = entry_scanner_p->next_share_mode_entry;
        entry_scanner_p = (shm_share_mode_entry*)
                           shmops->offset2addr(entry_scanner_p->next_share_mode_entry);
      }
      /* Decrement the number of share mode entries on this share mode record */
      file_scanner_p->num_share_mode_entries -= 1;

      /* PARANOIA TEST */
      if(file_scanner_p->num_share_mode_entries < 0)
      {
        DEBUG(0,("PANIC ERROR: get_share_mode: entries=%d dev=%d ino=%d\n",
		 file_scanner_p->num_share_mode_entries,dev, inode));
        return 0;
      }

      DEBUG(0,("get_share_modes: process %d no longer exists\n", pid));

      shmops->shm_free(shmops->addr2offset(delete_entry_p));
    } 
    else
    {
       /* This is a valid share mode entry and the process that
           created it still exists. Copy it into the output array.
       */
       share_array[num_entries_copied].pid = entry_scanner_p->e.pid;
       share_array[num_entries_copied].share_mode = entry_scanner_p->e.share_mode;
       share_array[num_entries_copied].op_port = entry_scanner_p->e.op_port;
       share_array[num_entries_copied].op_type = entry_scanner_p->e.op_type;
       memcpy(&share_array[num_entries_copied].time, &entry_scanner_p->e.time,
              sizeof(struct timeval));
       num_entries_copied++;
       DEBUG(5,("get_share_modes Read share mode 0x%X pid=%d\n", 
		entry_scanner_p->e.share_mode, entry_scanner_p->e.pid));
       entry_prev_p = entry_scanner_p;
       entry_scanner_p = (shm_share_mode_entry *)
                           shmops->offset2addr(entry_scanner_p->next_share_mode_entry);
    }
  }
  
  /* If no valid share mode entries were found then this record shouldn't exist ! */
  if(num_entries_copied == 0)
  {
    DEBUG(0,("get_share_modes: file with dev %d inode %d empty\n", 
	     dev, inode));
    if(*old_shares)
      free((char *)*old_shares);
    *old_shares = 0;

    if(file_prev_p == file_scanner_p)
      mode_array[hash_entry] = file_scanner_p->next_offset;
    else
      file_prev_p->next_offset = file_scanner_p->next_offset;
    shmops->shm_free(shmops->addr2offset(file_scanner_p));
  }

  DEBUG(5,("get_share_modes: file with dev %d inode %d -> %d entries\n",
	   dev, inode, num_entries_copied));

  return(num_entries_copied);
}  
Esempio n. 18
0
/*******************************************************************
  unlock a hash bucket entry in shared memory for share_mode management 
  ******************************************************************/
static BOOL shm_unlock_share_entry(int cnum, uint32 dev, uint32 inode, int token)
{
  return shmops->unlock_hash_entry(HASH_ENTRY(dev, inode));
}