fix: add fchmod api
add fchmod api and testcases Change-Id: I310e9e9d79bbe3fa8dbab6080bbfce8a77b79bb3 Signed-off-by: wcc0 <917033401@qq.com>
This commit is contained in:
parent
76507c05a8
commit
2f214bf4de
|
@ -2268,6 +2268,34 @@ OUT:
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SysFchmod(int fd, mode_t mode)
|
||||
{
|
||||
int ret;
|
||||
int sysFd;
|
||||
struct IATTR attr = {
|
||||
.attr_chg_mode = mode,
|
||||
.attr_chg_valid = CHG_MODE, /* change mode */
|
||||
};
|
||||
struct file *file = NULL;
|
||||
|
||||
sysFd = GetAssociatedSystemFd(fd);
|
||||
if (sysFd < 0) {
|
||||
return -EBADF;
|
||||
}
|
||||
|
||||
ret = fs_getfilep(sysFd, &file);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
ret = chattr(file->f_path, &attr);
|
||||
if (ret < 0) {
|
||||
return -get_errno();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysFchownat(int fd, const char *path, uid_t owner, gid_t group, int flag)
|
||||
{
|
||||
int ret;
|
||||
|
|
|
@ -234,6 +234,7 @@ extern int SysExecve(const char *fileName, char *const *argv, char *const *envp)
|
|||
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);
|
||||
extern int SysFchmod(int fd, mode_t mode);
|
||||
extern int SysChmod(const char *path, mode_t mode);
|
||||
extern int SysFchownat(int fd, const char *path, uid_t owner, gid_t group, int flag);
|
||||
extern int SysFchown(int fd, uid_t owner, gid_t group);
|
||||
|
|
|
@ -50,6 +50,7 @@ SYSCALL_HAND_DEF(__NR_sysinfo, SysInfo, 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)
|
||||
SYSCALL_HAND_DEF(__NR_fchmod, SysFchmod, int, ARG_NUM_2)
|
||||
SYSCALL_HAND_DEF(__NR_utimensat, SysUtimensat, int, ARG_NUM_4)
|
||||
SYSCALL_HAND_DEF(__NR_chmod, SysChmod, int, ARG_NUM_2)
|
||||
SYSCALL_HAND_DEF(__NR_lseek, SysLseek, off_t, ARG_NUM_7) /* current only support 32bit max 4G file */
|
||||
|
|
|
@ -211,6 +211,8 @@ 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_jffs_001.cpp",
|
||||
"jffs/full/It_jffs_002.cpp",
|
||||
"jffs/full/It_jffs_003.cpp",
|
||||
|
|
|
@ -271,6 +271,8 @@ void ItTestFsJffs001(void);
|
|||
void ItTestFsJffs002(void);
|
||||
void ItTestFsJffs003(void);
|
||||
void ItTestFsJffs004(void);
|
||||
void ItTestFsJffs102(void);
|
||||
void ItTestFsJffs103(void);
|
||||
VOID ItJffs001(VOID);
|
||||
VOID ItJffs002(VOID);
|
||||
VOID ItJffs003(VOID);
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -37,13 +37,85 @@ static int TestCase(void)
|
|||
INT32 fd = 0;
|
||||
INT32 ret = JFFS_IS_ERROR;
|
||||
CHAR pathname1[TEST_STRLEN] = JFFS_PATH_NAME0;
|
||||
struct stat info = {0};
|
||||
|
||||
fd = open(pathname1, O_NONBLOCK | O_CREAT | O_EXCL, 0777);
|
||||
fd = open(pathname1, O_NONBLOCK | O_CREAT | O_RDWR | O_EXCL, 0777);
|
||||
ICUNIT_GOTO_NOT_EQUAL(fd, -1, fd, EXIT1);
|
||||
|
||||
ret = fchmod(fd, S_IREAD);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
|
||||
/* EBADF */
|
||||
ret = fchmod(-1, S_IREAD);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EBADF, ret, EXIT1);
|
||||
|
||||
/* S_IRWXU */
|
||||
ret = fchmod(fd, S_IRWXU);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
|
||||
stat(pathname1, &info);
|
||||
ret = info.st_mode & S_IRWXU;
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
/* S_IRUSR */
|
||||
ret = fchmod(fd, S_IRUSR);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
|
||||
stat(pathname1, &info);
|
||||
ret = info.st_mode & S_IRUSR;
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
/* S_IWUSR */
|
||||
ret = fchmod(fd, S_IWUSR);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
|
||||
stat(pathname1, &info);
|
||||
ret = info.st_mode & S_IWUSR;
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
/* S_IXUSR */
|
||||
ret = fchmod(fd, S_IXUSR);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
|
||||
stat(pathname1, &info);
|
||||
ret = info.st_mode & S_IXUSR;
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
/* S_IRWXG */
|
||||
ret = fchmod(fd, S_IRWXG);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
|
||||
stat(pathname1, &info);
|
||||
ret = info.st_mode & S_IRWXG;
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
/* SIRGRP */
|
||||
ret = fchmod(fd, S_IRGRP);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
|
||||
stat(pathname1, &info);
|
||||
ret = info.st_mode & S_IRGRP;
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
/* S_IXGRP */
|
||||
ret = fchmod(fd, S_IXGRP);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
|
||||
stat(pathname1, &info);
|
||||
ret = info.st_mode & S_IXGRP;
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
/* S_IRWXO */
|
||||
ret = fchmod(fd, S_IRWXO);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
|
||||
stat(pathname1, &info);
|
||||
ret = info.st_mode &S_IRWXO;
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
/* S_IROTH */
|
||||
ret = fchmod(fd, S_IROTH);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
|
||||
stat(pathname1, &info);
|
||||
ret = info.st_mode & S_IROTH;
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
/* S_IXOTH */
|
||||
ret = fchmod(fd, S_IXOTH);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
|
||||
stat(pathname1, &info);
|
||||
ret = info.st_mode & S_IXOTH;
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT);
|
||||
ret = close(fd);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
|
||||
|
|
@ -28,8 +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
|
||||
|
||||
|
@ -41,6 +40,8 @@ static int TestCase(void)
|
|||
CHAR pathname0[TEST_STRLEN] = JFFS_PATH_NAME0;
|
||||
CHAR pathname1[TEST_STRLEN] = JFFS_PATH_NAME0;
|
||||
CHAR pathname2[TEST_STRLEN] = JFFS_PATH_NAME0;
|
||||
CHAR pathname3[TEST_STRLEN] = JFFS_PATH_NAME01;
|
||||
CHAR filebuf[256] = "abcdeab89abcedcde01234567fghij9876543210abcdeabc89abcedfghde0123456710abcdeabcde012876543289abcedfghij987654345673210abcdeabcde0123456789abcedfghij9876543210abcdeabcde0123456789abcedfg10abcdeahij9876543289abcedfghlbcde01234567I0lalalalalalalal";
|
||||
struct stat info = {0};
|
||||
|
||||
ret = mkdir(pathname0, 0777);
|
||||
|
@ -60,16 +61,54 @@ static int TestCase(void)
|
|||
dirfd = open(pathname0, O_DIRECTORY);
|
||||
ICUNIT_GOTO_NOT_EQUAL(dirfd, JFFS_IS_ERROR, dirfd, EXIT);
|
||||
|
||||
ret = fchmodat(fd, "test1", S_IREAD, 0);
|
||||
/* ENAMETOOLONG */
|
||||
ret = fchmodat(dirfd, filebuf, S_IREAD, 0);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, ENAMETOOLONG, ret, EXIT);
|
||||
|
||||
/* ENOENT */
|
||||
ret = fchmodat(-1, "test1", S_IREAD, 0);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, ENOENT, ret, EXIT);
|
||||
|
||||
/* EINVAL */
|
||||
ret = fchmodat(dirfd, NULL, S_IREAD, 0);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
|
||||
|
||||
/* absolute path */
|
||||
ret = fchmodat(0, pathname1, S_IRUSR | S_IWUSR | S_IXUSR, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
|
||||
|
||||
stat(pathname1, &info);
|
||||
ret = info.st_mode & S_IREAD;
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT);
|
||||
ret = info.st_mode & (S_IRUSR | S_IWUSR | S_IXUSR);
|
||||
ICUNIT_GOTO_EQUAL(ret, (S_IRUSR | S_IWUSR | S_IXUSR), ret, EXIT);
|
||||
|
||||
/* S_IRUSR | S_IWUSR | S_IXUSR */
|
||||
ret = fchmodat(dirfd, "test1", S_IRUSR | S_IWUSR | S_IXUSR, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
|
||||
stat(pathname1, &info);
|
||||
ret = info.st_mode & (S_IRUSR | S_IWUSR | S_IXUSR);
|
||||
ICUNIT_GOTO_EQUAL(ret, (S_IRUSR | S_IWUSR | S_IXUSR), ret, EXIT);
|
||||
|
||||
/* AT_FDCWD */
|
||||
ret = fchmodat(AT_FDCWD, "test/test1", S_IRUSR | S_IWUSR | S_IXUSR, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
|
||||
stat(pathname1, &info);
|
||||
ret = info.st_mode & (S_IRUSR | S_IWUSR | S_IXUSR);
|
||||
ICUNIT_GOTO_EQUAL(ret, (S_IRUSR | S_IWUSR | S_IXUSR), ret, EXIT);
|
||||
ret = close(dirfd);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
|
||||
|
||||
/* ENOTDIR */
|
||||
dirfd = open(pathname3, O_NONBLOCK | O_CREAT | O_RDWR | O_EXCL, 0777);
|
||||
ICUNIT_GOTO_NOT_EQUAL(fd, JFFS_IS_ERROR, fd, EXIT);
|
||||
ret = fchmodat(dirfd, "test1", S_IROTH | S_IWOTH | S_IXOTH, 0);
|
||||
ret = errno;
|
||||
ICUNIT_GOTO_EQUAL(ret, ENOTDIR, ret, EXIT);
|
||||
ret = close(dirfd);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
|
||||
ret = remove(pathname3);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
|
||||
ret = rmdir(pathname1);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
|
||||
|
||||
|
@ -85,17 +124,15 @@ static int TestCase(void)
|
|||
|
||||
stat(pathname2, &info);
|
||||
ret = info.st_mode & (S_IRUSR | S_IRGRP | S_IROTH);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
ICUNIT_GOTO_EQUAL(ret, (S_IRUSR | S_IRGRP | S_IROTH), ret, EXIT);
|
||||
ret = close(fd);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
|
||||
|
||||
ret = fchmodat(dirfd, "test.txt", S_IREAD, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT1);
|
||||
|
||||
ret = fchmodat(dirfd, "test.txt", S_IRUSR | S_IWUSR | S_IXUSR, 0);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
|
||||
stat(pathname2, &info);
|
||||
ret = info.st_mode & S_IREAD;
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT);
|
||||
ret = info.st_mode & (S_IRUSR | S_IWUSR | S_IXUSR);
|
||||
ICUNIT_GOTO_EQUAL(ret, (S_IRUSR | S_IWUSR | S_IXUSR), ret, EXIT);
|
||||
|
||||
ret = close(dirfd);
|
||||
ICUNIT_GOTO_EQUAL(ret, JFFS_NO_ERROR, ret, EXIT);
|
||||
|
@ -114,6 +151,7 @@ EXIT1:
|
|||
close(fd);
|
||||
}
|
||||
EXIT:
|
||||
remove(pathname3);
|
||||
remove(pathname2);
|
||||
remove(pathname1);
|
||||
remove(pathname0);
|
|
@ -1043,6 +1043,27 @@ HWTEST_F(VfsJffsTest, ItTestFsJffs004, TestSize.Level0)
|
|||
ItTestFsJffs004();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: ItTestFsJffs102
|
||||
* @tc.desc: function for VfsJffsTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(VfsJffsTest, ItTestFsJffs102, TestSize.Level0)
|
||||
{
|
||||
ItTestFsJffs102();
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: ItTestFsJffs103
|
||||
* @tc.desc: function for VfsJffsTest
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000EEMQ9
|
||||
*/
|
||||
HWTEST_F(VfsJffsTest, ItTestFsJffs103, TestSize.Level0)
|
||||
{
|
||||
ItTestFsJffs103();
|
||||
}
|
||||
/* *
|
||||
* @tc.name: IT_JFFS_002
|
||||
* @tc.desc: function for VfsJffsTest
|
||||
|
|
Loading…
Reference in New Issue