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

5
Last change on this file since a7f0096 was a7f0096, checked in by Sebastian Huber <sebastian.huber@…>, on 06/06/16 at 10:50:23

dosfs: Use proper semaphore attr for mutex

Close #2727.

  • Property mode set to 100644
File size: 4.3 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    rtems_status_code  sc = RTEMS_SUCCESSFUL;
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_LENGHT;
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    sc = rtems_semaphore_create(3,
137                                1,
138                                RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY |
139                                RTEMS_INHERIT_PRIORITY,
140                                0,
141                                &fs_info->vol_sema);
142    if (sc != RTEMS_SUCCESSFUL)
143    {
144        fat_file_close(&fs_info->fat, fat_fd);
145        fat_shutdown_drive(&fs_info->fat);
146        free(fs_info->cl_buf);
147        free(fs_info);
148        rtems_set_errno_and_return_minus_one( EIO );
149    }
150
151    temp_mt_entry->mt_fs_root->location.node_access = fat_fd;
152    temp_mt_entry->mt_fs_root->location.handlers = directory_handlers;
153    temp_mt_entry->ops = op_table;
154
155    return rc;
156}
Note: See TracBrowser for help on using the repository browser.