1 static char *device_name();
3 /*----------------------------------------------------------------------
4 Return space left in disk quota on file system which given path is in.
6 Args: path - Path name of file or directory on file system of concern
7 over - pointer to flag that is set if the user is over quota
9 Returns: If *over = 0, the number of bytes free in disk quota as per
11 If *over = 1, the number of bytes *over* quota.
12 -1 is returned on an error looking up quota
13 0 is returned if there is no quota
15 BUG: If there's more than 2.1Gb free this function will break
18 disk_quota(path, over)
22 static int no_quota = 0;
29 return(0L); /* If no quota the first time, then none the second. */
31 dprint(5, (debugfile, "quota_check path: %s\n", path ? path : "?"));
32 if(stat(path, &statx) < 0) {
39 dname = device_name(statx.st_dev);
43 dprint(7, (debugfile, "Quota check: UID:%d device: %s\n",
44 getuid(), dname ? dname : "?"));
45 if(quotactl(Q_GETQUOTA, dname, getuid(), (char *)"ax) < 0) {
46 dprint(5, (debugfile, "Quota failed : %s\n",
47 error_description(errno)));
48 return(-1L); /* Something went wrong */
51 dprint(5,(debugfile,"Quota: bsoftlimit:%d bhardlimit:%d curblock:%d\n",
52 quotax.dqb_bsoftlimit, quotax.dqb_bhardlimit, quotax.dqb_curblocks));
54 if(quotax.dqb_bsoftlimit == -1)
57 q = (quotax.dqb_bsoftlimit - quotax.dqb_curblocks) * 512;
63 dprint(5, (debugfile, "disk_quota returning :%d, over:%d\n", q, *over));
68 /*----------------------------------------------------------------------
71 * This routine is here so that ex can get a device name to check
72 * disk quotas. One might wonder, why not use getmntent(), rather
73 * than read /etc/mtab in this crude way? The problem with getmntent
74 * is that it uses stdio, and ex/vi pointedly doesn't.
77 *device_name(st_devArg)
81 #define MTABNAME "/etc/mtab"
84 static char devName[48];
85 static char *answer = (char *) 0;
92 if (st_devArg == st_dev)
95 mtab = read_file(MTABNAME);
99 /* Initialize save data. */
104 for (cur=bol=0, dname=1; cur < nb; ++cur) {
106 if (dname && (mtab[cur] <= ' ')) {
107 /* Space, tab or other such character has been found,
108 presumably marking the end of the device name string. */
111 c = mtab[cur]; /* Save current character. */
112 mtab[cur] = 0; /* C zero-terminated string. */
114 /* Get device number, via stat(). If it's the right
115 number, copy the string and return its address. */
116 if (stat (&mtab[bol], &devStat) == 0) {
117 if (devStat.st_rdev == st_dev) {
118 if ((cur - bol + 1) < sizeof (devName)) {
119 strncpy (devName, &mtab[bol], sizeof(devName));
120 devName[sizeof(devName)-1] = '\0';
121 answer = &devName[0];
128 if (mtab[cur] == '\n') {