void write_mntent(mntent_t *mtp, const char *mnttabname) { FILE *fp; if (lockmnttab() < 0) return; fp = fopen(mnttabname, "a"); if (fp == NULL) { plog(XLOG_ERROR, "Unable to append %s: %m", mnttabname); return; } write_mntent_to_mtab(fp, mtp); fclose(fp); unlockmnttab(); }
void write_mntent(mntent_t *mp, const char *mnttabname) { int fd; if (lockmnttab() == -1) return; fd = open(mnttabname, O_RDWR | O_APPEND); if (fd < 0) { plog(XLOG_ERROR, "Unable to append %s: %m", mnttabname); return; } write_mntent_to_mtab(fd, mp); close(fd); unlockmnttab(); }
void rewrite_mtab(mntlist *mp, const char *mnttabname) { int fd; assert(mtlckf != 0); fd = open(mnttabname, O_RDWR | O_TRUNC); if (fd < 0) { plog(XLOG_ERROR, "Can't open %s: %m", mnttabname); unlockmnttab(); } while (mp) { if (mp->mnt) write_mntent_to_mtab(fd, mp->mnt); mp = mp->mnext; } close(fd); unlockmnttab(); }
void rewrite_mtab(mntlist *mp, const char *mnttabname) { FILE *fp; assert(mntent_lock_fd >= 0); /* ensure lock fd is valid */ fp = fopen(mnttabname, "r+"); if (fp == NULL) { plog(XLOG_ERROR, "Can't open %s: %m", mnttabname); unlockmnttab(); return; } while (mp) { if (mp->mnt) write_mntent_to_mtab(fp, mp->mnt); mp = mp->mnext; } ftruncate(fileno(fp), ftell(fp)); fclose(fp); unlockmnttab(); }