Annotation of uae/src/od-win32/fsdb_win32.c, revision 1.1.1.4

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"
1.1.1.3   root       16: #include <windows.h>
1.1       root       17: 
1.1.1.2   root       18: /* these are deadly (but I think allowed on the Amiga): */
                     19: #define NUM_EVILCHARS 7
                     20: char evilchars[NUM_EVILCHARS] = { '\\', '*', '?', '\"', '<', '>', '|' };
                     21: 
1.1       root       22: /* Return nonzero for any name we can't create on the native filesystem.  */
                     23: int fsdb_name_invalid (const char *n)
                     24: {
1.1.1.2   root       25:     int i;
1.1       root       26:     char a = n[0];
                     27:     char b = (a == '\0' ? a : n[1]);
                     28:     char c = (b == '\0' ? b : n[2]);
1.1.1.2   root       29:     char d = (c == '\0' ? c : n[3]);
1.1.1.4 ! root       30:     int l = strlen (n);
1.1       root       31: 
                     32:     if (a >= 'a' && a <= 'z')
1.1.1.2   root       33:         a -= 32;
1.1       root       34:     if (b >= 'a' && b <= 'z')
1.1.1.2   root       35:         b -= 32;
1.1       root       36:     if (c >= 'a' && c <= 'z')
1.1.1.2   root       37:         c -= 32;
1.1       root       38: 
1.1.1.4 ! root       39:     if ((a == 'A' && b == 'U' && c == 'X' && l == 3) /* AUX  */
        !            40:        || (a == 'C' && b == 'O' && c == 'N' && l == 3) /* CON  */
        !            41:        || (a == 'P' && b == 'R' && c == 'N' && l == 3) /* PRN  */
        !            42:        || (a == 'N' && b == 'U' && c == 'L' && l == 3) /* NUL  */
        !            43:        || (a == 'L' && b == 'P' && c == 'T'  && (d >= '0' && d <= '9') && l == 4)  /* LPT# */
        !            44:        || (a == 'C' && b == 'O' && c == 'M'  && (d >= '0' && d <= '9') && l == 4)) /* COM# */
1.1       root       45:        return 1;
1.1.1.4 ! root       46:   
        !            47:     /* spaces and periods at the end are a no-no */
1.1.1.2   root       48:     i = strlen(n) - 1;
                     49:     if (n[i] == '.' || n[i] == ' ')
1.1       root       50:        return 1;
1.1.1.2   root       51: 
                     52:     /* these characters are *never* allowed */
                     53:     for (i = 0; i < NUM_EVILCHARS; i++) {
                     54:         if (strchr (n, evilchars[i]) != 0)
                     55:             return 1;
                     56:     }
                     57: 
                     58:     /* the reserved fsdb filename */
                     59:     if (strcmp (n, FSDB_FILE) == 0)
1.1       root       60:        return 1;
1.1.1.2   root       61:     return 0; /* the filename passed all checks, now it should be ok */
                     62: }
                     63: 
                     64: uae_u32 filesys_parse_mask(uae_u32 mask)
                     65: {
                     66:     return(mask ^ 0xf);
1.1       root       67: }
                     68: 
                     69: /* For an a_inode we have newly created based on a filename we found on the
                     70:  * native fs, fill in information about this file/directory.  */
                     71: void fsdb_fill_file_attrs (a_inode *aino)
                     72: {
1.1.1.2   root       73:     int mode;
                     74: 
                     75:     if((mode = GetFileAttributes(aino->nname)) == 0xFFFFFFFF) return;
                     76:        
                     77:     aino->dir = (mode & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0;
                     78:     aino->amigaos_mode = (FILE_ATTRIBUTE_ARCHIVE & mode) ? 0 : A_FIBF_ARCHIVE;
                     79:     aino->amigaos_mode |= 0xf; /* set rwed by default */
                     80:     aino->amigaos_mode = filesys_parse_mask(aino->amigaos_mode);
1.1       root       81: }
                     82: 
1.1.1.3   root       83: int fsdb_set_file_attrs (a_inode *aino, int mask)
1.1       root       84: {
                     85:     struct stat statbuf;
1.1.1.2   root       86:     uae_u32 mode=0, tmpmask;
1.1       root       87: 
1.1.1.2   root       88:     tmpmask = filesys_parse_mask(mask);
                     89:        
1.1       root       90:     if (stat (aino->nname, &statbuf) == -1)
1.1.1.2   root       91:        return ERROR_OBJECT_NOT_AROUND;
                     92:        
1.1       root       93:     /* Unix dirs behave differently than AmigaOS ones.  */
1.1.1.2   root       94:     /* windows dirs go where no dir has gone before...  */
1.1       root       95:     if (! aino->dir) {
1.1.1.2   root       96:        
                     97:        if (tmpmask & A_FIBF_ARCHIVE)
                     98:            mode |= FILE_ATTRIBUTE_ARCHIVE;
1.1       root       99:        else
1.1.1.2   root      100:            mode &= ~FILE_ATTRIBUTE_ARCHIVE;
1.1       root      101: 
1.1.1.2   root      102:        SetFileAttributes(aino->nname, mode);
1.1       root      103:     }
                    104: 
                    105:     aino->amigaos_mode = mask;
                    106:     aino->dirty = 1;
                    107:     return 0;
                    108: }
                    109: 
                    110: /* Return nonzero if we can represent the amigaos_mode of AINO within the
                    111:  * native FS.  Return zero if that is not possible.  */
                    112: int fsdb_mode_representable_p (const a_inode *aino)
                    113: {
                    114:     if (aino->dir)
                    115:        return aino->amigaos_mode == 0;
1.1.1.2   root      116:     return (aino->amigaos_mode & (A_FIBF_DELETE
                    117:                                  | A_FIBF_SCRIPT
                    118:                                  | A_FIBF_PURE
                    119:                                  | A_FIBF_EXECUTE
                    120:                                  | A_FIBF_READ
                    121:                                  | A_FIBF_WRITE)) == 0;
1.1       root      122: }
                    123: 
                    124: char *fsdb_create_unique_nname (a_inode *base, const char *suggestion)
                    125: {
                    126:     char *c;
                    127:     char tmp[256] = "__uae___";
1.1.1.2   root      128:     int i;
                    129: 
1.1       root      130:     strncat (tmp, suggestion, 240);
1.1.1.2   root      131:        
                    132:     /* replace the evil ones... */
                    133:     for (i=0; i < NUM_EVILCHARS; i++)
                    134:         while ((c = strchr (tmp, evilchars[i])) != 0)
                    135:             *c = '_';
1.1       root      136: 
                    137:     while ((c = strchr (tmp, '.')) != 0)
1.1.1.2   root      138:         *c = '_';
                    139:     while ((c = strchr (tmp, ' ')) != 0)
                    140:         *c = '_';
1.1       root      141: 
                    142:     for (;;) {
                    143:        char *p = build_nname (base->nname, tmp);
                    144:        if (access (p, R_OK) < 0 && errno == ENOENT) {
1.1.1.2   root      145:            write_log ("unique name: %s\n", p);
1.1       root      146:            return p;
                    147:        }
                    148:        free (p);
                    149: 
                    150:        /* tmpnam isn't reentrant and I don't really want to hack configure
                    151:         * right now to see whether tmpnam_r is available...  */
                    152:        for (i = 0; i < 8; i++) {
1.1.1.3   root      153:            tmp[i+8] = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[rand () % 63];
1.1       root      154:        }
                    155:     }
                    156: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.