MCPcopy Create free account
hub / github.com/Starry-OS/StarryOS / ioctl

Method ioctl

api/src/vfs/dev/loop.rs:81–147  ·  view source on GitHub ↗
(&self, cmd: u32, arg: usize)

Source from the content-addressed store, hash-verified

79 }
80
81 fn ioctl(&self, cmd: u32, arg: usize) -> VfsResult<usize> {
82 match cmd {
83 LOOP_SET_FD => {
84 let fd = arg as i32;
85 if fd < 0 {
86 return Err(AxError::BadFileDescriptor);
87 }
88 let f = get_file_like(fd)?;
89 let Some(file) = f.downcast_ref::<crate::file::File>() else {
90 return Err(AxError::InvalidInput);
91 };
92 let mut guard = self.file.lock();
93 if guard.is_some() {
94 return Err(AxError::ResourceBusy);
95 }
96
97 *guard = Some(file.inner().backend()?.clone());
98 }
99 LOOP_CLR_FD => {
100 let mut guard = self.file.lock();
101 if guard.is_none() {
102 return Err(AxError::from(LinuxError::ENXIO));
103 }
104 *guard = None;
105 }
106 LOOP_GET_STATUS => {
107 (arg as *mut loop_info).vm_write(self.get_info()?)?;
108 }
109 LOOP_SET_STATUS => {
110 // FIXME: AnyBitPattern
111 let info = unsafe { (arg as *const loop_info).vm_read_uninit()?.assume_init() };
112 self.set_info(info)?;
113 }
114 // TODO: the following should apply to any block devices
115 BLKGETSIZE | BLKGETSIZE64 => {
116 let file = self.clone_file()?;
117 let sectors = file.location().len()? / 512;
118 if cmd == BLKGETSIZE {
119 (arg as *mut u32).vm_write(sectors as _)?;
120 } else {
121 (arg as *mut u64).vm_write(sectors * 512)?;
122 }
123 }
124 BLKROGET => {
125 (arg as *mut u32).vm_write(self.ro.load(Ordering::Relaxed) as u32)?;
126 }
127 BLKROSET => {
128 let ro = (arg as *const u32).vm_read()?;
129 if ro != 0 && ro != 1 {
130 return Err(AxError::InvalidInput);
131 }
132 self.ro.store(ro != 0, Ordering::Relaxed);
133 }
134 BLKRAGET => {
135 (arg as *mut u32).vm_write(self.ra.load(Ordering::Relaxed))?;
136 }
137 BLKRASET => {
138 self.ra

Callers

nothing calls this directly

Calls 7

get_file_likeFunction · 0.85
get_infoMethod · 0.80
set_infoMethod · 0.80
clone_fileMethod · 0.80
loadMethod · 0.80
innerMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected