Ignore:
Timestamp:
Jul 2, 2003, 2:09:15 PM (18 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
1f5d2ba
Parents:
3b44f153
Message:

Patch from Victor V. Vengerov <vvv@…> to remove Linux code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libfs/src/dosfs/msdos_misc.c

    r3b44f153 rc125425  
    2828
    2929#include "msdos.h"
    30 
    31 /* This copied from Linux */
    32 static int day_n[] = { 0,31,59,90,120,151,181,212,243,273,304,334,0,0,0,0 };
    33                   /* JanFebMarApr May Jun Jul Aug Sep Oct Nov Dec */
    34 
    35 #undef CONFIG_ATARI
    36 
    37 /* MS-DOS "device special files" */
    38 static const char *reserved_names[] = {
    39 #ifndef CONFIG_ATARI /* GEMDOS is less stupid */
    40     "CON     ","PRN     ","NUL     ","AUX     ",
    41     "LPT1    ","LPT2    ","LPT3    ","LPT4    ",
    42     "COM1    ","COM2    ","COM3    ","COM4    ",
    43 #endif
    44     NULL };
    45 
    46 static char bad_chars[] = "*?<>|\"";
    47 #ifdef CONFIG_ATARI
    48 /* GEMDOS is less restrictive */
    49 static char bad_if_strict[] = " ";
    50 #else
    51 static char bad_if_strict[] = "+=,; ";
    52 #endif
    53 
    54 /* The following three functions copied from Linux */
    55 /*
    56  * Formats an MS-DOS file name. Rejects invalid names
    57  *
    58  * conv is relaxed/normal/strict, name is proposed name,
    59  * len is the length of the proposed name, res is the result name,
    60  * dotsOK is if hidden files get dots.
    61  */
    62 int
    63 msdos_format_name(char conv, const char *name, int len, char *res,
    64                   char dotsOK)
    65 {
    66         char *walk;
    67         const char **reserved;
    68         unsigned char c;
    69         int space;
    70         if (name[0] == '.') {  /* dotfile because . and .. already done */
    71                 if (!dotsOK) return -EINVAL;
    72                 /* Get rid of dot - test for it elsewhere */
    73                 name++; len--;
    74         }
    75 #ifndef CONFIG_ATARI
    76         space = 1; /* disallow names that _really_ start with a dot */
    77 #else
    78         space = 0; /* GEMDOS does not care */
    79 #endif
    80         c = 0;
    81         for (walk = res; len && walk-res < 8; walk++) {
    82                 c = *name++;
    83                 len--;
    84                 if (conv != 'r' && strchr(bad_chars,c)) return -EINVAL;
    85                 if (conv == 's' && strchr(bad_if_strict,c)) return -EINVAL;
    86                 if (c >= 'A' && c <= 'Z' && conv == 's') return -EINVAL;
    87                 if (c < ' ' || c == ':' || c == '\\') return -EINVAL;
    88 /*  0xE5 is legal as a first character, but we must substitute 0x05     */
    89 /*  because 0xE5 marks deleted files.  Yes, DOS really does this.       */
    90 /*  It seems that Microsoft hacked DOS to support non-US characters     */
    91 /*  after the 0xE5 character was already in use to mark deleted files.  */
    92                 if((res==walk) && (c==0xE5)) c=0x05;
    93                 if (c == '.') break;
    94                 space = (c == ' ');
    95                 *walk = (c >= 'a' && c <= 'z') ? c-32 : c;
    96         }
    97         if (space) return -EINVAL;
    98         if (conv == 's' && len && c != '.') {
    99                 c = *name++;
    100                 len--;
    101                 if (c != '.') return -EINVAL;
    102         }
    103         while (c != '.' && len--) c = *name++;
    104         if (c == '.') {
    105                 while (walk-res < 8) *walk++ = ' ';
    106                 while (len > 0 && walk-res < MSDOS_NAME_MAX) {
    107                         c = *name++;
    108                         len--;
    109                         if (conv != 'r' && strchr(bad_chars,c)) return -EINVAL;
    110                         if (conv == 's' && strchr(bad_if_strict,c))
    111                                 return -EINVAL;
    112                         if (c < ' ' || c == ':' || c == '\\')
    113                                 return -EINVAL;
    114                         if (c == '.') {
    115                                 if (conv == 's')
    116                                         return -EINVAL;
    117                                 break;
    118                         }
    119                         if (c >= 'A' && c <= 'Z' && conv == 's') return -EINVAL;
    120                         space = c == ' ';
    121                         *walk++ = c >= 'a' && c <= 'z' ? c-32 : c;
    122                 }
    123                 if (space) return -EINVAL;
    124                 if (conv == 's' && len) return -EINVAL;
    125         }
    126         while (walk-res < MSDOS_NAME_MAX) *walk++ = ' ';
    127         for (reserved = reserved_names; *reserved; reserved++)
    128                 if (!strncmp(res,*reserved,8)) return -EINVAL;
    129         return 0;
    130 }
    131 
    132 /* Convert a MS-DOS time/date pair to a UNIX date (seconds since 1 1 70) */
    133 unsigned int
    134 msdos_date_dos2unix(unsigned short time_val,unsigned short date)
    135 {
    136     int month,year,secs;
    137 
    138     month = ((date >> 5) & 15)-1;
    139     year = date >> 9;
    140     secs = (time_val & 31)*2+60*((time_val >> 5) & 63)+
    141            (time_val >> 11)*3600+86400*
    142         ((date & 31)-1+day_n[month]+(year/4)+year*365-((year & 3) == 0 &&
    143         month < 2 ? 1 : 0)+3653);
    144             /* days since 1.1.70 plus 80's leap day */
    145 
    146     return secs;
    147 }
    148 
    149 
    150 /* Convert linear UNIX date to a MS-DOS time/date pair */
    151 void msdos_date_unix2dos(int unix_date,
    152                          unsigned short *time_val,
    153                          unsigned short *date)
    154 {
    155         int day,year,nl_day,month;
    156 
    157         *time_val = (unix_date % 60)/2+(((unix_date/60) % 60) << 5)+
    158             (((unix_date/3600) % 24) << 11);
    159         day = unix_date/86400-3652;
    160         year = day/365;
    161         if ((year+3)/4+365*year > day) year--;
    162         day -= (year+3)/4+365*year;
    163         if (day == 59 && !(year & 3)) {
    164                 nl_day = day;
    165                 month = 2;
    166         }
    167         else {
    168                 nl_day = (year & 3) || day <= 59 ? day : day-1;
    169                 for (month = 0; month < 12; month++)
    170                         if (day_n[month] > nl_day) break;
    171         }
    172         *date = nl_day-day_n[month-1]+1+(month << 5)+(year << 9);
    173 }
    174 
    17530
    17631/* msdos_get_token --
     
    251106        }
    252107
    253         rc = msdos_format_name('r', token, *token_len, ret_token, 0);
     108        rc = msdos_filename_unix2dos(token, *token_len, ret_token);
    254109        if ( rc != RC_OK )
    255110            return MSDOS_INVALID_TOKEN;     
Note: See TracChangeset for help on using the changeset viewer.