1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Init Routine for MSDOS |
---|
5 | * @ingroup libfs |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia |
---|
10 | * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru> |
---|
11 | * |
---|
12 | * Modifications to support reference counting in the file system are |
---|
13 | * Copyright (c) 2012 embedded brains GmbH. |
---|
14 | * |
---|
15 | * Modifications to support UTF-8 in the file system are |
---|
16 | * Copyright (c) 2013 embedded brains GmbH. |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.org/license/LICENSE. |
---|
21 | */ |
---|
22 | |
---|
23 | #if HAVE_CONFIG_H |
---|
24 | #include "config.h" |
---|
25 | #endif |
---|
26 | |
---|
27 | #include <rtems/libio_.h> |
---|
28 | #include "dosfs.h" |
---|
29 | #include "msdos.h" |
---|
30 | |
---|
31 | static int msdos_clone_node_info(rtems_filesystem_location_info_t *loc) |
---|
32 | { |
---|
33 | fat_file_fd_t *fat_fd = loc->node_access; |
---|
34 | |
---|
35 | return fat_file_reopen(fat_fd); |
---|
36 | } |
---|
37 | |
---|
38 | static int msdos_utime( |
---|
39 | const rtems_filesystem_location_info_t *loc, |
---|
40 | time_t actime, |
---|
41 | time_t modtime |
---|
42 | ) |
---|
43 | { |
---|
44 | fat_file_fd_t *fat_fd = loc->node_access; |
---|
45 | |
---|
46 | if (actime != modtime) |
---|
47 | rtems_set_errno_and_return_minus_one( ENOTSUP ); |
---|
48 | |
---|
49 | fat_file_set_mtime(fat_fd, modtime); |
---|
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 | .utime_h = msdos_utime, |
---|
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_info_t *fs_info = mt_entry->fs_info; |
---|
79 | rtems_status_code sc = rtems_semaphore_obtain( |
---|
80 | fs_info->vol_sema, |
---|
81 | RTEMS_WAIT, |
---|
82 | RTEMS_NO_TIMEOUT |
---|
83 | ); |
---|
84 | if (sc != RTEMS_SUCCESSFUL) { |
---|
85 | rtems_fatal_error_occurred(0xdeadbeef); |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | void msdos_unlock(const rtems_filesystem_mount_table_entry_t *mt_entry) |
---|
90 | { |
---|
91 | msdos_fs_info_t *fs_info = mt_entry->fs_info; |
---|
92 | rtems_status_code sc = rtems_semaphore_release(fs_info->vol_sema); |
---|
93 | if (sc != RTEMS_SUCCESSFUL) { |
---|
94 | rtems_fatal_error_occurred(0xdeadbeef); |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | /* msdos_initialize -- |
---|
99 | * MSDOS filesystem initialization. Called when mounting an |
---|
100 | * MSDOS filesystem. |
---|
101 | * |
---|
102 | * PARAMETERS: |
---|
103 | * temp_mt_entry - mount table entry |
---|
104 | * |
---|
105 | * RETURNS: |
---|
106 | * RC_OK on success, or -1 if error occured (errno set apropriately). |
---|
107 | * |
---|
108 | */ |
---|
109 | int rtems_dosfs_initialize( |
---|
110 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
111 | const void *data |
---|
112 | ) |
---|
113 | { |
---|
114 | int rc = 0; |
---|
115 | const rtems_dosfs_mount_options *mount_options = data; |
---|
116 | rtems_dosfs_convert_control *converter; |
---|
117 | |
---|
118 | |
---|
119 | if (mount_options == NULL || mount_options->converter == NULL) { |
---|
120 | converter = rtems_dosfs_create_default_converter(); |
---|
121 | } else { |
---|
122 | converter = mount_options->converter; |
---|
123 | } |
---|
124 | |
---|
125 | if (converter != NULL) { |
---|
126 | rc = msdos_initialize_support(mt_entry, |
---|
127 | &msdos_ops, |
---|
128 | &msdos_file_handlers, |
---|
129 | &msdos_dir_handlers, |
---|
130 | converter); |
---|
131 | } else { |
---|
132 | errno = ENOMEM; |
---|
133 | rc = -1; |
---|
134 | } |
---|
135 | |
---|
136 | return rc; |
---|
137 | } |
---|