DRIVE_FILE* drive_file_new(const char* base_path, const char* path, UINT32 id, UINT32 DesiredAccess, UINT32 CreateDisposition, UINT32 CreateOptions) { DRIVE_FILE* file; file = (DRIVE_FILE*) calloc(1, sizeof(DRIVE_FILE)); if (!file) { WLog_ERR(TAG, "calloc failed!"); return NULL; } file->id = id; file->basepath = (char*) base_path; drive_file_set_fullpath(file, drive_file_combine_fullpath(base_path, path)); file->fd = -1; if (!drive_file_init(file, DesiredAccess, CreateDisposition, CreateOptions)) { drive_file_free(file); return NULL; } #if defined(__linux__) && defined(O_PATH) if (file->fd < 0 && file->err == EACCES) { /** * We have no access permissions for the file or directory but if the * peer is only interested in reading the object's attributes we can try * to obtain a file descriptor who's only purpose is to perform * operations that act purely at the file descriptor level. * See open(2) **/ { if ((file->fd = OPEN(file->fullpath, O_PATH)) >= 0) { file->err = 0; } } } #endif return file; }
DRIVE_FILE* drive_file_new(const char* base_path, const char* path, UINT32 id, UINT32 DesiredAccess, UINT32 CreateDisposition, UINT32 CreateOptions) { DRIVE_FILE* file; file = (DRIVE_FILE*) malloc(sizeof(DRIVE_FILE)); ZeroMemory(file, sizeof(DRIVE_FILE)); file->id = id; file->basepath = (char*) base_path; drive_file_set_fullpath(file, drive_file_combine_fullpath(base_path, path)); file->fd = -1; if (!drive_file_init(file, DesiredAccess, CreateDisposition, CreateOptions)) { (void) drive_file_free(file, TRUE); return NULL; } return file; }