From 61598093bbdd283a7edc367d900f223070ead8d2 Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Fri, 10 May 2024 07:43:03 +0000
Subject: [PATCH] add ax88772C AX88772C_eeprom_tools
---
kernel/tools/testing/selftests/filesystems/incfs/utils.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 92 insertions(+), 8 deletions(-)
diff --git a/kernel/tools/testing/selftests/filesystems/incfs/utils.c b/kernel/tools/testing/selftests/filesystems/incfs/utils.c
index e194f63..0411d91 100644
--- a/kernel/tools/testing/selftests/filesystems/incfs/utils.c
+++ b/kernel/tools/testing/selftests/filesystems/incfs/utils.c
@@ -25,6 +25,45 @@
#define __S_IFREG S_IFREG
#endif
+unsigned int rnd(unsigned int max, unsigned int *seed)
+{
+ return rand_r(seed) * ((uint64_t)max + 1) / RAND_MAX;
+}
+
+int remove_dir(const char *dir)
+{
+ int err = rmdir(dir);
+
+ if (err && errno == ENOTEMPTY) {
+ err = delete_dir_tree(dir);
+ if (err)
+ return err;
+ return 0;
+ }
+
+ if (err && errno != ENOENT)
+ return -errno;
+
+ return 0;
+}
+
+int drop_caches(void)
+{
+ int drop_caches =
+ open("/proc/sys/vm/drop_caches", O_WRONLY | O_CLOEXEC);
+ int i;
+
+ if (drop_caches == -1)
+ return -errno;
+ i = write(drop_caches, "3", 1);
+ close(drop_caches);
+
+ if (i != 1)
+ return -errno;
+
+ return 0;
+}
+
int mount_fs(const char *mount_dir, const char *backing_dir,
int read_timeout_ms)
{
@@ -77,6 +116,9 @@
size_t size = sizeof(struct signature_blob) + strlen(add_data) + 1;
struct signature_blob *sb = malloc(size);
+ if (!sb)
+ return 0;
+
*sb = (struct signature_blob){
.version = INCFS_SIGNATURE_VERSION,
.hash_section_size = sizeof(struct hash_section),
@@ -87,7 +129,7 @@
.salt_size = 0,
.hash_size = SHA256_DIGEST_SIZE,
},
- .signing_section_size = sizeof(uint32_t) + strlen(add_data) + 1,
+ .signing_section_size = strlen(add_data) + 1,
};
memcpy(sb->hash_section.hash, root_hash, SHA256_DIGEST_SIZE);
@@ -195,14 +237,28 @@
int open_log_file(const char *mount_dir)
{
- char cmd_file[255];
- int cmd_fd;
+ char file[255];
+ int fd;
- snprintf(cmd_file, ARRAY_SIZE(cmd_file), "%s/.log", mount_dir);
- cmd_fd = open(cmd_file, O_RDWR | O_CLOEXEC);
- if (cmd_fd < 0)
+ snprintf(file, ARRAY_SIZE(file), "%s/.log", mount_dir);
+ fd = open(file, O_RDWR | O_CLOEXEC);
+ if (fd < 0)
perror("Can't open log file");
- return cmd_fd;
+ return fd;
+}
+
+int open_blocks_written_file(const char *mount_dir)
+{
+ char file[255];
+ int fd;
+
+ snprintf(file, ARRAY_SIZE(file),
+ "%s/%s", mount_dir, INCFS_BLOCKS_WRITTEN_FILENAME);
+ fd = open(file, O_RDONLY | O_CLOEXEC);
+
+ if (fd < 0)
+ perror("Can't open blocks_written file");
+ return fd;
}
int wait_for_pending_reads(int fd, int timeout_ms,
@@ -233,7 +289,35 @@
return read_res / sizeof(*prs);
}
-char *concat_file_name(const char *dir, char *file)
+int wait_for_pending_reads2(int fd, int timeout_ms,
+ struct incfs_pending_read_info2 *prs, int prs_count)
+{
+ ssize_t read_res = 0;
+
+ if (timeout_ms > 0) {
+ int poll_res = 0;
+ struct pollfd pollfd = {
+ .fd = fd,
+ .events = POLLIN
+ };
+
+ poll_res = poll(&pollfd, 1, timeout_ms);
+ if (poll_res < 0)
+ return -errno;
+ if (poll_res == 0)
+ return 0;
+ if (!(pollfd.revents | POLLIN))
+ return 0;
+ }
+
+ read_res = read(fd, prs, prs_count * sizeof(*prs));
+ if (read_res < 0)
+ return -errno;
+
+ return read_res / sizeof(*prs);
+}
+
+char *concat_file_name(const char *dir, const char *file)
{
char full_name[FILENAME_MAX] = "";
--
Gitblit v1.6.2