File::Stat and file flags

In the UFS file system of FreeBSD a file can have special flags.

Is there any way to retrieve those flags within Ruby? I looked for
File::Stat.flags? and File::Stat.flags. However it doesn’t exist.

Is is anywhere else and I just didn’t find it?

Manfred

Hi,

In the UFS file system of FreeBSD a file can have special flags.

What flags?

Is there any way to retrieve those flags within Ruby? I looked for
File::Stat.flags? and File::Stat.flags. However it doesn’t exist.

What you want may be File::Stat#mode.

···

At Sun, 30 Nov 2003 18:47:09 +0900, Manfred Lotz wrote:


Nobu Nakada

Hi,

Hi,

In the UFS file system of FreeBSD a file can have special flags.

What flags?

arch the archived flag (super-user only)
opaque the opaque flag (owner or super-user only)
nodump the nodump flag (owner or super-user only)
sappnd the system append-only flag (super-user only)
schg the system immutable flag (super-user only)
sunlnk the system undeletable flag (super-user only)
uappnd the user append-only flag (owner or super-user only)
uchg the user immutable flag (owner or super-user only)
uunlnk the user undeletable flag (owner or super-user only)

Putting the letters no'' before or removing the letters no’’ from a
keyword causes the flag to be cleared.

Is there any way to retrieve those flags within Ruby? I looked for
File::Stat.flags? and File::Stat.flags. However it doesn’t exist.

What you want may be File::Stat#mode.

No. See above.

Manfred

···

On Mon, 01 Dec 2003 13:14:13 +0900, nobu.nokada wrote:

At Sun, 30 Nov 2003 18:47:09 +0900, > Manfred Lotz wrote:

Hi,

···

At Mon, 1 Dec 2003 15:12:08 +0900, Manfred Lotz wrote:

In the UFS file system of FreeBSD a file can have special flags.

What flags?

arch the archived flag (super-user only)
opaque the opaque flag (owner or super-user only)
nodump the nodump flag (owner or super-user only)
sappnd the system append-only flag (super-user only)
schg the system immutable flag (super-user only)
sunlnk the system undeletable flag (super-user only)
uappnd the user append-only flag (owner or super-user only)
uchg the user immutable flag (owner or super-user only)
uunlnk the user undeletable flag (owner or super-user only)

Putting the letters no'' before or removing the letters no’’ from a
keyword causes the flag to be cleared.

How can you access/operate those flags?


Nobu Nakada

In Message-Id: 200312010715.hB17Fga6008941@sharui.nakada.kanuma.tochigi.jp
nobu.nokada@softhome.net writes:

How can you access/operate those flags?

He is talking on file flags introduced at 4.4BSD, and they can be
referenced through st_flags of struct stat. To set these flags, you
can use chflags(2) or fchflags(2).
http://www.freebsd.org/cgi/man.cgi?query=chflags&apropos=0&sektion=0&manpath=FreeBSD+5.1-RELEASE+and+Ports&format=html

I think supporting file flags is too *BSD specific to incorporate into
standard interpreter though.

···


kjana@dm4lab.to December 2, 2003
Whatever is worth doing at all is worth doing well.

Hi,

I think supporting file flags is too *BSD specific to incorporate into
standard interpreter though.

So it should be “BSD” extension library?

Although not tested at all, and lacks constants and particular
methods, nodump?, opaque? and so on.

===File bsd/stat.c==========================================
#include <sys/stat.h>
#include <unistd.h>
#include “ruby.h”
#include “rubyio.h”

static VALUE stat_inspect;

static struct stat*
get_stat(self)
VALUE self;
{
struct stat* st;
Data_Get_Struct(self, struct stat, st);
if (!st) rb_raise(rb_eTypeError, “uninitialized File::Stat”);
return st;
}

static VALUE
bsd_stat_flags(VALUE self)
{
return ULONG2NUM(get_stat(self)->st_flags);
}

static VALUE
bsd_stat_inspect(VALUE self)
{
char tmp[sizeof(((struct stat*)0)->st_flags)*2+5];
VALUE bm = rb_funcall2(stat_inspect, rb_intern(“bind”), 1, &self);
VALUE str = rb_funcall2(bm, rb_intern(“call”), 0, 0);

snprintf(sizeof(tmp), ", 0x%lx", (unsigned long)get_stat(self)->st_flags);
rb_str_update(str, -2, 0, rb_str_new2(tmp));
return str;

}

static VALUE
bsd_chflags(VALUE self, VALUE flags)
{
OpenFile *fptr;

rb_secure(2);
GetOpenFile(self, fptr);
if (fchflags(fileno(fptr->f), NUM2ULONG(flags))) {
rb_sys_fail(0);
}
return INT2FIX(0);

}

static VALUE
bsd_s_chflags(VALUE self, VALUE file, VALUE flags)
{
VALUE tmp = rb_check_convert_type(file, T_FILE, “IO”, “to_io”);
if (!NIL_P(tmp)) {
return bsd_chflags(tmp, flags);
}
SafeStringValue(file);
if (chflags(StringValueCStr(file), NUM2ULONG(flags))) {
rb_sys_fail(0);
}
return INT2FIX(0);
}

void
Init_stat()
{
VALUE stat = rb_const_get_at(rb_cFile, rb_intern(“Stat”));
stat_inspect = rb_funcall(stat, rb_intern(“instance_method”),
1, ID2SYM(rb_intern(“inspect”)));
rb_define_method(stat, “inspect”, bsd_stat_inspect, 0);
rb_define_method(stat, “flags”, bsd_stat_flags, 0);
rb_define_method(rb_cFile, “chflags”, bsd_chflags, 1);
rb_define_singleton_method(rb_cFile, “chflags”, bsd_s_chflags, 2);
}

···

At Tue, 2 Dec 2003 00:31:38 +0900, YANAGAWA Kazuhisa wrote:


Nobu Nakada

Although not tested at all, and lacks constants and particular
methods, nodump?, opaque? and so on.

well, if you want to do this you'll perhaps find that the *BSD persons
expect, perhaps, a little more ...

see [ruby-talk:6297]

Guy Decoux

Hi,

···

At Tue, 2 Dec 2003 19:17:36 +0900, ts wrote:

Although not tested at all, and lacks constants and particular
methods, nodump?, opaque? and so on.

well, if you want to do this you’ll perhaps find that the *BSD persons
expect, perhaps, a little more …

Nope, just tried. Since I’ve no intention of maintaining it,
I’ll renounce its right or admit everyone, perhaps under the
term of Ruby license.


Nobu Nakada