void mkdir_safe(char *dir, int owner)
{
    if (mkdir(dir, 0750)) {
        if (errno == EEXIST) {
            /* OK, we've been told that this already exists.  Make sure
             * nothing's mounted on top of it, so we aren't doing something
             * nasty */
            if (is_mounted(dir)) {
                fprintf(stderr,
                        "Error: can't bindmount under %s: already mounted\n",
                        dir);
                exit(1);
            }
        } else {
            perror("Unable to mkdir() in /media");
            exit(1);
        }
    }
    if (chown(dir,owner,0)) {
	if (errno == EINVAL) {
           fprintf(stderr,
                 "Error: can't change ownership to %s: invalid uid\n",
                 owner);
	  exit(1);
        } else {
          perror("Unable to chown() in /media");
          exit(1);	     
	}
    }
}
