3 #include "gnome-vfs-module-shared.h"
12 #include "gnome-vfs-module.h"
13 #include "gnome-vfs-ops.h"
16 * gnome_vfs_mime_type_from_mode:
19 * Returns a MIME type based on the mode passed. It only works when mode
20 * references a special file (directory, device, fifo, socket or symlink)
22 * Returns: a string containing the MIME type, if @mode is a normal file
27 gnome_vfs_mime_type_from_mode (mode_t mode)
29 const gchar *mime_type;
33 else if (S_ISDIR (mode))
34 mime_type = "x-directory/normal";
35 else if (S_ISCHR (mode))
36 mime_type = "x-special/device-char";
37 else if (S_ISBLK (mode))
38 mime_type = "x-special/device-block";
39 else if (S_ISFIFO (mode))
40 mime_type = "x-special/fifo";
41 else if (S_ISLNK (mode))
42 mime_type = "x-special/symlink";
43 else if (S_ISSOCK (mode))
44 mime_type = "x-special/socket";
52 * gnome_vfs_get_special_mime_type:
55 * Gets the MIME type for @uri, this function only returns the type
56 * when the URI points to a file that can't be sniffed (sockets,
57 * directories, devices, and fifos).
59 * Returns: a string containing the mime type, NULL if the @uri doesn't
60 * present an special file.
64 gnome_vfs_get_special_mime_type (GnomeVFSURI *uri)
67 GnomeVFSFileInfo info;
69 /* Get file info and examine the type field to see if file is
70 * one of the special kinds.
72 error = gnome_vfs_get_file_info_uri (uri, &info, GNOME_VFS_FILE_INFO_DEFAULT);
73 if (error != GNOME_VFS_OK) {
78 case GNOME_VFS_FILE_TYPE_DIRECTORY:
79 return "x-directory/normal";
80 case GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE:
81 return "x-special/device-char";
82 case GNOME_VFS_FILE_TYPE_BLOCK_DEVICE:
83 return "x-special/device-block";
84 case GNOME_VFS_FILE_TYPE_FIFO:
85 return "x-special/fifo";
86 case GNOME_VFS_FILE_TYPE_SOCKET:
87 return "x-special/socket";
96 gnome_vfs_stat_to_file_info (GnomeVFSFileInfo *file_info,
97 const struct stat *statptr)
99 if (S_ISDIR (statptr->st_mode))
100 file_info->type = GNOME_VFS_FILE_TYPE_DIRECTORY;
101 else if (S_ISCHR (statptr->st_mode))
102 file_info->type = GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE;
103 else if (S_ISBLK (statptr->st_mode))
104 file_info->type = GNOME_VFS_FILE_TYPE_BLOCK_DEVICE;
105 else if (S_ISFIFO (statptr->st_mode))
106 file_info->type = GNOME_VFS_FILE_TYPE_FIFO;
107 else if (S_ISSOCK (statptr->st_mode))
108 file_info->type = GNOME_VFS_FILE_TYPE_SOCKET;
109 else if (S_ISREG (statptr->st_mode))
110 file_info->type = GNOME_VFS_FILE_TYPE_REGULAR;
111 else if (S_ISLNK (statptr->st_mode))
112 file_info->type = GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK;
114 file_info->type = GNOME_VFS_FILE_TYPE_UNKNOWN;
116 file_info->permissions
117 = statptr->st_mode & (GNOME_VFS_PERM_USER_ALL
118 | GNOME_VFS_PERM_GROUP_ALL
119 | GNOME_VFS_PERM_OTHER_ALL
120 | GNOME_VFS_PERM_SUID
121 | GNOME_VFS_PERM_SGID
122 | GNOME_VFS_PERM_STICKY);
124 file_info->device = statptr->st_dev;
125 file_info->inode = statptr->st_ino;
127 file_info->link_count = statptr->st_nlink;
129 file_info->uid = statptr->st_uid;
130 file_info->gid = statptr->st_gid;
132 file_info->size = statptr->st_size;
133 file_info->block_count = statptr->st_blocks;
134 file_info->io_block_size = statptr->st_blksize;
136 file_info->atime = statptr->st_atime;
137 file_info->ctime = statptr->st_ctime;
138 file_info->mtime = statptr->st_mtime;
140 file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_TYPE |
141 GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS | GNOME_VFS_FILE_INFO_FIELDS_FLAGS |
142 GNOME_VFS_FILE_INFO_FIELDS_DEVICE | GNOME_VFS_FILE_INFO_FIELDS_INODE |
143 GNOME_VFS_FILE_INFO_FIELDS_LINK_COUNT | GNOME_VFS_FILE_INFO_FIELDS_SIZE |
144 GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT | GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE |
145 GNOME_VFS_FILE_INFO_FIELDS_ATIME | GNOME_VFS_FILE_INFO_FIELDS_MTIME |
146 GNOME_VFS_FILE_INFO_FIELDS_CTIME;