printf(STDOUT_FD, "Maximum Memory Size: 0x%x\n", memsz);
+ /* Extra Credit: Max no of file descriptors */
+ /* Game Plan: File descriptors are allocated sequentially, as we know this
+ * from the xv6 book's explanation on replacing stdin/stdout. We shall keep
+ * track of the current and last file descriptor and keep on duplicating an
+ * existing file until dup returns -1.
+ *
+ * To prove that this works, I'll also keep a manual file counter and ensure
+ * they match.
+ */
+ int curfd, prevfd;
+ // int manual_tally;
+
+ // POC verified
+ // manual_tally = 3;
+
+ curfd = 2; /* because stderr. Only used if first dup fails. */
+
+ while ((prevfd = curfd) && (curfd = dup(0)) >= 0);
+ // ++manual_tally;
+
+ printf(STDOUT_FD, "Maximum Number of Files Open at Once: %d\n",
+ prevfd + 1); // remember first valid descriptor is 0
+ // poc validated
+ // printf(STDOUT_FD, "Maximum Number of Files Open at Once: %d\n",
+ // manual_tally);
exit();
}