I have written a utility in c on unix that will show all locked records in a
C-ISAM file. This has worked a treat, until we upgraded to C-ISAM 5.
The program now returns with no lock information. How has the locking
changed in C-ISAM from version 3 to 5+ ?
I am using fcntl() on the UNIX machine to check for locks, with a locking
table offset of 0x40000000L - is this what has changed ? if so what has it
changed to ?
Any help would be much appreciated.
Regards,
Robin Grayson.
It may have changed but I doubt it.
I know that once upon a very long time ago, I had to change the locking
base on a port of the old Informix 3.30 C-ISAM from the 1 GB (0x40000000)
default value to half that value because locking stopped working at 1 GB
(this was on a very old HP-UX; I think it was HP-UX 8.x, but it might have
been still older).
Why don't you lock record 1 in a C-ISAM file using the C-ISAM calls, and
then open the data file through normal Unix open() and then use fcntl to
determine where the locks in the range 0..0x7FFFFFFF are? I think you can
do that with a fcntl() call with the F_GETLK command and an flock structure
with l_whence = SEEK_SET, l_start = 0, l_len = 0x7FFFFFFF, l_type = F_WRLCK
applied to the file descriptor (not the ISAM file descriptor) of the .dat
file.
Yours,
Jonathan Leffler (jlef...@informix.com) #include <witticism.h>
Guardian of DBD::Informix v0.60 -- http://www.perl.com/CPAN
Informix IDN for D4GL & Linux -- http://www.informix.com/idn
I have tried as you suggested, it again, works ok if I link with C-ISAM
3.10.03B, but simply refuses to find any locks if I link with C-ISAM
5.05.UC2.
Here is the source for the program used to lock a record.....
----snip-----
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <isam.h>
void main(void)
{
int ret,fd,datfd;
struct dictinfo info;
char *rec;
fd=isopen("ffterm",ISMANULOCK+ISINOUT);
if(fd<0) {
printf("Error opening file: %d\n",iserrno);
exit(1);
}
isindexinfo(fd,&info,0);
printf("record size=%d, records=%d\n",info.di_recsize,info.di_nrecords);
rec = (char *)malloc(info.di_recsize+5);
isread(fd,rec,ISFIRST+ISLOCK);
printf("Locked record : %.20s - press return to unlock\n",rec,iserrno);
getchar();
free(rec);
isclose(fd);
close(datfd);
}
----- snip ------
And here is the code I am using to check for a lock on the .dat file ...
----- snip ------
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <isam.h>
int lock(int fd,unsigned long loc,unsigned long len);
void main(void)
{
int ret,fd,datfd;
struct dictinfo info;
fd=isopen("ffterm",ISMANULOCK+ISINOUT);
if(fd<0) {
printf("Error opening file: %d\n",iserrno);
exit(1);
}
if((datfd=open("ffterm.dat",O_RDWR))<0) {
printf("Error opening file: %d\n",errno);
exit(2);
}
isindexinfo(fd,&info,0);
printf("record size=%d, records=%d\n",info.di_recsize,info.di_nrecords);
if(lock(datfd,0,0x7FFFFFFFL)) {
printf("There is a lock somewhere....\n");
} else printf("There are no locks on that file\n");
isclose(fd);
close(datfd);
}
int lock(int fd,unsigned long loc,unsigned long len)
{
int retc;
struct flock arg;
arg.l_whence = SEEK_SET;
arg.l_start = loc;
arg.l_len = len;
arg.l_type = F_WRLCK;
retc=fcntl(fd,F_GETLK,&arg);
if(arg.l_type==F_UNLCK)
return(0);
else
return(1);
}
If I link the programs with C-ISAM version 3.10.03B, this is the output
.....
---snip---
record size=2500, records=40
There is a lock somewhere....
---snip---
If I link the programs with C-ISAM version 5.05.UC2, this is the output.....
---snip---
record size=2500, records=40
There are no locks on that file
---snip---
even though there are locks on that file.
Please can you offer any more help ? I am desparate to get this working :-(
Thanks again,
Robin Grayson
> Thanks for your reply,
>
> I have tried as you suggested, it again, works ok if I link with C-ISAM
> 3.10.03B, but simply refuses to find any locks if I link with C-ISAM
> 5.05.UC2.
I remember that Informix changed the lock method in the past
and the two methods cannot coexist.
There is a lot of info in Informix-SE documentation.
Bye.
--
am