summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Ørbekk <orbekk@pvv.ntnu.no>2008-04-25 15:10:08 +0200
committerKjetil Ørbekk <orbekk@pvv.ntnu.no>2008-04-25 15:10:08 +0200
commit3c4e33a50159b4c5f5321ad5a181d2a3c1674b9a (patch)
tree37910f33b527c52a13918474fe83ca2d7f0f765e
parenta43ff6faf155b95ba17eb9bd192e99f52cb25820 (diff)
parentb72c4650d1bc4dde150ee9ff4f0457394b7bf4a3 (diff)
- Merge
-rw-r--r--include/mp3fs.h14
-rw-r--r--src/mp3_subr.c94
-rwxr-xr-xsrc/mp3_vnops.c100
3 files changed, 111 insertions, 97 deletions
diff --git a/include/mp3fs.h b/include/mp3fs.h
index 4b6cc5d..50bdbee 100644
--- a/include/mp3fs.h
+++ b/include/mp3fs.h
@@ -2,4 +2,18 @@
#define _MP3FS_H_
struct fuse_args;
int mp3_run(int, char **);
+
+
+/*
+ * Data passed to traverse function pointers.'
+ */
+struct filler_data {
+ void *buf;
+ fuse_fill_dir_t filler;
+};
+/* Traverse files used in mp3_subr.c */
+typedef void traverse_fn_t(char *, void *);
+void traverse_hierarchy(char *, traverse_fn_t, void *);
+
+traverse_fn_t mp3_artist;
#endif
diff --git a/src/mp3_subr.c b/src/mp3_subr.c
index a570139..85eb03c 100644
--- a/src/mp3_subr.c
+++ b/src/mp3_subr.c
@@ -1 +1,95 @@
/* Miscellaneous subroutines for mp3fs. */
+#define FUSE_USE_VERSION 26
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <err.h>
+
+#include <sys/types.h>
+#include <dirent.h>
+#include <fuse.h>
+#include <sys/param.h>
+
+#include <tag_c.h>
+#include <mp3fs.h>
+
+/*
+ * Traverse a hierarchy given a directory path. Perform fileoperations on the
+ * files in the directory giving data as arguments, as well as recursing on
+ * sub-directories.
+ */
+void
+traverse_hierarchy(char *dirpath, traverse_fn_t fileop, void *data)
+{
+ DIR *dirp;
+ struct dirent *dp;
+ char filepath[MAXPATHLEN];
+ struct stat st;
+ struct filler_data *fd;
+
+ fd = data;
+ dirp = opendir(dirpath);
+ if (dirp == NULL) {
+ fd->filler(fd->buf, "lolerr", NULL, 0);
+ return;
+ }
+
+ /* Loop through all files. */
+ while ((dp = readdir(dirp)) != NULL) {
+ if (!strcmp(dp->d_name, ".") ||
+ !strcmp(dp->d_name, ".."))
+ continue;
+
+ snprintf(filepath, sizeof(filepath), "%s/%s",
+ dirpath, dp->d_name);
+ if (stat(filepath, &st) < 0)
+ err(1, "error doing stat on %s", filepath);
+ /* Recurse if it's a directory. */
+ if (st.st_mode & S_IFDIR) {
+ traverse_hierarchy(filepath, fileop, data);
+ continue;
+ }
+ /* If it's a regular file, perform the operation. */
+ if (st.st_mode & S_IFREG) {
+ fileop(filepath, data);
+ }
+ }
+ closedir(dirp);
+}
+
+/*
+ * Retrieve artist name given a file, and put in a buffer with a passed filler
+ * function
+ */
+void
+mp3_artist(char *filepath, void *data)
+{
+ struct filler_data *fd;
+ fuse_fill_dir_t filler;
+ void *buf;
+ char name[MAXPATHLEN];
+ TagLib_File *tagfile;
+ TagLib_Tag *tag;
+
+ /* Retrieve the filler function and pointers. */
+ fd = (struct filler_data *)data;
+ filler = fd->filler;
+ buf = fd->buf;
+
+ /* Get the tag. */
+ tagfile = taglib_file_new(filepath);
+ tag = taglib_file_tag(tagfile);
+
+ char *artist = taglib_tag_artist(tag);
+ if (artist == NULL)
+ return;
+
+ strcpy(name, artist);
+
+ filler(buf, name, NULL, 0);
+
+ taglib_tag_free_strings();
+ taglib_file_free(tagfile);
+ return;
+}
+
diff --git a/src/mp3_vnops.c b/src/mp3_vnops.c
index 3224314..c0cf76b 100755
--- a/src/mp3_vnops.c
+++ b/src/mp3_vnops.c
@@ -9,27 +9,15 @@
#include <sys/types.h>
#include <dirent.h>
#include <fuse.h>
+#include <sys/param.h>
#include <tag_c.h>
+#include <mp3fs.h>
-#include "debug.h"
-
-#define MAXPATHLEN 100000
+#include <debug.h>
char musicpath[MAXPATHLEN]; // = "/home/lulf/dev/mp3fs/music";
-typedef void traverse_fn_t(char *, void *);
-
-void traverse_hierarchy(char *, traverse_fn_t, void *);
-traverse_fn_t mp3_artist;
-/*
- * Data passed to traverse function pointers.'
- */
-struct filler_data {
- void *buf;
- fuse_fill_dir_t filler;
-};
-
static int mp3_getattr (const char *path, struct stat *stbuf)
{
memset (stbuf, 0, sizeof (struct stat));
@@ -85,88 +73,6 @@ call_lol(char *path)
printf("Path %s\n", path);
}
-/*
- * Traverse a hierarchy given a directory path. Perform fileoperations on the
- * files in the directory giving data as arguments, as well as recursing on
- * sub-directories.
- */
-void
-traverse_hierarchy(char *dirpath, traverse_fn_t fileop, void *data)
-{
- DIR *dirp;
- struct dirent *dp;
- char filepath[MAXPATHLEN];
- struct stat st;
- struct filler_data *fd;
-
- fd = data;
- dirp = opendir(dirpath);
- if (dirp == NULL) {
- fd->filler(fd->buf, "lolerr", NULL, 0);
- return;
- }
-
- /* Loop through all files. */
- while ((dp = readdir(dirp)) != NULL) {
- if (!strcmp(dp->d_name, ".") ||
- !strcmp(dp->d_name, ".."))
- continue;
-
- snprintf(filepath, sizeof(filepath), "%s/%s",
- dirpath, dp->d_name);
- if (stat(filepath, &st) < 0)
- err(1, "error doing stat on %s", filepath);
- /* Recurse if it's a directory. */
- if (st.st_mode & S_IFDIR) {
- traverse_hierarchy(filepath, fileop, data);
- continue;
- }
- /* If it's a regular file, perform the operation. */
- if (st.st_mode & S_IFREG) {
- fileop(filepath, data);
- }
- }
- closedir(dirp);
-}
-
-
-
-/*
- * Retrieve artist name given a file, and put in a buffer with a passed filler
- * function
- */
-void
-mp3_artist(char *filepath, void *data)
-{
- struct filler_data *fd;
- fuse_fill_dir_t filler;
- void *buf;
- char name[MAXPATHLEN];
- TagLib_File *tagfile;
- TagLib_Tag *tag;
-
- /* Retrieve the filler function and pointers. */
- fd = (struct filler_data *)data;
- filler = fd->filler;
- buf = fd->buf;
-
- /* Get the tag. */
- tagfile = taglib_file_new(filepath);
- tag = taglib_file_tag(tagfile);
-
- char *artist = taglib_tag_artist(tag);
- if (artist == NULL)
- return;
-
- strcpy(name, artist);
-
- filler(buf, name, NULL, 0);
-
- taglib_tag_free_strings();
- taglib_file_free(tagfile);
- return;
-}
-
static int mp3_open (const char *path, struct fuse_file_info *fi)
{
if (strcmp (path, "/Artists") == 0)