Changeset 4af18b3 in rtems


Ignore:
Timestamp:
Oct 11, 2018, 8:51:21 AM (6 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
35eab84
Parents:
68799dac
git-author:
Sebastian Huber <sebastian.huber@…> (10/11/18 08:51:21)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/18/18 09:11:24)
Message:

Support O_DIRECTORY open() flag

Close #3545.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/src/open.c

    r68799dac r4af18b3  
    7474  bool exclusive = (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL);
    7575  bool truncate = (oflag & O_TRUNC) == O_TRUNC;
     76  bool open_dir;
    7677  int eval_flags = RTEMS_FS_FOLLOW_LINK
    7778    | (read_access ? RTEMS_FS_PERMS_READ : 0)
     
    8788  }
    8889
    89   if ( write_access ) {
     90#ifdef O_DIRECTORY
     91  open_dir = ( oflag & O_DIRECTORY ) == O_DIRECTORY;
     92#else
     93  open_dir = false;
     94#endif
     95
     96  if ( write_access || open_dir ) {
    9097    const rtems_filesystem_location_info_t *currentloc =
    9198      rtems_filesystem_eval_path_get_currentloc( &ctx );
    9299    mode_t type = rtems_filesystem_location_type( currentloc );
    93100
    94     if ( S_ISDIR( type ) ) {
     101    if ( write_access && S_ISDIR( type ) ) {
    95102      rtems_filesystem_eval_path_error( &ctx, EISDIR );
     103    }
     104
     105    if ( open_dir && !S_ISDIR( type ) ) {
     106      rtems_filesystem_eval_path_error( &ctx, ENOTDIR );
    96107    }
    97108  }
  • testsuites/psxtests/psxfile01/test.c

    r68799dac r4af18b3  
    129129  }
    130130
     131}
     132
     133static void test_open_directory(void)
     134{
     135  static const char file[] = "somefile";
     136  int status;
     137  int fd;
     138
     139  fd = open( file, O_CREAT, S_IRWXU );
     140  rtems_test_assert( fd >= 0 );
     141
     142  status = close( fd );
     143  rtems_test_assert( status == 0 );
     144
     145#ifdef O_DIRECTORY
     146  errno = 0;
     147  fd = open( file, O_DIRECTORY, S_IRWXU );
     148  rtems_test_assert( fd == -1 );
     149  rtems_test_assert( errno == ENOTDIR );
     150#endif
     151
     152  status = unlink( file );
     153  rtems_test_assert( status == 0 );
    131154}
    132155
     
    162185  TEST_BEGIN();
    163186
     187  test_open_directory();
     188
    164189  /*
    165190   *  Grab the maximum size of an in-memory file.
Note: See TracChangeset for help on using the changeset viewer.