source: rtems/cpukit/libfs/src/dosfs/msdos_initsupp.c @ 0ec9bbc

5
Last change on this file since 0ec9bbc was 3b77417, checked in by Sebastian Huber <sebastian.huber@…>, on 12/13/17 at 15:15:25

dosfs: Use self-contained recursive mutex

Update #2843.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/**
2 * @file
3 *
4 * @brief MSDOS Filesystem Initialization
5 * @ingroup libfs_msdos MSDOS FileSystem
6 */
7
8/*
9 *  Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
10 *  Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <sys/types.h>
22#include <fcntl.h>
23#include <unistd.h>
24#include <stdlib.h>
25#include <stdio.h>
26
27#include <rtems.h>
28#include <rtems/libio_.h>
29
30#include "fat.h"
31#include "fat_fat_operations.h"
32#include "fat_file.h"
33
34#include "msdos.h"
35
36/* msdos_initialize_support --
37 *     MSDOS filesystem initialization
38 *
39 * PARAMETERS:
40 *     temp_mt_entry      - mount table entry
41 *     op_table           - filesystem operations table
42 *     file_handlers      - file operations table
43 *     directory_handlers - directory operations table
44 *
45 * RETURNS:
46 *     RC_OK and filled temp_mt_entry on success, or -1 if error occured
47 *     (errno set apropriately)
48 *
49 */
50int
51msdos_initialize_support(
52    rtems_filesystem_mount_table_entry_t    *temp_mt_entry,
53    const rtems_filesystem_operations_table *op_table,
54    const rtems_filesystem_file_handlers_r  *file_handlers,
55    const rtems_filesystem_file_handlers_r  *directory_handlers,
56    rtems_dosfs_convert_control             *converter
57    )
58{
59    int                rc = RC_OK;
60    msdos_fs_info_t   *fs_info = NULL;
61    fat_file_fd_t     *fat_fd = NULL;
62    fat_dir_pos_t      root_pos;
63    uint32_t           cl_buf_size;
64
65    fs_info = (msdos_fs_info_t *)calloc(1, sizeof(msdos_fs_info_t));
66    if (!fs_info)
67        rtems_set_errno_and_return_minus_one(ENOMEM);
68
69    temp_mt_entry->fs_info = fs_info;
70
71    fs_info->converter = converter;
72
73    rc = fat_init_volume_info(&fs_info->fat, temp_mt_entry->dev);
74    if (rc != RC_OK)
75    {
76        free(fs_info);
77        return rc;
78    }
79
80    fs_info->file_handlers      = file_handlers;
81    fs_info->directory_handlers = directory_handlers;
82
83    /*
84     * open fat-file which correspondes to  root directory
85     * (so inode number 0x00000010 is always used for root directory)
86     */
87    fat_dir_pos_init(&root_pos);
88    root_pos.sname.cln = FAT_ROOTDIR_CLUSTER_NUM;
89    rc = fat_file_open(&fs_info->fat, &root_pos, &fat_fd);
90    if (rc != RC_OK)
91    {
92        fat_shutdown_drive(&fs_info->fat);
93        free(fs_info);
94        return rc;
95    }
96
97    /* again: unfortunately "fat-file" is just almost fat file :( */
98    fat_fd->fat_file_type = FAT_DIRECTORY;
99    fat_fd->size_limit = MSDOS_MAX_DIR_LENGTH;
100    fat_fd->cln = fs_info->fat.vol.rdir_cl;
101
102    fat_fd->map.file_cln = 0;
103    fat_fd->map.disk_cln = fat_fd->cln;
104
105    /* if we have FAT12/16 */
106    if ( fat_fd->cln == 0 )
107    {
108        fat_fd->fat_file_size = fs_info->fat.vol.rdir_size;
109        cl_buf_size = (fs_info->fat.vol.bpc > fs_info->fat.vol.rdir_size) ?
110                      fs_info->fat.vol.bpc                                :
111                      fs_info->fat.vol.rdir_size;
112    }
113    else
114    {
115        rc = fat_file_size(&fs_info->fat, fat_fd);
116        if ( rc != RC_OK )
117        {
118            fat_file_close(&fs_info->fat, fat_fd);
119            fat_shutdown_drive(&fs_info->fat);
120            free(fs_info);
121            return rc;
122        }
123        cl_buf_size = fs_info->fat.vol.bpc;
124    }
125
126    fs_info->cl_buf = (uint8_t *)calloc(cl_buf_size, sizeof(char));
127    if (fs_info->cl_buf == NULL)
128    {
129        fat_file_close(&fs_info->fat, fat_fd);
130        fat_shutdown_drive(&fs_info->fat);
131        free(fs_info);
132        rtems_set_errno_and_return_minus_one(ENOMEM);
133    }
134
135    rtems_recursive_mutex_init(&fs_info->vol_mutex,
136                               RTEMS_FILESYSTEM_TYPE_DOSFS);
137
138    temp_mt_entry->mt_fs_root->location.node_access = fat_fd;
139    temp_mt_entry->mt_fs_root->location.handlers = directory_handlers;
140    temp_mt_entry->ops = op_table;
141
142    return rc;
143}
Note: See TracBrowser for help on using the repository browser.