X-Git-Url: https://git.saurik.com/apple/file_cmds.git/blobdiff_plain/b1857959f57db441de22908c2c6c28baac8cd28a..74e6a095cde8426176ac056299a621da2e5f847f:/ls/print.c diff --git a/ls/print.c b/ls/print.c index 5f222cd..de04bf3 100644 --- a/ls/print.c +++ b/ls/print.c @@ -50,10 +50,9 @@ __RCSID("$FreeBSD: src/bin/ls/print.c,v 1.57 2002/08/29 14:29:09 keramida Exp $" #include #include #include -#if !TARGET_OS_EMBEDDED +#include #include #include -#endif #include #endif @@ -62,6 +61,7 @@ __RCSID("$FreeBSD: src/bin/ls/print.c,v 1.57 2002/08/29 14:29:09 keramida Exp $" #include #include #include +#include #include #include #include @@ -72,7 +72,8 @@ __RCSID("$FreeBSD: src/bin/ls/print.c,v 1.57 2002/08/29 14:29:09 keramida Exp $" #include #include #endif - +#include /* intmax_t */ +#include #ifdef __APPLE__ #include #else @@ -127,7 +128,8 @@ printscol(DISPLAY *dp) { FTSENT *p; - if (COMPAT_MODE("bin/ls", "Unix2003")) { + assert(dp); + if (COMPAT_MODE("bin/ls", "Unix2003") && (dp->list != NULL)) { if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size)) (void)printf("total %qu\n", (u_int64_t)howmany(dp->btotal, blocksize)); } @@ -199,75 +201,46 @@ static struct { static char * uuid_to_name(uuid_t *uu) { -#if TARGET_OS_EMBEDDED - return strdup(""); -#else /* !TARGET_OS_EMBEDDED */ - int is_gid = -1; - struct group *tgrp = NULL; - struct passwd *tpass = NULL; - char *name = NULL; - uid_t id; - - + int type; + char *name = NULL; + char *recname = NULL; + #define MAXNAMETAG (MAXLOGNAME + 6) /* + strlen("group:") */ - name = (char *) malloc(MAXNAMETAG); - - if (NULL == name) - err(1, "malloc"); - - if (!f_numericonly) { - if (0 != mbr_uuid_to_id(*uu, &id, &is_gid)) - goto errout; + name = (char *) malloc(MAXNAMETAG); + + if (NULL == name) { + err(1, "malloc"); + } + + if (f_numericonly) { + goto errout; } - - switch (is_gid) { - case ID_TYPE_UID: - tpass = getpwuid(id); - if (!tpass) { - goto errout; - } - snprintf(name, MAXNAMETAG, "%s:%s", "user", tpass->pw_name); - break; - case ID_TYPE_GID: - tgrp = getgrgid((gid_t) id); - if (!tgrp) { - goto errout; - } - snprintf(name, MAXNAMETAG, "%s:%s", "group", tgrp->gr_name); - break; - default: + + if (mbr_identifier_translate(ID_TYPE_UUID, *uu, sizeof(*uu), ID_TYPE_NAME, (void **) &recname, &type)) { goto errout; - } - return name; - errout: - if (0 != mbr_uuid_to_string(*uu, name)) { - fprintf(stderr, "Unable to translate qualifier on ACL\n"); - strcpy(name, ""); } - return name; -#endif /* !TARGET_OS_EMBEDDED */ + + snprintf(name, MAXNAMETAG, "%s:%s", (type == MBR_REC_TYPE_USER ? "user" : "group"), recname); + free(recname); + + return name; +errout: + uuid_unparse_upper(*uu, name); + + return name; } static void -printxattr(DISPLAY *dp, char *filename, ssize_t xattr) +printxattr(DISPLAY *dp, int count, char *buf, int sizes[]) { - int flags = XATTR_NOFOLLOW; - char *buf = malloc(xattr); - - if (NULL == buf) - err(1, "malloc"); - if (listxattr(filename, buf, xattr, flags) > 0) { - char *name; - for (name = buf; name < buf+xattr; name += strlen(name) + 1) { - ssize_t size = getxattr(filename, name, 0, 0, 0, flags); - putchar('\t'); - printname(name); - putchar('\t'); - printsize(dp->s_size, size); - putchar('\n'); - } + for (int i = 0; i < count; i++) { + putchar('\t'); + printname(buf); + putchar('\t'); + printsize(dp->s_size, sizes[i]); + putchar('\n'); + buf += strlen(buf) + 1; } - free(buf); } static void @@ -287,17 +260,16 @@ printacl(acl_t acl, int isdir) for (index = 0; acl_get_entry(acl, entry == NULL ? ACL_FIRST_ENTRY : ACL_NEXT_ENTRY, &entry) == 0; index++) { - if ((applicable = (uuid_t *) acl_get_qualifier(entry)) == NULL) - continue; if (acl_get_tag_type(entry, &tag) != 0) continue; if (acl_get_flagset_np(entry, &flags) != 0) continue; if (acl_get_permset(entry, &perms) != 0) continue; + if ((applicable = (uuid_t *) acl_get_qualifier(entry)) == NULL) + continue; name = uuid_to_name(applicable); acl_free(applicable); - switch(tag) { case ACL_EXTENDED_ALLOW: type = "allow"; @@ -345,14 +317,6 @@ printlong(DISPLAY *dp) FTSENT *p; NAMES *np; char buf[20]; -#ifdef __APPLE__ - acl_t acl = NULL; - acl_entry_t dummy; - char full_path[MAXPATHLEN]; - char *filename; - ssize_t xattr = 0; - char str[2]; -#endif #ifdef COLORLS int color_printed = 0; #endif @@ -377,29 +341,7 @@ printlong(DISPLAY *dp) np = p->fts_pointer; #ifdef __APPLE__ buf[10] = '\0'; /* make +/@ abut the mode */ - filename = p->fts_name; - if (p->fts_level != FTS_ROOTLEVEL) - { - snprintf(full_path, sizeof full_path, "%s/%s", - p->fts_parent->fts_accpath, p->fts_name); - filename = full_path; - } - /* symlinks can not have ACLs */ - acl = acl_get_link_np(filename, ACL_TYPE_EXTENDED); - if (acl && acl_get_entry(acl, ACL_FIRST_ENTRY, &dummy) == -1) { - acl_free(acl); - acl = NULL; - } - xattr = listxattr(filename, NULL, 0, XATTR_NOFOLLOW); - if (xattr < 0) - xattr = 0; - str[1] = '\0'; - if (xattr > 0) - str[0] = '@'; - else if (acl != NULL) - str[0] = '+'; - else - str[0] = ' '; + char str[2] = { np->mode_suffix, '\0' }; #endif /* __APPLE__ */ if (f_group && f_owner) { /* means print neither */ #ifdef __APPLE__ @@ -458,6 +400,8 @@ printlong(DISPLAY *dp) printtime(sp->st_atime); else if (f_statustime) printtime(sp->st_ctime); + else if (f_birthtime) + printtime(sp->st_birthtime); else printtime(sp->st_mtime); #ifdef COLORLS @@ -475,14 +419,11 @@ printlong(DISPLAY *dp) printlink(p); (void)putchar('\n'); #ifdef __APPLE__ - if (f_xattr && xattr) { - printxattr(dp, filename, xattr); + if (np->xattr_count && f_xattr) { + printxattr(dp, np->xattr_count, np->xattr_names, np->xattr_sizes); } - if (acl != NULL) { - if (f_acl) - printacl(acl, S_ISDIR(sp->st_mode)); - acl_free(acl); - acl = NULL; + if (np->acl != NULL && f_acl) { + printacl(np->acl, S_ISDIR(sp->st_mode)); } #endif /* __APPLE__ */ } @@ -541,14 +482,15 @@ printcol(DISPLAY *dp) * Have to do random access in the linked list -- build a table * of pointers. */ - if (dp->entries > lastentries) { + if ((lastentries == -1) || (dp->entries > lastentries)) { lastentries = dp->entries; - if ((array = - realloc(array, dp->entries * sizeof(FTSENT *))) == NULL) { + if ((array = realloc(array, dp->entries * sizeof(FTSENT *))) == NULL) { warn(NULL); printscol(dp); + return; } } + memset(array, 0, dp->entries * sizeof(FTSENT *)); for (p = dp->list, num = 0; p; p = p->fts_link) if (p->fts_number != NO_PRINT) array[num++] = p; @@ -571,6 +513,7 @@ printcol(DISPLAY *dp) if (num % numcols) ++numrows; + assert(dp->list); if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size)) (void)printf("total %qu\n", (u_int64_t)howmany(dp->btotal, blocksize)); @@ -580,8 +523,8 @@ printcol(DISPLAY *dp) if (!f_sortacross) base = row; for (col = 0, chcnt = 0; col < numcols; ++col) { - chcnt += printaname(array[base], dp->s_inode, - dp->s_block); + assert(base < dp->entries); + chcnt += printaname(array[base], dp->s_inode, dp->s_block); if (f_sortacross) base++; else @@ -617,7 +560,11 @@ printaname(FTSENT *p, u_long inodefield, u_long sizefield) sp = p->fts_statp; chcnt = 0; if (f_inode) +#if _DARWIN_FEATURE_64_BIT_INODE + chcnt += printf("%*llu ", (int)inodefield, (u_quad_t)sp->st_ino); +#else chcnt += printf("%*lu ", (int)inodefield, (u_long)sp->st_ino); +#endif if (f_size) chcnt += printf("%*qu ", (int)sizefield, (u_int64_t)howmany(sp->st_blocks, blocksize)); @@ -886,5 +833,5 @@ printsize(size_t width, off_t bytes) HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); (void)printf("%5s ", buf); } else - (void)printf("%*jd ", (u_int)width, bytes); + (void)printf("%*jd ", (u_int)width, (intmax_t)bytes); }