File::Stat and file flags

M

Manfred Lotz

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
 
N

nobu.nokada

Hi,

At Sun, 30 Nov 2003 18:47:09 +0900,
Manfred said:
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.
 
M

Manfred Lotz

Hi,

Hi,

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


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.
What you want may be File::Stat#mode.

No. See above.


Manfred
 
N

nobu.nokada

Hi,

At Mon, 1 Dec 2003 15:12:08 +0900,
Manfred said:
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?
 
N

nobu.nokada

Hi,

At Tue, 2 Dec 2003 00:31:38 +0900,
YANAGAWA said:
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);
}
============================================================
 
T

ts

n> Although not tested at all, and lacks constants and particular
n> 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
 
N

nobu.nokada

Hi,

At Tue, 2 Dec 2003 19:17:36 +0900,
ts said:
n> Although not tested at all, and lacks constants and particular
n> 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,816
Members
47,361
Latest member
RogerDuabe

Latest Threads

Top