diff options
author | lulf@carrot.studby.ntnu.no <lulf@carrot.studby.ntnu.no> | 2008-04-23 16:31:29 +0200 |
---|---|---|
committer | lulf@carrot.studby.ntnu.no <lulf@carrot.studby.ntnu.no> | 2008-04-23 16:31:29 +0200 |
commit | 7a704ce7bc3d62311fdcb6283524cfde236424a1 (patch) | |
tree | da82f815b5990f6cb7114ff1060ee2a27ada3309 | |
parent | 86314731468527bada0cbd911359dba89ab98882 (diff) |
- Fix compiler warnings.
- Add comments.
-rwxr-xr-x | src/mp3_vnops.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/mp3_vnops.c b/src/mp3_vnops.c index cfaed2f..6d69e91 100755 --- a/src/mp3_vnops.c +++ b/src/mp3_vnops.c @@ -1,17 +1,19 @@ /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ #define FUSE_USE_VERSION 26 - -#include <fuse.h> #include <stdio.h> #include <errno.h> #include <string.h> -#include <id3.h> +#include <err.h> + #include <sys/types.h> #include <dirent.h> +#include <fuse.h> + +#include <id3.h> #define MAXPATHLEN 100000 -const char *musicpath = "/home/lulf/dev/mp3fs/music"; +char *musicpath = "/home/lulf/dev/mp3fs/music"; void traverse_hierarchy(char *, void (*)(char *, void *), void *); void mp3_artist(char *, void *); @@ -39,8 +41,6 @@ static int mp3_getattr (const char *path, struct stat *stbuf) static int mp3_readdir (const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { - char *tmp; - char *parsepath; filler (buf, ".", NULL, 0); filler (buf, "..", NULL, 0); @@ -66,6 +66,11 @@ static int mp3_readdir (const char *path, void *buf, fuse_fill_dir_t filler, } +/* + * 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, void (*fileop)(char *, void *), void *data) { @@ -75,6 +80,7 @@ traverse_hierarchy(char *dirpath, void (*fileop)(char *, void *), void *data) struct stat st; dirp = opendir(dirpath); + /* Loop through all files. */ while ((dp = readdir(dirp)) != NULL) { if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) @@ -84,6 +90,7 @@ traverse_hierarchy(char *dirpath, void (*fileop)(char *, void *), void *data) musicpath, 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); if (!(st.st_mode & S_IFREG)) @@ -92,7 +99,6 @@ traverse_hierarchy(char *dirpath, void (*fileop)(char *, void *), void *data) fileop(filepath, data); } closedir(dirp); - return (0); } struct filler_data { @@ -100,7 +106,10 @@ struct filler_data { fuse_fill_dir_t filler; }; -/* Retrieve artist name given a path. */ +/* + * Retrieve artist name given a file, and put in a buffer with a passed filler + * function + */ void mp3_artist(char *filepath, void *data) { @@ -112,17 +121,19 @@ mp3_artist(char *filepath, void *data) void *buf; char name[MAXPATHLEN]; + /* Retrieve the filler function and pointers. */ fd = (struct filler_data *)data; filler = fd->filler; buf = fd->buf; + /* Get the tag. */ tag = ID3Tag_New(); ID3Tag_Link(tag, filepath); artist = ID3Tag_FindFrameWithID(tag, ID3FID_LEADARTIST); field = ID3Frame_GetField(artist, ID3FN_TEXT); ID3Field_GetASCII(field, name, ID3Field_Size(field)); filler(buf, name, NULL, 0); - return 0; + ID3Tag_Delete(tag); } static int mp3_open (const char *path, struct fuse_file_info *fi) |