2011-04-29 00:24:10 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* fs/nxffs/nxffs_ioctl.c
|
|
|
|
*
|
2021-02-03 14:47:23 +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
|
2011-04-29 00:24:10 +02:00
|
|
|
*
|
2021-02-03 14:47:23 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-29 00:24:10 +02:00
|
|
|
*
|
2021-02-03 14:47:23 +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.
|
2011-04-29 00:24:10 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2012-03-21 19:01:07 +01:00
|
|
|
#include <nuttx/fs/fs.h>
|
|
|
|
#include <nuttx/fs/ioctl.h>
|
2013-11-15 18:22:23 +01:00
|
|
|
#include <nuttx/mtd/mtd.h>
|
2011-04-29 00:24:10 +02:00
|
|
|
|
|
|
|
#include "nxffs.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxffs_ioctl
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Standard mountpoint ioctl method.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int nxffs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
FAR struct nxffs_volume_s *volume;
|
2011-05-05 22:01:43 +02:00
|
|
|
int ret;
|
2011-04-29 00:24:10 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("cmd: %d arg: %08lx\n", cmd, arg);
|
2011-04-29 00:24:10 +02:00
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
2023-08-28 11:17:05 +02:00
|
|
|
DEBUGASSERT(filep->f_priv != NULL);
|
2011-04-29 00:24:10 +02:00
|
|
|
|
|
|
|
/* Recover the file system state from the open file */
|
|
|
|
|
|
|
|
volume = filep->f_inode->i_private;
|
|
|
|
DEBUGASSERT(volume != NULL);
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
/* Get exclusive access to the volume. Note that the volume lock
|
2011-05-05 22:01:43 +02:00
|
|
|
* protects the open file list.
|
|
|
|
*/
|
2011-04-29 00:24:10 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&volume->lock);
|
2017-10-04 23:22:27 +02:00
|
|
|
if (ret < 0)
|
2011-05-05 22:01:43 +02:00
|
|
|
{
|
2023-04-06 08:16:37 +02:00
|
|
|
ferr("ERROR: nxmutex_lock failed: %d\n", ret);
|
2011-05-05 22:01:43 +02:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2011-05-06 01:31:44 +02:00
|
|
|
/* Only a reformat and optimize commands are supported */
|
2011-05-05 22:01:43 +02:00
|
|
|
|
|
|
|
if (cmd == FIOC_REFORMAT)
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Reformat command\n");
|
2011-05-05 22:01:43 +02:00
|
|
|
|
|
|
|
/* We cannot reformat the volume if there are any open inodes */
|
|
|
|
|
|
|
|
if (volume->ofiles)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Open files\n");
|
2011-05-05 22:01:43 +02:00
|
|
|
ret = -EBUSY;
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2011-05-05 22:01:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Re-format the volume -- all is lost */
|
|
|
|
|
|
|
|
ret = nxffs_reformat(volume);
|
|
|
|
}
|
|
|
|
|
2011-05-06 01:31:44 +02:00
|
|
|
else if (cmd == FIOC_OPTIMIZE)
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Optimize command\n");
|
2011-05-06 01:31:44 +02:00
|
|
|
|
|
|
|
/* Pack the volume */
|
|
|
|
|
|
|
|
ret = nxffs_pack(volume);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-13 01:23:03 +01:00
|
|
|
/* Command not recognized, forward to the MTD driver */
|
2011-05-05 22:01:43 +02:00
|
|
|
|
2018-12-13 01:23:03 +01:00
|
|
|
ret = MTD_IOCTL(volume->mtd, cmd, arg);
|
2011-05-06 01:31:44 +02:00
|
|
|
}
|
2011-05-05 22:01:43 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
errout_with_lock:
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&volume->lock);
|
2011-05-05 22:01:43 +02:00
|
|
|
errout:
|
|
|
|
return ret;
|
2011-04-29 00:24:10 +02:00
|
|
|
}
|