1 | #ifdef HAVE_CONFIG_H |
---|
2 | #include <config.h> |
---|
3 | #endif |
---|
4 | |
---|
5 | #define _LARGEFILE64_SOURCE |
---|
6 | |
---|
7 | #include <dirent.h> |
---|
8 | #include <errno.h> |
---|
9 | #include <fcntl.h> |
---|
10 | #include <limits.h> |
---|
11 | #include <sys/stat.h> |
---|
12 | #include <sys/types.h> |
---|
13 | #include <unistd.h> |
---|
14 | |
---|
15 | #include "gnome-vfs-module.h" |
---|
16 | #include "gnome-vfs-module-shared.h" |
---|
17 | |
---|
18 | const gchar * |
---|
19 | gnome_vfs_mime_type_from_mode (mode_t mode) |
---|
20 | { |
---|
21 | const gchar *mime_type; |
---|
22 | |
---|
23 | if (S_ISREG (mode)) |
---|
24 | mime_type = NULL; |
---|
25 | else if (S_ISDIR (mode)) |
---|
26 | mime_type = "x-directory/normal"; |
---|
27 | else if (S_ISCHR (mode)) |
---|
28 | mime_type = "x-special/device-char"; |
---|
29 | else if (S_ISBLK (mode)) |
---|
30 | mime_type = "x-special/device-block"; |
---|
31 | else if (S_ISFIFO (mode)) |
---|
32 | mime_type = "x-special/fifo"; |
---|
33 | else if (S_ISLNK (mode)) |
---|
34 | mime_type = "x-special/symlink"; |
---|
35 | else if (S_ISSOCK (mode)) |
---|
36 | mime_type = "x-special/socket"; |
---|
37 | else |
---|
38 | mime_type = NULL; |
---|
39 | |
---|
40 | return mime_type; |
---|
41 | } |
---|
42 | |
---|
43 | const char * |
---|
44 | gnome_vfs_get_special_mime_type (GnomeVFSURI *uri) |
---|
45 | { |
---|
46 | GnomeVFSResult error; |
---|
47 | GnomeVFSFileInfo info; |
---|
48 | |
---|
49 | /* Get file info and examine the type field to see if file is |
---|
50 | * one of the special kinds. |
---|
51 | */ |
---|
52 | error = gnome_vfs_get_file_info_uri (uri, &info, GNOME_VFS_FILE_INFO_DEFAULT); |
---|
53 | if (error != GNOME_VFS_OK) { |
---|
54 | return NULL; |
---|
55 | } |
---|
56 | |
---|
57 | switch (info.type) { |
---|
58 | case GNOME_VFS_FILE_TYPE_DIRECTORY: |
---|
59 | return "x-directory/normal"; |
---|
60 | case GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE: |
---|
61 | return "x-special/device-char"; |
---|
62 | case GNOME_VFS_FILE_TYPE_BLOCK_DEVICE: |
---|
63 | return "x-special/device-block"; |
---|
64 | case GNOME_VFS_FILE_TYPE_FIFO: |
---|
65 | return "x-special/fifo"; |
---|
66 | case GNOME_VFS_FILE_TYPE_SOCKET: |
---|
67 | return "x-special/socket"; |
---|
68 | default: |
---|
69 | break; |
---|
70 | } |
---|
71 | |
---|
72 | return NULL; |
---|
73 | } |
---|
74 | |
---|
75 | void |
---|
76 | gnome_vfs_stat_to_file_info (GnomeVFSFileInfo *file_info, |
---|
77 | const struct stat *statptr) |
---|
78 | { |
---|
79 | if (S_ISDIR (statptr->st_mode)) |
---|
80 | file_info->type = GNOME_VFS_FILE_TYPE_DIRECTORY; |
---|
81 | else if (S_ISCHR (statptr->st_mode)) |
---|
82 | file_info->type = GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE; |
---|
83 | else if (S_ISBLK (statptr->st_mode)) |
---|
84 | file_info->type = GNOME_VFS_FILE_TYPE_BLOCK_DEVICE; |
---|
85 | else if (S_ISFIFO (statptr->st_mode)) |
---|
86 | file_info->type = GNOME_VFS_FILE_TYPE_FIFO; |
---|
87 | else if (S_ISSOCK (statptr->st_mode)) |
---|
88 | file_info->type = GNOME_VFS_FILE_TYPE_SOCKET; |
---|
89 | else if (S_ISREG (statptr->st_mode)) |
---|
90 | file_info->type = GNOME_VFS_FILE_TYPE_REGULAR; |
---|
91 | else if (S_ISLNK (statptr->st_mode)) |
---|
92 | file_info->type = GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK; |
---|
93 | else |
---|
94 | file_info->type = GNOME_VFS_FILE_TYPE_UNKNOWN; |
---|
95 | |
---|
96 | file_info->permissions |
---|
97 | = statptr->st_mode & (S_IRUSR | S_IWUSR | S_IXUSR |
---|
98 | | S_IRGRP | S_IWGRP | S_IXGRP |
---|
99 | | S_IROTH | S_IWOTH | S_IXOTH |
---|
100 | | S_ISUID | S_ISGID); |
---|
101 | |
---|
102 | #ifdef S_ISVTX |
---|
103 | GNOME_VFS_FILE_INFO_SET_STICKY (file_info, |
---|
104 | (statptr->st_mode & S_ISVTX) ? TRUE |
---|
105 | : FALSE); |
---|
106 | #else |
---|
107 | GNOME_VFS_FILE_INFO_SET_STICKY (file_info, FALSE); |
---|
108 | #endif |
---|
109 | |
---|
110 | file_info->device = statptr->st_dev; |
---|
111 | file_info->inode = statptr->st_ino; |
---|
112 | |
---|
113 | file_info->link_count = statptr->st_nlink; |
---|
114 | |
---|
115 | file_info->uid = statptr->st_uid; |
---|
116 | file_info->gid = statptr->st_gid; |
---|
117 | |
---|
118 | file_info->size = statptr->st_size; |
---|
119 | file_info->block_count = statptr->st_blocks; |
---|
120 | file_info->io_block_size = statptr->st_blksize; |
---|
121 | |
---|
122 | file_info->atime = statptr->st_atime; |
---|
123 | file_info->ctime = statptr->st_ctime; |
---|
124 | file_info->mtime = statptr->st_mtime; |
---|
125 | |
---|
126 | file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_TYPE | |
---|
127 | GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS | GNOME_VFS_FILE_INFO_FIELDS_FLAGS | |
---|
128 | GNOME_VFS_FILE_INFO_FIELDS_DEVICE | GNOME_VFS_FILE_INFO_FIELDS_INODE | |
---|
129 | GNOME_VFS_FILE_INFO_FIELDS_LINK_COUNT | GNOME_VFS_FILE_INFO_FIELDS_SIZE | |
---|
130 | GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT | GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE | |
---|
131 | GNOME_VFS_FILE_INFO_FIELDS_ATIME | GNOME_VFS_FILE_INFO_FIELDS_MTIME | |
---|
132 | GNOME_VFS_FILE_INFO_FIELDS_CTIME; |
---|
133 | } |
---|
134 | |
---|
135 | |
---|