erikb@cs.vu.nl (Erik Baalbergen) (06/01/89)
Inspired by a discussion in comp.unix.questions on how to find path names from inode numbers, I felt the need to spend few minutes on extending the 'find' program with the -xdev option to prevent 'find' to cross file system boundaries. (Thanks to Guy Harris who made me aware of the existence of -xdev in some UNIXes.) I haven't been able to test the new find on Minix, but I would be grateful if some kind soul could inform me whether -xdev really works. "find / -xdev -print" and "find / -print" should produce a rather short and a very, very long list of file names, respectively. Below I enclosed a diff listing between the 1.3 version and the new version. -- Erik Baalbergen : This is a shar archive. Extract with sh, not csh. : This archive ends with exit, so do not worry about trailing junk. : --------------------------- cut here -------------------------- PATH=/bin:/usr/bin:/usr/ucb echo Extracting 'find.c.diff' sed 's/^X//' > 'find.c.diff' << '+ END-OF-FILE ''find.c.diff' X8a9 X> * -xdev: do not cross file system boundaries X51a53 X> #define OP_XDEV 17 /* do not cross file-system boundaries */ X72a75 X> {"xdev", OP_XDEV}, X102a106,107 X> int xdev_flag = 0; X> int devnr; X139c144,146 X< for (i = 0; i < pathcnt; i++) X--- X> for (i = 0; i < pathcnt; i++) { X> if (xdev_flag) X> xdev_flag = 2; X140a148 X> } X158a167 X> X161a171,183 X> switch(xdev_flag) { X> case 0: X> break; X> case 1: X> if (st.st_dev != devnr) X> return; X> break; X> case 2: /* set current device number */ X> xdev_flag = 1; X> devnr = st.st_dev; X> break; X> } X> X229a252,253 X> case OP_XDEV: X> return 1; X451a476,478 X> break; X> case OP_XDEV: X> xdev_flag = 1; + END-OF-FILE find.c.diff chmod 'u=rw,g=r,o=r' 'find.c.diff' set `wc -c 'find.c.diff'` count=$1 case $count in 681) :;; *) echo 'Bad character count in ''find.c.diff' >&2 echo 'Count should be 681' >&2 esac exit 0