- fprintf(stderr, "%s on %s%s\n", spec, name,
- ro ? " read only" : "");
- np = spec;
- while (*np++)
- ;
- np--;
- while (*--np == '/')
- *np = '\0';
- while (np > spec && *--np != '/')
- ;
- if (*np == '/')
- np++;
- spec = np;
- for (mp = mtab; mp < &mtab[NMOUNT]; mp++)
- if (!strcmp(mp->spec, spec))
- goto replace;
- for (mp = mtab; mp < &mtab[NMOUNT]; mp++)
- if (mp->file[0] == 0)
- goto replace;
- return;
-replace:
- for (np = mp->spec; np < &mp->spec[NAMSIZ-1];)
- if ((*np++ = *spec++) == 0)
- spec--;
- for (np = mp->file; np < &mp->file[NAMSIZ-1];)
- if ((*np++ = *name++) == 0)
- name--;
- mp = &mtab[NMOUNT];
- while ((--mp)->file[0] == 0);
- mf = creat("/etc/mtab", 0644);
- write(mf, (char *)mtab, (mp-mtab+1)*2*NAMSIZ);
- close(mf);
- return;
+ prmtab(mp);
+
+ for (mp = mtab + NMOUNT - 1; mp > mtab && !*mp->m_path; --mp);
+ if ((fd = open(MTAB, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0)
+ mtaberr();
+ cnt = (mp - mtab + 1) * sizeof(struct mtab);
+ /* NOSTRICT */
+ if (write(fd, (char *)mtab, cnt) != cnt)
+ mtaberr();
+ (void)close(fd);
+}
+
+static
+prmtab(mp)
+ register struct mtab *mp;
+{
+ printf("%s on %s", mp->m_dname, mp->m_path);
+ if (!strcmp(mp->m_type, FSTAB_RO))
+ printf("\t(read-only)");
+ else if (!strcmp(mp->m_type, FSTAB_RQ))
+ printf("\t(with quotas)");
+ printf("\n");
+}
+
+static
+mtaberr()
+{
+ fprintf(stderr, "mount: %s: ", MTAB);
+ perror((char *)NULL);
+ exit(1);
+}
+
+static
+usage()
+{
+ fprintf(stderr, "usage: mount [-arw]\nor mount [-rw] special | node\nor mount [-rw] special node\n");
+ exit(1);