FIX: default kreadoff/kwriteoff must accept offset=0 for non-positioned I/O
The previous default only accepted u64::MAX as 'stream write' offset, but sys_write/sys_read pass offset=0 for non-positioned I/O. This caused ESPIPE on all writes to non-positioned FDs (Debug/stdout). Now both u64::MAX and 0 are accepted as 'no offset' for the default implementation. Schemes that override kwriteoff (AddrSpace) still handle offset=0 correctly.
This commit is contained in:
+4
-2
@@ -551,7 +551,9 @@ pub trait KernelScheme: Send + Sync + 'static {
|
||||
stored_flags: u32,
|
||||
token: &mut CleanLockToken,
|
||||
) -> Result<usize> {
|
||||
if offset != u64::MAX {
|
||||
// u64::MAX = explicit stream write; 0 = non-positioned write from sys_write/sys_read.
|
||||
// Any other offset would imply seeking on a non-seekable scheme.
|
||||
if offset != u64::MAX && offset != 0 {
|
||||
return Err(Error::new(ESPIPE));
|
||||
}
|
||||
self.kwrite(id, buf, flags, stored_flags, token)
|
||||
@@ -565,7 +567,7 @@ pub trait KernelScheme: Send + Sync + 'static {
|
||||
stored_flags: u32,
|
||||
token: &mut CleanLockToken,
|
||||
) -> Result<usize> {
|
||||
if offset != u64::MAX {
|
||||
if offset != u64::MAX && offset != 0 {
|
||||
return Err(Error::new(ESPIPE));
|
||||
}
|
||||
self.kread(id, buf, flags, stored_flags, token)
|
||||
|
||||
+2
-2
@@ -832,7 +832,7 @@ pub fn sys_read(fd: FileHandle, buf: UserSliceWo, token: &mut CleanLockToken) ->
|
||||
let offset = if desc.internal_flags.contains(InternalFlags::POSITIONED) {
|
||||
desc.offset
|
||||
} else {
|
||||
u64::MAX
|
||||
0
|
||||
};
|
||||
Ok((
|
||||
scheme.kreadoff(desc.number, buf, offset, desc.flags, desc.flags, token)?,
|
||||
@@ -861,7 +861,7 @@ pub fn sys_write(fd: FileHandle, buf: UserSliceRo, token: &mut CleanLockToken) -
|
||||
let offset = if desc.internal_flags.contains(InternalFlags::POSITIONED) {
|
||||
desc.offset
|
||||
} else {
|
||||
u64::MAX
|
||||
0
|
||||
};
|
||||
Ok((
|
||||
scheme.kwriteoff(desc.number, buf, offset, desc.flags, desc.flags, token)?,
|
||||
|
||||
Reference in New Issue
Block a user