Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!hp4nl!ruuinf!edwin From: edwin@ruuinf.cs.ruu.nl (Edwin Kremer) Newsgroups: comp.os.minix Subject: ST-MINIX 1.5.5 "getcwd" library fix Keywords: getcwd, libc.a, pwd, bug + patch Message-ID: <2746@ruuinf.cs.ruu.nl> Date: 27 Mar 90 22:43:23 GMT Organization: Utrecht University, Dept. of CS Lines: 51 We came across a bug in the "getcwd" library function in ST-MINIX 1.5.5, it might also occur in the PC version (actually, we're almost sure because the PC<->ST POSIX libraries are equal, aren't they?). As it turns out, getcwd() does *not* skip unused directory slots, e.g. entries that are no longer in use and have inode number 0 assigned. Ok, here's an example (some imaginary directory dump) d_ino d_name ============================ 1 . 1 .. 123 valid_file1 0 invalid_file 45 valid_file2 getcwd() loops through this directory to lookup an inode number; for every entry, it does a "stat()" system call on ``d_name''. On the fourth entry it stats "invalid_file" (inode 0 ==> free slot): stat() fails and getcwd() returns NULL. E.g. "/bin/pwd" now complains: "Can't search some directory on the path". The following (unofficial!!) patch fixes this problem. Good luck, Bart Muijzer Edwin Kremer ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *** getcwd.c.old Tue Mar 27 23:22:44 1990 --- getcwd.c Tue Mar 27 23:14:41 1990 *************** *** 52,57 **** --- 52,61 ---- /* Search the parent directory for the current entry */ if ((fd = open(".", O_RDONLY)) == -1) return((char *)NULL); while (!found && read(fd, (char *)&d, DIRECT_SIZE) == DIRECT_SIZE) { + if ( d.d_ino == 0 ) + /* skip free (unused) directory slots */ + continue; if (same_device) { if (current.st_ino == d.d_ino) found = 1; } else { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Edwin Kremer (SysAdm), Dept. of Computer Science, Utrecht University Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands Telephone: +31-30-534104 | UUCP: ...!uunet!mcsun!hp4nl!ruuinf!edwin Telefax : +31-30-513791 | Email: edwin@cs.ruu.nl [131.211.80.5]