source: rtems/cpukit/libblock/src/bdpart-mount.c @ 29e92b0

4.104.11
Last change on this file since 29e92b0 was 29e92b0, checked in by Chris Johns <chrisj@…>, on May 31, 2010 at 1:56:37 PM

2010-05-31 Chris Johns <chrisj@…>

  • libcsupport/Makefile.am: Add mount-mgr.c.
  • libcsupport/src/mount-mgr.c: New.
  • include/rtems/fs.h: Added rtems_filesystem_location_mount.
  • libcsupport/include/rtems/libio.h, libcsupport/src/mount.c: New mount interface. It is similar to Linux.
  • libcsupport/include/rtems/libio_.h: Remove the init_fs_mount_table call.
  • libcsupport/src/base_fs.c: Remove init_fs_mount_table_call. Use the new mount call. Remove setting the root node in the global pathloc. Mount does this now.
  • libcsupport/src/privateenv.c: Remove the hack to set the root mount table entry in the environment.
  • libcsupport/src/unmount.cL Free the target string.
  • libblock/src/bdpart-mount.c: New mount API.
  • libfs/src/devfs/devfs.h, libfs/src/devfs/devfs_init.c, libfs/src/dosfs/dosfs.h, libfs/src/dosfs/msdos.h, libfs/src/dosfs/msdos_init.c, libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_eval.c, libfs/src/imfs/imfs_init.c, libfs/src/imfs/miniimfs_init.c, libfs/src/nfsclient/src/librtemsNfs.h, libfs/src/rfs/rtems-rfs-rtems.c, libfs/src/rfs/rtems-rfs.h, libnetworking/lib/ftpfs.c, libnetworking/rtems/ftpfs.h, libnetworking/rtems/tftp.h: New mount_h API.
  • libfs/src/devfs/devfs_eval.c: Local include of extern ops.
  • libfs/src/nfsclient/src/nfs.c: New mount API. Removed the mount me call and fixed the initialisation to happen when mounting.
  • libmisc/Makefile.am, libmisc/shell/shellconfig.h: Remove mount filesystem files.
  • libmisc/fsmount/fsmount.c, libmisc/fsmount/fsmount.h: Updated to the new mount table values.
  • libmisc/shell/main_mount_ftp.c, libmisc/shell/main_mount_msdos.c, libmisc/shell/main_mount_rfs.c, libmisc/shell/main_mount_tftp.c: Removed.
  • libmisc/shell/main_mount.c: Use the new mount API. Also access the file system table for the file system types.
  • libnetworking/lib/tftpDriver.c: Updated to the new mount API. Fixed to allow mounting from any mount point. Also can now have more than file system mounted.
  • sapi/include/confdefs.h: Add file system configuration support.
  • Property mode set to 100644
