Exemplo n.º 1
0
CAMLprim value setFileInfos (value path, value fInfo) {
#ifdef __APPLE__

  CAMLparam2(path, fInfo);
  int retcode;
  struct attrlist attrList;
  unsigned long options = 0;
  struct {
    u_int32_t length;
    char      finderInfo [32];
  } __attribute__ ((packed))  attrBuf;

  attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  attrList.reserved = 0;
  attrList.commonattr = ATTR_CMN_FNDRINFO;
  attrList.volattr = 0;     /* volume attribute group */
  attrList.dirattr = 0;     /* directory attribute group */
  attrList.fileattr = 0;    /* file attribute group */
  attrList.forkattr = 0;    /* fork attribute group */

  memcpy (attrBuf.finderInfo, String_val (fInfo), 32);

  retcode = setattrlist(String_val (path), &attrList, attrBuf.finderInfo,
                        sizeof attrBuf.finderInfo, options);

  if (retcode == -1 && errno == EACCES) {
    /* Unlike with normal Unix attributes, we cannot set OS X attributes 
       if file is read-only.  Try making it writable temporarily. */
    struct stat st;
    int r = stat(String_val(path), &st);
    if (r == -1) uerror("setattrlist", path);
    r = chmod(String_val(path), st.st_mode | S_IWUSR);
    if (r == -1) uerror("setattrlist", path);
    /* Try again */
    retcode = setattrlist(String_val (path), &attrList, attrBuf.finderInfo,
                          sizeof attrBuf.finderInfo, options);
    /* Whether or not that worked, we should try to set the mode back. */
    chmod(String_val(path), st.st_mode);
  }

  if (retcode == -1) uerror("setattrlist", path);

  CAMLreturn (Val_unit);

#else

  unix_error (ENOSYS, "setattrlist", path);

#endif
}
Exemplo n.º 2
0
int main(int argc, char *argv[]) {
	char *path = NULL;
	struct attrlist alist;
	struct directoryinfo dirinfo;
	struct volumeinfo volinfo;
	struct statfs sfs;

	path = argv[1];

	bzero(&alist, sizeof(alist));
	alist.bitmapcount = 5;
	alist.commonattr = ATTR_CMN_OBJID;

	getattrlist(path, &alist, &dirinfo, sizeof(dirinfo), 0);

	printf("directory id: %lu\n", dirinfo.dirid);

	statfs(path, &sfs);

	printf("mountpoint: %s\n", sfs.f_mntonname);

	alist.commonattr = ATTR_CMN_FNDRINFO;
	alist.volattr = ATTR_VOL_INFO;

	getattrlist(sfs.f_mntonname, &alist, &volinfo, sizeof(volinfo), 0);
	volinfo.finderinfo[2] = dirinfo.dirid;
	setattrlist(sfs.f_mntonname, &alist, volinfo.finderinfo, sizeof(volinfo.finderinfo), 0);

	return EXIT_SUCCESS;
} 
Exemplo n.º 3
0
int do_chmod(const char *path, mode_t mode)
{
	int code;
	if (dry_run) return 0;
	RETURN_ERROR_IF_RO_OR_LO;
#ifdef HAVE_LCHMOD
	code = lchmod(path, mode & CHMOD_BITS);
#else
	if (S_ISLNK(mode)) {
# if defined HAVE_SETATTRLIST
		struct attrlist attrList;
		uint32_t m = mode & CHMOD_BITS; /* manpage is wrong: not mode_t! */

		memset(&attrList, 0, sizeof attrList);
		attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
		attrList.commonattr = ATTR_CMN_ACCESSMASK;
		code = setattrlist(path, &attrList, &m, sizeof m, FSOPT_NOFOLLOW);
# else
		code = 1;
# endif
	} else
		code = chmod(path, mode & CHMOD_BITS); /* DISCOURAGED FUNCTION */
#endif /* !HAVE_LCHMOD */
	if (code != 0 && (preserve_perms || preserve_executability))
		return code;
	return 0;
}
Exemplo n.º 4
0
int osx_attr_setattrlist
(const char *path, struct attrlist * attrList, void * attrBuf,
 size_t attrBufSize, unsigned long options)
{
  int r;
  caml_release_runtime_system();
  r = setattrlist(path, attrList, attrBuf, attrBufSize, options);
  caml_acquire_runtime_system();
  return r;
}
Exemplo n.º 5
0
void DAFileSystemRename( DAFileSystemRef      filesystem,
                         CFURLRef             mountpoint,
                         CFStringRef          name,
                         DAFileSystemCallback callback,
                         void *               callbackContext )
{
    /*
     * Rename the specified volume.  A status of 0 indicates success.
     */

    struct attrlist              attributes     = { 0 };
    __DAFileSystemRenameBuffer * buffer         = NULL;
    char *                       mountpointPath = NULL;
    int                          status         = 0;

    /*
     * Prepare to set the name.
     */

    attributes.bitmapcount = ATTR_BIT_MAP_COUNT;
    attributes.commonattr  = 0;
    attributes.dirattr     = 0;
    attributes.fileattr    = 0;
    attributes.forkattr    = 0;
    attributes.volattr     = ATTR_VOL_INFO | ATTR_VOL_NAME;

    buffer = malloc( sizeof( __DAFileSystemRenameBuffer ) );
    if ( buffer == NULL )  { status = ENOMEM; goto DAFileSystemRenameErr; }

    mountpointPath = ___CFURLCopyFileSystemRepresentation( mountpoint );
    if ( mountpointPath == NULL )  { status = EINVAL; goto DAFileSystemRenameErr; }

    /*
     * Set the name.
     */

    status = CFStringGetCString( name, buffer->name, sizeof( buffer->name ), kCFStringEncodingUTF8 );
    if ( status == FALSE )  { status = EINVAL; goto DAFileSystemRenameErr; }

    buffer->data.attr_dataoffset = sizeof( buffer->data );
    buffer->data.attr_length     = strlen( buffer->name ) + 1;

    status = setattrlist( mountpointPath, &attributes, buffer, sizeof( __DAFileSystemRenameBuffer ), 0 );
    if ( status == -1 )  { status = errno; goto DAFileSystemRenameErr; }

DAFileSystemRenameErr:

    if ( buffer         )  free( buffer );
    if ( mountpointPath )  free( mountpointPath );

    if ( callback )
    {
        ( callback )( status, callbackContext );
    }
}
Exemplo n.º 6
0
void set_bkuptime(const char* filename, struct timespec ts) {
	struct attrlist alist;
	bzero(&alist, sizeof(alist));
	alist.bitmapcount = ATTR_BIT_MAP_COUNT;
	alist.commonattr  = ATTR_CMN_BKUPTIME;
    int err = setattrlist(
		filename, 
		&alist, 
		&ts, 
		sizeof(ts), 
		FSOPT_NOFOLLOW
	);
    if(err != 0) {
		perror("setattrlist");
		exit(EXIT_FAILURE);
    }
}
Exemplo n.º 7
0
int
lchmod(const char *path, mode_t mode)
{
	struct stat s;
	struct attrlist a;
	int m;

	if(lstat(path, &s) < 0)
		return -1;
	if((s.st_mode & S_IFMT) != S_IFLNK)
		return chmod(path, mode);
	bzero(&a, sizeof(a));
	a.bitmapcount = ATTR_BIT_MAP_COUNT;
	a.commonattr = ATTR_CMN_ACCESSMASK;
	m = mode;
	return setattrlist(path, &a, &m, sizeof(int), FSOPT_NOFOLLOW);
}
Exemplo n.º 8
0
int do_chmod(const char *path, mode_t mode, uint32 fileflags)
{
	int code;
	if (dry_run) return 0;
	RETURN_ERROR_IF_RO_OR_LO;
#ifdef HAVE_LCHMOD
	code = lchmod(path, mode & CHMOD_BITS);
#else
	if (S_ISLNK(mode)) {
# if defined HAVE_SETATTRLIST
		struct attrlist attrList;
		uint32_t m = mode & CHMOD_BITS; /* manpage is wrong: not mode_t! */

		memset(&attrList, 0, sizeof attrList);
		attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
		attrList.commonattr = ATTR_CMN_ACCESSMASK;
		code = setattrlist(path, &attrList, &m, sizeof m, FSOPT_NOFOLLOW);
# else
		code = 1;
# endif
	} else
		code = chmod(path, mode & CHMOD_BITS); /* DISCOURAGED FUNCTION */
#endif /* !HAVE_LCHMOD */
#ifdef SUPPORT_FORCE_CHANGE
	if (code < 0 && force_change && errno == EPERM && !S_ISLNK(mode)) {
		if (fileflags == NO_FFLAGS) {
			STRUCT_STAT st;
			if (x_lstat(path, &st, NULL) == 0)
				fileflags = st.st_flags;
		}
		if (fileflags != NO_FFLAGS
		 && make_mutable(path, mode, fileflags, force_change) > 0) {
			code = chmod(path, mode & CHMOD_BITS);
			undo_make_mutable(path, fileflags);
			if (code == 0)
				return 0;
		}
		errno = EPERM;
	}
#else
	fileflags = 0; /* avoid compiler warning */
#endif
	if (code != 0 && (preserve_perms || preserve_executability))
		return code;
	return 0;
}
Exemplo n.º 9
0
__private_extern__ int ___chattr( const char * path, ___attr_t attr, ___attr_t noattr )
{
    /*
     * Change file flags.
     */

    struct __chattrbuf
    {
        uint32_t  size;
        uint8_t   reserved0032[8];
        ___attr_t attr;
        uint8_t   reserved0112[22];
    };

    typedef struct __chattrbuf __chattrbuf;

    struct attrlist attributes;
    __chattrbuf     buffer;
    int             status;

    attributes.bitmapcount = ATTR_BIT_MAP_COUNT;
    attributes.commonattr  = ATTR_CMN_FNDRINFO;
    attributes.dirattr     = 0;
    attributes.fileattr    = 0;
    attributes.forkattr    = 0;
    attributes.volattr     = 0;

    status = getattrlist( path, &attributes, &buffer, sizeof( buffer ), 0 );

    if ( status == 0 )
    {
        buffer.attr = OSSwapHostToBigInt16( ( OSSwapBigToHostInt16( buffer.attr ) & ~noattr ) | attr );

        status = setattrlist( path, &attributes, ( ( uint8_t * ) &buffer ) + sizeof( buffer.size ), sizeof( buffer ) - sizeof( buffer.size ), 0 );
    }

    return status;
}
Exemplo n.º 10
0
int main(int argc, char *argv[]) {

    char *path = NULL;
    struct attrlist alist;
    struct directoryinfo dirinfo;
    struct volumeinfo volinfo;
    struct statfs sfs;

    if (argc <= 1) {
	fprintf(stderr,"Usage: %s /Volumes/Foo/OpenMe/\n", argv[0]);
	exit(1);
    }

    path = argv[1];

    memset(&alist, 0, sizeof(alist));
    alist.bitmapcount = 5;
    alist.commonattr = ATTR_CMN_OBJID;

    getattrlist(path, &alist, &dirinfo, sizeof(dirinfo), 0);

    printf("directory id: %lu\n", dirinfo.dirid);

    statfs(path, &sfs);

    printf("mountpoint: %s\n", sfs.f_mntonname);

    alist.commonattr = ATTR_CMN_FNDRINFO;
    alist.volattr = ATTR_VOL_INFO;

    getattrlist(sfs.f_mntonname, &alist, &volinfo, sizeof(volinfo), 0);
    volinfo.finderinfo[2] = dirinfo.dirid;
    setattrlist(sfs.f_mntonname, &alist, volinfo.finderinfo, sizeof(volinfo.finderinfo), 0);

    return 0;
}
Exemplo n.º 11
0
static int
spade_fsetattr_x(const char *path, struct setattr_x *attr,
        struct fuse_file_info *fi) {
    int res;
    uid_t uid = -1;
    gid_t gid = -1;

    if (SETATTR_WANTS_MODE(attr)) {
        res = lchmod(path, attr->mode);
        if (res == -1) {
            return -errno;
        }
    }

    if (SETATTR_WANTS_UID(attr)) {
        uid = attr->uid;
    }

    if (SETATTR_WANTS_GID(attr)) {
        gid = attr->gid;
    }

    if ((uid != -1) || (gid != -1)) {
        res = lchown(path, uid, gid);
        if (res == -1) {
            return -errno;
        }
    }

    if (SETATTR_WANTS_SIZE(attr)) {
        if (fi) {
            res = ftruncate(fi->fh, attr->size);
        } else {
            res = truncate(path, attr->size);
        }
        if (res == -1) {
            return -errno;
        }
    }

    if (SETATTR_WANTS_MODTIME(attr)) {
        struct timeval tv[2];
        if (!SETATTR_WANTS_ACCTIME(attr)) {
            gettimeofday(&tv[0], NULL);
        } else {
            tv[0].tv_sec = attr->acctime.tv_sec;
            tv[0].tv_usec = attr->acctime.tv_nsec / 1000;
        }
        tv[1].tv_sec = attr->modtime.tv_sec;
        tv[1].tv_usec = attr->modtime.tv_nsec / 1000;
        res = utimes(path, tv);
        if (res == -1) {
            return -errno;
        }
    }

    if (SETATTR_WANTS_CRTIME(attr)) {
        struct attrlist attributes;

        attributes.bitmapcount = ATTR_BIT_MAP_COUNT;
        attributes.reserved = 0;
        attributes.commonattr = ATTR_CMN_CRTIME;
        attributes.dirattr = 0;
        attributes.fileattr = 0;
        attributes.forkattr = 0;
        attributes.volattr = 0;

        res = setattrlist(path, &attributes, &attr->crtime,
                sizeof (struct timespec), FSOPT_NOFOLLOW);

        if (res == -1) {
            return -errno;
        }
    }

    if (SETATTR_WANTS_CHGTIME(attr)) {
        struct attrlist attributes;

        attributes.bitmapcount = ATTR_BIT_MAP_COUNT;
        attributes.reserved = 0;
        attributes.commonattr = ATTR_CMN_CHGTIME;
        attributes.dirattr = 0;
        attributes.fileattr = 0;
        attributes.forkattr = 0;
        attributes.volattr = 0;

        res = setattrlist(path, &attributes, &attr->chgtime,
                sizeof (struct timespec), FSOPT_NOFOLLOW);

        if (res == -1) {
            return -errno;
        }
    }

    if (SETATTR_WANTS_BKUPTIME(attr)) {
        struct attrlist attributes;

        attributes.bitmapcount = ATTR_BIT_MAP_COUNT;
        attributes.reserved = 0;
        attributes.commonattr = ATTR_CMN_BKUPTIME;
        attributes.dirattr = 0;
        attributes.fileattr = 0;
        attributes.forkattr = 0;
        attributes.volattr = 0;

        res = setattrlist(path, &attributes, &attr->bkuptime,
                sizeof (struct timespec), FSOPT_NOFOLLOW);

        if (res == -1) {
            return -errno;
        }
    }

    if (SETATTR_WANTS_FLAGS(attr)) {
        res = lchflags(path, attr->flags);
        if (res == -1) {
            return -errno;
        }
    }

    return 0;
}