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

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

unix.superglobalmegacorp.com

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