Pārlūkot izejas kodu

Kernel: Correctly decode proc_file_type from identifier

inode identifiers in ProcFS are encoded in a way that the parent ID is
shifted 12 bits to the left and the PID is shifted by 16 bits. This
means that the rightmost 12 bits are reserved for the file type or the
fd.

Since the to_fd and to_proc_file_type decoders only decoded the
rightmost 8 bits, decoded values would wrap around beyond values of 255,
resulting in a different value compared to what was originally encoded.
Tim Schumacher 4 gadi atpakaļ
vecāks
revīzija
9559ac9dd6
1 mainītis faili ar 2 papildinājumiem un 2 dzēšanām
  1. 2 2
      Kernel/FileSystem/ProcFS.cpp

+ 2 - 2
Kernel/FileSystem/ProcFS.cpp

@@ -126,13 +126,13 @@ static inline ProcParentDirectory to_proc_parent_directory(const InodeIdentifier
 
 static inline ProcFileType to_proc_file_type(const InodeIdentifier& identifier)
 {
-    return (ProcFileType)(identifier.index().value() & 0xff);
+    return (ProcFileType)(identifier.index().value() & 0xfff);
 }
 
 static inline int to_fd(const InodeIdentifier& identifier)
 {
     VERIFY(to_proc_parent_directory(identifier) == PDI_PID_fd);
-    return (identifier.index().value() & 0xff) - FI_MaxStaticFileIndex;
+    return (identifier.index().value() & 0xfff) - FI_MaxStaticFileIndex;
 }
 
 static inline size_t to_sys_index(const InodeIdentifier& identifier)