Platforms to show: All Mac Windows Linux Cross-Platform

Back to DarwinChmodMBS class.

DarwinChmodMBS.chflags(path as string, flags as Integer) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Files MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ✅ Yes All
The file whose name is given by path has its flags changed to flags.

The flags specified are formed by or'ing the following values

UF_NODUMP0x00000001Do not dump the file.
UF_IMMUTABLE0x00000002The file may not be changed.
UF_APPEND0x00000004The file may only be appended to.
UF_OPAQUE0x00000008Directory is opaque wrt. union

The ''UF_IMMUTABLE'' and ''UF_APPEND'' flags may be set or unset by either the owner of a file or the super-user.

The ''SF_IMMUTABLE'' and ''SF_APPEND'' flags may only be set or unset by the super-user. They may be set at any time, but normally may only be unset when the system is in single-user mode.

You can type "man 2 chflags" on the Mac OS X terminal for more details.

Upon successful completion, a value of 0 is returned. Otherwise, -1 is returned.
Returns -2 on bad parameter or if function is not available.

Chflags() will fail it:

ENOTDIRA component of the path prefix is not a directory.
ENAMETOOLONGA component of a pathname exceeded {NAME_MAX} characters, or an entire path name exceeded {PATH_MAX} characters.
ENOENTThe named file does not exist.
EACCESSearch permission is denied for a component of the path prefix.
ELOOPToo many symbolic links were encountered in translating the pathname.
EPERMThe effective user ID does not match the owner of the file and the effective user ID is not the super-user.
EROFSThe named file resides on a read-only file system.
EFAULTPath points outside the process's allocated address space.
EIOAn I/O error occurred while reading from or writing to the file system.

DarwinChmodMBS.chmod(path as string, mode as Integer) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Files MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the file permission bits of the file specified by the pathname path to mode.
Example
dim f as FolderItem
dim g as FolderItem

f=SpecialFolder.Desktop.Child("test1")
g=SpecialFolder.Desktop.Child("test2")

dim d as DarwinChmodMBS

d=new DarwinChmodMBS

if d.stat(f.NativePath)=0 then // read mode
if d.chmod(g.NativePath,d.mode)=0 then // set mode
// worked
end if
end if

Chmod() verifies that the process owner (user) either owns the file specified by path (or fd), or is the super- user. A mode is created from or'd permission bit masks like this:

IRWXU&o0000700RWX mask for owner
IRUSR&o0000400R for owner
IWUSR&o0000200W for owner
IXUSR&o0000100X for owner
IRWXG&o0000070RWX mask for group
IRGRP&o0000040R for group
IWGRP&o0000020W for group
IXGRP&o0000010X for group
IRWXO&o0000007RWX mask for other
IROTH&o0000004R for other
IWOTH&o0000002W for other
IXOTH&o0000001X for other
ISUID&o0004000set user id on execution
ISGID&o0002000set group id on execution
ISVTX&o0001000save swapped text even after use

The ISVTX (the sticky bit) indicates to the system which executable files are shareable (the default) and the system maintains the program text of the files in the swap area. The sticky bit may only be set by the super user on shareable executable files.

If mode ISVTX (the 'sticky bit') is set on a directory, an unprivileged user may not delete or rename files of other users in that directory. The sticky bit may be set by any user on a directory which the user owns or has appropriate permissions. For more details of the properties of the sticky bit, see sticky(8).

Writing or changing the owner of a file turns off the set-user-id and set-group-id bits unless the user is the super-user. This makes the system somewhat more secure by protecting set-user-id (set-group-id) files from remaining set-user-id (set-group-id) if they are modified, at the expense of a degree of compatibility.

You can type "man 2 chmod" on the Mac OS X terminal for more details.

Upon successful completion, a value of 0 is returned. Otherwise, -1 is returned.
Returns -2 on bad parameter or if function is not available.

Chmod() will fail and the file mode will be unchanged if:

