@@ -114,7 +114,7 @@ impl From<FileStatus> for c::Status {
114114 }
115115}
116116
117- #[ derive( Clone ) ]
117+ #[ derive( Clone , Debug ) ]
118118pub enum NewStatusListenerFilter {
119119 Never ,
120120 OffToOn ,
@@ -260,15 +260,31 @@ impl IsSend for PosixFile {}
260260impl IsSync for PosixFile { }
261261
262262impl PosixFile {
263- pub fn read ( & mut self , bytes : & mut [ u8 ] , event_queue : & mut EventQueue ) -> SyscallReturn {
263+ pub fn close ( & mut self , event_queue : & mut EventQueue ) -> SyscallReturn {
264264 match self {
265- Self :: Pipe ( f) => f. read ( bytes , event_queue) ,
265+ Self :: Pipe ( f) => f. close ( event_queue) ,
266266 }
267267 }
268268
269- pub fn write ( & mut self , bytes : & [ u8 ] , event_queue : & mut EventQueue ) -> SyscallReturn {
269+ pub fn read (
270+ & mut self ,
271+ bytes : & mut [ u8 ] ,
272+ offset : libc:: off_t ,
273+ event_queue : & mut EventQueue ,
274+ ) -> SyscallReturn {
275+ match self {
276+ Self :: Pipe ( f) => f. read ( bytes, offset, event_queue) ,
277+ }
278+ }
279+
280+ pub fn write (
281+ & mut self ,
282+ bytes : & [ u8 ] ,
283+ offset : libc:: off_t ,
284+ event_queue : & mut EventQueue ,
285+ ) -> SyscallReturn {
270286 match self {
271- Self :: Pipe ( f) => f. write ( bytes, event_queue) ,
287+ Self :: Pipe ( f) => f. write ( bytes, offset , event_queue) ,
272288 }
273289 }
274290
@@ -303,6 +319,20 @@ impl PosixFile {
303319 }
304320}
305321
322+ impl std:: fmt:: Debug for PosixFile {
323+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
324+ match self {
325+ Self :: Pipe ( _) => write ! ( f, "Pipe" ) ?,
326+ }
327+ write ! (
328+ f,
329+ "(status: {:?}, flags: {:?})" ,
330+ self . status( ) ,
331+ self . get_flags( )
332+ )
333+ }
334+ }
335+
306336bitflags:: bitflags! {
307337 // Linux only supports a single descriptor flag:
308338 // https://www.gnu.org/software/libc/manual/html_node/Descriptor-Flags.html
@@ -311,17 +341,24 @@ bitflags::bitflags! {
311341 }
312342}
313343
314- #[ derive( Clone ) ]
344+ #[ derive( Clone , Debug ) ]
315345pub struct Descriptor {
346+ /// The PosixFile that this descriptor points to.
316347 file : Arc < AtomicRefCell < PosixFile > > ,
348+ /// Descriptor flags.
317349 flags : DescriptorFlags ,
350+ /// A count of how many open descriptors there are with reference to this file. Since a
351+ /// reference to the file can be held by other objects like an epoll file, it should
352+ /// be true that `Arc::strong_count(&self.count)` <= `Arc::strong_count(&self.file)`.
353+ open_count : Arc < ( ) > ,
318354}
319355
320356impl Descriptor {
321357 pub fn new ( file : Arc < AtomicRefCell < PosixFile > > ) -> Self {
322358 Self {
323359 file,
324360 flags : DescriptorFlags :: empty ( ) ,
361+ open_count : Arc :: new ( ( ) ) ,
325362 }
326363 }
327364
@@ -336,6 +373,10 @@ impl Descriptor {
336373 pub fn set_flags ( & mut self , flags : DescriptorFlags ) {
337374 self . flags = flags;
338375 }
376+
377+ pub fn get_open_count ( & self ) -> usize {
378+ Arc :: < ( ) > :: strong_count ( & self . open_count )
379+ }
339380}
340381
341382// don't implement copy or clone without considering the legacy descriptor's ref count
0 commit comments