2008-02-01 23:19:20 +01:00
|
|
|
/****************************************************************************
|
2022-03-11 15:13:17 +01:00
|
|
|
* drivers/misc/dev_zero.c
|
2008-02-01 23:19:20 +01:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* 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
|
2008-02-01 23:19:20 +01:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-02-01 23:19:20 +01:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* 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.
|
2008-02-01 23:19:20 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2009-12-15 15:25:14 +01:00
|
|
|
#include <stdbool.h>
|
2008-02-01 23:19:20 +01:00
|
|
|
#include <string.h>
|
2008-11-17 21:24:28 +01:00
|
|
|
#include <poll.h>
|
2008-02-01 23:19:20 +01:00
|
|
|
#include <errno.h>
|
2016-07-20 21:15:37 +02:00
|
|
|
|
2017-10-04 23:22:27 +02:00
|
|
|
#include <nuttx/semaphore.h>
|
2012-03-21 19:01:07 +01:00
|
|
|
#include <nuttx/fs/fs.h>
|
2016-07-20 21:15:37 +02:00
|
|
|
#include <nuttx/drivers/drivers.h>
|
2008-02-01 23:19:20 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
static ssize_t devzero_read(FAR struct file *filep, FAR char *buffer,
|
|
|
|
size_t buflen);
|
|
|
|
static ssize_t devzero_write(FAR struct file *filep, FAR const char *buffer,
|
|
|
|
size_t buflen);
|
2013-09-29 00:50:07 +02:00
|
|
|
static int devzero_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
2015-10-10 18:41:00 +02:00
|
|
|
bool setup);
|
2008-02-01 23:19:20 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2009-06-10 17:22:49 +02:00
|
|
|
static const struct file_operations devzero_fops =
|
2008-02-01 23:19:20 +01:00
|
|
|
{
|
2016-05-26 18:01:15 +02:00
|
|
|
NULL, /* open */
|
|
|
|
NULL, /* close */
|
2008-02-01 23:19:20 +01:00
|
|
|
devzero_read, /* read */
|
|
|
|
devzero_write, /* write */
|
2016-05-26 18:01:15 +02:00
|
|
|
NULL, /* seek */
|
2019-05-22 02:57:54 +02:00
|
|
|
NULL, /* ioctl */
|
2022-12-22 11:51:59 +01:00
|
|
|
NULL, /* truncate */
|
2019-05-22 02:57:54 +02:00
|
|
|
devzero_poll /* poll */
|
2016-05-26 18:01:15 +02:00
|
|
|
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
|
|
|
, NULL /* unlink */
|
|
|
|
#endif
|
2008-02-01 23:19:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-11-17 21:24:28 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: devzero_read
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-09-29 00:50:07 +02:00
|
|
|
static ssize_t devzero_read(FAR struct file *filep, FAR char *buffer,
|
|
|
|
size_t len)
|
2008-02-01 23:19:20 +01:00
|
|
|
{
|
2022-07-11 17:11:40 +02:00
|
|
|
UNUSED(filep);
|
|
|
|
|
2008-02-02 16:04:39 +01:00
|
|
|
memset(buffer, 0, len);
|
|
|
|
return len;
|
2008-02-01 23:19:20 +01:00
|
|
|
}
|
|
|
|
|
2008-11-17 21:24:28 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: devzero_write
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-09-29 00:50:07 +02:00
|
|
|
static ssize_t devzero_write(FAR struct file *filep, FAR const char *buffer,
|
|
|
|
size_t len)
|
2008-02-01 23:19:20 +01:00
|
|
|
{
|
2022-07-11 17:11:40 +02:00
|
|
|
UNUSED(filep);
|
|
|
|
UNUSED(buffer);
|
|
|
|
|
2008-02-01 23:19:20 +01:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-11-17 21:24:28 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: devzero_poll
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-09-29 00:50:07 +02:00
|
|
|
static int devzero_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
2009-12-15 15:25:14 +01:00
|
|
|
bool setup)
|
2008-11-17 21:24:28 +01:00
|
|
|
{
|
2022-07-11 17:11:40 +02:00
|
|
|
UNUSED(filep);
|
|
|
|
|
2008-11-19 19:43:50 +01:00
|
|
|
if (setup)
|
2008-11-17 21:24:28 +01:00
|
|
|
{
|
2022-09-19 05:08:57 +02:00
|
|
|
poll_notify(&fds, 1, POLLIN | POLLOUT);
|
2008-11-17 21:24:28 +01:00
|
|
|
}
|
2019-10-26 17:35:32 +02:00
|
|
|
|
2008-11-17 21:24:28 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2008-02-01 23:19:20 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-08-03 21:11:11 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: devzero_register
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Register /dev/zero
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-02-01 23:19:20 +01:00
|
|
|
void devzero_register(void)
|
|
|
|
{
|
2020-01-02 17:49:34 +01:00
|
|
|
register_driver("/dev/zero", &devzero_fops, 0666, NULL);
|
2008-02-01 23:19:20 +01:00
|
|
|
}
|