RTEMS 6.1-rc1
media.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * Copyright (C) 2009, 2018 embedded brains GmbH & Co. KG
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef RTEMS_MEDIA_H
37#define RTEMS_MEDIA_H
38
39#include <sys/types.h>
40#include <rtems.h>
41
42#ifdef __cplusplus
43extern "C" {
44#endif /* __cplusplus */
45
62#define RTEMS_MEDIA_MOUNT_BASE "/media"
63
64#define RTEMS_MEDIA_DELIMITER '-'
65
82typedef enum {
83 RTEMS_MEDIA_EVENT_DISK_ATTACH,
84 RTEMS_MEDIA_EVENT_DISK_DETACH,
85 RTEMS_MEDIA_EVENT_MOUNT,
86 RTEMS_MEDIA_EVENT_UNMOUNT,
87 RTEMS_MEDIA_EVENT_PARTITION_INQUIRY,
88 RTEMS_MEDIA_EVENT_PARTITION_ATTACH,
89 RTEMS_MEDIA_EVENT_PARTITION_DETACH,
90 RTEMS_MEDIA_EVENT_ERROR
92
104typedef enum {
105 RTEMS_MEDIA_STATE_INQUIRY,
106 RTEMS_MEDIA_STATE_READY,
107 RTEMS_MEDIA_STATE_ABORTED,
108 RTEMS_MEDIA_STATE_SUCCESS,
109 RTEMS_MEDIA_STATE_FAILED,
110 RTEMS_MEDIA_ERROR_DISK_UNKNOWN,
111 RTEMS_MEDIA_ERROR_DISK_EXISTS,
112 RTEMS_MEDIA_ERROR_DISK_OR_PARTITION_UNKNOWN,
113 RTEMS_MEDIA_ERROR_DISK_OR_PARTITION_EXISTS,
114 RTEMS_MEDIA_ERROR_PARTITION_UNKNOWN,
115 RTEMS_MEDIA_ERROR_PARTITION_ORPHAN,
116 RTEMS_MEDIA_ERROR_PARTITION_DETACH_WITH_MOUNT,
117 RTEMS_MEDIA_ERROR_PARTITION_WITH_UNKNOWN_DISK,
118 RTEMS_MEDIA_ERROR_MOUNT_POINT_UNKNOWN,
119 RTEMS_MEDIA_ERROR_MOUNT_POINT_EXISTS,
120 RTEMS_MEDIA_ERROR_MOUNT_POINT_ORPHAN
122
302 rtems_media_event event,
303 rtems_media_state state,
304 const char *src,
305 const char *dest,
306 void *listener_arg
307);
308
326 rtems_media_state state,
327 const char *src,
328 char **dest,
329 void *worker_arg
330);
331
346static inline rtems_status_code rtems_media_initialize(void)
347{
348 return RTEMS_SUCCESSFUL;
349}
350
359 rtems_media_listener listener,
360 void *listener_arg
361);
362
370 rtems_media_listener listener,
371 void *listener_arg
372);
373
390 rtems_media_event event,
391 const char *src,
392 char **dest,
393 rtems_media_worker worker,
394 void *worker_arg
395);
396
417 rtems_task_priority priority,
418 size_t stack_size,
419 rtems_mode modes,
420 rtems_attribute attributes
421);
422
433 rtems_media_event event,
434 const char *src,
435 rtems_media_worker worker,
436 void *worker_arg
437);
438
442static inline rtems_status_code rtems_media_server_disk_attach(
443 const char *driver_name,
444 rtems_media_worker worker,
445 void *worker_arg
446)
447{
449 RTEMS_MEDIA_EVENT_DISK_ATTACH,
450 driver_name,
451 worker,
452 worker_arg
453 );
454}
455
459static inline rtems_status_code rtems_media_server_disk_detach(
460 const char *disk_path
461)
462{
464 RTEMS_MEDIA_EVENT_DISK_DETACH,
465 disk_path,
466 NULL,
467 NULL
468 );
469}
470
484 const char *prefix,
485 const char *name,
487);
488
496char *rtems_media_replace_prefix(const char *new_prefix, const char *path);
497
504 const char *path,
506);
507
523 const char *device_path,
524 dev_t *device_identifier
525);
526
527const char *rtems_media_event_description(rtems_media_event event);
528
529const char *rtems_media_state_description(rtems_media_state state);
530
535#ifdef __cplusplus
536}
537#endif /* __cplusplus */
538
539#endif /* RTEMS_MEDIA_H */
uint32_t rtems_attribute
This type represents Classic API attributes.
Definition: attr.h:96
uint32_t rtems_device_major_number
This integer type represents the major number of devices.
Definition: io.h:103
uint32_t rtems_device_minor_number
This integer type represents the minor number of devices.
Definition: io.h:115
uint32_t rtems_mode
This type represents a Classic API task mode set.
Definition: modes.h:174
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:85
@ RTEMS_SUCCESSFUL
This status code indicates successful completion of a requested operation.
Definition: status.h:90
uint32_t rtems_task_priority
This integer type represents task priorities of the Classic API.
Definition: types.h:257
char * rtems_media_replace_prefix(const char *new_prefix, const char *path)
Replaces the prefix of the path with new_prefix.
Definition: media-path.c:64
char * rtems_media_append_minor(const char *path, rtems_device_minor_number minor)
Appends the minor number to the path resulting in "path-minor".
Definition: media-path.c:82
rtems_status_code rtems_media_post_event(rtems_media_event event, const char *src, char **dest, rtems_media_worker worker, void *worker_arg)
Posts the event with source src.
Definition: media.c:931
char * rtems_media_create_path(const char *prefix, const char *name, rtems_device_major_number major)
Creates a new path as "prefix/name-major".
Definition: media-path.c:44
rtems_status_code(* rtems_media_worker)(rtems_media_state state, const char *src, char **dest, void *worker_arg)
Do the work corresponding to an event.
Definition: media.h:325
rtems_status_code rtems_media_server_initialize(rtems_task_priority priority, size_t stack_size, rtems_mode modes, rtems_attribute attributes)
Initializes the media manager and media server.
Definition: media-server.c:86
rtems_status_code rtems_media_get_device_identifier(const char *device_path, dev_t *device_identifier)
Returns the device identifier for the device located at device_path in device_identifier.
Definition: media-dev-ident.c:44
rtems_status_code rtems_media_listener_add(rtems_media_listener listener, void *listener_arg)
Adds the listener with argument listener_arg.
Definition: media.c:111
rtems_status_code rtems_media_listener_remove(rtems_media_listener listener, void *listener_arg)
Removes the listener with argument listener_arg.
Definition: media.c:142
rtems_status_code(* rtems_media_listener)(rtems_media_event event, rtems_media_state state, const char *src, const char *dest, void *listener_arg)
Event listener.
Definition: media.h:301
rtems_media_state
Definition: media.h:104
rtems_status_code rtems_media_server_post_event(rtems_media_event event, const char *src, rtems_media_worker worker, void *worker_arg)
Sends an event message to the media server.
Definition: media-server.c:130
rtems_media_event
Definition: media.h:82
#define NULL
Requests a GPIO pin group configuration.
Definition: xil_types.h:54
This header file defines the RTEMS Classic API.