File size: 4.5 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_bdpart
5 *
6 * Block device partition management.
7 */
8
9/*
10 * Copyright (c) 2009, 2010
11 * embedded brains GmbH
12 * Obere Lagerstr. 30
13 * D-82178 Puchheim
14 * Germany
15 * <rtems@embedded-brains.de>
16 *
17 * The license and distribution terms for this file may be
18 * found in the file LICENSE in this distribution or at
19 * http://www.rtems.com/license/LICENSE.
20 */
21
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29
30#include <rtems.h>
31#include <rtems/bdpart.h>
32#include <rtems/fsmount.h>
33
34rtems_status_code rtems_bdpart_mount(
35  const char *disk_name,
36  const rtems_bdpart_partition *pt __attribute__((unused)),
37  size_t count,
38  const char *mount_base
39)
40{
41  rtems_status_code esc = RTEMS_SUCCESSFUL;
42  const char *disk_file_name = strrchr( disk_name, '/');
43  char *logical_disk_name = NULL;
44  char *logical_disk_marker = NULL;
45  char *mount_point = NULL;
46  char *mount_marker = NULL;
47  size_t disk_file_name_size = 0;
48  size_t disk_name_size = strlen( disk_name);
49  size_t mount_base_size = strlen( mount_base);
50  size_t i = 0;
51
52  /* Create logical disk name base */
53  logical_disk_name = malloc( disk_name_size + RTEMS_BDPART_NUMBER_SIZE);
54  if (logical_disk_name == NULL) {
55    return RTEMS_NO_MEMORY;
56  }
57  strncpy( logical_disk_name, disk_name, disk_name_size);
58
59  /* Get disk file name */
60  if (disk_file_name != NULL) {
61    disk_file_name += 1;
62    disk_file_name_size = strlen( disk_file_name);
63  } else {
64    disk_file_name = disk_name;
65    disk_file_name_size = disk_name_size;
66  }
67
68  /* Create mount point base */
69  mount_point = malloc( mount_base_size + 1 + disk_file_name_size + RTEMS_BDPART_NUMBER_SIZE);
70  if (mount_point == NULL) {
71    esc = RTEMS_NO_MEMORY;
72    goto cleanup;
73  }
74  strncpy( mount_point, mount_base, mount_base_size);
75  mount_point [mount_base_size] = '/';
76  strncpy( mount_point + mount_base_size + 1, disk_file_name, disk_file_name_size);
77
78  /* Markers */
79  logical_disk_marker = logical_disk_name + disk_name_size;
80  mount_marker = mount_point + mount_base_size + 1 + disk_file_name_size;
81
82  /* Mount supported file systems for each partition */
83  for (i = 0; i < count; ++i) {
84    /* Create logical disk name */
85    int rv = snprintf( logical_disk_marker, RTEMS_BDPART_NUMBER_SIZE, "%zu", i + 1);
86    if (rv >= RTEMS_BDPART_NUMBER_SIZE) {
87      esc = RTEMS_INVALID_NAME;
88      goto cleanup;
89    }
90
91    /* Create mount point */
92    strncpy( mount_marker, logical_disk_marker, RTEMS_BDPART_NUMBER_SIZE);
93    rv = rtems_fsmount_create_mount_point( mount_point);
94    if (rv != 0) {
95      esc = RTEMS_IO_ERROR;
96      goto cleanup;
97    }
98
99    /* Mount */
100    rv = mount(
101      logical_disk_name,
102      mount_point,
103      "msdos",
104      0,
105      NULL
106    );
107    if (rv != 0) {
108      rmdir( mount_point);
109    }
110  }
111
112cleanup:
113
114  free( logical_disk_name);
115  free( mount_point);
116
117  return esc;
118}
119
120rtems_status_code rtems_bdpart_unmount(
121  const char *disk_name,
122  const rtems_bdpart_partition *pt __attribute__((unused)),
123  size_t count,
124  const char *mount_base
125)
126{
127  rtems_status_code esc = RTEMS_SUCCESSFUL;
128  const char *disk_file_name = strrchr( disk_name, '/');
129  char *mount_point = NULL;
130  char *mount_marker = NULL;
131  size_t disk_file_name_size = 0;
132  size_t disk_name_size = strlen( disk_name);
133  size_t mount_base_size = strlen( mount_base);
134  size_t i = 0;
135
136  /* Get disk file name */
137  if (disk_file_name != NULL) {
138    disk_file_name += 1;
139    disk_file_name_size = strlen( disk_file_name);
140  } else {
141    disk_file_name = disk_name;
142    disk_file_name_size = disk_name_size;
143  }
144
145  /* Create mount point base */
146  mount_point = malloc( mount_base_size + 1 + disk_file_name_size + RTEMS_BDPART_NUMBER_SIZE);
147  if (mount_point == NULL) {
148    esc = RTEMS_NO_MEMORY;
149    goto cleanup;
150  }
151  strncpy( mount_point, mount_base, mount_base_size);
152  mount_point [mount_base_size] = '/';
153  strncpy( mount_point + mount_base_size + 1, disk_file_name, disk_file_name_size);
154
155  /* Marker */
156  mount_marker = mount_point + mount_base_size + 1 + disk_file_name_size;
157
158  /* Mount supported file systems for each partition */
159  for (i = 0; i < count; ++i) {
160    /* Create mount point */
161    int rv = snprintf( mount_marker, RTEMS_BDPART_NUMBER_SIZE, "%zu", i + 1);
162    if (rv >= RTEMS_BDPART_NUMBER_SIZE) {
163      esc = RTEMS_INVALID_NAME;
164      goto cleanup;
165    }
166
167    /* Unmount */
168    rv = unmount( mount_point);
169    if (rv == 0) {
170      /* Remove mount point */
171      rv = rmdir( mount_point);
172      if (rv != 0) {
173        esc = RTEMS_IO_ERROR;
174        goto cleanup;
175      }
176    }
177  }
178
179cleanup:
180
181  free( mount_point);
182
183  return esc;
184}
Note: See TracBrowser for help on using the repository browser.