2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef MPD_DIRECTORY_H
21 #define MPD_DIRECTORY_H
28 #include <sys/types.h>
30 #define DIRECTORY_DIR "directory: "
32 #define DEVICE_INARCHIVE (unsigned)(-1)
33 #define DEVICE_CONTAINER (unsigned)(-2)
36 struct dirvec children
;
38 struct directory
*parent
;
42 unsigned stat
; /* not needed if ino_t == dev_t == 0 is impossible */
43 char path
[sizeof(long)];
47 isRootDirectory(const char *name
)
49 return name
[0] == 0 || (name
[0] == '/' && name
[1] == 0);
53 directory_new(const char *dirname
, struct directory
*parent
);
56 directory_free(struct directory
*directory
);
59 directory_is_empty(const struct directory
*directory
)
61 return directory
->children
.nr
== 0 && directory
->songs
.nr
== 0;
64 static inline const char *
65 directory_get_path(const struct directory
*directory
)
67 return directory
->path
;
71 * Is this the root directory of the music database?
74 directory_is_root(const struct directory
*directory
)
76 return directory
->parent
== NULL
;
80 * Returns the base name of the directory.
83 directory_get_name(const struct directory
*directory
);
85 static inline struct directory
*
86 directory_get_child(const struct directory
*directory
, const char *name
)
88 return dirvec_find(&directory
->children
, name
);
91 static inline struct directory
*
92 directory_new_child(struct directory
*directory
, const char *name
)
94 struct directory
*subdir
= directory_new(name
, directory
);
95 dirvec_add(&directory
->children
, subdir
);
100 directory_prune_empty(struct directory
*directory
);
103 * Looks up a directory by its relative URI.
105 * @param directory the parent (or grandparent, ...) directory
106 * @param uri the relative URI
107 * @return the directory, or NULL if none was found
110 directory_lookup_directory(struct directory
*directory
, const char *uri
);
113 * Looks up a song by its relative URI.
115 * @param directory the parent (or grandparent, ...) directory
116 * @param uri the relative URI
117 * @return the song, or NULL if none was found
120 directory_lookup_song(struct directory
*directory
, const char *uri
);
123 directory_sort(struct directory
*directory
);
126 directory_walk(struct directory
*directory
,
127 int (*forEachSong
)(struct song
*, void *),
128 int (*forEachDir
)(struct directory
*, void *),