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 <errno.h>
0036 #include <fcntl.h>
0037 #include <stdio.h>
0038 #include <unistd.h>
0039 #include <utime.h>
0040 
0041 #include <rtems/imfs.h>
0042 #include <rtems/libio.h>
0043 
0044 const char rtems_test_name[] = "FSIMFSCONFIG 3";
0045 
0046 static const IMFS_node_control node_control = IMFS_GENERIC_INITIALIZER(
0047   &rtems_filesystem_handlers_default,
0048   IMFS_node_initialize_generic,
0049   IMFS_node_destroy_default
0050 );
0051 
0052 static void Init(rtems_task_argument arg)
0053 {
0054   const struct utimbuf times = {0};
0055   const char *generic = "generic";
0056   const char *mnt = "mnt";
0057   const char *dev = "device";
0058   const char *file = "file";
0059   const char *fifo = "fifo";
0060   int rv;
0061   int fd;
0062 
0063   TEST_BEGIN();
0064 
0065   rv = IMFS_make_generic_node(
0066     generic,
0067     S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO,
0068     &node_control,
0069     NULL
0070   );
0071   rtems_test_assert(rv == 0);
0072 
0073   errno = 0;
0074   rv = chown(generic, 0, 0);
0075   rtems_test_assert(rv == -1);
0076   rtems_test_assert(errno == ENOTSUP);
0077 
0078   errno = 0;
0079   rv = chmod(generic, 0);
0080   rtems_test_assert(rv == -1);
0081   rtems_test_assert(errno == ENOTSUP);
0082 
0083   errno = 0;
0084   rv = link(generic, "link");
0085   rtems_test_assert(rv == -1);
0086   rtems_test_assert(errno == ENOTSUP);
0087 
0088   rv = mkdir(mnt, S_IRWXU);
0089   rtems_test_assert(rv == 0);
0090 
0091   rv = mknod(dev, S_IFCHR | S_IRWXU, 0);
0092   rtems_test_assert(rv == 0);
0093 
0094   fd = creat(file, S_IRWXU);
0095   rtems_test_assert(fd == 0);
0096 
0097   rv = close(fd);
0098   rtems_test_assert(rv == 0);
0099 
0100   errno = 0;
0101   rv = mkfifo(fifo, S_IRWXU);
0102   rtems_test_assert(rv == -1);
0103   rtems_test_assert(errno == ENOSYS);
0104 
0105   rv = mount(
0106     "",
0107     mnt,
0108     RTEMS_FILESYSTEM_TYPE_IMFS,
0109     RTEMS_FILESYSTEM_READ_ONLY,
0110     NULL
0111   );
0112   rtems_test_assert(rv == 0);
0113 
0114   errno = 0;
0115   rv = unmount(mnt);
0116   rtems_test_assert(rv == -1);
0117   rtems_test_assert(errno == ENOTSUP);
0118 
0119   errno = 0;
0120   rv = rename(generic, "new");
0121   rtems_test_assert(rv == -1);
0122   rtems_test_assert(errno == ENOTSUP);
0123 
0124   errno = 0;
0125   rv = symlink(generic, "link");
0126   rtems_test_assert(rv == -1);
0127   rtems_test_assert(errno == ENOTSUP);
0128 
0129   errno = 0;
0130   rv = utime(generic, &times);
0131   rtems_test_assert(rv == -1);
0132   rtems_test_assert(errno == ENOTSUP);
0133 
0134   rv = unlink(generic);
0135   rtems_test_assert(rv == 0);
0136 
0137   TEST_END();
0138   rtems_test_exit(0);
0139 }
0140 
0141 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0142 
0143 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 1
0144 
0145 #define CONFIGURE_FILESYSTEM_IMFS
0146 
0147 #define CONFIGURE_USE_MINIIMFS_AS_BASE_FILESYSTEM
0148 
0149 #define CONFIGURE_MAXIMUM_TASKS 1
0150 
0151 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0152 
0153 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0154 
0155 #define CONFIGURE_INIT
0156 
0157 #include <rtems/confdefs.h>