freebsd-nq/share
Kirk McKusick fdece2b8f7 Declare a `struct extattr' that defines the format of an extended
attribute. Also define some macros to manipulate one of these
structures. Explain their use in the extattr.9 manual page.

The next step will be to make a sweep through the kernel replacing
the old pointer manipulation code. To get an idea of how they would
be used, the ffs_findextattr() function in ufs/ffs/ffs_vnops.c is
currently written as follows:

/*
 * Vnode operating to retrieve a named extended attribute.
 *
 * Locate a particular EA (nspace:name) in the area (ptr:length), and return
 * the length of the EA, and possibly the pointer to the entry and to the data.
 */
static int
ffs_findextattr(u_char *ptr, u_int length, int nspace, const char *name,
    u_char **eap, u_char **eac)
{
	u_char *p, *pe, *pn, *p0;
	int eapad1, eapad2, ealength, ealen, nlen;
	uint32_t ul;

	pe = ptr + length;
	nlen = strlen(name);

	for (p = ptr; p < pe; p = pn) {
		p0 = p;
		bcopy(p, &ul, sizeof(ul));
		pn = p + ul;
		/* make sure this entry is complete */
		if (pn > pe)
			break;
		p += sizeof(uint32_t);
		if (*p != nspace)
			continue;
		p++;
		eapad2 = *p++;
		if (*p != nlen)
			continue;
		p++;
		if (bcmp(p, name, nlen))
			continue;
		ealength = sizeof(uint32_t) + 3 + nlen;
		eapad1 = 8 - (ealength % 8);
		if (eapad1 == 8)
			eapad1 = 0;
		ealength += eapad1;
		ealen = ul - ealength - eapad2;
		p += nlen + eapad1;
		if (eap != NULL)
			*eap = p0;
		if (eac != NULL)
			*eac = p;
		return (ealen);
	}
	return(-1);
}

After applying the structure and macros, it would look like this:

/*
 * Vnode operating to retrieve a named extended attribute.
 *
 * Locate a particular EA (nspace:name) in the area (ptr:length), and return
 * the length of the EA, and possibly the pointer to the entry and to the data.
 */
static int
ffs_findextattr(u_char *ptr, u_int length, int nspace, const char *name,
    u_char **eapp, u_char **eac)
{
	struct extattr *eap, *eaend;

	eaend = (struct extattr *)(ptr + length);
	for (eap = (struct extattr *)ptr; eap < eaend; eap = EXTATTR_NEXT(eap)){
		/* make sure this entry is complete */
		if (EXTATTR_NEXT(eap) > eaend)
			break;
		if (eap->ea_namespace != nspace ||
		    eap->ea_namelength != length ||
		    bcmp(eap->ea_name, name, length))
			continue;
		if (eapp != NULL)
			*eapp = eap;
		if (eac != NULL)
			*eac = EXTATTR_CONTENT(eap);
		return (EXTATTR_CONTENT_SIZE(eap));
	}
	return(-1);
}

Not only is it considerably shorter, but it hopefully more readable :-)
2007-02-26 06:18:53 +00:00
..
colldef Add locales for nb_NO and nn_NO. 2006-11-09 18:10:34 +00:00
dict Correct typos containing my login name (plus one more in expr.y). 2007-02-18 19:48:59 +00:00
doc Remove some comments about NetBSD. This in on FreeBSD and we do not 2006-11-12 18:38:07 +00:00
examples - Add ports-ports-mgmt collection 2007-01-31 14:35:05 +00:00
info Start the dreaded NOFOO -> NO_FOO conversion. 2004-12-21 08:47:35 +00:00
isdn
man Declare a `struct extattr' that defines the format of an extended 2007-02-26 06:18:53 +00:00
me
misc o DragonFly 1.8.0 added. 2007-01-31 04:58:03 +00:00
mk Remove old libmytinfo link. 2007-02-01 08:45:27 +00:00
mklocale Add locales for nb_NO and nn_NO. 2006-11-09 18:10:34 +00:00
monetdef Add locales for nb_NO and nn_NO. 2006-11-09 18:10:34 +00:00
msgdef Add locales for nb_NO and nn_NO. 2006-11-09 18:10:34 +00:00
numericdef Add locales for nb_NO and nn_NO. 2006-11-09 18:10:34 +00:00
security Start the dreaded NOFOO -> NO_FOO conversion. 2004-12-21 08:47:35 +00:00
sendmail Start the dreaded NOFOO -> NO_FOO conversion. 2004-12-21 08:47:35 +00:00
skel Start the dreaded NOFOO -> NO_FOO conversion. 2004-12-21 08:47:35 +00:00
snmp Define a base OID for the FreeBSD version as returned in sysObjectID 2006-10-31 10:09:10 +00:00
syscons Fix hr.iso syscons keymap, making it possible to type < and >. 2007-02-04 17:10:18 +00:00
tabset
termcap Backout my last changes. ISO-8859-15 does not specify ACS graphics. 2006-04-30 09:05:56 +00:00
timedef Add locales for nb_NO and nn_NO. 2006-11-09 18:10:34 +00:00
zoneinfo Update with the latest Bulletin C from IERS. 2007-02-02 09:19:27 +00:00
Makefile Reimplementation of world/kernel build options. For details, see: 2006-03-17 18:54:44 +00:00
Makefile.inc