📄 apple.c
字号:
get_hfs_info(wname, dname, s_entry) char *wname; char *dname; dir_ent *s_entry;{ int type, wlen, i; wlen = strlen(wname) - strlen(dname); /* we may already know the type of Unix/HFS file - so process */ if (s_entry->hfs_type != TYPE_NONE) { type = s_entry->hfs_type; strcpy(tmp, wname); /* append or insert finderinfo filename part */ if (hfs_types[type].flags & APPEND) strcat(tmp, hfs_types[type].info); else sprintf(tmp + wlen, "%s%s", hfs_types[type].info, (hfs_types[type].flags & NOPEND) ? "" : dname); type = (*(hfs_types[type].get_info))(tmp, dname, s_entry, type); /* if everything is as expected, then return */ if (s_entry->hfs_type == type) return (type); } /* we don't know what type we have so, find out */ for (i = 1; i < hfs_num; i++) { if ((hfs_types[i].flags & PROBE) || *(hfs_types[i].info) == TYPE_NONE) { continue; } strcpy(tmp, wname); /* append or insert finderinfo filename part */ if (hfs_types[i].flags & APPEND) { strcat(tmp, hfs_types[i].info); } else { sprintf(tmp + wlen, "%s%s", hfs_types[i].info, (hfs_types[i].flags & NOPEND) ? "" : dname); } /* if the file exists - and not a type we've already tried */ if (!access(tmp, R_OK) && i != s_entry->hfs_type) { type = (*(hfs_types[i].get_info))(tmp, dname, s_entry, i); s_entry->hfs_type = type; return (type); } } /* nothing found, so just a Unix file */ type = (*(hfs_types[TYPE_NONE].get_info))(wname, dname, s_entry, TYPE_NONE); return (type);}/* * get_hfs_rname: set the name of the Unix rsrc file for a file */intget_hfs_rname(wname, dname, rname) char *wname; char *dname; char *rname;{ int wlen, type, i; int p_fd = -1; wlen = strlen(wname) - strlen(dname); /* try to find what sort of Unix HFS file type we have */ for (i = 1; i < hfs_num; i++) { /* skip if don't want to probe the files - (default) */ if (hfs_types[i].flags & PROBE) continue; strcpy(rname, wname); /* if we have a different info file, the find out it's type */ if (*(hfs_types[i].rsrc) && *(hfs_types[i].info)) { /* first test the Info file */ /* append or insert finderinfo filename part */ if (hfs_types[i].flags & APPEND) { strcat(rname, hfs_types[i].info); } else { sprintf(rname + wlen, "%s%s", hfs_types[i].info, (hfs_types[i].flags & NOPEND) ? "" : dname); } /* if it exists, then check the Rsrc file */ if (!access(rname, R_OK)) { if (hfs_types[i].flags & APPEND) { sprintf(rname + wlen, "%s%s", dname, hfs_types[i].rsrc); } else { sprintf(rname + wlen, "%s%s", hfs_types[i].rsrc, dname); } /* * for some types, a rsrc fork may not exist, * so just return the current type * in these cases */ if (hfs_types[i].flags & NORSRC || !access(rname, R_OK)) return (hfs_types[i].type); } } else { /* * if we are probing, * then have a look at the contents to find type */ if (p_fd < 0) { /* open file, if not already open */ if ((p_fd = open(wname, O_RDONLY | O_BINARY)) < 0) { /* can't open it, then give up */ return (TYPE_NONE); } else { if ((p_num = read(p_fd, p_buf, sizeof(p_buf))) <= 0) { /* * can't read, or zero length * - give up */ close(p_fd); return (TYPE_NONE); } /* get file pointer and close file */ p_fp = fdopen(p_fd, "rb"); close(p_fd); if (p_fp == NULL) return (TYPE_NONE); } } /* * call routine to do the work * - use the given dname as this * is the name we may use on the CD */ type = (*(hfs_types[i].get_info)) (rname, dname, 0, i); if (type != 0) { fclose(p_fp); return (type); } if (p_fp) { /* * close file * - just use contents of buffer next time */ fclose(p_fp); p_fp = NULL; } } } return (0);}/* * hfs_exclude: file/directory names that hold finder/resource * information that we want to exclude from the tree. * These files/directories are processed later ... */inthfs_exclude(d_name) char *d_name;{ /* we don't exclude "." and ".." */ if (!strcmp(d_name, ".")) return 0; if (!strcmp(d_name, "..")) return 0; /* do not add the following to our list of dir entries */ if (DO_CAP & hselect) { /* CAP */ if (!strcmp(d_name, ".finderinfo")) return 1; if (!strcmp(d_name, ".resource")) return 1; if (!strcmp(d_name, ".ADeskTop")) return 1; if (!strcmp(d_name, ".IDeskTop")) return 1; if (!strcmp(d_name, "Network Trash Folder")) return 1; /* * special case when HFS volume is mounted using Linux's hfs_fs * Brad Midgley <brad@pht.com> */ if (!strcmp(d_name, ".rootinfo")) return 1; } if (DO_ESH & hselect) { /* Helios EtherShare files */ if (!strcmp(d_name, ".rsrc")) return 1; if (!strcmp(d_name, ".Desktop")) return 1; if (!strcmp(d_name, ".DeskServer")) return 1; if (!strcmp(d_name, ".Label")) return 1; } if (DO_DBL & hselect) { /* Apple Double */ /* * special case when HFS volume is mounted using Linux's hfs_fs */ if (!strcmp(d_name, "%RootInfo")) return 1; /* * have to be careful here - a filename starting with '%' * may be vaild if the next two letters are a hex character - * unfortunately '%' 'digit' 'digit' may be a valid resource * file name ... */ if (*d_name == '%') if (hex2char(d_name) == 0) return 1; } if (DO_NETA & hselect) { if (!strcmp(d_name, ".AppleDouble")) return 1; if (!strcmp(d_name, ".AppleDesktop")) return 1; } if ((DO_FEU & hselect) || (DO_FEL & hselect)) { /* PC Exchange */ if (!strcmp(d_name, "RESOURCE.FRK")) return 1; if (!strcmp(d_name, "FINDER.DAT")) return 1; if (!strcmp(d_name, "DESKTOP")) return 1; if (!strcmp(d_name, "FILEID.DAT")) return 1; if (!strcmp(d_name, "resource.frk")) return 1; if (!strcmp(d_name, "finder.dat")) return 1; if (!strcmp(d_name, "desktop")) return 1; if (!strcmp(d_name, "fileid.dat")) return 1; } if (DO_SGI & hselect) { /* SGI */ if (!strcmp(d_name, ".HSResource")) return 1; if (!strcmp(d_name, ".HSancillary")) return 1; } if (DO_DAVE & hselect) { /* DAVE */ if (!strcmp(d_name, "resource.frk")) return 1; if (!strcmp(d_name, "DesktopFolderDB")) return 1; }#ifndef _WIN32 /* * NTFS streams are not "seen" as files, * so WinNT will not see these files - * so ignore - used for testing under Unix */ if (DO_SFM & hselect) { /* SFM */ char *dn = strrchr(d_name, ':'); if (dn) { if (!strcmp(dn, ":Afp_Resource")) return 1; if (!strcmp(dn, ":Comments")) return 1; if (!strcmp(dn, ":Afp_AfpInfo")) return 1; } }#endif /* _WIN32 */ return 0;}/* * print_hfs_info: print info about the HFS files. * */voidprint_hfs_info(s_entry) dir_ent *s_entry;{ fprintf(stderr, "Name: %s\n", s_entry->whole_name); fprintf(stderr, "\tFile type: %s\n", hfs_types[s_entry->hfs_type].desc); fprintf(stderr, "\tHFS Name: %s\n", s_entry->hfs_ent->name); fprintf(stderr, "\tISO Name: %s\n", s_entry->isorec.name); fprintf(stderr, "\tCREATOR: %s\n", s_entry->hfs_ent->u.file.creator); fprintf(stderr, "\tTYPE: %s\n", s_entry->hfs_ent->u.file.type);}/* * hfs_init: sets up the mapping list from the afpfile as well * the default mapping (with or without) an afpfile */#ifdef PROTOTYPESvoidhfs_init(char *name, u_short fdflags, u_int hfs_select)#elsevoidhfs_init(name, fdflags, hfs_select) char *name; /* afpfile name */ u_short fdflags; /* default finder flags */ u_int hfs_select; /* select certain mac files */#endif{ FILE *fp; /* File pointer */ int count = NUMMAP; /* max number of entries */ char buf[PATH_MAX]; /* working buffer */ afpmap *amap; /* mapping entry */ char *c, *t, *e; int i; /* setup number of Unix/HFS filetype - we may wish to not bother */ if (hfs_select) { hfs_num = sizeof(hfs_types) / sizeof(struct hfs_type); /* * code below needs to be tidied up * - most can be made redundant */ for (i = 0; i < hfs_num; i++) hfs_types[i].flags &= ~1; /* 0xfffffffe */ for (i = 1; i < hfs_num; i++) if (!((1 << i) & hfs_select)) hfs_types[i].flags |= PROBE; hselect = hfs_select; } else hfs_num = hselect = 0;#ifdef DEBUG for (i = 0; i < hfs_num; i++) fprintf(stderr, "type = %d flags = %d\n", i, hfs_types[i].flags);#endif /* DEBUG */ /* min length set to max to start with */ mlen = PATH_MAX; /* initialise magic file */ if (magic_file && init_magic(magic_file) != 0) perr("unable to open magic file"); /* set defaults */ map_num = last_ent = 0; /* allocate memory for the default entry */ if ((defmap = (afpmap *) malloc(sizeof(afpmap))) == NULL) perr("not enough memory"); /* set default values */ defmap->extn = DEFMATCH; /* make sure creator and type are 4 chars long */ strcpy(defmap->type, BLANK); strcpy(defmap->creator, BLANK); e = deftype; t = defmap->type; while (*e && (e - deftype) < CT_SIZE) *t++ = *e++; e = defcreator; c = defmap->creator; while (*e && (e - defcreator) < CT_SIZE) *c++ = *e++; /* length is not important here */ defmap->elen = 0; /* no flags */ defmap->fdflags = fdflags; /* no afpfile - no mappings */ if (*name == '\0') { map = NULL; return; } if ((fp = fopen(name, "r")) == NULL) perr("unable to open mapping file"); if ((map = (afpmap **) malloc(NUMMAP * sizeof(afpmap *))) == NULL) perr("not enough memory"); /* read afpfile line by line */ while (fgets(buf, PATH_MAX, fp) != NULL) { /* ignore any comment lines */ c = tmp; *c = '\0'; if (sscanf(buf, "%1s", c) == EOF || *c == '#') continue; /* increase list size if needed */ if (map_num == count) { count += NUMMAP; map = (afpmap **)realloc(map, count * sizeof(afpmap *)); if (map == NULL) perr("not enough memory"); } /* allocate memory for this entry */ if ((amap = (afpmap *) malloc(sizeof(afpmap))) == NULL) perr("not enough memory"); t = amap->type; c = amap->creator; /* extract the info */ if (sscanf(buf, "%s%*s%*1s%c%c%c%c%*1s%*1s%c%c%c%c%*1s", tmp, c, c + 1, c + 2, c + 3, t, t + 1, t + 2, t + 3) != 9) { fprintf(stderr, "error scanning afpfile %s - continuing", name); free(amap); continue; } /* copy the extension found */ if ((amap->extn = (char *) strdup(tmp)) == NULL) perr("not enough memory"); /* set end-of-string */ *(t + 4) = *(c + 4) = '\0'; /* find the length of the extension */ amap->elen = strlen(amap->extn); /* set flags */ amap->fdflags = fdflags; /* see if we have the default creator/type */ if (!strcmp(amap->extn, DEFMATCH)) { /* get rid of the old default */ free(defmap); /* make this the default */ defmap = amap; continue; } /* update the smallest extension length */ mlen = MIN(mlen, amap->elen); /* add entry to the list */ map[map_num++] = amap; } /* free up some memory */ if (map_num != count) { map = (afpmap **) realloc(map, map_num * sizeof(afpmap *)); if (map == NULL) perr("not enough memory"); }}/* * map_ext: map a files extension with the list to get type/creator */static voidmap_ext(name, type, creator, fdflags, whole_name) char *name; /* filename */ char **type; /* set type */ char **creator; /* set creator */ short *fdflags; /* set finder flags */ char *whole_name;{ int i; /* loop counter */ int len; /* filename length */ afpmap *amap; /* mapping entry */ char *ret; /* we don't take fdflags from the map or magic file */ *fdflags = defmap->fdflags; /* * if we have a magic file and we want to search it first, * then try to get a match */ if (magic_file && hfs_last == MAP_LAST) { ret = get_magic_match(whole_name); if (ret) { if (sscanf(ret, "%4s%4s", tmp_creator, tmp_type) == 2) { *type = tmp_type; *creator = tmp_creator; return; } } } len = strlen(name); /* have an afpfile and filename if long enough */ if (map && len >= mlen) { /* * search through the list - we start where we left off * last time in case this file is of the same type as the * last one */ for (i = 0; i < map_num; i++) { amap = map[last_ent]; /* compare the end of the filename *//* if (!strcmp((name+len - amap->elen), amap->extn)) { */ if (!strcasecmp((name+len - amap->elen), amap->extn)) { /* set the required info */ *type = amap->type; *creator = amap->creator; *fdflags = amap->fdflags; return; } /* * move on to the next entry - wrapping round * if neccessary */ last_ent++; last_ent %= map_num; } } /* * if no matches are found, file name too short, or no afpfile, * then take defaults */ *type = defmap->type; *creator = defmap->creator; /* * if we have a magic file and we haven't searched yet, * then try to get a match */ if (magic_file && hfs_last == MAG_LAST) { ret = get_magic_match(whole_name); if (ret) { if (sscanf(ret, "%4s%4s", tmp_creator, tmp_type) == 2) { *type = tmp_type; *creator = tmp_creator; } } }}voiddelete_rsrc_ent(s_entry) dir_ent *s_entry;{ dir_ent *s_entry1 = s_entry->next; if (s_entry1 == NULL) return; s_entry->next = s_entry1->next; s_entry->assoc = NULL; free(s_entry1->name); free(s_entry1->whole_name); free(s_entry1);}voidclean_hfs(){ if (map) free(map); if (defmap) free(defmap); if (magic_file) clean_magic();}#endif /* APPLE_HYB */voidperr(a) char *a;{ if (a) fprintf(stderr, "mkhybrid: %s\n", a); perror("mkhybrid"); exit(1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -