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_utimens( |
---|
40 | const rtems_filesystem_location_info_t *loc, |
---|
41 | struct timespec times[2] |
---|
42 | ) |
---|
43 | { |
---|
44 | fat_file_fd_t *fat_fd = loc->node_access; |
---|
45 | |
---|
46 | if (times[0].tv_sec != times[1].tv_sec) |
---|
47 | rtems_set_errno_and_return_minus_one( ENOTSUP ); |
---|
48 | |
---|
49 | fat_file_set_mtime(fat_fd, times[1].tv_sec); |
---|
50 | |
---|
51 | return RC_OK; |
---|
52 | } |
---|
53 | |
---|
54 | const rtems_filesystem_operations_table msdos_ops = { |
---|
55 | .lock_h = msdos_lock, |
---|
56 | .unlock_h = msdos_unlock, |
---|
57 | .eval_path_h = msdos_eval_path, |
---|
58 | .link_h = rtems_filesystem_default_link, |
---|
59 | .are_nodes_equal_h = rtems_filesystem_default_are_nodes_equal, |
---|
60 | .mknod_h = msdos_mknod, |
---|
61 | .rmnod_h = msdos_rmnod, |
---|
62 | .fchmod_h = rtems_filesystem_default_fchmod, |
---|
63 | .chown_h = rtems_filesystem_default_chown, |
---|
64 | .clonenod_h = msdos_clone_node_info, |
---|
65 | .freenod_h = msdos_free_node_info, |
---|
66 | .mount_h = rtems_filesystem_default_mount, |
---|
67 | .unmount_h = rtems_filesystem_default_unmount, |
---|
68 | .fsunmount_me_h = msdos_shut_down, |
---|
69 | .utimens_h = msdos_utimens, |
---|
70 | .symlink_h = rtems_filesystem_default_symlink, |
---|
71 | .readlink_h = rtems_filesystem_default_readlink, |
---|
72 | .rename_h = msdos_rename, |
---|
73 | .statvfs_h = msdos_statvfs |
---|
74 | }; |
---|
75 | |
---|
76 | void msdos_lock(const rtems_filesystem_mount_table_entry_t *mt_entry) |
---|
77 | { |
---|
78 | msdos_fs_lock(mt_entry->fs_info); |
---|
79 | } |
---|
80 | |
---|
81 | void msdos_unlock(const rtems_filesystem_mount_table_entry_t *mt_entry) |
---|
82 | { |
---|
83 | msdos_fs_unlock(mt_entry->fs_info); |
---|
84 | } |
---|
85 | |
---|
86 | /* msdos_initialize -- |
---|
87 | * MSDOS filesystem initialization. Called when mounting an |
---|
88 | * MSDOS filesystem. |
---|
89 | * |
---|
90 | * PARAMETERS: |
---|
91 | * temp_mt_entry - mount table entry |
---|
92 | * |
---|
93 | * RETURNS: |
---|
94 | * RC_OK on success, or -1 if error occured (errno set apropriately). |
---|
95 | * |
---|
96 | */ |
---|
97 | int rtems_dosfs_initialize( |
---|
98 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
99 | const void *data |
---|
100 | ) |
---|
101 | { |
---|
102 | int rc = 0; |
---|
103 | const rtems_dosfs_mount_options *mount_options = data; |
---|
104 | rtems_dosfs_convert_control *converter; |
---|
105 | bool converter_created = false; |
---|
106 | |
---|
107 | |
---|
108 | if (mount_options == NULL || mount_options->converter == NULL) { |
---|
109 | converter = rtems_dosfs_create_default_converter(); |
---|
110 | converter_created = true; |
---|
111 | } else { |
---|
112 | converter = mount_options->converter; |
---|
113 | } |
---|
114 | |
---|
115 | if (converter != NULL) { |
---|
116 | rc = msdos_initialize_support(mt_entry, |
---|
117 | &msdos_ops, |
---|
118 | &msdos_file_handlers, |
---|
119 | &msdos_dir_handlers, |
---|
120 | converter); |
---|
121 | if (rc != 0 && converter_created) { |
---|
122 | (*converter->handler->destroy)(converter); |
---|
123 | } |
---|
124 | } else { |
---|
125 | errno = ENOMEM; |
---|
126 | rc = -1; |
---|
127 | } |
---|
128 | |
---|
129 | return rc; |
---|
130 | } |
---|