Annotation of coherent/d/etc/umount.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Unmount a filesystem
                      3:  */
                      4: 
                      5: char helpmessage[] = "\
                      6: \
                      7: umount -- unmount file system\n\
                      8: Usage: /etc/umount special\n\
                      9: The block special file 'special' previously mounted by '/etc/mount'\n\
                     10: on 'directory' is unmounted and the previous contents of 'directory'\n\
                     11: are once again accessible.\n\
                     12: A file system can only be unmounted if all its files are closed.\n\
                     13: \
                     14: ";
                     15: 
                     16: #include <stdio.h>
                     17: #include <mtab.h>
                     18: #include <mnttab.h>
                     19: #include <errno.h>
                     20: 
                     21: char   mtabf[] = "/etc/mtab";
                     22: char   mnttabf[] = "/etc/mnttab";
                     23: 
                     24: struct mtab    mtab;
                     25: struct mnttab  mnttab;
                     26: struct mtab    zmtab;
                     27: struct mnttab  zmnttab;
                     28: char   special[MNAMSIZ];
                     29: 
                     30: main(argc, argv)
                     31: char *argv[];
                     32: {
                     33:        register FILE *fp;
                     34: 
                     35:        if (argc != 2)
                     36:                usage();
                     37:        if (umount(argv[1]) < 0)
                     38:                merror(argv[1]);
                     39:        if ((fp = fopen(mnttabf, "r+w")) != NULL) {
                     40:                mcopy(argv[1], special);
                     41:                while (fread(&mnttab, sizeof(mnttab), 1, fp) == 1)
                     42:                        if (mnttab.mt_dev[0] != '\0'
                     43:                          &&  strncmp(mnttab.mt_filsys, special, MNTNSIZ)==0) {
                     44:                                fseek(fp, (long)(-sizeof(mnttab)), 1);
                     45:                                if (fwrite(&zmnttab,sizeof(zmnttab),1,fp) != 1)
                     46:                                        merror(mnttabf);
                     47:                                break;
                     48:                        }
                     49:        }
                     50:        if ((fp = fopen(mtabf, "r+w")) != NULL) {
                     51:                mcopy(argv[1], special);
                     52:                while (fread(&mtab, sizeof(mtab), 1, fp) == 1)
                     53:                        if (mtab.mt_name[0] != '\0'
                     54:                          &&  strncmp(mtab.mt_special, special, MNAMSIZ)==0) {
                     55:                                fseek(fp, (long)(-sizeof(mtab)), 1);
                     56:                                if (fwrite(&zmtab, sizeof(zmtab), 1, fp) != 1)
                     57:                                        merror(mtabf);
                     58:                                break;
                     59:                        }
                     60:        }
                     61:        return (0);
                     62: }
                     63: 
                     64: usage()
                     65: {
                     66:        fprintf(stderr, helpmessage);
                     67:        exit (1);
                     68: }
                     69: 
                     70: merror(f)
                     71: char *f;
                     72: {
                     73:        register int err;
                     74:        extern int errno;
                     75: 
                     76:        err = errno;
                     77:        fprintf(stderr, "umount: %r", &f);
                     78:        if (err > 0 && err < sys_nerr)
                     79:                fprintf(stderr, ": %s\n", sys_errlist[err]);
                     80:        else
                     81:                fprintf(stderr, ": unrecognized error: %d\n", err);
                     82:        exit(1);
                     83: }
                     84: 
                     85: /*
                     86:  * Copy special pathname (stripped of
                     87:  * leading directories) into a fixed
                     88:  * size buffer.
                     89:  */
                     90: mcopy(ms, buf)
                     91: char *ms, *buf;
                     92: {
                     93:        register char *p1, *p2;
                     94: 
                     95:        for (p1=p2=ms; *p1 != '\0'; )
                     96:                if (*p1++ == '/')
                     97:                        p2 = p1;
                     98:        p1 = buf;
                     99:        while (*p1++ = *p2++)
                    100:                ;
                    101: }

unix.superglobalmegacorp.com

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