static void print_table_entry(NVCTRLAttributePermissionsRec *perms, const int index, const char *name) { /* * Don't print the attribute if *both* the permissions are empty * and the attribute table was missing an entry for the attribute. * Either condition by itself is acceptable: * * - Event-only attributes (e.g., NV_CTRL_GVO_CSC_CHANGED_EVENT) * don't have any permissions. * * - A missing table entry could just mean the table is stale * relative to NVCtrl.h. */ if ((perms->permissions == 0) && (name == NULL)) { return; } printf(" (%3d) [Perms: ", index); print_perms(perms); printf("] [ "); printf("%-32s", GetAttrTypeName(perms->type)); printf("] - %s\n", name ? name : "Unknown"); }
int sem_stat_sem( void ) { int maxid, semid, id; struct semid_ds semary; struct seminfo seminfo; struct ipc_perm *ipcp = &semary.sem_perm; struct passwd *pw = NULL; union semun arg; arg.array = (unsigned short *) (void *) &seminfo; maxid = semctl(0, 0, SEM_INFO, arg); if (maxid < 0) { DEBUG_PRINTF("kernel not configured for %s\n", "semaphores"); return -1; } for(id = 0; id <= maxid; id++) { arg.buf = (struct semid_ds *) &semary; semid = semctl(id, 0, SEM_STAT, arg); if (semid < 0) continue; ipcp = &semary.sem_perm; if(1) { print_perms(semid, ipcp); } pw = getpwuid(ipcp->uid); if (pw) printf("%-8d %-10.10s", semid, pw->pw_name); else printf("%-8d %-10d", semid, ipcp->uid); /* ctime uses static buffer: use separate calls */ printf(" %-26.24s", semary.sem_otime ? ctime(&semary.sem_otime) : "Not set"); printf(" %-26.24s\n", semary.sem_ctime ? ctime(&semary.sem_ctime) : "Not set"); printf("0x%08x ", ipcp->key); if (pw) printf("%-10d %-10.9s", semid, pw->pw_name); else printf("%-10d %-9d", semid, ipcp->uid); printf(" %-10o %-10ld\n", ipcp->mode & 0777, /* * glibc-2.1.3 and earlier has unsigned short; * glibc-2.1.91 has variation between * unsigned short and unsigned long * Austin prescribes unsigned short. */ (long) semary.sem_nsems); } return 0; }
void print_working_dir(pDataStruct workingData){ pNode temp = workingData->workingDir->directoryHeadNode; printf("Type Size Date Name Perms\n_______________________________________\n");//40_ while ( temp != NULL ){ if(temp->type == FILE){ printf("FILE @d @x @s ",get_file_size(temp->file), temp->date, temp->name); print_perms(temp,workingData); printf("\n"); } if(temp->type == DIRECTORY){ printf("DIR @d @x @s ",sizeof(sNode), temp->date, temp->name); print_perms(temp,workingData); printf("\n"); } temp = temp->next; } }
bufnode * getattr_1_svc(bufnode *argp, struct svc_req *rqstp) { static bufnode result; printf("Got a getattr req %s\n", argp->buffer); if(access(argp->buffer, F_OK) < 0) { result.size = -1; sprintf(result.buffer, "file or dir not exist !"); return &result; } result.size = 1; struct stat sb; stat(argp->buffer, &sb); print_perms(sb.st_mode, result.buffer); char buf[128]; struct passwd pwent, * pwentp; struct group grp, * grpt; char datestring[256]; struct tm time; sprintf(buf, " %d", (int)sb.st_nlink); strcat(result.buffer, buf); if (!getpwuid_r(sb.st_uid, &pwent, buf, sizeof(buf), &pwentp)) sprintf(buf, " %s", pwent.pw_name); else printf(buf, " %d", sb.st_uid); strcat(result.buffer, buf); if (!getgrgid_r (sb.st_gid, &grp, buf, sizeof(buf), &grpt)) sprintf(buf, " %s", grp.gr_name); else sprintf(buf, " %d", sb.st_gid); strcat(result.buffer, buf); sprintf(buf, " %5d", (int)sb.st_size); strcat(result.buffer, buf); localtime_r(&sb.st_mtime, &time); /* Get localized date string. */ strftime(datestring, sizeof(datestring), "%F %T", &time); sprintf(buf, " %s %s\n", datestring, argp->buffer); strcat(result.buffer, buf); return &result; }
static void do_msg(void) { int maxid, msqid, id; struct msqid_ds msgque; struct msginfo msginfo; struct ipc_perm *ipcp = &msgque.msg_perm; struct passwd *pw; maxid = msgctl(0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo); if (maxid < 0) { printf("kernel not configured for %s\n", "message queues"); return; } switch (format) { case LIMITS: if ((msgctl(0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0) return; printf("------ Message%s --------\n", "s: Limits"); printf( "max queues system wide = %d\n" "max size of message (bytes) = %d\n" "default max size of queue (bytes) = %d\n", msginfo.msgmni, msginfo.msgmax, msginfo.msgmnb); return; case STATUS: printf("------ Message%s --------\n", "s: Status"); printf( "allocated queues = %d\n" "used headers = %d\n" "used space = %d bytes\n", msginfo.msgpool, msginfo.msgmap, msginfo.msgtql); return; case CREATOR: printf("------ Message%s --------\n", " Queues: Creators/Owners"); printf( "%-10s %-10s %-10s %-10s %-10s %-10s\n", "msqid", "perms", "cuid", "cgid", "uid", "gid"); break; case TIME: printf("------ Message%s --------\n", " Queues Send/Recv/Change Times"); printf( "%-8s %-10s %-20s %-20s %-20s\n", "msqid", "owner", "send", "recv", "change"); break; case PID: printf("------ Message%s --------\n", " Queues PIDs"); printf( "%-10s %-10s %-10s %-10s\n", "msqid", "owner", "lspid", "lrpid"); break; default: printf("------ Message%s --------\n", " Queues"); printf( "%-10s %-10s %-10s %-10s %-12s %-12s\n", "key", "msqid", "owner", "perms", "used-bytes", "messages"); break; } for (id = 0; id <= maxid; id++) { msqid = msgctl(id, MSG_STAT, &msgque); if (msqid < 0) continue; if (format == CREATOR) { print_perms(msqid, ipcp); continue; } pw = getpwuid(ipcp->uid); switch (format) { case TIME: if (pw) printf("%-8d %-10.10s", msqid, pw->pw_name); else printf("%-8d %-10d", msqid, ipcp->uid); printf(" %-20.16s", msgque.msg_stime ? ctime(&msgque.msg_stime) + 4 : "Not set"); printf(" %-20.16s", msgque.msg_rtime ? ctime(&msgque.msg_rtime) + 4 : "Not set"); printf(" %-20.16s\n", msgque.msg_ctime ? ctime(&msgque.msg_ctime) + 4 : "Not set"); break; case PID: if (pw) printf("%-8d %-10.10s", msqid, pw->pw_name); else printf("%-8d %-10d", msqid, ipcp->uid); printf(" %5d %5d\n", msgque.msg_lspid, msgque.msg_lrpid); break; default: printf("0x%08x ", ipcp->KEY); if (pw) printf("%-10d %-10.10s", msqid, pw->pw_name); else printf("%-10d %-10d", msqid, ipcp->uid); printf(" %-10o %-12ld %-12ld\n", ipcp->mode & 0777, /* * glibc-2.1.3 and earlier has unsigned short; * glibc-2.1.91 has variation between * unsigned short, unsigned long * Austin has msgqnum_t */ (long) msgque.msg_cbytes, (long) msgque.msg_qnum); break; } } }
static void do_sem(void) { int maxid, semid, id; struct semid_ds semary; struct seminfo seminfo; struct ipc_perm *ipcp = &semary.sem_perm; struct passwd *pw; union semun arg; arg.array = (ushort *) (void *) &seminfo; maxid = semctl(0, 0, SEM_INFO, arg); if (maxid < 0) { printf("kernel not configured for %s\n", "semaphores"); return; } switch (format) { case LIMITS: printf("------ Semaphore %s --------\n", "Limits"); arg.array = (ushort *) (void *) &seminfo; /* damn union */ if ((semctl(0, 0, IPC_INFO, arg)) < 0) return; printf("max number of arrays = %d\n" "max semaphores per array = %d\n" "max semaphores system wide = %d\n" "max ops per semop call = %d\n" "semaphore max value = %d\n", seminfo.semmni, seminfo.semmsl, seminfo.semmns, seminfo.semopm, seminfo.semvmx); return; case STATUS: printf("------ Semaphore %s --------\n", "Status"); printf( "used arrays = %d\n" "allocated semaphores = %d\n", seminfo.semusz, seminfo.semaem); return; case CREATOR: printf("------ Semaphore %s --------\n", "Arrays Creators/Owners"); printf( "%-10s %-10s %-10s %-10s %-10s %-10s\n", "semid", "perms", "cuid", "cgid", "uid", "gid"); break; case TIME: printf("------ Shared Memory %s --------\n", "Operation/Change Times"); printf( "%-8s %-10s %-26.24s %-26.24s\n", "shmid", "owner", "last-op", "last-changed"); break; case PID: break; default: printf("------ Semaphore %s --------\n", "Arrays"); printf( "%-10s %-10s %-10s %-10s %-10s\n", "key", "semid", "owner", "perms", "nsems"); break; } for (id = 0; id <= maxid; id++) { arg.buf = (struct semid_ds *) &semary; semid = semctl(id, 0, SEM_STAT, arg); if (semid < 0) continue; if (format == CREATOR) { print_perms(semid, ipcp); continue; } pw = getpwuid(ipcp->uid); switch (format) { case TIME: if (pw) printf("%-8d %-10.10s", semid, pw->pw_name); else printf("%-8d %-10d", semid, ipcp->uid); /* ctime uses static buffer: use separate calls */ printf(" %-26.24s", semary.sem_otime ? ctime(&semary.sem_otime) : "Not set"); printf(" %-26.24s\n", semary.sem_ctime ? ctime(&semary.sem_ctime) : "Not set"); break; case PID: break; default: printf("0x%08x ", ipcp->KEY); if (pw) printf("%-10d %-10.9s", semid, pw->pw_name); else printf("%-10d %-9d", semid, ipcp->uid); printf(" %-10o %-10ld\n", ipcp->mode & 0777, /* * glibc-2.1.3 and earlier has unsigned short; * glibc-2.1.91 has variation between * unsigned short and unsigned long * Austin prescribes unsigned short. */ (long) semary.sem_nsems); break; } } }
static void do_shm(void) { int maxid, shmid, id; struct shmid_ds shmseg; struct shm_info shm_info; struct shminfo shminfo; struct ipc_perm *ipcp = &shmseg.shm_perm; struct passwd *pw; maxid = shmctl(0, SHM_INFO, (struct shmid_ds *) (void *) &shm_info); if (maxid < 0) { printf("kernel not configured for %s\n", "shared memory"); return; } switch (format) { case LIMITS: printf("------ Shared Memory %s --------\n", "Limits"); if ((shmctl(0, IPC_INFO, (struct shmid_ds *) (void *) &shminfo)) < 0) return; /* glibc 2.1.3 and all earlier libc's have ints as fields of struct shminfo; glibc 2.1.91 has unsigned long; ach */ printf("max number of segments = %lu\n" "max seg size (kbytes) = %lu\n" "max total shared memory (pages) = %lu\n" "min seg size (bytes) = %lu\n", (unsigned long) shminfo.shmmni, (unsigned long) (shminfo.shmmax >> 10), (unsigned long) shminfo.shmall, (unsigned long) shminfo.shmmin); return; case STATUS: printf("------ Shared Memory %s --------\n", "Status"); printf( "segments allocated %d\n" "pages allocated %ld\n" "pages resident %ld\n" "pages swapped %ld\n" "Swap performance: %ld attempts\t%ld successes\n", shm_info.used_ids, shm_info.shm_tot, shm_info.shm_rss, shm_info.shm_swp, shm_info.swap_attempts, shm_info.swap_successes); return; case CREATOR: printf("------ Shared Memory %s --------\n", "Segment Creators/Owners"); printf( "%-10s %-10s %-10s %-10s %-10s %-10s\n", "shmid", "perms", "cuid", "cgid", "uid", "gid"); break; case TIME: printf("------ Shared Memory %s --------\n", "Attach/Detach/Change Times"); printf( "%-10s %-10s %-20s %-20s %-20s\n", "shmid", "owner", "attached", "detached", "changed"); break; case PID: printf("------ Shared Memory %s --------\n", "Creator/Last-op"); printf( "%-10s %-10s %-10s %-10s\n", "shmid", "owner", "cpid", "lpid"); break; default: printf("------ Shared Memory %s --------\n", "Segments"); printf( "%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n", "key", "shmid", "owner", "perms", "bytes", "nattch", "status"); break; } for (id = 0; id <= maxid; id++) { shmid = shmctl(id, SHM_STAT, &shmseg); if (shmid < 0) continue; if (format == CREATOR) { print_perms(shmid, ipcp); continue; } pw = getpwuid(ipcp->uid); switch (format) { case TIME: if (pw) printf("%-10d %-10.10s", shmid, pw->pw_name); else printf("%-10d %-10d", shmid, ipcp->uid); /* ctime uses static buffer: use separate calls */ printf(" %-20.16s", shmseg.shm_atime ? ctime(&shmseg.shm_atime) + 4 : "Not set"); printf(" %-20.16s", shmseg.shm_dtime ? ctime(&shmseg.shm_dtime) + 4 : "Not set"); printf(" %-20.16s\n", shmseg.shm_ctime ? ctime(&shmseg.shm_ctime) + 4 : "Not set"); break; case PID: if (pw) printf("%-10d %-10.10s", shmid, pw->pw_name); else printf("%-10d %-10d", shmid, ipcp->uid); printf(" %-10d %-10d\n", shmseg.shm_cpid, shmseg.shm_lpid); break; default: printf("0x%08x ", ipcp->KEY); if (pw) printf("%-10d %-10.10s", shmid, pw->pw_name); else printf("%-10d %-10d", shmid, ipcp->uid); printf(" %-10o %-10lu %-10ld %-6s %-6s\n", ipcp->mode & 0777, /* * earlier: int, Austin has size_t */ (unsigned long) shmseg.shm_segsz, /* * glibc-2.1.3 and earlier has unsigned short; * Austin has shmatt_t */ (long) shmseg.shm_nattch, ipcp->mode & SHM_DEST ? "dest" : " ", ipcp->mode & SHM_LOCKED ? "locked" : " "); break; } } }
int main(void) { Display *dpy; Bool ret; int event_base, error_base, major, minor, screens, i; char *str; /* * open a connection to the X server indicated by the DISPLAY * environment variable */ dpy = XOpenDisplay(NULL); if (!dpy) { fprintf(stderr, "Cannot open display '%s'.\n", XDisplayName(NULL)); return 1; } /* * check if the NV-CONTROL X extension is present on this X server */ ret = XNVCTRLQueryExtension(dpy, &event_base, &error_base); if (ret != True) { fprintf(stderr, "The NV-CONTROL X extension does not exist on '%s'.\n", XDisplayName(NULL)); return 1; } /* * query the major and minor extension version */ ret = XNVCTRLQueryVersion(dpy, &major, &minor); if (ret != True) { fprintf(stderr, "The NV-CONTROL X extension does not exist on '%s'.\n", XDisplayName(NULL)); return 1; } /* * print statistics thus far */ printf("NV-CONTROL X extension present\n"); printf(" version : %d.%d\n", major, minor); printf(" event base : %d\n", event_base); printf(" error base : %d\n", error_base); /* * loop over each screen, and determine if each screen is * controlled by the NVIDIA X driver (and thus supports the * NV-CONTROL X extension); then, query the string attributes on * the screen. */ screens = ScreenCount(dpy); for (i = 0; i < screens; i++) { if (XNVCTRLIsNvScreen(dpy, i)) { printf("Screen %d supports the NV-CONTROL X extension\n", i); ret = XNVCTRLQueryStringAttribute(dpy, i, 0, /* XXX not curently used */ NV_CTRL_STRING_PRODUCT_NAME, &str); if (ret) { printf(" GPU : %s\n", str); XFree(str); } ret = XNVCTRLQueryStringAttribute(dpy, i, 0, /* XXX not curently used */ NV_CTRL_STRING_VBIOS_VERSION, &str); if (ret) { printf(" VideoBIOS : %s\n", str); XFree(str); } ret = XNVCTRLQueryStringAttribute(dpy, i, 0, /* XXX not curently used */ NV_CTRL_STRING_NVIDIA_DRIVER_VERSION, &str); if (ret) { printf(" Driver version : %s\n", str); XFree(str); } } } /* * print attribute permission and type information. */ printf("Attributes (Integers):\n"); for (i = 0; i < NV_CTRL_LAST_ATTRIBUTE; i++) { const char *name = attr2str(i, attr_int_table); if (name) { NVCTRLAttributePermissionsRec perms; printf(" (%3d) [Perms: ", i); memset(&perms, 0, sizeof(NVCTRLAttributePermissionsRec)); XNVCTRLQueryAttributePermissions(dpy, i, &perms); print_perms(&perms); printf("] [ "); printf("%-32s", GetAttrTypeName(perms.type)); printf("] - %s\n", name); } } printf("Attributes (Strings):\n"); for (i = 0; i < NV_CTRL_STRING_LAST_ATTRIBUTE; i++) { const char *name = attr2str(i, attr_str_table); if (name) { NVCTRLAttributePermissionsRec perms; printf(" (%3d) [Perms: ", i); memset(&perms, 0, sizeof(NVCTRLAttributePermissionsRec)); XNVCTRLQueryStringAttributePermissions(dpy, i, &perms); print_perms(&perms); printf("] [ "); printf("%-32s", GetAttrTypeName(perms.type)); printf("] - %s\n", name); } } printf("Attributes (Binary Data):\n"); for (i = 0; i < NV_CTRL_BINARY_DATA_LAST_ATTRIBUTE; i++) { const char *name = attr2str(i, attr_bin_table); if (name) { NVCTRLAttributePermissionsRec perms; printf(" (%3d) [Perms: ", i); memset(&perms, 0, sizeof(NVCTRLAttributePermissionsRec)); XNVCTRLQueryBinaryDataAttributePermissions(dpy, i, &perms); print_perms(&perms); printf("] [ "); printf("%-32s", GetAttrTypeName(perms.type)); printf("] - %s\n", name); } } printf("Attributes (String Operations):\n"); for (i = 0; i < NV_CTRL_STRING_OPERATION_LAST_ATTRIBUTE; i++) { const char *name = attr2str(i, attr_strop_table); if (name) { NVCTRLAttributePermissionsRec perms; printf(" (%3d) [Perms: ", i); memset(&perms, 0, sizeof(NVCTRLAttributePermissionsRec)); XNVCTRLQueryStringOperationAttributePermissions(dpy, i, &perms); print_perms(&perms); printf("] [ "); printf("%-32s", GetAttrTypeName(perms.type)); printf("] - %s\n", name); } } /* * close the display connection */ XCloseDisplay(dpy); return 0; }
int main(int argc, char *argv[]) { DIR *dsp; struct dirent *entlist[MAXDIRS] = {0}; struct stat stat_buf; struct tm *tsp; char path[DSIZE]; int show_perm = 0; /* show file permissions */ int show_size = 0; /* atarimae darou */ int show_last_access = 0; int c, j; int i = 0; while ((c = getopt(argc, argv, "spt")) != -1) switch(c) { case 'p': show_perm = 1; break; case 's': show_size = 1; break; case 't': show_last_access = 1; break; default: break; } /* if a directory name is provided, use it */ if (argv[optind]) strcpy(path, argv[optind]); else getcwd(path, sizeof(path)); dsp = opendir(path); if (dsp) { while ((entlist[i++] = readdir(dsp))) ; i--; /* number of entries */ printf("TOTAL ENTRIES: %d \n", i); qsort(entlist, i, sizeof(struct dirent *), compare_direntp); j = 0; while (j < i) { stat(entlist[j]->d_name, &stat_buf); if (show_perm) print_perms(stat_buf); if (show_size) print_size(stat_buf); if (show_last_access) { tsp = gmtime(&(stat_buf.st_atime)); printf("%-2d:%-2d:%-2d ", tsp->tm_hour, tsp->tm_min, tsp->tm_sec); } /* print yellow text if directory */ if (S_ISDIR(stat_buf.st_mode)) printf(COLOUR_NANDEMO "%s\n" COLOUR_RESET, entlist[j]->d_name); /* print blue text if regular and executable by owner */ else if (S_ISREG(stat_buf.st_mode) && (stat_buf.st_mode & S_IXUSR)) printf(COLOUR_BLUE "%s \n" COLOUR_RESET, entlist[j]->d_name); else printf("%s \n", entlist[j]->d_name); j++; } closedir(dsp); } else perror("error: could not access directory\n"); return 0; }