Subject: [clisp-list] linux:readdir always returns d_type=0 ?

From: Klaus Momberger <[email-masked]>
Date: Thu Feb 14 13:06:40 2002

Hello, 

I was just wondering why linux:readdir is always 
returning "0" as d_type, no matter if the file 
is a directory or regular file, such as : 

----------------------------------------------------
> (setf dir (linux:opendir "/etc"))
#<FOREIGN-ADDRESS #x08286758>
> (setf file (linux:readdir  dir))
#S(LINUX:dirent :|d_ino| 129793 :|d_off| 12
:|d_reclen| 16 :|d_type| 0
   :|d_name| ".")
> (slot-value file 'linux::|d_type|)
0
> (setf file (linux:readdir  dir))
#S(LINUX:dirent :|d_ino| 130395 :|d_off| 52
:|d_reclen| 24 :|d_type| 0
   :|d_name| "passwd")
> (slot-value file 'linux::|d_type|)
0
---------------------------------------------------

I was expecting values matching linux::S_IFDIR, etc.
Am I missing something ? What is it ?

regards,

Klaus Momberger

__________________________________________________
Do You Yahoo!?
Send FREE Valentine eCards with Yahoo! Greetings!
http://greetings.yahoo.com

---

From: Kaz Kylheku <[email-masked]>
Date: Thu Feb 14 16:20:04 2002

On Thu, 14 Feb 2002, Klaus Momberger wrote:

> Date: Thu, 14 Feb 2002 12:54:49 -0800 (PST)
> From: Klaus Momberger <[email-masked]>
> To: [email-masked]
> Subject: [clisp-list] linux:readdir always returns d_type=0 ?
> 
> Hello, 
> 

Hi Klaus,

The distinction between a file and directory is not recorded in a
directory entry. A directory is just a list of filenames.
Or, more precisely, it's an association list of filenames and
their corresponding inode numbers.

To get information about an object, you must use the stat() or lstat()
function.

I don't know what the d_type field is; it might have a meaning on some
file systems that store type information in the directory entry.

> Am I missing something ? What is it ?

Those would be applicable to the |st_mode| field of the structure returned
by linux:stat.

CLISP provides Lisp functions for predicate testing, linux:S_ISDIR,
and so on.

;; silly example
(defun exists-and-is-a-directory (path)
  (multiple-value-bind (result stat-struct) 
		       (linux:stat path)
    (when (/= result -1)
      (linux:S_ISDIR (slot-value stat-struct 'linux::|st_mode|)))))

This is ugly stuff: wrap, wrap, wrap. :)

---

From: Sam Steingold <[email-masked]>
Date: Thu Feb 14 16:37:08 2002

> * In message <[email-masked]>
> * On the subject of "[clisp-list] linux:readdir always returns d_type=0 ?"
> * Sent on Thu, 14 Feb 2002 12:54:49 -0800 (PST)
> * Honorable Klaus Momberger <[email-masked]> writes:
>

I do not observe this:

[1]> (setf dir (linux:opendir "/etc"))
#<FOREIGN-ADDRESS #x0826DC20>
[3]> (setf file (linux:readdir  dir))
#S(LINUX:dirent :|d_ino| 242881 :|d_off| 12 :|d_reclen| 16 :|d_type| 4
   :|d_name| ".")
[4]> (setf file (linux:readdir  dir))
#S(LINUX:dirent :|d_ino| 2 :|d_off| 24 :|d_reclen| 16 :|d_type| 4
   :|d_name| "..")
[5]> (setf file (linux:readdir  dir))
#S(LINUX:dirent :|d_ino| 259073 :|d_off| 44 :|d_reclen| 24 :|d_type| 4
   :|d_name| "sysconfig")
[6]> (setf file (linux:readdir  dir))
#S(LINUX:dirent :|d_ino| 291457 :|d_off| 56 :|d_reclen| 16 :|d_type| 4
   :|d_name| "X11")
[7]> (setf file (linux:readdir  dir))
#S(LINUX:dirent :|d_ino| 245042 :|d_off| 72 :|d_reclen| 24 :|d_type| 8
   :|d_name| "fstab")
[8]> (setf file (linux:readdir  dir))
#S(LINUX:dirent :|d_ino| 245046 :|d_off| 84 :|d_reclen| 16 :|d_type| 8
   :|d_name| "mtab")
[9]> (setf file (linux:readdir  dir))
#S(LINUX:dirent :|d_ino| 242884 :|d_off| 104 :|d_reclen| 24 :|d_type| 8
   :|d_name| "modules.conf")
[10]> (setf file (linux:readdir  dir))
#S(LINUX:dirent :|d_ino| 243046 :|d_off| 128 :|d_reclen| 24 :|d_type| 8
   :|d_name| "mime.types")
[11]> (setf file (linux:readdir  dir))
#S(LINUX:dirent :|d_ino| 243045 :|d_off| 144 :|d_reclen| 24 :|d_type| 8
   :|d_name| "mailcap")
[12]> (setf file (linux:readdir  dir))
#S(LINUX:dirent :|d_ino| 243048 :|d_off| 164 :|d_reclen| 24 :|d_type| 8
   :|d_name| "bashrc")
[13]> (setf file (linux:readdir  dir))
#S(LINUX:dirent :|d_ino| 243047 :|d_off| 176 :|d_reclen| 16 :|d_type| 10
   :|d_name| "rmt")

this is with the current development CVS.

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat7.2 GNU/Linux
Keep Jerusalem united! <http://www.onejerusalem.org/Petition.asp>
Read, think and remember! <http://www.iris.org.il> <http://www.memri.org/>
My inferiority complex is not as good as yours.

---

From: Kaz Kylheku <[email-masked]>
Date: Thu Feb 14 21:47:01 2002

> #S(LINUX:dirent :|d_ino| 2 :|d_off| 24 :|d_reclen| 16 :|d_type| 4

Interesting. What kind of filesystem is your /etc on?

---

From: Sam Steingold <[email-masked]>
Date: Sun Feb 17 21:51:03 2002

> * In message <[email-masked]>
> * On the subject of "Re: [clisp-list] linux:readdir always returns d_type=0 ?"
> * Sent on Thu, 14 Feb 2002 21:46:02 -0800 (PST)
> * Honorable Kaz Kylheku <[email-masked]> writes:
>

ext3
why?

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat7.2 GNU/Linux
Keep Jerusalem united! <http://www.onejerusalem.org/Petition.asp>
Read, think and remember! <http://www.iris.org.il> <http://www.memri.org/>
Of course, I haven't tried it. But it will work.    - Isaak Asimov