Fixed a bug from ticket 4462. (fs_rstat returns an incorrect value).

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33091 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Gerasim Troeglazov 2009-09-12 11:43:55 +00:00
parent cc8605dc75
commit 9d034e38f1

View File

@ -53,26 +53,23 @@ get_node_type(ntfs_inode* ni, int* _type)
{
ntfs_attr* na;
// get the node type
if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) {
// Directory
*_type = S_IFDIR;
return B_OK;
}
// Regular or Interix (INTX) file.
} else {
// Regular or Interix (INTX) file
*_type = S_IFREG;
if (ni->flags & FILE_ATTR_SYSTEM) {
na = ntfs_attr_open(ni, AT_DATA, NULL,0);
if (!na)
if (!na) {
return ENOENT;
if (!(ni->flags & FILE_ATTR_HIDDEN)) {
if (na->data_size == 0)
*_type = S_IFIFO;
}
if (na->data_size <= sizeof(INTX_FILE_TYPES) + sizeof(ntfschar) * MAX_PATH
&& na->data_size > sizeof(INTX_FILE_TYPES)) {
// Check whether it's Interix symbolic link
if (na->data_size <= sizeof(INTX_FILE_TYPES) +
sizeof(ntfschar) * PATH_MAX &&
na->data_size > sizeof(INTX_FILE_TYPES)) {
INTX_FILE *intx_file;
intx_file = ntfs_malloc(na->data_size);
@ -80,17 +77,19 @@ get_node_type(ntfs_inode* ni, int* _type)
ntfs_attr_close(na);
return EINVAL;
}
if (ntfs_attr_pread(na, 0, na->data_size, intx_file) != na->data_size) {
if (ntfs_attr_pread(na, 0, na->data_size,
intx_file) != na->data_size) {
free(intx_file);
ntfs_attr_close(na);
return EINVAL;
}
if (intx_file->magic == INTX_SYMBOLIC_LINK)
*_type = S_IFLNK;
*_type = FS_SLNK_MODE;
free(intx_file);
}
ntfs_attr_close(na);
}
}
return B_OK;
}
@ -591,42 +590,35 @@ fs_rstat(fs_volume *_vol, fs_vnode *_node, struct stat *stbuf)
result = ENOENT;
goto exit;
}
stbuf->st_dev = ns->id;
stbuf->st_ino = MREF(ni->mft_no);
if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) {
// Directory
stbuf->st_mode = FS_DIR_MODE;
na = ntfs_attr_open(ni, AT_INDEX_ALLOCATION, NTFS_INDEX_I30, 4);
if (na) {
stbuf->st_size = na->data_size;
stbuf->st_blocks = na->allocated_size >> 9;
ntfs_attr_close(na);
} else {
stbuf->st_size = 0;
}
stbuf->st_nlink = 1; // Needed for correct find work.
stbuf->st_nlink = 1;
} else {
// Regular or Interix (INTX) file.
// Regular or Interix (INTX) file
stbuf->st_mode = FS_FILE_MODE;
stbuf->st_size = ni->data_size;
stbuf->st_blocks = (ni->allocated_size + 511) >> 9;
stbuf->st_nlink = le16_to_cpu(ni->mrec->link_count);
if (ni->flags & FILE_ATTR_SYSTEM) {
na = ntfs_attr_open(ni, AT_DATA, NULL,0);
if (!na) {
result = ENOENT;
goto exit;
}
stbuf->st_size = na->data_size;
if (!(ni->flags & FILE_ATTR_HIDDEN)) {
if (na->data_size == 0)
stbuf->st_mode = S_IFIFO;
}
if (na->data_size <= sizeof(INTX_FILE_TYPES)
+ sizeof(ntfschar) * MAX_PATH
&& na->data_size >sizeof(INTX_FILE_TYPES)) {
stbuf->st_blocks = na->allocated_size >> 9;
// Check whether it's Interix symbolic link
if (na->data_size <= sizeof(INTX_FILE_TYPES) +
sizeof(ntfschar) * PATH_MAX &&
na->data_size > sizeof(INTX_FILE_TYPES)) {
INTX_FILE *intx_file;
intx_file = ntfs_malloc(na->data_size);
@ -635,8 +627,8 @@ fs_rstat(fs_volume *_vol, fs_vnode *_node, struct stat *stbuf)
ntfs_attr_close(na);
goto exit;
}
if (ntfs_attr_pread(na, 0, na->data_size,intx_file)
!= na->data_size) {
if (ntfs_attr_pread(na, 0, na->data_size,
intx_file) != na->data_size) {
result = EINVAL;
free(intx_file);
ntfs_attr_close(na);
@ -647,6 +639,7 @@ fs_rstat(fs_volume *_vol, fs_vnode *_node, struct stat *stbuf)
free(intx_file);
}
ntfs_attr_close(na);
}
stbuf->st_mode |= 0666;
}
@ -656,6 +649,7 @@ fs_rstat(fs_volume *_vol, fs_vnode *_node, struct stat *stbuf)
stbuf->st_uid = 0;
stbuf->st_gid = 0;
stbuf->st_ino = MREF(ni->mft_no);
stbuf->st_atime = ni->last_access_time;
stbuf->st_ctime = ni->last_mft_change_time;
stbuf->st_mtime = ni->last_data_change_time;
@ -797,10 +791,10 @@ fs_open(fs_volume *_vol, fs_vnode *_node, int omode, void **_cookie)
ntfs_attr *na = NULL;
status_t result = B_NO_ERROR;
LOCK_VOL(ns);
ERRPRINT("fs_open - ENTER\n");
LOCK_VOL(ns);
if (node == NULL) {
result = EINVAL;
goto exit;