You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: fcntl.rs
    path of file: ./repos/maestro/src/syscall
    
    the code of the file until where you have to start completion: /*
 * Copyright 2024 Luc Len√¥tre
 *
 * This file is part of Maestro.
 *
 * Maestro is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * Maestro is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * Maestro. If not, see <https://www.gnu.org/licenses/>.
 */

//! The `fcntl` syscall call allows to manipulate a file descriptor.

use crate::errno::Errno;
use crate::file::buffer;
use crate::file::buffer::pipe::PipeBuffer;
use crate::file::fd::NewFDConstraint;
use crate::file::FileContent;
use crate::process::Process;
use core::ffi::c_int;
use core::ffi::c_void;
use macros::syscall;

/// Duplicate the file descriptor using the lowest numbered available file descriptor greater than
/// or equal to the specified argument.
const F_DUPFD: i32 = 0;
/// Return the file descriptor flags.
const F_GETFD: i32 = 1;
/// Set the file descriptor flags.
const F_SETFD: i32 = 2;
/// Return the file access mode and the file status flags.
const F_GETFL: i32 = 3;
/// Set the file status flag.
const F_SETFL: i32 = 4;
/// TODO doc
const F_GETLK: i32 = 5;
/// TODO doc
const F_SETLK: i32 = 6;
/// TODO doc
const F_SETLKW: i32 = 7;
/// Set the process ID or process group ID that 
    
pub fn do_fcntl(fd: i32, cmd: i32, arg: *mut c_void, _fcntl64: bool) -> Result<i32, Errno> {
	if fd < 0 {
		return Err(errno!(EBADF));
	}

	let fds_mutex = {
		let proc_mutex = Process::current_assert();
		let proc = proc_mutex.lock();

		proc.get_fds().unwrap().clone()
	};
	let mut fds = fds_mutex.lock();

	match cmd {
		F_DUPFD => Ok(fds
			.duplicate_fd(fd as _, NewFDConstraint::Min(arg as _), false)?
			.get_id() as _),

		F_GETFD => {
			let fd = fds.get_fd(fd as _).ok_or_else(|| errno!(EBADF))?;
			Ok(fd.get_flags())
		}

		F_SETFD => {
			let fd = fds.get_fd_mut(fd as _).ok_or_else(|| errno!(EBADF))?;
			fd.set_flags(arg as _);
			Ok(0)
		}

		F_GETFL => {
			let fd = fds.get_fd(fd as _).ok_or_else(|| errno!(EBADF))?;
			let open_file_mutex = fd.get_open_file();
			let open_file = open_file_mutex.lock();

			Ok(open_file.get_flags())
		}

		F_SETFL => {
			let fd = fds.get_fd(fd as _).ok_or_else(|| errno!(EBADF))?;
			let open_file_mutex = fd.get_open_file();
			let mut open_file = open_file_mutex.lock();

			open_file.set_flags(arg as _);
			Ok(0)
		}

		F_GETLK => {
			// TODO
			todo!();
		}

		F_SETLK => {
			// TODO
			todo!();
		}

		F_SETLKW => {
			// TODO
			todo!();
		}

		F_SETOWN => {
			// TODO
			todo!();
		}

		F_GETOWN => {
			// TODO
			todo!();
		}

		F_SETSIG => {
			// TODO
			todo!();
		}

		F_GETSIG => {
			// TODO
			todo!();
		}

		F_GETLK64 => {
			// TODO
			todo!();
		}

		F_SETLK64 => {
			// TODO
			todo!();
		}

		F_SETLKW64 => {
			// TODO
			todo!();
		}

		F_SETOWN_EX => {
			// TODO
			todo!();
		}

		F_GETOWN_EX => {
			// TODO
			todo!();
		}

		F_OFD_GETLK => {
			// TODO
			todo!();
		}

		F_OFD_SETLK => {
			// TODO
			todo!();
		}

		F_OFD_SETLKW => {
			// TODO
			todo!();
		}

		F_SETLEASE => {
			// TODO
			todo!();
		}

		F_GETLEASE => {
			// TODO
			todo!();
		}

		F_NOTIFY => {
			// TODO
			todo!();
		}

		F_DUPFD_CLOEXEC => Ok(fds
			.duplicate_fd(fd as _, NewFDConstraint::Min(arg as _), true)?
			.get_id() as _),

		F_SETPIPE_SZ => {
			// TODO
			todo!();
		}

		F_GETPIPE_SZ => {
			let fd = fds.get_fd(fd as _).ok_or_else(|| errno!(EBADF))?;

			let open_file_mutex = fd.get_open_file();
			let open_file = open_file_mutex.lock();

			let file_mutex = open_file.get_file();
			let file = file_mutex.lock();

			match file.get_content() {
				FileContent::Fifo => {
					let buf = buffer::get_or_default::<PipeBuffer>(file.get_location())?;
					let cap = buf.lock().get_capacity();
					Ok(cap as _)
				}
				_ => Ok(0),
			}
		}

		F_ADD_SEALS => {
			// TODO
			todo!();
		}

		F_GET_SEALS => {
			// TODO
			todo!();
		}

		F_GET_RW_HINT => {
			// TODO
			todo!();
		}

		F_SET_RW_HINT => {
			// TODO
			todo!();
		}

		F_GET_FILE_RW_HINT => {
			// TODO
			todo!();
		}

		F_SET_FILE_RW_HINT => {
			// TODO
			todo!();
		}

		_ => Err(errno!(EINVAL)),
	}
}