sbuild  1.7.1
Public Types | Public Member Functions | Private Attributes | List of all members
sbuild::stat Class Reference

Get file status. More...

#include <util.h>

+ Collaboration diagram for sbuild::stat:

Public Types

enum  error_code { FILE, FD }
 Error codes. More...
 
enum  mode_bits {
  FILE_TYPE_MASK = S_IFMT, FILE_TYPE_SOCKET = S_IFSOCK, FILE_TYPE_LINK = S_IFLNK, FILE_TYPE_REGULAR = S_IFREG,
  FILE_TYPE_BLOCK = S_IFBLK, FILE_TYPE_DIRECTORY = S_IFDIR, FILE_TYPE_CHARACTER = S_IFCHR, FILE_TYPE_FIFO = S_IFIFO,
  PERM_SETUID = S_ISUID, PERM_SETGIT = S_ISGID, PERM_STICKY = S_ISVTX, PERM_USER_MASK = S_IRWXU,
  PERM_USER_READ = S_IRUSR, PERM_USER_WRITE = S_IWUSR, PERM_USER_EXECUTE = S_IXUSR, PERM_GROUP_MASK = S_IRWXG,
  PERM_GROUP_READ = S_IRGRP, PERM_GROUP_WRITE = S_IWGRP, PERM_GROUP_EXECUTE = S_IXGRP, PERM_OTHER_MASK = S_IRWXO,
  PERM_OTHER_READ = S_IROTH, PERM_OTHER_WRITE = S_IWOTH, PERM_OTHER_EXECUTE = S_IXOTH
}
 Mode bits. More...
 
typedef custom_error< error_codeerror
 Exception type.
 

Public Member Functions

 stat (const char *file, bool link=false)
 The constructor. More...
 
 stat (const std::string &file, bool link=false)
 The constructor. More...
 
 stat (const std::string &file, int fd)
 The constructor. More...
 
 stat (int fd)
 The constructor. More...
 
virtual ~stat ()
 The destructor.
 
void check () const
 Check if the file status was obtained. More...
 
struct::stat & get_detail ()
 Get the struct stat used internally. More...
 
dev_t device () const
 Get the device the file resides on. More...
 
ino_t inode () const
 Get the inode of the file. More...
 
mode_t mode () const
 Get the mode of the file. More...
 
nlink_t links () const
 Get the number of hard links to the file. More...
 
uid_t uid () const
 Get the user id owning the file. More...
 
gid_t gid () const
 Get the group id owning the file. More...
 
off_t size () const
 Get the file size. More...
 
blksize_t blocksize () const
 Get the file block size. More...
 
blkcnt_t blocks () const
 Get the file block count. More...
 
time_t atime () const
 Get the file access time. More...
 
time_t mtime () const
 Get the file modification time. More...
 
time_t ctime () const
 Get the file creation time. More...
 
bool is_regular () const
 Is the file a regular file? More...
 
bool is_directory () const
 Is the file a directory? More...
 
bool is_character () const
 Is the file a character device? More...
 
bool is_block () const
 Is the file a block device? More...
 
bool is_fifo () const
 Is the file a named pipe (FIFO)? More...
 
bool is_link () const
 Is the file a symbolic link? More...
 
bool is_socket () const
 Is the file a socket? More...
 
bool check_mode (mode_bits mask) const
 Check if particular mode bits are set. More...
 

Private Attributes

std::string file
 The filename being checked (if specified).
 
int fd
 The file descriptor being checked (if specified).
 
int errorno
 The error number set after stat(2) error.
 
struct::stat status
 The stat(2) results.
 

Detailed Description

Get file status.

stat(2) wrapper.

Member Enumeration Documentation

Error codes.

Enumerator
FILE 

Failed to stat file.

FD 

Failed to stat file descriptor.

Mode bits.

Enumerator
FILE_TYPE_MASK 

Mask for file type bit fields.

FILE_TYPE_SOCKET 

Socket file type.

FILE_TYPE_LINK 

Symbolic link file type.

FILE_TYPE_REGULAR 

Regular file type.

FILE_TYPE_BLOCK 

Block device file type.

FILE_TYPE_DIRECTORY 

Directory file type.

FILE_TYPE_CHARACTER 

Character device file type.

FILE_TYPE_FIFO 

Named pipe (FIFO) file type.

PERM_SETUID 

Set user ID permission.

PERM_SETGIT 

Set group ID permission.

PERM_STICKY 

Sticky permission.

PERM_USER_MASK 

Mask for user permissions.

PERM_USER_READ 

User read permission.

PERM_USER_WRITE 

User write permission.

PERM_USER_EXECUTE 

User execute permission.

PERM_GROUP_MASK 

Mask for group permissions.

PERM_GROUP_READ 

Group read permission.

PERM_GROUP_WRITE 

Group write permission.

PERM_GROUP_EXECUTE 

Group execute permission.

PERM_OTHER_MASK 

Mask for other permissions.

PERM_OTHER_READ 

Other read permission.

PERM_OTHER_WRITE 

Other write permission.

PERM_OTHER_EXECUTE 

Other execute permission.

Constructor & Destructor Documentation

sbuild::stat::stat ( const char *  file,
bool  link = false 
)

