[f36a7bfc] | 1 | /* |
---|
| 2 | * msdos.h |
---|
| 3 | * |
---|
| 4 | * The MSDOS filesystem constants/data structures/prototypes |
---|
| 5 | * |
---|
| 6 | * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia |
---|
| 7 | * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru> |
---|
| 8 | * |
---|
| 9 | * The license and distribution terms for this file may be |
---|
| 10 | * found in the file LICENSE in this distribution or at |
---|
| 11 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 12 | * |
---|
| 13 | * @(#) $Id$ |
---|
| 14 | */ |
---|
| 15 | #ifndef __DOSFS_MSDOS_H__ |
---|
| 16 | #define __DOSFS_MSDOS_H__ |
---|
| 17 | |
---|
| 18 | #ifdef __cplusplus |
---|
| 19 | extern "C" { |
---|
| 20 | #endif |
---|
| 21 | |
---|
| 22 | #include <rtems.h> |
---|
| 23 | #include <rtems/libio_.h> |
---|
| 24 | |
---|
| 25 | #include "fat.h" |
---|
| 26 | #include "fat_file.h" |
---|
| 27 | |
---|
| 28 | #ifndef RC_OK |
---|
| 29 | #define RC_OK 0x00000000 |
---|
| 30 | #endif |
---|
| 31 | |
---|
| 32 | #define MSDOS_NAME_NOT_FOUND_ERR 0xDD000001 |
---|
| 33 | |
---|
| 34 | /* |
---|
| 35 | * This structure identifies the instance of the filesystem on the MSDOS |
---|
| 36 | * level. |
---|
| 37 | */ |
---|
| 38 | typedef struct msdos_fs_info_s |
---|
| 39 | { |
---|
| 40 | fat_fs_info_t fat; /* |
---|
| 41 | * volume |
---|
| 42 | * description |
---|
| 43 | */ |
---|
| 44 | rtems_filesystem_file_handlers_r *directory_handlers; /* |
---|
| 45 | * a set of routines |
---|
| 46 | * that handles the |
---|
| 47 | * nodes of directory |
---|
| 48 | * type |
---|
| 49 | */ |
---|
| 50 | rtems_filesystem_file_handlers_r *file_handlers; /* |
---|
| 51 | * a set of routines |
---|
| 52 | * that handles the |
---|
| 53 | * nodes of file |
---|
| 54 | * type |
---|
| 55 | */ |
---|
| 56 | rtems_id vol_sema; /* |
---|
| 57 | * semaphore |
---|
| 58 | * associated with |
---|
| 59 | * the volume |
---|
| 60 | */ |
---|
| 61 | unsigned8 *cl_buf; /* |
---|
| 62 | * just placeholder |
---|
| 63 | * for anything |
---|
| 64 | */ |
---|
| 65 | } msdos_fs_info_t; |
---|
| 66 | |
---|
| 67 | /* a set of routines that handle the nodes which are directories */ |
---|
| 68 | extern rtems_filesystem_file_handlers_r msdos_dir_handlers; |
---|
| 69 | |
---|
| 70 | /* a set of routines that handle the nodes which are files */ |
---|
| 71 | extern rtems_filesystem_file_handlers_r msdos_file_handlers; |
---|
| 72 | |
---|
| 73 | /* Volume semaphore timeout value */ |
---|
| 74 | #define MSDOS_VOLUME_SEMAPHORE_TIMEOUT 100 |
---|
| 75 | |
---|
| 76 | /* Node types */ |
---|
| 77 | #define MSDOS_DIRECTORY RTEMS_FILESYSTEM_DIRECTORY |
---|
| 78 | #define MSDOS_REGULAR_FILE RTEMS_FILESYSTEM_MEMORY_FILE |
---|
| 79 | |
---|
| 80 | typedef rtems_filesystem_node_types_t msdos_node_type_t; |
---|
| 81 | |
---|
| 82 | /* |
---|
| 83 | * Macros for fetching fields from 32 bytes long FAT Directory Entry |
---|
| 84 | * Structure (see M$ White Paper) |
---|
| 85 | */ |
---|
| 86 | #define MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE 32 /* 32 bytes */ |
---|
| 87 | |
---|
| 88 | #define MSDOS_DIR_NAME(x) (unsigned8 *)((x) + 0) |
---|
| 89 | #define MSDOS_DIR_ATTR(x) (unsigned8 *)((x) + 11) |
---|
| 90 | #define MSDOS_DIR_NT_RES(x) (unsigned8 *)((x) + 12) |
---|
| 91 | #define MSDOS_DIR_CRT_TIME_TENTH(x) (unsigned8 *)((x) + 13) |
---|
| 92 | #define MSDOS_DIR_CRT_TIME(x) (unsigned16 *)((x) + 14) |
---|
| 93 | #define MSDOS_DIR_CRT_DATE(x) (unsigned16 *)((x) + 16) |
---|
| 94 | #define MSDOS_DIR_LAST_ACCESS_DATE(x) (unsigned16 *)((x) + 18) |
---|
| 95 | #define MSDOS_DIR_FIRST_CLUSTER_HI(x) (unsigned16 *)((x) + 20) |
---|
| 96 | #define MSDOS_DIR_WRITE_TIME(x) (unsigned16 *)((x) + 22) |
---|
| 97 | #define MSDOS_DIR_WRITE_DATE(x) (unsigned16 *)((x) + 24) |
---|
| 98 | #define MSDOS_DIR_FIRST_CLUSTER_LOW(x) (unsigned16 *)((x) + 26) |
---|
| 99 | #define MSDOS_DIR_FILE_SIZE(x) (unsigned32 *)((x) + 28) |
---|
| 100 | |
---|
| 101 | #define MSDOS_EXTRACT_CLUSTER_NUM(p) \ |
---|
| 102 | (unsigned32)( (CF_LE_W(*MSDOS_DIR_FIRST_CLUSTER_LOW(p))) | \ |
---|
[a36e988] | 103 | ((unsigned32)(CF_LE_W((*MSDOS_DIR_FIRST_CLUSTER_HI(p))))<<16) ) |
---|
[f36a7bfc] | 104 | |
---|
| 105 | /* |
---|
| 106 | * Fields offset in 32 bytes long FAT Directory Entry |
---|
| 107 | * Structure (see M$ White Paper) |
---|
| 108 | */ |
---|
| 109 | #define MSDOS_FILE_SIZE_OFFSET 28 |
---|
| 110 | #define MSDOS_FILE_NAME_OFFSET 0 |
---|
| 111 | #define MSDOS_FIRST_CLUSTER_HI_OFFSET 20 |
---|
| 112 | #define MSDOS_FIRST_CLUSTER_LOW_OFFSET 26 |
---|
| 113 | #define MSDOS_FILE_WDATE_OFFSET 24 |
---|
| 114 | #define MSDOS_FILE_WTIME_OFFSET 22 |
---|
| 115 | |
---|
| 116 | /* |
---|
| 117 | * Possible values of DIR_Attr field of 32 bytes long FAT Directory Entry |
---|
| 118 | * Structure (see M$ White Paper) |
---|
| 119 | */ |
---|
| 120 | #define MSDOS_ATTR_READ_ONLY 0x01 |
---|
| 121 | #define MSDOS_ATTR_HIDDEN 0x02 |
---|
| 122 | #define MSDOS_ATTR_SYSTEM 0x04 |
---|
| 123 | #define MSDOS_ATTR_VOLUME_ID 0x08 |
---|
| 124 | #define MSDOS_ATTR_DIRECTORY 0x10 |
---|
| 125 | #define MSDOS_ATTR_ARCHIVE 0x20 |
---|
| 126 | |
---|
| 127 | /* |
---|
| 128 | * Possible values of DIR_Name[0] field of 32 bytes long FAT Directory Entry |
---|
| 129 | * Structure (see M$ White Paper) |
---|
| 130 | */ |
---|
| 131 | #define MSDOS_THIS_DIR_ENTRY_EMPTY 0xE5 |
---|
| 132 | #define MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY 0x00 |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | /* |
---|
| 136 | * Macros for names parsing and formatting |
---|
| 137 | */ |
---|
| 138 | #define msdos_is_valid_name_char(_ch) (1) |
---|
| 139 | #define msdos_is_separator(_ch) rtems_filesystem_is_separator(_ch) |
---|
| 140 | |
---|
[01c5b9d7] | 141 | #define MSDOS_SHORT_BASE_LEN 8 /* 8 characters */ |
---|
| 142 | #define MSDOS_SHORT_EXT_LEN 3 /* 3 characters */ |
---|
| 143 | #define MSDOS_SHORT_NAME_LEN (MSDOS_SHORT_BASE_LEN+\ |
---|
| 144 | MSDOS_SHORT_EXT_LEN) /* 11 chars */ |
---|
[f36a7bfc] | 145 | #define MSDOS_NAME_MAX MSDOS_SHORT_NAME_LEN |
---|
| 146 | #define MSDOS_NAME_MAX_WITH_DOT (MSDOS_NAME_MAX + 1) |
---|
| 147 | |
---|
| 148 | #define MSDOS_DOT_NAME ". " /* ".", padded to MSDOS_NAME chars */ |
---|
| 149 | #define MSDOS_DOTDOT_NAME ".. " /* "..", padded to MSDOS_NAME chars */ |
---|
| 150 | |
---|
| 151 | typedef enum msdos_token_types_e |
---|
| 152 | { |
---|
| 153 | MSDOS_NO_MORE_PATH, |
---|
| 154 | MSDOS_CURRENT_DIR, |
---|
| 155 | MSDOS_UP_DIR, |
---|
| 156 | MSDOS_NAME, |
---|
| 157 | MSDOS_INVALID_TOKEN |
---|
| 158 | } msdos_token_types_t; |
---|
| 159 | |
---|
| 160 | /* Others macros */ |
---|
| 161 | #define MSDOS_RES_NT_VALUE 0x00 |
---|
| 162 | #define MSDOS_INIT_DIR_SIZE 0x00 |
---|
| 163 | |
---|
| 164 | /* "dot" entry offset in a directory */ |
---|
| 165 | #define MSDOS_DOT_DIR_ENTRY_OFFSET 0x00 /* first entry in directory */ |
---|
| 166 | |
---|
| 167 | /* "dotdot" entry offset in a directory */ |
---|
| 168 | #define MSDOS_DOTDOT_DIR_ENTRY_OFFSET 0x20 /* second entry in directory */ |
---|
| 169 | |
---|
| 170 | /* 'p' should be char* */ |
---|
| 171 | #define DOT_NODE_P(p) ((char *)(p)) |
---|
| 172 | #define DOTDOT_NODE_P(p) ((char *)((p) + MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE)) |
---|
| 173 | |
---|
| 174 | /* Size limits for files and directories (see M$ White Paper) */ |
---|
| 175 | #define MSDOS_MAX_DIR_LENGHT 0x200000 /* 2,097,152 bytes */ |
---|
| 176 | #define MSDOS_MAX_FILE_SIZE 0xFFFFFFFF /* 4 Gb */ |
---|
| 177 | |
---|
| 178 | /* |
---|
| 179 | * The number of 32 bytes long FAT Directory Entry |
---|
| 180 | * Structures per 512 bytes sector |
---|
| 181 | */ |
---|
| 182 | #define MSDOS_DPS512_NUM 16 |
---|
| 183 | |
---|
| 184 | /* Prototypes */ |
---|
| 185 | int |
---|
| 186 | msdos_initialize(rtems_filesystem_mount_table_entry_t *temp_mt_entry); |
---|
| 187 | |
---|
| 188 | int |
---|
| 189 | msdos_shut_down(rtems_filesystem_mount_table_entry_t *temp_mt_entry); |
---|
| 190 | |
---|
| 191 | int |
---|
| 192 | msdos_eval_path(const char *pathname, /* IN */ |
---|
| 193 | int flags, /* IN */ |
---|
| 194 | rtems_filesystem_location_info_t *pathloc /* IN/OUT */); |
---|
| 195 | |
---|
| 196 | int |
---|
| 197 | msdos_eval4make(const char *path, /* IN */ |
---|
| 198 | rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ |
---|
| 199 | const char **name /* OUT */); |
---|
| 200 | |
---|
| 201 | int |
---|
| 202 | msdos_unlink(rtems_filesystem_location_info_t *pathloc /* IN */); |
---|
| 203 | |
---|
| 204 | int |
---|
| 205 | msdos_free_node_info(rtems_filesystem_location_info_t *pathloc /* IN */); |
---|
| 206 | |
---|
| 207 | rtems_filesystem_node_types_t |
---|
| 208 | msdos_node_type(rtems_filesystem_location_info_t *pathloc); |
---|
| 209 | |
---|
| 210 | int |
---|
| 211 | msdos_mknod(const char *path, /* IN */ |
---|
| 212 | mode_t mode, /* IN */ |
---|
| 213 | dev_t dev, /* IN */ |
---|
| 214 | rtems_filesystem_location_info_t *pathloc /* IN/OUT */); |
---|
| 215 | |
---|
| 216 | int |
---|
| 217 | msdos_utime(rtems_filesystem_location_info_t *pathloc, /* IN */ |
---|
| 218 | time_t actime, /* IN */ |
---|
| 219 | time_t modtime /* IN */); |
---|
| 220 | |
---|
| 221 | int |
---|
| 222 | msdos_initialize_support( |
---|
| 223 | rtems_filesystem_mount_table_entry_t *temp_mt_entry, |
---|
| 224 | rtems_filesystem_operations_table *op_table, |
---|
| 225 | rtems_filesystem_file_handlers_r *file_handlers, |
---|
| 226 | rtems_filesystem_file_handlers_r *directory_handlers |
---|
| 227 | ); |
---|
| 228 | |
---|
| 229 | int |
---|
| 230 | msdos_file_open( |
---|
| 231 | rtems_libio_t *iop, /* IN */ |
---|
| 232 | const char *pathname, /* IN */ |
---|
| 233 | unsigned32 flag, /* IN */ |
---|
| 234 | unsigned32 mode /* IN */ |
---|
| 235 | ); |
---|
| 236 | |
---|
| 237 | int |
---|
| 238 | msdos_file_close(rtems_libio_t *iop /* IN */); |
---|
| 239 | |
---|
| 240 | ssize_t |
---|
| 241 | msdos_file_read( |
---|
| 242 | rtems_libio_t *iop, /* IN */ |
---|
| 243 | void *buffer, /* IN */ |
---|
| 244 | unsigned32 count /* IN */ |
---|
| 245 | ); |
---|
| 246 | |
---|
| 247 | ssize_t |
---|
| 248 | msdos_file_write( |
---|
| 249 | rtems_libio_t *iop, /* IN */ |
---|
| 250 | const void *buffer, /* IN */ |
---|
| 251 | unsigned32 count /* IN */ |
---|
| 252 | ); |
---|
| 253 | |
---|
| 254 | int |
---|
| 255 | msdos_file_lseek( |
---|
| 256 | rtems_libio_t *iop, /* IN */ |
---|
| 257 | off_t offset, /* IN */ |
---|
| 258 | int whence /* IN */ |
---|
| 259 | ); |
---|
| 260 | |
---|
| 261 | int |
---|
| 262 | msdos_file_stat(rtems_filesystem_location_info_t *loc, /* IN */ |
---|
| 263 | struct stat *buf /* OUT */); |
---|
| 264 | |
---|
| 265 | int |
---|
| 266 | msdos_file_ftruncate( |
---|
| 267 | rtems_libio_t *iop, /* IN */ |
---|
| 268 | off_t length /* IN */ |
---|
| 269 | ); |
---|
| 270 | |
---|
| 271 | int |
---|
| 272 | msdos_file_sync(rtems_libio_t *iop); |
---|
| 273 | |
---|
| 274 | int |
---|
| 275 | msdos_file_datasync(rtems_libio_t *iop); |
---|
| 276 | |
---|
| 277 | int |
---|
| 278 | msdos_file_ioctl( |
---|
| 279 | rtems_libio_t *iop, /* IN */ |
---|
| 280 | unsigned32 command, /* IN */ |
---|
| 281 | void *buffer /* IN */ |
---|
| 282 | ); |
---|
| 283 | |
---|
| 284 | int |
---|
| 285 | msdos_file_rmnod(rtems_filesystem_location_info_t *pathloc /* IN */); |
---|
| 286 | |
---|
| 287 | int |
---|
| 288 | msdos_dir_open( |
---|
| 289 | rtems_libio_t *iop, /* IN */ |
---|
| 290 | const char *pathname, /* IN */ |
---|
| 291 | unsigned32 flag, /* IN */ |
---|
| 292 | unsigned32 mode /* IN */ |
---|
| 293 | ); |
---|
| 294 | |
---|
| 295 | int |
---|
| 296 | msdos_dir_close(rtems_libio_t *iop /* IN */); |
---|
| 297 | |
---|
| 298 | ssize_t |
---|
| 299 | msdos_dir_read( |
---|
| 300 | rtems_libio_t *iop, /* IN */ |
---|
| 301 | void *buffer, /* IN */ |
---|
| 302 | unsigned32 count /* IN */ |
---|
| 303 | ); |
---|
| 304 | |
---|
| 305 | int |
---|
| 306 | msdos_dir_lseek( |
---|
| 307 | rtems_libio_t *iop, /* IN */ |
---|
| 308 | off_t offset, /* IN */ |
---|
| 309 | int whence /* IN */ |
---|
| 310 | ); |
---|
| 311 | |
---|
| 312 | int |
---|
| 313 | msdos_dir_rmnod(rtems_filesystem_location_info_t *pathloc /* IN */); |
---|
| 314 | |
---|
| 315 | int |
---|
| 316 | msdos_dir_sync(rtems_libio_t *iop); |
---|
| 317 | |
---|
| 318 | int |
---|
| 319 | msdos_dir_stat( |
---|
| 320 | rtems_filesystem_location_info_t *loc, /* IN */ |
---|
| 321 | struct stat *buf /* OUT */ |
---|
| 322 | ); |
---|
| 323 | |
---|
| 324 | int |
---|
| 325 | msdos_creat_node(rtems_filesystem_location_info_t *parent_loc, |
---|
| 326 | msdos_node_type_t type, |
---|
| 327 | char *name, |
---|
| 328 | mode_t mode); |
---|
| 329 | |
---|
| 330 | /* Misc prototypes */ |
---|
| 331 | msdos_token_types_t msdos_get_token(const char *path, |
---|
| 332 | char *token, |
---|
| 333 | int *token_len); |
---|
| 334 | |
---|
| 335 | int |
---|
| 336 | msdos_find_name(rtems_filesystem_location_info_t *parent_loc, |
---|
| 337 | char *name); |
---|
| 338 | |
---|
| 339 | int |
---|
| 340 | msdos_get_name_node(rtems_filesystem_location_info_t *parent_loc, |
---|
| 341 | char *name, |
---|
| 342 | fat_auxiliary_t *paux, |
---|
| 343 | char *name_dir_entry); |
---|
| 344 | |
---|
| 345 | int |
---|
| 346 | msdos_dir_info_remove(rtems_filesystem_location_info_t *pathloc); |
---|
| 347 | |
---|
| 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); |
---|
| 355 | |
---|
| 356 | int |
---|
| 357 | msdos_set_first_cluster_num(rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
| 358 | fat_file_fd_t *fat_fd); |
---|
| 359 | |
---|
| 360 | int |
---|
| 361 | msdos_set_file_size(rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
| 362 | fat_file_fd_t *fat_fd); |
---|
| 363 | |
---|
| 364 | int |
---|
| 365 | msdos_set_first_char4file_name(rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
| 366 | unsigned32 cl, |
---|
| 367 | unsigned32 ofs, |
---|
| 368 | unsigned char first_char); |
---|
| 369 | |
---|
| 370 | int |
---|
| 371 | msdos_set_dir_wrt_time_and_date( |
---|
| 372 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
| 373 | fat_file_fd_t *fat_fd |
---|
| 374 | ); |
---|
| 375 | |
---|
| 376 | |
---|
| 377 | int |
---|
| 378 | msdos_dir_is_empty(rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
| 379 | fat_file_fd_t *fat_fd, |
---|
| 380 | rtems_boolean *ret_val); |
---|
| 381 | |
---|
| 382 | int |
---|
| 383 | msdos_find_name_in_fat_file( |
---|
| 384 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
| 385 | fat_file_fd_t *fat_fd, |
---|
| 386 | char *name, |
---|
| 387 | fat_auxiliary_t *paux, |
---|
| 388 | char *name_dir_entry); |
---|
| 389 | |
---|
| 390 | int |
---|
| 391 | msdos_find_node_by_cluster_num_in_fat_file( |
---|
| 392 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
| 393 | fat_file_fd_t *fat_fd, |
---|
| 394 | unsigned32 cl4find, |
---|
| 395 | fat_auxiliary_t *paux, |
---|
| 396 | char *dir_entry |
---|
| 397 | ); |
---|
| 398 | |
---|
| 399 | int |
---|
| 400 | msdos_get_dotdot_dir_info_cluster_num_and_offset( |
---|
| 401 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
| 402 | unsigned32 cln, |
---|
| 403 | fat_auxiliary_t *paux, |
---|
| 404 | char *dir_entry |
---|
| 405 | ); |
---|
| 406 | |
---|
| 407 | #ifdef __cplusplus |
---|
| 408 | } |
---|
| 409 | #endif |
---|
| 410 | |
---|
| 411 | #endif /* __DOSFS_MSDOS_H__ */ |
---|