comparison lib/fsusage.c @ 793:d257c9ac0e72

(get_fs_usage): If DISK is 0 and we needed to use it, return -1 with 0 in ERRNO. From Miles.
author Jim Meyering <jim@meyering.net>
date Thu, 28 Nov 1996 19:37:01 +0000
parents 4361996c2116
children 5306f6a320de
comparison
equal deleted inserted replaced
792:85467f0ee1af 793:d257c9ac0e72
1 /* fsusage.c -- return space usage of mounted filesystems 1 /* fsusage.c -- return space usage of mounted filesystems
2 Copyright (C) 1991, 1992 Free Software Foundation, Inc. 2 Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option) 6 the Free Software Foundation; either version 2, or (at your option)
7 any later version. 7 any later version.
88 88
89 /* Fill in the fields of FSP with information about space usage for 89 /* Fill in the fields of FSP with information about space usage for
90 the filesystem on which PATH resides. 90 the filesystem on which PATH resides.
91 DISK is the device on which PATH is mounted, for space-getting 91 DISK is the device on which PATH is mounted, for space-getting
92 methods that need to know it. 92 methods that need to know it.
93 Return 0 if successful, -1 if not. */ 93 Return 0 if successful, -1 if not. When returning -1, ensure that
94 94 ERRNO is either a system error value, or zero if DISK is NULL
95 on a system that requires a non-NULL value. */
95 int 96 int
96 get_fs_usage (path, disk, fsp) 97 get_fs_usage (path, disk, fsp)
97 const char *path; 98 const char *path;
98 const char *disk; 99 const char *disk;
99 struct fs_usage *fsp; 100 struct fs_usage *fsp;
130 # define CONVERT_BLOCKS(B) \ 131 # define CONVERT_BLOCKS(B) \
131 adjust_blocks ((B), (fsd.s_type == Fs2b ? 1024 : 512), 512) 132 adjust_blocks ((B), (fsd.s_type == Fs2b ? 1024 : 512), 512)
132 133
133 struct filsys fsd; 134 struct filsys fsd;
134 int fd; 135 int fd;
136
137 if (! disk)
138 {
139 errno = 0;
140 return -1;
141 }
135 142
136 fd = open (disk, O_RDONLY); 143 fd = open (disk, O_RDONLY);
137 if (fd < 0) 144 if (fd < 0)
138 return -1; 145 return -1;
139 lseek (fd, (long) SUPERBOFF, 0); 146 lseek (fd, (long) SUPERBOFF, 0);