libcdio-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Libcdio-devel] [PATCH 3/4] Add UDF support to iso-info


From: Christophe Fergeau
Subject: [Libcdio-devel] [PATCH 3/4] Add UDF support to iso-info
Date: Wed, 17 Oct 2012 13:45:36 +0200

The code comes from examples/udf1.c
---
 src/Makefile.am |  2 +-
 src/iso-info.c  | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 78 insertions(+), 6 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 2339fe9..3430531 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -59,7 +59,7 @@ endif
 
 if BUILD_ISO_INFO
 iso_info_SOURCES = iso-info.c util.c util.h $(GETOPT_C)
-iso_info_LDADD   = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LTLIBICONV)
+iso_info_LDADD   = $(LIBUDF_LIBS) $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) 
$(LTLIBICONV)
 bin_iso_info     = iso-info
 man_iso_info     = iso-info.1
 endif
diff --git a/src/iso-info.c b/src/iso-info.c
index b4c04b9..5ca384b 100644
--- a/src/iso-info.c
+++ b/src/iso-info.c
@@ -37,6 +37,7 @@
 #include <cdio/cdio.h>
 #include <cdio/ds.h>
 #include <cdio/iso9660.h>
+#include <cdio/udf.h>
 
 #ifdef HAVE_STDIO_H
 #include <stdio.h>
@@ -293,6 +294,75 @@ print_iso9660_fs (iso9660_t *iso)
   print_iso9660_recurse (iso, "/");
 }
 
+static void 
+print_udf_file_info(const udf_dirent_t *p_udf_dirent, const char* psz_dirname)
+{
+  time_t mod_time = udf_get_modification_time(p_udf_dirent);
+  char psz_mode[11]="invalid";
+  const char *psz_fname= psz_dirname 
+    ? psz_dirname : udf_get_filename(p_udf_dirent);
+
+  /* Print directory attributes*/
+  printf("%s ", udf_mode_string(udf_get_posix_filemode(p_udf_dirent),
+                               psz_mode));
+  printf("%4d ", udf_get_link_count(p_udf_dirent));
+  printf("%lu ", (long unsigned int) udf_get_file_length(p_udf_dirent));
+  printf("%s %s",  *psz_fname ? psz_fname : "/", ctime(&mod_time));
+}
+
+static udf_dirent_t *
+list_udf_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const char *psz_path)
+{
+  if (!p_udf_dirent) return NULL;
+  
+  print_udf_file_info(p_udf_dirent, psz_path);
+
+  while (udf_readdir(p_udf_dirent)) {
+      
+    if (udf_is_dir(p_udf_dirent)) {
+      
+      udf_dirent_t *p_udf_dirent2 = udf_opendir(p_udf_dirent);
+      if (p_udf_dirent2) {
+       const char *psz_dirname = udf_get_filename(p_udf_dirent);
+       const unsigned int i_newlen=2 + strlen(psz_path) + strlen(psz_dirname);
+       char *psz_newpath = calloc(1, sizeof(char)*i_newlen);
+       
+       snprintf(psz_newpath, i_newlen, "%s%s/", psz_path, psz_dirname);
+       list_udf_files(p_udf, p_udf_dirent2, psz_newpath);
+       free(psz_newpath);
+      }
+    } else {
+      print_udf_file_info(p_udf_dirent, NULL);
+    }
+  }
+  return p_udf_dirent;
+}
+
+static int
+print_udf_fs (void)
+{
+  udf_t *p_udf;
+
+  p_udf = udf_open (source_name);
+
+  if (NULL == p_udf) {
+    fprintf(stderr, "Sorry, couldn't open %s as something using UDF\n", 
+           source_name);
+    return 1;
+  } else {
+    udf_dirent_t *p_udf_root = udf_get_root(p_udf, true, 0);
+    if (NULL == p_udf_root) {
+      fprintf(stderr, "Sorry, couldn't find / in %s\n", 
+             source_name);
+      return 1;
+    }
+    
+    list_udf_files(p_udf, p_udf_root, "");
+  }
+  udf_close(p_udf);
+  return 0;
+}
+
 
 /* Initialize global variables. */
 static void 
@@ -369,12 +439,14 @@ main(int argc, char *argv[])
   }
   
   if (opts.print_iso9660 || opts.print_iso9660_short) {
-    printf(STRONG "ISO-9660 Information\n" NORMAL);
-    if (opts.print_iso9660 && opts.print_iso9660_short) {
-      printf("Note: both -f and -l options given -- "
-            "-l (long listing) takes precidence\n");
+    if (print_udf_fs() == 1) {
+        printf(STRONG "ISO-9660 Information\n" NORMAL);
+        if (opts.print_iso9660 && opts.print_iso9660_short) {
+            printf("Note: both -f and -l options given -- "
+                    "-l (long listing) takes precidence\n");
+        }
+        print_iso9660_fs(p_iso);
     }
-    print_iso9660_fs(p_iso);
   }
 
   free(source_name);
-- 
1.7.12.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]