PageRenderTime 163ms CodeModel.GetById 152ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/filesystems/unixfs/ufs/ufs_mainx.c

http://macfuse.googlecode.com/
C | 101 lines | 84 code | 12 blank | 5 comment | 11 complexity | acd6efdac4e3f5dad20b108a21086f86 MD5 | raw file
  1/*
  2 * UFS for MacFUSE
  3 * Copyright (c) 2008 Amit Singh
  4 * http://osxbook.com
  5 */
  6
  7#include "unixfs.h"
  8
  9#include <errno.h>
 10#include <stddef.h>
 11#include <stdio.h>
 12#include <stdlib.h>
 13#include <string.h>
 14#include <unistd.h>
 15#include <ctype.h>
 16#include <dlfcn.h>
 17
 18static const char* PROGNAME = "ufs";
 19static const char* PROGVERS = "1.0";
 20
 21static struct filesystems {
 22    int   isalias;
 23    char* fstypename;
 24    char* fstypename_canonical;
 25} filesystems[] = {
 26    { 0, "old",         "ufs" },
 27    { 0, "sunos",       "ufs" },
 28    { 0, "sun",         "ufs" },
 29    { 0, "sunx86",      "ufs" }, 
 30    { 0, "hp",          "ufs" },
 31    { 0, "nextstep",    "ufs" },
 32    { 0, "nextstep-cd", "ufs" },
 33    { 0, "openstep",    "ufs" },
 34    { 0, "44bsd",       "ufs" },
 35    { 0, "5xbsd",       "ufs" },
 36    { 0, "ufs2",        "ufs" },
 37    { 0, NULL, NULL },
 38};
 39
 40__private_extern__
 41void
 42unixfs_usage(void)
 43{
 44    fprintf(stderr,
 45    "%s (version %s): UFS family of file systems for MacFUSE\n"
 46    "Amit Singh <http://osxbook.com>\n"
 47    "usage:\n"
 48    "      %s [--force] --dmg DMG --type TYPE MOUNTPOINT [MacFUSE args...]\n"
 49    "where:\n"
 50    "     . DMG must point to an ancient Unix disk image of a valid type\n"
 51    "     . TYPE is one of:",
 52    PROGNAME, PROGVERS, PROGNAME);
 53
 54    int i;
 55    for (i = 0; filesystems[i].fstypename != NULL; i++) {
 56        if (!filesystems[i].isalias)
 57            fprintf(stderr, " %s ", filesystems[i].fstypename);
 58    }
 59    fprintf(stderr, "\n");
 60
 61    fprintf(stderr, "%s",
 62    "     . --force attempts mounting even if there are warnings or errors\n"
 63    );
 64}
 65
 66__private_extern__
 67struct unixfs*
 68unixfs_preflight(char* dmg, char** type, struct unixfs** unixfsp)
 69{
 70    int i;
 71    *unixfsp = NULL;
 72
 73    if (!type || !*type)
 74        goto out;
 75
 76    for (i = 0; filesystems[i].fstypename != NULL; i++) {
 77        if (strcasecmp(*type, filesystems[i].fstypename) == 0) {
 78            char symb[255];
 79            snprintf(symb, 255, "%s_%s", "unixfs",
 80                     filesystems[i].fstypename_canonical);
 81            void* impl = dlsym(RTLD_DEFAULT, symb);
 82            if (impl != NULL) {
 83                *unixfsp = (struct unixfs*)impl;
 84                break;
 85            }
 86        }
 87    }
 88
 89out:
 90    return *unixfsp;
 91}
 92
 93__private_extern__
 94void
 95unixfs_postflight(char* fsname, char* volname, char* extra_args)
 96{
 97    snprintf(extra_args, UNIXFS_ARGLEN,
 98        "-oro,sparse,defer_permissions,daemon_timeout=5,"
 99        "volname=%s,fsname=%s File System",
100        volname, fsname);
101}