예제 #1
0
static int
analyze_dkmount_tree(qelem *q, fsi_mount *parent, disk_fs *dk)
{
  fsi_mount *mp;
  int errors = 0;

  ITER(mp, fsi_mount, q) {
    fsi_log("Mount %s:", mp->m_name);
    if (parent) {
      char n[MAXPATHLEN];
      xsnprintf(n, sizeof(n), "%s/%s", parent->m_name, mp->m_name);
      if (*mp->m_name == '/')
	lerror(mp->m_ioloc, "sub-directory %s of %s starts with '/'", mp->m_name, parent->m_name);
      else if (STREQ(mp->m_name, "default"))
	lwarning(mp->m_ioloc, "sub-directory of %s is named \"default\"", parent->m_name);
      fsi_log("Changing name %s to %s", mp->m_name, n);
      XFREE(mp->m_name);
      mp->m_name = strdup(n);
    }

    mp->m_name_len = strlen(mp->m_name);
    mp->m_parent = parent;
    mp->m_dk = dk;
    if (mp->m_mount)
      analyze_dkmount_tree(mp->m_mount, mp, dk);
  }
예제 #2
0
int
write_fstab(qelem *q)
{
  int errors = 0;

  if (fstab_pref) {
    host *hp;

    show_area_being_processed("write fstab", 4);
    ITER(hp, host, q) {
      if (hp->h_disk_fs || hp->h_mount) {
	FILE *ef = pref_open(fstab_pref, hp->h_hostname, gen_hdr, hp->h_hostname);
	if (ef) {
	  struct os_fstab_type *op = find_fstab_type(hp);
	  show_new(hp->h_hostname);
	  if (hp->h_disk_fs)
	    errors += write_dkfstab(ef, hp->h_disk_fs, op->op_fstab);
	  else
	    fsi_log("No local disk mounts on %s", hp->h_hostname);

	  if (hp->h_mount)
	    errors += write_dkrmount(ef, hp->h_mount, hp->h_hostname, op->op_mount);

	  pref_close(ef);
	}
      } else {
	error("no disk mounts on %s", hp->h_hostname);
      }
    }
  }
  return errors;
}
예제 #3
0
/*
 * Take a little-endian domain name and
 * transform into a big-endian Un*x pathname.
 * For example: kiska.doc.ic -> ic/doc/kiska
 */
static char *
compute_hostpath(char *hn)
{
  char *p = xmalloc(MAXPATHLEN);
  char *d;
  char path[MAXPATHLEN];

  xstrlcpy(p, hn, MAXPATHLEN);
  domain_strip(p, hostname);
  path[0] = '\0';

  do {
    d = strrchr(p, '.');
    if (d) {
      *d = 0;
      xstrlcat(path, d + 1, sizeof(path));
      xstrlcat(path, "/", sizeof(path));
    } else {
      xstrlcat(path, p, sizeof(path));
    }
  } while (d);

  fsi_log("hostpath of '%s' is '%s'", hn, path);

  xstrlcpy(p, path, MAXPATHLEN);
  return p;
}
예제 #4
0
static void
show_required(ioloc *l, int mask, char *info, char *hostname, char *strings[])
{
  int i;
  fsi_log("mask left for %s:%s is %#x", hostname, info, mask);

  for (i = 0; strings[i]; i++)
    if (ISSET(mask, i))
      lerror(l, "%s:%s needs field \"%s\"", hostname, info, strings[i]);
}
예제 #5
0
/*
 * Open a file with the given prefix and name
 */
FILE *
pref_open(char *pref, char *hn, void (*hdr) (FILE *, char *), char *arg)
{
  char p[MAXPATHLEN];
  FILE *ef;

  xsnprintf(p, sizeof(p), "%s%s", pref, hn);
  fsi_log("Writing %s info for %s to %s", pref, hn, p);
  ef = fopen(p, "w");
  if (ef) {
    (*hdr) (ef, arg);
    make_banner(ef);
  } else {
    error("can't open %s for writing", p);
  }

  return ef;
}
예제 #6
0
static dict_ent *
find_volname(char *nn)
{
  dict_ent *de;
  char *p = strdup(nn);
  char *q;

  do {
    fsi_log("Searching for volname %s", p);
    de = dict_locate(dict_of_volnames, p);
    q = strrchr(p, '/');
    if (q)
      *q = '\0';
  } while (!de && q);

  XFREE(p);
  return de;
}
예제 #7
0
파일: fsinfo.c 프로젝트: 0mp/freebsd
/*
 * Argument cracking...
 */
static void
fsi_get_args(int c, char *v[])
{
  int ch;
  int usage = 0;
  char *iptr = idvbuf;

  /*
   * Determine program name
   */
  if (v[0]) {
    progname = strrchr(v[0], '/');
    if (progname && progname[1])
      progname++;
    else
      progname = v[0];
  }

  if (!progname)
    progname = "fsinfo";

  while ((ch = getopt(c, v, "a:b:d:e:f:h:m:D:U:I:qv")) != -1)

    switch (ch) {

    case 'a':
      autodir = optarg;
      break;

    case 'b':
      if (bootparams_pref)
	fatal("-b option specified twice");
      bootparams_pref = optarg;
      break;

    case 'd':
      if (dumpset_pref)
	fatal("-d option specified twice");
      dumpset_pref = optarg;
      break;

    case 'h':
      xstrlcpy(hostname, optarg, sizeof(hostname));
      break;

    case 'e':
      if (exportfs_pref)
	fatal("-e option specified twice");
      exportfs_pref = optarg;
      break;

    case 'f':
      if (fstab_pref)
	fatal("-f option specified twice");
      fstab_pref = optarg;
      break;

    case 'm':
      if (mount_pref)
	fatal("-m option specified twice");
      mount_pref = optarg;
      break;

    case 'q':
      verbose = -1;
      break;

    case 'v':
      verbose = 1;
      break;

    case 'I':
    case 'D':
    case 'U':
      /* sizeof(iptr) is actually that of idvbuf.  See declaration above */
      xsnprintf(iptr, sizeof(idvbuf), "-%c%s ", ch, optarg);
      iptr += strlen(iptr);
      break;

    default:
      usage++;
      break;
    }

  if (c != optind) {
    g_argv = v + optind - 1;
#ifdef yywrap
    if (yywrap())
#endif /* yywrap */
      fatal("Cannot read any input files");
  } else {
    usage++;
  }

  if (usage) {
    fprintf(stderr,
	    "\
Usage: %s [-v] [-a autodir] [-h hostname] [-b bootparams] [-d dumpsets]\n\
\t[-e exports] [-f fstabs] [-m automounts]\n\
\t[-I dir] [-D|-U string[=string]] config ...\n", progname);
    exit(1);
  }

  if (g_argv[0])
    fsi_log("g_argv[0] = %s", g_argv[0]);
  else
    fsi_log("g_argv[0] = (nil)");
}