ENOTDIRA component of the path prefix is not a directory.
ENAMETOOLONGA component of a pathname exceeded {NAME_MAX} characters, or an entire path name exceeded {PATH_MAX} characters.
ENOENTThe named file does not exist.
EACCESSearch permission is denied for a component of the path prefix.
ELOOPToo many symbolic links were encountered in translating the pathname.
EPERMThe effective user ID does not match the owner of the file and the effective user ID is not the super-user.
EROFSThe named file resides on a read-only file system.
EFAULTPath points outside the process's allocated address space.
EIOAn I/O error occurred while reading from or writing to the file system.

DarwinChmodMBS.chown(path as string, uid as Integer, gid as Integer) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Files MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ✅ Yes All
The owner ID and group ID of the file (or link) named by path is changed as specified by the arguments owner (uid) and group (gid).

The owner of a file may change the group to a group of which he or she is a member, but the change owner capability is restricted to the superuser.

Chown() clears the set-user-id and set-group-id bits on the file to prevent accidental or mischievous creation of set-user-id and set-group-id programs.

You can type "man 2 chmod" on the Mac OS X terminal for more details.

Upon successful completion, a value of 0 is returned. Otherwise, -1 is returned.
Returns -2 on bad parameter or if function is not available.

Chown() will fail and the file or link will be unchanged if:

ENOTDIRA component of the path prefix is not a directory.
ENAMETOOLONGA component of a pathname exceeded {NAME_MAX} characters, or an entire path name exceeded {PATH_MAX} characters.
ENOENTThe named file does not exist.
EACCESSearch permission is denied for a component of the path prefix.
ELOOPToo many symbolic links were encountered in translating the pathname.
EPERMThe effective user ID is not the super-user.
EROFSThe named file resides on a read-only file system.
EFAULTPath points outside the process's allocated addressspace.
EIOAn I/O error occurred while reading from or writing to the file system.

DarwinChmodMBS.error as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Files MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the error code from the last operation.

This function asks the operation system. It's not a property like in other classes.

Error codes:

EPERM1Operation not permitted
ENOENT2No such file or directory
ESRCH3No such process
EINTR4Interrupted system call
EIO5Input/output error
ENXIO6Device not configured
E2BIG7Argument list too long
ENOEXEC8Exec format error
EBADF9Bad file descriptor
ECHILD10No child processes
EDEADLK11Resource deadlock avoided (11 was EAGAIN)
ENOMEM12Cannot allocate memory
EACCES13Permission denied
EFAULT14Bad address
ENOTBLK15Block device required
EBUSY16Device busy
EEXIST17File exists
EXDEV18Cross-device link
ENODEV19Operation not supported by device
ENOTDIR20Not a directory
EISDIR21Is a directory
EINVAL22Invalid argument
ENFILE23Too many open files in system
EMFILE24Too many open files
ENOTTY25Inappropriate ioctl for device
ETXTBSY26Text file busy
EFBIG27File too large
ENOSPC28No space left on device
ESPIPE29Illegal seek
EROFS30Read-only file system
EMLINK31Too many links
EPIPE32Broken pipe
math software
EDOM33Numerical argument out of domain
ERANGE34Result too large
non-blocking and interrupt i/o
EAGAIN35Resource temporarily unavailable
EWOULDBLOCKEAGAINOperation would block
EINPROGRESS36Operation now in progress
EALREADY37Operation already in progress
ipc/network software -- argument errors
ENOTSOCK38Socket operation on non-socket
EDESTADDRREQ39Destination address required
EMSGSIZE40Message too long
EPROTOTYPE41Protocol wrong type for socket
ENOPROTOOPT42Protocol not available
EPROTONOSUPPORT43Protocol not supported
ESOCKTNOSUPPORT44Socket type not supported
ENOTSUP45Operation not supported
EOPNOTSUPPENOTSUPOperation not supported
EPFNOSUPPORT46Protocol family not supported
EAFNOSUPPORT47Address family not supported by protocol family
EADDRINUSE48Address already in use
EADDRNOTAVAIL49Can't assign requested address
ipc/network software -- operational errors
ENETDOWN50Network is down
ENETUNREACH51Network is unreachable
ENETRESET52Network dropped connection on reset
ECONNABORTED53Software caused connection abort
ECONNRESET54Connection reset by peer
ENOBUFS55No buffer space available
EISCONN56Socket is already connected
ENOTCONN57Socket is not connected
ESHUTDOWN58Can't send after socket shutdown
ETOOMANYREFS59Too many references: can't splice
ETIMEDOUT60Operation timed out
ECONNREFUSED61Connection refused
ELOOP62Too many levels of symbolic links
ENAMETOOLONG63File name too long
should be rearranged
EHOSTDOWN64Host is down
EHOSTUNREACH65No route to host
ENOTEMPTY66Directory not empty
quotas & mush
EPROCLIM67Too many processes
EUSERS68Too many users
EDQUOT69Disc quota exceeded
Network File System
ESTALE70Stale NFS file handle
EREMOTE71Too many levels of remote in path
EBADRPC72RPC struct is bad
ERPCMISMATCH73RPC version wrong
EPROGUNAVAIL74RPC prog. not avail
EPROGMISMATCH75Program version wrong
EPROCUNAVAIL76Bad procedure for program
ENOLCK77No locks available
ENOSYS78Function not implemented
EFTYPE79Inappropriate file type or format
EAUTH80Authentication error
ENEEDAUTH81Need authenticator
Intelligent device errors
EPWROFF82Device power is off
EDEVERR83Device error, e.g. paper out
EOVERFLOW84Value too large to be stored in data type
Program loading errors
EBADEXEC85Bad executable
EBADARCH86Bad CPU type in executable
ESHLIBVERS87Shared library version mismatch
EBADMACHO88Malformed Macho file
ECANCELED89Operation canceled
ELAST89Must be equal largest errno

