Annotation of researchv10no/libc/gen/tmp/seekdir.c, revision 1.1.1.1

1.1       root        1: /* Copyright (c) 1982 Regents of the University of California
                      2:  * and modified by pjw in 1987 */
                      3: 
                      4: #include "ndir.h"
                      5: 
                      6: /*
                      7:  * seek to an entry in a directory.
                      8:  *
                      9:  * offset `told' is interpreted in a non-obvious way:
                     10:  * telldir computes it as  dd_offset*DIRBLKSIZ + dd_loc
                     11:  * dd_loc is the byte offset into the current dd_buf contents;
                     12:  * dd_offset is the number of times dirread(fd, buf, DIRBLKSIZ)
                     13:  * must be called to reproduce the same buffer.
                     14:  *
                     15:  * Why not just use lseek?  Because told isn't a seek offset,
                     16:  * and cannot conveniently be turned into one: the byte count
                     17:  * in dd_loc is unrelated to the seek offset required to reach
                     18:  * lseek(fd, 0L, 1)+dd_loc, because the seek offset refers to the raw
                     19:  * directory, but dirread has reformatted the data.
                     20:  * One might let dd_offset be the seek offset to the the beginning
                     21:  * of dd_buf, compute told the same way, and let seekdir become
                     22:  *     lseek(fd, told/DIRBLKSIZ, 0); dirp->dd_loc = told%DIRBLKSIZ;
                     23:  * but a somewhat strident prior implementor worries that this unfairly
                     24:  * constrains the size of directories.  This is probably a silly worry
                     25:  * (will any real system have directories a megabyte long?) but it
                     26:  * doesn't matter much except in programs that use seekdir a lot.
                     27:  */
                     28: void
                     29: seekdir(dirp, told)
                     30: register DIR *dirp;
                     31: long told;
                     32: {      long offset;
                     33: 
                     34:        offset = told / DIRBLKSIZ;
                     35:        dirp->dd_loc = told % DIRBLKSIZ;
                     36:        if (offset < dirp->dd_offset)
                     37:                lseek(dirp->dd_fd, dirp->dd_offset = 0L, 0);
                     38:        if(offset > dirp->dd_offset) {
                     39:                do {
                     40:                        dirp->dd_size = dirread(dirp->dd_fd, dirp->dd_buf,
                     41:                                                DIRBLKSIZ);
                     42:                        if(dirp->dd_size < 0)
                     43:                                dirp->dd_size = pdirread(dirp->dd_fd,
                     44:                                        dirp->dd_buf, DIRBLKSIZ);
                     45:                        }
                     46:                        while(++dirp->dd_offset < offset);
                     47:                }
                     48: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.