Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Filelock #11724

Merged
merged 8 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -8564,3 +8564,72 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
include/search.h
======================
$NetBSD: search.h,v 1.12 1999/02/22 10:34:28 christos Exp $
$FreeBSD: src/include/search.h,v 1.4 2002/03/23 17:24:53 imp Exp $

Written by J.T. Conklin <jtc@netbsd.org>
Public domain.

libs/libc/search/hcreate.c
libs/libc/search/hcreate_r.c
======================
$NetBSD: hcreate.c,v 1.2 2001/02/19 21:26:04 ross Exp $

Copyright (c) 2001 Christopher G. Demetriou
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

libs/libc/search/hash_func.c
======================
Copyright (c) 1990, 1993
The Regents of the University of California. All rights reserved.

This code is derived from software contributed to Berkeley by
Margo Seltzer.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
4 changes: 4 additions & 0 deletions fs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ config FS_NEPOLL_DESCRIPTORS
---help---
The maximum number of default epoll descriptors for epoll_create1(2)

config FS_LOCK_BUCKET_SIZE
int "Maximum number of hash bucket using file locks"
default 0

config DISABLE_PSEUDOFS_OPERATIONS
bool "Disable pseudo-filesystem operations"
default DEFAULT_SMALL
Expand Down
3 changes: 3 additions & 0 deletions fs/fs_initialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "rpmsgfs/rpmsgfs.h"
#include "inode/inode.h"
#include "aio/aio.h"
#include "vfs/lock.h"

/****************************************************************************
* Private Functions
Expand Down Expand Up @@ -83,6 +84,8 @@ void fs_initialize(void)

inode_initialize();

file_initlk();

#ifdef CONFIG_FS_AIO
/* Initialize for asynchronous I/O */

Expand Down
4 changes: 4 additions & 0 deletions fs/vfs/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ CSRCS += fs_syncfs.c fs_truncate.c

# Certain interfaces are not available if there is no mountpoint support

ifneq ($(CONFIG_FS_LOCK_BUCKET_SIZE),0)
CSRCS += fs_lock.c
crafcat7 marked this conversation as resolved.
Show resolved Hide resolved
endif

ifneq ($(CONFIG_PSEUDOFS_SOFTLINKS),0)
CSRCS += fs_link.c fs_symlink.c fs_readlink.c
endif
Expand Down
3 changes: 3 additions & 0 deletions fs/vfs/fs_close.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <nuttx/fs/fs.h>

#include "inode/inode.h"
#include "vfs/lock.h"

/****************************************************************************
* Public Functions
Expand Down Expand Up @@ -65,6 +66,8 @@ int file_close(FAR struct file *filep)

if (inode)
{
file_closelk(filep);

/* Close the file, driver, or mountpoint. */

if (inode->u.i_ops && inode->u.i_ops->close)
Expand Down
20 changes: 18 additions & 2 deletions fs/vfs/fs_fcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <nuttx/fs/fs.h>

#include "inode/inode.h"
#include "lock.h"

/****************************************************************************
* Private Functions
Expand Down Expand Up @@ -195,6 +196,12 @@ static int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
* for the lock type which shall be set to F_UNLCK.
*/

{
FAR struct flock *flock = va_arg(ap, FAR struct flock *);
ret = file_getlk(filep, flock);
}

break;
case F_SETLK:
/* Set or clear a file segment lock according to the lock
* description pointed to by the third argument, arg, taken as a
Expand All @@ -206,6 +213,12 @@ static int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
* shall return immediately with a return value of -1.
*/

{
FAR struct flock *flock = va_arg(ap, FAR struct flock *);
ret = file_setlk(filep, flock, true);
}

break;
case F_SETLKW:
/* This command shall be equivalent to F_SETLK except that if a
* shared or exclusive lock is blocked by other locks, the thread
Expand All @@ -216,9 +229,12 @@ static int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
* the lock operation shall not be done.
*/

ret = -ENOSYS; /* Not implemented */
break;
{
FAR struct flock *flock = va_arg(ap, FAR struct flock *);
ret = file_setlk(filep, flock, false);
}

break;
case F_GETPATH:
/* Get the path of the file descriptor. The argument must be a buffer
* of size PATH_MAX or greater.
Expand Down
Loading
Loading