source: trunk/third/gnome-vfs/libgnomevfs/gnome-vfs-module-shared.c @ 18126

Revision 18126, 3.5 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18125, which included commits to RCS files with non-trunk default branches.
Line 
1#include <config.h>
2
3#define _BSD_SOURCE /* so S_ISVTX and hence GNOME_VFS_PERM_STICKY will be defined */
4
5#include "gnome-vfs-module-shared.h"
6#include <dirent.h>
7#include <errno.h>
8#include <fcntl.h>
9#include <limits.h>
10#include <sys/stat.h>
11#include <sys/types.h>
12#include <unistd.h>
13
14#include "gnome-vfs-module.h"
15#include "gnome-vfs-ops.h"
16
17const gchar *
18gnome_vfs_mime_type_from_mode (mode_t mode)
19{
20        const gchar *mime_type;
21
22        if (S_ISREG (mode))
23                mime_type = NULL;
24        else if (S_ISDIR (mode))
25                mime_type = "x-directory/normal";
26        else if (S_ISCHR (mode))
27                mime_type = "x-special/device-char";
28        else if (S_ISBLK (mode))
29                mime_type = "x-special/device-block";
30        else if (S_ISFIFO (mode))
31                mime_type = "x-special/fifo";
32        else if (S_ISLNK (mode))
33                mime_type = "x-special/symlink";
34        else if (S_ISSOCK (mode))
35                mime_type = "x-special/socket";
36        else
37                mime_type = NULL;
38
39        return mime_type;
40}
41
42const char *
43gnome_vfs_get_special_mime_type (GnomeVFSURI *uri)
44{
45        GnomeVFSResult error;
46        GnomeVFSFileInfo info;
47
48        /* Get file info and examine the type field to see if file is
49         * one of the special kinds.
50         */
51        error = gnome_vfs_get_file_info_uri (uri, &info, GNOME_VFS_FILE_INFO_DEFAULT);
52        if (error != GNOME_VFS_OK) {
53                return NULL;
54        }
55
56        switch (info.type) {
57        case GNOME_VFS_FILE_TYPE_DIRECTORY:
58                return "x-directory/normal";
59        case GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE:
60                return "x-special/device-char";
61        case GNOME_VFS_FILE_TYPE_BLOCK_DEVICE:
62                return "x-special/device-block";
63        case GNOME_VFS_FILE_TYPE_FIFO:
64                return "x-special/fifo";
65        case GNOME_VFS_FILE_TYPE_SOCKET:
66                return "x-special/socket";
67        default:
68                break;
69        }
70
71        return NULL;   
72}
73
74void
75gnome_vfs_stat_to_file_info (GnomeVFSFileInfo *file_info,
76                             const struct stat *statptr)
77{
78        if (S_ISDIR (statptr->st_mode))
79                file_info->type = GNOME_VFS_FILE_TYPE_DIRECTORY;
80        else if (S_ISCHR (statptr->st_mode))
81                file_info->type = GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE;
82        else if (S_ISBLK (statptr->st_mode))
83                file_info->type = GNOME_VFS_FILE_TYPE_BLOCK_DEVICE;
84        else if (S_ISFIFO (statptr->st_mode))
85                file_info->type = GNOME_VFS_FILE_TYPE_FIFO;
86        else if (S_ISSOCK (statptr->st_mode))
87                file_info->type = GNOME_VFS_FILE_TYPE_SOCKET;
88        else if (S_ISREG (statptr->st_mode))
89                file_info->type = GNOME_VFS_FILE_TYPE_REGULAR;
90        else if (S_ISLNK (statptr->st_mode))
91                file_info->type = GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK;
92        else
93                file_info->type = GNOME_VFS_FILE_TYPE_UNKNOWN;
94
95        file_info->permissions
96                = statptr->st_mode & (GNOME_VFS_PERM_USER_ALL
97                                      | GNOME_VFS_PERM_GROUP_ALL
98                                      | GNOME_VFS_PERM_OTHER_ALL
99                                      | GNOME_VFS_PERM_SUID
100                                      | GNOME_VFS_PERM_SGID
101                                      | GNOME_VFS_PERM_STICKY);
102
103        file_info->device = statptr->st_dev;
104        file_info->inode = statptr->st_ino;
105
106        file_info->link_count = statptr->st_nlink;
107
108        file_info->uid = statptr->st_uid;
109        file_info->gid = statptr->st_gid;
110
111        file_info->size = statptr->st_size;
112        file_info->block_count = statptr->st_blocks;
113        file_info->io_block_size = statptr->st_blksize;
114
115        file_info->atime = statptr->st_atime;
116        file_info->ctime = statptr->st_ctime;
117        file_info->mtime = statptr->st_mtime;
118
119        file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_TYPE |
120          GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS | GNOME_VFS_FILE_INFO_FIELDS_FLAGS |
121          GNOME_VFS_FILE_INFO_FIELDS_DEVICE | GNOME_VFS_FILE_INFO_FIELDS_INODE |
122          GNOME_VFS_FILE_INFO_FIELDS_LINK_COUNT | GNOME_VFS_FILE_INFO_FIELDS_SIZE |
123          GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT | GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE |
124          GNOME_VFS_FILE_INFO_FIELDS_ATIME | GNOME_VFS_FILE_INFO_FIELDS_MTIME |
125          GNOME_VFS_FILE_INFO_FIELDS_CTIME;
126}
127
128
Note: See TracBrowser for help on using the repository browser.