Updated to 2001-04-20 BeBits release
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2984 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
ba5d0baeee
commit
72b94394b8
@ -2,7 +2,6 @@
|
||||
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
/* attr.c
|
||||
* handles mime type information for dosfs
|
||||
* gets/sets mime information in vnode
|
||||
|
@ -2,7 +2,6 @@
|
||||
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#ifndef _DOSFS_ATTR_H_
|
||||
#define _DOSFS_ATTR_H_
|
||||
|
||||
|
@ -738,11 +738,20 @@ status_t create_volume_label(nspace *vol, const char name[11], uint32 *index)
|
||||
bool is_filename_legal(const char *name)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int len = strlen(name);
|
||||
|
||||
if (len <= 0) return false;
|
||||
|
||||
// names ending with a dot are not allowed
|
||||
if (name[len - 1] == '.') return false;
|
||||
// names ending with a space are not allowed
|
||||
if (name[len - 1] == ' ') return false;
|
||||
|
||||
// XXX illegal character search can be made faster
|
||||
for(i=0; i<strlen(name); i++) {
|
||||
for(i=0; i<len; i++) {
|
||||
if(name[i] & 0x80) continue; //belongs to an utf8 char
|
||||
if(strchr(illegal, name[i])) return false;
|
||||
if(name[i] < 32) return false;
|
||||
if((unsigned char)name[i] < 32) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -790,18 +799,25 @@ status_t create_dir_entry(nspace *vol, vnode *dir, vnode *node,
|
||||
return error;
|
||||
}
|
||||
|
||||
// if there is a long name, patch short name and check for duplication
|
||||
// if there is a long name, patch short name if necessary and check for duplication
|
||||
if (requires_long_name(name, nlong)) {
|
||||
char tshort[11]; // temporary short name
|
||||
int iter = 1;
|
||||
|
||||
memcpy(tshort, nshort, 11);
|
||||
|
||||
do {
|
||||
memcpy(nshort, tshort, 11);
|
||||
DPRINTF(0, ("trying short name %11.11s\n", nshort));
|
||||
munge_short_name1(nshort, iter, encoding);
|
||||
} while (((error = find_short_name(vol, dir, nshort)) == B_OK) && (++iter < 10));
|
||||
if (requires_munged_short_name((uchar *)name, nshort, encoding))
|
||||
error = B_OK;
|
||||
else
|
||||
error = find_short_name(vol, dir, nshort);
|
||||
|
||||
if (error == B_OK) {
|
||||
do {
|
||||
memcpy(nshort, tshort, 11);
|
||||
DPRINTF(0, ("trying short name %11.11s\n", nshort));
|
||||
munge_short_name1(nshort, iter, encoding);
|
||||
} while (((error = find_short_name(vol, dir, nshort)) == B_OK) && (++iter < 10));
|
||||
}
|
||||
|
||||
if ((error != B_OK) && (error != ENOENT)) return error;
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#ifndef _DOSFS_DIR_H_
|
||||
#define _DOSFS_DIR_H_
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
/*
|
||||
directory vnode id list
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#ifndef _DOSFS_DLIST_H_
|
||||
#define _DOSFS_DLIST_H_
|
||||
|
||||
|
@ -40,6 +40,8 @@ int debug_attr = 0, debug_dir = 0, debug_dlist = 0, debug_dosfs = 0,
|
||||
CHECK_MAGIC(vnode,struct vnode,VNODE_MAGIC)
|
||||
CHECK_MAGIC(nspace,struct _nspace, NSPACE_MAGIC)
|
||||
|
||||
static status_t get_fsinfo(nspace *vol, uint32 *free_count, uint32 *last_allocated);
|
||||
|
||||
#if DEBUG
|
||||
|
||||
int32 instances = 0;
|
||||
@ -420,7 +422,7 @@ static status_t mount_fat_disk(const char *path, nspace_id nsid,
|
||||
vol->id = nsid;
|
||||
strncpy(vol->device,path,256);
|
||||
|
||||
// XXX: if fsinfo exists, read from there?
|
||||
// this will be updated later if fsinfo exists
|
||||
vol->last_allocated = 2;
|
||||
|
||||
vol->beos_vnid = INVALID_VNID_BITS_MASK;
|
||||
@ -453,11 +455,25 @@ static status_t mount_fat_disk(const char *path, nspace_id nsid,
|
||||
if (vol->flags & B_FS_IS_READONLY)
|
||||
vol->free_clusters = 0;
|
||||
else {
|
||||
if ((err = count_free_clusters(vol)) < 0) {
|
||||
dprintf("error counting free clusters (%s)\n", strerror(err));
|
||||
goto error3;
|
||||
uint32 free_count, last_allocated;
|
||||
err = get_fsinfo(vol, &free_count, &last_allocated);
|
||||
if (err >= 0) {
|
||||
if (free_count < vol->total_clusters)
|
||||
vol->free_clusters = free_count;
|
||||
else {
|
||||
dprintf("free cluster count from fsinfo block invalid %x\n",free_count);
|
||||
err = -1;
|
||||
}
|
||||
if (last_allocated < vol->total_clusters)
|
||||
vol->last_allocated = last_allocated; //update to a closer match
|
||||
}
|
||||
if (err < 0) {
|
||||
if ((err = count_free_clusters(vol)) < 0) {
|
||||
dprintf("error counting free clusters (%s)\n", strerror(err));
|
||||
goto error3;
|
||||
}
|
||||
vol->free_clusters = err;
|
||||
}
|
||||
vol->free_clusters = err;
|
||||
}
|
||||
|
||||
DPRINTF(0, ("built at %s on %s\n", build_time, build_date));
|
||||
@ -626,13 +642,17 @@ static void update_fsinfo(nspace *vol)
|
||||
uchar *buffer;
|
||||
if ((buffer = (uchar *)get_block(vol->fd, vol->fsinfo_sector, vol->bytes_per_sector)) != NULL) {
|
||||
if ((read32(buffer,0) == 0x41615252) && (read32(buffer,0x1e4) == 0x61417272) && (read16(buffer,0x1fe) == 0xaa55)) {
|
||||
//number of free clusters
|
||||
buffer[0x1e8] = (vol->free_clusters & 0xff);
|
||||
buffer[0x1e9] = ((vol->free_clusters >> 8) & 0xff);
|
||||
buffer[0x1ea] = ((vol->free_clusters >> 16) & 0xff);
|
||||
buffer[0x1eb] = ((vol->free_clusters >> 24) & 0xff);
|
||||
//cluster number of most recently allocated cluster
|
||||
buffer[0x1ec] = (vol->last_allocated & 0xff);
|
||||
buffer[0x1ed] = ((vol->last_allocated >> 8) & 0xff);
|
||||
buffer[0x1ee] = ((vol->last_allocated >> 16) & 0xff);
|
||||
buffer[0x1ef] = ((vol->last_allocated >> 24) & 0xff);
|
||||
mark_blocks_dirty(vol->fd, vol->fsinfo_sector, 1);
|
||||
|
||||
// should also store next free cluster
|
||||
} else {
|
||||
dprintf("update_fsinfo: fsinfo block has invalid magic number\n");
|
||||
}
|
||||
@ -643,6 +663,32 @@ static void update_fsinfo(nspace *vol)
|
||||
}
|
||||
}
|
||||
|
||||
static status_t get_fsinfo(nspace *vol, uint32 *free_count, uint32 *last_allocated)
|
||||
{
|
||||
uchar *buffer;
|
||||
int32 result;
|
||||
|
||||
if ((vol->fat_bits != 32) || (vol->fsinfo_sector == 0xffff))
|
||||
return B_ERROR;
|
||||
|
||||
if ((buffer = (uchar *)get_block(vol->fd, vol->fsinfo_sector, vol->bytes_per_sector)) == NULL) {
|
||||
dprintf("get_fsinfo: error getting fsinfo sector %x\n", vol->fsinfo_sector);
|
||||
return EIO;
|
||||
}
|
||||
|
||||
if ((read32(buffer,0) == 0x41615252) && (read32(buffer,0x1e4) == 0x61417272) && (read16(buffer,0x1fe) == 0xaa55)) {
|
||||
*free_count = read32(buffer,0x1e8);
|
||||
*last_allocated = read32(buffer,0x1ec);
|
||||
result = B_OK;
|
||||
} else {
|
||||
dprintf("get_fsinfo: fsinfo block has invalid magic number\n");
|
||||
result = B_ERROR;
|
||||
}
|
||||
|
||||
release_block(vol->fd, vol->fsinfo_sector);
|
||||
return result;
|
||||
}
|
||||
|
||||
static int dosfs_unmount(void *_vol)
|
||||
{
|
||||
int result = B_NO_ERROR;
|
||||
|
@ -31,6 +31,8 @@ enum {
|
||||
SJIS_CONVERSION
|
||||
};
|
||||
|
||||
#define BEGINS_UTF8CHAR(byte) (((byte) & 0xc0) != 0x80)
|
||||
|
||||
const uint16 msdostou[] = {
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
|
||||
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
|
||||
@ -1528,6 +1530,45 @@ status_t msdos_to_utf8(uchar *msdos, uchar *utf8, uint32 utf8len)
|
||||
(char *)utf8, (int32 *)&utf8len);
|
||||
}
|
||||
|
||||
bool requires_munged_short_name(const uchar *utf8name, const uchar nshort[11], int encoding)
|
||||
{
|
||||
int leading = 0;
|
||||
int trailing = 0;
|
||||
int i, len;
|
||||
|
||||
if (encoding != MS_DOS_CONVERSION) return true;
|
||||
|
||||
for ( ; *utf8name != 0; utf8name++) {
|
||||
if (!BEGINS_UTF8CHAR(*utf8name)) continue;
|
||||
if (*utf8name == '.') break;
|
||||
leading++;
|
||||
if (leading > 8) return true;
|
||||
if ((nshort[leading - 1] == '_') && (*utf8name != '_')) return true;
|
||||
}
|
||||
|
||||
if (*utf8name != 0) {
|
||||
utf8name++;
|
||||
|
||||
for ( ; *utf8name != 0; utf8name++) {
|
||||
if (!BEGINS_UTF8CHAR(*utf8name)) continue;
|
||||
if (*utf8name == '.') return true;
|
||||
trailing++;
|
||||
if (trailing > 3) return true;
|
||||
if ((nshort[leading + trailing - 1] == '_') && (*utf8name != '_')) return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0, len = 0; i < 8; i++)
|
||||
if (nshort[i] != ' ') len++;
|
||||
if (len != leading) return true;
|
||||
|
||||
for (i = 8, len = 0; i < 11; i++)
|
||||
if (nshort[i] != ' ') len++;
|
||||
if (len != trailing) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef USER
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
@ -2,7 +2,6 @@
|
||||
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#ifndef _DOSFS_ENCODINGS_H_
|
||||
#define _DOSFS_ENCODINGS_H_
|
||||
|
||||
@ -13,6 +12,9 @@ extern "C" {
|
||||
status_t unicode_to_utf8(const uchar *uni, uint32 unilen, uint8 *utf8,
|
||||
uint32 utf8len);
|
||||
|
||||
bool requires_munged_short_name(const uchar *utf8name,
|
||||
const uchar nshort[11], int encoding);
|
||||
|
||||
bool requires_long_name(const char *utf8, const uchar *unicode);
|
||||
status_t utf8_to_unicode(const char *utf8, uchar *uni, uint32 unilen);
|
||||
status_t munge_short_name2(uchar nshort[11], int encoding);
|
||||
|
@ -2,7 +2,6 @@
|
||||
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#include <KernelExport.h>
|
||||
|
||||
#include <fsproto.h>
|
||||
|
@ -2,7 +2,6 @@
|
||||
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#ifndef _DOSFS_FAT_H_
|
||||
#define _DOSFS_FAT_H_
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#ifndef _DOSFS_FILE_H_
|
||||
#define _DOSFS_FILE_H_
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#include <KernelExport.h>
|
||||
|
||||
#include <fsproto.h>
|
||||
|
@ -2,7 +2,6 @@
|
||||
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#ifndef _DOSFS_ITER_H_
|
||||
#define _DOSFS_ITER_H_
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
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>
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#ifndef _DOSFS_UTIL_H_
|
||||
#define _DOSFS_UTIL_H_
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
/*
|
||||
The FAT file system has no good way of assigning unique persistent values to
|
||||
nodes. The only obvious choice, storing the starting cluster number of the
|
||||
|
@ -2,7 +2,6 @@
|
||||
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#ifndef _DOSFS_VCACHE_H_
|
||||
#define _DOSFS_VCACHE_H_
|
||||
|
||||
|
@ -2,6 +2,5 @@
|
||||
Copyright 1999-2001, Be Incorporated. All Rights Reserved.
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
const char *build_time = __TIME__;
|
||||
const char *build_date = __DATE__;
|
||||
|
Loading…
Reference in New Issue
Block a user