* Applied slightly cleaned up patch by romain that sanitizes the volume names.
* This closes bug #4602. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35523 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -187,7 +187,7 @@ volume_init(int fd, uint8* buf,
|
|||||||
uint8 media_buf[512];
|
uint8 media_buf[512];
|
||||||
int i;
|
int i;
|
||||||
status_t err;
|
status_t err;
|
||||||
|
|
||||||
if ((vol = (nspace *)calloc(sizeof(nspace), 1)) == NULL) {
|
if ((vol = (nspace *)calloc(sizeof(nspace), 1)) == NULL) {
|
||||||
dprintf("dosfs error: out of memory\n");
|
dprintf("dosfs error: out of memory\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -303,7 +303,7 @@ volume_init(int fd, uint8* buf,
|
|||||||
0x00, 0x02, 0x04, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00,
|
0x00, 0x02, 0x04, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00,
|
||||||
0xf8, 0xc0, 0x00, 0x20, 0x00, 0x40, 0x00, 0x20, 0x00, 0x00
|
0xf8, 0xc0, 0x00, 0x20, 0x00, 0x40, 0x00, 0x20, 0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
if (memcmp(buf + 0x0b, bogus_zip_data, sizeof(bogus_zip_data)) == 0
|
if (memcmp(buf + 0x0b, bogus_zip_data, sizeof(bogus_zip_data)) == 0
|
||||||
&& vol->total_sectors == 196576
|
&& vol->total_sectors == 196576
|
||||||
&& ((off_t)geo->sectors_per_track * (off_t)geo->cylinder_count
|
&& ((off_t)geo->sectors_per_track * (off_t)geo->cylinder_count
|
||||||
@@ -497,7 +497,7 @@ mount_fat_disk(const char *path, fs_volume *_vol, const int flags,
|
|||||||
int vol_flags;
|
int vol_flags;
|
||||||
|
|
||||||
vol_flags = B_FS_IS_PERSISTENT | B_FS_HAS_MIME;
|
vol_flags = B_FS_IS_PERSISTENT | B_FS_HAS_MIME;
|
||||||
|
|
||||||
// open read-only for now
|
// open read-only for now
|
||||||
if ((err = (fd = open(path, O_RDONLY | O_NOCACHE))) < 0) {
|
if ((err = (fd = open(path, O_RDONLY | O_NOCACHE))) < 0) {
|
||||||
dprintf("dosfs error: unable to open %s (%s)\n", path, strerror(err));
|
dprintf("dosfs error: unable to open %s (%s)\n", path, strerror(err));
|
||||||
@@ -575,7 +575,7 @@ mount_fat_disk(const char *path, fs_volume *_vol, const int flags,
|
|||||||
dprintf("dosfs error: error reading boot sector\n");
|
dprintf("dosfs error: error reading boot sector\n");
|
||||||
goto error1;
|
goto error1;
|
||||||
}
|
}
|
||||||
|
|
||||||
vol = volume_init(fd, buf, vol_flags, fs_flags, &geo);
|
vol = volume_init(fd, buf, vol_flags, fs_flags, &geo);
|
||||||
|
|
||||||
/* check that the partition is large enough to contain the file system */
|
/* check that the partition is large enough to contain the file system */
|
||||||
@@ -765,6 +765,7 @@ dosfs_identify_partition(int fd, partition_data *partition, void **_cookie)
|
|||||||
|
|
||||||
cookie->bytes_per_sector = bytes_per_sector;
|
cookie->bytes_per_sector = bytes_per_sector;
|
||||||
cookie->total_sectors = total_sectors;
|
cookie->total_sectors = total_sectors;
|
||||||
|
sanitize_name(name, 12);
|
||||||
strlcpy(cookie->name, name, 12);
|
strlcpy(cookie->name, name, 12);
|
||||||
*_cookie = cookie;
|
*_cookie = cookie;
|
||||||
|
|
||||||
@@ -994,7 +995,6 @@ static status_t
|
|||||||
dosfs_read_fs_stat(fs_volume *_vol, struct fs_info * fss)
|
dosfs_read_fs_stat(fs_volume *_vol, struct fs_info * fss)
|
||||||
{
|
{
|
||||||
nspace* vol = (nspace*)_vol->private_volume;
|
nspace* vol = (nspace*)_vol->private_volume;
|
||||||
int i;
|
|
||||||
|
|
||||||
LOCK_VOL(vol);
|
LOCK_VOL(vol);
|
||||||
|
|
||||||
@@ -1021,19 +1021,11 @@ dosfs_read_fs_stat(fs_volume *_vol, struct fs_info * fss)
|
|||||||
strncpy(fss->device_name, vol->device, sizeof(fss->device_name));
|
strncpy(fss->device_name, vol->device, sizeof(fss->device_name));
|
||||||
|
|
||||||
if (vol->vol_entry > -2)
|
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
|
else
|
||||||
strcpy(fss->volume_name, "no name");
|
strcpy(fss->volume_name, "no name");
|
||||||
|
|
||||||
// XXX: should sanitize name as well
|
sanitize_name(fss->volume_name, 12);
|
||||||
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';
|
|
||||||
}
|
|
||||||
|
|
||||||
// File system name
|
// File system name
|
||||||
strcpy(fss->fsh_name, "fat");
|
strcpy(fss->fsh_name, "fat");
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
||||||
This file may be used under the terms of the Be Sample Code License.
|
This file may be used under the terms of the Be Sample Code License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
|
|
||||||
@@ -164,3 +166,20 @@ hash_msdos_name(const char *name)
|
|||||||
c = (c << 7) + (c >> 1) + *(p++);
|
c = (c << 7) + (c >> 1) + *(p++);
|
||||||
return c;
|
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';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,8 +5,10 @@
|
|||||||
#ifndef _DOSFS_UTIL_H_
|
#ifndef _DOSFS_UTIL_H_
|
||||||
#define _DOSFS_UTIL_H_
|
#define _DOSFS_UTIL_H_
|
||||||
|
|
||||||
|
|
||||||
#include <ByteOrder.h>
|
#include <ByteOrder.h>
|
||||||
|
|
||||||
|
|
||||||
// debugging functions
|
// debugging functions
|
||||||
#ifndef ASSERT
|
#ifndef ASSERT
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
@@ -25,6 +27,7 @@ time_t dos2time_t(uint32 t);
|
|||||||
uint32 time_t2dos(time_t s);
|
uint32 time_t2dos(time_t s);
|
||||||
|
|
||||||
uint8 hash_msdos_name(const char *name);
|
uint8 hash_msdos_name(const char *name);
|
||||||
|
void sanitize_name(char *name, int length);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#define read32(buffer,off) \
|
#define read32(buffer,off) \
|
||||||
@@ -41,4 +44,4 @@ uint8 hash_msdos_name(const char *name);
|
|||||||
#define read16(buffer,off) \
|
#define read16(buffer,off) \
|
||||||
B_LENDIAN_TO_HOST_INT16(*(uint16 *)&buffer[off])
|
B_LENDIAN_TO_HOST_INT16(*(uint16 *)&buffer[off])
|
||||||
|
|
||||||
#endif
|
#endif /* _DOSFS_UTIL_H_ */
|
||||||
|
|||||||
Reference in New Issue
Block a user