Changeset 13697
- Timestamp:
- Dec 27, 2012, 7:41:34 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/platform.c
r13696 r13697 63 63 #include <fcntl.h> 64 64 #include <unistd.h> /* getuid getpid close */ 65 66 #ifdef HAVE_XFS_XFS_H 67 #define HAVE_XQM 68 #include <xfs/xqm.h> 69 #endif 65 70 66 71 #include "transmission.h" … … 754 759 755 760 static char * 761 getfstype( const char * device ) 762 { 763 #ifdef HAVE_GETMNTENT 764 FILE *fp; 765 struct mntent *mnt; 766 767 if ((fp = setmntent(_PATH_MOUNTED, "r")) == NULL) 768 { 769 return NULL; 770 } 771 while ((mnt = getmntent(fp)) != NULL) 772 { 773 if (strcmp(device, mnt->mnt_fsname) == 0) 774 { 775 break; 776 } 777 } 778 endmntent(fp); 779 return mnt ? mnt->mnt_type : NULL; 780 #else /* BSD derived systems */ 781 int n, i; 782 struct statfs *mnt; 783 784 if ((n = getmntinfo(&mnt, MNT_WAIT)) == 0) 785 { 786 return NULL; 787 } 788 for (i=0; i<n; i++) 789 { 790 if (strcmp(device, mnt[i].f_mntfromname) == 0) 791 { 792 break; 793 } 794 } 795 return (i < n) ? mnt[i].f_fstypename : NULL; 796 #endif 797 } 798 799 static char * 756 800 getblkdev( const char * path ) 757 801 { … … 809 853 return -1; 810 854 } 811 #endif 855 856 #ifdef HAVE_XQM 857 static int64_t 858 getxfsquota( char * device ) 859 { 860 struct fs_disk_quota dq; 861 int64_t freespace, limit; 862 863 if (quotactl(QCMD(Q_XGETQUOTA, USRQUOTA), device, getuid(), 864 (caddr_t) &dq) == 0) 865 { 866 if (dq.d_blk_softlimit > 0) 867 { 868 /* Use soft limit first */ 869 limit = dq.d_blk_softlimit >> 1; 870 } 871 else if (dq.d_blk_hardlimit > 0) 872 { 873 limit = dq.d_blk_hardlimit >> 1; 874 } 875 else 876 { 877 /* No quota enabled for this user */ 878 return -1; 879 } 880 freespace = limit - (dq.d_bcount >> 1); 881 return (freespace < 0) ? 0 : freespace * 1024; 882 } 883 884 /* Something went wrong */ 885 return -1; 886 } 887 #endif /* HAVE_XQM */ 888 #endif /* WIN32 */ 812 889 813 890 static int64_t … … 816 893 int64_t ret=-1; 817 894 #ifndef WIN32 818 char *device; 819 820 if ((device = getblkdev(path)) != NULL) 821 { 895 char *d, *device; 896 char *fstype; 897 898 if ((d = getblkdev(path)) == NULL) 899 { 900 return ret; 901 } 902 /* 'd' points to static area of memory, so copy it */ 903 device = tr_strdup(d); 904 905 fstype = getfstype(device); 906 if (fstype != NULL && strcasecmp(fstype, "xfs") == 0) 907 { 908 #ifdef HAVE_XQM 909 ret = getxfsquota(device); 910 #endif 911 } else { 822 912 ret = getquota(device); 823 913 } 824 #endif 914 915 tr_free(device); 916 #endif /* WIN32 */ 825 917 return ret; 826 918 }
Note: See TracChangeset
for help on using the changeset viewer.