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

4.115
Last change on this file since d883ce2 was d883ce2, checked in by Mathew Kallada <matkallada@…>, on 12/20/12 at 14:22:52

libfs: Doxygen Enhancement Task #6"

  • Property mode set to 100644
File size: 4.2 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.com/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    )
57{
58    int                rc = RC_OK;
59    rtems_status_code  sc = RTEMS_SUCCESSFUL;
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    rc = fat_init_volume_info(&fs_info->fat, temp_mt_entry->dev);
72    if (rc != RC_OK)
73    {
74        free(fs_info);
75        return rc;
76    }
77
78    fs_info->file_handlers      = file_handlers;
79    fs_info->directory_handlers = directory_handlers;
80
81    /*
82     * open fat-file which correspondes to  root directory
83     * (so inode number 0x00000010 is always used for root directory)
84     */
85    fat_dir_pos_init(&root_pos);
86    root_pos.sname.cln = FAT_ROOTDIR_CLUSTER_NUM;
87    rc = fat_file_open(&fs_info->fat, &root_pos, &fat_fd);
88    if (rc != RC_OK)
89    {
90        fat_shutdown_drive(&fs_info->fat);
91        free(fs_info);
92        return rc;
93    }
94
95    /* again: unfortunately "fat-file" is just almost fat file :( */
96    fat_fd->fat_file_type = FAT_DIRECTORY;
97    fat_fd->size_limit = MSDOS_MAX_DIR_LENGHT;
98    fat_fd->cln = fs_info->fat.vol.rdir_cl;
99
100    fat_fd->map.file_cln = 0;
101    fat_fd->map.disk_cln = fat_fd->cln;
102
103    /* if we have FAT12/16 */
104    if ( fat_fd->cln == 0 )
105    {
106        fat_fd->fat_file_size = fs_info->fat.vol.rdir_size;
107        cl_buf_size = (fs_info->fat.vol.bpc > fs_info->fat.vol.rdir_size) ?
108                      fs_info->fat.vol.bpc                                :
109                      fs_info->fat.vol.rdir_size;
110    }
111    else
112    {
113        rc = fat_file_size(&fs_info->fat, fat_fd);
114        if ( rc != RC_OK )
115        {
116            fat_file_close(&fs_info->fat, fat_fd);
117            fat_shutdown_drive(&fs_info->fat);
118            free(fs_info);
119            return rc;
120        }
121        cl_buf_size = fs_info->fat.vol.bpc;
122    }
123
124    fs_info->cl_buf = (uint8_t *)calloc(cl_buf_size, sizeof(char));
125    if (fs_info->cl_buf == NULL)
126    {
127        fat_file_close(&fs_info->fat, fat_fd);
128        fat_shutdown_drive(&fs_info->fat);
129        free(fs_info);
130        rtems_set_errno_and_return_minus_one(ENOMEM);
131    }
132
133    sc = rtems_semaphore_create(3,
134                                1,
135                                RTEMS_BINARY_SEMAPHORE | RTEMS_FIFO,
136                                0,
137                                &fs_info->vol_sema);
138    if (sc != RTEMS_SUCCESSFUL)
139    {
140        fat_file_close(&fs_info->fat, fat_fd);
141        fat_shutdown_drive(&fs_info->fat);
142        free(fs_info->cl_buf);
143        free(fs_info);
144        rtems_set_errno_and_return_minus_one( EIO );
145    }
146
147    temp_mt_entry->mt_fs_root->location.node_access = fat_fd;
148    temp_mt_entry->mt_fs_root->location.handlers = directory_handlers;
149    temp_mt_entry->ops = op_table;
150
151    return rc;
152}
Note: See TracBrowser for help on using the repository browser.