[comp.sys.hp] find

scott@grlab.UUCP (Scott Blachowicz) (05/11/89)

I'm working with the rh program posted to the net recently (it is a find(1)
"replacement" that deals with C-style expressions). It doesn't handle
some of the stuff that find(1) does on our HP9000/300 Series system, so
I'm wondering how find does it or how I could do it...

 1) find has a -mountstop(or something like that)==>it recognizes mount
    points. It would be nice to able to tell my program to not cross
    mount points without having to tell it to explicitly "prune" all of
    the mount point directories.
 2) find recognizes file system types.
 3) HP-UX has "Context Dependent Files"(CDFs) that are really hidden
    directories containing the file that is really referred to. The file
    system decides which file to get based on the "context" of the
    requesting CPU. This allows the discless workstations to share the
    same file system without duplicating lots of stuff. Physically it
    looks like this:
      /etc:
      Hrwsr-xr-x   2 root     other       1024 May  2 14:27 inittab+

      /etc/inittab+:
      -r--r--r--   1 root     other       1163 May  2 14:26 server_node
      -r--r--r--   1 root     other        735 May  4 12:07 discless_node1
      -r--r--r--   1 root     other        735 May  4 12:07 discless_node2
    
    At any rate, the readdir routines read the contents of /etc as
    including the regular file "inittab" instead of the hidden
    directory "inittab+", but find(1) is able to display the hidden
    directories with a "-hidden" switch or "-type H". I want to do this,
    too.

Thanx for your help,
Scott Blachowicz
USPS:  Graphicus                UUCP:    ...!hpubvwa!grlab!scott
       150 Lake Str S, #206     VoicePh: 206/828-4691
       Kirkland, WA 98033       FAX:     206/828-4236

stroyan@hpfcdc.HP.COM (Mike Stroyan) (05/12/89)

>  1) find has a -mountstop(or something like that)==>it recognizes mount
>     points. It would be nice to able to tell my program to not cross
>     mount points without having to tell it to explicitly "prune" all of
>     the mount point directories.

You can recognize mount points by using stat(2) on each directory and
watching for changes in the st_dev field.

>  2) find recognizes file system types.

You can check the file system type of a path by using getmntent(3X)
to look up the /etc/mnttab entries and matching the mnt_fsname field
to the mount point.  The file system type is in the mnt_type field.

>  3) HP-UX has "Context Dependent Files"(CDFs) that are really hidden
>     directories containing the file that is really referred to.
      
>     At any rate, the readdir routines read the contents of /etc as
>     including the regular file "inittab" instead of the hidden
>     directory "inittab+", but find(1) is able to display the hidden
>     directories with a "-hidden" switch or "-type H". I want to do this,
>     too.

The CDFs can recognized by calling stat(2).  The S_ISCDF macro described
in stat(5) will test for a CDF using the st_mode field.

You might also want to watch for symbolic links with the S_ISLNK macro
from stat(5).

Mike Stroyan, stroyan@hpstryn

rml@hpfcdc.HP.COM (Bob Lenk) (05/13/89)

> >     At any rate, the readdir routines read the contents of /etc as
> >     including the regular file "inittab" instead of the hidden
> >     directory "inittab+", but find(1) is able to display the hidden
> >     directories with a "-hidden" switch or "-type H". I want to do this,
> >     too.
> 
> The CDFs can recognized by calling stat(2).  The S_ISCDF macro described
> in stat(5) will test for a CDF using the st_mode field.

You must first attempt to append a '+' to the filename and then call
stat().  If it fails with ENOENT, the file is not a CDF.  If it succeeds
the S_ISDCF() macro will tell whether it is a CDF.

If you call stat("/etc/inittab", &buf), the information returned will
refer to /etc/inittab+/<cnodename> not to the hidden directory, and
S_ISCDF(buf.st_mode) will return zero.

> You might also want to watch for symbolic links with the S_ISLNK macro
> from stat(5).

This requires use of lstat() rather than stat().

		Bob Lenk
		hplabs!hpfcla!rml
		rml@hpfcla.hp.com

decot@hpisod2.HP.COM (Dave Decot) (05/13/89)

> The CDFs can recognized by calling stat(2).  The S_ISCDF macro described
> in stat(5) will test for a CDF using the st_mode field.

Actually, the macro is not described on stat(5).

It is, however, defined in <sys/stat.h>.

Dave Decot
HP

scott@grlab.UUCP (Scott Blachowicz) (05/17/89)

/ grlab:comp.sys.hp / stroyan@hpfcdc.HP.COM (Mike Stroyan) /  8:42 pm  May 11, 1989 /
> > ...
> >  3) HP-UX has "Context Dependent Files"(CDFs) that are really hidden
> >     directories containing the file that is really referred to.
>       
> >     At any rate, the readdir routines read the contents of /etc as
> >     including the regular file "inittab" instead of the hidden
> >     directory "inittab+", but find(1) is able to display the hidden
> >     directories with a "-hidden" switch or "-type H". I want to do this,
> >     too.
> 
> The CDFs can recognized by calling stat(2).  The S_ISCDF macro described
> in stat(5) will test for a CDF using the st_mode field.
I notice that macro, but the problem is that the readdir routine resolves
the CDF "for" me, so I never get a filename to do a stat on. The only
thing I've come up with so far is to have an option that says "look at
hidden directories", then call getcdf(3C) on each file and compare with
the input file name...if different then back the path up and walk the
hidden directory. That is, do something like:
   real_path = getcdf (readdir_returned_path, real_path, sizeof(real_path))
   if (strcmp (real_path, readdir_returned_path) != 0) {
      *(strrchr (real_path, '/')) = '\0';
      /* Treat real_path as a normal directory file for directory */
      /* tree walking purposes.                                   */
   }
   else { /* Non-CDF file processing */ }


> You might also want to watch for symbolic links with the S_ISLNK macro
> from stat(5).
I do a similar sort of maneuver for links, but readdir doesn't resolve
them for me, so I have a directory entry I can either stat or lstat
depending on what I'm doing.

Thanx for the info,
Scott Blachowicz           scott@grlab.UUCP