Returns -2 if function is not available.

DarwinChmodMBS.lstat(path as string) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Files MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ✅ Yes All
The stat function obtains information about the file pointed to by path.
Example
// we use truechild to not resolve the symbol link
dim f as FolderItem = SpecialFolder.Desktop.trueChild("test.rtf")

dim c as new DarwinChmodMBS
if c.lstat(f.NativePath) = 0 then
// ok

Break // see values in debugger
else
MsgBox "failed"
end if

See stat for details.

DarwinChmodMBS.stat(path as string) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Files MBS MacCF Plugin 3.1 ✅ Yes ❌ No ❌ No ✅ Yes All
The stat function obtains information about the file pointed to by path.
Example
dim d as DarwinChmodMBS
dim f as FolderItem

f=SpecialFolder.Desktop.Child("test")
d=new DarwinChmodMBS

if d.stat(f.NativePath)=0 then
MsgBox hex(d.mode)
end if

Read, write or execute permission of the named file is not required, but all directories listed in the path name leading to the file must be searchable.

Lstat() is like stat() except in the case where the named file is a symbolic link, in which case lstat() returns information about the link, while stat() returns information about the file the link references. Unlike other filesystem objects, symbolic links do not have an owner, group, access mode, times, etc. Instead, these attributes are taken from the directory that contains the link. The only attributes returned from an lstat() that refer to the symbolic link itself are the file type (S_IFLNK), size, blocks, and link count (always 1).

Information about the file is stored directly into the fields of the class if the function is successfull.

You can type "man 2 stat" on the Mac OS X terminal for more details.

Upon successful completion, a value of 0 is returned. Otherwise, -1 is returned.
Returns -2 on bad parameter or if function is not available.

Stat() and lstat() will fail if:

ENOTDIRA component of the path prefix is not a directory.
ENAMETOOLONGA component of a pathname exceeded {NAME_MAX} characters, or an entire path name exceeded {PATH_MAX} characters.
ENOENTThe named file does not exist.
EACCESSearch permission is denied for a component of the path prefix.
ELOOPToo many symbolic links were encountered in translating the pathname.
EFAULTSb or name points to an invalid address.
EIOAn I/O error occurred while reading from or writing to the file system.

The items on this page are in the following plugins: MBS MacCF Plugin.


The biggest plugin in space...