1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/* -*- 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>
static int mp3_getattr (const char *path, struct stat *stbuf)
{
memset (stbuf, 0, sizeof (struct stat));
if (strcmp (path, "/") == 0) {
stbuf->st_mode = S_IFDIR | 0755;
stbuf->st_nlink = 2;
return 0;
}
if (strcmp (path, "/MP3Z") == 0) {
stbuf->st_mode = S_IFREG | 0444;
stbuf->st_nlink = 1;
stbuf->st_size = 12;
return 0;
}
return -ENOENT;
}
static int mp3_readdir (const char *path, void *buf, fuse_fill_dir_t filler,
off_t offset, struct fuse_file_info *fi)
{
if (strcmp (path, "/") != 0)
return -ENOENT;
filler (buf, ".", NULL, 0);
filler (buf, "..", NULL, 0);
filler (buf, "MP3Z", NULL, 0);
/*
* 1. Parse the path.
* 2. Find the mp3s that matches the tags given from the path.
* 3. Return the list of those mp3s.
*/
return 0;
}
static int mp3_open (const char *path, struct fuse_file_info *fi)
{
if (strcmp (path, "/MP3Z") == 0)
return 0;
/*
* 1. Have a lookup cache for names?.
* Parse Genre, Album, Artist etc.
* 2. Find MP3s that match. XXX what do we do with duplicates? just
* return the first match?
* 3. Put the mnode of the mp3 in our cache.
* 4. Signal in mnode that the mp3 is being read?
*/
return -ENOENT;
}
static int mp3_read (const char *path, char *buf, size_t size, off_t offset,
struct fuse_file_info *fi)
{
if (strcmp (path, "/MP3Z") == 0) {
memcpy (buf, "Oh you wish\n", 12);
return 12;
}
/*
* 1. Find the mnode given the path. If not in cache, read through mp3
* list to find it.
* 2. Read the offset of the mp3 and return the data.
*/
return -ENOENT;
}
static struct fuse_operations mp3_oper = {
.getattr = mp3_getattr,
.readdir = mp3_readdir,
.open = mp3_open,
.read = mp3_read,
};
|