From: skeezix Date: Wed, 10 Jun 2009 09:25:02 +0000 (-0400) Subject: Moved path determination to pnd_apps (more likely people will see it, and makes sense... X-Git-Tag: Release-2010-05/1~171 X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b945d7a6b257ab73f11f7c97448dae3600a9484c;p=pandora-libraries.git Moved path determination to pnd_apps (more likely people will see it, and makes sense.) Could also be pnd_utility maybe, but meh. Made get_ro_mountpoint and get_appdata_path for clarifying the two mountpoints.. 99% will want get_appdata_path --- diff --git a/include/pnd_apps.h b/include/pnd_apps.h index 12cfa6b..13dc07a 100644 --- a/include/pnd_apps.h +++ b/include/pnd_apps.h @@ -55,6 +55,20 @@ unsigned char pnd_apps_exec ( char *pndrun, char *fullpath, char *unique_id, char *rel_exec, char *rel_startdir, unsigned int clockspeed, unsigned int options ); +// should you wish to know where an app will get mounted, call this function to obtain a guess. The +// logic is wrapped up in pnd_run.sh, but in theory should be easily determined. + +// get_appdata_path() is the one you probably want.. the appdata path (which includes both the +// files in the pnd, and any files updated/written-out from that app. Look up aufs or union-filesystems.) +// ie: appdata path is read/write, while ro_mountpoint is read-only +// Returns >0 on success, and if not-NULL will fill r_path (up to path_len length.) +unsigned char pnd_get_appdata_path ( char *fullpath, char *unique_id, char *r_path, unsigned int path_len ); +// get_ro_mountpoint() returns the _read only_ mountpoint, where the dir or .pnd is actually +// mounted to. This is probably NOT WHAT YOU WANT. You probably want the read/write mountpoint, which +// is the union-filesystem version of it.. see pnd_get_appdata_path() +// r_mountpoint (if !NULL) will be populated; mountpoint_len should specify the maxlen of the buffer +void pnd_get_ro_mountpoint ( char *fullpath, char *unique_id, char *r_mountpoint, unsigned int mountpoint_len ); + #ifdef __cplusplus } /* "C" */ #endif diff --git a/include/pnd_pndfiles.h b/include/pnd_pndfiles.h index d804913..ab13838 100644 --- a/include/pnd_pndfiles.h +++ b/include/pnd_pndfiles.h @@ -40,10 +40,6 @@ char *pnd_match_binbuf ( char *haystack, unsigned int maxlen, char *needle ); // On success, _mount and _unmount return >0 unsigned char pnd_pnd_mount ( char *pndrun, char *fullpath, char *unique_id ); unsigned char pnd_pnd_unmount ( char *pndrun, char *fullpath, char *unique_id ); -// should you wish to know where an app will get mounted, call this function to obtain a guess. The -// logic is wrapped up in pnd_run.sh, but in theory should be easily determined. -// r_mountpoint (if !NULL) will be populated; mountpoint_len should specify the maxlen of the buffer -void pnd_get_mountpoint ( char *unique_id, char *r_mountpoint, unsigned int mountpoint_len ); #ifdef __cplusplus } /* "C" */ diff --git a/lib/pnd_apps.c b/lib/pnd_apps.c index c4a0ad0..72a251d 100644 --- a/lib/pnd_apps.c +++ b/lib/pnd_apps.c @@ -106,3 +106,60 @@ unsigned char pnd_apps_exec ( char *pndrun, char *fullpath, char *unique_id, return ( 1 ); } + +void pnd_get_ro_mountpoint ( char *fullpath, char *unique_id, char *r_mountpoint, unsigned int mountpoint_len ) { + + if ( ! r_mountpoint ) { + return; // sillyness + } + + snprintf ( r_mountpoint, mountpoint_len, "%s/%s/", PND_MOUNT_PATH, unique_id ); + + return; +} + +unsigned char pnd_get_appdata_path ( char *fullpath, char *unique_id, char *r_path, unsigned int path_len ) { + // you know, determining the 'mount point' used is sort of a pain in the rear + // use df , skip header line, grab first token. Cheap and should work. + // (Rather than just assume first two path chunks in path, say, which would be pretty darned + // accurate, but whose to say they're not using NFS or crazy mountpoints?) + FILE *df; + char cmdbuf [ 1024 ]; + + snprintf ( cmdbuf, 1023, "/bin/df %s", fullpath ); + + df = popen ( cmdbuf, "r" ); + + if ( ! df ) { + return ( 0 ); // tunefs: you can tune a filesystem but you can't tune a fish + } + + // fetch and discard header + if ( ! fgets ( cmdbuf, 1023, df ) ) { + pclose ( df ); + return ( 0 ); + } + + // grab df result line + if ( ! fgets ( cmdbuf, 1023, df ) ) { + pclose ( df ); + return ( 0 ); + } + + pclose ( df ); + + // parse + char *ws = strchr ( cmdbuf, ' ' ); + + if ( ! ws ) { + return ( 0 ); + } + + *ws = '\0'; + + if ( r_path && path_len ) { + snprintf ( r_path, path_len, "%s/appdata/%s/", cmdbuf, unique_id ); + } + + return ( 1 ); +} diff --git a/lib/pnd_pndfiles.c b/lib/pnd_pndfiles.c index d249636..3e3f833 100644 --- a/lib/pnd_pndfiles.c +++ b/lib/pnd_pndfiles.c @@ -133,17 +133,6 @@ char *pnd_match_binbuf ( char *haystack, unsigned int maxlen, char *needle ) { return ( NULL ); } -void pnd_get_mountpoint ( char *unique_id, char *r_mountpoint, unsigned int mountpoint_len ) { - - if ( ! r_mountpoint ) { - return; // sillyness - } - - snprintf ( r_mountpoint, mountpoint_len, "%s/%s", PND_MOUNT_PATH, unique_id ); - - return; -} - static unsigned char pnd_pnd_mountie ( char *pndrun, char *fullpath, char *unique_id, unsigned char do_mount ) { char *argv [ 20 ]; int f; diff --git a/test/discotest.c b/test/discotest.c index 364af15..a1b3038 100644 --- a/test/discotest.c +++ b/test/discotest.c @@ -199,6 +199,17 @@ int main ( int argc, char *argv[] ) { } else if ( d -> object_type == pnd_object_type_pnd ) { sprintf ( fullpath, "%s/%s", d -> object_path, d -> object_filename ); } + + printf ( "Guessing appdata path..\n" ); + char appdata_path [ 1024 ]; + pnd_get_ro_mountpoint ( fullpath, d -> unique_id, appdata_path, 1024 ); + printf ( "Guessed readonly app mountpoint '%s'\n", appdata_path ); + if ( pnd_get_appdata_path ( fullpath, d -> unique_id, appdata_path, 1024 ) ) { + printf ( " Appdata should be: %s\n", appdata_path ); + } else { + printf ( " Error determining appdata path..\n" ); + } + printf ( "Trying to exec '%s'\n", fullpath ); pnd_apps_exec ( pndrun, fullpath, d -> unique_id, d -> exec, d -> startdir, atoi ( d -> clockspeed ), PND_EXEC_OPTION_BLOCK ); } @@ -215,6 +226,7 @@ int main ( int argc, char *argv[] ) { } // extra testing - tilde-substitution + printf ( "Unrelated test..\n" ); char *p = strdup ( "~/.applications" ); printf ( "Tilde substitution: in '%s'\n", p ); printf ( " out '%s'\n", pnd_expand_tilde ( p ) );