summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/common/file.c20
-rw-r--r--firmware/include/file_internal.h16
2 files changed, 15 insertions, 21 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index 028bdbe9f0..cb918c6eab 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -349,13 +349,14 @@ file_error:;
349/* actually do the open gruntwork */ 349/* actually do the open gruntwork */
350static int open_internal_inner2(const char *path, 350static int open_internal_inner2(const char *path,
351 struct filestr_desc *file, 351 struct filestr_desc *file,
352 unsigned int callflags) 352 unsigned int callflags,
353 int oflag)
353{ 354{
354 int rc; 355 int rc;
355 356
356 struct path_component_info compinfo; 357 struct path_component_info compinfo;
357 358
358 if (callflags & FF_CREAT) 359 if (oflag & O_CREAT)
359 callflags |= FF_PARENTINFO; 360 callflags |= FF_PARENTINFO;
360 361
361 rc = open_stream_internal(path, callflags, &file->stream, &compinfo); 362 rc = open_stream_internal(path, callflags, &file->stream, &compinfo);
@@ -369,7 +370,7 @@ static int open_internal_inner2(const char *path,
369 370
370 if (rc > 0) 371 if (rc > 0)
371 { 372 {
372 if (callflags & FF_EXCL) 373 if (oflag & O_EXCL)
373 { 374 {
374 DEBUGF("File exists\n"); 375 DEBUGF("File exists\n");
375 FILE_ERROR(EEXIST, -2); 376 FILE_ERROR(EEXIST, -2);
@@ -386,7 +387,7 @@ static int open_internal_inner2(const char *path,
386 compinfo.filesize = MAX_DIRECTORY_SIZE; /* allow file ops */ 387 compinfo.filesize = MAX_DIRECTORY_SIZE; /* allow file ops */
387 } 388 }
388 } 389 }
389 else if (callflags & FF_CREAT) 390 else if (oflag & O_CREAT)
390 { 391 {
391 if (compinfo.attr & ATTR_DIRECTORY) 392 if (compinfo.attr & ATTR_DIRECTORY)
392 { 393 {
@@ -483,15 +484,10 @@ static int open_internal_inner1(const char *path, int oflag,
483 /* O_CREAT and O_APPEND are fine without write mode 484 /* O_CREAT and O_APPEND are fine without write mode
484 * for the former, an empty file is created but no data may be written 485 * for the former, an empty file is created but no data may be written
485 * for the latter, no append will be allowed anyway */ 486 * for the latter, no append will be allowed anyway */
486 if (oflag & O_CREAT) 487 if (!(oflag & O_CREAT))
487 { 488 oflag &= ~O_EXCL; /* result is undefined: we choose "ignore" */
488 callflags |= FF_CREAT;
489
490 if (oflag & O_EXCL)
491 callflags |= FF_EXCL;
492 }
493 489
494 rc = open_internal_inner2(path, file, callflags); 490 rc = open_internal_inner2(path, file, callflags, oflag);
495 if (rc < 0) 491 if (rc < 0)
496 FILE_ERROR(ERRNO, rc * 10 - 3); 492 FILE_ERROR(ERRNO, rc * 10 - 3);
497 493
diff --git a/firmware/include/file_internal.h b/firmware/include/file_internal.h
index e7edb3a441..bb1236aed1 100644
--- a/firmware/include/file_internal.h
+++ b/firmware/include/file_internal.h
@@ -130,15 +130,13 @@ enum fildes_and_obj_flags
130 FF_DIR = 0x00010000, /* expect dir; accept dir only */ 130 FF_DIR = 0x00010000, /* expect dir; accept dir only */
131 FF_ANYTYPE = 0x00020000, /* succeed if either file or dir */ 131 FF_ANYTYPE = 0x00020000, /* succeed if either file or dir */
132 FF_TYPEMASK = 0x00030000, /* mask of typeflags */ 132 FF_TYPEMASK = 0x00030000, /* mask of typeflags */
133 FF_CREAT = 0x00040000, /* create if file doesn't exist */ 133 FF_CHECKPREFIX = 0x00040000, /* detect if file is prefix of path */
134 FF_EXCL = 0x00080000, /* fail if creating and file exists */ 134 FF_NOISO = 0x00080000, /* do not decode ISO filenames to UTF-8 */
135 FF_CHECKPREFIX = 0x00100000, /* detect if file is prefix of path */ 135 FF_PROBE = 0x00100000, /* only test existence; don't open */
136 FF_NOISO = 0x00200000, /* do not decode ISO filenames to UTF-8 */ 136 FF_CACHEONLY = 0x00200000, /* succeed only if in dircache */
137 FF_PROBE = 0x00400000, /* only test existence; don't open */ 137 FF_INFO = 0x00400000, /* return info on self */
138 FF_CACHEONLY = 0x00800000, /* succeed only if in dircache */ 138 FF_PARENTINFO = 0x00800000, /* return info on parent */
139 FF_INFO = 0x01000000, /* return info on self */ 139 FF_MASK = 0x00ff0000,
140 FF_PARENTINFO = 0x02000000, /* return info on parent */
141 FF_MASK = 0x03ff0000,
142}; 140};
143 141
144/** Common data structures used throughout **/ 142/** Common data structures used throughout **/