More file system primitives

Bug #295846 reported by Andreas Rottmann
2
Affects Status Importance Assigned to Milestone
Ikarus Scheme
Fix Committed
Medium
Abdulaziz Ghuloum

Bug Description

It would be nice to have more file system functions; I propose the following additions:

file-readable? path -> boolean
file-writable? path -> boolean
file-executable? path -> boolean
file-size path -> integer
rename-file source dest -> undefined

With the obvious semantics.

Related branches

Revision history for this message
Andreas Rottmann (rotty) wrote :
Revision history for this message
Derick Eddington (derick-eddington) wrote : Re: [Bug 295846] Re: More file system primitives

On Sun, 2008-11-09 at 05:45 +0000, Andreas Rottmann wrote:
> ** Attachment added: "Adds a few file system primitives"
> http://launchpadlibrarian.net/19504032/filesys.patch

Is this a bug in the patch?:

If, on a 32-bit system, large file support is enabled (like requested at
bug #295833), thus making off_t be 64-bit, then will this result in C
numbers possibly too large for Ikarus 30-bit fixnums?:

+ikptr
+ikrt_file_size(ikptr filename, ikptr res){
+ char* fn = (char*)(filename + off_bytevector_data);
+ struct stat s;
+ int r;
+
+ r = stat(fn, &s);
+
+ if (r == 0)
+ {
+ ref(res, off_car) = fix(s.st_size >> 24); <---- THIS
+ ref(res, off_cdr) = fix(s.st_size & ~(-1L << 24));
+ return fix(0);
+ }
+ else
+ return ik_errno_to_code();
+}

struct stat's st_size field is an off_t, and if this field is 64-bits
and we're on a 32-bit system and say the value of this field (the size
of the file) is 0x0200000000000000 (crazy, I know :), but otherwise
we're relying on the unknown variable file-system type to prevent sizes
this large), then:

s.st_size >> 24 == 0x000000020000000

which is too big for a 30-bit fixnum:

> (<= #x20000000 (greatest-fixnum))
#f
> (printf "#x~x\n" (greatest-fixnum))
#x1FFFFFFF
>

Maybe this s.st_size should be chopped into 3 pieces, or Aziz can make
it into a bignum from C if it's too big for a fixnum? What's the best
portable way?

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

On Nov 9, 2008, at 10:36 AM, Derick Eddington wrote:

> Maybe this s.st_size should be chopped into 3 pieces, or Aziz can make
> it into a bignum from C if it's too big for a fixnum? What's the best
> portable way?

I don't know. It depends on how pervasive the size of file-size is.
I usually chop it into pieces when I should not allocate (e.g., in
time-it). Otherwise, I'd just return a fixnum or bignum depending
on the size.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

In the patch, there is:

+ r = access(fn, c_how);
+ if (r == 0)
+ return true_object;
+ else if (errno == EACCES || errno == EROFS)
+ return false_object;
+ else
+ return ik_errno_to_code();
+}

Is there a reason why ETXTBSY is not included in the middle check.
My manpage says:

     [EROFS] Write access is requested for a file on a read-only
                        file system.

     [ETXTBSY] Write access is requested for a pure procedure (shared
                        text) file presently being executed.

     [EACCES] Permission bits of the file mode do not permit the
                        requested access, or search permission is denied on a
                        component of the path prefix. The owner of a file has
                        permission checked with respect to the ``owner'' read,
                        write, and execute mode bits, members of the file's
                        group other than the owner have permission checked
                        with respect to the ``group'' mode bits, and all oth-
                        ers have permissions checked with respect to the
                        ``other'' mode bits.

Changed in ikarus:
assignee: nobody → aghuloum
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Andreas Rottmann (rotty) wrote :

> Is there a reason why ETXTBSY is not included in the middle check.

No, seems I just overlooked that.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Added in 1666. (just for future reference, if you happen to submit a patch, try to modify the files in the same branch directory (one you got from "bzr branch" or "bzr checkout" and use "bzr diff" to generate the patch, it would make my life much easier. Thanks again.)

Changed in ikarus:
status: Confirmed → Fix Committed
Changed in ikarus:
milestone: none → 0.0.4
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.