File indexing completed on 2025-05-11 08:24:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032
0033 #include <sys/stat.h>
0034 #include <limits.h>
0035 #include <fcntl.h>
0036 #include <errno.h>
0037 #include <stdio.h>
0038 #include <stdint.h>
0039 #include <stdlib.h>
0040 #include <string.h>
0041 #include <unistd.h>
0042
0043 #include "fstest.h"
0044 #include "fs_config.h"
0045 #include <tmacros.h>
0046
0047 const char rtems_test_name[] = "FSERROR " FILESYSTEM;
0048 const RTEMS_TEST_STATE rtems_test_state = TEST_STATE;
0049
0050 static void open_mkdir_error (void)
0051 {
0052 int fd;
0053 int status;
0054 char *name01 = "name01";
0055 char *name02 = "name02";
0056 char *name03 = "name03";
0057
0058 char name[20];
0059
0060 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
0061
0062 const char *wd = __func__;
0063
0064
0065
0066
0067 status = mkdir (wd, mode);
0068 rtems_test_assert (status == 0);
0069 status = chdir (wd);
0070 rtems_test_assert (status == 0);
0071
0072
0073
0074
0075
0076 fd = creat (name01, mode);
0077 status = close (fd);
0078 rtems_test_assert (status == 0);
0079 status = mkdir (name02, mode);
0080 rtems_test_assert (status == 0);
0081
0082
0083
0084
0085 EXPECT_ERROR (EEXIST, open, name01, O_CREAT | O_EXCL);
0086
0087 EXPECT_ERROR (EEXIST, mkdir, name01, mode);
0088
0089
0090
0091
0092 EXPECT_ERROR (EISDIR, open, name02, O_WRONLY);
0093 EXPECT_ERROR (EISDIR, open, name02, O_RDWR);
0094
0095
0096
0097
0098
0099
0100
0101 sprintf (name, "%s/%s", name03, name02);
0102 EXPECT_ERROR (ENOENT, open, name, O_WRONLY);
0103 EXPECT_ERROR (ENOENT, open, "", O_WRONLY);
0104 EXPECT_ERROR (ENOENT, open, name03, O_WRONLY);
0105
0106 EXPECT_ERROR (ENOENT, mkdir, name, mode);
0107 EXPECT_ERROR (ENOENT, mkdir, "", mode);
0108
0109
0110
0111
0112
0113 sprintf (name, "%s/%s", name01, name02);
0114 EXPECT_ERROR (ENOTDIR, open, name, O_WRONLY);
0115
0116 EXPECT_ERROR (ENOTDIR, mkdir, name, mode);
0117
0118
0119
0120 EXPECT_ERROR (EBADF, close, -1);
0121 EXPECT_ERROR (EBADF, close, 100);
0122
0123
0124
0125
0126 status = chdir ("..");
0127 rtems_test_assert (status == 0);
0128
0129 }
0130
0131 static void rename_error (void)
0132 {
0133
0134 int fd;
0135 int status;
0136 char *name01 = "name01";
0137 char *name02 = "name02";
0138 char *name03 = "name03";
0139
0140 char name[20];
0141
0142 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
0143 const char *wd = __func__;
0144
0145
0146
0147
0148
0149 status = mkdir (wd, mode);
0150 rtems_test_assert (status == 0);
0151 status = chdir (wd);
0152 rtems_test_assert (status == 0);
0153
0154
0155
0156
0157
0158
0159 status = mkdir (name01, mode);
0160 rtems_test_assert (status == 0);
0161 status = mkdir (name02, mode);
0162 rtems_test_assert (status == 0);
0163 sprintf (name, "%s/%s", name01, name03);
0164 status = mkdir (name, mode);
0165 rtems_test_assert (status == 0);
0166
0167
0168
0169
0170
0171 status = rename (name02, name01);
0172 rtems_test_assert (status != 0);
0173 rtems_test_assert (errno == EEXIST || errno == ENOTEMPTY);
0174
0175
0176
0177
0178 fd = creat (name03, mode);
0179 status = close (fd);
0180 rtems_test_assert (status == 0);
0181
0182
0183
0184
0185
0186 EXPECT_ERROR (ENOENT, rename, name01, "");
0187
0188
0189
0190
0191
0192
0193
0194 sprintf (name, "%s/%s", name03, name01);
0195 EXPECT_ERROR (ENOTDIR, rename, name03, name);
0196
0197
0198
0199
0200 status = chdir ("..");
0201 rtems_test_assert (status == 0);
0202 }
0203
0204 static void truncate_error (void)
0205 {
0206
0207 int fd;
0208 int status;
0209 char *file = "name";
0210
0211 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
0212
0213 const char *wd = __func__;
0214
0215
0216
0217
0218 status = mkdir (wd, mode);
0219 rtems_test_assert (status == 0);
0220 status = chdir (wd);
0221 rtems_test_assert (status == 0);
0222
0223
0224
0225 fd = creat (file, mode);
0226 status = close (fd);
0227 rtems_test_assert (status == 0);
0228
0229
0230
0231
0232
0233 EXPECT_ERROR (EINVAL, truncate, file, -1);
0234
0235
0236
0237
0238 status = chdir ("..");
0239 rtems_test_assert (status == 0);
0240 }
0241
0242
0243 static void rmdir_unlink_error (void)
0244 {
0245 int status;
0246 int fd;
0247 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
0248 char *nonexistence = "name04";
0249
0250 const char *wd = __func__;
0251
0252
0253
0254
0255 status = mkdir (wd, mode);
0256 rtems_test_assert (status == 0);
0257 status = chdir (wd);
0258 rtems_test_assert (status == 0);
0259
0260
0261
0262
0263 status = mkdir ("tmp", mode);
0264 rtems_test_assert (status == 0);
0265 fd = creat ("tmp/file", mode);
0266 status = close (fd);
0267 rtems_test_assert (status == 0);
0268
0269
0270
0271
0272
0273
0274
0275
0276 EXPECT_ERROR (ENOTEMPTY, rmdir, "tmp");
0277
0278
0279
0280
0281
0282
0283
0284 EXPECT_ERROR (EINVAL, rmdir, ".");
0285 EXPECT_ERROR (EINVAL, rmdir, "tmp/.");
0286
0287
0288
0289
0290
0291
0292 EXPECT_ERROR (ENOENT, rmdir, "");
0293 EXPECT_ERROR (ENOENT, rmdir, nonexistence);
0294
0295 EXPECT_ERROR (ENOENT, unlink, "");
0296 EXPECT_ERROR (ENOENT, unlink, nonexistence);
0297
0298
0299
0300
0301
0302 EXPECT_ERROR (ENOTDIR, rmdir, "tmp/file");
0303
0304 EXPECT_ERROR (ENOTDIR, unlink, "tmp/file/dir");
0305
0306
0307
0308 status = chdir ("..");
0309 rtems_test_assert (status == 0);
0310
0311
0312 }
0313
0314 static void rdwr_error (void)
0315 {
0316
0317 int status;
0318 int fd;
0319 char *file01 = "name01";
0320 char *databuf = "test";
0321 char *readbuf[10];
0322 int shift = sizeof(off_t) * 8 - 1;
0323 off_t one = 1;
0324 off_t tiny = one << shift;
0325 off_t huge = tiny - 1;
0326 off_t off;
0327
0328 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
0329 const char *wd = __func__;
0330
0331
0332
0333
0334 status = mkdir (wd, mode);
0335 rtems_test_assert (status == 0);
0336 status = chdir (wd);
0337 rtems_test_assert (status == 0);
0338
0339 fd = open (file01, O_WRONLY | O_CREAT, mode);
0340
0341
0342
0343
0344
0345 EXPECT_ERROR (EBADF, read, fd, readbuf, 10);
0346 EXPECT_ERROR (EBADF, read, 100, readbuf, 10);
0347
0348 status = close (fd);
0349 rtems_test_assert (status == 0);
0350
0351
0352
0353 fd = open (file01, O_RDONLY, mode);
0354
0355 EXPECT_ERROR (EBADF, write, fd, databuf, 10);
0356
0357 status = close (fd);
0358 rtems_test_assert (status == 0);
0359
0360 EXPECT_ERROR (EBADF, write, fd, readbuf, 10);
0361
0362
0363
0364
0365
0366
0367
0368 fd = open (file01, O_RDWR, mode);
0369
0370 EXPECT_ERROR (EINVAL, lseek, fd, -100, SEEK_END);
0371 EXPECT_ERROR (EINVAL, lseek, fd, -100, SEEK_CUR);
0372 EXPECT_ERROR (EINVAL, lseek, fd, -100, SEEK_SET);
0373
0374 status = ftruncate (fd, 1);
0375 rtems_test_assert (status == 0);
0376 EXPECT_ERROR (EOVERFLOW, lseek, fd, huge, SEEK_END);
0377
0378 off = lseek (fd, 1, SEEK_SET);
0379 rtems_test_assert (off == 1);
0380 EXPECT_ERROR (EOVERFLOW, lseek, fd, huge, SEEK_CUR);
0381
0382 status = close (fd);
0383 rtems_test_assert (status == 0);
0384
0385 EXPECT_ERROR (EBADF, lseek, fd, 0, SEEK_SET);
0386
0387
0388
0389
0390 status = chdir ("..");
0391 rtems_test_assert (status == 0);
0392
0393 }
0394
0395 void test (void)
0396 {
0397
0398 open_mkdir_error ();
0399 rename_error ();
0400 truncate_error ();
0401 rmdir_unlink_error ();
0402 rdwr_error ();
0403 }