Re: Setting st_flags returned by stat
Re: Setting st_flags returned by stat
- Subject: Re: Setting st_flags returned by stat
- From: rohan a <email@hidden>
- Date: Fri, 1 May 2009 17:37:07 +0530
Hello,
Thanks for this.
1. However, man 2 stat
says that st_flags is of type u_long, but chflags() takes as argument flags which is u_int.
2. If I do an lstat() on a file and take its st_flags:
lstat(path, &statbuf);
and then use statbuf.st_flags in the chflags() call, to set the flags to another file:
chflags(file, statbuf.st_flags);
Is this right?
On 5/1/09, Dominic Giampaolo <email@hidden> wrote:
The stat() / lstat() API returns st_flags which are "user defined
flags for file".
How do we set these flags back to a file?
Should it be done using the chflags() function call?
As Terry Lambert noted, you use the chflags() call
to set flags on a file. However do not set undefined
bits - only use the bits in /usr/include/sys/stat.h.
Specifically these are:
#define UF_NODUMP 0x00000001 /* do not dump file */
#define UF_IMMUTABLE 0x00000002 /* file may not be changed */
#define UF_APPEND 0x00000004 /* writes to file may only append */
#define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */
and if you're the super-user you can set:
#define SF_ARCHIVED 0x00010000 /* file is archived */
#define SF_IMMUTABLE 0x00020000 /* file may not be changed */
#define SF_APPEND 0x00040000 /* writes to file may only append */
Keep in mind that most of these bits have defined
meanings in the file system: IMMUTABLE and APPEND in
particular. Bits such as NODUMP are not really used
on MacOS X.
--dominic
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden