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

Last change on this file since a7d1992c was da154e14, checked in by Sebastian Huber <sebastian.huber@…>, on 05/14/12 at 14:55:41

Filesystem: Move operations to mount table entry

The scope of the file system operations is the file system instance.
The scope of the file system node handlers is the file location. The
benefit of moving the operations to the mount table entry is a size
reduction of the file location (rtems_filesystem_location_info_t). The
code size is slightly increased due to additional load instructions.

Restructure rtems_filesystem_mount_table_entry_t to improve cache
efficiency.

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