Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closer dkP r33 support #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.o
*.d
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
endif

.SUFFIXES:
Expand All @@ -11,7 +11,8 @@ SOURCES = source
BUILD = build

CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE)
LDFLAGS = -L$(LIBOGC_LIB) -lntfs -lseeprom -lotp -lisfs -lnandimg -lfst -lwod -liso -ldi -lwiiuse -lbte -lfat -logc -lm -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80a00000
LDFLAGS = -L$(LIBOGC_LIB) -L$(PORTLIBS) -lntfs -lseeprom -lotp -lisfs -lnandimg -lfst -lwod -liso -ldi -lwiiuse -lbte -lfat -logc -lm \
-g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80a00000
PRELOADER_LDFLAGS = -L$(LIBOGC_LIB) -logc -g $(MACHDEP) -Wl,-Map,$(notdir $@).map

ifneq ($(BUILD),$(notdir $(CURDIR)))
Expand All @@ -23,7 +24,7 @@ export LD := $(CC)

export OFILES := reset.o dvd.o pad.o net.o fs.o ftp.o loader.o vrt.o dol.o ftpii.o
export PRELOADER_OFILES := _$(TARGET).dol.o dol.o preloader.o
export INCLUDE := -I$(CURDIR)/$(BUILD) -I$(LIBOGC_INC)
export INCLUDE := -I$(CURDIR)/$(BUILD) -I$(LIBOGC_INC) -I$(PORTLIBS)/include/

.PHONY: $(BUILD) clean run

Expand Down
13 changes: 7 additions & 6 deletions source/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ misrepresented as being the original software.

#define CACHE_PAGES 8
#define CACHE_SECTORS_PER_PAGE 64
#define MAXPATHLEN 128

