5 void assert_exit_yaffs(char *fun_name, int fun_return_value){
6 if (fun_return_value < 0) {
7 printf("yaffs command: %s failed with error code %d \n", fun_name, fun_return_value);
8 int error_code = yaffsfs_GetLastError();
9 printf("error code is: %d, which is %s\n", error_code, yaffs_error_to_str(error_code));
10 printf("exiting program now\n");
18 assert_exit_yaffs("yaffs_mount", yaffs_mount(YAFFS_MOUNT_POINT));
23 int shared_create(int argc, char *argv[]){
26 printf("wrong number of arguments\n");
27 printf("requires $ create file_name time\n");
32 char *file_path = argv[1];
33 int handle = yaffs_open(file_path, O_CREAT | O_RDWR, S_IREAD |S_IWRITE);
34 assert_exit_yaffs ( "yaffs_open", handle);
36 assert_exit_yaffs ( "yaffs_close", yaffs_close(handle));
40 uint time = atoi(argv[2]);
42 struct yaffs_utimbuf new_times;
43 new_times.actime = time;
44 int ret = yaffs_utime(file_path, &new_times);
45 assert_exit_yaffs("yaffs_utime", ret);
47 assert_exit_yaffs("yaffs_unmount", yaffs_unmount(YAFFS_MOUNT_POINT));
51 int shared_validate_file(int argc, char *argv[]){
54 printf("wrong number of arguments\n");
55 printf("requires $ create file_name time\n");
60 char *file_path = argv[1];
61 int handle = yaffs_open(file_path, O_RDWR, S_IREAD |S_IWRITE);
62 assert_exit_yaffs ( "yaffs_open", handle);
64 //assert the file is the correct size and has the correct time.
65 uint expected_time = atoi(argv[2]);
66 struct yaffs_stat stat;
67 assert_exit_yaffs ( "yaffs_stat", yaffs_stat(file_path, &stat));
68 assert_exit_yaffs ( "yaffs_close", yaffs_close(handle));
69 if (stat.yst_atime != expected_time) {
70 printf("stat time is different from expected time\n");
73 assert_exit_yaffs("yaffs_unmount", yaffs_unmount(YAFFS_MOUNT_POINT));