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();
}
Example #2
0
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();
}
/*
 * Read a mount table into memory
 */
mntlist *
read_mtab(char *fs, const char *mnttabname)
{
  mntlist **mpp, *mhp;
  /* From: Piete Brooks <*****@*****.**> */
  int fd;
  mntent_t mountbuffer[NMOUNT], *fs_data;
  int ret;
  int nmts;

  if (lockmnttab() != 0)
    return (mntlist *) 0;

  fd = open(mnttabname, O_RDONLY);
  if (fd < 0) {
    plog(XLOG_ERROR, "Can't open %s: %m", mnttabname);
    return (mntlist *) 0;
  }
  mpp = &mhp;
  while ((ret = read(fd, (char *) mountbuffer, NMOUNT * sizeof(mntent_t))) > 0) {
    nmts = ret / sizeof(mntent_t);
    for (fs_data = mountbuffer; fs_data < &mountbuffer[nmts]; fs_data++) {
      /*
       * Allocate a new slot
       */
      *mpp = ALLOC(struct mntlist);

      /*
       * Copy the data returned by getmntent
       */
      (*mpp)->mnt = mnt_dup(fs_data);

      /*
       * Move to next pointer
       */
      mpp = &(*mpp)->mnext;
    }
  }
  if (ret < 0) {
    plog(XLOG_ERROR, "read error on %s: %m", mnttabname);
    unlockmnttab();
    mhp = (mntlist *) 0;
  }
  *mpp = 0;

  close(fd);
  return mhp;
}
Example #4
0
/*
 * Read a mount table into memory
 */
mntlist *
read_mtab(char *fs, const char *mnttabname)
{
  mntlist **mpp, *mhp;
  FILE *fp;
  mntent_t mountbuf;
  int ret;

  if (lockmnttab() < 0)		/* failed locking */
    return NULL;

  fp = fopen(mnttabname, "r");
  if (fp == NULL) {
    plog(XLOG_ERROR, "Can't open %s: %m", mnttabname);
    return NULL;
  }
  mpp = &mhp;

  while ((ret = getmntent(fp, &mountbuf)) == 0) {
    /*
     * Allocate a new slot
     */
    *mpp = ALLOC(struct mntlist);

    /*
     * Copy the data returned by getmntent
     */
    (*mpp)->mnt = mnt_dup(&mountbuf);

    /*
     * Move to next pointer
     */
    mpp = &(*mpp)->mnext;
  }

  if (ret > 0) {
    plog(XLOG_ERROR, "read error on %s: %m", mnttabname);
    unlockmnttab();
    mhp = NULL;
  }
  *mpp = NULL;

  fclose(fp);
  return mhp;
}
Example #5
0
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();
}
Example #7
0
void
unlock_mntlist(void)
{
  unlockmnttab();
}
void
unlock_mntlist(void)
{
  dlog("unlock_mntlist: releasing");
  unlockmnttab();
}