

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
19 messages in net.java.dev.jna.usersRe: [jna-users] Re: Identifying symbo...| From | Sent On | Attachments |
|---|---|---|
| Timothy Wall | Dec 11, 2007 5:34 am | |
| Normen Müller | Dec 11, 2007 6:35 am | |
| Normen Müller | Dec 11, 2007 6:52 am | |
| Timothy Wall | Dec 11, 2007 7:20 am | |
| Timothy Wall | Dec 11, 2007 7:53 am | |
| Timothy Wall | Dec 11, 2007 7:55 am | |
| Nikolas Lotz | Dec 11, 2007 8:05 am | |
| Normen Müller | Dec 11, 2007 8:27 am | |
| Normen Müller | Dec 11, 2007 8:37 am | |
| Timothy Wall | Dec 11, 2007 10:25 am | |
| Duncan McGregor | Dec 11, 2007 3:05 pm | |
| Normen Müller | Dec 12, 2007 12:04 am | |
| Peter Reilly | Dec 12, 2007 1:34 am | |
| Normen Müller | Dec 12, 2007 1:39 am | |
| Timothy Wall | Dec 12, 2007 4:34 am | |
| Timothy Wall | Dec 12, 2007 4:38 am | |
| Normen Müller | Dec 12, 2007 4:57 am | |
| Normen Müller | Dec 12, 2007 5:04 am | |
| Timothy Wall | Dec 12, 2007 5:36 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [jna-users] Re: Identifying symbolic links on Mac OSX 10.5.1 | Actions... |
|---|---|---|
| From: | Normen Müller (n.mu...@jacobs-university.de) | |
| Date: | Dec 12, 2007 5:04:56 am | |
| List: | net.java.dev.jna.users | |
On Dec 12, 2007, at 1:57 PM, Normen Müller wrote:
However I guess I still have to modify
int mode = SVNFileUtil.isOSX || SVNFileUtil.isBSD ? ourSharedMemory.getShort(8) : ourSharedMemory.getShort(16);
I guess it should rather be something like:
int mode = 0 if (SVNFileUtil.isOSX) mode = ourSharedMemory.getShort(8) if (SVNFileUtil.isBSD) mode = ourSharedMemory.getInt(8);
Oops, I mean
int mode = 0 if (SVNFileUtil.isOSX) mode = ourSharedMemory.getShort(8); if (SVNFileUtil.isBSD) mode = ourSharedMemory.getInt(8); else mode = ourSharedMemory.getInt(16);
But unfortunately I am not sure :-\
/nm
Otherwise this code will not work on a proper linux system, right?
Regarding your last question ``what are the values (in hex) in either case''? I don't really understand what you are asking me for :-\ Do you mean the hex value of ``mode'' variable?
So class look like this now:
class SVNLinuxUtil {
private static Memory ourSharedMemory;
static { try { ourSharedMemory = new Memory(1024); } catch (Throwable th) { ourSharedMemory = null; } }
public static SVNFileType getFileType(File file) { if (file == null || ourSharedMemory == null) { return null; } String path = file.getAbsolutePath(); if (path.endsWith("/") && path.length() > 1) { path = path.substring(0, path.length() - 1); } try { ISVNCLibrary cLibrary = JNALibraryLoader.getCLibrary(); if (cLibrary == null) { return null; } synchronized (ourSharedMemory) { ourSharedMemory.clear(); int rc; synchronized (cLibrary) { rc = SVNFileUtil.isOSX || SVNFileUtil.isBSD ? cLibrary.lstat(path, ourSharedMemory) : cLibrary.__lxstat64(0, path, ourSharedMemory); } if (rc < 0) { if (file.exists() || file.isDirectory() || file.isFile()) { return null; } return SVNFileType.NONE; } /* int mode = SVNFileUtil.isOSX || SVNFileUtil.isBSD ? ourSharedMemory.getInt(8) : ourSharedMemory.getInt(16); */ int mode = SVNFileUtil.isOSX || SVNFileUtil.isBSD ? ourSharedMemory.getShort(8) : ourSharedMemory.getShort(16); int type = mode & 0170000; if (type == 0120000) { return SVNFileType.SYMLINK; } else if (type == 0040000) { return SVNFileType.DIRECTORY; } else if (type == 0100000) { return SVNFileType.FILE; } else { if (file.exists() || file.isDirectory() || file.isFile()) { return null; } return SVNFileType.NONE; } } } catch (Throwable th) { // } return null; } }
On Dec 12, 2007, at 4:39 AM, Normen Müller wrote:
I just ran your little C program and the output is ``offset=8''. So, shouldn't
int mode = SVNFileUtil.isOSX || SVNFileUtil.isBSD ? ourSharedMemory.getInt(8) : ourSharedMemory.getInt(16);
just work fine?
Cheers, /nm
On Dec 11, 2007, at 7:25 PM, Timothy Wall wrote:
It only makes sense to define the full struct if you're going to use it. If you're using a single field, it may not be worth the effort. The benefit of defining the structure is you don't have to manually calculate its size or any field offset, you just have to map each field to the appropriately-sized type.
Write a simple C program that calculates the offset of the field you want:
#include <stdio.h> #include <sys/stat.h>
int main(int argc, char* argv[]) { struct stat s; printf("offset=%d\n", (char*)&s.st_mode - (char*)&s); }
If ino_t or dev_t correspond to the size of a pointer, then you can use Pointer.SIZE as the basis for the offset, rather than hardcoding 4 bytes per field.
On Dec 11, 2007, at 11:37 AM, Normen Müller wrote:
Ok, first I looked at /Developer/SDKs/MacOSX10.5.sdk/usr/include/ sys/ , but, although they are not linked, it seems like the files are equal to /usr/include/sys/
I will add some snippets out of /usr/include/sys/stat.h, maybe you could help me on how to clean up the code:
[...] /* * This structure is used as the second parameter to the fstat64(), * lstat64(), and stat64() functions, and for struct stat when * __DARWIN_64_BIT_INO_T is set. __DARWIN_STRUCT_STAT64 is defined * above, depending on whether we use struct timespec or the direct * components. * * This is simillar to stat except for 64bit inode number * number instead of 32bit ino_t and the addition of create(birth) time. */ #define __DARWIN_STRUCT_STAT64 { \ dev_t st_dev; /* [XSI] ID of device containing file */ \ mode_t st_mode; /* [XSI] Mode of file (see below) */ \ nlink_t st_nlink; /* [XSI] Number of hard links */ \ __darwin_ino64_t st_ino; /* [XSI] File serial number */ \ uid_t st_uid; /* [XSI] User ID of the file */ \ gid_t st_gid; /* [XSI] Group ID of the file */ \ dev_t st_rdev; /* [XSI] Device ID */ \ __DARWIN_STRUCT_STAT64_TIMES \ off_t st_size; /* [XSI] file size, in bytes */ \ blkcnt_t st_blocks; /* [XSI] blocks allocated for file */ \ blksize_t st_blksize; /* [XSI] optimal blocksize for I/O */ \ __uint32_t st_flags; /* user defined flags for file */ \ __uint32_t st_gen; /* file generation number */ \ __int32_t st_lspare; /* RESERVED: DO NOT USE! */ \ __int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */ \ }
/* * [XSI] This structure is used as the second parameter to the fstat(), * lstat(), and stat() functions. */ #if __DARWIN_64_BIT_INO_T
struct stat __DARWIN_STRUCT_STAT64;
#else /* !__DARWIN_64_BIT_INO_T */
struct stat { dev_t st_dev; /* [XSI] ID of device containing file */ ino_t st_ino; /* [XSI] File serial number */ mode_t st_mode; /* [XSI] Mode of file (see below) */ nlink_t st_nlink; /* [XSI] Number of hard links */ uid_t st_uid; /* [XSI] User ID of the file */ gid_t st_gid; /* [XSI] Group ID of the file */ dev_t st_rdev; /* [XSI] Device ID */ #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) struct timespec st_atimespec; /* time of last access */ struct timespec st_mtimespec; /* time of last data modification */ struct timespec st_ctimespec; /* time of last status change */ #else time_t st_atime; /* [XSI] Time of last access */ long st_atimensec; /* nsec of last access */ time_t st_mtime; /* [XSI] Last data modification time */ long st_mtimensec; /* last data modification nsec */ time_t st_ctime; /* [XSI] Time of last status change */ long st_ctimensec; /* nsec of last status change */ #endif off_t st_size; /* [XSI] file size, in bytes */ blkcnt_t st_blocks; /* [XSI] blocks allocated for file */ blksize_t st_blksize; /* [XSI] optimal blocksize for I/O */ __uint32_t st_flags; /* user defined flags for file */ __uint32_t st_gen; /* file generation number */ __int32_t st_lspare; /* RESERVED: DO NOT USE! */ __int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */ };
#endif /* __DARWIN_64_BIT_INO_T */
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
struct stat64 __DARWIN_STRUCT_STAT64;
#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
[...]
#ifndef S_IFMT /* File type */ #define S_IFMT 0170000 /* [XSI] type of file mask */ #define S_IFIFO 0010000 /* [XSI] named pipe (fifo) */ #define S_IFCHR 0020000 /* [XSI] character special */ #define S_IFDIR 0040000 /* [XSI] directory */ #define S_IFBLK 0060000 /* [XSI] block special */ #define S_IFREG 0100000 /* [XSI] regular */ #define S_IFLNK 0120000 /* [XSI] symbolic link */ #define S_IFSOCK 0140000 /* [XSI] socket */ #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) #define S_IFWHT 0160000 /* whiteout */ #define S_IFXATTR 0200000 /* extended attribute */ #endif
So as far as I can see the used constant in SVNKit are alright and the used offset as well, but there must be something else, cause it still doesn't work.
But, as I don't want to get on your nerves, do you have any further suggestions on how I can fix this code? Maybe you can teach me how to define the stat structure in Java, cause I guess than I don't need this offset-thing, right?
Cheers, /nm
On Dec 11, 2007, at 4:20 PM, Timothy Wall wrote:
try "cat /usr/include/sys/stat.h", which is where the function is declared.
On Dec 11, 2007, at 9:52 AM, Normen Müller wrote:
On Dec 11, 2007, at 2:34 PM, Timothy Wall wrote:
Several things to look at: 1) how is the C library loaded? is it loaded properly on OSX (i.e. do you get an instance of ISVNCLibrary)? 2) how is lstat defined on OSX 10.5.1? in glibc, it is a macro that points to _xstat
All I could find is:
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/lstat.2.html
/nm
I would recommend writing a small unit test program that reproduces the SVNKit code, then you can instrument it as needed to figure out where it is failing.
On Dec 11, 2007, at 7:12 AM, Normen Müller wrote:
Dear JNA developers,
could you point me to an example on how to identifying symbolic links on Mac OS 10.5.1?
Currently I am using SVNKit@HEAD which pointed my to your library. In SVNKit there is a function for identifying file types, but on my Mac OS X 10.5.1 it always returns null, no matter if I commit a symbolic link to a directory or to a file.
Do you have any ideas how to fix this?
In the following is a copy of getFileType function out of the SVNKit library:
public static SVNFileType getFileType(File file) { if (file == null || ourSharedMemory == null) { return null; } String path = file.getAbsolutePath(); if (path.endsWith("/") && path.length() > 1) { path = path.substring(0, path.length() - 1); } try { ISVNCLibrary cLibrary = JNALibraryLoader.getCLibrary(); if (cLibrary == null) { return null; } synchronized (ourSharedMemory) { ourSharedMemory.clear(); int rc; synchronized (cLibrary) { rc = SVNFileUtil.isOSX || SVNFileUtil.isBSD ? cLibrary.lstat(path, ourSharedMemory) : cLibrary.__lxstat64(0, path, ourSharedMemory); } if (rc < 0) { if (file.exists() || file.isDirectory() || file.isFile()) { return null; } return SVNFileType.NONE; } int mode = SVNFileUtil.isOSX || SVNFileUtil.isBSD ? ourSharedMemory.getInt(8) : ourSharedMemory.getInt(16); int type = mode & 0170000; if (type == 0120000) { return SVNFileType.SYMLINK; } else if (type == 0040000) { return SVNFileType.DIRECTORY; } else if (type == 0100000) { return SVNFileType.FILE; } else { if (file.exists() || file.isDirectory() || file.isFile()) { return null; } return SVNFileType.NONE; } } } catch (Throwable th) { // } return null; }
I would appreciate your help, /nm







