Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:30

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * Copyright (c) 2015 embedded brains GmbH & Co. KG
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031 
0032 #include "tmacros.h"
0033 
0034 #include <sys/stat.h>
0035 #include <dirent.h>
0036 #include <errno.h>
0037 #include <fcntl.h>
0038 #include <stdio.h>
0039 #include <unistd.h>
0040 #include <utime.h>
0041 
0042 #include <rtems/imfs.h>
0043 #include <rtems/libio.h>
0044 
0045 const char rtems_test_name[] = "FSIMFSCONFIG 1";
0046 
0047 static const IMFS_node_control node_control = IMFS_GENERIC_INITIALIZER(
0048   &rtems_filesystem_handlers_default,
0049   IMFS_node_initialize_generic,
0050   IMFS_node_destroy_default
0051 );
0052 
0053 static void Init(rtems_task_argument arg)
0054 {
0055   const struct utimbuf times = {0};
0056   const char *generic = "generic";
0057   const char *mnt = "mnt";
0058   const char *dev = "device";
0059   const char *file = "file";
0060   const char *fifo = "fifo";
0061   int rv;
0062   int fd;
0063   DIR *dirp;
0064   struct dirent *dire;
0065   struct stat st;
0066 
0067   TEST_BEGIN();
0068 
0069   rv = IMFS_make_generic_node(
0070     generic,
0071     S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO,
0072     &node_control,
0073     NULL
0074   );
0075   rtems_test_assert(rv == 0);
0076 
0077   errno = 0;
0078   rv = chown(generic, 0, 0);
0079   rtems_test_assert(rv == -1);
0080   rtems_test_assert(errno == ENOTSUP);
0081 
0082   errno = 0;
0083   rv = chmod(generic, 0);
0084   rtems_test_assert(rv == -1);
0085   rtems_test_assert(errno == ENOTSUP);
0086 
0087   errno = 0;
0088   rv = link(generic, "link");
0089   rtems_test_assert(rv == -1);
0090   rtems_test_assert(errno == ENOTSUP);
0091 
0092   rv = mkdir(mnt, S_IRWXU);
0093   rtems_test_assert(rv == 0);
0094 
0095   rv = mknod(dev, S_IFCHR | S_IRWXU, 0);
0096   rtems_test_assert(rv == 0);
0097 
0098   errno = 0;
0099   fd = creat(file, S_IRWXU);
0100   rtems_test_assert(fd == -1);
0101   rtems_test_assert(errno == ENOSYS);
0102 
0103   errno = 0;
0104   rv = mkfifo(fifo, S_IRWXU);
0105   rtems_test_assert(rv == -1);
0106   rtems_test_assert(errno == ENOSYS);
0107 
0108   dirp = opendir(mnt);
0109   rtems_test_assert(dirp != NULL);
0110 
0111   errno = 0;
0112   dire = readdir(dirp);
0113   rtems_test_assert(dire == NULL);
0114   rtems_test_assert(errno == ENOTSUP);
0115 
0116   rv = closedir(dirp);
0117   rtems_test_assert(rv == 0);
0118 
0119   rv = stat(mnt, &st);
0120   rtems_test_assert(rv == 0);
0121   rtems_test_assert(st.st_size == 0);
0122 
0123   errno = 0;
0124   rv = mount(
0125     "",
0126     mnt,
0127     RTEMS_FILESYSTEM_TYPE_IMFS,
0128     RTEMS_FILESYSTEM_READ_ONLY,
0129     NULL
0130   );
0131   rtems_test_assert(rv == -1);
0132   rtems_test_assert(errno == ENOTSUP);
0133 
0134   errno = 0;
0135   rv = rename(generic, "new");
0136   rtems_test_assert(rv == -1);
0137   rtems_test_assert(errno == ENOTSUP);
0138 
0139   errno = 0;
0140   rv = symlink(generic, "link");
0141   rtems_test_assert(rv == -1);
0142   rtems_test_assert(errno == ENOTSUP);
0143 
0144   errno = 0;
0145   rv = utime(generic, &times);
0146   rtems_test_assert(rv == -1);
0147   rtems_test_assert(errno == ENOTSUP);
0148 
0149   errno = 0;
0150   rv = unlink(generic);
0151   rtems_test_assert(rv == -1);
0152   rtems_test_assert(errno == ENOTSUP);
0153 
0154   TEST_END();
0155   rtems_test_exit(0);
0156 }
0157 
0158 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0159 
0160 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
0161 
0162 #define CONFIGURE_FILESYSTEM_IMFS
0163 
0164 #define CONFIGURE_IMFS_DISABLE_CHOWN
0165 #define CONFIGURE_IMFS_DISABLE_CHMOD
0166 #define CONFIGURE_IMFS_DISABLE_LINK
0167 
0168 #if 0
0169 /*
0170  * This would lead to a fatal error since rtems_filesystem_initialize() creates
0171  * a "/dev" directory.
0172  */
0173 #define CONFIGURE_IMFS_DISABLE_MKNOD
0174 #endif
0175 
0176 #define CONFIGURE_IMFS_DISABLE_MKNOD_FILE
0177 #define CONFIGURE_IMFS_DISABLE_MOUNT
0178 #define CONFIGURE_IMFS_DISABLE_RENAME
0179 #define CONFIGURE_IMFS_DISABLE_READDIR
0180 #define CONFIGURE_IMFS_DISABLE_RMNOD
0181 #define CONFIGURE_IMFS_DISABLE_SYMLINK
0182 #define CONFIGURE_IMFS_DISABLE_UTIME
0183 
0184 #define CONFIGURE_MAXIMUM_TASKS 1
0185 
0186 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0187 
0188 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0189 
0190 #define CONFIGURE_INIT
0191 
0192 #include <rtems/confdefs.h>