]> git.saurik.com Git - apple/system_cmds.git/blobdiff - fs_usage.tproj/fs_usage.c
system_cmds-279.6.1.tar.gz
[apple/system_cmds.git] / fs_usage.tproj / fs_usage.c
index 62ffde951b44dbde6ed7c039325a6d42e87db96c..041d30c88163e6d7dba45b3feedebf8313179127 100644 (file)
@@ -266,6 +266,10 @@ void            create_map_entry(int, int, char *);
 #define BSC_rmdir    0x040C0224
 #define BSC_utimes   0x040C0228
 #define BSC_futimes  0x040C022C
+#define BSC_pread    0x040C0264
+#define BSC_pread_extended    0x040E0264
+#define BSC_pwrite   0x040C0268
+#define BSC_pwrite_extended   0x040E0268
 #define BSC_statfs   0x040C0274        
 #define BSC_fstatfs  0x040C0278        
 #define BSC_stat     0x040C02F0        
@@ -914,6 +918,7 @@ sample_sc()
                 struct diskio  *dio;
                void enter_syscall();
                void exit_syscall();
+               void extend_syscall();
                void kill_thread_map();
 
                thread  = kd[i].arg5 & KDBG_THREAD_MASK;
@@ -1297,7 +1302,12 @@ sample_sc()
                        enter_syscall(thread, type, &kd[i], p, (double)now);
                        continue;
                }
+               
                switch (type) {
+                   
+               case BSC_pread_extended:
+               case BSC_pwrite_extended:
+                   extend_syscall(thread, type, &kd[i], (double)now);
 
                case MACH_pageout:
                    if (kd[i].arg2) 
@@ -1504,6 +1514,14 @@ sample_sc()
                    exit_syscall("writev", thread, type, kd[i].arg1, kd[i].arg2, 1, 1, (double)now);
                    break;
 
+               case BSC_pread:
+                   exit_syscall("pread", thread, type, kd[i].arg1, kd[i].arg2, 1, 9, (double)now);
+                   break;
+
+               case BSC_pwrite:
+                   exit_syscall("pwrite", thread, type, kd[i].arg1, kd[i].arg2, 1, 9, (double)now);
+                   break;
+
                case BSC_fchown:
                    exit_syscall("fchown", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now);
                    break;
@@ -1879,6 +1897,8 @@ enter_syscall(int thread, int type, kd_buf *kd, char *name, double now)
        case BSC_fsync:
        case BSC_readv:
        case BSC_writev:
+       case BSC_pread:
+       case BSC_pwrite:
        case BSC_fchown:
        case BSC_fchmod:
        case BSC_rename:
@@ -1999,13 +2019,13 @@ enter_syscall(int thread, int type, kd_buf *kd, char *name, double now)
                   }
 
                   /* Print timestamp column */
-                  printf(buf);
+                  printf("%s", buf);
 
                   map = find_thread_map(thread);
                   if (map) {
                       sprintf(buf, "  %-25.25s ", name);
                       nmclen = strlen(buf);
-                      printf(buf);
+                      printf("%s", buf);
 
                       sprintf(buf, "(%d, 0x%x, 0x%x, 0x%x)", (short)kd->arg1, kd->arg2, kd->arg3, kd->arg4);
                       argsclen = strlen(buf);
@@ -2022,17 +2042,17 @@ enter_syscall(int thread, int type, kd_buf *kd, char *name, double now)
 
                       if(clen > 0)
                         {
-                          printf(buf);   /* print the kdargs */
+                          printf("%s", buf);   /* print the kdargs */
                           memset(buf, ' ', clen);
                           buf[clen] = '\0';
-                          printf(buf);
+                          printf("%s", buf);
                         }
                       else if ((argsclen + clen) > 0)
                         {
                           /* no room so wipe out the kdargs */
                           memset(buf, ' ', (argsclen + clen));
                           buf[argsclen + clen] = '\0';
-                          printf(buf);
+                          printf("%s", buf);
                         }
 
                       if (columns > MAXCOLS || wideflag)
@@ -2062,6 +2082,40 @@ enter_syscall(int thread, int type, kd_buf *kd, char *name, double now)
        fflush (0);
 }
 
