Standards / Extensions | C or C++ | Dependencies |
---|---|---|
z/OS® UNIX |
both | z/OS V1R2 |
#define _OPEN_SYS_FILE_EXT 1
#include <sys/stat.h>
int __chattr(char* pathname, attrib_t *attributes, int attributes_len);
The __chattr() function modifies the attributes that are associated with a file. It can be used to change the mode, owner, access time, modification time, change time, reference time, audit flags, general attribute flags, file tag, and file format and size. The file to be impacted is defined by the pathname argument.
Element | Data Type | General Description |
---|---|---|
Bit Flags Indicating Which Attributes to Change | ||
att_modechg:1 | int | 1=Change to mode indicated |
att_ownerchg:1 | int | 1=Change to Owner indicated |
att_setgen:1 | int | 1=Set General Attributes |
att_trunc:1 | int | 1=Truncate Size |
att_atimechg:1 | int | 1=Change the Atime |
att_atimetod:1 | int | 1=Change Atime to Cur.Time |
att_mtimechg:1 | int | 1=Change the Mtime |
att_mtimetod:1 | int | 1=Change Mtime to Cur.Time |
att_maaudit:1 | int | 1=Modify auditor audit info |
att_muaudit:1 | int | 1=Modify user audit info |
att_ctimechg:1 | int | 1=Change the Ctime |
att_ctimetod:1 | int | 1=Change Ctime to Cur.Time |
att_reftimechg:1 | int | 1=Change the RefTime |
att_reftimetod:1 | int | 1=Change RefTime to Cur.Time |
att_filefmtchg:1 | int | 1=Change File Format |
att_filetagchg:1 | int | 1=Change File Tag |
att_seclabelchg:1 | int | 1=Change Seclabel |
Modified Values for Indicated Attributes to Change | ||
att_mode | mode_t | File Mode |
att_uid | int | User ID of the owner of the file |
att_gid | int | Group ID of the Group of the file |
att_sharelibmask:1 | int | 1=Shared Library Mask |
att_noshareasmask:1 | int | 1=No Shareas Flag Mask |
att_apfauthmask:1 | int | 1=APF Authorized Flag Mask |
att_progctlmask:1 | int | 1=Prog. Controlled Flag Mask |
att_sharelib:1 | int | 1=Shared Library Flag |
att_noshareas:1 | int | 1=No Shareas Flag |
att_apfauth:1 | int | 1=APF Authorized Flag |
att_progctl:1 | int | 1=Program Controlled Flag |
att_size | off_t | File size |
att_atime | time_t | Time of last access |
att_mtime | time_t | Time of last data modification |
att_auditoraudit | int | Area for auditor audit info |
att_useraudit | int | Area for user audit info |
att_ctime | time_t | Time of last file status change |
att_reftime | time_t | Reference Time |
att_filefmt | char | File Format |
att_filetag | struct file_tag | File Tag |
att_seclabel | char | Security Label |
If successful, __chattr() returns 0.
If unsuccessful, __chattr() returns -1 and sets errno to one of the following values:
#define _POSIX_SOURCE 1
#define _OPEN_SYS_FILE_EXT 1
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
int main(int argc, char *argv[]) {
int fd;
attrib_t myAtt;
struct stat attr;
char filename[] = "chattr.testfile";
/* Create an empty file */
if ( (fd = creat(filename, S_IRWXU | S_IRGRP | S_IROTH)) < 0) {
perror("Failed to create testfile");
exit(1);
}
close(fd);
/* Clear myAtt structure */
memset(&myAtt, 0, sizeof(myAtt));
/* Update myAtt to request file tag change and set file tag values */
myAtt.att_filetagchg = 1;
myAtt.att_filetag.ft_ccsid = 12345;
myAtt.att_filetag.ft_txtflag = 1;
/* Change Attributes */
if ( __chattr(filename, &myAtt, sizeof(myAtt)) != 0 ) {
perror("Failed to change attributes for testfile");
exit(2);
}
/* Verify Change */
if ( stat(filename,&attr) !=0 ) {
perror("Failed to acquire statistics for testfile");
exit(3);
}
if ((attr.st_tag.ft_ccsid == 12345)
&& (attr.st_tag.ft_txtflag == 1)) {
printf("File attributes changed successfully\n");
}
}