Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:16

0001 /**
0002  * @file
0003  *
0004  * @ingroup DOSFS
0005  *
0006  * @brief Init Routine for MSDOS
0007  */
0008 
0009 /*
0010  *  Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
0011  *  Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
0012  *
0013  *  Modifications to support reference counting in the file system are
0014  *  Copyright (c) 2012 embedded brains GmbH & Co. KG
0015  *
0016  *  Modifications to support UTF-8 in the file system are
0017  *  Copyright (c) 2013 embedded brains GmbH & Co. KG
0018  *
0019  *  The license and distribution terms for this file may be
0020  *  found in the file LICENSE in this distribution or at
0021  *  http://www.rtems.org/license/LICENSE.
0022  */
0023 
0024 #ifdef HAVE_CONFIG_H
0025 #include "config.h"
0026 #endif
0027 
0028 #include <rtems/libio_.h>
0029 #include <rtems/dosfs.h>
0030 #include "msdos.h"
0031 
0032 static int msdos_clone_node_info(rtems_filesystem_location_info_t *loc)
0033 {
0034     fat_file_fd_t *fat_fd = loc->node_access;
0035 
0036     return fat_file_reopen(fat_fd);
0037 }
0038 
0039 static int msdos_utimens(
0040   const rtems_filesystem_location_info_t *loc,
0041   struct timespec                         times[2]
0042 )
0043 {
0044     fat_file_fd_t *fat_fd = loc->node_access;
0045 
0046     if (times[0].tv_sec != times[1].tv_sec)
0047         rtems_set_errno_and_return_minus_one( ENOTSUP );
0048 
0049     fat_file_set_mtime(fat_fd, times[1].tv_sec);
0050 
0051     return RC_OK;
0052 }
0053 
0054 const rtems_filesystem_operations_table  msdos_ops = {
0055   .lock_h         =  msdos_lock,
0056   .unlock_h       =  msdos_unlock,
0057   .eval_path_h    =  msdos_eval_path,
0058   .link_h         =  rtems_filesystem_default_link,
0059   .are_nodes_equal_h = rtems_filesystem_default_are_nodes_equal,
0060   .mknod_h        =  msdos_mknod,
0061   .rmnod_h        =  msdos_rmnod,
0062   .fchmod_h       =  rtems_filesystem_default_fchmod,
0063   .chown_h        =  rtems_filesystem_default_chown,
0064   .clonenod_h     =  msdos_clone_node_info,
0065   .freenod_h      =  msdos_free_node_info,
0066   .mount_h        =  rtems_filesystem_default_mount,
0067   .unmount_h      =  rtems_filesystem_default_unmount,
0068   .fsunmount_me_h =  msdos_shut_down,
0069   .utimens_h      =  msdos_utimens,
0070   .symlink_h      =  rtems_filesystem_default_symlink,
0071   .readlink_h     =  rtems_filesystem_default_readlink,
0072   .rename_h       =  msdos_rename,
0073   .statvfs_h      =  msdos_statvfs
0074 };
0075 
0076 void msdos_lock(const rtems_filesystem_mount_table_entry_t *mt_entry)
0077 {
0078   msdos_fs_lock(mt_entry->fs_info);
0079 }
0080 
0081 void msdos_unlock(const rtems_filesystem_mount_table_entry_t *mt_entry)
0082 {
0083   msdos_fs_unlock(mt_entry->fs_info);
0084 }
0085 
0086 /* msdos_initialize --
0087  *     MSDOS filesystem initialization. Called when mounting an
0088  *     MSDOS filesystem.
0089  *
0090  * PARAMETERS:
0091  *     temp_mt_entry - mount table entry
0092  *
0093  * RETURNS:
0094  *     RC_OK on success, or -1 if error occurred (errno set apropriately).
0095  *
0096  */
0097 int rtems_dosfs_initialize(
0098   rtems_filesystem_mount_table_entry_t *mt_entry,
0099   const void                           *data
0100 )
0101 {
0102     int                                rc = 0;
0103     const rtems_dosfs_mount_options   *mount_options = data;
0104     rtems_dosfs_convert_control       *converter;
0105     bool                               converter_created = false;
0106 
0107 
0108     if (mount_options == NULL || mount_options->converter == NULL) {
0109         converter = rtems_dosfs_create_default_converter();
0110         converter_created = true;
0111     } else {
0112         converter = mount_options->converter;
0113     }
0114 
0115     if (converter != NULL) {
0116         rc = msdos_initialize_support(mt_entry,
0117                                       &msdos_ops,
0118                                       &msdos_file_handlers,
0119                                       &msdos_dir_handlers,
0120                                       converter);
0121         if (rc != 0 && converter_created) {
0122             (*converter->handler->destroy)(converter);
0123         }
0124     } else {
0125         errno = ENOMEM;
0126         rc = -1;
0127     }
0128 
0129     return rc;
0130 }