Skip to content

Commit

Permalink
format code, remove unused fn
Browse files Browse the repository at this point in the history
  • Loading branch information
coolyjg committed Dec 5, 2023
1 parent fa98772 commit 40d1727
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 158 deletions.
2 changes: 1 addition & 1 deletion api/arceos_posix_api/ctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <signal.h>
#include <stddef.h>
#include <sys/epoll.h>
#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/select.h>
#include <sys/socket.h>
Expand All @@ -28,4 +29,3 @@
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <sys/ioctl.h>
5 changes: 0 additions & 5 deletions api/arceos_posix_api/src/imp/fd_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub trait FileLike: Send + Sync {
fn into_any(self: Arc<Self>) -> Arc<dyn core::any::Any + Send + Sync>;
fn poll(&self) -> LinuxResult<PollState>;
fn set_nonblocking(&self, nonblocking: bool) -> LinuxResult;
fn set_closeonexec(&self, closeonexec: bool) -> LinuxResult;
}

lazy_static::lazy_static! {
Expand Down Expand Up @@ -147,10 +146,6 @@ pub fn sys_fcntl(fd: c_int, cmd: c_int, arg: usize) -> c_int {
// TODO: Change fd flags
dup_fd(fd)
}
ctypes::F_SETFD => {
get_file_like(fd)?.set_closeonexec(arg & (ctypes::O_CLOEXEC as usize) > 0)?;
Ok(0)
}
ctypes::F_SETFL => {
if fd == 0 || fd == 1 || fd == 2 {
return Ok(0);
Expand Down
23 changes: 19 additions & 4 deletions api/arceos_posix_api/src/imp/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ impl FileLike for File {
fn set_nonblocking(&self, _nonblocking: bool) -> LinuxResult {
Ok(())
}

fn set_closeonexec(&self, _closeonexec: bool) -> LinuxResult {
Ok(())
}
}

/// Convert open flags to [`OpenOptions`].
Expand Down Expand Up @@ -387,3 +383,22 @@ pub fn sys_mkdirat(fd: c_int, pathname: *const c_char, mode: ctypes::mode_t) ->
);
sys_mkdir(pathname, mode)
}

/// Changes the ownership of the file referred to by the open file descriptor fd
pub fn sys_fchownat(
fd: c_int,
path: *const c_char,
uid: ctypes::uid_t,
gid: ctypes::gid_t,
flag: c_int,
) -> c_int {
debug!(
"sys_fchownat <= fd: {}, path: {:?}, uid: {}, gid: {}, flag: {}",
fd,
char_ptr_to_str(path),
uid,
gid,
flag
);
syscall_body!(sys_fchownat, Ok(0))
}
44 changes: 16 additions & 28 deletions api/arceos_posix_api/src/imp/io_mpx/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ impl FileLike for EpollInstance {
fn set_nonblocking(&self, _nonblocking: bool) -> LinuxResult {
Ok(())
}

fn set_closeonexec(&self, _closeonexec: bool) -> LinuxResult {
Ok(())
}
}

/// Creates a new epoll instance.
Expand Down Expand Up @@ -219,37 +215,29 @@ pub unsafe fn sys_epoll_wait(
loop {
#[cfg(feature = "net")]
axnet::poll_interfaces();

let poll_all_res = epoll_instance.poll_all(events);
let mut events_num = 0;
match poll_all_res {
Ok(num) => events_num = num,
Err(e) => {
error!("sys epoll events err {:?}", e);
if e == LinuxError::EBADF {
let mut deleted_fd: usize = 0;
{
let ready_list = epoll_instance.events.lock();
for (infd, _ev) in ready_list.iter() {
match get_file_like(*infd as c_int) {
Ok(_) => {}
Err(_) => {
warn!("sys epoll deleted fd err {}", *infd);
deleted_fd = *infd;
break;
}
}
}
Err(LinuxError::EBADF) => {
error!("sys_epoll_wait a non-exist fd");
let mut events = epoll_instance.events.lock();
let del_fds = events
.iter()
.filter(|(&fd, _)| get_file_like(fd as _).is_err())
.map(|(&fd, _)| fd)
.collect::<alloc::vec::Vec<_>>();
del_fds.iter().for_each(|&fd| {
if let Entry::Occupied(ocp) = events.entry(fd) {
ocp.remove_entry();
}
{
let mut events = epoll_instance.events.lock();
if let Entry::Occupied(ocp) = events.entry(deleted_fd) {
ocp.remove_entry();
}
}
return Ok(0);
}
});
return Ok(0);
}
Err(_) => {}
}

if events_num > 0 {
return Ok(events_num as c_int);
}
Expand Down
3 changes: 1 addition & 2 deletions api/arceos_posix_api/src/imp/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* See the Mulan PSL v2 for more details.
*/

#[cfg(feature = "fd")]
use crate::imp::fd_ops::get_file_like;
use axerrno::LinuxError;
use core::ffi::c_int;
Expand All @@ -17,7 +16,7 @@ pub const TCGETS: usize = 0x5401;
pub const TIOCGPGRP: usize = 0x540F;
pub const TIOCSPGRP: usize = 0x5410;
pub const TIOCGWINSZ: usize = 0x5413;
pub const FIONBIO: usize = 21537;
pub const FIONBIO: usize = 0x5421;

#[derive(Clone, Copy, Default)]
pub struct ConsoleWinSize {
Expand Down
4 changes: 0 additions & 4 deletions api/arceos_posix_api/src/imp/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,6 @@ impl FileLike for Socket {
}
Ok(())
}

fn set_closeonexec(&self, _closeonexec: bool) -> LinuxResult {
Ok(())
}
}

impl From<SocketAddrV4> for ctypes::sockaddr_in {
Expand Down
4 changes: 0 additions & 4 deletions api/arceos_posix_api/src/imp/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,6 @@ impl FileLike for Pipe {
fn set_nonblocking(&self, _nonblocking: bool) -> LinuxResult {
Ok(())
}

fn set_closeonexec(&self, _closeonexec: bool) -> LinuxResult {
Ok(())
}
}

/// Create a pipe
Expand Down
5 changes: 5 additions & 0 deletions api/arceos_posix_api/src/imp/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ pub fn sys_umask(mode: ctypes::mode_t) -> ctypes::mode_t {
debug!("sys_umask <= mode: {:x}", mode);
syscall_body!(sys_umask, Ok(0))
}

/// Returns the effective user ID of the calling process
pub fn sys_geteuid() -> core::ffi::c_uint {
syscall_body!(sys_geteuid, Ok(0))
}
8 changes: 0 additions & 8 deletions api/arceos_posix_api/src/imp/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ impl super::fd_ops::FileLike for Stdin {
fn set_nonblocking(&self, _nonblocking: bool) -> LinuxResult {
Ok(())
}

fn set_closeonexec(&self, _closeonexec: bool) -> LinuxResult {
Ok(())
}
}

#[cfg(feature = "fd")]
Expand Down Expand Up @@ -180,8 +176,4 @@ impl super::fd_ops::FileLike for Stdout {
fn set_nonblocking(&self, _nonblocking: bool) -> LinuxResult {
Ok(())
}

fn set_closeonexec(&self, _closeonexec: bool) -> LinuxResult {
Ok(())
}
}
6 changes: 6 additions & 0 deletions api/arceos_posix_api/src/imp/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ pub unsafe extern "C" fn sys_sysinfo(info: *mut ctypes::sysinfo) -> c_int {
Ok(0)
})
}

/// Print system information
pub fn sys_uname(_uts: *mut core::ffi::c_void) -> c_int {
debug!("sys_uname not implemented");
syscall_body!(sys_uname, Ok(0))
}
10 changes: 5 additions & 5 deletions api/arceos_posix_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ pub mod ctypes;
pub use imp::io::{sys_read, sys_readv, sys_write, sys_writev};
pub use imp::resources::{sys_getrlimit, sys_prlimit64, sys_setrlimit};
pub use imp::rt_sig::{sys_rt_sigaction, sys_rt_sigprocmask};
pub use imp::stat::sys_umask;
pub use imp::sys::sys_sysinfo;
pub use imp::stat::{sys_geteuid, sys_umask};
pub use imp::sys::{sys_sysinfo, sys_uname};
pub use imp::sys_invalid;
pub use imp::task::{sys_exit, sys_getpid, sys_sched_yield};
pub use imp::time::{sys_clock_gettime, sys_clock_settime, sys_nanosleep};
Expand All @@ -60,9 +60,9 @@ pub use imp::fd_ops::sys_dup3;
pub use imp::fd_ops::{sys_close, sys_dup, sys_dup2, sys_fcntl};
#[cfg(feature = "fs")]
pub use imp::fs::{
sys_fdatasync, sys_fstat, sys_fsync, sys_getcwd, sys_lseek, sys_lstat, sys_mkdir, sys_mkdirat,
sys_newfstatat, sys_open, sys_openat, sys_rename, sys_renameat, sys_rmdir, sys_stat,
sys_unlink, sys_unlinkat,
sys_fchownat, sys_fdatasync, sys_fstat, sys_fsync, sys_getcwd, sys_lseek, sys_lstat, sys_mkdir,
sys_mkdirat, sys_newfstatat, sys_open, sys_openat, sys_rename, sys_renameat, sys_rmdir,
sys_stat, sys_unlink, sys_unlinkat,
};
#[cfg(feature = "epoll")]
pub use imp::io_mpx::{sys_epoll_create, sys_epoll_ctl, sys_epoll_pwait, sys_epoll_wait};
Expand Down
2 changes: 1 addition & 1 deletion apps/c/nginx/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
nginx-app
html
*.img
*.img
85 changes: 0 additions & 85 deletions apps/c/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,47 +1,23 @@

#user nobody;
worker_processes 1;
daemon off;
master_process off;

#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log debug;

#pid logs/nginx.pid;


events {
worker_connections 32;
}


http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

#sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 5555;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

index index.html;

root /v9fs;
Expand All @@ -55,71 +31,10 @@ http {
root /v9fs;
}

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /v9fs;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}


# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}
10 changes: 2 additions & 8 deletions modules/axfs/src/fs/fatfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,10 @@ impl VfsNodeOps for FileWrapper<'static> {

let mut total_read = 0;
while total_read < buf.len() {
let remaining = &mut buf[total_read..];
let read_len = file.read(remaining).map_err(as_vfs_err)?;

let read_len = file.read(&mut buf[total_read..]).map_err(as_vfs_err)?;
if read_len == 0 {
break;
}

total_read += read_len;
}

Expand All @@ -107,13 +104,10 @@ impl VfsNodeOps for FileWrapper<'static> {

let mut total_write = 0;
while total_write < buf.len() {
let remaining = &buf[total_write..];
let write_len = file.write(remaining).map_err(as_vfs_err)?;

let write_len = file.write(&buf[total_write..]).map_err(as_vfs_err)?;
if write_len == 0 {
break;
}

total_write += write_len;
}

Expand Down
Loading

0 comments on commit 40d1727

Please sign in to comment.