[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

File::Stat and file flags

Manfred Lotz

11/30/2003 9:36:00 AM

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
7 Answers

nobu.nokada

12/1/2003 4:14:00 AM

0

Hi,

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

--
Nobu Nakada


Manfred Lotz

12/1/2003 5:26:00 AM

0

Hi,

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

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

>> 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

nobu.nokada

12/1/2003 7:16:00 AM

0

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

YANAGAWA Kazuhisa

12/1/2003 3:32:00 PM

0

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&forma...


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.


nobu.nokada

12/2/2003 5:16:00 AM

0

Hi,

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

--
Nobu Nakada


ts

12/2/2003 10:18:00 AM

0

>>>>> "n" == nobu nokada <nobu.nokada@softhome.net> writes:

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

nobu.nokada

12/2/2003 1:34:00 PM

0

Hi,

At Tue, 2 Dec 2003 19:17:36 +0900,
ts wrote:
> 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.

--
Nobu Nakada