lock driver

utzoo!decvax!ucbvax!unix-wizards utzoo!decvax!ucbvax!unix-wizards
Wed Aug 19 06:41:59 AEST 1981


>From dsp.dove at MIT-SPEECH@MIT-AI Wed Aug 19 06:37:34 1981
How about this:

long lock[8];			/* lock bits (one/minor-dev) */
lkopen(dev, flag)
dev_t dev;
int flag;
{
	register int word, bit, mdev;

	mdev = minor(dev);

	word = mdev/32;
	bit = mdev%32;
	if( lock[word] & (1L<<bit) )
	{
		u.uerror = EPERM;
		return;
	}
	else
		lock[word] |= (1L<<bit);
}

lkclose(dev, flag)
dev_t dev;
int flag;
{
	register int word, bit, mdev;

	mdev = minor(dev);

	word = mdev/32;
	bit = mdev%32;
	if( (lock[word] & (1L<<bit)) == 0 )
	{
		printf("lock %d not set\n", mdev);
		return;
	}
	else
		lock[word] &= ~(1L<<bit);
}

This would give you 256 locks of various names and no problems with clearing
them when programs crash.  It might even work on a vax!
-------





More information about the Comp.unix.wizards mailing list