diff --git a/romfs/Makefile b/romfs/Makefile index 5f356169..5283b5ab 100644 --- a/romfs/Makefile +++ b/romfs/Makefile @@ -12,10 +12,7 @@ EE_OBJS += romfs.o romfs_io.o EE_OBJS := $(EE_OBJS:%=$(EE_OBJS_DIR)%) all: $(EE_OBJS_DIR) $(EE_LIB_DIR) $(EE_LIB) - -tools: tools/genromfs $(MAKE) -C tools/genromfs all - cp -f tools/genromfs/genromfs $(DESTDIR)$(PS2SDK)/bin/ $(EE_OBJS_DIR): mkdir -p $(EE_OBJS_DIR) @@ -32,6 +29,7 @@ install: all mkdir -p $(DESTDIR)$(PS2SDK)/ports/lib cp -f $(EE_LIB) $(DESTDIR)$(PS2SDK)/ports/lib cp -f include/*.h $(DESTDIR)$(PS2SDK)/ports/include/ + cp -f tools/genromfs/genromfs $(DESTDIR)$(PS2SDK)/bin/ clean: rm -f -r $(EE_OBJS_DIR) $(EE_LIB_DIR) diff --git a/romfs/tools/genromfs/Makefile b/romfs/tools/genromfs/Makefile index d278efc5..abb6e120 100644 --- a/romfs/tools/genromfs/Makefile +++ b/romfs/tools/genromfs/Makefile @@ -1,6 +1,12 @@ # Makefile for the genromfs program. +# Modified to build on MINGW +ifeq ($(OS), Windows_NT) + LDLIBS = -lshlwapi -lws2_32 +endif + + all: genromfs PACKAGE = genromfs @@ -21,7 +27,7 @@ bindir = $(prefix)/bin mandir = $(prefix)/man genromfs: genromfs.o - $(CC) $(LDFLAGS) genromfs.o -o genromfs + $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) .c.o: $(CC) $(CFLAGS) $< -c -o $@ diff --git a/romfs/tools/genromfs/genromfs.c b/romfs/tools/genromfs/genromfs.c index 9d05fdcc..9d23d678 100644 --- a/romfs/tools/genromfs/genromfs.c +++ b/romfs/tools/genromfs/genromfs.c @@ -57,21 +57,31 @@ * Sorry about that. Feel free to contact me if you have problems. */ +#ifdef __CYGWIN__ +#define _WIN32 +#endif + #include /* Userland pieces of the ANSI C standard I/O package */ #include /* Userland prototypes of the ANSI C std lib functions */ +#include #include /* Userland prototypes of the string handling funcs */ #include /* Userland prototypes of the Unix std system calls */ #include /* Flag value for file handling functions */ #include +#if defined (_WIN32) && !defined(__CYGWIN__) +#include +#include +#include +#define lstat stat +#else +#include /* Consts & structs defined by the internet system */ #include +#endif /* _WIN32 */ #include #include #include - -#include /* Consts & structs defined by the internet system */ - -/* good old times without autoconf... */ -#if defined(__linux__) || defined(__sun__) || defined(__CYGWIN__) +#include +#if defined(__linux__) || defined(__sun__) #include #endif @@ -193,7 +203,11 @@ int nodematch(char *pattern, struct filenode *node) char *start = node->name; /* XXX: ugly realbase is global */ if (pattern[0] == '/') start = node->realname + realbase; +#if defined(_WIN32) && !defined(__CYGWIN__) + return !PathMatchSpec(start, pattern); +#else return fnmatch(pattern,start,FNM_PATHNAME|FNM_PERIOD); +#endif } int findalign(struct filenode *node) @@ -284,7 +298,7 @@ void dumpri(struct romfh *ri, struct filenode *n, FILE *f) { int len; - len = strlen(n->name)+1; + len = strlen(n->name) + 1; memcpy(bigbuf, ri, sizeof(*ri)); memcpy(bigbuf+16, n->name, len); if (len&15) { @@ -299,13 +313,13 @@ void dumpri(struct romfh *ri, struct filenode *n, FILE *f) #if 0 fprintf(stderr, "RI: [at %06x] %08lx, %08lx, %08lx, %08lx [%s]\n", n->offset, - ntohl(ri->nextfh), ntohl(ri->spec), - ntohl(ri->size), ntohl(ri->checksum), + (long unsigned int)ntohl(ri->nextfh), (long unsigned int)ntohl(ri->spec), + (long unsigned int)ntohl(ri->size), (long unsigned int)ntohl(ri->checksum), n->name); #endif } -void dumpnode(struct filenode *node, FILE *f) +int dumpnode(struct filenode *node, FILE *f) { struct romfh ri; struct filenode *p; @@ -336,13 +350,19 @@ void dumpnode(struct filenode *node, FILE *f) ri.spec = htonl(node->dirlist.head->offset); } dumpri(&ri, node, f); - } else if (S_ISLNK(node->modes)) { + } +#if !defined(_WIN32) || defined(__CYGWIN__) + else if (S_ISLNK(node->modes)) { ri.nextfh |= htonl(ROMFH_LNK); dumpri(&ri, node, f); memset(bigbuf, 0, sizeof(bigbuf)); - readlink(node->realname, bigbuf, node->size); + if (readlink(node->realname, bigbuf, node->size) < 0) { + return 1; + } dumpdataa(bigbuf, node->size, f); - } else if (S_ISREG(node->modes)) { + } +#endif + else if (S_ISREG(node->modes)) { int offset, len, fd, max, avail; ri.nextfh |= htonl(ROMFH_REG); dumpri(&ri, node, f); @@ -372,7 +392,9 @@ void dumpnode(struct filenode *node, FILE *f) dumpdata(bigbuf, avail, f); offset+=avail; } - } else if (S_ISCHR(node->modes)) { + } +#if !defined(_WIN32) || defined(__CYGWIN__) + else if (S_ISCHR(node->modes)) { ri.nextfh |= htonl(ROMFH_CHR); ri.spec = htonl(major(node->devnode)<<16|minor(node->devnode)); dumpri(&ri, node, f); @@ -387,16 +409,19 @@ void dumpnode(struct filenode *node, FILE *f) ri.nextfh |= htonl(ROMFH_SCK); dumpri(&ri, node, f); } +#endif p = node->dirlist.head; while (p->next) { - dumpnode(p, f); + if(dumpnode(p, f)) { + return 1; + } p = p->next; } + return 0; } -void dumpall(struct filenode *node, int lastoff, FILE *f) -{ +int dumpall(struct filenode *node, int lastoff, FILE *f) { struct romfh ri; struct filenode *p; @@ -407,12 +432,16 @@ void dumpall(struct filenode *node, int lastoff, FILE *f) dumpri(&ri, node, f); p = node->dirlist.head; while (p->next) { - dumpnode(p, f); + if(dumpnode(p, f)) { + return 1; + } p = p->next; } /* Align the whole bunch to ROMBSIZE boundary */ if (lastoff&1023) dumpzero(1024-(lastoff&1023), f); + + return 0; } /* Node manipulating functions */ @@ -495,7 +524,11 @@ struct filenode *findnode(struct filenode *node, dev_t dev, ino_t ino) while (p->next) { found = findnode(p, dev, ino); if (found) +#if defined(_WIN32) && !defined (__CYGWIN__) + return NULL; +#else return found; +#endif p = p->next; } return NULL; @@ -579,14 +612,16 @@ int processdir(int level, const char *base, const char *dirname, struct stat *sb fprintf(stderr, "ignoring '%s' (lstat failed)\n", n->realname); freenode(n); continue; } - +#if !defined(_WIN32) || defined(__CYGWIN__) /* Handle special names */ if ( n->name[0] == '@' ) { if (S_ISLNK(sb->st_mode)) { /* this is a link to follow at build time */ n->name = n->name + 1; /* strip off the leading @ */ memset(bigbuf, 0, sizeof(bigbuf)); - readlink(n->realname, bigbuf, sizeof(bigbuf)); + if (readlink(n->realname, bigbuf, sizeof(bigbuf))) { + return -1; + } n->realname = strdup(bigbuf); if (lstat(n->realname, sb)) { @@ -628,13 +663,17 @@ int processdir(int level, const char *base, const char *dirname, struct stat *sb } } } +#endif setnode(n, sb->st_dev, sb->st_ino, sb->st_mode); + +#if !defined(_WIN32) || defined(__CYGWIN__) /* Skip unreadable files/dirs */ if (!S_ISLNK(n->modes) && access(n->realname, R_OK)) { fprintf(stderr, "ignoring '%s' (access failed)\n", n->realname); freenode(n); continue; } +#endif /* Look up old links */ if ( strcmp(n->name, ".") == 0 ) { @@ -658,9 +697,12 @@ int processdir(int level, const char *base, const char *dirname, struct stat *sb n->size = sb->st_size; } else curroffset = alignnode(n, curroffset, 0); + +#if !defined(_WIN32) || defined(__CYGWIN__) if (S_ISLNK(sb->st_mode)) { n->size = sb->st_size; } +#endif curroffset += spaceneeded(n); if (S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode)) { n->devnode = sb->st_rdev; @@ -674,6 +716,9 @@ int processdir(int level, const char *base, const char *dirname, struct stat *sb curroffset = processdir(level+1, n->realname, dp->d_name, sb, n, root, curroffset); } + + if(curroffset < 0) + return -1; } } if (dirfd) closedir(dirfd); @@ -780,7 +825,7 @@ int main(int argc, char *argv[]) } if (!volname) { - sprintf(buf, "rom %08lx", time(NULL)); + sprintf(buf, "rom %" PRId64, (int64_t)time(NULL)); volname = buf; } if (!outf) { @@ -802,9 +847,16 @@ int main(int argc, char *argv[]) root = newnode(dir, volname, 0); root->parent = root; lastoff = processdir (1, dir, dir, &sb, root, root, spaceneeded(root)); + if(lastoff < 0) { + fprintf(stderr, "Error while processing directory.\n"); + return 1; + } if (verbose) shownode(0, root, stderr); - dumpall(root, lastoff, f); + if(dumpall(root, lastoff, f)) { + fprintf(stderr, "Error while dumping!\n"); + return 1; + } - exit(0); + return 0; }