mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
Add 'readdir' call.
This adds a readdir call (mostly intended for programs). The return value is a list of guestfs_dirent structures. This adds the new types 'struct guestfs_dirent' and 'struct guestfs_dirent_list', along with all the code to return these in the different language bindings. Also includes additional tests for OCaml and Perl bindings to test this.
This commit is contained in:
@@ -25,6 +25,7 @@ java_sources = \
|
||||
$(CPTH)/LV.java \
|
||||
$(CPTH)/Stat.java \
|
||||
$(CPTH)/StatVFS.java \
|
||||
$(CPTH)/Dirent.java \
|
||||
$(CPTH)/GuestFS.java
|
||||
|
||||
java_tests = \
|
||||
|
||||
34
java/com/redhat/et/libguestfs/Dirent.java
Normal file
34
java/com/redhat/et/libguestfs/Dirent.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/* libguestfs generated file
|
||||
* WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'.
|
||||
* ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
|
||||
*
|
||||
* Copyright (C) 2009 Red Hat Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package com.redhat.et.libguestfs;
|
||||
|
||||
/**
|
||||
* Libguestfs Dirent structure.
|
||||
*
|
||||
* @author rjones
|
||||
* @see GuestFS
|
||||
*/
|
||||
public class Dirent {
|
||||
public long ino;
|
||||
public char ftyp;
|
||||
public String name;
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import com.redhat.et.libguestfs.LV;
|
||||
import com.redhat.et.libguestfs.Stat;
|
||||
import com.redhat.et.libguestfs.StatVFS;
|
||||
import com.redhat.et.libguestfs.IntBool;
|
||||
import com.redhat.et.libguestfs.Dirent;
|
||||
|
||||
/**
|
||||
* The GuestFS object is a libguestfs handle.
|
||||
@@ -4054,4 +4055,30 @@ public HashMap<String,String> test0rhashtableerr ()
|
||||
private native int _umask (long g, int mask)
|
||||
throws LibGuestFSException;
|
||||
|
||||
/**
|
||||
* read directories entries
|
||||
* <p>
|
||||
* This returns the list of directory entries in directory
|
||||
* "dir".
|
||||
* <p>
|
||||
* All entries in the directory are returned, including "."
|
||||
* and "..". The entries are *not* sorted, but returned in
|
||||
* the same order as the underlying filesystem.
|
||||
* <p>
|
||||
* This function is primarily intended for use by programs.
|
||||
* To get a simple list of names, use "g.ls". To get a
|
||||
* printable directory for human consumption, use "g.ll".
|
||||
* <p>
|
||||
* @throws LibGuestFSException
|
||||
*/
|
||||
public Dirent[] readdir (String dir)
|
||||
throws LibGuestFSException
|
||||
{
|
||||
if (g == 0)
|
||||
throw new LibGuestFSException ("readdir: handle is closed");
|
||||
return _readdir (g, dir);
|
||||
}
|
||||
private native Dirent[] _readdir (long g, String dir)
|
||||
throws LibGuestFSException;
|
||||
|
||||
}
|
||||
|
||||
@@ -4635,3 +4635,39 @@ Java_com_redhat_et_libguestfs_GuestFS__1umask
|
||||
return (jint) r;
|
||||
}
|
||||
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
Java_com_redhat_et_libguestfs_GuestFS__1readdir
|
||||
(JNIEnv *env, jobject obj, jlong jg, jstring jdir)
|
||||
{
|
||||
guestfs_h *g = (guestfs_h *) (long) jg;
|
||||
jobjectArray jr;
|
||||
jclass cl;
|
||||
jfieldID fl;
|
||||
jobject jfl;
|
||||
struct guestfs_dirent_list *r;
|
||||
const char *dir;
|
||||
int i;
|
||||
|
||||
dir = (*env)->GetStringUTFChars (env, jdir, NULL);
|
||||
r = guestfs_readdir (g, dir);
|
||||
(*env)->ReleaseStringUTFChars (env, jdir, dir);
|
||||
if (r == NULL) {
|
||||
throw_exception (env, guestfs_last_error (g));
|
||||
return NULL;
|
||||
}
|
||||
cl = (*env)->FindClass (env, "com/redhat/et/libguestfs/Dirent");
|
||||
jr = (*env)->NewObjectArray (env, r->len, cl, NULL);
|
||||
for (i = 0; i < r->len; ++i) {
|
||||
jfl = (*env)->AllocObject (env, cl);
|
||||
fl = (*env)->GetFieldID (env, cl, "ino", "J");
|
||||
(*env)->SetLongField (env, jfl, fl, r->val[i].ino);
|
||||
fl = (*env)->GetFieldID (env, cl, "ftyp", "J");
|
||||
(*env)->SetLongField (env, jfl, fl, r->val[i].ftyp);
|
||||
fl = (*env)->GetFieldID (env, cl, "name", "Ljava/lang/String;");
|
||||
(*env)->SetObjectField (env, jfl, fl, (*env)->NewStringUTF (env, r->val[i].name));
|
||||
(*env)->SetObjectArrayElement (env, jfl, i, jfl);
|
||||
}
|
||||
guestfs_free_dirent_list (r);
|
||||
return jr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user