From 141076fdff1fa6a918eb4d276c95f94b92c31771 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 15 Apr 2022 22:08:40 -0500 Subject: [PATCH] Update: Add missing checks to f_file_link_hard_at() and use F_file_descriptor. The F_data_not tests are missing, add them. The EBADF is returning F_directory_descriptor. In this specific case, the descriptor is not for a directory per-say but for a general file. The F_file_descriptor code should be returned in this case. This has been revealed by the unit tests that I am writing. --- level_0/f_file/c/file.c | 6 +++++- level_0/f_file/c/file.h | 1 + level_0/f_file/c/private-file.c | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/level_0/f_file/c/file.c b/level_0/f_file/c/file.c index 98de2d6..23c160a 100644 --- a/level_0/f_file/c/file.c +++ b/level_0/f_file/c/file.c @@ -578,9 +578,13 @@ extern "C" { #ifndef _di_f_file_link_hard_at_ f_status_t f_file_link_hard_at(const int at_id_target, const int at_id_point, const f_string_static_t target, const f_string_static_t point, const int flag) { + if (!target.used || !point.used) { + return F_data_not; + } + if (linkat(at_id_target, target.string, at_id_point, point.string, flag) < 0) { if (errno == EACCES) return F_status_set_error(F_access_denied); - if (errno == EBADF) return F_status_set_error(F_directory_descriptor); + if (errno == EBADF) return F_status_set_error(F_file_descriptor); if (errno == EDQUOT) return F_status_set_error(F_filesystem_quota_block); if (errno == EEXIST) return F_status_set_error(F_file_found); if (errno == EFAULT) return F_status_set_error(F_buffer); diff --git a/level_0/f_file/c/file.h b/level_0/f_file/c/file.h index 1ed2602..80c314d 100644 --- a/level_0/f_file/c/file.h +++ b/level_0/f_file/c/file.h @@ -929,6 +929,7 @@ extern "C" { * F_busy (with error bit) if file system is too busy to perform write. * F_directory_descriptor (with error bit) when either at_id_target or at_id_point is not a valid file descriptor (at_id must point to a directory). * F_directory_not (with error bit) if a supposed directory in path is not actually a directory. + * F_file_descriptor (with error bit) if file descriptor is invalid. * F_file_found (with error bit) if a file aleady exists at the path. * F_file_found_not (with error bit) if a parent path in point does not exist or is a broken symlink. * F_filesystem_quota_block (with error bit) if file system's disk blocks or inodes are exhausted. diff --git a/level_0/f_file/c/private-file.c b/level_0/f_file/c/private-file.c index 8cb410d..a4f3e49 100644 --- a/level_0/f_file/c/private-file.c +++ b/level_0/f_file/c/private-file.c @@ -404,7 +404,7 @@ extern "C" { #if !defined(_di_f_file_link_read_) || !defined(_di_f_file_copy_) f_status_t private_f_file_link_read(const f_string_static_t path, const struct stat link_stat, f_string_dynamic_t * const target) { - // create a NULL terminated string based on file stat. + // Create a NULL terminated string based on file stat. if (link_stat.st_size + 1 > target->size) { if (link_stat.st_size + 1 > F_array_length_t_size_d) { return F_status_set_error(F_string_too_large); -- 1.8.3.1