The constructor.

Parameters
filethe filename to use.
linkuse lstat rather than stat (i.e. don't follow symlinks).

References errorno, and status.

Referenced by stat().

+ Here is the caller graph for this function:

sbuild::stat::stat ( const std::string &  file,
bool  link = false 
)

The constructor.

Parameters
filethe filename to use.
linkuse lstat rather than stat (i.e. don't follow symlinks).

References errorno, stat(), and status.

sbuild::stat::stat ( const std::string &  file,
int  fd 
)

The constructor.

Parameters
filethe filename to use (only used for error reporting).
fdthe file descriptor to use.

References errorno, and status.

sbuild::stat::stat ( int  fd)

The constructor.

Parameters
fdthe file descriptor to use.

References errorno, and status.

Member Function Documentation

time_t sbuild::stat::atime ( ) const
inline

Get the file access time.

Returns
the access time.

References check(), and status.

blkcnt_t sbuild::stat::blocks ( ) const
inline

Get the file block count.

Returns
the block count.

References check(), and status.

blksize_t sbuild::stat::blocksize ( ) const
inline

Get the file block size.

Returns
the block size.

References check(), and status.

void sbuild::stat::check ( ) const
inline

Check if the file status was obtained.

An error will be thrown if stat(2) failed to get the file status.

References errorno, FD, fd, FILE, and file.

Referenced by atime(), blocks(), blocksize(), check_mode(), ctime(), device(), sbuild::session::get_shell(), gid(), inode(), links(), mode(), mtime(), size(), and uid().

+ Here is the caller graph for this function:

bool sbuild::stat::check_mode ( mode_bits  mask) const
inline

Check if particular mode bits are set.

Parameters
maskA bitmask containing the bits to check are set.
Returns
true if all the bits in mask are set, otherwise false.

References check(), and status.

Referenced by is_block(), is_character(), is_directory(), is_fifo(), is_link(), is_regular(), is_socket(), and sbuild::chroot::config::load_data().

+ Here is the caller graph for this function:

time_t sbuild::stat::ctime ( ) const
inline

Get the file creation time.

Returns
the creation time.

References check(), and status.

dev_t sbuild::stat::device ( ) const
inline

Get the device the file resides on.

Returns
the device.

References check(), and status.

struct ::stat& sbuild::stat::get_detail ( )
inline

Get the struct stat used internally.

This is returned by stat(2).

Returns
the stat struct.

References status.

gid_t sbuild::stat::gid ( ) const
inline

Get the group id owning the file.

Returns
the uid.

References check(), and status.

ino_t sbuild::stat::inode ( ) const
inline

Get the inode of the file.

Returns
the inode.

References check(), and status.

bool sbuild::stat::is_block ( ) const
inline

Is the file a block device?

Returns
true if a block device, otherwise false.

References check_mode(), FILE_TYPE_BLOCK, and FILE_TYPE_MASK.

bool sbuild::stat::is_character ( ) const
inline

Is the file a character device?

Returns
true if a character device, otherwise false.

References check_mode(), FILE_TYPE_CHARACTER, and FILE_TYPE_MASK.

bool sbuild::stat::is_directory ( ) const
inline

Is the file a directory?

Returns
true if a directory, otherwise false.

References check_mode(), FILE_TYPE_DIRECTORY, and FILE_TYPE_MASK.

bool sbuild::stat::is_fifo ( ) const
inline

Is the file a named pipe (FIFO)?

Returns
true if a named pipe, otherwise false.

References check_mode(), FILE_TYPE_FIFO, and FILE_TYPE_MASK.

bool sbuild::stat::is_link ( ) const
inline

Is the file a symbolic link?

Returns
true if a symbolic link, otherwise false.

References check_mode(), FILE_TYPE_LINK, and FILE_TYPE_MASK.

bool sbuild::stat::is_regular ( ) const
inline

Is the file a regular file?

Returns
true if regular, otherwise false.

References check_mode(), FILE_TYPE_MASK, and FILE_TYPE_REGULAR.

Referenced by sbuild::chroot::config::add_config_directory(), sbuild::find_program_in_path(), and sbuild::chroot::config::load_data().

+ Here is the caller graph for this function:

bool sbuild::stat::is_socket ( ) const
inline

Is the file a socket?

Returns
true if a socket, otherwise false.

References check_mode(), FILE_TYPE_MASK, and FILE_TYPE_SOCKET.

nlink_t sbuild::stat::links ( ) const
inline

Get the number of hard links to the file.

Returns
the hard link count.

References check(), and status.

mode_t sbuild::stat::mode ( ) const
inline

Get the mode of the file.

Returns
the mode.

References check(), and status.

time_t sbuild::stat::mtime ( ) const
inline

Get the file modification time.

Returns
the modification time.

References check(), and status.

off_t sbuild::stat::size ( ) const
inline

Get the file size.

Returns
the file size.

References check(), and status.

uid_t sbuild::stat::uid ( ) const
inline

Get the user id owning the file.

Returns
the uid.

References check(), and status.

Referenced by sbuild::chroot::config::load_data().

+ Here is the caller graph for this function:


The documentation for this class was generated from the following files: