source: rtems/cpukit/libfs/src/imfs/imfs_initsupp.c @ 51435fc7

4.104.114.84.95
Last change on this file since 51435fc7 was 51435fc7, checked in by Joel Sherrill <joel.sherrill@…>, on 10/12/99 at 19:26:37

Split null handlers table to own file and renamed.

Renamed IMFS handler tables to include IMFS prefix.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 *  IMFS Initialization
3 *
4 *  COPYRIGHT (c) 1989-1998.
5 *  On-Line Applications Research Corporation (OAR).
6 *  Copyright assigned to U.S. Government, 1994.
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#include <sys/types.h>         /* for mkdir */
16#include <fcntl.h>
17#include <unistd.h>
18#include <stdlib.h>
19
20#include <assert.h>
21
22#include "imfs.h"
23#include "libio_.h"
24
25#if defined(IMFS_DEBUG)
26#include <stdio.h>
27#endif
28
29/*
30 *  IMFS file system operations table
31 */
32
33rtems_filesystem_operations_table  IMFS_ops = {
34  IMFS_eval_path,
35  IMFS_evaluate_for_make,
36  IMFS_link,
37  IMFS_unlink,
38  IMFS_node_type,
39  IMFS_mknod,
40  IMFS_rmnod,
41  IMFS_chown,
42  IMFS_freenodinfo,
43  IMFS_mount,
44  IMFS_initialize,
45  IMFS_unmount,
46  IMFS_fsunmount,
47  IMFS_utime,
48  IMFS_evaluate_link,
49  IMFS_symlink,
50  IMFS_readlink
51};
52
53/*
54 *  IMFS_initialize
55 */
56
57int IMFS_initialize(
58  rtems_filesystem_mount_table_entry_t *temp_mt_entry
59)
60{
61  IMFS_fs_info_t                        *fs_info;
62  IMFS_jnode_t                          *jnode;
63
64  /*
65   *  Create the root node
66   */
67
68  temp_mt_entry->mt_fs_root.node_access = IMFS_create_node(
69    NULL,
70    IMFS_DIRECTORY,
71    "",
72    ( S_IRWXO | S_IRWXG| S_IRWXU ),
73    NULL
74  );
75
76  temp_mt_entry->mt_fs_root.handlers    = &IMFS_directory_handlers;
77  temp_mt_entry->mt_fs_root.ops         = &IMFS_ops;
78  temp_mt_entry->pathconf_limits_and_options = IMFS_LIMITS_AND_OPTIONS;
79
80  /*
81   * Create custom file system data.
82   */
83  fs_info = calloc( 1, sizeof( IMFS_fs_info_t ) );
84  if ( !fs_info ){
85    free(temp_mt_entry->mt_fs_root.node_access);
86    return 1;
87  }
88  temp_mt_entry->fs_info = fs_info;
89
90  /*
91   * Set st_ino for the root to 1.
92   */
93
94  fs_info->ino_count   = 1;
95
96  jnode = temp_mt_entry->mt_fs_root.node_access;
97  jnode->st_ino = fs_info->ino_count;
98
99  return 0;
100}
101
102#define jnode_get_control( jnode ) \
103  (&jnode->info.directory.Entries)
104
105#define jnode_has_no_children( jnode )  \
106  Chain_Is_empty( jnode_get_control( jnode ) )
107
108#define jnode_has_children( jnode ) \
109  ( ! jnode_has_no_children( jnode ) )
110
111#define jnode_get_first_child( jnode ) \
112    ((IMFS_jnode_t *)( Chain_Head( jnode_get_control( jnode ) )->next))
113
114
115int IMFS_fsunmount(
116  rtems_filesystem_mount_table_entry_t *temp_mt_entry
117)
118{
119   IMFS_jnode_t                     *jnode;
120   IMFS_jnode_t                     *next;
121   rtems_filesystem_location_info_t loc;       
122   int                              result = 0;
123
124   /*
125    * Traverse tree that starts at the mt_fs_root and deallocate memory
126    * associated memory space
127    */
128   
129   jnode = (IMFS_jnode_t *)temp_mt_entry->mt_fs_root.node_access;
130
131   do {
132     next = jnode->Parent;
133     loc.node_access = (void *)jnode;
134
135     if ( jnode->type != IMFS_DIRECTORY ) {
136        result = IMFS_unlink( &loc );
137        if (result != 0)
138          return -1;
139        jnode = next;
140     } else if ( jnode_has_no_children( jnode ) ) {
141        result = IMFS_unlink( &loc );
142        if (result != 0)
143          return -1;
144        jnode = next;
145     }
146     if ( jnode != NULL ) {
147       if ( jnode->type == IMFS_DIRECTORY ) {
148         if ( jnode_has_children( jnode ) )
149           jnode = jnode_get_first_child( jnode );
150       }
151     }
152   } while (jnode != NULL);
153
154   return 0;
155}
156
157
158
Note: See TracBrowser for help on using the repository browser.