1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup DOSFS |
---|
5 | * |
---|
6 | * @brief Init Routine for MSDOS |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia |
---|
11 | * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru> |
---|
12 | * |
---|
13 | * Modifications to support reference counting in the file system are |
---|
14 | * Copyright (c) 2012 embedded brains GmbH. |
---|
15 | * |
---|
16 | * Modifications to support UTF-8 in the file system are |
---|
17 | * Copyright (c) 2013 embedded brains GmbH. |
---|
18 | * |
---|
19 | * The license and distribution terms for this file may be |
---|
20 | * found in the file LICENSE in this distribution or at |
---|
21 | * http://www.rtems.org/license/LICENSE. |
---|
22 | */ |
---|
23 | |
---|
24 | #ifdef HAVE_CONFIG_H |
---|
25 | #include "config.h" |
---|
26 | #endif |
---|
27 | |
---|
28 | #include <rtems/libio_.h> |
---|
29 | #include <rtems/dosfs.h> |
---|
30 | #include "msdos.h" |
---|
31 | |
---|
32 | static int msdos_clone_node_info(rtems_filesystem_location_info_t *loc) |
---|
33 | { |
---|
34 | fat_file_fd_t *fat_fd = loc->node_access; |
---|
35 | |
---|
36 | return fat_file_reopen(fat_fd); |
---|
37 | } |
---|
38 | |
---|
39 | static int msdos_utime( |
---|
40 | const rtems_filesystem_location_info_t *loc, |
---|
41 | time_t actime, |
---|
42 | time_t modtime |
---|
43 | ) |
---|
44 | { |
---|
45 | fat_file_fd_t *fat_fd = loc->node_access; |
---|
46 | |
---|
47 | if (actime != modtime) |
---|
48 | rtems_set_errno_and_return_minus_one( ENOTSUP ); |
---|
49 | |
---|
50 | fat_file_set_mtime(fat_fd, modtime); |
---|
51 | |
---|
52 | return RC_OK; |
---|
53 | } |
---|
54 | |
---|
55 | const rtems_filesystem_operations_table msdos_ops = { |
---|
56 | .lock_h = msdos_lock, |
---|
57 | .unlock_h = msdos_unlock, |
---|
58 | .eval_path_h = msdos_eval_path, |
---|
59 | .link_h = rtems_filesystem_default_link, |
---|
60 | .are_nodes_equal_h = rtems_filesystem_default_are_nodes_equal, |
---|
61 | .mknod_h = msdos_mknod, |
---|
62 | .rmnod_h = msdos_rmnod, |
---|
63 | .fchmod_h = rtems_filesystem_default_fchmod, |
---|
64 | .chown_h = rtems_filesystem_default_chown, |
---|
65 | .clonenod_h = msdos_clone_node_info, |
---|
66 | .freenod_h = msdos_free_node_info, |
---|
67 | .mount_h = rtems_filesystem_default_mount, |
---|
68 | .unmount_h = rtems_filesystem_default_unmount, |
---|
69 | .fsunmount_me_h = msdos_shut_down, |
---|
70 | .utime_h = msdos_utime, |
---|
71 | .symlink_h = rtems_filesystem_default_symlink, |
---|
72 | .readlink_h = rtems_filesystem_default_readlink, |
---|
73 | .rename_h = msdos_rename, |
---|
74 | .statvfs_h = msdos_statvfs |
---|
75 | }; |
---|
76 | |
---|
77 | void msdos_lock(const rtems_filesystem_mount_table_entry_t *mt_entry) |
---|
78 | { |
---|
79 | msdos_fs_lock(mt_entry->fs_info); |
---|
80 | } |
---|
81 | |
---|
82 | void msdos_unlock(const rtems_filesystem_mount_table_entry_t *mt_entry) |
---|
83 | { |
---|
84 | msdos_fs_unlock(mt_entry->fs_info); |
---|
85 | } |
---|
86 | |
---|
87 | /* msdos_initialize -- |
---|
88 | * MSDOS filesystem initialization. Called when mounting an |
---|
89 | * MSDOS filesystem. |
---|
90 | * |
---|
91 | * PARAMETERS: |
---|
92 | * temp_mt_entry - mount table entry |
---|
93 | * |
---|
94 | * RETURNS: |
---|
95 | * RC_OK on success, or -1 if error occured (errno set apropriately). |
---|
96 | * |
---|
97 | */ |
---|
98 | int rtems_dosfs_initialize( |
---|
99 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
100 | const void *data |
---|
101 | ) |
---|
102 | { |
---|
103 | int rc = 0; |
---|
104 | const rtems_dosfs_mount_options *mount_options = data; |
---|
105 | rtems_dosfs_convert_control *converter; |
---|
106 | bool converter_created = false; |
---|
107 | |
---|
108 | |
---|
109 | if (mount_options == NULL || mount_options->converter == NULL) { |
---|
110 | converter = rtems_dosfs_create_default_converter(); |
---|
111 | converter_created = true; |
---|
112 | } else { |
---|
113 | converter = mount_options->converter; |
---|
114 | } |
---|
115 | |
---|
116 | if (converter != NULL) { |
---|
117 | rc = msdos_initialize_support(mt_entry, |
---|
118 | &msdos_ops, |
---|
119 | &msdos_file_handlers, |
---|
120 | &msdos_dir_handlers, |
---|
121 | converter); |
---|
122 | if (rc != 0 && converter_created) { |
---|
123 | (*converter->handler->destroy)(converter); |
---|
124 | } |
---|
125 | } else { |
---|
126 | errno = ENOMEM; |
---|
127 | rc = -1; |
---|
128 | } |
---|
129 | |
---|
130 | return rc; |
---|
131 | } |
---|