Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!udel!mmdf From: Postmaster@locke.bitnet (PMDF Mail Server) Newsgroups: comp.os.minix Subject: Undeliverable mail Message-ID: <852@louie.udel.EDU> Date: 18 Dec 87 18:25:52 GMT Sender: mmdf@udel.EDU Lines: 471 The message could not be delivered to: Addressee: MINIX Reason: %MAIL-E, no such user MINIX at node LOCKE ---------------------------------------- Received: from JNET-DAEMON by locke.hs.washington.edu; Fri, 18 Dec 87 10:22 PST Received: From NDSUVM1(MAILER) by UWALOCKE with RSCS id 2697 for MINIX@UWALOCKE; Fri, 18 Dec 87 10:21 PST Received: by NDSUVM1 (Mailer X1.24) id 2651; Fri, 18 Dec 87 11:03:59 CST Date: 17 Dec 87 05:17:23 GMT From: Freeman Pascal Subject: Directory(3) library calls for MINIX Sender: Minix operating system To: Local Redistribution Reply-to: INFO-MINIX@UDEL.edu Comments: To: info-minix@UDEL.EDU Hello, Here I am again. This time I have the directory(3) library calls. I have followed the BSD description as closely as the BSD 4.3 PRM allows me to (some entries have so little info in them). I hope they can be of some use. N O T E ------- I would not suggest using these routines if you already have a tried and tested set of directory functions that work for you. Use these as a last resort (I have such confidence in my code). I know the readdir(), opendir(), and closedir() work properly. Although, I had to make some assumptions on how to implement telldir() and seekdir(). I basicly decided to pass and returned what was needed for the lseek() call. I hope this was correct. If anyone knows the correct specs on these calls or know where to point me to please do. Enjoy. Freeman P. Pascal IV ncpascal@ndsuvax # /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh INSTALL <<'END_OF_INSTALL' XManifest: X-------- X INSTALL this file X Makefile makefile for tty X makelibc shell script to make C library X tst.c test file for directory(3) X dir.c library function to return tty name (see directory(3)) X XInstallation instructions: X------------------------- X X1. install dir.h in /usr/include/sys. X X2. Add "typedef unshort ino_t" or "#define ino_t inode_nr" to X /usr/include/sys/types.h depending on your thinking how this X declaration should be handled. X X3. Compile dir.c as a library routine and place in /usr/lib/libc.a. X If you are using the makelibc shell script that was posted quite X awhile back just append "ar av libc.a dir.s" to the beginning and run. X I am including my version if you don't have it. X X4. Run makefile to compile tst.c and run it to test directory(3). X X5. Enjoy X XNotes: X----- X X I'm not sure on the exact operations performed by telldir() and Xseekdir(). I set up telldir() to return the current position (long int Xlike seek()) within the opened directory. Seekdir() was set up likewise, Xit will set the file postion within the opened directory without regard Xif it entry boundries or if the entry is active (d_ino entry is non-zero). X X In all actuality, I would suggest that if you use the POSIX version of Xdirectory(3) that came across the net lately. At the time I wrote these Xroutines I was attempting to get the BSD version of arc to work under MINIX. XI am now leaning towards using the POSIX implementation. I am including Xthese only for the sake of completeness for my scandir(3) routines I'm also Xposting. X X I must also state I don't garentee that theses routines work correctly. XI have tested them and found them to work as I need them to. I would Xsuggest you run them through your own tests to decide if they work for Xyour own purposes. (Gee - I have such confidence in my own code :-) X X Freeman P. Pascal IV X ncpascal@ndsuvax END_OF_INSTALL if test 1907 -ne `wc -c Makefile <<'END_OF_Makefile' XCFLAGS=-T. -i X Xall: tst dir.s X Xtst: tst.s dir.s X @cc -o tst $(CFLAGS) tst.s dir.s X @echo "Done." X Xtst.s: tst.c X Xdir.s: dir.c END_OF_Makefile if test 125 -ne `wc -c dir.c <<'END_OF_dir.c' X/* X * dirs.c - BSD 4.x compatible directory functions X * X * Freeman P. Pascal IV X */ X/* X * History: X * X * 04 Dec 87 fpp Creation X */ X#include X#include X#include X#include X#include X X#ifndef VOID X#define VOID void X#endif X X#ifndef PUBLIC X#define PUBLIC X#endif X X#ifndef NULL X#define NULL 0 X#endif X X#define loop while( 1 ) /* loop forever */ X Xstruct direct __dir; Xextern int errno; X X/*========================================================================*\ X** opendir() ** X\*========================================================================*/ XPUBLIC DIR * Xopendir( path ) Xchar *path; X{ X/* X * Open a directory for reading X */ X struct stat sp; X DIR *dirp; X X if (( dirp = (DIR *) malloc( sizeof( DIR ))) == (DIR *) NULL ) { X errno = ENOMEM; X return( NULL ); X } X if (( dirp->dd_fd = open( path, O_RDONLY )) == -1 ) { X#ifdef DIR_DEBUG X perror( "opendir() (open)" ); X#endif X return( NULL ); X } X if ( fstat( dirp->dd_fd, &sp ) == -1 ) { X#ifdef DIR_DEBUG X perror( "opendir() (fstat)" ); X#endif X return( NULL ); X } X dirp->dd_loc = 0; X return( dirp ); X} X X/*========================================================================*\ X** readdir() ** X\*========================================================================*/ XPUBLIC struct direct * Xreaddir( dirp ) Xregister DIR *dirp; X{ X/* X * Read and return the next directory structure X * referenced by *dirp X */ X register struct direct *dp; X X loop { X if (dirp->dd_loc == 0) { X dirp->dd_size = read( dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ ); X if (dirp->dd_size <= 0) X return( NULL ); X } X if (dirp->dd_loc >= dirp->dd_size) { X dirp->dd_loc = 0; /* reload buffer */ X continue; X } X dp = (struct direct *) (dirp->dd_buf + dirp->dd_loc); X dirp->dd_loc += sizeof( struct direct ); X if (dp->d_ino == 0) X continue; /* skip empty entries */ X __dir.d_ino = dp->d_ino; X strncpy( __dir.d_name, dp->d_name, DIRSIZ ); X __dir.d_name[ DIRSIZ ] = '\0'; X return( &__dir ); X } X} X X/*========================================================================*\ X** telldir() ** X\*========================================================================*/ XPUBLIC long Xtelldir( dirp ) XDIR *dirp; X{ X/* X * Return current position within directory stream. X */ X return( lseek( dirp->dd_fd, 0L, L_INCR )); X} X X/*========================================================================*\ X** seekdir() ** X\*========================================================================*/ XPUBLIC int Xseekdir( dirp, loc ) XDIR *dirp; Xlong loc; X{ X/* X * Set position within directory stream. X */ X long pos; X X dirp->dd_loc = 0; /* force readdir() read into dd_buf */ X return( lseek( dirp->dd_fd, loc, L_SET )); X} X X/*========================================================================*\ X** rewinddir() ** X\*========================================================================*/ XPUBLIC int Xrewinddir( dirp ) XDIR *dirp; X{ X/* X * Resets the position of the directory stream to the beginning. X */ X return( seekdir( dirp, 0L )); X} X X/*========================================================================*\ X** closedir() ** X\*========================================================================*/ XPUBLIC int Xclosedir( dirp ) XDIR *dirp; X{ X/* X * Close given directory and free memory used by *dirp X */ X close( dirp->dd_fd ); X free(( char * ) dirp ); X return( 0 ); X} X END_OF_dir.c if test 3423 -ne `wc -c dir.h <<'END_OF_dir.h' X/* X * dir.h X * X * Minix directory structures X * X */ X/* X * History: X * X * 16 Dec 87 fpp Changed type of d_ino in direct structure X * from "inode_nr" (from orginal types.h) X * to "ino_t" (added to types.h for compatibl- X * ity) X * 29 July 87 fpp Creation X */ X#define DIRSIZ 14 X#define DIRBLKSIZ 512 /* read this much in at a time */ X Xstruct direct { X ino_t d_ino; /* inode of file */ X char d_name[ DIRSIZ ]; /* file name */ X}; X Xtypedef struct _dirdesc X{ X int dd_fd; /* directory file descriptor */ X long dd_loc; /* current location in dd_buf */ X long dd_size; /* size of last read */ X char dd_buf[ DIRBLKSIZ ]; /* read buffer */ X X} DIR; X XDIR *opendir(); Xstruct direct *readdir(); Xlong telldir(); X END_OF_dir.h if test 741 -ne `wc -c makelibc <<'END_OF_makelibc' X# X# makelibc - Make C library X# X# - NOTE - X# X# This shell script will -REMOVE- the old version of libc.a if it X# exists in the current directory. It will also -REPLACE- the old X# /usr/lib/libc.a with version just packaged. X# Xif (test -f ./libc.a) # remove old libc.a if it exists X then rm ./libc.a Xfi Xar av libc.a getwd.s rename.s # getwd(3) rename(2) Xar av libc.a dir.s scandir.s # directory(3), scandir(3) Xar av libc.a getgrp.s # process groups Xar av libc.a termcap.s gtty.s stty.s # v1.2 update Xar av libc.a popen.s ctime.s system.s qsort.s # v1.2 upgrade Xar av libc.a regexp.s regsub.s Xar av libc.a getopt.s getgrent.s getpwent.s crypt.s Xar av libc.a fdopen.s Xar av libc.a fgets.s fprintf.s fputs.s fread.s freopen.s fclose.s Xar av libc.a fopen.s fseek.s ftell.s fwrite.s gets.s scanf.s getc.s printdat.s Xar av libc.a fflush.s setbuf.s sprintf.s doprintf.s putc.s ungetc.s strcmp.s Xar av libc.a access.s chdir.s chmod.s chown.s chroot.s creat.s dup.s dup2.s Xar av libc.a exec.s exit.s cleanup.s fork.s isatty.s fstat.s getegid.s getenv. s Xar av libc.a geteuid.s getgid.s getpass.s close.s getuid.s ioctl.s kill.s Xar av libc.a link.s lseek.s malloc.s brk.s brk2.s brksize.s mknod.s mktemp.s Xar av libc.a getpid.s mount.s open.s perror.s pipe.s prints.s read.s setgid.s Xar av libc.a setuid.s sleep.s alarm.s pause.s signal.s catchsig.s stat.s Xar av libc.a stime.s strcat.s strcpy.s strlen.s strncat.s strncmp.s strncpy.s Xar av libc.a ftime.s Xar av libc.a sync.s time.s times.s umask.s umount.s unlink.s utime.s wait.s Xar av libc.a stderr.s write.s syslib.s call.s atoi.s message.s sendrec.s Xar av libc.a printk.s abort.s itoa.s stb.s abs.s atol.s ctype.s index.s bcopy. s Xar av libc.a getutil.s rand.s rindex.s adi.s and.s cii.s cms.s cmu4.s com.s Xar av libc.a csa2.s csb2.s cuu.s .dup.s dvi.s dvi4.s dvu.s dvu4.s exg.s fakfp. s Xar av libc.a gto.s iaar.s ilar.s inn.s ior.s isar.s lar2.s loi.s mli.s mli4.s Xar av libc.a ngi.s nop.s rck.s rmi.s rmi4.s rmu.s rmu4.s rol.s ror.s sar2.s Xar av libc.a sbi.s set.s sli.s sri.s sti.s xor.s error.s unknown.s trp.s Xar av libc.a setjmp.s X Xcp libc.a /usr/lib Xecho Xecho "Done." Xecho X END_OF_makelibc if test 2138 -ne `wc -c tst.c <<'END_OF_tst.c' X#include X#include X X#define NULL (DIR *) 0 X#define PRDIR( dp ) printf( "%14s\t%d\n", dp->d_name, dp->d_ino ) X Xmain() X{ X DIR *dirp; X struct direct *dp; X X if (( dirp = opendir( "." ) ) == NULL ) { X perror( "\".\"" ); X exit( 1 ); X } X while(( dp = readdir( dirp )) != NULL ) X PRDIR( dp ); X X prints( "\nseekdir: " ); X seekdir( dirp, 45 ); dp = readdir( dirp ); PRDIR( dp ); X X printf( "\ntelldir(): %20s %D\n", dp->d_name, telldir( dirp )); X X prints( "\nrewind(): " ); X rewinddir( dirp ); dp = readdir( dirp ); PRDIR( dp ); X X printf( "\ntelldir(): %20s %D\n", dp->d_name, telldir( dirp )); X X prints( "\nseekdir: " ); X seekdir( dirp, 4 * sizeof( struct direct )); X dp = readdir( dirp ); PRDIR( dp ); X X closedir( dirp ); X} END_OF_tst.c if test 765 -ne `wc -c