Skip to content

Commit a5db588

Browse files
committed
fs: _kern_open_parent_dir, use the right fd and handle root path
1 parent d71f0a5 commit a5db588

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/system/libroot2/fs/fs.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ _kern_open_parent_dir(int fd, char* name, size_t length)
112112

113113
int dirfd = _kern_open_dir(fd, "..");
114114
if (dirfd < 0)
115-
return dirfd;
115+
return -errno;
116116

117117
if (name != NULL) {
118118
if (length <= 0) {
@@ -121,7 +121,7 @@ _kern_open_parent_dir(int fd, char* name, size_t length)
121121
}
122122

123123
char buf[B_PATH_NAME_LENGTH];
124-
status_t ret = _kern_fd_to_path(dirfd, -1, buf, sizeof(buf));
124+
status_t ret = _kern_fd_to_path(fd, -1, buf, sizeof(buf));
125125
if (ret != B_OK) {
126126
close(dirfd);
127127
return ret;
@@ -133,13 +133,16 @@ _kern_open_parent_dir(int fd, char* name, size_t length)
133133
return B_ENTRY_NOT_FOUND;
134134
}
135135

136+
if (strcmp(baseName, "/") == 0)
137+
baseName = (char*)".";
138+
136139
size_t len = strlen(baseName);
137140
if (len+1 > length) {
138141
close(dirfd);
139142
return B_BUFFER_OVERFLOW;
140143
}
141144

142-
if (strlcpy(name, baseName, len) >= len) {
145+
if (strlcpy(name, baseName, length) >= length) {
143146
close(dirfd);
144147
return B_BUFFER_OVERFLOW;
145148
}

0 commit comments

Comments
 (0)