/*--------------------------------------------------------------* * ss_m::create_file() * *--------------------------------------------------------------*/ rc_t ss_m::create_file( vid_t vid, stid_t& fid, store_property_t property, shpid_t cluster_hint // = 0 ) { #if FILE_LOG_COMMENT_ON W_DO(log_comment("create_file")); #endif SM_PROLOGUE_RC(ss_m::create_file, in_xct, read_write, 0); DBGTHRD(<<"create_file " <<vid << " " << property ); W_DO(_create_file(vid, fid, property, cluster_hint)); DBGTHRD(<<"create_file returns " << fid); return RCOK; }
//----------------------------------------------------------------------------- // fopen: Open or Create a file for reading or writing //----------------------------------------------------------------------------- FL_FILE* fl_fopen(char *path, char *mode) { int modlen, i; FL_FILE* file; BOOL read = FALSE; BOOL write = FALSE; BOOL append = FALSE; BOOL binary = FALSE; BOOL create = FALSE; BOOL erase = FALSE; // If first call to library, initialise CHECK_FL_INIT(); if ((path==NULL) || (mode==NULL)) return NULL; modlen = (int)strlen(mode); // Supported Modes: // "r" Open a file for reading. The file must exist. // "w" Create an empty file for writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file. // "a" Append to a file. Writing operations append data at the end of the file. The file is created if it does not exist. // "r+" Open a file for update both reading and writing. The file must exist. // "w+" Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file. // "a+" Open a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. You can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist. for (i=0;i<modlen;i++) { switch (tolower(mode[i])) { case 'r': read = TRUE; break; case 'w': write = TRUE; erase = TRUE; create = TRUE; break; case 'a': write = TRUE; append = TRUE; create = TRUE; break; case '+': if (read) write = TRUE; else if (write) { read = TRUE; erase = TRUE; create = TRUE; } else if (append) { read = TRUE; write = TRUE; append = TRUE; create = TRUE; } break; case 'b': binary = TRUE; break; } } file = NULL; // Read if (read) file = _read_file(path); // Create New #ifdef INCLUDE_WRITE_SUPPORT if ( (file==NULL) && (create) ) file = _create_file(path, 0); #else create = FALSE; write = FALSE; append = FALSE; #endif // Write Existing if ( !create && !read && (write || append) ) file = _read_file(path); if (file!=NULL) { file->Read = read; file->Write = write; file->Append = append; file->Binary = binary; file->Erase = erase; } return file; }
//----------------------------------------------------------------------------- // fopen: Open or Create a file for reading or writing //----------------------------------------------------------------------------- void* fl_fopen(const char *path, const char *mode) { int i; FL_FILE* file; unsigned char flags = 0; // If first call to library, initialise CHECK_FL_INIT(); if (!_filelib_valid) return NULL; if (!path || !mode) return NULL; // Supported Modes: // "r" Open a file for reading. The file must exist. // "w" Create an empty file for writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file. // "a" Append to a file. Writing operations append data at the end of the file. The file is created if it does not exist. // "r+" Open a file for update both reading and writing. The file must exist. // "w+" Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file. // "a+" Open a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. You can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist. for (i=0;i<(int)strlen(mode);i++) { switch (tolower(mode[i])) { case 'r': flags |= FILE_READ; break; case 'w': flags |= FILE_WRITE; flags |= FILE_ERASE; flags |= FILE_CREATE; break; case 'a': flags |= FILE_WRITE; flags |= FILE_APPEND; flags |= FILE_CREATE; break; case '+': if (flags & FILE_READ) flags |= FILE_WRITE; else if (flags & FILE_WRITE) { flags |= FILE_READ; flags |= FILE_ERASE; flags |= FILE_CREATE; } else if (flags & FILE_APPEND) { flags |= FILE_READ; flags |= FILE_WRITE; flags |= FILE_APPEND; flags |= FILE_CREATE; } break; case 'b': flags |= FILE_BINARY; break; } } file = NULL; #ifndef FATFS_INC_WRITE_SUPPORT // No write support! flags &= ~(FILE_CREATE | FILE_WRITE | FILE_APPEND); #endif // No write access - remove write/modify flags if (!_fs.disk_io.write_sector) flags &= ~(FILE_CREATE | FILE_WRITE | FILE_APPEND); FL_LOCK(&_fs); // Read file = _open_file(path); //if (!(flags & FILE_READ)) // _free_file(file); // Create New #ifdef FATFS_INC_WRITE_SUPPORT // Remove old file if(flags & FILE_ERASE) { fl_remove(path); if(file) _free_file(file); } if (!file && (flags & FILE_CREATE)) file = _create_file(path); #endif // Write Existing (and not open due to read or create) //if (!(flags & FILE_READ)) // if (!(flags & FILE_CREATE)) // if (flags & (FILE_WRITE | FILE_APPEND)) // file = _open_file(path); if (file) file->flags = flags; FL_UNLOCK(&_fs); return file; }