📄 atheos.c
字号:
#ifdef SYMLINKSint set_symlnk_attribs(__G__ slnk_entry) __GDEF slinkentry *slnk_entry;{ if (slnk_entry->attriblen > 0) setAtheOSexfield(slnk_entry->fname, (uch *)slnk_entry->buf); /* currently, no error propagation... */ return PK_OK;}#endif /* SYMLINKS */#ifdef SET_DIR_ATTRIB/* messages of code for setting directory attributes */static ZCONST char Far DirlistUidGidFailed[] = "warning: cannot set UID %d and/or GID %d for %s\n";static ZCONST char Far DirlistUtimeFailed[] = "warning: cannot set modification, access times for %s\n";# ifndef NO_CHMOD static ZCONST char Far DirlistChmodFailed[] = "warning: cannot set permissions for %s\n";# endifint defer_dir_attribs(__G__ pd) __GDEF direntry **pd;{ uxdirattr *d_entry; d_entry = (uxdirattr *)malloc(sizeof(uxdirattr) + strlen(G.filename)); *pd = (direntry *)d_entry; if (d_entry == (uxdirattr *)NULL) { return PK_MEM; } d_entry->fn = d_entry->fnbuf; strcpy(d_entry->fn, G.filename); d_entry->perms = G.pInfo->file_attr; d_entry->have_uidgid = get_extattribs(__G__ &(d_entry->u.t3), d_entry->uidgid); return PK_OK;} /* end function defer_dir_attribs() */int set_direc_attribs(__G__ d) __GDEF direntry *d;{ int errval = PK_OK; if (UxAtt(d)->have_uidgid && chown(UxAtt(d)->fn, (uid_t)UxAtt(d)->uidgid[0], (gid_t)UxAtt(d)->uidgid[1])) { Info(slide, 0x201, ((char *)slide, LoadFarString(DirlistUidGidFailed), UxAtt(d)->uidgid[0], UxAtt(d)->uidgid[1], FnFilter1(d->fn))); if (!errval) errval = PK_WARN; } if (utime(d->fn, &UxAtt(d)->u.t2)) { Info(slide, 0x201, ((char *)slide, LoadFarString(DirlistUtimeFailed), FnFilter1(d->fn))); if (!errval) errval = PK_WARN; }#ifndef NO_CHMOD if (chmod(d->fn, filtattr(__G__ UxAtt(d)->perms))) { Info(slide, 0x201, ((char *)slide, LoadFarString(DirlistChmodFailed), FnFilter1(d->fn))); /* perror("chmod (file attributes) error"); */ if (!errval) errval = PK_WARN; }#endif /* !NO_CHMOD */ return errval;} /* end function set_direc_attribs() */#endif /* SET_DIR_ATTRIB */#ifdef TIMESTAMP/***************************//* Function stamp_file() *//***************************/int stamp_file(fname, modtime) ZCONST char *fname; time_t modtime;{ ztimbuf tp; tp.modtime = tp.actime = modtime; return (utime(fname, &tp));} /* end function stamp_file() */#endif /* TIMESTAMP */#ifndef SFX/************************//* Function version() *//************************/void version(__G) __GDEF{ sprintf((char *)slide, LoadFarString(CompiledWith),#ifdef __GNUC__ "gcc ", __VERSION__,#else "(unknown compiler) ","",#endif "Syllable",#if defined(i486) || defined(__i486) || defined(__i486__) || defined(i386) || defined(__i386) || defined(__i386__) " (x86)",#else " (unknown platform)",#endif#ifdef __DATE__ " on ", __DATE__#else "", ""#endif ); (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);} /* end function version() */#endif /* !SFX *//*********************************//* AtheOS extra field functions *//*********************************//*** Scan the extra fields in extra_field, and look for a AtheOS EF; return a** pointer to that EF, or NULL if it's not there.*/static uch *scanAtheOSexfield(const uch *ef_ptr, unsigned ef_len){ while( ef_ptr != NULL && ef_len >= EB_HEADSIZE ) { unsigned eb_id = makeword(EB_ID + ef_ptr); unsigned eb_len = makeword(EB_LEN + ef_ptr); if (eb_len > (ef_len - EB_HEADSIZE)) { Trace((stderr, "scanAtheOSexfield: block length %u > rest ef_size %u\n", eb_len, ef_len - EB_HEADSIZE)); break; } if (eb_id == EF_ATHEOS && eb_len >= EB_BEOS_HLEN) { return (uch *)ef_ptr; } ef_ptr += (eb_len + EB_HEADSIZE); ef_len -= (eb_len + EB_HEADSIZE); } return NULL;}/* Used by setAtheOSexfield():Set a file/directory's attributes to the attributes passed in.If set_file_attrs() fails, an error will be returned: EOK - no errors occurred(other values will be whatever the failed function returned; no docsyet, or I'd list a few)*/static int set_file_attrs( const char *name, const unsigned char *attr_buff, const off_t attr_size ){ int retval = EOK; unsigned char *ptr; const unsigned char *guard; int fd; ptr = (unsigned char *)attr_buff; guard = ptr + attr_size; fd = open(name, O_RDWR | O_NOTRAVERSE); if (fd < 0) { return errno; /* should it be -fd ? */ } while (ptr < guard) { ssize_t nError; struct attr_info fa_info; const char *attr_name; unsigned char *attr_data; attr_name = (char *)&(ptr[0]); ptr += strlen(attr_name) + 1; /* The attr_info data is stored in little-endian format because the */ /* Intel i386 port was here first. */ memcpy(&fa_info, ptr, sizeof(struct attr_info)); ptr += sizeof(struct attr_info); if (fa_info.ai_size < 0LL) { Info(slide, 0x201, ((char *)slide, "warning: skipping attribute with invalid length (%Ld)\n", fa_info.ai_size)); break; } attr_data = ptr; ptr += fa_info.ai_size; if (ptr > guard) { /* We've got a truncated attribute. */ Info(slide, 0x201, ((char *)slide, "warning: truncated attribute\n")); break; } /* write_attr() doesn't return count of written bytes now (Syllable 0.5.3)... */ nError = write_attr(fd, attr_name, O_TRUNC, fa_info.ai_type, attr_data, 0, fa_info.ai_size); if (nError < 0) { Info(slide, 0x201, ((char *)slide, "warning: error writing file attribute\n")); } } close(fd); return retval;}static void setAtheOSexfield(const char *path, uch *extra_field){ uch *ptr = extra_field; ush id = 0; ush size = 0; ulg full_size = 0; uch flags = 0; uch *attrbuff = NULL; int retval; if( extra_field == NULL ) { return; } /* Collect the data from the extra field buffer. */ id = makeword(ptr); ptr += 2; /* we don't use this... */ size = makeword(ptr); ptr += 2; full_size = makelong(ptr); ptr += 4; flags = *ptr; ptr++; /* Do a little sanity checking. */ if (flags & EB_BE_FL_BADBITS) { /* corrupted or unsupported */ Info(slide, 0x201, ((char *)slide, "Unsupported flags set for this AtheOS extra field, skipping.\n")); return; } if (size <= EB_BEOS_HLEN) { /* corrupted, unsupported, or truncated */ Info(slide, 0x201, ((char *)slide, "AtheOS extra field is %d bytes, should be at least %d.\n", size, EB_BEOS_HLEN)); return; } if (full_size < (size - EB_BEOS_HLEN)) { Info(slide, 0x201, ((char *)slide, "Skipping attributes: AtheOS extra field is %d bytes, " "data size is %ld.\n", size - EB_BEOS_HLEN, full_size)); return; } /* Find the AtheOS file attribute data. */ if (flags & EB_BE_FL_UNCMPR) { /* Uncompressed data */ attrbuff = ptr; } else { /* Compressed data */ attrbuff = (uch *)malloc( full_size ); if (attrbuff == NULL) { /* No memory to uncompress attributes */ Info(slide, 0x201, ((char *)slide, "Can't allocate memory to uncompress file attributes.\n")); return; } retval = memextract(__G__ attrbuff, full_size, ptr, size - EB_BEOS_HLEN); if( retval != PK_OK ) { /* error uncompressing attributes */ Info(slide, 0x201, ((char *)slide, "Error uncompressing file attributes.\n")); /* Some errors here might not be so bad; we should expect */ /* some truncated data, for example. If the data was */ /* corrupt, we should _not_ attempt to restore the attrs */ /* for this file... there's no way to detect what attrs */ /* are good and which are bad. */ free (attrbuff); return; } } /* Now attempt to set the file attributes on the extracted file. */ retval = set_file_attrs(path, attrbuff, (off_t)full_size); if (retval != EOK) { Info(slide, 0x201, ((char *)slide, "Error writing file attributes.\n")); } /* Clean up, if necessary */ if (attrbuff != ptr) { free(attrbuff); } return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -