[haiku-commits] r35523 - haiku/trunk/src/add-ons/kernel/file_systems/fat

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 19 Feb 2010 17:52:55 +0100 (CET)

Author: axeld
Date: 2010-02-19 17:52:55 +0100 (Fri, 19 Feb 2010)
New Revision: 35523
Changeset: http://dev.haiku-os.org/changeset/35523/haiku
Ticket: http://dev.haiku-os.org/ticket/4602

Modified:
   haiku/trunk/src/add-ons/kernel/file_systems/fat/dosfs.c
   haiku/trunk/src/add-ons/kernel/file_systems/fat/util.c
   haiku/trunk/src/add-ons/kernel/file_systems/fat/util.h
Log:
* Applied slightly cleaned up patch by romain that sanitizes the volume names.
* This closes bug #4602.


Modified: haiku/trunk/src/add-ons/kernel/file_systems/fat/dosfs.c
===================================================================
--- haiku/trunk/src/add-ons/kernel/file_systems/fat/dosfs.c     2010-02-19 
16:44:55 UTC (rev 35522)
+++ haiku/trunk/src/add-ons/kernel/file_systems/fat/dosfs.c     2010-02-19 
16:52:55 UTC (rev 35523)
@@ -187,7 +187,7 @@
        uint8 media_buf[512];
        int i;
        status_t err;
-                       
+
        if ((vol = (nspace *)calloc(sizeof(nspace), 1)) == NULL) {
                dprintf("dosfs error: out of memory\n");
                return NULL;
@@ -303,7 +303,7 @@
                                0x00, 0x02, 0x04, 0x01, 0x00, 0x02, 0x00, 0x02, 
0x00, 0x00,
                                0xf8, 0xc0, 0x00, 0x20, 0x00, 0x40, 0x00, 0x20, 
0x00, 0x00
                        };
-       
+
                        if (memcmp(buf + 0x0b, bogus_zip_data, 
sizeof(bogus_zip_data)) == 0
                                && vol->total_sectors == 196576
                                && ((off_t)geo->sectors_per_track * 
(off_t)geo->cylinder_count
@@ -497,7 +497,7 @@
        int vol_flags;
 
        vol_flags = B_FS_IS_PERSISTENT | B_FS_HAS_MIME;
- 
+
        // open read-only for now
        if ((err = (fd = open(path, O_RDONLY | O_NOCACHE))) < 0) {
                dprintf("dosfs error: unable to open %s (%s)\n", path, 
strerror(err));
@@ -575,7 +575,7 @@
                dprintf("dosfs error: error reading boot sector\n");
                goto error1;
        }
-       
+
        vol = volume_init(fd, buf, vol_flags, fs_flags, &geo);
 
        /* check that the partition is large enough to contain the file system 
*/
@@ -765,6 +765,7 @@
 
        cookie->bytes_per_sector = bytes_per_sector;
        cookie->total_sectors = total_sectors;
+       sanitize_name(name, 12);
        strlcpy(cookie->name, name, 12);
        *_cookie = cookie;
 
@@ -994,7 +995,6 @@
 dosfs_read_fs_stat(fs_volume *_vol, struct fs_info * fss)
 {
        nspace* vol = (nspace*)_vol->private_volume;
-       int i;
 
        LOCK_VOL(vol);
 
@@ -1021,19 +1021,11 @@
        strncpy(fss->device_name, vol->device, sizeof(fss->device_name));
 
        if (vol->vol_entry > -2)
-               strncpy(fss->volume_name, vol->vol_label, 
sizeof(fss->volume_name));
+               strlcpy(fss->volume_name, vol->vol_label, 
sizeof(fss->volume_name));
        else
                strcpy(fss->volume_name, "no name");
 
-       // XXX: should sanitize name as well
-       for (i=10;i>0;i--)
-               if (fss->volume_name[i] != ' ')
-                       break;
-       fss->volume_name[i+1] = 0;
-       for (;i>=0;i--) {
-               if ((fss->volume_name[i] >= 'A') && (fss->volume_name[i] <= 
'Z'))
-                       fss->volume_name[i] += 'a' - 'A';
-       }
+       sanitize_name(fss->volume_name, 12);
 
        // File system name
        strcpy(fss->fsh_name, "fat");

Modified: haiku/trunk/src/add-ons/kernel/file_systems/fat/util.c
===================================================================
--- haiku/trunk/src/add-ons/kernel/file_systems/fat/util.c      2010-02-19 
16:44:55 UTC (rev 35522)
+++ haiku/trunk/src/add-ons/kernel/file_systems/fat/util.c      2010-02-19 
16:52:55 UTC (rev 35523)
@@ -2,6 +2,8 @@
        Copyright 1999-2001, Be Incorporated.   All Rights Reserved.
        This file may be used under the terms of the Be Sample Code License.
 */
+
+
 #include <SupportDefs.h>
 #include <KernelExport.h>
 
@@ -164,3 +166,20 @@
                c = (c << 7) + (c >> 1) + *(p++);
        return c;
 }
+
+
+void
+sanitize_name(char *name, int length)
+{
+       int i;
+
+       for (i = length - 1; i > 0; i--) {
+               if (name[i] != ' ')
+                       break;
+       }
+       name[i + 1] = 0;
+       for (; i >= 0; i--) {
+               if (name[i] >= 'A' && name[i] <= 'Z')
+                       name[i] += 'a' - 'A';
+       }
+}

Modified: haiku/trunk/src/add-ons/kernel/file_systems/fat/util.h
===================================================================
--- haiku/trunk/src/add-ons/kernel/file_systems/fat/util.h      2010-02-19 
16:44:55 UTC (rev 35522)
+++ haiku/trunk/src/add-ons/kernel/file_systems/fat/util.h      2010-02-19 
16:52:55 UTC (rev 35523)
@@ -5,8 +5,10 @@
 #ifndef _DOSFS_UTIL_H_
 #define _DOSFS_UTIL_H_
 
+
 #include <ByteOrder.h>
 
+
 // debugging functions
 #ifndef ASSERT
 #ifndef DEBUG
@@ -25,6 +27,7 @@
 uint32 time_t2dos(time_t s);
 
 uint8  hash_msdos_name(const char *name);
+void   sanitize_name(char *name, int length);
 
 #if 0
 #define read32(buffer,off) \
@@ -41,4 +44,4 @@
 #define read16(buffer,off) \
        B_LENDIAN_TO_HOST_INT16(*(uint16 *)&buffer[off])
 
-#endif
+#endif /* _DOSFS_UTIL_H_ */


Other related posts:

  • » [haiku-commits] r35523 - haiku/trunk/src/add-ons/kernel/file_systems/fat - axeld