2 * Copyright (C) 2003-2009 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
27 #include <sys/types.h>
29 #define DIRECTORY_DIR "directory: "
31 #define DEVICE_INARCHIVE (unsigned)(-1)
32 #define DEVICE_CONTAINER (unsigned)(-2)
35 struct dirvec children
;
37 struct directory
*parent
;
41 unsigned stat
; /* not needed if ino_t == dev_t == 0 is impossible */
42 char path
[sizeof(long)];
46 isRootDirectory(const char *name
)
48 return name
[0] == 0 || (name
[0] == '/' && name
[1] == 0);
52 directory_new(const char *dirname
, struct directory
*parent
);
55 directory_free(struct directory
*directory
);
58 directory_is_empty(const struct directory
*directory
)
60 return directory
->children
.nr
== 0 && directory
->songs
.nr
== 0;
63 static inline const char *
64 directory_get_path(const struct directory
*directory
)
66 return directory
->path
;
70 * Is this the root directory of the music database?
73 directory_is_root(const struct directory
*directory
)
75 return directory
->parent
== NULL
;
79 * Returns the base name of the directory.
82 directory_get_name(const struct directory
*directory
);
84 static inline struct directory
*
85 directory_get_child(const struct directory
*directory
, const char *name
)
87 return dirvec_find(&directory
->children
, name
);
90 static inline struct directory
*
91 directory_new_child(struct directory
*directory
, const char *name
)
93 struct directory
*subdir
= directory_new(name
, directory
);
94 dirvec_add(&directory
->children
, subdir
);
99 directory_prune_empty(struct directory
*directory
);
102 * Looks up a directory by its relative URI.
104 * @param directory the parent (or grandparent, ...) directory
105 * @param uri the relative URI
106 * @return the directory, or NULL if none was found
109 directory_lookup_directory(struct directory
*directory
, const char *uri
);
112 * Looks up a song by its relative URI.
114 * @param directory the parent (or grandparent, ...) directory
115 * @param uri the relative URI
116 * @return the song, or NULL if none was found
119 directory_lookup_song(struct directory
*directory
, const char *uri
);
122 directory_sort(struct directory
*directory
);
125 directory_walk(struct directory
*directory
,
126 int (*forEachSong
)(struct song
*, void *),
127 int (*forEachDir
)(struct directory
*, void *),