Changeset 3ba4f828 in rtems


Ignore:
Timestamp:
Mar 2, 2012, 9:18:10 AM (8 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
adef4e4
Parents:
3b7c123
git-author:
Sebastian Huber <sebastian.huber@…> (03/02/12 09:18:10)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/13/12 11:23:44)
Message:

Filesystem: Read-only file system checks

o Make sure EROFS is indicated for write operations on a read-only file

system.

o Add error indication for read-only file systems in fchmod() and

fchown() according to POSIX.

Files:
4 added
5 edited

Legend:

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

    r3b7c123 r3ba4f828  
    2929  rtems_libio_check_is_open(iop);
    3030
    31   rtems_filesystem_instance_lock( &iop->pathinfo );
    32   rv = (*iop->pathinfo.ops->fchmod_h)( &iop->pathinfo, mode );
    33   rtems_filesystem_instance_unlock( &iop->pathinfo );
     31  if (iop->pathinfo.mt_entry->writeable) {
     32    rtems_filesystem_instance_lock( &iop->pathinfo );
     33    rv = (*iop->pathinfo.ops->fchmod_h)( &iop->pathinfo, mode );
     34    rtems_filesystem_instance_unlock( &iop->pathinfo );
     35  } else {
     36    errno = EROFS;
     37    rv = -1;
     38  }
    3439
    3540  return rv;
  • cpukit/libcsupport/src/fchown.c

    r3b7c123 r3ba4f828  
    2929  rtems_libio_check_is_open(iop);
    3030
    31   rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
    32 
    33   rtems_filesystem_instance_lock( &iop->pathinfo );
    34   rv = (*iop->pathinfo.ops->chown_h)( &iop->pathinfo, owner, group );
    35   rtems_filesystem_instance_unlock( &iop->pathinfo );
     31  if (iop->pathinfo.mt_entry->writeable) {
     32    rtems_filesystem_instance_lock( &iop->pathinfo );
     33    rv = (*iop->pathinfo.ops->chown_h)( &iop->pathinfo, owner, group );
     34    rtems_filesystem_instance_unlock( &iop->pathinfo );
     35  } else {
     36    errno = EROFS;
     37    rv = -1;
     38  }
    3639
    3740  return rv;
  • cpukit/libcsupport/src/sup_fs_eval_path.c

    r3b7c123 r3ba4f828  
    6969{
    7070  const rtems_filesystem_location_info_t *currentloc = &ctx->currentloc;
    71   struct stat st;
    72   int rv;
    73 
    74   st.st_mode = 0;
    75   st.st_uid = 0;
    76   st.st_gid = 0;
    77   rv = (*currentloc->handlers->fstat_h)(currentloc, &st);
    78   if (rv == 0) {
    79     bool access_ok = rtems_filesystem_check_access(
    80       eval_flags,
    81       st.st_mode,
    82       st.st_uid,
    83       st.st_gid
    84     );
    85 
    86     if (!access_ok) {
    87       rtems_filesystem_eval_path_error(ctx, EACCES);
     71  const rtems_filesystem_mount_table_entry_t *mt_entry = currentloc->mt_entry;
     72
     73  if ((eval_flags & RTEMS_LIBIO_PERMS_WRITE) == 0 || mt_entry->writeable) {
     74    struct stat st;
     75    int rv;
     76
     77    st.st_mode = 0;
     78    st.st_uid = 0;
     79    st.st_gid = 0;
     80    rv = (*currentloc->handlers->fstat_h)(currentloc, &st);
     81    if (rv == 0) {
     82      bool access_ok = rtems_filesystem_check_access(
     83        eval_flags,
     84        st.st_mode,
     85        st.st_uid,
     86        st.st_gid
     87      );
     88
     89      if (!access_ok) {
     90        rtems_filesystem_eval_path_error(ctx, EACCES);
     91      }
     92    } else {
     93      rtems_filesystem_eval_path_error(ctx, 0);
    8894    }
    8995  } else {
    90     rtems_filesystem_eval_path_error(ctx, 0);
     96    rtems_filesystem_eval_path_error(ctx, EROFS);
    9197  }
    9298}
  • testsuites/psxtests/psxfchx01/init.c

    r3b7c123 r3ba4f828  
    185185  rtems_test_assert( fd != -1 );
    186186 
    187   puts( "Init - fchown, with the opened file descriptor - expect EINVAL" );
     187  puts( "Init - fchown, with the opened file descriptor - OK" );
    188188  status = fchown( fd, 0, 0 );
    189   rtems_test_assert( status == -1 );
    190   rtems_test_assert( errno == EINVAL );
     189  rtems_test_assert( status == 0 );
    191190
    192191  puts( "Init - close and remove /newfile" );
  • testsuites/psxtests/psxmount/test.c

    r3b7c123 r3ba4f828  
    243243   */
    244244
    245   printf("create c/y/my_mount_point/../../y/my_mount_point/new_dir\n");
    246   status = mkdir("c/y/my_mount_point/../../y/my_mount_point/new_dir",S_IRWXU );
    247   rtems_test_assert( status == 0 );
    248   status = stat("c/y/my_mount_point/../../y/my_mount_point/new_dir",&statbuf );
    249   rtems_test_assert( status == 0 );
    250   status = stat("c/y/my_mount_point/new_dir/..", &statbuf );
     245  printf("create c/y/my_mount_point/../../y/new_dir\n");
     246  status = mkdir("c/y/my_mount_point/../../y/new_dir",S_IRWXU );
     247  rtems_test_assert( status == 0 );
     248  status = stat("c/y/my_mount_point/../../y/new_dir",&statbuf );
     249  rtems_test_assert( status == 0 );
     250  status = stat("c/y/new_dir", &statbuf );
    251251  rtems_test_assert( status == 0 );
    252252
     
    255255   */
    256256
    257   printf("Verify a mount point returns EBUSY for another mount\n");
     257  printf("Verify a mount point returns EROFS for another mount\n");
    258258  status = mount(
    259259    "null",
     
    263263     NULL );
    264264  rtems_test_assert( status == -1 );
     265  rtems_test_assert( errno == EROFS);
     266
     267  printf("Unmount /c/y/my_mount_point\n");
     268  status = unmount( "/c/y/my_mount_point" );
     269  rtems_test_assert( status == 0 );
     270
     271  printf("Mount a read-write file system at /c/y/my_mount_point\n");
     272  status = mount(
     273    "null",
     274    "/c/y/my_mount_point",
     275    "imfs",
     276    RTEMS_FILESYSTEM_READ_WRITE,
     277    NULL );
     278  rtems_test_assert( status == 0 );
     279
     280  printf("Verify a mount point returns EBUSY for another mount\n");
     281  status = mount(
     282    "null",
     283    "/c/y/my_mount_point",
     284    "imfs",
     285     RTEMS_FILESYSTEM_READ_ONLY,
     286     NULL );
     287  rtems_test_assert( status == -1 );
    265288  rtems_test_assert( errno == EBUSY);
    266289
     
    331354    "/c/y/my_mount_point",
    332355    "imfs",
    333     RTEMS_FILESYSTEM_READ_ONLY,
     356    RTEMS_FILESYSTEM_READ_WRITE,
    334357    NULL );
    335358  rtems_test_assert( status == 0 );
Note: See TracChangeset for help on using the changeset viewer.