gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > FAT_GetFileCluster() libfat 01-27-2007 equivalent

#133043 - tondopie - Mon Jul 02, 2007 10:02 pm

I'm updating the GBAMP .nds file launching code to work with libfat. What is the libfat equivalent to FAT_GetFileCluster()?

#133079 - chishm - Tue Jul 03, 2007 4:06 am

Call stat() or fstat() on the file. The cluster is stored in st_ino of the returned stat struct.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#133085 - tondopie - Tue Jul 03, 2007 4:30 am

thanks, does it matter which? stat() or fstat()?

#133090 - chishm - Tue Jul 03, 2007 5:26 am

tondopie wrote:
thanks, does it matter which? stat() or fstat()?

No, they return the same data. One works with open files (openned with open(), not fopen()) and the other works with file names.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#133112 - tondopie - Tue Jul 03, 2007 1:36 pm

I'd probably want to use fstat() for this then

#133131 - tondopie - Tue Jul 03, 2007 7:01 pm

what are the parimeters for fstat?

#133135 - chuckstudios - Tue Jul 03, 2007 7:26 pm

According to http://www.opengroup.org/onlinepubs/009695399/functions/fstat.html :


#include <sys/stat.h>

int fstat(int fildes, struct stat *buf);

#133138 - wintermute - Tue Jul 03, 2007 7:49 pm

tondopie wrote:
I'd probably want to use fstat() for this then


Probably stat, as chishm said, fstat requires a file descriptor obtained from open rather than fopen.

man page wrote:

NAME
stat, fstat, lstat - get file status

SYNOPSIS
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

int stat(const char *path, struct stat *buf);
int fstat(int filedes, struct stat *buf);

_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#133421 - tondopie - Fri Jul 06, 2007 3:12 am

none of the members from the stat structure seem to work right. I looked at FAT_GetFIleCluster() through CVS and it looked like it looked fro the last access. the members that I chose didn't seem to work.

I always get

Code:
warning: passing argument 2 of 'stat' makes pointer from integer without a cast


should this be the GBAMP .nds loading BootStrap? or a different member of the 'stat' struct? I'm kind of lost on what it should be.

#133427 - chishm - Fri Jul 06, 2007 4:25 am

Code:

struct stat st;
u32 cluster;

stat ("/testfile.nds", &st);

cluster = st.st_ino;


EDIT: fixed
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com


Last edited by chishm on Fri Jul 06, 2007 11:37 am; edited 1 time in total

#133471 - mml - Fri Jul 06, 2007 10:41 am

st.st_ino ;)

#133479 - chishm - Fri Jul 06, 2007 11:38 am

mml wrote:
st.st_ino ;)

Um, yeah.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#133533 - tondopie - Fri Jul 06, 2007 11:03 pm

I used that the first time and it came up with the same error, but you have also included other code to so Thank You very much. This helps me quite a lot!

#134566 - tondopie - Sat Jul 14, 2007 1:59 am

Despite efforts, it still hangs. Oh well. I just have to backtrack to a r20 modifcation of GBA_NDS_FAT.