svn commit: r259590 - head/lib/libstand

Marcel Moolenaar marcel at FreeBSD.org
Thu Dec 19 05:23:11 UTC 2013


Author: marcel
Date: Thu Dec 19 05:23:10 2013
New Revision: 259590
URL: http://svnweb.freebsd.org/changeset/base/259590

Log:
  Fix readdir for the root directory on a FAT32 file system. The root
  directory is like any subdirectory and as such needs to use a real
  cluster number. To this end, keep a DE structure for the root in
  the DOS_FS structure and populate it accordingly.
  
  While here:
  o   allow consecutive path separators by skipping them all.
  o   add missing $FreeBSD$ keyword to dosfs.h.

Modified:
  head/lib/libstand/dosfs.c
  head/lib/libstand/dosfs.h

Modified: head/lib/libstand/dosfs.c
==============================================================================
--- head/lib/libstand/dosfs.c	Thu Dec 19 05:22:48 2013	(r259589)
+++ head/lib/libstand/dosfs.c	Thu Dec 19 05:23:10 2013	(r259590)
@@ -162,6 +162,14 @@ dos_mount(DOS_FS *fs, struct open_file *
         (void)dosunmount(fs);
         return(err);
     }
+    fs->root = dot[0];
+    fs->root.name[0] = ' ';
+    if (fs->fatsz == 32) {
+        fs->root.clus[0] = fs->rdcl & 0xff;
+        fs->root.clus[1] = (fs->rdcl >> 8) & 0xff;
+        fs->root.dex.h_clus[0] = (fs->rdcl >> 16) & 0xff;
+        fs->root.dex.h_clus[1] = (fs->rdcl >> 24) & 0xff;
+    }
     return 0;
 }
 
@@ -494,10 +502,12 @@ namede(DOS_FS *fs, const char *path, DOS
     int err;
 
     err = 0;
-    de = dot;
-    if (*path == '/')
-        path++;
+    de = &fs->root;
     while (*path) {
+        while (*path == '/')
+            path++;
+        if (*path == '\0')
+            break;
         if (!(s = strchr(path, '/')))
             s = strchr(path, 0);
         if ((n = s - path) > 255)
@@ -509,8 +519,6 @@ namede(DOS_FS *fs, const char *path, DOS
             return ENOTDIR;
         if ((err = lookup(fs, stclus(fs->fatsz, de), name, &de)))
             return err;
-        if (*path == '/')
-            path++;
     }
     *dep = de;
     return 0;

Modified: head/lib/libstand/dosfs.h
==============================================================================
--- head/lib/libstand/dosfs.h	Thu Dec 19 05:22:48 2013	(r259589)
+++ head/lib/libstand/dosfs.h	Thu Dec 19 05:23:10 2013	(r259590)
@@ -23,6 +23,8 @@
  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
  */
 
 #ifndef DOSIO_H
@@ -108,6 +110,7 @@ typedef struct {
     u_int lsndta;               /* start of data area */
     u_int fatsz;                /* FAT entry size */
     u_int xclus;                /* maximum cluster number */
+    DOS_DE root;
 } DOS_FS;
 
 typedef struct {


More information about the svn-src-all mailing list