|
580 | 580 | return ps2link_response_rmdir(result); |
581 | 581 | } |
582 | 582 |
|
| 583 | +int ps2link_request_getstat(void *packet) { |
| 584 | + struct { unsigned int number; unsigned short length; char name[256]; } PACKED *request = packet; |
| 585 | + struct stat stats; struct tm *loctime; |
| 586 | + int ret; |
| 587 | + unsigned int mode; unsigned char ctime[8]; unsigned char atime[8]; unsigned char mtime[8]; |
| 588 | + |
| 589 | + // Fix the arguments. |
| 590 | + fix_pathname(request->name); |
| 591 | + |
| 592 | + // Fetch the entry's statistics. |
| 593 | + ret = stat(request->name, &stats); |
| 594 | + |
| 595 | + if (ret == 0) { |
| 596 | + // Convert the mode. |
| 597 | + mode = (stats.st_mode & 0x07); |
| 598 | + if (S_ISDIR(stats.st_mode)) { mode |= 0x20; } |
| 599 | + #ifndef _WIN32 |
| 600 | + if (S_ISLNK(stats.st_mode)) { mode |= 0x08; } |
| 601 | + #endif |
| 602 | + if (S_ISREG(stats.st_mode)) { mode |= 0x10; } |
| 603 | + |
| 604 | + // Convert the creation time. |
| 605 | + loctime = localtime(&(stats.st_ctime)); |
| 606 | + ctime[6] = (unsigned char)loctime->tm_year; |
| 607 | + ctime[5] = (unsigned char)loctime->tm_mon + 1; |
| 608 | + ctime[4] = (unsigned char)loctime->tm_mday; |
| 609 | + ctime[3] = (unsigned char)loctime->tm_hour; |
| 610 | + ctime[2] = (unsigned char)loctime->tm_min; |
| 611 | + ctime[1] = (unsigned char)loctime->tm_sec; |
| 612 | + |
| 613 | + // Convert the access time. |
| 614 | + loctime = localtime(&(stats.st_atime)); |
| 615 | + atime[6] = (unsigned char)loctime->tm_year; |
| 616 | + atime[5] = (unsigned char)loctime->tm_mon + 1; |
| 617 | + atime[4] = (unsigned char)loctime->tm_mday; |
| 618 | + atime[3] = (unsigned char)loctime->tm_hour; |
| 619 | + atime[2] = (unsigned char)loctime->tm_min; |
| 620 | + atime[1] = (unsigned char)loctime->tm_sec; |
| 621 | + |
| 622 | + // Convert the last modified time. |
| 623 | + loctime = localtime(&(stats.st_mtime)); |
| 624 | + mtime[6] = (unsigned char)loctime->tm_year; |
| 625 | + mtime[5] = (unsigned char)loctime->tm_mon + 1; |
| 626 | + mtime[4] = (unsigned char)loctime->tm_mday; |
| 627 | + mtime[3] = (unsigned char)loctime->tm_hour; |
| 628 | + mtime[2] = (unsigned char)loctime->tm_min; |
| 629 | + mtime[1] = (unsigned char)loctime->tm_sec; |
| 630 | + } |
| 631 | + |
| 632 | + return ps2link_response_getstat(ret, mode, 0, stats.st_size, ctime, atime, mtime, 0); |
| 633 | + } |
| 634 | + |
583 | 635 | //////////////////////////////// |
584 | 636 | // PS2LINK RESPONSE FUNCTIONS // |
585 | 637 | //////////////////////////////// |
|
737 | 789 | return network_send(request_socket, &response, sizeof(response)); |
738 | 790 | } |
739 | 791 |
|
| 792 | +int ps2link_response_getstat(int result, unsigned int mode, unsigned int attr, unsigned int size, unsigned char *ctime, unsigned char *atime, unsigned char *mtime, unsigned int hisize) { |
| 793 | + struct { unsigned int number; unsigned short length; int result; unsigned int mode; unsigned int attr; unsigned int size; unsigned char ctime[8]; unsigned char atime[8]; unsigned char mtime[8]; unsigned int hisize; } PACKED response; |
| 794 | + |
| 795 | + // Build the response packet. |
| 796 | + response.number = htonl(PS2LINK_RESPONSE_GETSTAT); |
| 797 | + response.length = htons(sizeof(response)); |
| 798 | + response.result = htonl(result); |
| 799 | + response.mode = htonl(mode); |
| 800 | + response.attr = htonl(attr); |
| 801 | + response.size = htonl(size); |
| 802 | + if (ctime) { memcpy(response.ctime, ctime, 8); } |
| 803 | + if (atime) { memcpy(response.atime, atime, 8); } |
| 804 | + if (mtime) { memcpy(response.mtime, mtime, 8); } |
| 805 | + response.hisize = htonl(hisize); |
| 806 | + |
| 807 | + // Send the response packet. |
| 808 | + return network_send(request_socket, &response, sizeof(response)); |
| 809 | + } |
| 810 | + |
740 | 811 | ////////////////////////////// |
741 | 812 | // PS2LINK THREAD FUNCTIONS // |
742 | 813 | ////////////////////////////// |
|
801 | 872 | if (ntohl(packet.number) == PS2LINK_REQUEST_READDIR) { ps2link_request_readdir(&packet); } else |
802 | 873 | if (ntohl(packet.number) == PS2LINK_REQUEST_REMOVE) { ps2link_request_remove(&packet); } else |
803 | 874 | if (ntohl(packet.number) == PS2LINK_REQUEST_MKDIR) { ps2link_request_mkdir(&packet); } else |
804 | | - if (ntohl(packet.number) == PS2LINK_REQUEST_RMDIR) { ps2link_request_rmdir(&packet); } |
| 875 | + if (ntohl(packet.number) == PS2LINK_REQUEST_RMDIR) { ps2link_request_rmdir(&packet); } else |
| 876 | + if (ntohl(packet.number) == PS2LINK_REQUEST_GETSTAT) { ps2link_request_getstat(&packet); } |
805 | 877 |
|
806 | 878 | // Reset the timeout counter. |
807 | 879 | ps2link_counter = 0; |
|
0 commit comments