diff --git a/syscall/fs_syscall.c b/syscall/fs_syscall.c index 94e42e10..5d3f4cc7 100644 --- a/syscall/fs_syscall.c +++ b/syscall/fs_syscall.c @@ -502,6 +502,30 @@ int SysExecve(const char *fileName, char *const *argv, char *const *envp) } #endif +int SysFchdir(int fd) +{ + int ret; + int sysFd; + struct file *file = NULL; + + sysFd = GetAssociatedSystemFd(fd); + if (sysFd < 0) { + return -EBADF; + } + + ret = fs_getfilep(sysFd, &file); + if (ret < 0) { + return -get_errno(); + } + + ret = chdir(file->f_path); + if (ret < 0) { + ret = -get_errno(); + } + + return ret; +} + int SysChdir(const char *path) { int ret; diff --git a/syscall/los_syscall.h b/syscall/los_syscall.h index 51abfde2..0a7edc1a 100644 --- a/syscall/los_syscall.h +++ b/syscall/los_syscall.h @@ -231,6 +231,7 @@ extern int SysSymlinkat(const char *target, int dirfd, const char *linkpath); extern ssize_t SysReadlinkat(int dirfd, const char *pathname, char *buf, size_t bufsize); extern int SysUnlink( const char *pathname); extern int SysExecve(const char *fileName, char *const *argv, char *const *envp); +extern int SysFchdir(int fd); extern int SysChdir(const char *path); extern int SysUtimensat(int fd, const char *path, struct timespec times[2], int flag); extern int SysFchmodat(int fd, const char *path, mode_t mode, int flag); diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index d2181aa8..89bf894e 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -47,6 +47,7 @@ SYSCALL_HAND_DEF(__NR_execve, SysExecve, int, ARG_NUM_3) #endif SYSCALL_HAND_DEF(__NR_sysinfo, SysInfo, int, ARG_NUM_1) +SYSCALL_HAND_DEF(__NR_fchdir, SysFchdir, int, ARG_NUM_1) SYSCALL_HAND_DEF(__NR_chdir, SysChdir, int, ARG_NUM_1) SYSCALL_HAND_DEF(__NR_utimensat, SysUtimensat, int, ARG_NUM_4) SYSCALL_HAND_DEF(__NR_fchmodat, SysFchmodat, int, ARG_NUM_4) diff --git a/testsuites/unittest/fs/BUILD.gn b/testsuites/unittest/fs/BUILD.gn index d907e799..0e26f4bf 100644 --- a/testsuites/unittest/fs/BUILD.gn +++ b/testsuites/unittest/fs/BUILD.gn @@ -211,8 +211,11 @@ sources_full = [ "jffs/full/it_test_fs_jffs_002.cpp", "jffs/full/it_test_fs_jffs_003.cpp", "jffs/full/it_test_fs_jffs_004.cpp", - "jffs/full/it_test_fs_jffs_102.cpp", - "jffs/full/it_test_fs_jffs_103.cpp", + "jffs/full/it_test_fs_jffs_100.cpp", + "jffs/full/it_test_fs_jffs_101.cpp", + "jffs/full/it_test_fs_jffs_106.cpp", + "jffs/full/it_test_fs_jffs_112.cpp", + "jffs/full/it_test_fs_jffs_113.cpp", "jffs/full/It_jffs_001.cpp", "jffs/full/It_jffs_002.cpp", "jffs/full/It_jffs_003.cpp", diff --git a/testsuites/unittest/fs/jffs/It_vfs_jffs.h b/testsuites/unittest/fs/jffs/It_vfs_jffs.h index 56415cc3..30d525a7 100644 --- a/testsuites/unittest/fs/jffs/It_vfs_jffs.h +++ b/testsuites/unittest/fs/jffs/It_vfs_jffs.h @@ -271,8 +271,13 @@ void ItTestFsJffs001(void); void ItTestFsJffs002(void); void ItTestFsJffs003(void); void ItTestFsJffs004(void); +void ItTestFsJffs100(void); +void ItTestFsJffs101(void); void ItTestFsJffs102(void); void ItTestFsJffs103(void); +void ItTestFsJffs106(void); +void ItTestFsJffs112(void); +void ItTestFsJffs113(void); VOID ItJffs001(VOID); VOID ItJffs002(VOID); VOID ItJffs003(VOID); diff --git a/testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_100.cpp b/testsuites/unittest/fs/jffs/full/it_test_fs_jffs_100.cpp similarity index 99% rename from testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_100.cpp rename to testsuites/unittest/fs/jffs/full/it_test_fs_jffs_100.cpp index ca3fca14..d21b1ca9 100644 --- a/testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_100.cpp +++ b/testsuites/unittest/fs/jffs/full/it_test_fs_jffs_100.cpp @@ -28,7 +28,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "It_fs_jffs.h" +#include "It_vfs_jffs.h" static int TestCase(void) { diff --git a/testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_101.cpp b/testsuites/unittest/fs/jffs/full/it_test_fs_jffs_101.cpp similarity index 92% rename from testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_101.cpp rename to testsuites/unittest/fs/jffs/full/it_test_fs_jffs_101.cpp index 6d481031..cc56a689 100644 --- a/testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_101.cpp +++ b/testsuites/unittest/fs/jffs/full/it_test_fs_jffs_101.cpp @@ -28,7 +28,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "It_fs_jffs.h" +#include "It_vfs_jffs.h" #define TEST_STRLEN 30 @@ -56,6 +56,16 @@ static int TestCase(void) fd = open(pathname2, O_DIRECTORY); ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT); + /* EBADF */ + ret = fchdir(-1); + ICUNIT_GOTO_NOT_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1); + + ret = errno; + ICUNIT_GOTO_EQUAL(ret, EBADF, ret, EXIT1); + + ret = chdir(pathname); + ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1); + pret = getcwd(buf1, TEST_STRLEN); ICUNIT_GOTO_NOT_EQUAL(pret, NULL, pret, EXIT1); ICUNIT_GOTO_STRING_EQUAL(buf1, pathname, buf1, EXIT1); diff --git a/testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_106.cpp b/testsuites/unittest/fs/jffs/full/it_test_fs_jffs_106.cpp similarity index 85% rename from testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_106.cpp rename to testsuites/unittest/fs/jffs/full/it_test_fs_jffs_106.cpp index 47723827..202b3ecc 100644 --- a/testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_106.cpp +++ b/testsuites/unittest/fs/jffs/full/it_test_fs_jffs_106.cpp @@ -28,7 +28,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "It_fs_jffs.h" +#include "It_vfs_jffs.h" #define TEST_STR "abcdefghijk" @@ -41,20 +41,30 @@ static int TestCase(void) CHAR buf[JFFS_STANDARD_NAME_LENGTH] = TEST_STR; CHAR str[JFFS_STANDARD_NAME_LENGTH] = ""; FILE *ptr = NULL; - fd = open(pathname1, O_CREAT | O_RDWR, 0777); + + fd = open(pathname1, O_CREAT, 0777); ICUNIT_GOTO_NOT_EQUAL(fd, -1, fd, EXIT); - len = write(fd, buf, JFFS_STANDARD_NAME_LENGTH); - ICUNIT_GOTO_NOT_EQUAL(len, -1, len, EXIT); + ret = close(fd); ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT1); - ptr = freopen(pathname1, "rb", stdin); + + ptr = freopen(pathname1, "w+", stdin); ICUNIT_GOTO_NOT_EQUAL(ptr, NULL, ptr, EXIT1); - ret = scanf_s("%s", JFFS_STANDARD_NAME_LENGTH, str); - ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT1); - ret = strcmp(buf, str); + + ret = fwrite(buf, JFFS_STANDARD_NAME_LENGTH, 1, ptr); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT1); + + ret = fclose(ptr); ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); - fclose(ptr); + fd = open(pathname1, O_RDWR, 0777); + ret = read(fd, str, JFFS_STANDARD_NAME_LENGTH); + + ret = close(fd); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT1); + + ret = strcmp(buf, str); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); ret = unlink(pathname1); ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); diff --git a/testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_112.cpp b/testsuites/unittest/fs/jffs/full/it_test_fs_jffs_112.cpp similarity index 99% rename from testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_112.cpp rename to testsuites/unittest/fs/jffs/full/it_test_fs_jffs_112.cpp index f9739353..8782e61a 100644 --- a/testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_112.cpp +++ b/testsuites/unittest/fs/jffs/full/it_test_fs_jffs_112.cpp @@ -28,7 +28,7 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "It_fs_jffs.h" +#include "It_vfs_jffs.h" static int TestCase(void) { diff --git a/testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_113.cpp b/testsuites/unittest/fs/jffs/full/it_test_fs_jffs_113.cpp similarity index 98% rename from testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_113.cpp rename to testsuites/unittest/fs/jffs/full/it_test_fs_jffs_113.cpp index 1e65fc74..1f92e148 100644 --- a/testsuites/unittest/fs/jffs/smoke/it_test_fs_jffs_113.cpp +++ b/testsuites/unittest/fs/jffs/full/it_test_fs_jffs_113.cpp @@ -28,15 +28,15 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "It_fs_jffs.h" +#include "It_vfs_jffs.h" +#include static FILE *g_filep; #define NUM 64 #define COUNT 10 -void *DoChild() +void *DoChild(void *) { - int fd = 0; int ret, count; char buf[NUM]; diff --git a/testsuites/unittest/fs/jffs/vfs_jffs_test.cpp b/testsuites/unittest/fs/jffs/vfs_jffs_test.cpp index 8010040b..57fd4d93 100644 --- a/testsuites/unittest/fs/jffs/vfs_jffs_test.cpp +++ b/testsuites/unittest/fs/jffs/vfs_jffs_test.cpp @@ -1043,6 +1043,28 @@ HWTEST_F(VfsJffsTest, ItTestFsJffs004, TestSize.Level0) ItTestFsJffs004(); } +/* * + * @tc.name: ItTestFsJffs100 + * @tc.desc: function for VfsJffsTest + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(VfsJffsTest, ItTestFsJffs100, TestSize.Level0) +{ + ItTestFsJffs100(); +} + +/* * + * @tc.name: ItTestFsJffs101 + * @tc.desc: function for VfsJffsTest + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(VfsJffsTest, ItTestFsJffs101, TestSize.Level0) +{ + ItTestFsJffs101(); +} + /* * * @tc.name: ItTestFsJffs102 * @tc.desc: function for VfsJffsTest @@ -1064,6 +1086,40 @@ HWTEST_F(VfsJffsTest, ItTestFsJffs103, TestSize.Level0) { ItTestFsJffs103(); } + +/* * + * @tc.name: ItTestFsJffs106 + * @tc.desc: function for VfsJffsTest + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(VfsJffsTest, ItTestFsJffs106, TestSize.Level0) +{ + ItTestFsJffs106(); +} + +/* * + * @tc.name: ItTestFsJffs112 + * @tc.desc: function for VfsJffsTest + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(VfsJffsTest, ItTestFsJffs112, TestSize.Level0) +{ + ItTestFsJffs112(); +} + +/* * + * @tc.name: ItTestFsJffs113 + * @tc.desc: function for VfsJffsTest + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(VfsJffsTest, ItTestFsJffs113, TestSize.Level0) +{ + ItTestFsJffs113(); +} + /* * * @tc.name: IT_JFFS_002 * @tc.desc: function for VfsJffsTest