Use raw pointer instead of shared_ptr

Throughout update_engine, there are many places we pass a shared_ptr of
FileDescriptor, for memory safety. But in many cases, functions only
need to use the pointer througout execution of the function, and do not
need to store these pointers. In these cases, it's perfectly safe to use
a raw pointer. Furthermore, the overuse of shared_ptr make life time of
FileDescriptors unpredictable. This is harmful in context of VABC, where
presence of a file descriptor can cause UnmapAllPartitions() to fail.
Therefore, we switch some of the safe usecases to raw pointer.

Test: th
Bug: 216391325
Change-Id: I3d986688e81fcc1d761b7f4926a3c81ac691788a
diff --git a/common/utils.h b/common/utils.h
index a33efb2..0f8da22 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -68,12 +68,15 @@
 bool WriteAll(int fd, const void* buf, size_t count);
 bool PWriteAll(int fd, const void* buf, size_t count, off_t offset);
 
-bool WriteAll(const FileDescriptorPtr& fd, const void* buf, size_t count);
+bool WriteAll(FileDescriptor* fd, const void* buf, size_t count);
+
+constexpr bool WriteAll(const FileDescriptorPtr& fd,
+                        const void* buf,
+                        size_t count) {
+  return WriteAll(fd.get(), buf, count);
+}
 // WriteAll writes data at specified offset, but it modifies file position.
-bool WriteAll(const FileDescriptorPtr& fd,
-              const void* buf,
-              size_t count,
-              off_t off);
+bool WriteAll(FileDescriptorPtr* fd, const void* buf, size_t count, off_t off);
 
 // https://man7.org/linux/man-pages/man2/pread.2.html
 // PWriteAll writes data at specified offset, but it DOES NOT modify file
@@ -97,21 +100,38 @@
     int fd, void* buf, size_t count, off_t offset, ssize_t* out_bytes_read);
 
 // Reads data at specified offset, this function does change file position.
-bool ReadAll(const FileDescriptorPtr& fd,
+
+bool ReadAll(FileDescriptor* fd,
              void* buf,
              size_t count,
              off_t offset,
              ssize_t* out_bytes_read);
 
+constexpr bool ReadAll(const FileDescriptorPtr& fd,
+                       void* buf,
+                       size_t count,
+                       off_t offset,
+                       ssize_t* out_bytes_read) {
+  return ReadAll(fd.get(), buf, count, offset, out_bytes_read);
+}
+
 // https://man7.org/linux/man-pages/man2/pread.2.html
 // Reads data at specified offset, this function DOES NOT change file position.
 // Behavior is similar to linux's pread syscall.
-bool PReadAll(const FileDescriptorPtr& fd,
+bool PReadAll(FileDescriptor* fd,
               void* buf,
               size_t count,
               off_t offset,
               ssize_t* out_bytes_read);
 
+constexpr bool PReadAll(const FileDescriptorPtr& fd,
+                        void* buf,
+                        size_t count,
+                        off_t offset,
+                        ssize_t* out_bytes_read) {
+  return PReadAll(fd.get(), buf, count, offset, out_bytes_read);
+}
+
 // Opens |path| for reading and appends its entire content to the container
 // pointed to by |out_p|. Returns true upon successfully reading all of the
 // file's content, false otherwise, in which case the state of the output