Changeset 615d8cc in rtems


Ignore:
Timestamp:
Jul 1, 2010, 2:29:09 PM (10 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.10
Children:
3d3a18e6
Parents:
00bf6744
Message:

2010-06-08 Sebastian Huber <sebastian.huber@…>

  • libcsupport/include/rtems/libio.h: Documentation.

2010-06-08 Sebastian Huber <sebastian.huber@…>

PR 1524/filesystem

  • libcsupport/src/rtems_mkdir.c: New file.
  • libcsupport/src/Makefile.am: Reflect change above.
  • libcsupport/include/rtems/libio.h: Added rtems_mkdir().
  • libmisc/fsmount/fsmount.h, libmisc/fsmount/fsmount.c, libblock/src/bdpart-mount.c, libnetworking/rtems/mkrootfs.h, libnetworking/rtems/mkrootfs.c: Use rtems_mkdir(). Removed rtems_fsmount_create_mount_point() and rtems_rootfs_mkdir().
Location:
cpukit
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r00bf6744 r615d8cc  
    207207        * configure.ac: Remove c4x (dead port).
    208208        * score/cpu/Makefile.am: Remove c4x (dead port).
     209
     2102010-06-08      Sebastian Huber <sebastian.huber@embedded-brains.de>
     211
     212        * libcsupport/include/rtems/libio.h: Documentation.
     213
     2142010-06-08      Sebastian Huber <sebastian.huber@embedded-brains.de>
     215
     216        PR 1524/filesystem
     217        * libcsupport/src/rtems_mkdir.c: New file.
     218        * libcsupport/src/Makefile.am: Reflect change above.
     219        * libcsupport/include/rtems/libio.h: Added rtems_mkdir().
     220        * libmisc/fsmount/fsmount.h, libmisc/fsmount/fsmount.c,
     221        libblock/src/bdpart-mount.c, libnetworking/rtems/mkrootfs.h,
     222        libnetworking/rtems/mkrootfs.c: Use rtems_mkdir().  Removed
     223        rtems_fsmount_create_mount_point() and rtems_rootfs_mkdir().
    209224
    2102252010-06-07      Sebastian Huber <sebastian.huber@embedded-brains.de>
  • cpukit/libblock/src/bdpart-mount.c

    r00bf6744 r615d8cc  
    3030#include <rtems.h>
    3131#include <rtems/bdpart.h>
    32 #include <rtems/fsmount.h>
     32#include <rtems/libio.h>
    3333
    3434rtems_status_code rtems_bdpart_mount(
     
    9191    /* Create mount point */
    9292    strncpy( mount_marker, logical_disk_marker, RTEMS_BDPART_NUMBER_SIZE);
    93     rv = rtems_fsmount_create_mount_point( mount_point);
     93    rv = rtems_mkdir( mount_point, S_IRWXU | S_IRWXG | S_IRWXO);
    9494    if (rv != 0) {
    9595      esc = RTEMS_IO_ERROR;
  • cpukit/libcsupport/Makefile.am

    r00bf6744 r615d8cc  
    4747    src/mount-mgr.c src/libio_init.c \
    4848    src/libio_sockets.c src/eval.c src/fs_null_handlers.c src/privateenv.c \
    49     src/open_dev_console.c src/__usrenv.c
     49    src/open_dev_console.c src/__usrenv.c src/rtems_mkdir.c
    5050
    5151TERMIOS_C_FILES = src/cfgetispeed.c src/cfgetospeed.c src/cfsetispeed.c \
  • cpukit/libcsupport/include/rtems/libio.h

    r00bf6744 r615d8cc  
    11/**
    2  * @file rtems/libio.h
    3  */
    4 
    5 /*
    6  *  System call and file system interface definition
    7  *
    8  *  General purpose communication channel for RTEMS to allow UNIX/POSIX
    9  *  system call behavior under RTEMS.  Initially this supported only
    10  *  IO to devices but has since been enhanced to support networking
    11  *  and support for mounted file systems.
    12  *
     2 * @file
     3 *
     4 * @ingroup LibIO
     5 *
     6 * @brief Basic IO API.
     7 */
     8
     9/*
    1310 *  COPYRIGHT (c) 1989-2008.
    1411 *  On-Line Applications Research Corporation (OAR).
     
    2421#define _RTEMS_RTEMS_LIBIO_H
    2522
    26 #include <rtems.h>
    27 #include <rtems/chain.h>
    2823#include <sys/types.h>
    2924#include <sys/stat.h>
     
    3126#include <sys/statvfs.h>
    3227
    33 /*
    34  *  Define data types which must be constructed using forward references.
    35  */
    36 
     28#include <unistd.h>
     29#include <termios.h>
     30
     31#include <rtems.h>
    3732#include <rtems/fs.h>
     33#include <rtems/chain.h>
    3834
    3935#ifdef __cplusplus
     
    4137#endif
    4238
    43 /*
    44  * A 64bit file offset for internal use by RTEMS. Based on the newlib type.
     39/**
     40 * @defgroup LibIO IO Library
     41 *
     42 * @brief Provides system call and file system interface definitions.
     43 *
     44 * General purpose communication channel for RTEMS to allow UNIX/POSIX
     45 * system call behavior under RTEMS.  Initially this supported only
     46 * IO to devices but has since been enhanced to support networking
     47 * and support for mounted file systems.
     48 *
     49 * @{
     50 */
     51
     52/**
     53 * @brief A 64-bit file offset for internal use by RTEMS. Based on the Newlib
     54 * type.
    4555 */
    4656typedef _off64_t rtems_off64_t;
    4757
    48 /*
    49  * Valid RTEMS file types.
    50  */
     58/**
     59 * @name File system node types.
     60 *
     61 * @{
     62 */
     63
    5164#define RTEMS_FILESYSTEM_DIRECTORY   1
    5265#define RTEMS_FILESYSTEM_DEVICE      2
     
    5467#define RTEMS_FILESYSTEM_SYM_LINK    4
    5568#define RTEMS_FILESYSTEM_MEMORY_FILE 5
     69
     70/** @} */
     71
    5672typedef int rtems_filesystem_node_types_t;
    5773
    58 /*
    59  *  File Handler Operations Table
    60  */
     74/**
     75 * @name File System Node Operations
     76 *
     77 * @{
     78 */
     79
    6180typedef int (*rtems_filesystem_open_t)(
    6281  rtems_libio_t *iop,
     
    132151);
    133152
     153/** @} */
     154
     155/**
     156 * @brief File system node operations table.
     157 */
    134158struct _rtems_filesystem_file_handlers_r {
    135159    rtems_filesystem_open_t         open_h;
     
    149173};
    150174
    151 /*
    152  *  File System Operations Table
     175/**
     176 * @name File System Operations
     177 *
     178 * @{
    153179 */
    154180
     
    262288);
    263289
    264 /*
    265  * operations table that must be defined for every file system.
    266  */
    267 
    268 /*
    269  * File system types
     290/** @} */
     291
     292/**
     293 * @brief File system operations table.
    270294 */
    271295struct _rtems_filesystem_operations_table {
     
    308332 * @brief Per file system table entry routine type.
    309333 *
    310  * Return @c true to continue the iteration, and @c false to stop.
     334 * @see rtems_filesystem_iterate().
     335 *
     336 * @retval true Continue the iteration.
     337 * @retval false Stop the iteration.
    311338 */
    312339typedef bool (*rtems_per_filesystem_routine)(
     
    328355
    329356/**
    330  * @brief Returns the file system mount handler associated with the @a type, or
     357 * @brief Gets the mount handler for the file system @a type.
     358 *
     359 * @return The file system mount handler associated with the @a type, or
    331360 * @c NULL if no such association exists.
    332361 */
     
    365394);
    366395
    367 /*
    368  *  Structure used to contain file system specific information which
    369  *  is required to support fpathconf().
     396/**
     397 * @brief Contain file system specific information which is required to support
     398 * fpathconf().
    370399 */
    371400typedef struct {
     
    384413} rtems_filesystem_limits_and_options_t;
    385414
    386 /*
    387  * Default pathconf settings. Override in a filesystem.
     415/**
     416 * @brief Default pathconf settings.
     417 *
     418 * Override in a filesystem.
    388419 */
    389420extern const rtems_filesystem_limits_and_options_t rtems_filesystem_default_pathconf;
    390421
    391 /*
    392  * Structure for a mount table entry.
    393  */
    394 
     422/**
     423 * @brief Mount table entry.
     424 */
    395425struct rtems_filesystem_mount_table_entry_tt {
    396426  rtems_chain_node                       Node;
     
    423453
    424454/**
    425  * The pathconf setting for a file system.
     455 * @brief The pathconf setting for a file system.
    426456 */
    427457#define rtems_filesystem_pathconf(_mte) ((_mte)->pathconf_limits_and_options)
    428458
    429459/**
    430  * The type of file system. Its name.
     460 * @brief The type of file system. Its name.
    431461 */
    432462#define rtems_filesystem_type(_mte) ((_mte)->type)
    433463
    434464/**
    435  * The mount point of a file system.
     465 * @brief The mount point of a file system.
    436466 */
    437467#define rtems_filesystem_mount_point(_mte) ((_mte)->target)
    438468
    439469/**
    440  * The device entry of a file system.
     470 * @brief The device entry of a file system.
    441471 */
    442472#define rtems_filesystem_mount_device(_mte) ((_mte)->dev)
    443473
    444 /*
    445  *  Valid RTEMS file systems options
     474/**
     475 * @brief File systems options.
    446476 */
    447477typedef enum {
     
    451481} rtems_filesystem_options_t;
    452482
    453 
    454 /*
    455  *  An open file data structure, indexed by 'fd'
    456  *  TODO:
    457  *     should really have a separate per/file data structure that this
    458  *     points to (eg: size, offset, driver, pathname should be in that)
     483/**
     484 * @brief An open file data structure.
     485 *
     486 * It will be indexed by 'fd'.
     487 *
     488 * @todo Should really have a separate per/file data structure that this points
     489 * to (eg: size, offset, driver, pathname should be in that)
    459490 */
    460491struct rtems_libio_tt {
     
    471502};
    472503
    473 /*
    474  *  param block for read/write
    475  *  Note: it must include 'offset' instead of using iop's offset since
    476  *        we can have multiple outstanding i/o's on a device.
     504/**
     505 * @brief Paramameter block for read/write.
     506 *
     507 * It must include 'offset' instead of using iop's offset since we can have
     508 * multiple outstanding i/o's on a device.
    477509 */
    478510typedef struct {
     
    485517} rtems_libio_rw_args_t;
    486518
    487 /*
    488  *  param block for open/close
     519/**
     520 * @brief Parameter block for open/close.
    489521 */
    490522typedef struct {
     
    494526} rtems_libio_open_close_args_t;
    495527
    496 /*
    497  *  param block for ioctl
     528/**
     529 * @brief Parameter block for ioctl.
    498530 */
    499531typedef struct {
     
    504536} rtems_libio_ioctl_args_t;
    505537
    506 /*
    507  *  Values for 'flag'
    508  */
     538/**
     539 * @name Flag Values
     540 *
     541 * @{
     542 */
     543
    509544#define LIBIO_FLAGS_NO_DELAY      0x0001  /* return immediately if no data */
    510545#define LIBIO_FLAGS_READ          0x0002  /* reading */
     
    516551#define LIBIO_FLAGS_READ_WRITE    (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE)
    517552
     553/** @} */
     554
    518555void rtems_libio_init(void);
    519556
    520 /*
    521  *  External I/O handlers
     557/**
     558 * @name External I/O Handlers
     559 *
     560 * @{
    522561 */
    523562
     
    555594  int           whence
    556595);
     596
     597/** @} */
     598
     599/**
     600 * @name Permission Macros
     601 *
     602 * @{
     603 */
    557604
    558605/*
     
    568615#define RTEMS_LIBIO_PERMS_RWX    S_IRWXO
    569616
    570 /*
    571  *  Macros
    572  */
    573 
    574 #include <unistd.h>
     617/** @} */
    575618
    576619union __rtems_dev_t {
     
    633676void rtems_filesystem_initialize( void );
    634677
    635 /*
    636  * Callbacks from TERMIOS routines to device-dependent code
    637  */
    638 #include <termios.h>
     678int unmount(
     679  const char *mount_path
     680);
     681
     682int mount(
     683  const char                 *source,
     684  const char                 *target,
     685  const char                 *filesystemtype,
     686  rtems_filesystem_options_t options,
     687  const void                 *data
     688);
     689
     690/*
     691 *  Boot Time Mount Table Structure
     692 */
     693
     694typedef struct {
     695  const char                              *type;
     696  rtems_filesystem_options_t               fsoptions;
     697  const char                              *device;
     698  const char                              *mount_point;
     699} rtems_filesystem_mount_table_t;
     700
     701extern const rtems_filesystem_mount_table_t *rtems_filesystem_mount_table;
     702extern const int                             rtems_filesystem_mount_table_size;
     703
     704typedef void (*rtems_libio_init_functions_t)(void);
     705extern  rtems_libio_init_functions_t rtems_libio_init_helper;
     706
     707void    open_dev_console(void);
     708
     709typedef void (*rtems_libio_supp_functions_t)(void);
     710extern  rtems_libio_supp_functions_t rtems_libio_supp_helper;
     711
     712typedef void (*rtems_fs_init_functions_t)(void);
     713extern  rtems_fs_init_functions_t    rtems_fs_init_helper;
     714
     715/**
     716 * @brief Creates a directory and all its parrent directories according to
     717 * @a path.
     718 *
     719 * The @a mode value selects the access permissions of the directory.
     720 *
     721 * @retval 0 Successful operation.
     722 * @retval -1 An error occured.  @c errno indicates the error.
     723 */
     724extern int rtems_mkdir(const char *path, mode_t mode);
     725
     726/** @} */
     727
     728/**
     729 * @defgroup Termios Termios
     730 *
     731 * @ingroup LibIO
     732 *
     733 * @brief Termios
     734 *
     735 * @{
     736 */
    639737
    640738typedef struct rtems_termios_callbacks {
     
    649747} rtems_termios_callbacks;
    650748
    651 /*
    652  *  Device-independent TERMIOS routines
    653  */
    654749void rtems_termios_initialize (void);
    655750
     
    699794);
    700795
    701 int unmount(
    702   const char *mount_path
    703 );
    704 
    705 int mount(
    706   const char                 *source,
    707   const char                 *target,
    708   const char                 *filesystemtype,
    709   rtems_filesystem_options_t options,
    710   const void                 *data
    711 );
    712 
    713 /*
    714  *  Boot Time Mount Table Structure
    715  */
    716 
    717 typedef struct {
    718   const char                              *type;
    719   rtems_filesystem_options_t               fsoptions;
    720   const char                              *device;
    721   const char                              *mount_point;
    722 } rtems_filesystem_mount_table_t;
    723 
    724 extern const rtems_filesystem_mount_table_t *rtems_filesystem_mount_table;
    725 extern const int                             rtems_filesystem_mount_table_size;
    726 
    727 typedef void (*rtems_libio_init_functions_t)(void);
    728 extern  rtems_libio_init_functions_t rtems_libio_init_helper;
    729 
    730 void    open_dev_console(void);
    731 
    732 typedef void (*rtems_libio_supp_functions_t)(void);
    733 extern  rtems_libio_supp_functions_t rtems_libio_supp_helper;
    734 
    735 typedef void (*rtems_fs_init_functions_t)(void);
    736 extern  rtems_fs_init_functions_t    rtems_fs_init_helper;
     796/** @} */
    737797
    738798#ifdef __cplusplus
  • cpukit/libmisc/fsmount/fsmount.c

    r00bf6744 r615d8cc  
    3535#include <rtems.h>
    3636#include <rtems/fsmount.h>
     37#include <rtems/libio.h>
    3738#include <stdio.h>
    3839#include <stdlib.h>
    3940#include <string.h>
    4041#include <errno.h>
    41 #include <rtems/imfs.h>
    42 #include <sys/stat.h>
    43 
    44 /*=========================================================================*\
    45 | Function:                                                                 |
    46 \*-------------------------------------------------------------------------*/
    47 int rtems_fsmount_create_mount_point
    48 (
    49 /*-------------------------------------------------------------------------*\
    50 | Purpose:                                                                  |
    51 |  This function will create the mount point given                          |
    52 +---------------------------------------------------------------------------+
    53 | Input Parameters:                                                         |
    54 \*-------------------------------------------------------------------------*/
    55  const char *mount_point
    56  )
    57 /*-------------------------------------------------------------------------*\
    58 | Return Value:                                                             |
    59 |    0, if success, -1 and errno if failed                                  |
    60 \*=========================================================================*/
    61 {
    62   int rc = 0;
    63   char *tok_buffer = NULL;
    64   char *token = NULL;
    65   int    token_len;
    66   size_t total_len;
    67   IMFS_token_types token_type;
    68   struct stat file_info;
    69   /*
    70    * allocate temp memory to rebuild path name
    71    */
    72   tok_buffer = calloc(strlen(mount_point)+1,sizeof(char));
    73   if ( !tok_buffer )
    74     return -1;
    75   token = tok_buffer;
    76   total_len = 0;
    77   do {
    78     /*
    79      * scan through given string, one segment at a time
    80      */
    81     token_type = IMFS_get_token(
    82       mount_point+total_len,
    83       strlen(mount_point+total_len),
    84       token,
    85       &token_len
    86     );
    87     total_len += token_len;
    88     strncpy(tok_buffer,mount_point,total_len);
    89     tok_buffer[total_len] = '\0';
    90 
    91     if ((token_type != IMFS_NO_MORE_PATH) &&
    92         (token_type != IMFS_CURRENT_DIR)  &&
    93         (token_type != IMFS_INVALID_TOKEN)) {
    94       /*
    95        * check, whether segment exists
    96        */
    97       if (0 != stat(tok_buffer,&file_info)) {
    98         /*
    99          * if not, create directory
    100          */
    101         rc = mknod(tok_buffer,S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR,0);
    102       }
    103     }
    104   } while ((rc == 0) &&
    105            (token_type != IMFS_NO_MORE_PATH) &&
    106            (token_type != IMFS_INVALID_TOKEN));
    107 
    108   /*
    109    * return token buffer to heap. Verified to be non-NULL when calloc'ed.
    110    */
    111   free(tok_buffer);
    112   return rc;
    113 }
    11442
    11543/*=========================================================================*\
     
    14977     */
    15078    if (tmp_rc == 0) {
    151       tmp_rc = rtems_fsmount_create_mount_point(fstab_ptr->target);
     79      tmp_rc = rtems_mkdir(fstab_ptr->target, S_IRWXU | S_IRWXG | S_IRWXO);
    15280      if (tmp_rc != 0) {
    15381        if (0 != (fstab_ptr->report_reasons & FSMOUNT_MNTPNT_CRTERR)) {
  • cpukit/libmisc/fsmount/fsmount.h

    r00bf6744 r615d8cc  
    122122
    123123/**
    124  * Creates the mount point with path @a mount_point.
    125  *
    126  * On success, zero is returned.  On error, -1 is returned, and @c errno is set
    127  * appropriately.
    128  *
    129  * @see rtems_fsmount().
    130  */
    131 int rtems_fsmount_create_mount_point(const char *mount_point);
    132 
    133 /**
    134124 * Mounts the file systems listed in the file system mount table @a fstab of
    135125 * size @a size.
     
    138128 * In case of an abort condition the corresponding table index will be reported
    139129 * in @a abort_index.  The pointer @a abort_index may be @c NULL.  The mount
    140  * point paths will be created with rtems_fsmount_create_mount_point() and need
    141  * not exist beforehand.
     130 * point paths will be created with rtems_mkdir() and need not exist
     131 * beforehand.
    142132 *
    143133 * On success, zero is returned.  On error, -1 is returned, and @c errno is set
  • cpukit/libnetworking/rtems/mkrootfs.c

    r00bf6744 r615d8cc  
    6969
    7070/*
    71  * Build a path. Taken from the BSD `mkdir' command.
    72  */
    73 
    74 int
    75 rtems_rootfs_mkdir (const char *path_orig, mode_t omode)
    76 {
    77   struct stat sb;
    78   mode_t      numask, oumask;
    79   int         first, last, retval;
    80   char        path[128];
    81   char        *p = path;
    82 
    83   if (strlen (path_orig) >= sizeof path)
    84   {
    85     printf ("root fs: mkdir path too long `%s'\n", path);
    86     return -1;
    87   }
    88 
    89   strcpy (path, path_orig);
    90   oumask = 0;
    91   retval = 0;
    92   if (p[0] == '/')    /* Skip leading '/'. */
    93     ++p;
    94   for (first = 1, last = 0; !last ; ++p)
    95   {
    96     if (p[0] == '\0')
    97       last = 1;
    98     else if (p[0] != '/')
    99       continue;
    100     *p = '\0';
    101     if (p[1] == '\0')
    102       last = 1;
    103     if (first)
    104     {
    105       /*
    106        * POSIX 1003.2:
    107        * For each dir operand that does not name an existing
    108        * directory, effects equivalent to those cased by the
    109        * following command shall occcur:
    110        *
    111        * mkdir -p -m $(umask -S),u+wx $(dirname dir) &&
    112        *    mkdir [-m mode] dir
    113        *
    114        * We change the user's umask and then restore it,
    115        * instead of doing chmod's.
    116        */
    117       oumask = umask(0);
    118       numask = oumask & ~(S_IWUSR | S_IXUSR);
    119       umask(numask);
    120       first = 0;
    121     }
    122     if (last)
    123       umask(oumask);
    124     if (stat(path, &sb))
    125     {
    126       if (errno != ENOENT)
    127       {
    128         printf ("root fs: error stat'ing path `%s', %s\n",
    129                 path, strerror (errno));
    130         retval = 1;
    131         break;
    132       }
    133       if (mkdir(path, last ? omode : S_IRWXU | S_IRWXG | S_IRWXO) < 0)
    134       {
    135         printf ("root fs: error building path `%s', %s\n",
    136                 path, strerror (errno));
    137         retval = 1;
    138         break;
    139       }
    140     }
    141     else if ((sb.st_mode & S_IFMT) != S_IFDIR)
    142     {
    143       if (last)
    144         errno = EEXIST;
    145       else
    146         errno = ENOTDIR;
    147       printf ("root fs: path `%s' contains a file, %s\n",
    148               path, strerror (errno));
    149       retval = 1;
    150       break;
    151     }
    152     if (!last)
    153       *p = '/';
    154   }
    155   if (!first && !last)
    156     umask(oumask);
    157   return retval;
    158 }
    159 
    160 /*
    16171 * Create enough files to support the networking stack.
    16272 * Points to a table of strings.
     
    206116          path[i] = '\0';
    207117
    208           if (rtems_rootfs_mkdir (path, MKDIR_MODE))
     118          if (rtems_mkdir (path, MKDIR_MODE))
    209119            return -1;
    210120          break;
     
    311221       i < (sizeof (default_directories) / sizeof (rtems_rootfs_dir_table));
    312222       i++)
    313     if (rtems_rootfs_mkdir (default_directories[i].name,
     223    if (rtems_mkdir (default_directories[i].name,
    314224                            default_directories[i].mode))
    315225      return -1;
  • cpukit/libnetworking/rtems/mkrootfs.h

    r00bf6744 r615d8cc  
    3030extern "C" {
    3131#endif
    32 
    33 /*
    34  *  Builds the complete path, like "mkdir -p".
    35  */
    36 
    37 int
    38 rtems_rootfs_mkdir (const char *path, mode_t omode);
    3932
    4033/**
Note: See TracChangeset for help on using the changeset viewer.