Change FIOC_MMAP into file operation call

- Add mmap into file_operations and remove it from ioctl definitions.
- Add mm_map structure definitions to support future unmapping
- Modify all drivers to initialize the operations struct accordingly

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
This commit is contained in:
Jukka Laitinen
2023-01-02 17:02:51 +04:00
committed by Alan Carvalho de Assis
parent 41e9df2f3e
commit f33dc4df3f
111 changed files with 320 additions and 96 deletions
+3
View File
@@ -37,6 +37,7 @@
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/mm/map.h>
/****************************************************************************
* Pre-processor Definitions
@@ -213,6 +214,7 @@ struct file_operations
off_t (*seek)(FAR struct file *filep, off_t offset, int whence);
int (*ioctl)(FAR struct file *filep, int cmd, unsigned long arg);
int (*truncate)(FAR struct file *filep, off_t length);
int (*mmap)(FAR struct file *filep, FAR struct mm_map_entry_s *map);
/* The two structures need not be common after this point */
@@ -300,6 +302,7 @@ struct mountpt_operations
off_t (*seek)(FAR struct file *filep, off_t offset, int whence);
int (*ioctl)(FAR struct file *filep, int cmd, unsigned long arg);
int (*truncate)(FAR struct file *filep, off_t length);
int (*mmap)(FAR struct file *filep, FAR struct mm_map_entry_s *map);
/* The two structures need not be common after this point. The following
* are extended methods needed to deal with the unique needs of mounted
+13 -18
View File
@@ -134,55 +134,50 @@
#define _FIOCVALID(c) (_IOC_TYPE(c)==_FIOCBASE)
#define _FIOC(nr) _IOC(_FIOCBASE,nr)
#define FIOC_MMAP _FIOC(0x0001) /* IN: Location to return address (void **)
* OUT: If media is directly accessible,
* return (void*) base address
* of file
*/
#define FIOC_REFORMAT _FIOC(0x0002) /* IN: None
#define FIOC_REFORMAT _FIOC(0x0001) /* IN: None
* OUT: None
*/
#define FIOC_OPTIMIZE _FIOC(0x0003) /* IN: The number of bytes to recover
#define FIOC_OPTIMIZE _FIOC(0x0002) /* IN: The number of bytes to recover
* (ignored on most file systems)
* OUT: None
*/
#define FIOC_FILEPATH _FIOC(0x0004) /* IN: FAR char *(length >= PATH_MAX)
#define FIOC_FILEPATH _FIOC(0x0003) /* IN: FAR char *(length >= PATH_MAX)
* OUT: The full file path
*/
#define FIOC_INTEGRITY _FIOC(0x0005) /* Run a consistency check on the
#define FIOC_INTEGRITY _FIOC(0x0004) /* Run a consistency check on the
* file system media.
* IN: None
* OUT: None
*/
#define FIOC_DUMP _FIOC(0x0006) /* Dump logical content of media.
#define FIOC_DUMP _FIOC(0x0005) /* Dump logical content of media.
* IN: None
* OUT: None
*/
#define FIONREAD _FIOC(0x0007) /* IN: Location to return value (int *)
#define FIONREAD _FIOC(0x0006) /* IN: Location to return value (int *)
* OUT: Bytes readable from this fd
*/
#define FIONWRITE _FIOC(0x0008) /* IN: Location to return value (int *)
#define FIONWRITE _FIOC(0x0007) /* IN: Location to return value (int *)
* OUT: Number bytes in send queue
*/
#define FIONSPACE _FIOC(0x0009) /* IN: Location to return value (int *)
#define FIONSPACE _FIOC(0x0008) /* IN: Location to return value (int *)
* OUT: Free space in send queue.
*/
#define FIONUSERFS _FIOC(0x000a) /* IN: Pointer to struct usefs_config_s
#define FIONUSERFS _FIOC(0x0009) /* IN: Pointer to struct usefs_config_s
* holding userfs configuration.
* OUT: Instance number is returned on
* success.
*/
#define FIONBIO _FIOC(0x000b) /* IN: Boolean option takes an
#define FIONBIO _FIOC(0x000a) /* IN: Boolean option takes an
* int value.
* OUT: Origin option.
*/
#define FIOCLEX _FIOC(0x000c) /* IN: None
#define FIOCLEX _FIOC(0x000b) /* IN: None
* OUT: None
*/
#define FIONCLEX _FIOC(0x000d) /* IN: None
#define FIONCLEX _FIOC(0x000c) /* IN: None
* OUT: None
*/
#define FIOC_NOTIFY _FIOC(0x000e) /* IN: Pointer to struct automount_notify_s
#define FIOC_NOTIFY _FIOC(0x000d) /* IN: Pointer to struct automount_notify_s
* holding automount notification
* configuration
* OUT: None
+73
View File
@@ -0,0 +1,73 @@
/****************************************************************************
* include/nuttx/mm/map.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_MM_MAP_H
#define __INCLUDE_NUTTX_MM_MAP_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/queue.h>
#include <nuttx/mutex.h>
/****************************************************************************
* Public Types
****************************************************************************/
/* A memory mapping list item */
struct mm_map_entry_s
{
FAR struct mm_map_entry *flink; /* this is used as sq_entry_t */
FAR const void *vaddr;
size_t length;
off_t offset;
int prot;
int flags;
FAR void *priv;
/* Drivers which register mappings may also
* implement the unmap function to undo anything done in mmap.
* Nb. Implementation must NOT use "this_task()->group" since
* this is not valid during process exit. The argument "group" will be
* NULL in this case.
*/
int (*munmap)(FAR struct task_group_s *group,
FAR struct mm_map_entry_s *map,
FAR void *start,
size_t length);
};
/* A structure for the task group */
struct mm_map_s
{
sq_queue_t mm_map_sq;
mutex_t mm_map_mutex;
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#endif /* __INCLUDE_NUTTX_MM_MM_MAP_H */