Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!ucbvax!hplabs!hpl-opus!hpccc!culberts From: culberts@hpccc.HP.COM (Bruce Culbertson) Newsgroups: comp.os.minix Subject: Re: getdents.c bug fix, fixes new ls also Message-ID: <6910005@hpccc.HP.COM> Date: 28 Aug 89 21:04:11 GMT References: <6910004@hpccc.HP.COM> Organization: Hewlett-Packard Co. Lines: 79 I regret to say that the original bug fix I posted for getdents.c was not entirely correct. Previously I tested it with readdir(), which unfortunately did not expose the problem which still existed. I have tested the new version with a good sampling of directory sizes and buffer sizes. I hope this will be my last message on this subject! This cdif is relative to the original 1.4a version. Bruce Culbertson culberts@hplabs.hp.com --------------------------------- cut ---------------------------------- *** getdents.old Thu Aug 24 09:04:24 1989 --- getdents.c Thu Aug 24 18:28:17 1989 *************** *** 100,107 **** #endif #ifndef DIRBLKSIZ ! #define DIRBLKSIZ 4096 /* directory file read buffer size */ #endif #ifndef NULL #define NULL 0 --- 100,117 ---- #endif #ifndef DIRBLKSIZ ! /* directory file read buffer size ! * For directory files with fixed sized records, this should be a ! * multiple of the record size. For variable sized records, this code ! * is probably unreliable if the directory is larger than DIRBLKSIZ -- ! * so make DIRBLKSIZ big. ! */ ! #ifdef UFS ! #define DIRBLKSIZ (64*sizeof(struct direct)) ! #else ! #define DIRBLKSIZ 4096 #endif + #endif #ifndef NULL #define NULL 0 *************** *** 109,114 **** --- 119,125 ---- #ifndef SEEK_CUR #define SEEK_CUR 1 + #define SEEK_SET 0 #endif #ifndef S_ISDIR /* macro to test for directory file */ *************** *** 275,282 **** if ( (char *)bp + reclen > &buf[nbyte] ) { ! errno = EINVAL; ! return -1; /* buf too small */ } bp->d_ino = dp->d_fileno; --- 286,302 ---- if ( (char *)bp + reclen > &buf[nbyte] ) { ! /* buf too small, lseek so we get the ! * rest on next call to getdents() ! */ ! if (lseek (fildes, ! (long)((char *)dp-u.dblk+offset), ! SEEK_SET) < 0) ! { ! /* errno set by lseek */ ! return -1; ! } ! break; } bp->d_ino = dp->d_fileno;