blob: ec7b2efdbde5b5b516dc95afb3f602e57696143d [file] [log] [blame]
Frank Gevaertsad9db4d2008-11-01 16:25:04 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Frank Gevaerts
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __MV_H__
23#define __MV_H__
24
Thomas Martitzf6c26d32014-02-07 18:30:50 +010025#include <stdbool.h>
Frank Gevaertsad9db4d2008-11-01 16:25:04 +000026#include "config.h"
27
28/* FixMe: These macros are a bit nasty and perhaps misplaced here.
29 We'll get rid of them once decided on how to proceed with multivolume. */
Frank Gevaertsc0a5a672009-07-17 22:28:49 +000030
Michael Sevakisa56f1ca2013-08-17 12:18:22 -040031/* Drives are things like a disk, a card, a flash chip. They can have volumes
32 on them */
Frank Gevaertsc0a5a672009-07-17 22:28:49 +000033#ifdef HAVE_MULTIDRIVE
Michael Sevakisa56f1ca2013-08-17 12:18:22 -040034#define IF_MD(x...) x /* valist contents or empty */
35#define IF_MD_NONVOID(x...) x /* valist contents or 'void' */
36#define IF_MD_DRV(d) d /* drive argument or '0' */
Frank Gevaertsc0a5a672009-07-17 22:28:49 +000037#else /* empty definitions if no multi-drive */
Michael Sevakisa56f1ca2013-08-17 12:18:22 -040038#define IF_MD(x...)
39#define IF_MD_NONVOID(x...) void
40#define IF_MD_DRV(d) 0
Thomas Martitz706e6b72014-02-18 07:11:11 +010041#endif /* HAVE_MULTIDRIVE */
Frank Gevaertsc0a5a672009-07-17 22:28:49 +000042
43/* Volumes mean things that have filesystems on them, like partitions */
Frank Gevaertsad9db4d2008-11-01 16:25:04 +000044#ifdef HAVE_MULTIVOLUME
Michael Sevakisa56f1ca2013-08-17 12:18:22 -040045#define IF_MV(x...) x /* valist contents or empty */
46#define IF_MV_NONVOID(x...) x /* valist contents or 'void' */
47#define IF_MV_VOL(v) v /* volume argument or '0' */
Thomas Martitz46137eb2014-02-22 23:17:16 +010048
Michael Sevakis7d1a47c2013-08-05 22:02:45 -040049/* Format: "/<DEC###>/foo/bar"
50 * The "DEC" is pure decoration and treated as a comment. Only an unbroken
51 * trailing string of digits within the brackets is parsed as the volume
52 * number.
53 *
54 * IMPORTANT!: Adjust VOL_DEC_MAX_LEN if needed to the longest of these
55 */
56#define DEFAULT_VOL_DEC "Volume"
57
58#if (CONFIG_STORAGE & STORAGE_ATA)
59#define ATA_VOL_DEC "HDD"
Thomas Martitz46137eb2014-02-22 23:17:16 +010060#endif
Michael Sevakis7d1a47c2013-08-05 22:02:45 -040061#if (CONFIG_STORAGE & STORAGE_MMC)
62#define MMC_VOL_DEC "MMC"
63#endif
64#if (CONFIG_STORAGE & STORAGE_SD)
65#define SD_VOL_DEC "microSD"
66#endif
67#if (CONFIG_STORAGE & STORAGE_NAND)
68#define NAND_VOL_DEC "NAND"
69#endif
70#if (CONFIG_STORAGE & STORAGE_RAMDISK)
71#define RAMDISK_VOL_DEC "RAMDisk"
72#endif
73#if (CONFIG_STORAGE & STORAGE_HOSTFS)
74#ifndef HOSTFS_VOL_DEC /* overridable */
75#define HOSTFS_VOL_DEC DEFAULT_VOL_DEC
76#endif
77#endif
78
79/* Characters that delimit a volume specifier at any root point in the path.
80 The tokens must be outside of legal filename characters */
81#define VOL_START_TOK '<'
82#define VOL_END_TOK '>'
83#define VOL_DEC_MAX_LEN 7 /* biggest of all xxx_VOL_DEC defines */
84#define VOL_MAX_LEN (1 + VOL_DEC_MAX_LEN + 2 + 1)
85#define VOL_NUM_MAX 100
Thomas Martitz46137eb2014-02-22 23:17:16 +010086
Frank Gevaertsad9db4d2008-11-01 16:25:04 +000087#else /* empty definitions if no multi-volume */
Michael Sevakisa56f1ca2013-08-17 12:18:22 -040088#define IF_MV(x...)
89#define IF_MV_NONVOID(x...) void
90#define IF_MV_VOL(v) 0
Thomas Martitz706e6b72014-02-18 07:11:11 +010091#endif /* HAVE_MULTIVOLUME */
Frank Gevaertsc0a5a672009-07-17 22:28:49 +000092
Michael Sevakis7d1a47c2013-08-05 22:02:45 -040093#define CHECK_VOL(volume) \
94 ((unsigned int)IF_MV_VOL(volume) < NUM_VOLUMES)
95
96#define CHECK_DRV(drive) \
97 ((unsigned int)IF_MD_DRV(drive) < NUM_DRIVES)
98
99/* Volume-centric functions (in disk.c) */
100void volume_recalc_free(IF_MV_NONVOID(int volume));
101unsigned int volume_get_cluster_size(IF_MV_NONVOID(int volume));
102void volume_size(IF_MV(int volume,) unsigned long *size, unsigned long *free);
Solomon Peachy51fe1b62019-07-28 09:24:40 -0400103#ifdef HAVE_DIRCACHE
Michael Sevakis7d1a47c2013-08-05 22:02:45 -0400104bool volume_ismounted(IF_MV_NONVOID(int volume));
Solomon Peachy51fe1b62019-07-28 09:24:40 -0400105#endif
Michael Sevakis7d1a47c2013-08-05 22:02:45 -0400106#ifdef HAVE_HOTSWAP
107bool volume_removable(int volume);
108bool volume_present(int volume);
109#endif /* HAVE_HOTSWAP */
110
111#ifdef HAVE_MULTIDRIVE
112int volume_drive(int volume);
113#else /* !HAVE_MULTIDRIVE */
114static inline int volume_drive(int volume)
115{
116 return 0;
117 (void)volume;
118}
119#endif /* HAVE_MULTIDRIVE */
120
Michael Sevakisa56f1ca2013-08-17 12:18:22 -0400121#endif /* __MV_H__ */