summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1997-11-01 07:33:55 +0000
committerAndrew Tridgell <tridge@samba.org>1997-11-01 07:33:55 +0000
commit264b1e0e75ae63467b6fe51b339e1e5f3c4477bc (patch)
tree9b1e8ec3cfb0725ee34f0da45f4a05b3a78ecc62
parent03deca0070b3c7004963938b973519e9c56f2f5c (diff)
downloadsamba-264b1e0e75ae63467b6fe51b339e1e5f3c4477bc.tar.gz
samba-264b1e0e75ae63467b6fe51b339e1e5f3c4477bc.tar.bz2
samba-264b1e0e75ae63467b6fe51b339e1e5f3c4477bc.zip
some locking code cleanups
(This used to be commit 6d77311d6cecabafb86c02e26b30724425ef6208)
-rw-r--r--source3/include/smb.h3
-rw-r--r--source3/locking/locking_shm.c136
-rw-r--r--source3/locking/shmem.c20
-rw-r--r--source3/locking/shmem_sysv.c304
4 files changed, 222 insertions, 241 deletions
diff --git a/source3/include/smb.h b/source3/include/smb.h
index 8f0bd31bf4..8bb1e993cd 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -57,9 +57,6 @@
typedef int BOOL;
-/* offset in shared memory */
-#define NULL_OFFSET (int)(0)
-
/* limiting size of ipc replies */
#define REALLOC(ptr,size) Realloc(ptr,MAX((size),4*1024))
diff --git a/source3/locking/locking_shm.c b/source3/locking/locking_shm.c
index dfabbac290..45ab14d452 100644
--- a/source3/locking/locking_shm.c
+++ b/source3/locking/locking_shm.c
@@ -112,9 +112,9 @@ static int shm_get_share_modes(int cnum, int token, uint32 dev, uint32 inode,
mode_array = (int *)shmops->offset2addr(shmops->get_userdef_off());
- if(mode_array[hash_entry] == NULL_OFFSET)
+ if(mode_array[hash_entry] == 0)
{
- DEBUG(5,("get_share_modes (FAST_SHARE_MODES): hash bucket %d empty\n", hash_entry));
+ DEBUG(5,("get_share_modes hash bucket %d empty\n", hash_entry));
return 0;
}
@@ -137,16 +137,15 @@ static int shm_get_share_modes(int cnum, int token, uint32 dev, uint32 inode,
if(!found)
{
- DEBUG(5,("get_share_modes (FAST_SHARE_MODES): no entry for \
-file dev = %d, ino = %d in hash_bucket %d\n", dev, inode, hash_entry));
+ 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 (FAST_SHARE_MODES): Deleting old share mode \
-record due to old locking version %d for file dev = %d, inode = %d in hash \
-bucket %d\n", file_scanner_p->locking_version, dev, inode, hash_entry));
+ 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
@@ -163,7 +162,7 @@ bucket %d\n", file_scanner_p->locking_version, dev, inode, hash_entry));
malloc(num_entries * sizeof(share_mode_entry));
if(*old_shares == 0)
{
- DEBUG(0,("get_share_modes (FAST_SHARE_MODES): malloc fail !\n"));
+ DEBUG(0,("get_share_modes: malloc fail!\n"));
return 0;
}
}
@@ -181,7 +180,6 @@ bucket %d\n", file_scanner_p->locking_version, dev, inode, hash_entry));
{
/* Delete this share mode entry */
shm_share_mode_entry *delete_entry_p = entry_scanner_p;
- int share_mode = entry_scanner_p->e.share_mode;
if(entry_prev_p == entry_scanner_p)
{
@@ -203,17 +201,12 @@ bucket %d\n", file_scanner_p->locking_version, dev, inode, hash_entry));
/* PARANOIA TEST */
if(file_scanner_p->num_share_mode_entries < 0)
{
- DEBUG(0,("PANIC ERROR:get_share_mode (FAST_SHARE_MODES): num_share_mode_entries < 0 (%d) \
-for dev = %d, ino = %d, hashbucket %d\n", file_scanner_p->num_share_mode_entries,
- dev, inode, hash_entry));
+ 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 (FAST_SHARE_MODES): process %d no longer exists and \
-it left a share mode entry with mode 0x%X for file dev = %d, ino = %d in hash \
-bucket %d (number of entries now = %d)\n",
- pid, share_mode, dev, inode, hash_entry,
- file_scanner_p->num_share_mode_entries));
+ DEBUG(0,("get_share_modes: process %d no longer exists\n", pid));
shmops->free(shmops->addr2offset(delete_entry_p));
}
@@ -229,8 +222,8 @@ bucket %d (number of entries now = %d)\n",
memcpy(&share_array[num_entries_copied].time, &entry_scanner_p->e.time,
sizeof(struct timeval));
num_entries_copied++;
- DEBUG(5,("get_share_modes (FAST_SHARE_MODES): Read share mode \
-record mode 0x%X pid=%d\n", entry_scanner_p->e.share_mode, entry_scanner_p->e.pid));
+ 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);
@@ -240,9 +233,8 @@ record mode 0x%X pid=%d\n", entry_scanner_p->e.share_mode, entry_scanner_p->e.pi
/* If no valid share mode entries were found then this record shouldn't exist ! */
if(num_entries_copied == 0)
{
- DEBUG(0,("get_share_modes (FAST_SHARE_MODES): file with dev %d, inode %d in \
-hash bucket %d has a share mode record but no entries - deleting\n",
- dev, inode, hash_entry));
+ 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;
@@ -254,8 +246,8 @@ hash bucket %d has a share mode record but no entries - deleting\n",
shmops->free(shmops->addr2offset(file_scanner_p));
}
- DEBUG(5,("get_share_modes (FAST_SHARE_MODES): file with dev %d, inode %d in \
-hash bucket %d returning %d entries\n", dev, inode, hash_entry, num_entries_copied));
+ DEBUG(5,("get_share_modes: file with dev %d inode %d -> %d entries\n",
+ dev, inode, num_entries_copied));
return(num_entries_copied);
}
@@ -282,9 +274,9 @@ static void shm_del_share_mode(int token, int fnum)
mode_array = (int *)shmops->offset2addr(shmops->get_userdef_off());
- if(mode_array[hash_entry] == NULL_OFFSET)
+ if(mode_array[hash_entry] == 0)
{
- DEBUG(0,("PANIC ERROR:del_share_mode (FAST_SHARE_MODES): hash bucket %d empty\n",
+ DEBUG(0,("PANIC ERROR:del_share_mode hash bucket %d empty\n",
hash_entry));
return;
}
@@ -309,16 +301,15 @@ static void shm_del_share_mode(int token, int fnum)
if(!found)
{
- DEBUG(0,("ERROR:del_share_mode (FAST_SHARE_MODES): no entry found for dev %d, \
-inode %d in hash bucket %d\n", dev, inode, hash_entry));
+ 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 (FAST_SHARE_MODES): Deleting old share mode \
-record due to old locking version %d for file dev %d, inode %d hash bucket %d\n",
- file_scanner_p->locking_version, dev, inode, hash_entry ));
+ 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
@@ -353,9 +344,8 @@ record due to old locking version %d for file dev %d, inode %d hash bucket %d\n"
/* Decrement the number of entries in the record. */
file_scanner_p->num_share_mode_entries -= 1;
- DEBUG(2,("del_share_modes (FAST_SHARE_MODES): \
-Deleting share mode entry dev = %d, inode = %d in hash bucket %d (num entries now = %d)\n",
- dev, inode, hash_entry, file_scanner_p->num_share_mode_entries));
+ 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;
@@ -366,17 +356,16 @@ Deleting share mode entry dev = %d, inode = %d in hash bucket %d (num entries no
/* PARANOIA TEST */
if(file_scanner_p->num_share_mode_entries < 0)
{
- DEBUG(0,("PANIC ERROR:del_share_mode (FAST_SHARE_MODES): num_share_mode_entries < 0 (%d) \
-for dev = %d, ino = %d, hashbucket %d\n", file_scanner_p->num_share_mode_entries,
- dev, inode, hash_entry));
+ 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 (FAST_SHARE_MODES): num entries = 0, deleting share_mode \
-record dev = %d, inode = %d in hash bucket %d\n", dev, inode, hash_entry));
+ 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
@@ -386,8 +375,8 @@ record dev = %d, inode = %d in hash bucket %d\n", dev, inode, hash_entry));
}
else
{
- DEBUG(0,("ERROR: del_share_modes (FAST_SHARE_MODES): No share mode record found \
-dev = %d, inode = %d in hash bucket %d\n", dev, inode, hash_entry));
+ DEBUG(0,("ERROR: del_share_modes No share mode dev=%d ino=%d\n",
+ dev, inode));
}
}
@@ -435,19 +424,18 @@ static BOOL shm_set_share_mode(int token, int fnum, uint16 port, uint16 op_type)
{
/* We must create a share_mode_record */
share_mode_record *new_mode_p = NULL;
- int new_offset = shmops->alloc( sizeof(share_mode_record) +
- strlen(fs_p->name) + 1);
- if(new_offset == NULL_OFFSET)
- {
- DEBUG(0,("ERROR:set_share_mode (FAST_SHARE_MODES): shmops->alloc fail !\n"));
- return False;
+ int new_offset = shmops->alloc(sizeof(share_mode_record) +
+ strlen(fs_p->name) + 1);
+ if(new_offset == 0) {
+ DEBUG(0,("ERROR:set_share_mode shmops->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 = NULL_OFFSET;
+ new_mode_p->share_mode_entries = 0;
strcpy(new_mode_p->file_name, fs_p->name);
/* Chain onto the start of the hash chain (in the hope we will be used first). */
@@ -456,21 +444,20 @@ static BOOL shm_set_share_mode(int token, int fnum, uint16 port, uint16 op_type)
file_scanner_p = new_mode_p;
- DEBUG(3,("set_share_mode (FAST_SHARE_MODES): Created share record for %s (dev %d \
-inode %d in hash bucket %d\n", fs_p->name, dev, inode, hash_entry));
+ 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->alloc( sizeof(shm_share_mode_entry));
- if(new_entry_offset == NULL_OFFSET)
- {
- int delete_offset = mode_array[hash_entry];
- DEBUG(0,("ERROR:set_share_mode (FAST_SHARE_MODES): shmops->alloc fail 1!\n"));
- /* Unlink the damaged record */
- mode_array[hash_entry] = file_scanner_p->next_offset;
- /* And delete it */
- shmops->free( delete_offset );
- return False;
+ new_entry_offset = shmops->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->alloc fail 1!\n"));
+ /* Unlink the damaged record */
+ mode_array[hash_entry] = file_scanner_p->next_offset;
+ /* And delete it */
+ shmops->free( delete_offset );
+ return False;
}
new_entry_p = shmops->offset2addr(new_entry_offset);
@@ -488,18 +475,16 @@ inode %d in hash bucket %d\n", fs_p->name, dev, inode, hash_entry));
/* PARANOIA TEST */
if(file_scanner_p->num_share_mode_entries < 0)
{
- DEBUG(0,("PANIC ERROR:set_share_mode (FAST_SHARE_MODES): num_share_mode_entries < 0 (%d) \
-for dev = %d, ino = %d, hashbucket %d\n", file_scanner_p->num_share_mode_entries,
- dev, inode, hash_entry));
+ 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 (FAST_SHARE_MODES): Created share entry for %s with mode \
-0x%X pid=%d (num_entries now = %d)\n",fs_p->name, fs_p->share_mode, new_entry_p->e.pid,
- file_scanner_p->num_share_mode_entries));
+ 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);
}
@@ -526,9 +511,9 @@ static BOOL shm_remove_share_oplock(int fnum, int token)
mode_array = (int *)shmops->offset2addr(shmops->get_userdef_off());
- if(mode_array[hash_entry] == NULL_OFFSET)
+ if(mode_array[hash_entry] == 0)
{
- DEBUG(0,("PANIC ERROR:remove_share_oplock (FAST_SHARE_MODES): hash bucket %d empty\n",
+ DEBUG(0,("PANIC ERROR:remove_share_oplock: hash bucket %d empty\n",
hash_entry));
return False;
}
@@ -553,16 +538,15 @@ static BOOL shm_remove_share_oplock(int fnum, int token)
if(!found)
{
- DEBUG(0,("ERROR:remove_share_oplock (FAST_SHARE_MODES): no entry found for dev %d, \
-inode %d in hash bucket %d\n", dev, inode, hash_entry));
+ 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 (FAST_SHARE_MODES): Deleting old share mode \
-record due to old locking version %d for file dev %d, inode %d hash bucket %d\n",
- file_scanner_p->locking_version, dev, inode, hash_entry ));
+ 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
@@ -598,8 +582,8 @@ record due to old locking version %d for file dev %d, inode %d hash bucket %d\n"
if(!found)
{
- DEBUG(0,("ERROR: remove_share_oplock (FAST_SHARE_MODES): No oplock granted share \
-mode record found dev = %d, inode = %d in hash bucket %d\n", dev, inode, hash_entry));
+ DEBUG(0,("ERROR: remove_share_oplock: No oplock granted. dev=%d ino=%d\n",
+ dev, inode));
return False;
}
@@ -621,7 +605,7 @@ static int shm_share_forall(void (*fn)(share_mode_entry *, char *))
for( i = 0; i < shmops->hash_size(); i++) {
shmops->lock_hash_entry(i);
- if(mode_array[i] == NULL_OFFSET) {
+ if(mode_array[i] == 0) {
shmops->unlock_hash_entry(i);
continue;
}
diff --git a/source3/locking/shmem.c b/source3/locking/shmem.c
index 909e8dd435..864f7c298b 100644
--- a/source3/locking/shmem.c
+++ b/source3/locking/shmem.c
@@ -70,7 +70,7 @@ struct SmbShmBlockDesc
};
#define EOList_Addr (struct SmbShmBlockDesc *)( 0 )
-#define EOList_Off (NULL_OFFSET)
+#define EOList_Off 0
#define CellSize sizeof(struct SmbShmBlockDesc)
@@ -158,7 +158,7 @@ static BOOL smb_shm_global_unlock(void)
static void *smb_shm_offset2addr(int offset)
{
- if (offset == NULL_OFFSET )
+ if (offset == 0 )
return (void *)(0);
if (!smb_shm_header_p)
@@ -170,10 +170,10 @@ static void *smb_shm_offset2addr(int offset)
static int smb_shm_addr2offset(void *addr)
{
if (!addr)
- return NULL_OFFSET;
+ return 0;
if (!smb_shm_header_p)
- return NULL_OFFSET;
+ return 0;
return (int)((char *)addr - (char *)smb_shm_header_p);
}
@@ -193,7 +193,7 @@ static int smb_shm_alloc(int size)
{
/* not mapped yet */
DEBUG(0,("ERROR smb_shm_alloc : shmem not mapped\n"));
- return NULL_OFFSET;
+ return 0;
}
smb_shm_global_lock();
@@ -202,7 +202,7 @@ static int smb_shm_alloc(int size)
{
DEBUG(0,("ERROR smb_shm_alloc : shmem not consistent\n"));
smb_shm_global_unlock();
- return NULL_OFFSET;
+ return 0;
}
@@ -225,7 +225,7 @@ static int smb_shm_alloc(int size)
{
DEBUG(0,("ERROR smb_shm_alloc : alloc of %d bytes failed, no free space found\n",size));
smb_shm_global_unlock();
- return (NULL_OFFSET);
+ return (0);
}
/* going to modify shared mem */
@@ -296,7 +296,7 @@ static BOOL smb_shm_create_hash_table( unsigned int size )
smb_shm_global_lock();
smb_shm_header_p->userdef_off = smb_shm_alloc( size );
- if(smb_shm_header_p->userdef_off == NULL_OFFSET)
+ if(smb_shm_header_p->userdef_off == 0)
{
DEBUG(0,("smb_shm_create_hash_table: Failed to create hash table of size %d\n",size));
smb_shm_global_unlock();
@@ -486,7 +486,7 @@ static BOOL smb_shm_initialize(int size)
smb_shm_header_p->smb_shm_version = SMB_SHM_VERSION;
smb_shm_header_p->total_size = size;
smb_shm_header_p->first_free_off = AlignedHeaderSize;
- smb_shm_header_p->userdef_off = NULL_OFFSET;
+ smb_shm_header_p->userdef_off = 0;
first_free_block_p = (struct SmbShmBlockDesc *)smb_shm_offset2addr(smb_shm_header_p->first_free_off);
first_free_block_p->next = EOList_Off;
@@ -638,7 +638,7 @@ static BOOL smb_shm_free(int offset)
static int smb_shm_get_userdef_off(void)
{
if (!smb_shm_header_p)
- return NULL_OFFSET;
+ return 0;
else
return smb_shm_header_p->userdef_off;
}
diff --git a/source3/locking/shmem_sysv.c b/source3/locking/shmem_sysv.c
index 8832902820..14ed199738 100644
--- a/source3/locking/shmem_sysv.c
+++ b/source3/locking/shmem_sysv.c
@@ -2,7 +2,7 @@
Unix SMB/Netbios implementation.
Version 1.9.
Shared memory functions - SYSV IPC implementation
- Copyright (C) Erik Devriendt 1996-1997
+ Copyright (C) Andrew Tridgell 1997
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
@@ -53,7 +53,7 @@ extern int DEBUGLEVEL;
#define SHMEM_HASH_SIZE 63
#endif
-#define MIN_SHM_SIZE 10240
+#define MIN_SHM_SIZE 0x1000
static int shm_id;
static int sem_id;
@@ -83,19 +83,18 @@ struct ShmBlockDesc
{
int next; /* offset of next block in the free list or
SHM_NOT_FREE_OFF when block in use */
- int size; /* user size in BlockDescSize units */
+ int size; /* user size in BlockDescSize units */
};
-#define EOList_Addr (struct ShmBlockDesc *)( 0 )
-#define EOList_Off (NULL_OFFSET)
+#define EOList_Addr NULL
+#define EOList_Off (0)
#define CellSize sizeof(struct ShmBlockDesc)
-/* HeaderSize aligned on 8 byte boundary */
-#define AlignedHeaderSize ((sizeof(struct ShmHeader)+7) & ~7)
-
-static struct ShmHeader *shm_header_p = (struct ShmHeader *)0;
+/* HeaderSize aligned on a 8 byte boundary */
+#define AlignedHeaderSize ((sizeof(struct ShmHeader)+7) & ~7)
+static struct ShmHeader *shm_header_p = NULL;
static BOOL shm_initialize_called = False;
static int read_only;
@@ -156,22 +155,22 @@ static BOOL global_unlock(void)
static void *shm_offset2addr(int offset)
{
- if (offset == NULL_OFFSET )
+ if (offset == 0 )
return (void *)(0);
if (!shm_header_p)
return (void *)(0);
- return (void *)((char *)shm_header_p + offset );
+ return (void *)((char *)shm_header_p + offset);
}
static int shm_addr2offset(void *addr)
{
if (!addr)
- return NULL_OFFSET;
+ return 0;
if (!shm_header_p)
- return NULL_OFFSET;
+ return 0;
return (int)((char *)addr - (char *)shm_header_p);
}
@@ -189,7 +188,7 @@ static int shm_alloc(int size)
if (!shm_header_p) {
/* not mapped yet */
DEBUG(0,("ERROR shm_alloc : shmem not mapped\n"));
- return NULL_OFFSET;
+ return 0;
}
global_lock();
@@ -197,13 +196,13 @@ static int shm_alloc(int size)
if (!shm_header_p->consistent) {
DEBUG(0,("ERROR shm_alloc : shmem not consistent\n"));
global_unlock();
- return NULL_OFFSET;
+ return 0;
}
- /* calculate the number of cells */
- num_cells = (size + CellSize -1) / CellSize;
+ /* calculate the number of cells */
+ num_cells = (size + (CellSize-1)) / CellSize;
- /* set start of scan */
+ /* set start of scan */
prev_p = (struct ShmBlockDesc *)shm_offset2addr(shm_header_p->first_free_off);
scanner_p = prev_p ;
@@ -216,144 +215,50 @@ static int shm_alloc(int size)
/* at this point scanner point to a block header or to the end of
the list */
if (scanner_p == EOList_Addr) {
- DEBUG(0,("ERROR shm_alloc : alloc of %d bytes failed, no free space found\n",size));
+ DEBUG(0,("ERROR shm_alloc : alloc of %d bytes failed\n",size));
global_unlock();
- return (NULL_OFFSET);
+ return (0);
}
/* going to modify shared mem */
shm_header_p->consistent = False;
/* if we found a good one : scanner == the good one */
- if (scanner_p->size <= num_cells + 2) {
- /* there is no use in making a new one, it will be too small anyway
- * we will link out scanner
- */
- if ( prev_p == scanner_p ) {
- shm_header_p->first_free_off = scanner_p->next ;
- } else {
- prev_p->next = scanner_p->next ;
- }
- shm_header_p->statistics.cells_free -= scanner_p->size;
- shm_header_p->statistics.cells_used += scanner_p->size;
- } else {
+ if (scanner_p->size > num_cells + 2) {
/* Make a new one */
new_p = scanner_p + 1 + num_cells;
- new_p->size = scanner_p->size - num_cells - 1;
+ new_p->size = scanner_p->size - (num_cells + 1);
new_p->next = scanner_p->next;
scanner_p->size = num_cells;
scanner_p->next = shm_addr2offset(new_p);
-
- if (prev_p != scanner_p) {
- prev_p->next = shm_addr2offset(new_p) ;
- } else {
- shm_header_p->first_free_off = shm_addr2offset(new_p);
- }
- shm_header_p->statistics.cells_free -= num_cells+1;
- shm_header_p->statistics.cells_used += num_cells;
+
+ shm_header_p->statistics.cells_free -= 1;
shm_header_p->statistics.cells_system += 1;
}
- result_offset = shm_addr2offset( &(scanner_p[1]) );
- scanner_p->next = SHM_NOT_FREE_OFF ;
+ /* take it from the free list */
+ if (prev_p == scanner_p) {
+ shm_header_p->first_free_off = scanner_p->next;
+ } else {
+ prev_p->next = scanner_p->next;
+ }
+ shm_header_p->statistics.cells_free -= scanner_p->size;
+ shm_header_p->statistics.cells_used += scanner_p->size;
+
+ result_offset = shm_addr2offset(&(scanner_p[1]));
+ scanner_p->next = SHM_NOT_FREE_OFF;
/* end modification of shared mem */
shm_header_p->consistent = True;
-
- DEBUG(6,("shm_alloc : request for %d bytes, allocated %d bytes at offset %d\n",size,scanner_p->size*CellSize,result_offset ));
global_unlock();
+
+ DEBUG(6,("shm_alloc : allocated %d bytes at offset %d\n",
+ size,result_offset));
+
return result_offset;
}
-
-
-/*
- * Function to create the hash table for the share mode entries. Called
- * when smb shared memory is global locked.
- */
-static BOOL shm_create_hash_table( unsigned int size )
-{
- size *= sizeof(int);
-
- global_lock();
- shm_header_p->userdef_off = shm_alloc( size );
-
- if(shm_header_p->userdef_off == NULL_OFFSET) {
- DEBUG(0,("shm_create_hash_table: Failed to create hash table of size %d\n",size));
- global_unlock();
- return False;
- }
-
- /* Clear hash buckets. */
- memset( shm_offset2addr(shm_header_p->userdef_off), '\0', size);
- global_unlock();
- return True;
-}
-
-static BOOL shm_validate_header(int size)
-{
- if( !shm_header_p ) {
- /* not mapped yet */
- DEBUG(0,("ERROR shm_validate_header : shmem not mapped\n"));
- return False;
- }
-
- if(shm_header_p->shm_magic != SHM_MAGIC) {
- DEBUG(0,("ERROR shm_validate_header : bad magic\n"));
- return False;
- }
-
- if(shm_header_p->shm_version != SHM_VERSION) {
- DEBUG(0,("ERROR shm_validate_header : bad version %X\n",shm_header_p->shm_version));
- return False;
- }
-
- if(shm_header_p->total_size != size) {
- DEBUG(0,("ERROR shm_validate_header : shmem size mismatch (old = %d, new = %d)\n",shm_header_p->total_size,size));
- return False;
- }
-
- if(!shm_header_p->consistent) {
- DEBUG(0,("ERROR shm_validate_header : shmem not consistent\n"));
- return False;
- }
- return True;
-}
-
-static BOOL shm_initialize(int size)
-{
- struct ShmBlockDesc * first_free_block_p;
-
- DEBUG(5,("shm_initialize : initializing shmem file of size %d\n",size));
-
- if( !shm_header_p ) {
- /* not mapped yet */
- DEBUG(0,("ERROR shm_initialize : shmem not mapped\n"));
- return False;
- }
-
- shm_header_p->shm_magic = SHM_MAGIC;
- shm_header_p->shm_version = SHM_VERSION;
- shm_header_p->total_size = size;
- shm_header_p->first_free_off = AlignedHeaderSize;
- shm_header_p->userdef_off = NULL_OFFSET;
-
- first_free_block_p = (struct ShmBlockDesc *)shm_offset2addr(shm_header_p->first_free_off);
- first_free_block_p->next = EOList_Off;
- first_free_block_p->size = ( size - AlignedHeaderSize - CellSize ) / CellSize ;
-
- shm_header_p->statistics.cells_free = first_free_block_p->size;
- shm_header_p->statistics.cells_used = 0;
- shm_header_p->statistics.cells_system = 1;
-
- shm_header_p->consistent = True;
-
- shm_initialize_called = True;
-
- return True;
-}
-
static void shm_solve_neighbors(struct ShmBlockDesc *head_p )
{
struct ShmBlockDesc *next_p;
@@ -364,9 +269,9 @@ static void shm_solve_neighbors(struct ShmBlockDesc *head_p )
if ( head_p->next == EOList_Off ) return ;
next_p = (struct ShmBlockDesc *)shm_offset2addr(head_p->next);
- if ( ( head_p + head_p->size + 1 ) == next_p) {
- head_p->size += next_p->size +1 ; /* adapt size */
- head_p->next = next_p->next ; /* link out */
+ if ((head_p + head_p->size + 1) == next_p) {
+ head_p->size += next_p->size + 1; /* adapt size */
+ head_p->next = next_p->next; /* link out */
shm_header_p->statistics.cells_free += 1;
shm_header_p->statistics.cells_system -= 1;
@@ -374,21 +279,13 @@ static void shm_solve_neighbors(struct ShmBlockDesc *head_p )
}
-
-
-static BOOL shm_close( void )
-{
- return True;
-}
-
-
static BOOL shm_free(int offset)
{
struct ShmBlockDesc *header_p; /* pointer to header of
- block to free */
+ block to free */
struct ShmBlockDesc *scanner_p; /* used to scan the list */
struct ShmBlockDesc *prev_p; /* holds previous in the
- list */
+ list */
if (!shm_header_p) {
/* not mapped yet */
@@ -416,14 +313,16 @@ static BOOL shm_free(int offset)
/* find a place in the free_list to put the header in */
/* set scanner and previous pointer to start of list */
- prev_p = (struct ShmBlockDesc *)shm_offset2addr(shm_header_p->first_free_off);
+ prev_p = (struct ShmBlockDesc *)
+ shm_offset2addr(shm_header_p->first_free_off);
scanner_p = prev_p ;
while ((scanner_p != EOList_Addr) &&
(scanner_p < header_p)) {
/* while we didn't scan past its position */
prev_p = scanner_p ;
- scanner_p = (struct ShmBlockDesc *)shm_offset2addr(scanner_p->next);
+ scanner_p = (struct ShmBlockDesc *)
+ shm_offset2addr(scanner_p->next);
}
shm_header_p->consistent = False;
@@ -436,11 +335,12 @@ static BOOL shm_free(int offset)
shm_header_p->statistics.cells_used -= header_p->size;
/* we must free it at the beginning of the list */
- shm_header_p->first_free_off = shm_addr2offset(header_p); /* set the free_list_pointer to this block_header */
+ shm_header_p->first_free_off = shm_addr2offset(header_p);
+ /* set the free_list_pointer to this block_header */
/* scanner is the one that was first in the list */
header_p->next = shm_addr2offset(scanner_p);
- shm_solve_neighbors( header_p ); /* if neighbors then link them */
+ shm_solve_neighbors(header_p);
shm_header_p->consistent = True;
} else {
@@ -460,14 +360,113 @@ static BOOL shm_free(int offset)
}
+/*
+ * Function to create the hash table for the share mode entries. Called
+ * when smb shared memory is global locked.
+ */
+static BOOL shm_create_hash_table(unsigned int hash_entries)
+{
+ int size = hash_entries * sizeof(int);
+
+ global_lock();
+ shm_header_p->userdef_off = shm_alloc(size);
+
+ if(shm_header_p->userdef_off == 0) {
+ DEBUG(0,("shm_create_hash_table: Failed to create hash table of size %d\n",
+ size));
+ global_unlock();
+ return False;
+ }
+
+ /* Clear hash buckets. */
+ memset(shm_offset2addr(shm_header_p->userdef_off), '\0', size);
+ global_unlock();
+ return True;
+}
+
+
+static BOOL shm_validate_header(int size)
+{
+ if(!shm_header_p) {
+ /* not mapped yet */
+ DEBUG(0,("ERROR shm_validate_header : shmem not mapped\n"));
+ return False;
+ }
+
+ if(shm_header_p->shm_magic != SHM_MAGIC) {
+ DEBUG(0,("ERROR shm_validate_header : bad magic\n"));
+ return False;
+ }
+
+ if(shm_header_p->shm_version != SHM_VERSION) {
+ DEBUG(0,("ERROR shm_validate_header : bad version %X\n",
+ shm_header_p->shm_version));
+ return False;
+ }
+
+ if(shm_header_p->total_size != size) {
+ DEBUG(0,("ERROR shmem size mismatch (old = %d, new = %d)\n",
+ shm_header_p->total_size,size));
+ return False;
+ }
+
+ if(!shm_header_p->consistent) {
+ DEBUG(0,("ERROR shmem not consistent\n"));
+ return False;
+ }
+ return True;
+}
+
+
+static BOOL shm_initialize(int size)
+{
+ struct ShmBlockDesc * first_free_block_p;
+
+ DEBUG(5,("shm_initialize : initializing shmem size %d\n",size));
+
+ if( !shm_header_p ) {
+ /* not mapped yet */
+ DEBUG(0,("ERROR shm_initialize : shmem not mapped\n"));
+ return False;
+ }
+
+ shm_header_p->shm_magic = SHM_MAGIC;
+ shm_header_p->shm_version = SHM_VERSION;
+ shm_header_p->total_size = size;
+ shm_header_p->first_free_off = AlignedHeaderSize;
+ shm_header_p->userdef_off = 0;
+
+ first_free_block_p = (struct ShmBlockDesc *)
+ shm_offset2addr(shm_header_p->first_free_off);
+ first_free_block_p->next = EOList_Off;
+ first_free_block_p->size =
+ (size - (AlignedHeaderSize+CellSize))/CellSize;
+ shm_header_p->statistics.cells_free = first_free_block_p->size;
+ shm_header_p->statistics.cells_used = 0;
+ shm_header_p->statistics.cells_system = 1;
+
+ shm_header_p->consistent = True;
+
+ shm_initialize_called = True;
+
+ return True;
+}
+
+static BOOL shm_close( void )
+{
+ return True;
+}
+
+
static int shm_get_userdef_off(void)
{
if (!shm_header_p)
- return NULL_OFFSET;
+ return 0;
else
return shm_header_p->userdef_off;
}
+
/*******************************************************************
Lock a particular hash bucket entry.
******************************************************************/
@@ -500,7 +499,8 @@ static BOOL shm_get_usage(int *bytes_free,
*bytes_free = shm_header_p->statistics.cells_free * CellSize;
*bytes_used = shm_header_p->statistics.cells_used * CellSize;
- *bytes_overhead = shm_header_p->statistics.cells_system * CellSize + AlignedHeaderSize;
+ *bytes_overhead = shm_header_p->statistics.cells_system * CellSize +
+ AlignedHeaderSize;
return True;
}