source: rtems/cpukit/libfs/src/dosfs/msdos_initsupp.c @ 36655b8

Last change on this file since 36655b8 was 36655b8, checked in by Sebastian Huber <sebastian.huber@…>, on 07/16/21 at 11:27:00

cpukit: occured -> occurred

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