I am working on making a ruby module to wrapper the xsan quota fctl
calls.
I have C code that will get the quota information, but using the picaxe
book i dont quite understand how to make a wrapper.
Essecally i need 2 functions, a GetQuota function that would return a
Ruby struct with the information and a SetQuota function
the GetQuota would take only a name(“mcgoverp”) and a type (“U”), the
SetQuota function would take a hard limit soft limit and time out as
well as a name and a type.
This is my current trial
#include “ruby.h”
#include “./extapi.h”
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
static VALUE cXsanQuota;
static void free_quota(void *p)
{
}
static VALUE quota_alloc(VALUE klass){
}
static VALUE quota_initialize(VALUE self)
{
return self;
}
static VALUE get_quota(VALUE self,VALUE user,VALUE system)
{
const char* in_file = “/Home/”;
int in_fd = open(in_file, O_RDONLY); //open existing file
GetQuotaReqReply_t test;
GetQuotaReq_t request;
request.gq_type=‘U’;
strcpy(request.gq_quotaname,t.pw_name);
test.req=request;
int res=fcntl(in_fd,F_GETQUOTA,&test);
//test.response has struct
//how do i return that?
}
static VALUE set_quota(VALUE self,VALUE user, VALUE hl, VALUE sl, VALUE
to)
{
SetQuotaReq_t setquota;
char *str;
str=RSTRING(user)->ptr;
strcpy(setquota.sq_quotaname,str);
setquota.sq_type=“U”;
setquota.sq_timelimit=FIX2INT(to);
setquota.sq_hardlimit=NUM2ULONG(hl);
setquota.sq_softlimit=NUM2ULONG(sl);
res=fcntl(in_fd,F_SETQUOTA,&setquota);
return res;
}
void Init_XsanQuota()
{
cXsanQuota=rb_define_class(“XsanQuota”,rb_cObject);
rb_define_alloc_func(cXsanQuota,quota_alloc);
rb_define_method(cXsanQuota,“initialize”, quota_initialize,1);
rb_define_method(cXsanQuota,“getQuota”, quota_initialize,3);
rb_define_method(cXsanQuota,“setQuota”, quota_initialize,5);
}