|
|
1.1 ! root 1: /* ! 2: * UAE - The Un*x Amiga Emulator ! 3: * ! 4: * Library of functions to make emulated filesystem as independent as ! 5: * possible of the host filesystem's capabilities. ! 6: * This is the Win32 version. ! 7: * ! 8: * Copyright 1997 Mathias Ortmann ! 9: * Copyright 1999 Bernd Schmidt ! 10: */ ! 11: ! 12: #include "sysconfig.h" ! 13: #include "sysdeps.h" ! 14: ! 15: #include "fsdb.h" ! 16: ! 17: /* Return nonzero for any name we can't create on the native filesystem. */ ! 18: int fsdb_name_invalid (const char *n) ! 19: { ! 20: char a = n[0]; ! 21: char b = (a == '\0' ? a : n[1]); ! 22: char c = (b == '\0' ? b : n[2]); ! 23: ! 24: if (a >= 'a' && a <= 'z') ! 25: a -= 32; ! 26: if (b >= 'a' && b <= 'z') ! 27: b -= 32; ! 28: if (c >= 'a' && c <= 'z') ! 29: c -= 32; ! 30: ! 31: if ((a == 'A' && b == 'U' && c == 'X') ! 32: || (a == 'C' && b == 'O' && c == 'N') ! 33: || (a == 'P' && b == 'R' && c == 'N') ! 34: || (a == 'N' && b == 'U' && c == 'L')) ! 35: return 1; ! 36: ! 37: if (strchr (n, '\\') != 0) ! 38: return 1; ! 39: ! 40: if (strcmp (n, FSDB_FILE) == 0) ! 41: return 1; ! 42: if (n[0] != '.') ! 43: return 0; ! 44: if (n[1] == '\0') ! 45: return 1; ! 46: return n[1] == '.' && n[2] == '\0'; ! 47: } ! 48: ! 49: /* For an a_inode we have newly created based on a filename we found on the ! 50: * native fs, fill in information about this file/directory. */ ! 51: void fsdb_fill_file_attrs (a_inode *aino) ! 52: { ! 53: struct stat statbuf; ! 54: /* This really shouldn't happen... */ ! 55: if (stat (aino->nname, &statbuf) == -1) ! 56: return; ! 57: aino->dir = S_ISDIR (statbuf.st_mode) ? 1 : 0; ! 58: aino->amigaos_mode = ((S_IXUSR & statbuf.st_mode ? 0 : A_FIBF_EXECUTE) ! 59: | (S_IWUSR & statbuf.st_mode ? 0 : A_FIBF_WRITE) ! 60: | (S_IRUSR & statbuf.st_mode ? 0 : A_FIBF_READ)); ! 61: } ! 62: ! 63: int fsdb_set_file_attrs (a_inode *aino, int mask) ! 64: { ! 65: struct stat statbuf; ! 66: int mode; ! 67: ! 68: if (stat (aino->nname, &statbuf) == -1) ! 69: return ERROR_OBJECT_NOT_FOUND; ! 70: ! 71: mode = statbuf.st_mode; ! 72: /* Unix dirs behave differently than AmigaOS ones. */ ! 73: if (! aino->dir) { ! 74: if (mask & A_FIBF_READ) ! 75: mode &= ~S_IRUSR; ! 76: else ! 77: mode |= S_IRUSR; ! 78: ! 79: if (mask & A_FIBF_WRITE) ! 80: mode &= ~S_IWUSR; ! 81: else ! 82: mode |= S_IWUSR; ! 83: ! 84: if (mask & A_FIBF_EXECUTE) ! 85: mode &= ~S_IXUSR; ! 86: else ! 87: mode |= S_IXUSR; ! 88: ! 89: chmod (aino->nname, mode); ! 90: } ! 91: ! 92: aino->amigaos_mode = mask; ! 93: aino->dirty = 1; ! 94: return 0; ! 95: } ! 96: ! 97: /* Return nonzero if we can represent the amigaos_mode of AINO within the ! 98: * native FS. Return zero if that is not possible. */ ! 99: int fsdb_mode_representable_p (const a_inode *aino) ! 100: { ! 101: if (aino->dir) ! 102: return aino->amigaos_mode == 0; ! 103: return (aino->amigaos_mode & (A_FIBF_DELETE | A_FIBF_SCRIPT | A_FIBF_PURE)) == 0; ! 104: } ! 105: ! 106: char *fsdb_create_unique_nname (a_inode *base, const char *suggestion) ! 107: { ! 108: char *c; ! 109: char tmp[256] = "__uae___"; ! 110: strncat (tmp, suggestion, 240); ! 111: ! 112: /* @@@ Brian... this may or may not need fixing. */ ! 113: while ((c = strchr (tmp, '\\')) != 0) ! 114: *c = '_'; ! 115: while ((c = strchr (tmp, '.')) != 0) ! 116: *c = '_'; ! 117: ! 118: for (;;) { ! 119: int i; ! 120: char *p = build_nname (base->nname, tmp); ! 121: if (access (p, R_OK) < 0 && errno == ENOENT) { ! 122: printf ("unique name: %s\n", p); ! 123: return p; ! 124: } ! 125: free (p); ! 126: ! 127: /* tmpnam isn't reentrant and I don't really want to hack configure ! 128: * right now to see whether tmpnam_r is available... */ ! 129: for (i = 0; i < 8; i++) { ! 130: tmp[i] = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[random () % 63]; ! 131: } ! 132: } ! 133: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.