[comp.os.minix] ST Minix 1.5 Fix for Getdents.c

cechew@bruce.OZ (Earl Chew) (02/13/90)

Posted on behalf of: R_Prandolini@csvax.qut.oz

Here is the fix for the recently supplied getdents.c with the Minix ST 1.5
upgrade package.


The problem is caused in the way getdents constructs its list of names in
an irregular array. The structure used to hold the info is incremented in
size by reclen for each file name then referenced as a struct * this cast
from char * to struct * causes an address error when the size of the
filename is odd. The fix I have implemented is the simplest, if reclen is
forced to be an even number, the address will never be odd but one byte is
wasted on odd length filenames. There is undoubtably a better fix than this
(involving manipulating the struct bp only as a char * ) but this requires
minimal code changes ( the fix will work on the pc as well ) and even 
allignment of the struct allows faster handling ( no byte instructions ).

If anybody knows a better way , Please, be my guest .

This fix includes the previously posted alterations to the macro definitions





------------------------cut here---------cut here------------------------



echo x - getdents.cdiff
sed '/^X/s///' > getdents.cdiff << '/'
X*** /usr/src/lib/other/getdents.c	Fri Jan 26 22:58:01 1990
X--- getdents.c	Sat Feb 10 06:58:18 1990
X***************
X*** 59,68 ****
X  #include	<signal.h>
X  #endif
X  
X- #ifdef BSD_SYSV
X- struct dirent __dirent;		/* (just for the DIRENTBASESIZ macro) */
X- #endif
X- 
X  #ifdef UFS
X  #define	RecLen( dp )	(sizeof(struct direct))	/* fixed-length entries */
X  #else				/* BFS || NFS */
X--- 59,64 ----
X***************
X*** 93,103 ****
X  #define	DELETED	0
X  #endif
X  
X! #ifndef DIRENTSIZ
X! #define DIRENTSIZ(x)	(x)
X! #endif
X! #ifndef DIRENTBASESIZ
X! #define DIRENTBASESIZ 0
X  #endif
X  #ifndef DIRBLKSIZ
X  #define	DIRBLKSIZ	4096	/* directory file read buffer size */
X--- 89,101 ----
X  #define	DELETED	0
X  #endif
X  
X! #ifndef DIRENTBASESIZ
X! struct dirent __dirent;		/* (just for the DIRENTBASESIZ macro) */
X! #define DIRENTBASESIZ sizeof(__dirent) + 1  /*+1 is for eostring*/
X! #endif
X! 
X! #ifndef DIRENTSIZ
X! #define DIRENTSIZ(x)	(x + DIRENTBASESIZ)
X  #endif
X  #ifndef DIRBLKSIZ
X  #define	DIRBLKSIZ	4096	/* directory file read buffer size */
X***************
X*** 263,269 ****
X  		if (dp->d_fileno != DELETED) {	/* non-empty; copy to
X  						 * user buffer */
X  			register int reclen =
X! 			DIRENTSIZ(NameLen(dp->d_name));
X  
X  			if ((char *) bp + reclen > &buf[nbyte]) {
X  				errno = EINVAL;
X--- 261,267 ----
X  		if (dp->d_fileno != DELETED) {	/* non-empty; copy to
X  						 * user buffer */
X  			register int reclen =
X! 			(DIRENTSIZ(NameLen(dp->d_name))+1)&(~1); /* force word alignment */
X  
X  			if ((char *) bp + reclen > &buf[nbyte]) {
X  				errno = EINVAL;
/

-- 
Earl Chew, Dept of Computer Science, Monash University, Australia 3168
ARPA: cechew%bruce.cs.monash.oz.au@uunet.uu.net  ACS : cechew@bruce.oz
----------------------------------------------------------------------