Fixed a bug that regular files could not be created by mknod

This commit is contained in:
Takeshi Nakatani 2022-06-19 06:02:23 +00:00 committed by Andrew Gaul
parent 73b49c1038
commit f11eb7d69b
3 changed files with 11 additions and 7 deletions

View File

@ -1545,7 +1545,7 @@ int FdEntity::RowFlushMultipart(PseudoFdInfo* pseudo_obj, const char* tpath)
S3FS_PRN_ERR("failed to truncate file(physical_fd=%d) to zero, but continue...", physical_fd);
}
// put pending headers or create new file
if(0 != (result = UploadPending())){
if(0 != (result = UploadPending(-1))){
return result;
}
}
@ -1673,7 +1673,7 @@ int FdEntity::RowFlushMixMultipart(PseudoFdInfo* pseudo_obj, const char* tpath)
S3FS_PRN_ERR("failed to truncate file(physical_fd=%d) to zero, but continue...", physical_fd);
}
// put pending headers or create new file
if(0 != (result = UploadPending())){
if(0 != (result = UploadPending(-1))){
return result;
}
}

View File

@ -105,7 +105,7 @@ class FdEntity
int GetPhysicalFd() const { return physical_fd; }
bool IsModified() const;
bool MergeOrgMeta(headers_t& updatemeta);
int UploadPending(int fd = -1);
int UploadPending(int fd);
bool GetStats(struct stat& st, bool lock_already_held = false);
int SetCtime(struct timespec time, bool lock_already_held = false);

View File

@ -82,7 +82,7 @@ bool TestMknod(const char* basepath, mode_t mode)
break;
case S_IFBLK:
str_mode = str_mode_blk;
dev = makedev((long long)(259), 0); // temporary value
dev = makedev((unsigned int)(259), 0); // temporary value
sprintf(filepath, "%s.%s", basepath, str_ext_blk);
break;
case S_IFIFO:
@ -93,7 +93,8 @@ bool TestMknod(const char* basepath, mode_t mode)
case S_IFSOCK:
str_mode = str_mode_sock;
dev = 0;
sprintf(filepath, "%s.%s", basepath, str_ext_sock);
snprintf(filepath, S3FS_TEST_PATH_MAX, "%s.%s", basepath, str_ext_sock);
filepath[S3FS_TEST_PATH_MAX - 1] = '\0'; // for safety
break;
default:
fprintf(stderr, "[ERROR] Called function with wrong mode argument.\n");
@ -137,11 +138,11 @@ int main(int argc, char *argv[])
{
// Parse parameters
if(2 != argc){
fprintf(stderr, "[ERROR] No paraemter is specified.\n");
fprintf(stderr, "[ERROR] No parameter is specified.\n");
fprintf(stderr, "%s\n", usage_string);
exit(EXIT_FAILURE);
}
if(0 == strcasecmp("-h", argv[1]) || 0 == strcasecmp("--help", argv[1])){
if(0 == strcmp("-h", argv[1]) || 0 == strcmp("--help", argv[1])){
fprintf(stdout, "%s\n", usage_string);
exit(EXIT_SUCCESS);
}
@ -155,6 +156,9 @@ int main(int argc, char *argv[])
// [NOTE]
// Privilege is required to execute S_IFBLK.
//
if(0 != geteuid()){
fprintf(stderr, "[WARNING] Skipping mknod(S_IFBLK) due to missing root privileges.\n");
}
if(!TestMknod(argv[1], S_IFREG) ||
!TestMknod(argv[1], S_IFCHR) ||
!TestMknod(argv[1], S_IFIFO) ||