home *** CD-ROM | disk | FTP | other *** search
- /*
- * fsfilt - filesystem filter for find (System V).
- *
- * This program is intended for machines without a -mount option on their
- * find(1) command. We use this program for doing backups, when we do not
- * want find to cross mountpoints in the directory structure. This program
- * will pick up the current working directory, read the mount table
- * (/etc/mnttab on system V machines) and build a list of directories that
- * should NOT be backed up.
- *
- * This program is inteneded to have find(1) output piped into it. Each
- * filename is examined, and if it does not contain references to any of
- * the children filesystems of the current filesystem (if any) then the
- * filename is printed on standard output, otherwise it is trashed.
- *
- * An example command would be:
- * find . -print | fsfilt | cpio -ocB > /dev/rmt1
- *
- * In addition to children filesystems, the tmp directory in both / and /usr
- * are not backed up. This dependancy is hardcoded into the source.
- *
- * Please send any enhancements, comments or bugs to the author.
- *
- * Author: Mark H. Colburn (mark@ems.mn.org)
- * EMS/McGraw-Hill
- *
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <sys/types.h>
- #include <mnttab.h>
-
- #define STRSIZ 200
-
- void perror();
- int nmnt;
- struct mnttab fs[NMOUNT];
- char except[NMOUNT][32];
- int numex = 0;
-
- /* ARGSUSED */
- int main(argc, argv)
- int argc;
- char *argv[];
- {
- int i, found;
- char str[STRSIZ];
-
- nmnt = read_mnttab();
- get_exceptions();
- while (!feof(stdin)) {
- if (fgets(str, STRSIZ, stdin) == NULL && !feof(stdin))
- perror("Unable to read stdin");
- str[strlen(str) - 1] = '\0';
- found = 0;
- if (numex > 0)
- for (i = 0; !found && i < numex; i++)
- found = (strncmp(str, except[i],
- strlen(except[i])) == 0);
- if (!found)
- puts(str);
- }
- return (0);
- }
-
- /*
- * get_exceptions - get list of children filesystem of this directory
- */
-
- int get_exceptions()
- {
- char fsname[100], work[100], work1[100];
- int i, j, found = 0;
- char *cp;
- char *strindex();
-
- (void) getcwd(fsname, 100);
- if (strcmp(fsname, "/") == 0 || strcmp(fsname,"/usr") == 0)
- (void) strcpy(except[numex++], "./tmp/");
- for (i = 0; i < nmnt; i++) {
- if (strncmp(fsname, fs[i].mt_filsys, strlen(fsname)) == 0 &&
- strcmp(fsname, fs[i].mt_filsys) != 0) {
- if (strcmp(fsname, "/") == 0)
- (void) strcpy(work, fs[i].mt_filsys+
- strlen(fsname));
- else
- (void) strcpy(work, fs[i].mt_filsys +
- strlen(fsname)+1);
- if ((cp = strchr(work, '/')) == NULL) {
- (void) strcpy(work1, work);
- (void) strcat(work1, "/");
- } else {
- *(cp + 1) = '\0';
- (void) strcpy(work1, work);
- }
- found = 0;
- (void) sprintf(work,"./%s", work1);
- for (j = 0; !found && j < numex; j++)
- found = (strcmp(except[j], work) == 0);
- if (!found)
- strcpy(except[numex++], work);
- }
- }
- }
-
- /*
- * read_mount_table - get a list of all currently mounted filesystems
- */
-
- int read_mnttab()
- {
- int i, ret;
- FILE *fp;
-
- if ((fp = fopen("/etc/mnttab", "r")) == NULL) {
- (void) fprintf("Unable to open /etc/mnttab, exiting\n");
- exit(1);
- }
- i = 0;
- while (!feof(fp))
- if (fread((char *) &fs[i], sizeof(struct mnttab), 1, fp) > 0)
- i++;
- (void) fclose(fp);
- return (i);
- }
-
- /*
- * char *strindex(s1,s2) - return a pointer to where s2 exists in s1, or
- * NULL.
- */
-
- char *strindex(s1, s2)
- char *s1, *s2;
- {
- register int i;
- register char *cp;
-
- i = strlen(s2);
- if (strlen(s1) == i)
- return (strcmp(s2, s1) ? NULL : s1);
- if (strlen(s1) > i) {
- for (cp = s1; *cp; cp++)
- if (*cp == *s2 && strncmp(cp, s2, i) == 0)
- return (cp);
- }
- return (NULL);
- }
-