1/*
2 * Copyright 2001-2009, Axel Dörfler, axeld@pinc-software.de.
3 * Copyright 2014 Haiku, Inc. All rights reserved.
4 *
5 * Distributed under the terms of the MIT License.
6 *
7 * Authors:
8 *		Axel Dörfler, axeld@pinc-software.de
9 *		John Scipione, jscipione@gmail.com
10 */
11#ifndef UTILITY_H
12#define UTILITY_H
13
14
15#include "exfat.h"
16
17
18enum inode_type {
19	S_DIRECTORY		= S_IFDIR,
20	S_FILE			= S_IFREG,
21	S_SYMLINK		= S_IFLNK,
22
23	S_INDEX_TYPES	= (S_STR_INDEX | S_INT_INDEX | S_UINT_INDEX
24						| S_LONG_LONG_INDEX | S_ULONG_LONG_INDEX
25						| S_FLOAT_INDEX | S_DOUBLE_INDEX),
26
27	S_EXTENDED_TYPES = (S_ATTR_DIR | S_ATTR | S_INDEX_DIR)
28};
29
30
31/*!	Converts the open mode, the open flags given to bfs_open(), into
32	access modes, e.g. since O_RDONLY requires read access to the
33	file, it will be converted to R_OK.
34*/
35inline int
36open_mode_to_access(int openMode)
37{
38	openMode &= O_RWMASK;
39	if (openMode == O_RDONLY)
40		return R_OK;
41	if (openMode == O_WRONLY)
42		return W_OK;
43
44	return R_OK | W_OK;
45}
46
47
48/*!	Reads the volume name from an exfat entry and writes it to
49	\a name as a UTF-8 char array.
50
51	Writes a blank string to \a name if the volume name is not set.
52
53	\param entry The \a entry to look for the volume name in.
54	\param name The \a name array to fill out.
55	\param length The \a length of the name array in bytes.
56
57	\returns A status code, \c B_OK on success or an error code otherwise.
58	\retval B_OK Wrote the volume name to \a name successfully.
59	\retval B_BAD_VALUE \a entry or \a name was \c NULL.
60	\retval B_NAME_NOT_FOUND Volume name was not found in this \a entry.
61	\retval B_NAME_TOO_LONG \a name wasn't long enough to fit the volume name.
62*/
63status_t get_volume_name(struct exfat_entry* entry, char* name, size_t length);
64
65
66/*!	Writes a more or less descriptive volume name to \a name.
67
68	\param partitionSize The partion size in bytes.
69	\param name The \a name array to fill out.
70	\param length The \a length of the name array in bytes.
71*/
72void get_default_volume_name(off_t partitionSize, char* name, size_t length);
73
74
75#endif	// UTILITY_H
76