VIRTUAL_PARTITION VIRTUAL_PARTITIONS[] = {
{ "SD Gecko A", "/carda", "carda", "carda:/", false, false, &__io_gcsda },
Expand Down Expand Up @@ -98,7 +99,7 @@ static bool is_dvd(VIRTUAL_PARTITION *partition) {
}

bool mounted(VIRTUAL_PARTITION *partition) {
DIR_ITER *dir = diropen(partition->prefix);
DIR *dir = _FAT_diropen_r(partition->prefix);
if (dir) {
dirclose(dir);
return true;
Expand Down Expand Up @@ -133,7 +134,7 @@ static u64 mount_timer = 0;

bool mount(VIRTUAL_PARTITION *partition) {
if (!partition || mounted(partition) || (is_dvd(partition) && dvd_mountWait())) return false;

bool success = false;
printf("Mounting %s...", partition->name);
if (is_dvd(partition)) {
Expand Down Expand Up @@ -245,7 +246,7 @@ void check_removable_devices(u64 now) {
}
}
}

device_check_timer = gettime() + secs_to_ticks(2);
}

Expand Down Expand Up @@ -318,9 +319,9 @@ void initialise_fs() {
This function is not thread-safe.
*/
char *dirname(char *path) {
static char result[MAXPATHLEN];
strncpy(result, path, MAXPATHLEN - 1);
result[MAXPATHLEN - 1] = '\0';
static char result[MAXNAMLEN];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why define MAXPATHLEN, and then switch usages to MAXNAMLEN? I haven't actually tried to build this new code...are we still using MAXPATHLEN for other things?

strncpy(result, path, MAXNAMLEN - 1);
result[MAXNAMLEN - 1] = '\0';
s32 i;
for (i = strlen(result) - 1; i >= 0; i--) {
if (result[i] == '/') {
Expand Down
21 changes: 11 additions & 10 deletions source/ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ misrepresented as being the original software.

#define FTP_BUFFER_SIZE 1024
#define MAX_CLIENTS 5
#define MAXPATHLEN 128

static const u16 SRC_PORT = 20;
static const s32 EQUIT = 696969;
Expand Down Expand Up @@ -356,7 +357,7 @@ static s32 prepare_data_connection_active(client_t *client, data_connection_call
net_close(data_socket);
return result;
}

client->data_socket = data_socket;
printf("Attempting to connect to client at %s:%u\n", inet_ntoa(client->address.sin_addr), ntohs(client->address.sin_port));
return 0;
Expand Down Expand Up @@ -387,7 +388,7 @@ static s32 prepare_data_connection(client_t *client, void *callback, void *arg,
return result;
}

static s32 send_nlst(s32 data_socket, DIR_ITER *dir) {
static s32 send_nlst(s32 data_socket, DIR *dir) {
s32 result = 0;
char filename[MAXPATHLEN + 2];
struct stat st;
Expand All @@ -403,7 +404,7 @@ static s32 send_nlst(s32 data_socket, DIR_ITER *dir) {
return result < 0 ? result : 0;
}

static s32 send_list(s32 data_socket, DIR_ITER *dir) {
static s32 send_list(s32 data_socket, DIR *dir) {
s32 result = 0;
char filename[MAXPATHLEN];
struct stat st;
Expand All @@ -424,7 +425,7 @@ static s32 ftp_NLST(client_t *client, char *path) {
path = ".";
}

DIR_ITER *dir = vrt_diropen(client->cwd, path);
DIR *dir = vrt_diropen(client->cwd, path);
if (dir == NULL) {
return write_reply(client, 550, strerror(errno));
}
Expand All @@ -447,7 +448,7 @@ static s32 ftp_LIST(client_t *client, char *path) {
path = ".";
}

DIR_ITER *dir = vrt_diropen(client->cwd, path);
DIR *dir = vrt_diropen(client->cwd, path);
if (dir == NULL) {
return write_reply(client, 550, strerror(errno));
}
Expand Down Expand Up @@ -584,7 +585,7 @@ typedef s32 (*ftp_command_handler)(client_t *client, char *args);
static s32 dispatch_to_handler(client_t *client, char *cmd_line, const char **commands, const ftp_command_handler *handlers) {
char cmd[FTP_BUFFER_SIZE], rest[FTP_BUFFER_SIZE];
char *args[] = { cmd, rest };
split(cmd_line, ' ', 1, args);
split(cmd_line, ' ', 1, args);
s32 i;
for (i = 0; commands[i]; i++) {
if (!strcasecmp(commands[i], cmd)) break;
Expand Down Expand Up @@ -815,7 +816,7 @@ static void process_control_events(client_t *client) {
}
client->offset += bytes_read;
client->buf[client->offset] = '\0';

if (strchr(offset_buf, '\0') != (client->buf + client->offset)) {
printf("Received a null byte from client, closing connection ;-)\n"); // i have decided this isn't allowed =P
goto recv_loop_end;
Expand All @@ -829,7 +830,7 @@ static void process_control_events(client_t *client) {
printf("Received a line-feed from client without preceding carriage return, closing connection ;-)\n"); // i have decided this isn't allowed =P
goto recv_loop_end;
}

if (*next) {
s32 result;
if ((result = process_command(client, next)) < 0) {
Expand All @@ -839,9 +840,9 @@ static void process_control_events(client_t *client) {
goto recv_loop_end;
}
}

}

if (next != client->buf) { // some lines were processed
client->offset = strlen(next);
char tmp_buf[client->offset];
Expand Down
2 changes: 0 additions & 2 deletions source/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ void load_from_file(FILE *f, char *arg) {
argv.argv = &argv.commandLine;
argv.endARGV = argv.argv + 1;

struct stat st;
int fd = fileno(f);
if (fstat(fd, &st)) return;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to remove this? I can't remember, but assume it was probably there for a reason :/

u8 *buf = (u8 *)0x92000000;
if (!read_from_file(buf, f)) return;

Expand Down
10 changes: 5 additions & 5 deletions source/vrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static char *virtual_abspath(char *virtual_cwd, char *virtual_path) {
strcpy(path, virtual_cwd);
strcat(path, virtual_path);
}

char *normalised_path = malloc(strlen(path) + 1);
if (!normalised_path) goto end;
*normalised_path = '\0';
Expand Down Expand Up @@ -141,7 +141,7 @@ char *to_real_path(char *virtual_cwd, char *virtual_path) {
errno = ENODEV;
goto end;
}

size_t real_path_size = strlen(prefix) + strlen(rest) + 1;
if (real_path_size > MAXPATHLEN) goto end;

Expand All @@ -160,7 +160,7 @@ typedef void * (*path_func)(char *path, ...);
static void *with_virtual_path(void *virtual_cwd, void *void_f, char *virtual_path, s32 failed, ...) {
char *path = to_real_path(virtual_cwd, virtual_path);
if (!path || !*path) return (void *)failed;

path_func f = (path_func)void_f;
va_list ap;
void *args[3];
Expand All @@ -172,7 +172,7 @@ static void *with_virtual_path(void *virtual_cwd, void *void_f, char *virtual_pa
args[num_args++] = arg;
} while (1);
va_end(ap);

void *result;
switch (num_args) {
case 0: result = f(path); break;
Expand All @@ -181,7 +181,7 @@ static void *with_virtual_path(void *virtual_cwd, void *void_f, char *virtual_pa
case 3: result = f(path, args[0], args[1], args[2]); break;
default: result = (void *)failed;
}

free(path);
return result;
}
Expand Down
6 changes: 3 additions & 3 deletions source/vrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ int vrt_chdir(char *cwd, char *path);
int vrt_unlink(char *cwd, char *path);
int vrt_mkdir(char *cwd, char *path, mode_t mode);
int vrt_rename(char *cwd, char *from_path, char *to_path);
DIR_ITER *vrt_diropen(char *cwd, char *path);
int vrt_dirnext(DIR_ITER *iter, char *filename, struct stat *st);
int vrt_dirclose(DIR_ITER *iter);
DIR *vrt_diropen(char *cwd, char *path);
int vrt_dirnext(DIR *iter, char *filename, struct stat *st);
int vrt_dirclose(DIR *iter);

#endif /* _VRT_H_ */