+/*
+ * Handle system call extended trace data.
+ * pread and pwrite:
+ *     Wipe out the kd args that were collected upon syscall_entry
+ *     because it is the extended info that we really want, and it
+ *     is all we really need.
+*/
+
+void
+extend_syscall(int thread, int type, kd_buf *kd, char *name, double now)
+{
+       struct th_info *ti;
+
+       switch (type) {
+       case BSC_pread_extended:
+          if ((ti = find_thread(thread, BSC_pread)) == (struct th_info *)0)
+              return;
+          ti->arg1   = kd->arg1;  /* the fd */
+          ti->arg2   = kd->arg2;  /* nbytes */
+          ti->arg3   = kd->arg3;  /* top half offset */
+          ti->arg4   = kd->arg4;  /* bottom half offset */        
+          break;
+       case BSC_pwrite_extended:
+          if ((ti = find_thread(thread, BSC_pwrite)) == (struct th_info *)0)
+              return;
+          ti->arg1   = kd->arg1;  /* the fd */
+          ti->arg2   = kd->arg2;  /* nbytes */
+          ti->arg3   = kd->arg3;  /* top half offset */
+          ti->arg4   = kd->arg4;  /* bottom half offset */
+          break;
+       default:
+          return;
+       }
+}
 
 void
 exit_syscall(char *sc_name, int thread, int type, int error, int retval,
@@ -2150,7 +2204,9 @@ format_print(struct th_info *ti, char *sc_name, int thread, int type, int error,
                 else
                     sprintf(&buf[clen], "  B=0x%-6x   /dev/%s", dio->iosize, find_disk_name(dio->dev));
             } else {
-              
+
+               off_t offset_reassembled = 0LL;
+               
               if (has_fd == 2 && error == 0)
                       sprintf(&buf[clen], " F=%-3d", retval);
               else if (has_fd == 1)
@@ -2179,12 +2235,22 @@ format_print(struct th_info *ti, char *sc_name, int thread, int type, int error,
                       sprintf(&buf[clen], "B=0x%-8x", retval);
               else if (has_ret == 8)  /* BSC_select */
                       sprintf(&buf[clen], "  S=%-3d     ", retval);           
+              else if (has_ret == 9)  /* BSC_pread, BSC_pwrite */
+              {
+                  sprintf(&buf[clen], "B=0x%-8x", retval);
+                  clen = strlen(buf);
+                  offset_reassembled = (((off_t)(unsigned int)(ti->arg3)) << 32) | (unsigned int)(ti->arg4);
+                  if ((offset_reassembled >> 32) != 0)
+                      sprintf(&buf[clen], "O=0x%16.16qx", (off_t)offset_reassembled);
+                  else
+                      sprintf(&buf[clen], "O=0x%8.8qx", (off_t)offset_reassembled);
+              }
               else
                       sprintf(&buf[clen], "            ");
             }
             clen = strlen(buf);
        }
-       printf(buf);
+       printf("%s", buf);
 
        /*
         Calculate space available to print pathname
@@ -2211,17 +2277,17 @@ format_print(struct th_info *ti, char *sc_name, int thread, int type, int error,
           */
           memset(&buf[len], ' ', clen - len);
           buf[clen] = '\0';
-          printf(buf);
+          printf("%s", buf);
         }
        else if (clen == len)
         {
-          printf(buf);
+          printf("%s", buf);
         }
        else if ((clen > 0) && (clen < len))
         {
           /* This prints the tail end of the pathname */
           buf[len-clen] = ' ';
-          printf(&buf[len - clen]);
+          printf("%s", &buf[len - clen]);
         }
 
        usecs = (unsigned long)((now - stime) / divisor);