Changeset 4a998bf9 in mainline
- Timestamp:
- 2026-03-17T12:36:58Z (22 hours ago)
- Children:
- 7c2a3c7
- Parents:
- 7956257
- git-author:
- Vít Skalický <skalicky@…> (2026-03-12 10:44:21)
- git-committer:
- Vít Skalický <skalicky@…> (2026-03-17 12:36:58)
- File:
-
- 1 edited
-
uspace/app/cmpdirs/cmpdirs.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/cmpdirs/cmpdirs.c
r7956257 r4a998bf9 46 46 #include <str_error.h> 47 47 #include <io/log.h> 48 #include <io/logctl.h> 48 49 49 50 #define NAME "cmpdirs" … … 108 109 rc = log_init(NAME); 109 110 if (rc != EOK) goto close_end; 111 logctl_set_log_level(NAME, LVL_DEBUG2); 110 112 111 113 // lookup both directories … … 114 116 rc = vfs_lookup(argv[0], 0, &handle1); 115 117 check_ok(rc, close_end, "Failed to lookup \"%s\"\n", argv[0]); 118 log_msg(LOG_DEFAULT, LVL_DEBUG2, "fd of \"%s\" is %d", argv[0], handle1); 116 119 rc = vfs_lookup(argv[1], 0, &handle2); 117 120 check_ok(rc, close1, "Failed to lookup \"%s\"\n", argv[1]); 121 log_msg(LOG_DEFAULT, LVL_DEBUG2, "fd of \"%s\" is %d", argv[1], handle2); 118 122 119 123 bool equal; … … 338 342 // 3. lookup it in handle2 339 343 // 4. add both new handles to stack 340 // 5. iterate again over entries of handel2 -> gives you entry name341 // 6. try to look it up in handle1 jut to check that it exists342 343 // 5. and 6. are probably redundant, since the sizes of both directories must be equal.344 344 345 345 for (ssize_t pos = 0; 346 346 ((size_t) pos) < stat1.size; 347 pos++) {347 ) { 348 348 // 1. 349 349 ssize_t read; 350 350 rc = list_dir(item.handle1, pos, NAME_BUFFER_SIZE, name_buffer, &read); 351 351 log_msg(LOG_DEFAULT, LVL_DEBUG2, "Read directory entry name: result %s, read size: %"PRIdn".", str_error_name(rc), read); 352 check_ok_break(rc, "Failed to list handle %d\n", item.handle1); 352 check_ok_break(rc, "Failed (1) to list handle %d, pos %"PRIdn", total size of directory: %"PRIu64"\n", item.handle1, pos, stat1.size); 353 // Calculate the real length of the entry name (excluding null-terminator) 354 size_t name_size = str_nsize(name_buffer, NAME_BUFFER_SIZE); 353 355 // check that the string is null-terminated before the end of the buffer 354 if ( str_nsize(name_buffer, NAME_BUFFER_SIZE)>= NAME_BUFFER_SIZE) {356 if (name_size >= NAME_BUFFER_SIZE) { 355 357 rc = ENAMETOOLONG; 356 358 } 357 359 check_ok_break(rc, "Name too long (limit is %d excluding null-terminator)", NAME_BUFFER_SIZE); 360 // advance pos to after the name of the entry (add 1 for null-terminator) 361 pos += read; // NOLINT(*-narrowing-conversions) because name_size < NAME_BUFFER_SIZE 362 log_msg(LOG_DEFAULT, LVL_DEBUG2, "Listed %d: pos %"PRIdn", name: %s\n", item.handle1, pos, name_buffer); 358 363 // 2. 359 364 int entry_handle1; // don't forget to put … … 386 391 } 387 392 if (rc != EOK) goto close_inner; 388 389 // 5.390 for (ssize_t pos = 0;391 ((size_t) pos) < stat2.size; // must be equal to stat1.size anyway392 pos++) {393 // 5.394 ssize_t read;395 rc = list_dir(item.handle2, pos, NAME_BUFFER_SIZE, name_buffer, &read);396 log_msg(LOG_DEFAULT, LVL_DEBUG2, "Read directory entry name: result %s, read size: %"PRIdn".", str_error_name(rc), read);397 check_ok_break(rc, "Failed to list handle %d\n", item.handle2);398 // check that the string is null-terminated before the end of the buffer399 if (str_nsize(name_buffer, NAME_BUFFER_SIZE) >= NAME_BUFFER_SIZE) {400 rc = ENAMETOOLONG;401 }402 check_ok_break(rc, "Name too long (limit is %d excluding null-terminator)", NAME_BUFFER_SIZE);403 // 6.404 int entry_handle; // don't forget to put405 rc = vfs_walk(item.handle1, name_buffer, 0, &entry_handle);406 errno_t rc2 = vfs_put(entry_handle);407 (void) rc2; // if put failed, I guess there is nothing I can do about it408 if (rc != EOK) {409 if (rc == ENOENT) { // todo is ENOENT the correct one?410 rc = EOK;411 equal = false;412 break;413 }414 check_ok_break(rc, "(2) Failed to find entry \"%s\" in directory of handle %d\n", name_buffer, item.handle1);415 }416 }417 if (rc != EOK) goto close_inner;418 393 } 419 394
Note:
See TracChangeset
for help on using the changeset viewer.
