Changeset d9c2dce0 in rtems
- Timestamp:
- Jul 2, 2003, 1:58:38 PM (18 years ago)
- Children:
- 8e308413
- Parents:
- 86ca3f83
- Location:
- cpukit/libfs/src/dosfs
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/libfs/src/dosfs/Makefile.am
r86ca3f83 rd9c2dce0 15 15 msdos_free.c msdos_fsunmount.c msdos_handlers_dir.c \ 16 16 msdos_handlers_file.c msdos_init.c msdos_initsupp.c \ 17 msdos_misc.c msdos_mknod.c msdos_node_type.c 17 msdos_misc.c msdos_mknod.c msdos_node_type.c \ 18 msdos_conv.c 18 19 19 20 if !UNIX -
cpukit/libfs/src/dosfs/msdos.h
r86ca3f83 rd9c2dce0 82 82 /* 83 83 * Macros for fetching fields from 32 bytes long FAT Directory Entry 84 * Structure (see M$ White Paper)84 * Structure 85 85 */ 86 86 #define MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE 32 /* 32 bytes */ … … 105 105 /* 106 106 * Fields offset in 32 bytes long FAT Directory Entry 107 * Structure (see M$ White Paper)107 * Structure 108 108 */ 109 109 #define MSDOS_FILE_SIZE_OFFSET 28 … … 116 116 /* 117 117 * Possible values of DIR_Attr field of 32 bytes long FAT Directory Entry 118 * Structure (see M$ White Paper)118 * Structure 119 119 */ 120 120 #define MSDOS_ATTR_READ_ONLY 0x01 … … 125 125 #define MSDOS_ATTR_ARCHIVE 0x20 126 126 127 #define MSDOS_DT_2SECONDS_MASK 0x1F /* seconds divided by 2 */ 128 #define MSDOS_DT_2SECONDS_SHIFT 0 129 #define MSDOS_DT_MINUTES_MASK 0x7E0 /* minutes */ 130 #define MSDOS_DT_MINUTES_SHIFT 5 131 #define MSDOS_DT_HOURS_MASK 0xF800 /* hours */ 132 #define MSDOS_DT_HOURS_SHIFT 11 133 134 #define MSDOS_DD_DAY_MASK 0x1F /* day of month */ 135 #define MSDOS_DD_DAY_SHIFT 0 136 #define MSDOS_DD_MONTH_MASK 0x1E0 /* month */ 137 #define MSDOS_DD_MONTH_SHIFT 5 138 #define MSDOS_DD_YEAR_MASK 0xFE00 /* year - 1980 */ 139 #define MSDOS_DD_YEAR_SHIFT 9 140 141 127 142 /* 128 143 * Possible values of DIR_Name[0] field of 32 bytes long FAT Directory Entry 129 * Structure (see M$ White Paper)144 * Structure 130 145 */ 131 146 #define MSDOS_THIS_DIR_ENTRY_EMPTY 0xE5 … … 172 187 #define DOTDOT_NODE_P(p) ((char *)((p) + MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE)) 173 188 174 /* Size limits for files and directories (see M$ White Paper)*/189 /* Size limits for files and directories */ 175 190 #define MSDOS_MAX_DIR_LENGHT 0x200000 /* 2,097,152 bytes */ 176 191 #define MSDOS_MAX_FILE_SIZE 0xFFFFFFFF /* 4 Gb */ … … 346 361 msdos_dir_info_remove(rtems_filesystem_location_info_t *pathloc); 347 362 348 void 349 msdos_date_unix2dos(int unix_date, 350 unsigned short *time_val, 351 unsigned short *date); 352 353 unsigned int 354 msdos_date_dos2unix(unsigned short time_val, unsigned short date); 363 int 364 msdos_filename_unix2dos(char *un, int unlen, char *dn); 365 366 void 367 msdos_date_unix2dos(unsigned int tsp, unsigned short *ddp, 368 unsigned short *dtp); 369 370 unsigned int 371 msdos_date_dos2unix(unsigned int dd, unsigned int dt); 355 372 356 373 int -
cpukit/libfs/src/dosfs/msdos_create.c
r86ca3f83 rd9c2dce0 31 31 /* msdos_creat_node -- 32 32 * Create a new node. If a new node is file, FAT 32 Bytes Directory 33 * Entry Structure (see M$ White Paper) is initialized, free space is 34 * found in parent directory and structure is written to the disk. 35 * In case of directory, all above steps present and also new cluster 36 * is allocated for a new directory and dot and dotdot nodes are created 37 * in alloceted cluster. 33 * Entry Structure is initialized, free space is found in parent 34 * directory and structure is written to the disk. In case of directory, 35 * all above steps present and also new cluster is allocated for a 36 * new directory and dot and dotdot nodes are created in alloceted cluster. 38 37 * 39 38 * PARAMETERS: … … 95 94 /* 96 95 * find free space in the parent directory and write new initialized 97 * FAT 32 Bytes Directory Entry Structure (see M$ White Paper) 98 * to the disk 96 * FAT 32 Bytes Directory Entry Structure to the disk 99 97 */ 100 98 rc = msdos_get_name_node(parent_loc, NULL, &aux, new_node); -
cpukit/libfs/src/dosfs/msdos_dir.c
r86ca3f83 rd9c2dce0 443 443 * The following routine does a syncronization on a MSDOS directory node. 444 444 * DIR_WrtTime, DIR_WrtDate and DIR_fileSize fields of 32 Bytes Directory 445 * Entry Structure (see M$ White Paper) should not be updated for446 * directories, so only callto corresponding fat-file routine.445 * Entry Structure should not be updated for directories, so only call 446 * to corresponding fat-file routine. 447 447 * 448 448 * PARAMETERS: -
cpukit/libfs/src/dosfs/msdos_misc.c
r86ca3f83 rd9c2dce0 28 28 29 29 #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_ATARI36 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 #endif44 NULL };45 46 static char bad_chars[] = "*?<>|\"";47 #ifdef CONFIG_ATARI48 /* GEMDOS is less restrictive */49 static char bad_if_strict[] = " ";50 #else51 static char bad_if_strict[] = "+=,; ";52 #endif53 54 /* The following three functions copied from Linux */55 /*56 * Formats an MS-DOS file name. Rejects invalid names57 *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 int63 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_ATARI76 space = 1; /* disallow names that _really_ start with a dot */77 #else78 space = 0; /* GEMDOS does not care */79 #endif80 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 int134 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 175 30 176 31 /* msdos_get_token -- … … 251 106 } 252 107 253 rc = msdos_f ormat_name('r', token, *token_len, ret_token, 0);108 rc = msdos_filename_unix2dos(token, *token_len, ret_token); 254 109 if ( rc != RC_OK ) 255 110 return MSDOS_INVALID_TOKEN;
Note: See TracChangeset
for help on using the changeset viewer.