summaryrefslogtreecommitdiffstats
path: root/cpukit/libfs/src/dosfs/msdos_misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/libfs/src/dosfs/msdos_misc.c')
-rw-r--r--cpukit/libfs/src/dosfs/msdos_misc.c147
1 files changed, 1 insertions, 146 deletions
diff --git a/cpukit/libfs/src/dosfs/msdos_misc.c b/cpukit/libfs/src/dosfs/msdos_misc.c
index fe2779f7a8..f40820c27b 100644
--- a/cpukit/libfs/src/dosfs/msdos_misc.c
+++ b/cpukit/libfs/src/dosfs/msdos_misc.c
@@ -28,151 +28,6 @@
#include "msdos.h"
-/* This copied from Linux */
-static int day_n[] = { 0,31,59,90,120,151,181,212,243,273,304,334,0,0,0,0 };
- /* JanFebMarApr May Jun Jul Aug Sep Oct Nov Dec */
-
-#undef CONFIG_ATARI
-
-/* MS-DOS "device special files" */
-static const char *reserved_names[] = {
-#ifndef CONFIG_ATARI /* GEMDOS is less stupid */
- "CON ","PRN ","NUL ","AUX ",
- "LPT1 ","LPT2 ","LPT3 ","LPT4 ",
- "COM1 ","COM2 ","COM3 ","COM4 ",
-#endif
- NULL };
-
-static char bad_chars[] = "*?<>|\"";
-#ifdef CONFIG_ATARI
-/* GEMDOS is less restrictive */
-static char bad_if_strict[] = " ";
-#else
-static char bad_if_strict[] = "+=,; ";
-#endif
-
-/* The following three functions copied from Linux */
-/*
- * Formats an MS-DOS file name. Rejects invalid names
- *
- * conv is relaxed/normal/strict, name is proposed name,
- * len is the length of the proposed name, res is the result name,
- * dotsOK is if hidden files get dots.
- */
-int
-msdos_format_name(char conv, const char *name, int len, char *res,
- char dotsOK)
-{
- char *walk;
- const char **reserved;
- unsigned char c;
- int space;
- if (name[0] == '.') { /* dotfile because . and .. already done */
- if (!dotsOK) return -EINVAL;
- /* Get rid of dot - test for it elsewhere */
- name++; len--;
- }
-#ifndef CONFIG_ATARI
- space = 1; /* disallow names that _really_ start with a dot */
-#else
- space = 0; /* GEMDOS does not care */
-#endif
- c = 0;
- for (walk = res; len && walk-res < 8; walk++) {
- c = *name++;
- len--;
- if (conv != 'r' && strchr(bad_chars,c)) return -EINVAL;
- if (conv == 's' && strchr(bad_if_strict,c)) return -EINVAL;
- if (c >= 'A' && c <= 'Z' && conv == 's') return -EINVAL;
- if (c < ' ' || c == ':' || c == '\\') return -EINVAL;
-/* 0xE5 is legal as a first character, but we must substitute 0x05 */
-/* because 0xE5 marks deleted files. Yes, DOS really does this. */
-/* It seems that Microsoft hacked DOS to support non-US characters */
-/* after the 0xE5 character was already in use to mark deleted files. */
- if((res==walk) && (c==0xE5)) c=0x05;
- if (c == '.') break;
- space = (c == ' ');
- *walk = (c >= 'a' && c <= 'z') ? c-32 : c;
- }
- if (space) return -EINVAL;
- if (conv == 's' && len && c != '.') {
- c = *name++;
- len--;
- if (c != '.') return -EINVAL;
- }
- while (c != '.' && len--) c = *name++;
- if (c == '.') {
- while (walk-res < 8) *walk++ = ' ';
- while (len > 0 && walk-res < MSDOS_NAME_MAX) {
- c = *name++;
- len--;
- if (conv != 'r' && strchr(bad_chars,c)) return -EINVAL;
- if (conv == 's' && strchr(bad_if_strict,c))
- return -EINVAL;
- if (c < ' ' || c == ':' || c == '\\')
- return -EINVAL;
- if (c == '.') {
- if (conv == 's')
- return -EINVAL;
- break;
- }
- if (c >= 'A' && c <= 'Z' && conv == 's') return -EINVAL;
- space = c == ' ';
- *walk++ = c >= 'a' && c <= 'z' ? c-32 : c;
- }
- if (space) return -EINVAL;
- if (conv == 's' && len) return -EINVAL;
- }
- while (walk-res < MSDOS_NAME_MAX) *walk++ = ' ';
- for (reserved = reserved_names; *reserved; reserved++)
- if (!strncmp(res,*reserved,8)) return -EINVAL;
- return 0;
-}
-
-/* Convert a MS-DOS time/date pair to a UNIX date (seconds since 1 1 70) */
-unsigned int
-msdos_date_dos2unix(unsigned short time_val,unsigned short date)
-{
- int month,year,secs;
-
- month = ((date >> 5) & 15)-1;
- year = date >> 9;
- secs = (time_val & 31)*2+60*((time_val >> 5) & 63)+
- (time_val >> 11)*3600+86400*
- ((date & 31)-1+day_n[month]+(year/4)+year*365-((year & 3) == 0 &&
- month < 2 ? 1 : 0)+3653);
- /* days since 1.1.70 plus 80's leap day */
-
- return secs;
-}
-
-
-/* Convert linear UNIX date to a MS-DOS time/date pair */
-void msdos_date_unix2dos(int unix_date,
- unsigned short *time_val,
- unsigned short *date)
-{
- int day,year,nl_day,month;
-
- *time_val = (unix_date % 60)/2+(((unix_date/60) % 60) << 5)+
- (((unix_date/3600) % 24) << 11);
- day = unix_date/86400-3652;
- year = day/365;
- if ((year+3)/4+365*year > day) year--;
- day -= (year+3)/4+365*year;
- if (day == 59 && !(year & 3)) {
- nl_day = day;
- month = 2;
- }
- else {
- nl_day = (year & 3) || day <= 59 ? day : day-1;
- for (month = 0; month < 12; month++)
- if (day_n[month] > nl_day) break;
- }
- *date = nl_day-day_n[month-1]+1+(month << 5)+(year << 9);
-}
-
-
/* msdos_get_token --
* Routine to get a token (name or separator) from the path.
*
@@ -250,7 +105,7 @@ msdos_get_token(const char *path, char *ret_token, int *token_len)
return type;
}
- rc = msdos_format_name('r', token, *token_len, ret_token, 0);
+ rc = msdos_filename_unix2dos(token, *token_len, ret_token);
if ( rc != RC_OK )
return MSDOS_INVALID_TOKEN;
}