CS360 Midterm Exam: March 2, 2004. Question 2

Here is a program jl.c, whose executable is in my bin directory.
#include < stdio.h >
#include < sys/types.h >
#include < dirent.h >
#include < sys/stat.h >
#include < string.h >
#include "jrb.h"

typedef struct {
  JRB t;
  int nl;
  int size;
} F;

main()
{
  DIR *d;      F *f;
  struct dirent *de;
  JRB t, tmp, tmp2;
  struct stat buf;

  d = opendir(".");
  if (d == NULL) { 
    perror("."); 
    exit(1); 
  }
  t = make_jrb();
  
  for (de = readdir(d); 
       de != NULL; 
       de = readdir(d)) {
    if (stat(de->d_name, &buf) == 0) {
      tmp = jrb_find_int(t, buf.st_ino);
      if (tmp == NULL) {
        f = (F *) malloc(sizeof(F));
        if (f == NULL) { 
          perror("malloc f"); 
          exit(1); 
        }
        f->t = make_jrb();
        f->nl = buf.st_nlink;
        f->size = buf.st_size;
        tmp = jrb_insert_int(t, 
                 buf.st_ino, 
                 new_jval_v((void *) f));
      } 
      f = (F *) tmp->val.v;
      jrb_insert_str(f->t, 
                 strdup(de->d_name), 
                 new_jval_v(NULL));
    }
  }
 
  jrb_traverse(tmp, t) {
    f = (F *) tmp->val.v;
    printf("%5d %6d", f->nl, f->size);
    jrb_traverse(tmp2, f->t) {
      printf(" %s", tmp2->key.s);
    }
    printf("\n");
  }
}
Suppose I execute the following sequence of Unix commands:
UNIX>  mkdir ex1 
UNIX>  cd ex1 
UNIX>  echo "Hi!" > f1
UNIX>  echo "Exam" > f2
UNIX>  ln f1 f3
UNIX>  ln -s f3 f4
UNIX>  ln -s f1 f5
UNIX>  mkdir d1
UNIX>  mkdir d1/d2
UNIX>  ln f2 d1/f2
UNIX>  rm f1
UNIX>  jl > f6
What is the output of that last command? You may make the following assumptions:
  • You are running on one of our hydra machines.

  • The size of a directory is 512 bytes if it has fewer than 25 files in it.

  • If you cannot determine a part of the output, put a reasonable value there, circle it, and explain why you chose that value, either after the output or in the margins.